]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_IDMapper.hxx
Salome HOME
Merge from V6_main 01/04/2013
[modules/visu.git] / src / CONVERTOR / VISU_IDMapper.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU CONVERTOR :
24 //  File   : VISU_Convertor.hxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #ifndef VISU_IDMapper_HeaderFile
29 #define VISU_IDMapper_HeaderFile
30
31 /*! 
32   \file VISU_IDMapper.hxx
33   \brief The file contains declarations for basic interfaces that defines mapping of mesh elements
34 */
35
36 #include "VISUConvertor.hxx"
37
38 #include "MED_SharedPtr.hxx"
39 #include "MED_Vector.hxx"
40 #include "VTKViewer.h"
41
42 #include <vtkType.h>
43
44 #include <string>
45 #include <map>
46
47 class vtkUnstructuredGrid;
48 class vtkPolyData;
49 class vtkDataSet;
50 class vtkCell;
51 class vtkAlgorithmOutput;
52
53 namespace VISU
54 {
55   using MED::SharedPtr;
56   using MED::TVector;
57
58
59   //---------------------------------------------------------------
60   class VISU_CONVERTOR_EXPORT TStructuredId
61   {
62     vtkIdType myData[3];
63
64   public:
65     TStructuredId();
66
67     vtkIdType&
68     operator [] ( size_t theId );
69
70     const vtkIdType&
71     operator [] ( size_t theId ) const;
72
73     bool
74     operator == ( const TStructuredId& theId ) const;
75   };
76
77   typedef std::map<vtkIdType, TStructuredId> TObj2StructuredId;
78   typedef MED::SharedPtr<TObj2StructuredId> PObj2StructuredId;
79   
80   struct TStructured;
81   typedef MED::SharedPtr<TStructured> PStructured;
82   
83   struct VISU_CONVERTOR_EXPORT TStructured
84   {
85     TStructured():
86       myIsStructured(false),
87       myIsPolarType(true)
88     {}
89
90     //! Copys all information which should be sinchronized between two instances
91     virtual
92     void
93     CopyStructure(PStructured theStructured);
94
95     bool
96     IsStructured() const;
97
98     /*!
99      * Get structure of grille
100      * see also MED::TGrilleInfo::GetGrilleStructure
101      * see also MED::TGrilleInfo::GetNbIndexes
102      */
103     TStructuredId
104     GetStructure();
105     
106     vtkIdType
107     GetStructureDim();
108     
109     /*!
110      * Gets i,j,k by object id
111      * return -1, if not found
112      */
113     TStructuredId
114     GetIndexesOfNode(vtkIdType theNodeId);
115
116     /*!
117      * Gets object id by i,j,k
118      * return -1, if not found
119      */
120     vtkIdType
121     GetObjectIDByIndexes(TStructuredId theVec);
122
123     bool myIsStructured; //!< To define mesh type (structured - true, non structured - false)
124     bool myIsPolarType; //!< To define structured mesh is polair
125
126     /*!provides grille structure for structured grid.
127      * Example: {3,4,5}, 3 nodes in X axe, 4 nodes in Y axe, ...
128      */
129     TStructuredId myGrilleStructure;
130     
131     TObj2StructuredId myObj2StructuredId;//!< map of object id to i,j,k ids of structured grid nodes    
132   };
133   
134   //---------------------------------------------------------------
135   //! Defines a basic class for intemediate data structures
136   struct VISU_CONVERTOR_EXPORT TBaseStructure: virtual TStructured
137   {
138     //! Just to provide possibility of dynamic navigation through the class hierarchy
139     virtual ~TBaseStructure()
140     {}
141
142     std::string myEntry; //!< To simplify publication of the object tree
143   };
144   typedef MED::SharedPtr<TBaseStructure> PBaseStructure;
145
146   //---------------------------------------------------------------
147   //! Defines a basic abstract interface for VTK to object ID's and backward mapping
148   /*!
149     Where object ID means ID which attached to corresponding MED entity.
150     For example, each MED node can have its own ID as well as any other mesh cell
151   */
152   struct VISU_CONVERTOR_EXPORT TIDMapper: virtual TBaseStructure
153   {
154     //! Get node object ID for corresponding VTK ID
155     virtual 
156     vtkIdType 
157     GetNodeObjID(vtkIdType theID) const;
158
159     //! Get node VTK ID for corresponding object ID
160     virtual 
161     vtkIdType 
162     GetNodeVTKID(vtkIdType theID) const;
163
164     //! Get coordinates of node for corresponding object ID
165     virtual
166     double* 
167     GetNodeCoord(vtkIdType theObjID);
168
169     //! Get cell object ID for corresponding VTK ID
170     virtual 
171     vtkIdType 
172     GetElemObjID(vtkIdType theID) const;
173
174     //! Get cell VTK ID for corresponding object ID
175     virtual 
176     vtkIdType 
177     GetElemVTKID(vtkIdType theID) const;
178
179     //! Get VTK representation of mesh cell for corresponding object ID
180     virtual
181     vtkCell* 
182     GetElemCell(vtkIdType theObjID);
183
184     //! Get VTK representation of mesh for corresponding MED entity
185     virtual
186     vtkDataSet*
187     GetOutput() = 0;
188
189     //! Gets memory size used by the instance (bytes).
190     virtual
191     unsigned long int
192     GetMemorySize() = 0;
193   };
194   typedef MED::SharedPtr<TIDMapper> PIDMapper;
195   
196
197   //---------------------------------------------------------------
198   struct VISU_CONVERTOR_EXPORT TUnstructuredGridIDMapper: virtual TIDMapper
199   {
200     //! Get VTK representation of mesh for corresponding MED entity
201     virtual
202     vtkUnstructuredGrid*
203     GetUnstructuredGridOutput() = 0;
204
205     //! Reimplement the TIDMapper::GetOutput
206     virtual
207     vtkDataSet*
208     GetOutput();
209
210     //! Get VTK representation of mesh for corresponding MED entity as algorithm output
211     virtual
212     vtkAlgorithmOutput*
213     GetOutputPort() = 0;
214   };
215   typedef MED::SharedPtr<TUnstructuredGridIDMapper> PUnstructuredGridIDMapper;
216   
217
218   //---------------------------------------------------------------
219   //! Defines an abstract interface for VTK to object ID's and backward mapping
220   /*!
221     This class defines some additional methods that allow get names for corresponding mesh elements
222   */
223   struct TNamedIDMapper: virtual TUnstructuredGridIDMapper
224   {
225     //! Get name of mesh node for corresponding object ID
226     virtual
227     std::string 
228     GetNodeName(vtkIdType theObjID) const = 0;
229
230     //! Get name of mesh cell for corresponding object ID
231     virtual
232     std::string 
233     GetElemName(vtkIdType theObjID) const = 0;
234   };
235   typedef MED::SharedPtr<TNamedIDMapper> PNamedIDMapper;
236   
237
238   //---------------------------------------------------------------
239   struct TPolyDataIDMapper: virtual TIDMapper
240   {
241     //! Get VTK representation of mesh for corresponding MED entity
242     virtual
243     vtkPolyData*
244     GetPolyDataOutput() = 0;
245
246     //! Reimplement the TIDMapper::GetOutput
247     virtual
248     vtkDataSet*
249     GetOutput();
250
251     //! Get VTK representation of mesh for corresponding MED entity as algorithm output
252     virtual
253     vtkAlgorithmOutput*
254     GetOutputPort() = 0;
255   };
256   typedef MED::SharedPtr<TPolyDataIDMapper> PPolyDataIDMapper;
257   
258
259   //---------------------------------------------------------------
260   typedef vtkIdType TCellID; 
261   typedef vtkIdType TLocalPntID;
262   //! Defines a type that represent complex ID for defined Gauss Point
263   typedef std::pair<TCellID,TLocalPntID> TGaussPointID;
264
265   struct TGaussPtsIDMapper: virtual TPolyDataIDMapper
266   {
267     //! Gets complex Gauss Point ID by its VTK ID
268     virtual 
269     TGaussPointID 
270     GetObjID(vtkIdType theID) const = 0;
271
272     //! Gets VTK ID by its complex Gauss Point ID 
273     virtual 
274     vtkIdType 
275     GetVTKID(const TGaussPointID& theID) const = 0;
276
277     //! Gets parent TNamedIDMapper, which contains reference mesh cells
278     virtual 
279     TNamedIDMapper*
280     GetParent() const = 0;
281   };
282   typedef MED::SharedPtr<TGaussPtsIDMapper> PGaussPtsIDMapper;
283
284   //---------------------------------------------------------------
285 }
286
287 #endif