Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/paravis.git] / src / Plugins / MedReader / IO / vtkMedReader.h
1 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __vtkMedReader_h_
21 #define __vtkMedReader_h_
22
23 #include "vtkMultiBlockDataSetAlgorithm.h"
24 #include "vtkMedSetGet.h"
25 #include <map>
26
27 class vtkMedFile;
28 class vtkMedDriver;
29 class vtkMedSelection;
30 class vtkMedFieldOverEntity;
31 class vtkMedFieldStep;
32 class vtkMedField;
33 class vtkMedMesh;
34 class vtkMedFamily;
35 class vtkMedLocalization;
36 class vtkMedEntityArray;
37 class vtkMedFamilyOnEntity;
38 class vtkMedFamilyOnEntityOnProfile;
39 class vtkMedProfile;
40 class vtkMedComputeStep;
41 class vtkMedGrid;
42 class vtkMedFieldOnProfile;
43 class vtkMedListOfFieldSteps;
44 class vtkMedEntity;
45
46 class vtkUnstructuredGrid;
47 class vtkUnsignedCharArray;
48 class vtkIdList;
49 class vtkDoubleArray;
50 class vtkFieldData;
51 class vtkInformationDataObjectKey;
52 class vtkMutableDirectedGraph;
53 class vtkDataSet;
54
55 class VTK_EXPORT vtkMedReader: public vtkMultiBlockDataSetAlgorithm
56 {
57 public:
58   static vtkMedReader* New();
59   vtkTypeRevisionMacro(vtkMedReader, vtkMultiBlockDataSetAlgorithm);
60   void PrintSelf(ostream& os, vtkIndent indent);
61
62   // Description:
63   // Set the file name to read from
64   virtual void SetFileName(const char*);
65   vtkGetStringMacro(FileName)
66
67   // Description:
68   // Is the given file a MED file?
69   virtual int CanReadFile(const char* fname);
70
71   // Description:
72   // Get the file extensions for this format.
73   // Returns a string with a space separated list of extensions in
74   // the format .extension
75   virtual const char*
76   GetFileExtensions()
77   {
78     return ".med .rmed";
79   }
80
81   // Description:
82   // Return a descriptive name for the file format that might be
83   // useful in a GUI.
84   virtual const char*
85   GetDescriptiveName()
86   {
87     return "MED file (Modele d'Echange de Donnees)";
88   }
89
90   // Description:
91   // use these methods to enable/disable point arrays
92   virtual int GetPointFieldArrayStatus(const char* name);
93   virtual void SetPointFieldArrayStatus(const char* name, int status);
94   virtual int GetNumberOfPointFieldArrays();
95   virtual const char* GetPointFieldArrayName(int);
96
97   // Description:
98   // use these methods to enable/disable cell arrays
99   virtual int GetCellFieldArrayStatus(const char* name);
100   virtual void SetCellFieldArrayStatus(const char* name, int status);
101   virtual int GetNumberOfCellFieldArrays();
102   virtual const char* GetCellFieldArrayName(int);
103
104   // Description:
105   // use these methods to enable/disable quadrature arrays
106   virtual int GetQuadratureFieldArrayStatus(const char* name);
107   virtual void SetQuadratureFieldArrayStatus(const char* name, int status);
108   virtual int GetNumberOfQuadratureFieldArrays();
109   virtual const char* GetQuadratureFieldArrayName(int);
110
111   // Description:
112   // use these methods to enable/disable quadrature arrays
113   virtual int GetElnoFieldArrayStatus(const char* name);
114   virtual void SetElnoFieldArrayStatus(const char* name, int status);
115   virtual int GetNumberOfElnoFieldArrays();
116   virtual const char* GetElnoFieldArrayName(int);
117
118   // Description:
119   // use this method to enable/disable cell types
120   // the key is encoded with the vtkMedUtilities::EntityKey method
121   // which returns a string
122   // CELL_TYPE/MED_ENTITE_MAILLAGE/MED_GEOMETRIE_ELEMENT
123   virtual void SetEntityStatus(const char* key, int flag);
124   virtual int GetEntityStatus(const vtkMedEntity&);
125
126   // Description:
127   // use this method to enable/disable a family support
128   // the key is formatted by the vtkMedUtilities::FamilyKey method which
129   // returns a string
130   // GROUP/MESH_NAME/OnPoint/FAMILY_NAME or MESH_NAME/OnCell/FAMILY_NAME
131   virtual void SetGroupStatus(const char* key, int flag);
132   virtual int GetGroupStatus(const char* key);
133
134   // Description:
135   // the animation mode modify the way the reader answers time requests from
136   // the pipeline.
137   // Default (0) : this is PhysicalTime if there are times, or Iterations
138   // if there are only iterations
139   // PhysicalTime (1) : the reader aggregates all physical times available
140   // in the file.
141   // for a given time t, the reader will return for each field the
142   // ComputeStep with the highest time inferior
143   // to t, and with the highest iteration.
144   // Iteration (2) : you need to also set the TimeIndexForIterations field.
145   // In this case, the reader will understand
146   // time requests has a request to iterate over iterations for the given time.
147   // Modes (3) : the reader will output the selected fields at all selected
148   // frequencies, and will output a fake TimeRange of -PI/+PI.
149   // Use the *FrequencyArray* interface to select them.
150   //BTX
151   enum eAnimationMode
152   {
153     Default=0, PhysicalTime=1, Iteration=2, Modes=3
154   };
155   //ETX
156   vtkSetMacro(AnimationMode, int);
157   vtkGetMacro(AnimationMode, int);
158
159   // Description:
160   // in med files, the ComputeSteps are defined by a
161   // pair <iteration, physicalTime>.
162   // the TimeIndexForIterations ivar is used only if the TimeMode is
163   // Iteration.
164   // it fixes the PhysicalTime index when iterating over iterations : only
165   // iterations with the corresponding physical time will be iterated over.
166   // The index given here is an index into the AvailableTimes array
167   // that is returned be the GetAvailableTimes Method.
168   vtkSetMacro(TimeIndexForIterations, double);
169   vtkGetMacro(TimeIndexForIterations, double);
170
171   // Description:
172   // use these methods to enable/disable a given frequency for modal analysis
173   virtual int GetFrequencyArrayStatus(const char* name);
174   virtual void SetFrequencyArrayStatus(const char* name, int status);
175   virtual int GetNumberOfFrequencyArrays();
176   virtual const char* GetFrequencyArrayName(int);
177
178   // Description:
179   // returns the available physical times. Use this to get the times when in
180   // iteration mode.
181   virtual vtkDoubleArray* GetAvailableTimes();
182
183   // Description:
184   // Build the graph used to pass information to the client on the supports
185   virtual void BuildSIL(vtkMutableDirectedGraph*);
186
187   // Description:
188   // Every time the SIL is updated a this will return a different value.
189   virtual int GetSILUpdateStamp();
190
191   // Description:
192   // reset the selection arrays without having to rebuild the SIL.
193   virtual void ClearSelections();
194
195   // Description:
196   // The CacheStrategy indicates to the reader if it
197   // should cache some of the arrays.
198   //BTX
199   enum eCacheStrategy
200   {
201     CacheNothing, CacheGeometry, CacheGeometryAndFields
202   };
203   //ETX
204   vtkSetMacro(CacheStrategy, int)
205   vtkGetMacro(CacheStrategy, int)
206
207   // Description :
208   // release arrays read from MED (point coordinates, profile ids, family ids)
209   void ClearMedSupports();
210
211   // Description :
212   // release arrays read from MED (fields)
213   void ClearMedFields();
214
215   // Description:
216   // If this flag is set, the reader will output a vector field for each
217   // field in the file that has 2 or more components by extracting the
218   // first 3 compoenents
219   vtkSetMacro(GenerateVectors, int);
220   vtkGetMacro(GenerateVectors, int);
221
222 protected:
223   vtkMedReader();
224   virtual ~vtkMedReader();
225
226   // Description:
227   // This is called by the superclass.
228   virtual int RequestDataObject(vtkInformation*, vtkInformationVector**,
229       vtkInformationVector*);
230
231   // Description:
232   // This is called by the superclass.
233   virtual int RequestInformation(vtkInformation*, vtkInformationVector**,
234       vtkInformationVector*);
235
236   // Description:
237   // This is called by the superclass.
238   virtual int RequestData(vtkInformation*, vtkInformationVector**,
239       vtkInformationVector*);
240
241   // Description:
242   // Gather all compute steps in the fields
243   virtual void GatherComputeSteps();
244
245   // Description:
246   // Give the animation steps to the pipeline
247   virtual void AdvertiseTime(vtkInformation*);
248
249   // Description:
250   // returns 1 if at least one the families of this mesh is selected,
251   // 0 otherwise.
252   virtual int IsMeshSelected(vtkMedMesh*);
253
254   // Description:
255   // returns if the field is selected.
256   virtual int IsFieldSelected(vtkMedField*);
257   virtual int IsPointFieldSelected(vtkMedField*);
258   virtual int IsCellFieldSelected(vtkMedField*);
259   virtual int IsQuadratureFieldSelected(vtkMedField*);
260   virtual int IsElnoFieldSelected(vtkMedField*);
261
262   virtual void AddQuadratureSchemeDefinition(vtkInformation*,
263       vtkMedLocalization*);
264
265   //BTX
266   enum
267   {
268     Initialize,
269     StartRequest,
270     AfterCreateMedSupports,
271     EndBuildVTKSupports,
272     EndRequest
273   };
274   //ETX
275   virtual void ClearCaches(int when);
276
277   virtual void CreateMedSupports();
278
279   virtual bool BuildVTKSupport(vtkMedFamilyOnEntityOnProfile*,
280                                int doBuildSupport);
281
282   virtual void MapFieldsOnSupport(vtkMedFamilyOnEntityOnProfile* foe,
283                                   int doMapField);
284
285   virtual void CreateVTKFieldOnSupport(vtkMedFieldOnProfile*,
286                                        vtkMedFamilyOnEntityOnProfile*,
287                                        int doCreateField);
288
289   virtual void MapFieldOnSupport(vtkMedFieldOnProfile*,
290                                  vtkMedFamilyOnEntityOnProfile*,
291                                  int doCreateField);
292
293   // Description:
294   // Necessary call for the initialization of the filters used for the MED
295   // library in their parallel reads
296   virtual void InitializeParallelRead();
297
298   // Description:
299   // This method is called after all info from all med files are read.
300   // it links information coming from different files :
301   // for instance, it creates the vtkMedFamilyOnEntityOnProfile instances
302   // to link mesh and field.
303   virtual void  LinkMedInfo();
304
305   virtual vtkMedProfile* GetProfile(const char*);
306
307   virtual vtkMedLocalization* GetLocalization(const char*);
308
309   virtual int GetLocalizationKey(vtkMedFieldOnProfile*);
310
311   virtual void InitializeQuadratureOffsets(vtkMedFieldOnProfile*,
312                                            vtkMedFamilyOnEntityOnProfile*);
313
314   virtual void SetVTKFieldOnSupport(vtkMedFieldOnProfile*,
315                                     vtkMedFamilyOnEntityOnProfile*);
316
317   // Description:
318   // returns the current grid to use for this mesh.
319   vtkMedGrid* FindGridStep(vtkMedMesh* mesh);
320
321   virtual void  GatherFieldSteps(vtkMedField*, vtkMedListOfFieldSteps&);
322
323   // Description:
324   // returns the index of the given frequency in the AvailableTimes array.
325   vtkIdType GetFrequencyIndex(double);
326
327   virtual void ChooseRealAnimationMode();
328
329   // Description :
330   // Load the connectivity of this entities, and also those of the
331   // sub-entities in the case of non nodal connectivity.
332   virtual void LoadConnectivity(vtkMedEntityArray*);
333
334   virtual void InitializeCellGlobalIds();
335
336   // Description :
337   // returns 1 if any point/cell family of this mesh is selected.
338   int HasMeshAnyCellSelectedFamily(vtkMedMesh*);
339   int HasMeshAnyPointSelectedFamily(vtkMedMesh*);
340
341   // Description:
342   // use this method to enable/disable a family support
343   // the key is formatted by the vtkMedUtilities::FamilyKey method which
344   // returns a string
345   // FAMILY/MESH_NAME/OnPoint/FAMILY_NAME or MESH_NAME/OnCell/FAMILY_NAME
346   virtual void SetFamilyStatus(const char* key, int flag);
347   virtual int GetFamilyStatus(vtkMedMesh*, vtkMedFamily*);
348
349   // Description:
350   // This is a helper function that is called when requesting a family status
351   // if a group status has been set after the last family status update.
352   virtual void SelectFamiliesFromGroups();
353
354   // Description:
355   // Instanciate a new vtkDataSet and initialize it to the points
356   // of this support.
357   vtkDataSet* CreateUnstructuredGridForPointSupport(
358       vtkMedFamilyOnEntityOnProfile* foep);
359
360   // Field selections
361   vtkMedSelection* PointFields;
362   vtkMedSelection* CellFields;
363   vtkMedSelection* QuadratureFields;
364   vtkMedSelection* ElnoFields;
365
366   // Support selection
367   vtkMedSelection* Entities;
368   vtkMedSelection* Groups;
369
370   // name of the file to read from
371   char* FileName;
372
373   // time management
374   int AnimationMode;
375   double TimeIndexForIterations;
376   vtkDoubleArray* AvailableTimes;
377   double TimePrecision;
378   vtkMedSelection* Frequencies;
379
380   int CacheStrategy;
381   int GenerateVectors;
382
383   //BTX
384   class vtkMedReaderInternal;
385   vtkMedReaderInternal* Internal;
386   //ETX
387
388 private:
389   vtkMedReader(const vtkMedReader&); // Not implemented.
390   void operator=(const vtkMedReader&); // Not implemented.
391 };
392
393 #endif //__vtkMedReader_h_