1 // Copyright (C) 2010-2011 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.
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
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);
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 int getVtkCellId(int cellId)
83 return _vtkCellIds[cellId];
89 static int getCellDimension(unsigned char cellType);
91 SMDS_Downward(SMDS_UnstructuredGrid *grid, int nbDownCells);
93 int addCell(int vtkId = -1);
94 virtual void initCell(int cellId);
95 virtual void allocate(int nbElems) = 0;
96 virtual void compactStorage() = 0;
97 virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); //!< Id's are downward connectivity id's
98 virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
99 virtual int getNodeSet(int cellId, int* nodeSet);
101 SMDS_UnstructuredGrid* _grid;
103 int _nbDownCells; //!< the same number for all cells of a derived class
104 std::vector<int> _cellIds; //!< growing size: all the down cell id's, size = _maxId * _nbDownCells
105 std::vector<int> _vtkCellIds; //!< growing size: size = _maxId, either vtkId or -1
106 std::vector<unsigned char> _cellTypes; //!< fixed size: the same vector for all cells of a derived class
108 static std::vector<int> _cellDimension; //!< conversion table: type --> dimension
111 class SMDS_Down1D: public SMDS_Downward
113 friend class SMDS_UnstructuredGrid;
115 virtual int getNumberOfUpCells(int cellId);
116 virtual const int* getUpCells(int cellId);
117 virtual const unsigned char* getUpTypes(int cellId);
118 virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
119 virtual int getNodes(int cellId, int* nodevec) { return getNodeSet(cellId, nodevec); }
121 SMDS_Down1D(SMDS_UnstructuredGrid *grid, int nbDownCells);
123 virtual void initCell(int cellId);
124 virtual void allocate(int nbElems);
125 virtual void compactStorage();
126 virtual void addUpCell(int cellId, int upCellId, unsigned char aType); //!< Id's are downward connectivity id's
127 virtual int getNodeSet(int cellId, int* nodeSet);
128 void setNodes(int cellId, int vtkId);
129 void setNodes(int cellId, const int* nodeIds);
130 int computeVtkCells(int cellId, std::vector<int>& vtkIds);
131 int computeVtkCells(int* pts, std::vector<int>& vtkIds);
132 int computeFaces(int cellId, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
133 int computeFaces(int* pts, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
135 std::vector<std::vector<int> > _upCellIdsVector; //!< the number of faces sharing an edge is not known
136 std::vector<std::vector<unsigned char> > _upCellTypesVector; //!< the number of faces sharing an edge is not known
137 std::vector<int> _upCellIds; //!< compacted storage after connectivity calculation
138 std::vector<unsigned char> _upCellTypes; //!< compacted storage after connectivity calculation
139 std::vector<int> _upCellIndex; //!< compacted storage after connectivity calculation
142 class SMDS_Down2D: public SMDS_Downward
144 friend class SMDS_UnstructuredGrid;
145 friend class SMDS_Down1D;
147 virtual int getNumberOfUpCells(int cellId);
148 virtual const int* getUpCells(int cellId);
149 virtual const unsigned char* getUpTypes(int cellId);
150 virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
152 SMDS_Down2D(SMDS_UnstructuredGrid *grid, int nbDownCells);
154 virtual void allocate(int nbElems);
155 virtual void compactStorage();
156 virtual void addUpCell(int cellId, int upCellId, unsigned char aType);
157 virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
158 virtual int getNodeSet(int cellId, int* nodeSet);
159 int computeVolumeIds(int cellId, int* ids);
160 int computeVolumeIds(ElemByNodesType& faceByNodes, int* ids);
161 int computeVolumeIdsFromNodesFace(int* nodes, int nbNodes, int* ids);
162 void setTempNodes(int cellId, int vtkId);
163 void setTempNodes(int cellId, ElemByNodesType& faceByNodes);
164 bool isInFace(int cellId, int *pts, int npts);
165 int FindEdgeByNodes(int cellId, ElemByNodesType& edgeByNodes);
167 std::vector<int> _upCellIds; //!< 2 volumes max. per face
168 std::vector<unsigned char> _upCellTypes; //!< 2 volume types per face
169 std::vector<int> _tempNodes; //!< temporary storage of nodes, until downward connectivity completion
170 int _nbNodes; //!< number of nodes in a face
173 class SMDS_Down3D: public SMDS_Downward
175 friend class SMDS_UnstructuredGrid;
177 virtual int getNumberOfUpCells(int cellId);
178 virtual const int* getUpCells(int cellId);
179 virtual const unsigned char* getUpTypes(int cellId);
180 virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
181 virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes) = 0;
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_DownEdge: public SMDS_Down1D
193 friend class SMDS_UnstructuredGrid;
196 SMDS_DownEdge(SMDS_UnstructuredGrid *grid);
200 class SMDS_DownQuadEdge: public SMDS_Down1D
202 friend class SMDS_UnstructuredGrid;
205 SMDS_DownQuadEdge(SMDS_UnstructuredGrid *grid);
206 ~SMDS_DownQuadEdge();
209 class 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_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_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_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_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_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_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_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_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_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_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_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_ */