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