Salome HOME
Update French translation file
[modules/smesh.git] / src / SMDS / SMDS_Mesh.hxx
index 61144a4d63a5b014c28b471020d35dd4ed00617f..9df39f25ad369c1a0075ff2d12a119af901b095b 100644 (file)
@@ -1,58 +1,85 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SMESH SMDS : implementaion of Salome mesh data structure
 //  File   : SMDS_Mesh.hxx
 //  Module : SMESH
-
+//
 #ifndef _SMDS_Mesh_HeaderFile
 #define _SMDS_Mesh_HeaderFile
 
 #include "SMESH_SMDS.hxx"
 
 #include "SMDS_MeshNode.hxx"
+#include "SMDS_MeshCell.hxx"
 #include "SMDS_Mesh0DElement.hxx"
 #include "SMDS_MeshEdge.hxx"
 #include "SMDS_MeshFace.hxx"
 #include "SMDS_MeshVolume.hxx"
+#include "SMDS_MeshNodeIDFactory.hxx"
 #include "SMDS_MeshElementIDFactory.hxx"
 #include "SMDS_MeshInfo.hxx"
 #include "SMDS_ElemIterator.hxx"
-#include <NCollection_Map.hxx>
+#include "SMDS_VolumeOfNodes.hxx"
+#include "SMDS_VtkEdge.hxx"
+#include "SMDS_VtkFace.hxx"
+#include "SMDS_VtkVolume.hxx"
+#include "ObjectPool.hxx"
+#include "SMDS_UnstructuredGrid.hxx"
 
 #include <boost/shared_ptr.hpp>
 #include <set>
 #include <list>
+#include <vector>
+#include <vtkSystemIncludes.h>
+#include <cassert>
+
+#include "Utils_SALOME_Exception.hxx"
+#define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified"));
 
 class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{
 public:
+  friend class SMDS_MeshIDFactory;
+  friend class SMDS_MeshNodeIDFactory;
+  friend class SMDS_MeshElementIDFactory;
+  friend class SMDS_MeshVolumeVtkNodes;
+  friend class SMDS_MeshNode;
 
   SMDS_Mesh();
+  
+  //! to retreive this SMDS_Mesh instance from its elements (index stored in SMDS_Elements)
+  static std::vector<SMDS_Mesh*> _meshList;
 
-  SMDS_NodeIteratorPtr nodesIterator() const;
-  SMDS_0DElementIteratorPtr elements0dIterator() const;
-  SMDS_EdgeIteratorPtr edgesIterator() const;
-  SMDS_FaceIteratorPtr facesIterator() const;
-  SMDS_VolumeIteratorPtr volumesIterator() const;
-  SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
+  //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
+  inline SMDS_UnstructuredGrid* getGrid() {return myGrid; }
+  inline int getMeshId() {return myMeshId; }
+
+  virtual SMDS_NodeIteratorPtr      nodesIterator     (bool idInceasingOrder=false) const;
+  virtual SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
+  virtual SMDS_EdgeIteratorPtr      edgesIterator     (bool idInceasingOrder=false) const;
+  virtual SMDS_FaceIteratorPtr      facesIterator     (bool idInceasingOrder=false) const;
+  virtual SMDS_VolumeIteratorPtr    volumesIterator   (bool idInceasingOrder=false) const;
+
+  virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
 
   SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const;
 
@@ -419,6 +446,11 @@ public:
                            (std::vector<const SMDS_MeshNode*> nodes,
                             std::vector<int>                  quantities);
 
+  virtual SMDS_MeshVolume* AddVolumeFromVtkIds(const std::vector<vtkIdType>& vtkNodeIds);
+
+  virtual SMDS_MeshVolume* AddVolumeFromVtkIdsWithID(const std::vector<vtkIdType>& vtkNodeIds,
+                                                     const int ID);
+
   virtual void RemoveElement(const SMDS_MeshElement *        elem,
                              std::list<const SMDS_MeshElement *>& removedElems,
                              std::list<const SMDS_MeshElement *>& removedNodes,
@@ -450,8 +482,10 @@ public:
 
   virtual void Renumber (const bool isNodes, const int startID = 1, const int deltaID = 1);
   // Renumber all nodes or elements.
+  virtual void compactMesh();
 
   const SMDS_MeshNode *FindNode(int idnode) const;
+  const SMDS_MeshNode *FindNodeVtk(int idnode) const;
   const SMDS_Mesh0DElement* Find0DElement(int idnode) const;
   const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2) const;
   const SMDS_MeshEdge *FindEdge(int idnode1, int idnode2, int idnode3) const;
@@ -490,8 +524,11 @@ public:
                                        const SMDS_MeshNode *n7,
                                        const SMDS_MeshNode *n8);
 
