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>
26 #include <vtksys/SystemTools.hxx>
28 vtkStandardNewMacro(vtkStaticEnSightGoldReader);
30 //----------------------------------------------------------------------------
31 int vtkStaticEnSightGoldReader::RequestData(vtkInformation* vtkNotUsed(request),
32 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
34 vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::GetData(outputVector);
36 vtkInformation* outInfo = outputVector->GetInformationObject(0);
37 int tsLength = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
38 double* steps = outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
40 this->ActualTimeValue = this->TimeValue;
42 // Check if a particular time was requested by the pipeline.
43 // This overrides the ivar.
44 if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) && tsLength > 0)
46 // Get the requested time step. We only support requests of a single time
47 // step in this reader right now
48 double requestedTimeStep = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
50 // find the first time value larger than requested time value
51 // this logic could be improved
53 while (cnt < tsLength - 1 && steps[cnt] < requestedTimeStep)
57 this->ActualTimeValue = steps[cnt];
60 if (!this->UseStaticMesh || this->CacheMTime < this->GetMTime())
62 if (vtksys::SystemTools::HasEnv("VTK_DEBUG_STATIC_MESH"))
64 vtkWarningMacro("Building static mesh cache");
67 if (!this->CaseFileRead)
69 vtkErrorMacro("error reading case file");
73 this->NumberOfNewOutputs = 0;
74 this->NumberOfGeometryParts = 0;
75 if (this->GeometryFileName)
77 vtkIdType timeStep = 1;
78 vtkIdType timeStepInFile = 1;
80 std::string fileName(this->GeometryFileName);
81 fileName.resize(fileName.size() + 10);
83 if (this->UseTimeSets)
85 vtkIdType timeSet = this->TimeSetIds->IsId(this->GeometryTimeSet);
88 vtkDataArray* times = this->TimeSets->GetItem(timeSet);
89 this->GeometryTimeValue = times->GetComponent(0, 0);
90 for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
92 double newTime = times->GetComponent(i, 0);
93 if (newTime <= this->ActualTimeValue && newTime > this->GeometryTimeValue)
95 this->GeometryTimeValue = newTime;
100 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
102 int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->GeometryTimeSet);
103 if (collectionNum > -1)
105 vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
106 int filenameNum = filenameNumbers->GetId(timeStep - 1);
107 if (!this->UseFileSets)
109 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
114 // There can only be file sets if there are also time sets.
115 if (this->UseFileSets)
117 vtkIdType fileSet = this->FileSets->IsId(this->GeometryFileSet);
118 vtkIdList* numStepsList =
119 static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
121 if (timeStep > numStepsList->GetId(0))
123 vtkIdType numSteps = numStepsList->GetId(0);
124 timeStepInFile -= numSteps;
126 for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
128 numSteps += numStepsList->GetId(i);
129 if (timeStep > numSteps)
132 timeStepInFile -= numStepsList->GetId(i);
136 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
138 int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->GeometryFileSet);
139 if (collectionNum > -1)
141 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(collectionNum);
142 int filenameNum = filenameNumbers->GetId(fileNum - 1);
143 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
150 if (!this->ReadGeometryFile(fileName.data(), timeStepInFile, this->Cache))
152 vtkErrorMacro("error reading geometry file");
156 if (this->MeasuredFileName)
158 vtkIdType timeStep = 1;
159 vtkIdType timeStepInFile = 1;
161 std::string fileName(this->MeasuredFileName);
162 fileName.resize(fileName.size() + 10);
164 if (this->UseTimeSets)
166 vtkIdType timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
169 vtkDataArray* times = this->TimeSets->GetItem(timeSet);
170 this->MeasuredTimeValue = times->GetComponent(0, 0);
171 for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
173 double newTime = times->GetComponent(i, 0);
174 if (newTime <= this->ActualTimeValue && newTime > this->MeasuredTimeValue)
176 this->MeasuredTimeValue = newTime;
181 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
183 int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->MeasuredTimeSet);
184 if (collectionNum > -1)
186 vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
187 int filenameNum = filenameNumbers->GetId(timeStep - 1);
188 if (!this->UseFileSets)
190 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
195 // There can only be file sets if there are also time sets.
196 if (this->UseFileSets)
198 vtkIdType fileSet = this->FileSets->IsId(this->MeasuredFileSet);
199 vtkIdList* numStepsList =
200 static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
202 if (timeStep > numStepsList->GetId(0))
204 vtkIdType numSteps = numStepsList->GetId(0);
205 timeStepInFile -= numSteps;
207 for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
209 numSteps += numStepsList->GetId(i);
210 if (timeStep > numSteps)
213 timeStepInFile -= numStepsList->GetId(i);
217 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
219 int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->MeasuredFileSet);
220 if (collectionNum > -1)
222 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(fileSet);
223 int filenameNum = filenameNumbers->GetId(fileNum - 1);
224 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
230 if (!this->ReadMeasuredGeometryFile(fileName.data(), timeStepInFile, this->Cache))
232 vtkErrorMacro("error reading measured geometry file");
236 this->CacheMTime.Modified();
238 output->ShallowCopy(this->Cache);
240 if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
242 if (!this->ReadVariableFiles(output))
244 vtkErrorMacro("error reading variable files");