Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.hxx
1 //  VISU CONVERTOR :
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Convertor.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #ifndef VISU_Convertor_HeaderFile
28 #define VISU_Convertor_HeaderFile
29
30 /*! 
31   \file VISU_Convertor.hxx
32   \brief The file contains definitions for basic classes of the VISU CONVERTER package
33 */
34
35 #include "VISU_IDMapper.hxx"
36 #include "VISU_ConvertorDef.hxx"
37
38 #include "MED_Vector.hxx"
39
40 #include <map>
41 #include <set>
42 #include <utility>
43 #include <string>
44 #include <stdexcept>
45
46 namespace VISU
47 {
48   using MED::TVector;
49
50   //---------------------------------------------------------------
51   typedef std::string TName;
52
53   typedef TVector<TName> TNames;
54
55   //---------------------------------------------------------------
56   //! Define a basic class for all MED entites which can be identified by its number
57   struct TIntId: virtual TBaseStructure
58   {
59     vtkIdType myId;
60
61     TIntId(): myId(0)
62     {}
63   };
64
65
66   //---------------------------------------------------------------
67   typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
68   typedef std::map<TName,PGroup> TGroupMap;
69
70   //! Define a basic class which corresponds to MED MESH entity
71   /*!
72     This class in its turn contains map of TMeshOnEntity and TGroup substructures,
73     also it keeps name and dimention of corresponding MED MESH entity.
74   */
75   struct TMesh: virtual TBaseStructure
76   {
77     TMeshOnEntityMap myMeshOnEntityMap; //!< Contains corresponding meshes for MED ENTITIES
78     TGroupMap myGroupMap; //!< Contains map of bounded MED GROUPS
79     TName myName; //! Name of the corresponding MED MESH
80     int myDim; //! Dimension of the corresponding MED MESH
81
82     std::string myGroupsEntry; //!< To simplify publication of the groups in a data tree
83     std::string myFieldsEntry; //!< To simplify publication of the fiels in a data tree
84
85     TMesh(): myDim(0)
86     {}
87   };
88   typedef std::map<std::string,PMesh> TMeshMap;
89
90
91   //---------------------------------------------------------------
92   //! Define a basic class which corresponds to MED PROFILE entity
93   struct TSubProfile: virtual TBaseStructure
94   {};
95
96
97   //---------------------------------------------------------------
98   //! Define a containerfor MED PROFILE entities which belongs to the same MED ENTITY
99   struct TProfile: virtual TNamedIDMapper
100   {};
101
102
103   //---------------------------------------------------------------
104   bool
105   operator<(const PSubProfile& theLeft, const PSubProfile& theRight);
106
107   typedef std::set<PSubProfile> TProfileKey;
108   typedef std::map<TProfileKey,PProfile> TProfileMap;
109
110
111   //---------------------------------------------------------------
112   //! Define a basic class for MED GAUSS entity
113   struct TGauss: virtual TBaseStructure
114   {};
115
116
117   //---------------------------------------------------------------
118   //! Define a container for mesh generated from MED GAUSS and corresponding MED PROFILE
119   struct TGaussSubMesh: virtual TBaseStructure
120   {
121     PSubProfile mySubProfile; //!< Keeps reference on what submesh the Gauss Points are located
122   };
123
124   
125   //---------------------------------------------------------------
126   //! Define a container for all TGaussSubMesh that belongs to the same MED ENTITY
127   struct TGaussMesh: virtual TGaussPtsIDMapper
128   {};
129
130
131   //---------------------------------------------------------------
132   bool
133   operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight);
134
135   typedef std::set<PGaussSubMesh> TGaussKey;
136   typedef std::map<TGaussKey,PGaussMesh> TGaussMeshMap;
137
138
139   //---------------------------------------------------------------
140
141   typedef std::map<TName,PFamily> TFamilyMap;
142   typedef std::map<TName,PField> TFieldMap;
143
144   //! Define a basic class which corresponds to MED ENTITY
145   /*!
146     This class in its turn contains map of TGaussMesh and TProfile substructures,
147     also it keeps corresponding map of MED FAMILIES and FIELDS.
148   */
149   struct TMeshOnEntity: virtual TNamedIDMapper
150   {
151     TGaussMeshMap myGaussMeshMap; //!< Contains map of Gauss mesh which exist on it
152     TProfileMap myProfileMap; //!< Contains map of Profile mesh which exist on it
153
154     TFamilyMap myFamilyMap; //!< Contains map of MED FAMILIES which belongs to it
155     TFieldMap myFieldMap; //!< Contains map of MED FIELDS which belongs to it
156
157     TName myMeshName; //!< Contains name of the MED MESH where the it belongs to.
158     TEntity myEntity; //!< Referes to MED ENTITY where the it belongs to.
159   };
160
161
162   //---------------------------------------------------------------
163   //! Define a basic class for MED FAMILY entity
164   struct TFamily: virtual TIntId,
165                   virtual TIDMapper
166   {
167     TEntity myEntity; //!< Referes to MED ENTITY where the TFamily belongs to.
168     TName myName; //!< Contains name of the corresponding MED FAMILY
169   };
170
171
172   //---------------------------------------------------------------
173   typedef std::set<PFamily> TFamilySet;
174
175   //! Define a basic class for MED GROUP entity
176   struct TGroup: virtual TIDMapper
177   {
178     TFamilySet myFamilySet;
179   };
180
181
182   //---------------------------------------------------------------
183   typedef std::map<vtkIdType,PValForTime> TValField;
184   typedef std::pair<vtkFloatingPointType,vtkFloatingPointType> TMinMax;
185
186   //! Define a basic class for MED FIELD entity
187   struct TField: virtual TIntId
188   {
189     TEntity myEntity; //!< Referes to MED ENTITY where it belongs to.
190     TName myName; //!< Contains name of the corresponding MED FIELD
191     TName myMeshName; //!< Contains name of the MED MESH where it belongs to.
192     TValField myValField; //!< Contains sequence of values for corresponding MED TIMESTAMPS
193     TNames myCompNames; //!< Contains names of components of the MED FIELD
194     TNames myUnitNames; //!< Contains names of units of the MED FIELD
195     vtkIdType myNbComp; //!< Keeps number of components for the MED FIELD
196
197     //! Calculate min/max values for each of the MED FIELD components among all its timestamps
198     /*!
199       Numeration of the components starts from 1.
200       Zero component contains min/max value for modulus of corresponding vector
201     */
202     virtual
203     TMinMax 
204     GetMinMax(vtkIdType theCompID) = 0;
205     
206     bool myIsMinMaxInitilized; //!< Is the min / max values are calculated
207
208     TField(): 
209       myNbComp(0),
210       myIsMinMaxInitilized(false)
211     {}
212   };
213  
214
215   //---------------------------------------------------------------
216   typedef std::pair<double,std::string> TTime;
217
218   //! Define a basic class for MED TIMESTAMP entity
219   struct TValForTime: virtual TIntId
220   {
221     TEntity myEntity; //!< Referes to MED ENTITY where it belongs to.
222     TName myMeshName; //!< Contains name of the MED MESH where it belongs to.
223     TName myFieldName; //!< Contains name of the MED FIELD where it belongs to.
224     TTime myTime;
225
226     PProfile myProfile; //!< Contains corresponding MED PROFILE where the MED TIEMSTMAP attached to
227     PGaussMesh myGaussMesh;
228   };
229
230
231   //---------------------------------------------------------------
232   //! The utility function allows to write vtkUnstructuredGrid to a file with defined name
233   void 
234   WriteToFile(vtkUnstructuredGrid* theDataSet, 
235               const std::string& theFileName);
236 };
237
238
239 //---------------------------------------------------------------
240 //! This class defines interface to read VTK interpretation of MED entities
241 /*!
242   It is the main class of the VISU CONVERTER package.
243   Following MED entities can be retrived from any MED file:
244   - mesh from corresponding MED ENTITIES;
245   - MED TIMESTAMPS;
246   - MED FAMILIES;
247   - MED GROUPS.
248   The class produce its work in two main steps:
249   1. Perfrom parsing of MED file to get known what MED entities are pressent in it
250   2. Get VTK representation for any existing MED entity
251   Also, it can perform some additional work to calculate expected amount of memory to build defined VTK representation
252   
253 */
254 class VISU_Convertor
255 {
256 protected:
257   std::string myName;
258   VISU::TMeshMap myMeshMap;
259   int myIsDone;
260
261 public:
262   virtual 
263   ~VISU_Convertor()
264   {};
265   
266   //! Get brief name of the corresponding source MED file
267   virtual
268   const std::string& 
269   GetName(){ return myName;}
270
271   //! Let known whether the source MED file parsed or not
272   virtual
273   int
274   IsDone() const { return myIsDone; }
275
276   //! Defines what subtype of vtkDataSet is used for MED to VTK mapping
277   typedef VISU::TVTKOutput TOutput;
278
279   //! This method perform first parsing of MED file to get known what MED entities are pressent in it
280   virtual
281   VISU_Convertor* 
282   Build() = 0;
283
284   //! This method perform first parsing of MED file to get known what MED mesh entities are pressent in it
285   virtual
286   VISU_Convertor* 
287   BuildEntities() = 0;
288
289   //! This method perform first parsing of MED file to get known what MED fields are pressent in it
290   virtual
291   VISU_Convertor* 
292   BuildFields() = 0;
293
294   //! This min /max calculation over existing MED fields
295   virtual
296   VISU_Convertor* 
297   BuildMinMax() = 0;
298
299   //! This method perform first parsing of MED file to get known what MED groups are pressent in it
300   virtual
301   VISU_Convertor* 
302   BuildGroups() = 0;
303
304   //! This method allow to get known what MED entities are present is the MED file
305   virtual
306   const VISU::TMeshMap& 
307   GetMeshMap();
308
309   //! Get amount of memory to build VTK representations for all existing MED entities
310   virtual
311   vtkFloatingPointType
312   GetSize() = 0;
313
314   //! Get mesh for corresponding MED ENTITY
315   virtual
316   VISU::PNamedIDMapper 
317   GetMeshOnEntity(const std::string& theMeshName, 
318                   const VISU::TEntity& theEntity) = 0;
319   
320   //! Get amount of memory to build mesh for corresponding MED ENTITY
321   virtual
322   vtkFloatingPointType
323   GetMeshOnEntitySize(const std::string& theMeshName, 
324                       const VISU::TEntity& theEntity) = 0;
325   
326   //! Get mesh for corresponding MED FAMILY
327   virtual 
328   VISU::PIDMapper 
329   GetFamilyOnEntity(const std::string& theMeshName, 
330                     const VISU::TEntity& theEntity,
331                     const std::string& theFamilyName) = 0;
332
333   //! Get amount of memory to build mesh for corresponding MED FAMILY
334   virtual 
335   vtkFloatingPointType 
336   GetFamilyOnEntitySize(const std::string& theMeshName, 
337                         const VISU::TEntity& theEntity,
338                         const std::string& theFamilyName) = 0;
339
340   //! Get mesh for corresponding MED GROUP
341   virtual
342   VISU::PIDMapper
343   GetMeshOnGroup(const std::string& theMeshName, 
344                  const std::string& theGroupName) = 0;
345   
346   //! Get amount of memory to build mesh for corresponding MED GROUP
347   virtual
348   vtkFloatingPointType
349   GetMeshOnGroupSize(const std::string& theMeshName, 
350                      const std::string& theGroupName) = 0;
351   
352   //! Get mesh with attached values for corresponding MED TIMESTAMP
353   virtual
354   VISU::PIDMapper 
355   GetTimeStampOnMesh(const std::string& theMeshName, 
356                      const VISU::TEntity& theEntity,
357                      const std::string& theFieldName,
358                      int theStampsNum) = 0;
359
360   //! Get Gauss Points mesh with attached values for corresponding MED TIMESTAMP
361   virtual
362   VISU::PGaussPtsIDMapper 
363   GetTimeStampOnGaussPts(const std::string& theMeshName, 
364                          const VISU::TEntity& theEntity,
365                          const std::string& theFieldName,
366                          int theStampsNum) = 0;
367    
368   //! Get amount of memory to build mesh for corresponding MED TIMESTAMP
369   virtual 
370   vtkFloatingPointType
371   GetTimeStampSize(const std::string& theMeshName, 
372                    const VISU::TEntity& theEntity,
373                    const std::string& theFieldName,
374                    int theStampsNum) = 0;
375     
376   //! Get amount of memory to build all MED TIMESTAMPS for corresponding MED FIELD
377   virtual 
378   vtkFloatingPointType
379   GetFieldOnMeshSize(const std::string& theMeshName, 
380                      const VISU::TEntity& theEntity,
381                      const std::string& theFieldName) = 0;
382   
383   //! Find MED FIELD container
384   virtual
385   const VISU::PField 
386   GetField(const std::string& theMeshName, 
387            VISU::TEntity theEntity, 
388            const std::string& theFieldName) = 0;
389   
390   //! Find MED TIMESTAMP container
391   virtual
392   const VISU::PValForTime 
393   GetTimeStamp(const std::string& theMeshName, 
394                const VISU::TEntity& theEntity,
395                const std::string& theFieldName,
396                int theStampsNum) = 0;
397     
398   //! Allow to generate pretty name for MED TIMESTAMP
399   static 
400   std::string 
401   GenerateName(const VISU::TTime& aTime);
402
403   static 
404   std::string 
405   GenerateName(const std::string& theName, unsigned int theTimeId);
406 };
407
408 extern "C"
409 {
410   //! Instatiate proper VISU_Convertor subclass
411   VISU_Convertor* 
412   CreateConvertor(const std::string& theFileName);
413 };
414
415
416 #endif