Salome HOME
Copyright update: 2016
[modules/smesh.git] / src / SMDS / SMDS_Downward.hxx
1 // Copyright (C) 2010-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File: SMDS_Downward.hxx
21 // Created: Jun 3, 2010
22 // Author: prascle
23
24 #ifndef SMDS_DOWNWARD_HXX_
25 #define SMDS_DOWNWARD_HXX_
26
27 #include "SMDS_UnstructuredGrid.hxx"
28
29 #include <vector>
30 #include <set>
31
32 typedef struct
33 {
34   int nodeIds[8]; //!< max number of nodes in a face or edge: quad quad = 8
35   int nbNodes;
36   unsigned char vtkType;
37 } ElemByNodesType; // TODO resize for polyhedrons
38
39 typedef struct
40 {
41   ElemByNodesType elems[6]; //!< max number of faces in a volume or edges in a face : hexahedron = 6
42   int nbElems;
43 } ListElemByNodesType; // TODO resize for polyhedrons
44
45 class SMDS_EXPORT DownIdType
46 {
47 public:
48   DownIdType(int a, unsigned char b) :
49     cellId(a), cellType(b)
50   {
51   }
52   int cellId;
53   unsigned char cellType;
54 };
55
56 struct DownIdCompare
57 {
58   bool operator ()(const DownIdType e1, const DownIdType e2) const
59   {
60     if (e1.cellId == e2.cellId)
61       return (e1.cellType < e2.cellType);
62     else
63       return (e1.cellId < e2.cellId);
64   }
65 };
66
67 class SMDS_EXPORT SMDS_Downward
68 {
69   friend class SMDS_UnstructuredGrid;
70   friend class SMDS_Down2D;
71   friend class SMDS_Down3D;
72 public:
73   virtual int getNumberOfDownCells(int cellId);
74   virtual const int* getDownCells(int cellId);
75   virtual const unsigned char* getDownTypes(int cellId);
76   virtual int getNumberOfUpCells(int cellId) = 0;
77   virtual const int* getUpCells(int cellId) = 0;
78   virtual const unsigned char* getUpTypes(int cellId) = 0;
79   virtual void getNodeIds(int cellId, std::set<int>& nodeSet) = 0;
80   virtual int getNodes(int cellId, int* nodevec) {return 0; }
81   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes) {};
82   int getVtkCellId(int cellId)
83   {
84     return _vtkCellIds[cellId];
85   }
86   int getMaxId()
87   {
88     return _maxId;
89   }
90   static int getCellDimension(unsigned char cellType);
91 protected:
92   SMDS_Downward(SMDS_UnstructuredGrid *grid, int nbDownCells);
93   ~SMDS_Downward();
94   int addCell(int vtkId = -1);
95   virtual void initCell(int cellId);
96   virtual void allocate(int nbElems) = 0;
97   virtual void compactStorage() = 0;
98   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
99   virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
100   virtual int getNodeSet(int cellId, int* nodeSet);
101
102   SMDS_UnstructuredGrid* _grid;
103   int _maxId;
104   int _nbDownCells; //!< the same number for all cells of a derived class
105   std::vector<int> _cellIds; //!< growing size: all the down cell id's, size = _maxId * _nbDownCells
106   std::vector<int> _vtkCellIds; //!< growing size: size = _maxId, either vtkId or -1
107   std::vector<unsigned char> _cellTypes; //!< fixed size: the same vector for all cells of a derived class
108
109   static std::vector<int> _cellDimension; //!< conversion table: type --> dimension
110 };
111
112 class SMDS_EXPORT SMDS_Down1D: public SMDS_Downward
113 {
114   friend class SMDS_UnstructuredGrid;
115 public:
116   virtual int getNumberOfUpCells(int cellId);
117   virtual const int* getUpCells(int cellId);
118   virtual const unsigned char* getUpTypes(int cellId);
119   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
120   virtual int getNodes(int cellId, int* nodevec) { return getNodeSet(cellId, nodevec); }
121 protected:
122   SMDS_Down1D(SMDS_UnstructuredGrid *grid, int nbDownCells);
123   ~SMDS_Down1D();
124   virtual void initCell(int cellId);
125   virtual void allocate(int nbElems);
126   virtual void compactStorage();
127   virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
128   virtual int getNodeSet(int cellId, int* nodeSet);
129   void setNodes(int cellId, int vtkId);
130   void setNodes(int cellId, const int* nodeIds);
131   int computeVtkCells(int cellId, std::vector<int>& vtkIds);
132   int computeVtkCells(int* pts, std::vector<int>& vtkIds);
133   int computeFaces(int cellId, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
134   int computeFaces(int* pts, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
135
136   std::vector<std::vector<int> > _upCellIdsVector; //!< the number of faces sharing an edge is not known
137   std::vector<std::vector<unsigned char> > _upCellTypesVector; //!< the number of faces sharing an edge is not known
138   std::vector<int> _upCellIds; //!< compacted storage after connectivity calculation
139   std::vector<unsigned char> _upCellTypes; //!< compacted storage after connectivity calculation
140   std::vector<int> _upCellIndex; //!< compacted storage after connectivity calculation
141 };
142
143 class SMDS_EXPORT SMDS_Down2D: public SMDS_Downward
144 {
145   friend class SMDS_UnstructuredGrid;
146   friend class SMDS_Down1D;
147 public:
148   virtual int getNumberOfUpCells(int cellId);
149   virtual const int* getUpCells(int cellId);
150   virtual const unsigned char* getUpTypes(int cellId);
151   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
152 protected:
153   SMDS_Down2D(SMDS_UnstructuredGrid *grid, int nbDownCells);
154   ~SMDS_Down2D();
155   virtual void allocate(int nbElems);
156   virtual void compactStorage();
157   virtual void addUpCell(int cellId, int upCellId, unsigned char aType);
158   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
159   virtual int getNodeSet(int cellId, int* nodeSet);
160   int computeVolumeIds(int cellId, int* ids);
161   int computeVolumeIds(ElemByNodesType& faceByNodes, int* ids);
162   int computeVolumeIdsFromNodesFace(int* nodes, int nbNodes, int* ids);
163   void setTempNodes(int cellId, int vtkId);
164   void setTempNodes(int cellId, ElemByNodesType& faceByNodes);
165   bool isInFace(int cellId, int *pts, int npts);
166   int FindEdgeByNodes(int cellId, ElemByNodesType& edgeByNodes);
167
168   std::vector<int> _upCellIds; //!< 2 volumes max. per face
169   std::vector<unsigned char> _upCellTypes; //!< 2 volume types per face
170   std::vector<int> _tempNodes; //!< temporary storage of nodes, until downward connectivity completion
171   int _nbNodes; //!< number of nodes in a face
172 };
173
174 class SMDS_EXPORT SMDS_Down3D: public SMDS_Downward
175 {
176   friend class SMDS_UnstructuredGrid;
177 public:
178   virtual int getNumberOfUpCells(int cellId);
179   virtual const int* getUpCells(int cellId);
180   virtual const unsigned char* getUpTypes(int cellId);
181   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
182 protected:
183   SMDS_Down3D(SMDS_UnstructuredGrid *grid, int nbDownCells);
184   ~SMDS_Down3D();
185   virtual void allocate(int nbElems);
186   virtual void compactStorage();
187   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
188   int FindFaceByNodes(int cellId, ElemByNodesType& faceByNodes);
189 };
190
191 class SMDS_EXPORT SMDS_DownEdge: public SMDS_Down1D
192 {
193   friend class SMDS_UnstructuredGrid;
194 public:
195 protected:
196   SMDS_DownEdge(SMDS_UnstructuredGrid *grid);
197   ~SMDS_DownEdge();
198 };
199
200 class SMDS_EXPORT SMDS_DownQuadEdge: public SMDS_Down1D
201 {
202   friend class SMDS_UnstructuredGrid;
203 public:
204 protected:
205   SMDS_DownQuadEdge(SMDS_UnstructuredGrid *grid);
206   ~SMDS_DownQuadEdge();
207 };
208
209 class SMDS_EXPORT SMDS_DownTriangle: public SMDS_Down2D
210 {
211   friend class SMDS_UnstructuredGrid;
212 public:
213 protected:
214   SMDS_DownTriangle(SMDS_UnstructuredGrid *grid);
215   ~SMDS_DownTriangle();
216   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
217   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
218 };
219
220 class SMDS_EXPORT SMDS_DownQuadTriangle: public SMDS_Down2D
221 {
222   friend class SMDS_UnstructuredGrid;
223 public:
224 protected:
225   SMDS_DownQuadTriangle(SMDS_UnstructuredGrid *grid);
226   ~SMDS_DownQuadTriangle();
227   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
228   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
229 };
230
231 class SMDS_EXPORT SMDS_DownQuadrangle: public SMDS_Down2D
232 {
233   friend class SMDS_UnstructuredGrid;
234 public:
235 protected:
236   SMDS_DownQuadrangle(SMDS_UnstructuredGrid *grid);
237   ~SMDS_DownQuadrangle();
238   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
239   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
240 };
241
242 class SMDS_EXPORT SMDS_DownQuadQuadrangle: public SMDS_Down2D
243 {
244   friend class SMDS_UnstructuredGrid;
245 public:
246 protected:
247   SMDS_DownQuadQuadrangle(SMDS_UnstructuredGrid *grid);
248   ~SMDS_DownQuadQuadrangle();
249   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
250   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
251 };
252
253 //class SMDS_DownPolygon: public SMDS_Down2D
254 //{
255 //public:
256 //  SMDS_DownPolygon(SMDS_UnstructuredGrid *grid);
257 //  ~SMDS_DownPolygon();
258 //protected:
259 //};
260
261 //class SMDS_DownQuadPolygon: public SMDS_Down2D
262 //{
263 //public:
264 //  SMDS_DownQuadPolygon(SMDS_UnstructuredGrid *grid);
265 //  ~SMDS_DownQuadPolygon();
266 //protected:
267 //};
268
269 class SMDS_EXPORT SMDS_DownTetra: public SMDS_Down3D
270 {
271   friend class SMDS_UnstructuredGrid;
272 public:
273   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
274 protected:
275   SMDS_DownTetra(SMDS_UnstructuredGrid *grid);
276   ~SMDS_DownTetra();
277   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
278   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
279 };
280
281 class SMDS_EXPORT SMDS_DownQuadTetra: public SMDS_Down3D
282 {
283   friend class SMDS_UnstructuredGrid;
284 public:
285   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
286 protected:
287   SMDS_DownQuadTetra(SMDS_UnstructuredGrid *grid);
288   ~SMDS_DownQuadTetra();
289   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
290   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
291 };
292
293 class SMDS_EXPORT SMDS_DownPyramid: public SMDS_Down3D
294 {
295   friend class SMDS_UnstructuredGrid;
296 public:
297   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
298 protected:
299   SMDS_DownPyramid(SMDS_UnstructuredGrid *grid);
300   ~SMDS_DownPyramid();
301   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
302   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
303 };
304
305 class SMDS_EXPORT SMDS_DownQuadPyramid: public SMDS_Down3D
306 {
307   friend class SMDS_UnstructuredGrid;
308 public:
309   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
310 protected:
311   SMDS_DownQuadPyramid(SMDS_UnstructuredGrid *grid);
312   ~SMDS_DownQuadPyramid();
313   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
314   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
315 };
316
317 class SMDS_EXPORT SMDS_DownPenta: public SMDS_Down3D
318 {
319   friend class SMDS_UnstructuredGrid;
320 public:
321   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
322 protected:
323   SMDS_DownPenta(SMDS_UnstructuredGrid *grid);
324   ~SMDS_DownPenta();
325   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
326   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
327 };
328
329 class SMDS_EXPORT SMDS_DownQuadPenta: public SMDS_Down3D
330 {
331   friend class SMDS_UnstructuredGrid;
332 public:
333   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
334 protected:
335   SMDS_DownQuadPenta(SMDS_UnstructuredGrid *grid);
336   ~SMDS_DownQuadPenta();
337   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
338   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
339 };
340
341 class SMDS_EXPORT SMDS_DownHexa: public SMDS_Down3D
342 {
343   friend class SMDS_UnstructuredGrid;
344 public:
345   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
346 protected:
347   SMDS_DownHexa(SMDS_UnstructuredGrid *grid);
348   ~SMDS_DownHexa();
349   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
350   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
351 };
352
353 class SMDS_EXPORT SMDS_DownQuadHexa: public SMDS_Down3D
354 {
355   friend class SMDS_UnstructuredGrid;
356 public:
357   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
358 protected:
359   SMDS_DownQuadHexa(SMDS_UnstructuredGrid *grid);
360   ~SMDS_DownQuadHexa();
361   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
362   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
363 };
364
365 //class SMDS_DownPolyhedra: public SMDS_Down3D
366 //{
367 //public:
368 //  SMDS_DownPolyhedra(SMDS_UnstructuredGrid *grid);
369 //  ~SMDS_DownPolyhedra();
370 //protected:
371 //};
372
373 //class SMDS_DownQuadPolyhedra: public SMDS_Down3D
374 //{
375 //public:
376 //  SMDS_DownQuadPolyhedra(SMDS_UnstructuredGrid *grid);
377 //  ~SMDS_DownQuadPolyhedra();
378 //protected:
379 //};
380
381 #endif /* SMDS_DOWNWARD_HXX_ */