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