1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: vtkStaticEnSightGoldReader.cxx
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
15 #include "vtkStaticEnSightGoldReader.h"
17 #include <vtkDataArray.h>
18 #include <vtkDataArrayCollection.h>
19 #include <vtkIdList.h>
20 #include <vtkIdListCollection.h>
21 #include <vtkInformation.h>
22 #include <vtkInformationVector.h>
23 #include <vtkMultiBlockDataSet.h>
24 #include <vtkObjectFactory.h>
25 #include <vtkStreamingDemandDrivenPipeline.h>
27 vtkStandardNewMacro(vtkStaticEnSightGoldReader);
29 //----------------------------------------------------------------------------
30 int vtkStaticEnSightGoldReader::RequestData(
31 vtkInformation *vtkNotUsed(request),
32 vtkInformationVector **vtkNotUsed(inputVector),
33 vtkInformationVector *outputVector)
35 vtkDebugMacro("In execute ");
37 vtkInformation *outInfo = outputVector->GetInformationObject(0);
38 vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast(
39 outInfo->Get(vtkDataObject::DATA_OBJECT()));
42 outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
44 outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
46 this->ActualTimeValue = this->TimeValue;
48 // Check if a particular time was requested by the pipeline.
49 // This overrides the ivar.
50 if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) && tsLength>0)
52 // Get the requested time step. We only support requests of a single time
53 // step in this reader right now
54 double requestedTimeStep =
55 outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
57 // find the first time value larger than requested time value
58 // this logic could be improved
60 while (cnt < tsLength-1 && steps[cnt] < requestedTimeStep)
64 this->ActualTimeValue = steps[cnt];
67 vtkDebugMacro("Executing with: " << this->ActualTimeValue);
69 if (this->CacheMTime < this->GetMTime())
71 int i, timeSet, fileSet, timeStep, timeStepInFile, fileNum;
73 vtkIdList *numStepsList, *filenameNumbers;
79 if ( ! this->CaseFileRead)
81 vtkErrorMacro("error reading case file");
85 this->NumberOfNewOutputs = 0;
86 this->NumberOfGeometryParts = 0;
87 if (this->GeometryFileName)
89 timeStep = timeStepInFile = 1;
91 fileName = new char[strlen(this->GeometryFileName) + 10];
92 strcpy(fileName, this->GeometryFileName);
94 if (this->UseTimeSets)
96 timeSet = this->TimeSetIds->IsId(this->GeometryTimeSet);
99 times = this->TimeSets->GetItem(timeSet);
100 this->GeometryTimeValue = times->GetComponent(0, 0);
101 for (i = 1; i < times->GetNumberOfTuples(); i++)
103 newTime = times->GetComponent(i, 0);
104 if (newTime <= this->ActualTimeValue &&
105 newTime > this->GeometryTimeValue)
107 this->GeometryTimeValue = newTime;
112 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
114 int collectionNum = this->TimeSetsWithFilenameNumbers->
115 IsId(this->GeometryTimeSet);
116 if (collectionNum > -1)
119 this->TimeSetFileNameNumbers->GetItem(collectionNum);
120 filenameNum = filenameNumbers->GetId(timeStep-1);
121 if (! this->UseFileSets)
123 this->ReplaceWildcards(fileName, filenameNum);
128 // There can only be file sets if there are also time sets.
129 if (this->UseFileSets)
131 fileSet = this->FileSets->IsId(this->GeometryFileSet);
132 numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
133 GetItemAsObject(fileSet));
135 if (timeStep > numStepsList->GetId(0))
137 numSteps = numStepsList->GetId(0);
138 timeStepInFile -= numSteps;
140 for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
142 numSteps += numStepsList->GetId(i);
143 if (timeStep > numSteps)
146 timeStepInFile -= numStepsList->GetId(i);
150 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
152 int collectionNum = this->FileSetsWithFilenameNumbers->
153 IsId(this->GeometryFileSet);
154 if (collectionNum > -1)
156 filenameNumbers = this->FileSetFileNameNumbers->
157 GetItem(collectionNum);
158 filenameNum = filenameNumbers->GetId(fileNum-1);
159 this->ReplaceWildcards(fileName, filenameNum);
166 if (!this->ReadGeometryFile(fileName, timeStepInFile, this->Cache))
168 vtkErrorMacro("error reading geometry file");
175 if (this->MeasuredFileName)
177 timeStep = timeStepInFile = 1;
179 fileName = new char[strlen(this->MeasuredFileName) + 10];
180 strcpy(fileName, this->MeasuredFileName);
182 if (this->UseTimeSets)
184 timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
187 times = this->TimeSets->GetItem(timeSet);
188 this->MeasuredTimeValue = times->GetComponent(0, 0);
189 for (i = 1; i < times->GetNumberOfTuples(); i++)
191 newTime = times->GetComponent(i, 0);
192 if (newTime <= this->ActualTimeValue &&
193 newTime > this->MeasuredTimeValue)
195 this->MeasuredTimeValue = newTime;
200 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
202 int collectionNum = this->TimeSetsWithFilenameNumbers->
203 IsId(this->MeasuredTimeSet);
204 if (collectionNum > -1)
206 filenameNumbers = this->TimeSetFileNameNumbers->
207 GetItem(collectionNum);
208 filenameNum = filenameNumbers->GetId(timeStep-1);
209 if (! this->UseFileSets)
211 this->ReplaceWildcards(fileName, filenameNum);
216 // There can only be file sets if there are also time sets.
217 if (this->UseFileSets)
219 fileSet = this->FileSets->IsId(this->MeasuredFileSet);
220 numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
221 GetItemAsObject(fileSet));
223 if (timeStep > numStepsList->GetId(0))
225 numSteps = numStepsList->GetId(0);
226 timeStepInFile -= numSteps;
228 for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
230 numSteps += numStepsList->GetId(i);
231 if (timeStep > numSteps)
234 timeStepInFile -= numStepsList->GetId(i);
238 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
240 int collectionNum = this->FileSetsWithFilenameNumbers->
241 IsId(this->MeasuredFileSet);
242 if (collectionNum > -1)
244 filenameNumbers = this->FileSetFileNameNumbers->
246 filenameNum = filenameNumbers->GetId(fileNum-1);
247 this->ReplaceWildcards(fileName, filenameNum);
253 if (!this->ReadMeasuredGeometryFile(fileName, timeStepInFile, this->Cache))
255 vtkErrorMacro("error reading measured geometry file");
261 this->CacheMTime.Modified();
263 output->ShallowCopy(this->Cache);
265 if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
267 if (!this->ReadVariableFiles(output))
269 vtkErrorMacro("error reading variable files");