]> SALOME platform Git repositories - modules/paravis.git/blob - src/Plugins/StaticMesh/plugin/StaticMeshModule/vtkStaticEnSightGoldBinaryReader.cxx
Salome HOME
bos #42937: [CEA 41954] Integration of UB24.04 patches
[modules/paravis.git] / src / Plugins / StaticMesh / plugin / StaticMeshModule / vtkStaticEnSightGoldBinaryReader.cxx
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkStaticEnSightGoldBinaryReader.cxx
5
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
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.
13
14 =========================================================================*/
15 #include "vtkStaticEnSightGoldBinaryReader.h"
16
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>
27
28 vtkStandardNewMacro(vtkStaticEnSightGoldBinaryReader);
29
30 //----------------------------------------------------------------------------
31 int vtkStaticEnSightGoldBinaryReader::RequestData(vtkInformation* vtkNotUsed(request),
32   vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
33 {
34   vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::GetData(outputVector);
35
36   vtkInformation* outInfo = outputVector->GetInformationObject(0);
37   int tsLength = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
38   double* steps = outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
39
40   this->ActualTimeValue = this->TimeValue;
41
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)
45   {
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());
49
50     // find the first time value larger than requested time value
51     // this logic could be improved
52     int cnt = 0;
53     while (cnt < tsLength - 1 && steps[cnt] < requestedTimeStep)
54     {
55       cnt++;
56     }
57     this->ActualTimeValue = steps[cnt];
58   }
59
60   if (!this->UseStaticMesh || this->CacheMTime < this->GetMTime())
61   {
62     if (vtksys::SystemTools::HasEnv("VTK_DEBUG_STATIC_MESH"))
63     {
64       vtkWarningMacro("Building static mesh cache");
65     }
66
67     if (!this->CaseFileRead)
68     {
69       vtkErrorMacro("error reading case file");
70       return 0;
71     }
72
73     this->NumberOfNewOutputs = 0;
74     this->NumberOfGeometryParts = 0;
75     if (this->GeometryFileName)
76     {
77       vtkIdType timeStep = 1;
78       vtkIdType timeStepInFile = 1;
79       int fileNum = 1;
80       std::string fileName(this->GeometryFileName);
81       fileName.resize(fileName.size() + 10);
82
83       if (this->UseTimeSets)
84       {
85         vtkIdType timeSet = this->TimeSetIds->IsId(this->GeometryTimeSet);
86         if (timeSet >= 0)
87         {
88           // Always consider the first mesh when reading geometry
89           this->GeometryTimeValue = this->MinimumTimeValue;
90
91           vtkDataArray* times = this->TimeSets->GetItem(timeSet);
92           this->GeometryTimeValue = times->GetComponent(0, 0);
93           for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
94           {
95             double newTime = times->GetComponent(i, 0);
96             if (newTime <= this->ActualTimeValue && newTime > this->GeometryTimeValue)
97             {
98               timeStep++;
99               timeStepInFile++;
100             }
101           }
102
103           if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
104           {
105             int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->GeometryTimeSet);
106             if (collectionNum > -1)
107             {
108               vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
109               int filenameNum = filenameNumbers->GetId(timeStep - 1);
110               if (!this->UseFileSets)
111               {
112                 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
113               }
114             }
115           }
116
117           // There can only be file sets if there are also time sets.
118           if (this->UseFileSets)
119           {
120             vtkIdType fileSet = this->FileSets->IsId(this->GeometryFileSet);
121             vtkIdList* numStepsList =
122               static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
123
124             if (timeStep > numStepsList->GetId(0))
125             {
126               vtkIdType numSteps = numStepsList->GetId(0);
127               timeStepInFile -= numSteps;
128               fileNum = 2;
129               for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
130               {
131                 numSteps += numStepsList->GetId(i);
132                 if (timeStep > numSteps)
133                 {
134                   fileNum++;
135                   timeStepInFile -= numStepsList->GetId(i);
136                 }
137               }
138             }
139             if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
140             {
141               int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->GeometryFileSet);
142               if (collectionNum > -1)
143               {
144                 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(collectionNum);
145                 int filenameNum = filenameNumbers->GetId(fileNum - 1);
146                 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
147               }
148             }
149           }
150         }
151       }
152
153       if (!this->ReadGeometryFile(fileName.data(), timeStepInFile, this->Cache))
154       {
155         vtkErrorMacro("error reading geometry file");
156         return 0;
157       }
158     }
159     if (this->MeasuredFileName)
160     {
161       vtkIdType timeStep = 1;
162       vtkIdType timeStepInFile = 1;
163       int fileNum = 1;
164       std::string fileName(this->MeasuredFileName);
165       fileName.resize(fileName.size() + 10);
166
167       if (this->UseTimeSets)
168       {
169         vtkIdType timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
170         if (timeSet >= 0)
171         {
172           vtkDataArray* times = this->TimeSets->GetItem(timeSet);
173           this->MeasuredTimeValue = times->GetComponent(0, 0);
174           for (vtkIdType i = 1; i < times->GetNumberOfTuples(); i++)
175           {
176             double newTime = times->GetComponent(i, 0);
177             if (newTime <= this->ActualTimeValue && newTime > this->MeasuredTimeValue)
178             {
179               this->MeasuredTimeValue = newTime;
180               timeStep++;
181               timeStepInFile++;
182             }
183           }
184           if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
185           {
186             int collectionNum = this->TimeSetsWithFilenameNumbers->IsId(this->MeasuredTimeSet);
187             if (collectionNum > -1)
188             {
189               vtkIdList* filenameNumbers = this->TimeSetFileNameNumbers->GetItem(collectionNum);
190               int filenameNum = filenameNumbers->GetId(timeStep - 1);
191               if (!this->UseFileSets)
192               {
193                 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
194               }
195             }
196           }
197
198           // There can only be file sets if there are also time sets.
199           if (this->UseFileSets)
200           {
201             vtkIdType fileSet = this->FileSets->IsId(this->MeasuredFileSet);
202             vtkIdList* numStepsList =
203               static_cast<vtkIdList*>(this->FileSetNumberOfSteps->GetItemAsObject(fileSet));
204
205             if (timeStep > numStepsList->GetId(0))
206             {
207               vtkIdType numSteps = numStepsList->GetId(0);
208               timeStepInFile -= numSteps;
209               fileNum = 2;
210               for (vtkIdType i = 1; i < numStepsList->GetNumberOfIds(); i++)
211               {
212                 numSteps += numStepsList->GetId(i);
213                 if (timeStep > numSteps)
214                 {
215                   fileNum++;
216                   timeStepInFile -= numStepsList->GetId(i);
217                 }
218               }
219             }
220             if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
221             {
222               int collectionNum = this->FileSetsWithFilenameNumbers->IsId(this->MeasuredFileSet);
223               if (collectionNum > -1)
224               {
225                 vtkIdList* filenameNumbers = this->FileSetFileNameNumbers->GetItem(fileSet);
226                 int filenameNum = filenameNumbers->GetId(fileNum - 1);
227                 this->ReplaceWildcardsHelper(&fileName[0], filenameNum);
228               }
229             }
230           }
231         }
232       }
233       if (!this->ReadMeasuredGeometryFile(fileName.data(), timeStepInFile, this->Cache))
234       {
235         vtkErrorMacro("error reading measured geometry file");
236         return 0;
237       }
238     }
239     this->CacheMTime.Modified();
240   }
241   output->ShallowCopy(this->Cache);
242
243   if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
244   {
245     if (!this->ReadVariableFiles(output))
246     {
247       vtkErrorMacro("error reading variable files");
248       return 0;
249     }
250   }
251
252   return 1;
253 }