-  const SMDS_MeshFace *FindFace(std::vector<int> nodes_ids) const;
-  static const SMDS_MeshFace* FindFace(std::vector<const SMDS_MeshNode *> nodes);
+  const SMDS_MeshFace *FindFace(const std::vector<int>& nodes_ids) const;
+  static const SMDS_MeshFace* FindFace(const std::vector<const SMDS_MeshNode *>& nodes);
+  static const SMDS_MeshElement* FindElement(const std::vector<const SMDS_MeshNode *>& nodes,
+                                             const SMDSAbs_ElementType                 type=SMDSAbs_All,
+                                             const bool                                noMedium=true);
 
   /*!
    * \brief Raise an exception if free memory (ram+swap) too low
@@ -507,21 +544,22 @@ public:
 
   const SMDS_MeshInfo& GetMeshInfo() const { return myInfo; }
 
-  int NbNodes() const;
-  int Nb0DElements() const;
-  int NbEdges() const;
-  int NbFaces() const;
-  int NbVolumes() const;
-  int NbSubMesh() const;
+  virtual int NbNodes() const;
+  virtual int Nb0DElements() const;
+  virtual int NbEdges() const;
+  virtual int NbFaces() const;
+  virtual int NbVolumes() const;
+  virtual int NbSubMesh() const;
+
   void DumpNodes() const;
   void Dump0DElements() const;
   void DumpEdges() const;
   void DumpFaces() const;
   void DumpVolumes() const;
   void DebugStats() const;
-  SMDS_Mesh *boundaryFaces();
-  SMDS_Mesh *boundaryEdges();
+
   virtual ~SMDS_Mesh();
+
   bool hasConstructionEdges();
   bool hasConstructionFaces();
   bool hasInverseElements();
@@ -537,23 +575,40 @@ public:
    */
   bool Contains (const SMDS_MeshElement* elem) const;
 
-  typedef NCollection_Map<SMDS_MeshNode *> SetOfNodes;
-  typedef NCollection_Map<SMDS_Mesh0DElement *> SetOf0DElements;
-  typedef NCollection_Map<SMDS_MeshEdge *> SetOfEdges;
-  typedef NCollection_Map<SMDS_MeshFace *> SetOfFaces;
-  typedef NCollection_Map<SMDS_MeshVolume *> SetOfVolumes;
+  typedef std::vector<SMDS_MeshNode *> SetOfNodes;
+  typedef std::vector<SMDS_MeshCell *> SetOfCells;
+
+  void updateNodeMinMax();
+  void updateBoundingBox();
+  double getMaxDim();
+  int fromVtkToSmds(int vtkid);
+
+  void incrementNodesCapacity(int nbNodes);
+  void incrementCellsCapacity(int nbCells);
+  void adjustStructure();
+  void dumpGrid(string ficdump="dumpGrid");
+  static int chunkSize;
+
+  //! low level modification: add, change or remove node or element
+  inline void setMyModified() { this->myModified = true; }
 
-private:
+  void Modified();
+  unsigned long GetMTime() const;
+  bool isCompacted();
+
+protected:
   SMDS_Mesh(SMDS_Mesh * parent);
 
   SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1,
                                  const SMDS_MeshNode * node2,
