1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: SMDS_Downward.hxx
21 // Created: Jun 3, 2010
24 #ifndef SMDS_DOWNWARD_HXX_
25 #define SMDS_DOWNWARD_HXX_
27 #include "SMDS_UnstructuredGrid.hxx"
34 int nodeIds[8]; //!< max number of nodes in a face or edge: quad quad = 8
36 unsigned char vtkType;
37 } ElemByNodesType; // TODO resize for polyhedrons
41 ElemByNodesType elems[6]; //!< max number of faces in a volume or edges in a face : hexahedron = 6
43 } ListElemByNodesType; // TODO resize for polyhedrons
45 class SMDS_EXPORT DownIdType
48 DownIdType(int a, unsigned char b) :
49 cellId(a), cellType(b)
53 unsigned char cellType;
58 bool operator ()(const DownIdType e1, const DownIdType e2) const
60 if (e1.cellId == e2.cellId)
61 return (e1.cellType < e2.cellType);
63 return (e1.cellId < e2.cellId);
67 class SMDS_EXPORT SMDS_Downward
69 friend class SMDS_UnstructuredGrid;
70 friend class SMDS_Down2D;
71 friend class SMDS_Down3D;
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)
84 return _vtkCellIds[cellId];
90 static int getCellDimension(unsigned char cellType);
92 SMDS_Downward(SMDS_UnstructuredGrid *grid, int nbDownCells);
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);
102 SMDS_UnstructuredGrid* _grid;
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
109 static std::vector<int> _cellDimension; //!< conversion table: type --> dimension
112 class SMDS_EXPORT SMDS_Down1D: public SMDS_Downward
114 friend class SMDS_UnstructuredGrid;
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); }
122 SMDS_Down1D(SMDS_UnstructuredGrid *grid, int nbDownCells);
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);
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
143 class SMDS_EXPORT SMDS_Down2D: public SMDS_Downward
145 friend class SMDS_UnstructuredGrid;
146 friend class SMDS_Down1D;
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);
153 SMDS_Down2D(SMDS_UnstructuredGrid *grid, int nbDownCells);
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);
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
174 class SMDS_EXPORT SMDS_Down3D: public SMDS_Downward
176 friend class SMDS_UnstructuredGrid;
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);
183 SMDS_Down3D(SMDS_UnstructuredGrid *grid, int nbDownCells);
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);
191 class SMDS_EXPORT SMDS_DownEdge: public SMDS_Down1D
193 friend class SMDS_UnstructuredGrid;
196 SMDS_DownEdge(SMDS_UnstructuredGrid *grid);
200 class SMDS_EXPORT SMDS_DownQuadEdge: public SMDS_Down1D
202 friend class SMDS_UnstructuredGrid;
205 SMDS_DownQuadEdge(SMDS_UnstructuredGrid *grid);
206 ~SMDS_DownQuadEdge();
209 class SMDS_EXPORT SMDS_DownTriangle: public SMDS_Down2D
211 friend class SMDS_UnstructuredGrid;
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
220 class SMDS_EXPORT SMDS_DownQuadTriangle: public SMDS_Down2D
222 friend class SMDS_UnstructuredGrid;
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
231 class SMDS_EXPORT SMDS_DownQuadrangle: public SMDS_Down2D
233 friend class SMDS_UnstructuredGrid;
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
242 class SMDS_EXPORT SMDS_DownQuadQuadrangle: public SMDS_Down2D
244 friend class SMDS_UnstructuredGrid;
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
253 //class SMDS_DownPolygon: public SMDS_Down2D
256 // SMDS_DownPolygon(SMDS_UnstructuredGrid *grid);
257 // ~SMDS_DownPolygon();
261 //class SMDS_DownQuadPolygon: public SMDS_Down2D
264 // SMDS_DownQuadPolygon(SMDS_UnstructuredGrid *grid);
265 // ~SMDS_DownQuadPolygon();
269 class SMDS_EXPORT SMDS_DownTetra: public SMDS_Down3D
271 friend class SMDS_UnstructuredGrid;
273 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
275 SMDS_DownTetra(SMDS_UnstructuredGrid *grid);
277 virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
278 virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
281 class SMDS_EXPORT SMDS_DownQuadTetra: public SMDS_Down3D
283 friend class SMDS_UnstructuredGrid;
285 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
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);
293 class SMDS_EXPORT SMDS_DownPyramid: public SMDS_Down3D
295 friend class SMDS_UnstructuredGrid;
297 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
299 SMDS_DownPyramid(SMDS_UnstructuredGrid *grid);
301 virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
302 virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
305 class SMDS_EXPORT SMDS_DownQuadPyramid: public SMDS_Down3D
307 friend class SMDS_UnstructuredGrid;
309 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
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);
317 class SMDS_EXPORT SMDS_DownPenta: public SMDS_Down3D
319 friend class SMDS_UnstructuredGrid;
321 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
323 SMDS_DownPenta(SMDS_UnstructuredGrid *grid);
325 virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
326 virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
329 class SMDS_EXPORT SMDS_DownQuadPenta: public SMDS_Down3D
331 friend class SMDS_UnstructuredGrid;
333 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
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);
341 class SMDS_EXPORT SMDS_DownHexa: public SMDS_Down3D
343 friend class SMDS_UnstructuredGrid;
345 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
347 SMDS_DownHexa(SMDS_UnstructuredGrid *grid);
349 virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
350 virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
353 class SMDS_EXPORT SMDS_DownQuadHexa: public SMDS_Down3D
355 friend class SMDS_UnstructuredGrid;
357 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
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);
365 //class SMDS_DownPolyhedra: public SMDS_Down3D
368 // SMDS_DownPolyhedra(SMDS_UnstructuredGrid *grid);
369 // ~SMDS_DownPolyhedra();
373 //class SMDS_DownQuadPolyhedra: public SMDS_Down3D
376 // SMDS_DownQuadPolyhedra(SMDS_UnstructuredGrid *grid);
377 // ~SMDS_DownQuadPolyhedra();
381 #endif /* SMDS_DOWNWARD_HXX_ */