Salome HOME
[EDF17832] : Move VoroGauss GaussToCell StaticMesh DevelopedSurface from EDF to parav...
[modules/paravis.git] / src / Plugins / StaticMesh / vtkStaticEnSightGoldReader.cxx
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    vtkStaticEnSightGoldReader.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 "vtkStaticEnSightGoldReader.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
27 vtkStandardNewMacro(vtkStaticEnSightGoldReader);
28
29 //----------------------------------------------------------------------------
30 int vtkStaticEnSightGoldReader::RequestData(
31   vtkInformation *vtkNotUsed(request),
32   vtkInformationVector **vtkNotUsed(inputVector),
33   vtkInformationVector *outputVector)
34 {
35   vtkDebugMacro("In execute ");
36
37   vtkInformation *outInfo = outputVector->GetInformationObject(0);
38   vtkMultiBlockDataSet *output = vtkMultiBlockDataSet::SafeDownCast(
39     outInfo->Get(vtkDataObject::DATA_OBJECT()));
40
41   int tsLength =
42     outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
43   double* steps =
44     outInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
45
46   this->ActualTimeValue = this->TimeValue;
47
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)
51   {
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());
56
57     // find the first time value larger than requested time value
58     // this logic could be improved
59     int cnt = 0;
60     while (cnt < tsLength-1 && steps[cnt] < requestedTimeStep)
61     {
62       cnt++;
63     }
64     this->ActualTimeValue = steps[cnt];
65   }
66
67   vtkDebugMacro("Executing with: " << this->ActualTimeValue);
68
69   if (this->CacheMTime < this->GetMTime())
70   {
71     int i, timeSet, fileSet, timeStep, timeStepInFile, fileNum;
72     vtkDataArray *times;
73     vtkIdList *numStepsList, *filenameNumbers;
74     float newTime;
75     int numSteps;
76     char* fileName;
77     int filenameNum;
78
79     if ( ! this->CaseFileRead)
80     {
81       vtkErrorMacro("error reading case file");
82       return 0;
83     }
84
85     this->NumberOfNewOutputs = 0;
86     this->NumberOfGeometryParts = 0;
87     if (this->GeometryFileName)
88     {
89       timeStep = timeStepInFile = 1;
90       fileNum = 1;
91       fileName = new char[strlen(this->GeometryFileName) + 10];
92       strcpy(fileName, this->GeometryFileName);
93
94       if (this->UseTimeSets)
95       {
96         timeSet = this->TimeSetIds->IsId(this->GeometryTimeSet);
97         if (timeSet >= 0)
98         {
99           times = this->TimeSets->GetItem(timeSet);
100           this->GeometryTimeValue = times->GetComponent(0, 0);
101           for (i = 1; i < times->GetNumberOfTuples(); i++)
102           {
103             newTime = times->GetComponent(i, 0);
104             if (newTime <= this->ActualTimeValue &&
105                 newTime > this->GeometryTimeValue)
106             {
107               this->GeometryTimeValue = newTime;
108               timeStep++;
109               timeStepInFile++;
110             }
111           }
112           if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
113           {
114             int collectionNum = this->TimeSetsWithFilenameNumbers->
115               IsId(this->GeometryTimeSet);
116             if (collectionNum > -1)
117             {
118               filenameNumbers =
119                 this->TimeSetFileNameNumbers->GetItem(collectionNum);
120               filenameNum = filenameNumbers->GetId(timeStep-1);
121               if (! this->UseFileSets)
122               {
123                 this->ReplaceWildcards(fileName, filenameNum);
124               }
125             }
126           }
127
128           // There can only be file sets if there are also time sets.
129           if (this->UseFileSets)
130           {
131             fileSet = this->FileSets->IsId(this->GeometryFileSet);
132             numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
133                                                    GetItemAsObject(fileSet));
134
135             if (timeStep > numStepsList->GetId(0))
136             {
137               numSteps = numStepsList->GetId(0);
138               timeStepInFile -= numSteps;
139               fileNum = 2;
140               for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
141               {
142                 numSteps += numStepsList->GetId(i);
143                 if (timeStep > numSteps)
144                 {
145                   fileNum++;
146                   timeStepInFile -= numStepsList->GetId(i);
147                 }
148               }
149             }
150             if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
151             {
152               int collectionNum = this->FileSetsWithFilenameNumbers->
153                 IsId(this->GeometryFileSet);
154               if (collectionNum > -1)
155               {
156                 filenameNumbers = this->FileSetFileNameNumbers->
157                   GetItem(collectionNum);
158                 filenameNum = filenameNumbers->GetId(fileNum-1);
159                 this->ReplaceWildcards(fileName, filenameNum);
160               }
161             }
162           }
163         }
164       }
165
166       if (!this->ReadGeometryFile(fileName, timeStepInFile, this->Cache))
167       {
168         vtkErrorMacro("error reading geometry file");
169         delete [] fileName;
170         return 0;
171       }
172
173       delete [] fileName;
174     }
175     if (this->MeasuredFileName)
176     {
177       timeStep = timeStepInFile = 1;
178       fileNum = 1;
179       fileName = new char[strlen(this->MeasuredFileName) + 10];
180       strcpy(fileName, this->MeasuredFileName);
181
182       if (this->UseTimeSets)
183       {
184         timeSet = this->TimeSetIds->IsId(this->MeasuredTimeSet);
185         if (timeSet >= 0)
186         {
187           times = this->TimeSets->GetItem(timeSet);
188           this->MeasuredTimeValue = times->GetComponent(0, 0);
189           for (i = 1; i < times->GetNumberOfTuples(); i++)
190           {
191             newTime = times->GetComponent(i, 0);
192             if (newTime <= this->ActualTimeValue &&
193                 newTime > this->MeasuredTimeValue)
194             {
195               this->MeasuredTimeValue = newTime;
196               timeStep++;
197               timeStepInFile++;
198             }
199           }
200           if (this->TimeSetFileNameNumbers->GetNumberOfItems() > 0)
201           {
202             int collectionNum = this->TimeSetsWithFilenameNumbers->
203               IsId(this->MeasuredTimeSet);
204             if (collectionNum > -1)
205             {
206               filenameNumbers = this->TimeSetFileNameNumbers->
207                 GetItem(collectionNum);
208               filenameNum = filenameNumbers->GetId(timeStep-1);
209               if (! this->UseFileSets)
210               {
211                 this->ReplaceWildcards(fileName, filenameNum);
212               }
213             }
214           }
215
216           // There can only be file sets if there are also time sets.
217           if (this->UseFileSets)
218           {
219             fileSet = this->FileSets->IsId(this->MeasuredFileSet);
220             numStepsList = static_cast<vtkIdList*>(this->FileSetNumberOfSteps->
221                                                    GetItemAsObject(fileSet));
222
223             if (timeStep > numStepsList->GetId(0))
224             {
225               numSteps = numStepsList->GetId(0);
226               timeStepInFile -= numSteps;
227               fileNum = 2;
228               for (i = 1; i < numStepsList->GetNumberOfIds(); i++)
229               {
230                 numSteps += numStepsList->GetId(i);
231                 if (timeStep > numSteps)
232                 {
233                   fileNum++;
234                   timeStepInFile -= numStepsList->GetId(i);
235                 }
236               }
237             }
238             if (this->FileSetFileNameNumbers->GetNumberOfItems() > 0)
239             {
240               int collectionNum = this->FileSetsWithFilenameNumbers->
241                 IsId(this->MeasuredFileSet);
242               if (collectionNum > -1)
243               {
244                 filenameNumbers = this->FileSetFileNameNumbers->
245                   GetItem(fileSet);
246                 filenameNum = filenameNumbers->GetId(fileNum-1);
247                 this->ReplaceWildcards(fileName, filenameNum);
248               }
249             }
250           }
251         }
252       }
253       if (!this->ReadMeasuredGeometryFile(fileName, timeStepInFile, this->Cache))
254       {
255         vtkErrorMacro("error reading measured geometry file");
256         delete [] fileName;
257         return 0;
258       }
259       delete [] fileName;
260     }
261     this->CacheMTime.Modified();
262   }
263   output->ShallowCopy(this->Cache);
264
265   if ((this->NumberOfVariables + this->NumberOfComplexVariables) > 0)
266   {
267     if (!this->ReadVariableFiles(output))
268     {
269       vtkErrorMacro("error reading variable files");
270       return 0;
271     }
272   }
273
274   return 1;
275 }