1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: vtkStaticEnSightGoldBinaryReader.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 "vtkStaticEnSightGoldBinaryReader.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(vtkStaticEnSightGoldBinaryReader);
30 //----------------------------------------------------------------------------
31 int vtkStaticEnSightGoldBinaryReader::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 // Always consider the first mesh when reading geometry
89 this->GeometryTimeValue = this->MinimumTimeValue;
91 vtkDataArray* times = this->TimeSets->GetItem(timeSet);
92 this->GeometryTimeValue = times->GetComponent(0, 0);
93 for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
95 double newTime = times->GetComponent(i, 0);
96 if (newTime <= this->ActualTimeValue && newTime > this->GeometryTimeValue)
103 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
105 int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->GeometryTimeSet);
106 if (collectionNum > -1)
108 vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
109 int filenameNum = filenameNumbers->GetId(timeStep - 1);
110 if (!this->UseFileSets)
112 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
117 // There can only be file sets if there are also time sets.
118 if (this->UseFileSets)
120 vtkIdType fileSet = this->FileSets->IsId(this->GeometryFileSet);
121 vtkIdList* numStepsList =
122 static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
124 if (timeStep > numStepsList->GetId(0))
126 vtkIdType numSteps = numStepsList->GetId(0);
127 timeStepInFile -= numSteps;
129 for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
131 numSteps += numStepsList->GetId(i);
132 if (timeStep > numSteps)
135 timeStepInFile -= numStepsList->GetId(i);
139 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
141 int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->GeometryFileSet);
142 if (collectionNum > -1)
144 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(collectionNum);
145 int filenameNum = filenameNumbers->GetId(fileNum - 1);
146 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
153 if (!this->ReadGeometryFile(fileName.data(), timeStepInFile, this->Cache))
155 vtkErrorMacro("error reading geometry file");
159 if (this->MeasuredFileName)
161 vtkIdType timeStep = 1;
162 vtkIdType timeStepInFile = 1;
164 std::string fileName(this->MeasuredFileName);
165 fileName.resize(fileName.size() + 10);
167 if (this->UseTimeSets)
169 vtkIdType timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
172 vtkDataArray* times = this->TimeSets->GetItem(timeSet);
173 this->MeasuredTimeValue = times->GetComponent(0, 0);
174 for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
176 double newTime = times->GetComponent(i, 0);
177 if (newTime <= this->ActualTimeValue && newTime > this->MeasuredTimeValue)
179 this->MeasuredTimeValue = newTime;
184 if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
186 int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->MeasuredTimeSet);
187 if (collectionNum > -1)
189 vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
190 int filenameNum = filenameNumbers->GetId(timeStep - 1);
191 if (!this->UseFileSets)
193 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
198 // There can only be file sets if there are also time sets.
199 if (this->UseFileSets)
201 vtkIdType fileSet = this->FileSets->IsId(this->MeasuredFileSet);
202 vtkIdList* numStepsList =
203 static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
205 if (timeStep > numStepsList->GetId(0))
207 vtkIdType numSteps = numStepsList->GetId(0);
208 timeStepInFile -= numSteps;
210 for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
212 numSteps += numStepsList->GetId(i);
213 if (timeStep > numSteps)
216 timeStepInFile -= numStepsList->GetId(i);
220 if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
222 int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->MeasuredFileSet);
223 if (collectionNum > -1)
225 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(fileSet);
226 int filenameNum = filenameNumbers->GetId(fileNum - 1);
227 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
233 if (!this->ReadMeasuredGeometryFile(fileName.data(), timeStepInFile, this->Cache))
235 vtkErrorMacro("error reading measured geometry file");
239 this->CacheMTime.Modified();
241 output->ShallowCopy(this->Cache);
243 if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
245 if (!this->ReadVariableFiles(output))
247 vtkErrorMacro("error reading variable files");