-                                 const SMDS_MeshNode * node3);
+                                 const SMDS_MeshNode * node3,
+                                 int ID);
   SMDS_MeshFace * createQuadrangle(const SMDS_MeshNode * node1,
                                    const SMDS_MeshNode * node2,
                                    const SMDS_MeshNode * node3,
-                                   const SMDS_MeshNode * node4);
-  SMDS_Mesh0DElement* Find0DElementOrCreate(const SMDS_MeshNode * n);
+                                   const SMDS_MeshNode * node4,
+                                   int ID);
+//  SMDS_Mesh0DElement* Find0DElementOrCreate(const SMDS_MeshNode * n);
   SMDS_MeshEdge* FindEdgeOrCreate(const SMDS_MeshNode * n1,
                                   const SMDS_MeshNode * n2);
   SMDS_MeshFace* FindFaceOrCreate(const SMDS_MeshNode *n1,
@@ -570,22 +625,77 @@ private:
                             const SMDS_MeshElement * element,
                             std::set<const SMDS_MeshElement*>& nodes);
 
+  inline void adjustmyCellsCapacity(int ID)
+  {
+    assert(ID >= 0);
+    myElementIDFactory->adjustMaxId(ID);
+    if (ID >= myCells.size())
+      myCells.resize(ID+SMDS_Mesh::chunkSize,0);
+  }
+
+  inline void adjustBoundingBox(double x, double y, double z)
+  {
+    if (x > xmax) xmax = x;
+    else if (x < xmin) xmin = x;
+    if (y > ymax) ymax = y;
+    else if (y < ymin) ymin = y;
+    if (z > zmax) zmax = z;
+    else if (z < zmin) zmin = z;
+  }
+
   // Fields PRIVATE
 
+  //! index of this SMDS_mesh in the static vector<SMDS_Mesh*> _meshList
+  int myMeshId;
+
+  //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid
+  SMDS_UnstructuredGrid*      myGrid;
+
+  //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new
+  ObjectPool<SMDS_MeshNode>* myNodePool;
+
+  //! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new
+  ObjectPool<SMDS_VtkVolume>* myVolumePool;
+  ObjectPool<SMDS_VtkFace>* myFacePool;
+  ObjectPool<SMDS_VtkEdge>* myEdgePool;
+
+  //! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape
   SetOfNodes             myNodes;
-  SetOf0DElements        my0DElements;
-  SetOfEdges             myEdges;
-  SetOfFaces             myFaces;
-  SetOfVolumes           myVolumes;
+
+  //! SMDS_MeshCells refer to vtk cells (vtk id != index in myCells),store reference to this mesh, and subshape
+  SetOfCells             myCells;
+
+  //! for cells only: index = ID for SMDS users, value = ID in vtkUnstructuredGrid
+  //std::vector<int>       myCellIdSmdsToVtk;
+
+  //! for cells only: index = ID in vtkUnstructuredGrid, value = ID for SMDS users
+  std::vector<int>       myCellIdVtkToSmds;
+
   SMDS_Mesh *            myParent;
   std::list<SMDS_Mesh *> myChildren;
-  SMDS_MeshElementIDFactory *myNodeIDFactory;
+  SMDS_MeshNodeIDFactory *myNodeIDFactory;
   SMDS_MeshElementIDFactory *myElementIDFactory;
   SMDS_MeshInfo          myInfo;
 
+  //! use a counter to keep track of modifications
+  unsigned long myModifTime, myCompactTime;
+
+  int myNodeMin;
+  int myNodeMax;
+
   bool myHasConstructionEdges;
   bool myHasConstructionFaces;
   bool myHasInverseElements;
+
+  //! any add, remove or change of node or cell
+  bool myModified;
+
+  double xmin;
+  double xmax;
+  double ymin;
+  double ymax;
+  double zmin;
+  double zmax;
 };