Back to index

salome-smesh  6.5.0
SMDS_Downward.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File: SMDS_Downward.hxx
00021 // Created: Jun 3, 2010
00022 // Author: prascle
00023 
00024 #ifndef SMDS_DOWNWARD_HXX_
00025 #define SMDS_DOWNWARD_HXX_
00026 
00027 #include "SMDS_UnstructuredGrid.hxx"
00028 
00029 #include <vector>
00030 #include <set>
00031 
00032 typedef struct
00033 {
00034   int nodeIds[8]; 
00035   int nbNodes;
00036   unsigned char vtkType;
00037 } ElemByNodesType; // TODO resize for polyhedrons
00038 
00039 typedef struct
00040 {
00041   ElemByNodesType elems[6]; 
00042   int nbElems;
00043 } ListElemByNodesType; // TODO resize for polyhedrons
00044 
00045 class DownIdType
00046 {
00047 public:
00048   DownIdType(int a, unsigned char b) :
00049     cellId(a), cellType(b)
00050   {
00051   }
00052   int cellId;
00053   unsigned char cellType;
00054 };
00055 
00056 struct DownIdCompare
00057 {
00058   bool operator ()(const DownIdType e1, const DownIdType e2) const
00059   {
00060     if (e1.cellId == e2.cellId)
00061       return (e1.cellType < e2.cellType);
00062     else
00063       return (e1.cellId < e2.cellId);
00064   }
00065 };
00066 
00067 class SMDS_Downward
00068 {
00069   friend class SMDS_UnstructuredGrid;
00070   friend class SMDS_Down2D;
00071   friend class SMDS_Down3D;
00072 public:
00073   virtual int getNumberOfDownCells(int cellId);
00074   virtual const int* getDownCells(int cellId);
00075   virtual const unsigned char* getDownTypes(int cellId);
00076   virtual int getNumberOfUpCells(int cellId) = 0;
00077   virtual const int* getUpCells(int cellId) = 0;
00078   virtual const unsigned char* getUpTypes(int cellId) = 0;
00079   virtual void getNodeIds(int cellId, std::set<int>& nodeSet) = 0;
00080   virtual int getNodes(int cellId, int* nodevec) {return 0; }
00081   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes) {};
00082   int getVtkCellId(int cellId)
00083   {
00084     return _vtkCellIds[cellId];
00085   }
00086   int getMaxId()
00087   {
00088     return _maxId;
00089   }
00090   static int getCellDimension(unsigned char cellType);
00091 protected:
00092   SMDS_Downward(SMDS_UnstructuredGrid *grid, int nbDownCells);
00093   ~SMDS_Downward();
00094   int addCell(int vtkId = -1);
00095   virtual void initCell(int cellId);
00096   virtual void allocate(int nbElems) = 0;
00097   virtual void compactStorage() = 0;
00098   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); 
00099   virtual void addUpCell(int cellId, int upCellId, unsigned char aType); 
00100   virtual int getNodeSet(int cellId, int* nodeSet);
00101 
00102   SMDS_UnstructuredGrid* _grid;
00103   int _maxId;
00104   int _nbDownCells; 
00105   std::vector<int> _cellIds; 
00106   std::vector<int> _vtkCellIds; 
00107   std::vector<unsigned char> _cellTypes; 
00108 
00109   static std::vector<int> _cellDimension; 
00110 };
00111 
00112 class SMDS_Down1D: public SMDS_Downward
00113 {
00114   friend class SMDS_UnstructuredGrid;
00115 public:
00116   virtual int getNumberOfUpCells(int cellId);
00117   virtual const int* getUpCells(int cellId);
00118   virtual const unsigned char* getUpTypes(int cellId);
00119   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
00120   virtual int getNodes(int cellId, int* nodevec) { return getNodeSet(cellId, nodevec); }
00121 protected:
00122   SMDS_Down1D(SMDS_UnstructuredGrid *grid, int nbDownCells);
00123   ~SMDS_Down1D();
00124   virtual void initCell(int cellId);
00125   virtual void allocate(int nbElems);
00126   virtual void compactStorage();
00127   virtual void addUpCell(int cellId, int upCellId, unsigned char aType); 
00128   virtual int getNodeSet(int cellId, int* nodeSet);
00129   void setNodes(int cellId, int vtkId);
00130   void setNodes(int cellId, const int* nodeIds);
00131   int computeVtkCells(int cellId, std::vector<int>& vtkIds);
00132   int computeVtkCells(int* pts, std::vector<int>& vtkIds);
00133   int computeFaces(int cellId, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
00134   int computeFaces(int* pts, int* vtkIds, int nbcells, int* downFaces, unsigned char* downTypes);
00135 
00136   std::vector<std::vector<int> > _upCellIdsVector; 
00137   std::vector<std::vector<unsigned char> > _upCellTypesVector; 
00138   std::vector<int> _upCellIds; 
00139   std::vector<unsigned char> _upCellTypes; 
00140   std::vector<int> _upCellIndex; 
00141 };
00142 
00143 class SMDS_Down2D: public SMDS_Downward
00144 {
00145   friend class SMDS_UnstructuredGrid;
00146   friend class SMDS_Down1D;
00147 public:
00148   virtual int getNumberOfUpCells(int cellId);
00149   virtual const int* getUpCells(int cellId);
00150   virtual const unsigned char* getUpTypes(int cellId);
00151   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
00152 protected:
00153   SMDS_Down2D(SMDS_UnstructuredGrid *grid, int nbDownCells);
00154   ~SMDS_Down2D();
00155   virtual void allocate(int nbElems);
00156   virtual void compactStorage();
00157   virtual void addUpCell(int cellId, int upCellId, unsigned char aType);
00158   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
00159   virtual int getNodeSet(int cellId, int* nodeSet);
00160   int computeVolumeIds(int cellId, int* ids);
00161   int computeVolumeIds(ElemByNodesType& faceByNodes, int* ids);
00162   int computeVolumeIdsFromNodesFace(int* nodes, int nbNodes, int* ids);
00163   void setTempNodes(int cellId, int vtkId);
00164   void setTempNodes(int cellId, ElemByNodesType& faceByNodes);
00165   bool isInFace(int cellId, int *pts, int npts);
00166   int FindEdgeByNodes(int cellId, ElemByNodesType& edgeByNodes);
00167 
00168   std::vector<int> _upCellIds; 
00169   std::vector<unsigned char> _upCellTypes; 
00170   std::vector<int> _tempNodes; 
00171   int _nbNodes; 
00172 };
00173 
00174 class SMDS_Down3D: public SMDS_Downward
00175 {
00176   friend class SMDS_UnstructuredGrid;
00177 public:
00178   virtual int getNumberOfUpCells(int cellId);
00179   virtual const int* getUpCells(int cellId);
00180   virtual const unsigned char* getUpTypes(int cellId);
00181   virtual void getNodeIds(int cellId, std::set<int>& nodeSet);
00182 protected:
00183   SMDS_Down3D(SMDS_UnstructuredGrid *grid, int nbDownCells);
00184   ~SMDS_Down3D();
00185   virtual void allocate(int nbElems);
00186   virtual void compactStorage();
00187   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes) = 0;
00188   int FindFaceByNodes(int cellId, ElemByNodesType& faceByNodes);
00189 };
00190 
00191 class SMDS_DownEdge: public SMDS_Down1D
00192 {
00193   friend class SMDS_UnstructuredGrid;
00194 public:
00195 protected:
00196   SMDS_DownEdge(SMDS_UnstructuredGrid *grid);
00197   ~SMDS_DownEdge();
00198 };
00199 
00200 class SMDS_DownQuadEdge: public SMDS_Down1D
00201 {
00202   friend class SMDS_UnstructuredGrid;
00203 public:
00204 protected:
00205   SMDS_DownQuadEdge(SMDS_UnstructuredGrid *grid);
00206   ~SMDS_DownQuadEdge();
00207 };
00208 
00209 class SMDS_DownTriangle: public SMDS_Down2D
00210 {
00211   friend class SMDS_UnstructuredGrid;
00212 public:
00213 protected:
00214   SMDS_DownTriangle(SMDS_UnstructuredGrid *grid);
00215   ~SMDS_DownTriangle();
00216   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
00217   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); 
00218 };
00219 
00220 class SMDS_DownQuadTriangle: public SMDS_Down2D
00221 {
00222   friend class SMDS_UnstructuredGrid;
00223 public:
00224 protected:
00225   SMDS_DownQuadTriangle(SMDS_UnstructuredGrid *grid);
00226   ~SMDS_DownQuadTriangle();
00227   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
00228   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); 
00229 };
00230 
00231 class SMDS_DownQuadrangle: public SMDS_Down2D
00232 {
00233   friend class SMDS_UnstructuredGrid;
00234 public:
00235 protected:
00236   SMDS_DownQuadrangle(SMDS_UnstructuredGrid *grid);
00237   ~SMDS_DownQuadrangle();
00238   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
00239   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); 
00240 };
00241 
00242 class SMDS_DownQuadQuadrangle: public SMDS_Down2D
00243 {
00244   friend class SMDS_UnstructuredGrid;
00245 public:
00246 protected:
00247   SMDS_DownQuadQuadrangle(SMDS_UnstructuredGrid *grid);
00248   ~SMDS_DownQuadQuadrangle();
00249   virtual void computeEdgesWithNodes(int cellId, ListElemByNodesType& edgesWithNodes);
00250   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType); 
00251 };
00252 
00253 //class SMDS_DownPolygon: public SMDS_Down2D
00254 //{
00255 //public:
00256 //  SMDS_DownPolygon(SMDS_UnstructuredGrid *grid);
00257 //  ~SMDS_DownPolygon();
00258 //protected:
00259 //};
00260 
00261 //class SMDS_DownQuadPolygon: public SMDS_Down2D
00262 //{
00263 //public:
00264 //  SMDS_DownQuadPolygon(SMDS_UnstructuredGrid *grid);
00265 //  ~SMDS_DownQuadPolygon();
00266 //protected:
00267 //};
00268 
00269 class SMDS_DownTetra: public SMDS_Down3D
00270 {
00271   friend class SMDS_UnstructuredGrid;
00272 public:
00273   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00274 protected:
00275   SMDS_DownTetra(SMDS_UnstructuredGrid *grid);
00276   ~SMDS_DownTetra();
00277   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00278   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00279 };
00280 
00281 class SMDS_DownQuadTetra: public SMDS_Down3D
00282 {
00283   friend class SMDS_UnstructuredGrid;
00284 public:
00285   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00286 protected:
00287   SMDS_DownQuadTetra(SMDS_UnstructuredGrid *grid);
00288   ~SMDS_DownQuadTetra();
00289   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00290   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00291 };
00292 
00293 class SMDS_DownPyramid: public SMDS_Down3D
00294 {
00295   friend class SMDS_UnstructuredGrid;
00296 public:
00297   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00298 protected:
00299   SMDS_DownPyramid(SMDS_UnstructuredGrid *grid);
00300   ~SMDS_DownPyramid();
00301   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00302   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00303 };
00304 
00305 class SMDS_DownQuadPyramid: public SMDS_Down3D
00306 {
00307   friend class SMDS_UnstructuredGrid;
00308 public:
00309   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00310 protected:
00311   SMDS_DownQuadPyramid(SMDS_UnstructuredGrid *grid);
00312   ~SMDS_DownQuadPyramid();
00313   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00314   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00315 };
00316 
00317 class SMDS_DownPenta: public SMDS_Down3D
00318 {
00319   friend class SMDS_UnstructuredGrid;
00320 public:
00321   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00322 protected:
00323   SMDS_DownPenta(SMDS_UnstructuredGrid *grid);
00324   ~SMDS_DownPenta();
00325   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00326   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00327 };
00328 
00329 class SMDS_DownQuadPenta: public SMDS_Down3D
00330 {
00331   friend class SMDS_UnstructuredGrid;
00332 public:
00333   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00334 protected:
00335   SMDS_DownQuadPenta(SMDS_UnstructuredGrid *grid);
00336   ~SMDS_DownQuadPenta();
00337   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00338   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00339 };
00340 
00341 class SMDS_DownHexa: public SMDS_Down3D
00342 {
00343   friend class SMDS_UnstructuredGrid;
00344 public:
00345   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00346 protected:
00347   SMDS_DownHexa(SMDS_UnstructuredGrid *grid);
00348   ~SMDS_DownHexa();
00349   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00350   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00351 };
00352 
00353 class SMDS_DownQuadHexa: public SMDS_Down3D
00354 {
00355   friend class SMDS_UnstructuredGrid;
00356 public:
00357   virtual void getOrderedNodesOfFace(int cellId, std::vector<vtkIdType>& orderedNodes);
00358 protected:
00359   SMDS_DownQuadHexa(SMDS_UnstructuredGrid *grid);
00360   ~SMDS_DownQuadHexa();
00361   virtual void addDownCell(int cellId, int lowCellId, unsigned char aType);
00362   virtual void computeFacesWithNodes(int cellId, ListElemByNodesType& facesWithNodes);
00363 };
00364 
00365 //class SMDS_DownPolyhedra: public SMDS_Down3D
00366 //{
00367 //public:
00368 //  SMDS_DownPolyhedra(SMDS_UnstructuredGrid *grid);
00369 //  ~SMDS_DownPolyhedra();
00370 //protected:
00371 //};
00372 
00373 //class SMDS_DownQuadPolyhedra: public SMDS_Down3D
00374 //{
00375 //public:
00376 //  SMDS_DownQuadPolyhedra(SMDS_UnstructuredGrid *grid);
00377 //  ~SMDS_DownQuadPolyhedra();
00378 //protected:
00379 //};
00380 
00381 #endif /* SMDS_DOWNWARD_HXX_ */