Salome HOME
b1fcd87b711d358ab18451eb96ebe6a427cfe033
[modules/visu.git] / src / CONVERTOR / VISU_PointCoords.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_PointCoords_HeaderFile
28 #define VISU_PointCoords_HeaderFile
29
30 /*! 
31   \file VISU_PointCoords.hxx
32   \brief The file contains declarations for basic interfaces that defines point coords of mesh elements
33 */
34
35 #include "VISUConvertor.hxx"
36 #include "VISU_Convertor.hxx"
37 #include "VISU_ConvertorDef_impl.hxx"
38
39 #include "MED_SliceArray.hxx"
40 #include "MED_Structures.hxx"
41
42 #include <vtkSmartPointer.h>
43
44 class vtkPointSet;
45
46 namespace VISU
47 {
48   //---------------------------------------------------------------
49   typedef vtkSmartPointer<vtkPointSet> PPointSet;
50
51   typedef MED::TFloat TCoord;
52   using MED::TCoordSlice;
53   using MED::TCCoordSlice;
54
55   //---------------------------------------------------------------
56   //! This class is responsible for keeping the mesh node coordinates
57   class VISU_CONVERTOR_EXPORT TCoordHolderBase: public virtual TBaseStructure
58   {
59   public:
60     //! To initilize the instance
61     void
62     Init(vtkIdType theNbPoints,
63          vtkIdType theDim);
64
65     vtkIdType
66     GetNbPoints() const;
67
68     vtkIdType
69     GetDim() const;
70
71     size_t
72     size() const;
73
74     //! Gets memory size used by the instance (bytes).
75     virtual
76     unsigned long int
77     GetMemorySize();
78
79     //! Get slice of coordinates for defined node (const version)
80     virtual
81     TCCoordSlice
82     GetCoordSlice(vtkIdType theNodeId) const = 0;
83
84     //! Get slice of coordinates for defined node
85     virtual
86     TCoordSlice 
87     GetCoordSlice(vtkIdType theNodeId) = 0;
88
89     virtual
90     unsigned char*
91     GetValuePtr() = 0;
92
93   protected:
94     vtkIdType myDim; //!< Dimension of the nodal coordinates
95     vtkIdType myNbPoints; //!< Number of nodes in corresponding mesh
96   };
97   typedef MED::SharedPtr<TCoordHolderBase> PCoordHolder;
98
99
100   //---------------------------------------------------------------
101   template<class TContainerType>
102   class TCoordHolder: public virtual TCoordHolderBase
103   {
104   public:
105     //! To initilize the class instance
106     void
107     Init(vtkIdType theNbPoints,
108          vtkIdType theDim,
109          const TContainerType& theCoord)
110     {
111       TCoordHolderBase::Init(theNbPoints, theDim);
112       myCoord = theCoord;
113     }
114
115     //! Gets pointer to the first element in the node coordinates array
116     virtual
117     TCoord*
118     GetPointer() = 0;
119
120     //! Gets pointer to the first element in the node coordinates array (const version)
121     virtual
122     const TCoord*
123     GetPointer() const = 0;
124
125     //! Get slice of coordinates for defined node (const version)
126     virtual
127     TCCoordSlice
128     GetCoordSlice(vtkIdType theNodeId) const
129     {
130       return TCCoordSlice(this->GetPointer(), 
131                           this->size(),
132                           std::slice(theNodeId * this->GetDim(), this->GetDim(), 1));
133     }
134
135     //! Get slice of coordinates for defined node
136     virtual
137     TCoordSlice 
138     GetCoordSlice(vtkIdType theNodeId)
139     {
140       return TCoordSlice(this->GetPointer(), 
141                          this->size(),
142                          std::slice(theNodeId * this->GetDim(), this->GetDim(), 1));
143     }
144
145     virtual
146     unsigned char*
147     GetValuePtr()
148     {
149       return (unsigned char*)this->GetPointer();
150     }
151
152   protected:
153     mutable TContainerType myCoord; //!< Keeps the node coordinates container itself
154   };
155
156
157   //---------------------------------------------------------------
158   //! This class is responsible for representation of mesh nodes
159   class VISU_CONVERTOR_EXPORT TPointCoords: public virtual TIsVTKDone
160   {
161   public:
162     TPointCoords();
163
164     //! To initilize the class
165     void
166     Init(const PCoordHolder& theCoord);
167
168     vtkIdType
169     GetNbPoints() const;
170
171     vtkIdType
172     GetDim() const;
173
174     virtual
175     vtkPointSet*
176     GetPointSet() const; //!< Gets corresponding VTK structure
177
178     //! Gets memory size used by the instance (bytes).
179     virtual
180     unsigned long int
181     GetMemorySize();
182
183     //! Get slice of coordinates for defined node (const version)
184     TCCoordSlice
185     GetCoordSlice(vtkIdType theNodeId) const;
186
187     //! Get slice of coordinates for defined node
188     TCoordSlice 
189     GetCoordSlice(vtkIdType theNodeId);
190
191     //! Get object number for node by its VTK one
192     virtual
193     vtkIdType
194     GetObjID(vtkIdType theID) const;
195
196     //! Get VTK number for node by its object one
197     virtual
198     vtkIdType
199     GetVTKID(vtkIdType theID) const;
200
201   protected:
202     //! An container for coordinates of the nodes
203     /*!
204       Usage of slices allow to minimize amount of memory to store the nodal coordinates and
205       provide unifirm way of conversation with this coordinates (independant from mesh dimension)
206     */
207     PCoordHolder myCoord; //!< A pointer to the coordinates container holder
208     PPointSet myPointSet; //!< VTK representation for the mesh nodes
209
210     void
211     SetVoidArray() const; //!< Passes the MED node coordinates data directly to VTK
212   };
213
214
215   //---------------------------------------------------------------
216   //! This class is responsible for representation of mesh nodes
217   /*!
218     In additition to its base functionlity it support mapping of VTK to object numeration and
219     keeps names for each of nodes.
220   */
221   class VISU_CONVERTOR_EXPORT TNamedPointCoords: public virtual TPointCoords
222   {
223   public:
224     //! To initilize the class (numeration of the nodes can be missed)
225     void
226     Init(const PCoordHolder& theCoord);
227     
228     //! Get name for defined dimension
229     std::string&
230     GetName(vtkIdType theDim);
231     
232     //! Get name for defined dimension (const version)
233     const std::string&
234     GetName(vtkIdType theDim) const;
235
236     //! Get name of node by its object number
237     virtual
238     std::string 
239     GetNodeName(vtkIdType theObjID) const;
240
241     virtual
242     vtkPointSet*
243     GetPointSet() const; //!< Gets initialized corresponding VTK structure
244
245     //! Gets memory size used by the instance (bytes).
246     virtual
247     unsigned long int
248     GetMemorySize();
249
250   protected:
251     typedef TVector<std::string> TPointsDim;
252     TPointsDim myPointsDim; //!< Keeps name of each dimension
253   };
254
255
256   //---------------------------------------------------------------
257 }
258
259 #endif