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