From 256c68c3f97225b1fa805d3f30ea2f422c1d2856 Mon Sep 17 00:00:00 2001 From: prascle Date: Fri, 8 Jan 2010 15:53:25 +0000 Subject: [PATCH] PR: display hexahedron --- src/SMDS/Makefile.am | 6 ++ src/SMDS/Notes | 32 ++++++++ src/SMDS/SMDS_Mesh.cxx | 7 +- src/SMDS/SMDS_Mesh.hxx | 33 +++++++-- src/SMDS/SMDS_Mesh0DElement.hxx | 2 +- src/SMDS/SMDS_MeshCell.cxx | 19 +++++ src/SMDS/SMDS_MeshCell.hxx | 22 ++++++ src/SMDS/SMDS_MeshEdge.hxx | 2 +- src/SMDS/SMDS_MeshElement.cxx | 13 ---- src/SMDS/SMDS_MeshElement.hxx | 18 ----- src/SMDS/SMDS_MeshFace.hxx | 2 +- src/SMDS/SMDS_MeshVolume.hxx | 2 +- src/SMDS/SMDS_VolumeOfNodes.cxx | 117 ------------------------------ src/SMDS/SMDS_VolumeOfNodes.hxx | 32 -------- src/SMDS/SMDS_VtkCellIterator.cxx | 21 ++++++ src/SMDS/SMDS_VtkCellIterator.hxx | 24 ++++++ src/SMDS/SMDS_VtkVolume.cxx | 116 +++++++++++++++++++++++++++++ src/SMDS/SMDS_VtkVolume.hxx | 39 ++++++++++ 18 files changed, 312 insertions(+), 195 deletions(-) create mode 100644 src/SMDS/SMDS_MeshCell.cxx create mode 100644 src/SMDS/SMDS_MeshCell.hxx create mode 100644 src/SMDS/SMDS_VtkCellIterator.cxx create mode 100644 src/SMDS/SMDS_VtkCellIterator.hxx create mode 100644 src/SMDS/SMDS_VtkVolume.cxx create mode 100644 src/SMDS/SMDS_VtkVolume.hxx diff --git a/src/SMDS/Makefile.am b/src/SMDS/Makefile.am index 2e8347604..54234dab8 100644 --- a/src/SMDS/Makefile.am +++ b/src/SMDS/Makefile.am @@ -38,6 +38,7 @@ salomeinclude_HEADERS = \ SMDS_Mesh0DElement.hxx \ SMDS_MeshEdge.hxx \ SMDS_MeshElement.hxx \ + SMDS_MeshElement.cxx \ SMDS_MeshElementIDFactory.hxx \ SMDS_MeshFace.hxx \ SMDS_MeshGroup.hxx \ @@ -53,6 +54,8 @@ salomeinclude_HEADERS = \ SMDS_IteratorOfElements.hxx \ SMDS_VolumeOfFaces.hxx \ SMDS_VolumeOfNodes.hxx \ + SMDS_VtkVolume.hxx \ + SMDS_VtkCellIterator.hxx \ SMDS_PolyhedralVolumeOfNodes.hxx \ SMDS_FaceOfEdges.hxx \ SMDS_FaceOfNodes.hxx \ @@ -72,6 +75,7 @@ lib_LTLIBRARIES = libSMDS.la dist_libSMDS_la_SOURCES = \ SMDS_MeshObject.cxx \ SMDS_MeshElement.cxx \ + SMDS_MeshCell.cxx \ SMDS_Position.cxx \ SMDS_EdgePosition.cxx \ SMDS_FacePosition.cxx \ @@ -90,6 +94,8 @@ dist_libSMDS_la_SOURCES = \ SMDS_IteratorOfElements.cxx \ SMDS_VolumeOfFaces.cxx \ SMDS_VolumeOfNodes.cxx \ + SMDS_VtkVolume.cxx \ + SMDS_VtkCellIterator.cxx \ SMDS_PolyhedralVolumeOfNodes.cxx \ SMDS_FaceOfEdges.cxx \ SMDS_FaceOfNodes.cxx \ diff --git a/src/SMDS/Notes b/src/SMDS/Notes index c0bcbd15c..a9bc5a37e 100644 --- a/src/SMDS/Notes +++ b/src/SMDS/Notes @@ -60,6 +60,12 @@ verifier ID dans SMDS_Mesh::Find*OrCreate =================================================== occupation memoire cube 100*100*100 sans affichage +NOTES: +- sur Debian Sarge 64 bits, les mesures malloc_stat() semblent coherentes + avec une mesure externe globale(recherche du passage en swap du process). +- sur Ubuntu 9.10 64 bits, les mesures malloc_stat() donnent des resultats bizarres (surestimation ?), + mais la mesure avec l'outil KDE de surveillance systeme est OK avec la recherche du swap. + Reference : V513 Debian Sarge 64 bits: --> 463 - 33 = 430 Mo ------------------------------------- @@ -175,3 +181,29 @@ system bytes = 429334528 in use bytes = 426424576 : 426M max mmap regions = 59 max mmap bytes = 184692736 + +remplacement std::set par std::vector dans SMESHDS_SubMesh --> 347 - 35 = 312M +---------------------------------------------------------- +sizeof(SMDS_MeshElement) 24 +sizeof(SMDS_MeshNode) 32 +sizeof(SMDS_MeshCell) 24 +sizeof(SMDS_VolumeVtkNodes) 24 +sizeof(SMDS_Position) 16 +sizeof(SMDS_SpacePosition) 16 + +Total (incl. mmap): +system bytes = 45404160 +in use bytes = 35132160 --> 35M +max mmap regions = 49 +max mmap bytes = 17723392 +---- +Total (incl. mmap): +system bytes = 349831168 +in use bytes = 346885424 --> 347M +max mmap regions = 73 +max mmap bytes = 204148736 + +Ce resultat est coherent avec une recherche de swap sur une machine a 8Go de memoire: +Cube a 270**3 mailles (~20M mailles) --> 6.2 Go (idem Debian Sarge et Ubuntu 9.10, 64 bits) +Le meme avec V5.1.3 --> 14 Go (swap) + diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index d147b6672..b61334849 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -123,14 +123,14 @@ SMDS_Mesh::SMDS_Mesh() MESSAGE("sizeof(SMDS_MeshElement) " << sizeof(SMDS_MeshElement) ); MESSAGE("sizeof(SMDS_MeshNode) " << sizeof(SMDS_MeshNode) ); MESSAGE("sizeof(SMDS_MeshCell) " << sizeof(SMDS_MeshCell) ); - MESSAGE("sizeof(SMDS_VolumeVtkNodes) " << sizeof(SMDS_VolumeVtkNodes) ); + MESSAGE("sizeof(SMDS_VtkVolume) " << sizeof(SMDS_VtkVolume) ); MESSAGE("sizeof(SMDS_Position) " << sizeof(SMDS_Position) ); MESSAGE("sizeof(SMDS_SpacePosition) " << sizeof(SMDS_SpacePosition) ); myNodeIDFactory->SetMesh(this); myElementIDFactory->SetMesh(this); _meshList.push_back(this); myNodePool = new ObjectPool(SMDS_Mesh::chunkSize); - myVolumePool = new ObjectPool(SMDS_Mesh::chunkSize); + myVolumePool = new ObjectPool(SMDS_Mesh::chunkSize); myNodes.clear(); myCells.clear(); @@ -872,8 +872,7 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, nodeIds.push_back(n7->getId()); nodeIds.push_back(n8->getId()); - //volume = new SMDS_VolumeVtkNodes(nodeIds, this); - SMDS_VolumeVtkNodes *volvtk = myVolumePool->getNew(); + SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); volume = volvtk; adjustmyCellsCapacity(ID); diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index 203ec83f3..438053d73 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -29,6 +29,7 @@ #include "SMESH_SMDS.hxx" #include "SMDS_MeshNode.hxx" +#include "SMDS_MeshCell.hxx" #include "SMDS_Mesh0DElement.hxx" #include "SMDS_MeshEdge.hxx" #include "SMDS_MeshFace.hxx" @@ -38,6 +39,7 @@ #include "SMDS_MeshInfo.hxx" #include "SMDS_ElemIterator.hxx" #include "SMDS_VolumeOfNodes.hxx" +#include "SMDS_VtkVolume.hxx" #include "ObjectPool.hxx" #include @@ -52,12 +54,15 @@ class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{ public: friend class SMDS_MeshElementIDFactory; friend class SMDS_MeshVolumeVtkNodes; - - static std::vector _meshList; // --- to find the SMDS_mesh from its elements SMDS_Mesh(); + + //! to retreive this SMDS_Mesh instance from its elements (index stored in SMDS_Elements) + static std::vector _meshList; + //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid inline vtkUnstructuredGrid* getGrid() {return myGrid; }; + inline int getMeshId() {return myMeshId; }; SMDS_NodeIteratorPtr nodesIterator() const; SMDS_0DElementIteratorPtr elements0dIterator() const; @@ -553,7 +558,7 @@ public: typedef std::vector SetOfCells; void updateNodeMinMax(); - int fromVtkToSmds(int vtkid) { return myVtkIndex[vtkid]; }; + inline int fromVtkToSmds(int vtkid) { return myVtkIndex[vtkid]; }; void incrementNodesCapacity(int nbNodes); void incrementCellsCapacity(int nbCells); @@ -599,15 +604,29 @@ private: // Fields PRIVATE - int myMeshId; // --- index for this mesh in the vector + //! index of this SMDS_mesh in the static vector _meshList + int myMeshId; + + //! actual nodes coordinates, cells definition and reverse connectivity are stored in a vtkUnstructuredGrid vtkUnstructuredGrid* myGrid; + //! Small objects like SMDS_MeshNode are allocated by chunks to limit memory costs of new ObjectPool* myNodePool; - ObjectPool* myVolumePool; + + //! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new + ObjectPool* myVolumePool; + + //! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape SetOfNodes myNodes; + + //! SMDS_MeshCells refer to vtk cells (vtk id != index in myCells),store reference to this mesh, and subshape SetOfCells myCells; - std::vector myIDElements; // index = ID client, value = ID vtk - std::vector myVtkIndex; // index = ID vtk, value = ID client + + //! for cells only: index = ID for SMDS users, value = ID in vtkUnstructuredGrid + std::vector myIDElements; + + //! for cells only: index = ID in vtkUnstructuredGrid, value = ID for SMDS users + std::vector myVtkIndex; SMDS_Mesh * myParent; std::list myChildren; diff --git a/src/SMDS/SMDS_Mesh0DElement.hxx b/src/SMDS/SMDS_Mesh0DElement.hxx index b3273a6b1..5807c3844 100644 --- a/src/SMDS/SMDS_Mesh0DElement.hxx +++ b/src/SMDS/SMDS_Mesh0DElement.hxx @@ -28,7 +28,7 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshCell.hxx" #include diff --git a/src/SMDS/SMDS_MeshCell.cxx b/src/SMDS/SMDS_MeshCell.cxx new file mode 100644 index 000000000..2feea3d18 --- /dev/null +++ b/src/SMDS/SMDS_MeshCell.cxx @@ -0,0 +1,19 @@ + +#include "SMDS_MeshCell.hxx" +#include "utilities.h" + +using namespace std; + +int SMDS_MeshCell::nbCells = 0; + + +SMDS_MeshCell::SMDS_MeshCell() : SMDS_MeshElement(-1) +{ + nbCells++; + myVtkID = -1; +}; + +SMDS_MeshCell::~SMDS_MeshCell() +{ + nbCells--; +} diff --git a/src/SMDS/SMDS_MeshCell.hxx b/src/SMDS/SMDS_MeshCell.hxx new file mode 100644 index 000000000..fb291d1ee --- /dev/null +++ b/src/SMDS/SMDS_MeshCell.hxx @@ -0,0 +1,22 @@ +#ifndef _SMDS_MESHCELL_HXX_ +#define _SMDS_MESHCELL_HXX_ + +#include "SMDS_MeshElement.hxx" + +/*! + * \brief Base class for all cells + */ + +class SMDS_EXPORT SMDS_MeshCell:public SMDS_MeshElement +{ +public: + SMDS_MeshCell(); + virtual ~SMDS_MeshCell(); + inline void setVtkId(int vtkId) { myVtkID = vtkId; }; + inline int getVtkId() const {return myVtkID; }; + static int nbCells; +protected: + int myVtkID; +}; + +#endif diff --git a/src/SMDS/SMDS_MeshEdge.hxx b/src/SMDS/SMDS_MeshEdge.hxx index 3edbd91d7..cd6b8f1f2 100644 --- a/src/SMDS/SMDS_MeshEdge.hxx +++ b/src/SMDS/SMDS_MeshEdge.hxx @@ -28,7 +28,7 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshCell.hxx" #include class SMDS_EXPORT SMDS_MeshEdge:public SMDS_MeshCell diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index f309847d1..6f5b5eb54 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -34,8 +34,6 @@ using namespace std; -int SMDS_MeshCell::nbCells = 0; - SMDS_MeshElement::SMDS_MeshElement(int ID):myID(ID), myMeshId(-1), myShapeId(-1), myIdInShape(-1) { } @@ -245,14 +243,3 @@ int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const return i; return -1; } - -SMDS_MeshCell::SMDS_MeshCell() : SMDS_MeshElement(-1) -{ - nbCells++; - myVtkID = -1; -}; - -SMDS_MeshCell::~SMDS_MeshCell() -{ - nbCells--; -} diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 30950ad8b..014293912 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -146,24 +146,6 @@ protected: int myIdInShape; }; -// ============================================================ -/*! - * \brief Base class for all cells - */ -// ============================================================ - -class SMDS_EXPORT SMDS_MeshCell:public SMDS_MeshElement -{ -public: - SMDS_MeshCell(); - virtual ~SMDS_MeshCell(); - inline void setVtkId(int vtkId) { myVtkID = vtkId; }; - inline int getVtkId() const {return myVtkID; }; - static int nbCells; -protected: - int myVtkID; -}; - // ============================================================ /*! diff --git a/src/SMDS/SMDS_MeshFace.hxx b/src/SMDS/SMDS_MeshFace.hxx index 8593c1d95..3a1fa1b29 100644 --- a/src/SMDS/SMDS_MeshFace.hxx +++ b/src/SMDS/SMDS_MeshFace.hxx @@ -28,7 +28,7 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshCell.hxx" class SMDS_EXPORT SMDS_MeshFace:public SMDS_MeshCell { diff --git a/src/SMDS/SMDS_MeshVolume.hxx b/src/SMDS/SMDS_MeshVolume.hxx index 58a55c48e..03f44d355 100644 --- a/src/SMDS/SMDS_MeshVolume.hxx +++ b/src/SMDS/SMDS_MeshVolume.hxx @@ -28,7 +28,7 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshCell.hxx" class SMDS_EXPORT SMDS_MeshVolume:public SMDS_MeshCell { diff --git a/src/SMDS/SMDS_VolumeOfNodes.cxx b/src/SMDS/SMDS_VolumeOfNodes.cxx index 449212df2..b17e89318 100644 --- a/src/SMDS/SMDS_VolumeOfNodes.cxx +++ b/src/SMDS/SMDS_VolumeOfNodes.cxx @@ -32,10 +32,6 @@ #include "SMDS_Mesh.hxx" #include "utilities.h" -#include - -#include - using namespace std; /////////////////////////////////////////////////////////////////////////////// @@ -254,116 +250,3 @@ SMDSAbs_EntityType SMDS_VolumeOfNodes::GetEntityType() const } -// ************************************************************************************* -// - -SMDS_VolumeVtkNodes::SMDS_VolumeVtkNodes() -{ -} - -SMDS_VolumeVtkNodes::SMDS_VolumeVtkNodes(std::vector nodeIds, SMDS_Mesh* mesh) -{ - init(nodeIds, mesh); -} - -void SMDS_VolumeVtkNodes::init(std::vector nodeIds, SMDS_Mesh* mesh) -{ - vtkUnstructuredGrid* grid = mesh->getGrid(); - myVtkID = grid->InsertNextLinkedCell(GetType(), nodeIds.size(), &nodeIds[0]); -} - -bool SMDS_VolumeVtkNodes::ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes) -{ - // utilise dans SMDS_Mesh - return true; -} - -SMDS_VolumeVtkNodes::~SMDS_VolumeVtkNodes() -{ -} - -void SMDS_VolumeVtkNodes::Print(ostream & OS) const -{ - OS << "volume <" << GetID() << "> : "; -} - -int SMDS_VolumeVtkNodes::NbFaces() const -{ - switch(NbNodes()) - { - case 4: return 4; - case 5: return 5; - case 6: return 5; - case 8: return 6; - default: MESSAGE("invalid number of nodes"); - } - return 0; -} - -int SMDS_VolumeVtkNodes::NbNodes() const -{ - vtkUnstructuredGrid* grid =SMDS_Mesh::_meshList[myMeshId]->getGrid(); - int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); - return nbPoints; -} - -int SMDS_VolumeVtkNodes::NbEdges() const -{ - switch(NbNodes()) - { - case 4: return 6; - case 5: return 8; - case 6: return 9; - case 8: return 12; - default: MESSAGE("invalid number of nodes"); - } - return 0; -} - -SMDS_ElemIteratorPtr SMDS_VolumeVtkNodes::elementsIterator(SMDSAbs_ElementType type) const -{ - switch(type) - { -// case SMDSAbs_Volume: -// return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume); -// case SMDSAbs_Node: -// return SMDS_ElemIteratorPtr(new SMDS_VolumeVtkNodes_MyIterator(myNodes,myNbNodes)); -// case SMDSAbs_Face: -// return SMDS_ElemIteratorPtr(new _MySubWNIterator(this,SMDSAbs_Face)); -// case SMDSAbs_Edge: -// return SMDS_ElemIteratorPtr(new _MySubWNIterator(this,SMDSAbs_Edge)); - default: - MESSAGE("ERROR : Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); - } -} - -SMDSAbs_ElementType SMDS_VolumeVtkNodes::GetType() const -{ - return SMDSAbs_Volume; -} - -/*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ -const SMDS_MeshNode* SMDS_VolumeVtkNodes::GetNode(const int ind) const -{ - return 0; -} - -SMDSAbs_EntityType SMDS_VolumeVtkNodes::GetEntityType() const -{ - SMDSAbs_EntityType aType = SMDSEntity_Tetra; - switch(NbNodes()) - { - case 4: aType = SMDSEntity_Tetra; break; - case 5: aType = SMDSEntity_Pyramid; break; - case 6: aType = SMDSEntity_Penta; break; - case 8: - default: aType = SMDSEntity_Hexa; break; - } - return aType; -} diff --git a/src/SMDS/SMDS_VolumeOfNodes.hxx b/src/SMDS/SMDS_VolumeOfNodes.hxx index 2aabf9fc3..6b67328c6 100644 --- a/src/SMDS/SMDS_VolumeOfNodes.hxx +++ b/src/SMDS/SMDS_VolumeOfNodes.hxx @@ -29,8 +29,6 @@ #include "SMESH_SMDS.hxx" #include "SMDS_MeshVolume.hxx" -#include -#include class SMDS_EXPORT SMDS_VolumeOfNodes:public SMDS_MeshVolume { @@ -89,34 +87,4 @@ class SMDS_EXPORT SMDS_VolumeOfNodes:public SMDS_MeshVolume }; -class SMDS_EXPORT SMDS_VolumeVtkNodes:public SMDS_MeshVolume -{ -public: - SMDS_VolumeVtkNodes(); - SMDS_VolumeVtkNodes(std::vector nodeIds, SMDS_Mesh* mesh); - ~SMDS_VolumeVtkNodes(); - void init(std::vector nodeIds, SMDS_Mesh* mesh); - bool ChangeNodes(const SMDS_MeshNode* nodes[], - const int nbNodes); - - void Print(std::ostream & OS) const; - int NbFaces() const; - int NbNodes() const; - int NbEdges() const; - virtual SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const; - - /*! - * \brief Return node by its index - * \param ind - node index - * \retval const SMDS_MeshNode* - the node - */ - virtual const SMDS_MeshNode* GetNode(const int ind) const; - - protected: - SMDS_ElemIteratorPtr - elementsIterator(SMDSAbs_ElementType type) const; -}; - - #endif diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx new file mode 100644 index 000000000..82d5460cd --- /dev/null +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -0,0 +1,21 @@ + +#include "SMDS_VtkCellIterator.hxx" + +SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId): + _mesh(mesh), _cellId(vtkCellId), _index(0) +{ + vtkUnstructuredGrid* grid = _mesh->getGrid(); + _vtkIdList = grid->GetCell(_cellId)->GetPointIds(); + _nbNodes = _vtkIdList->GetNumberOfIds(); +} + +bool SMDS_VtkCellIterator::more() +{ + return (_index < _nbNodes); +} + +const SMDS_MeshElement* SMDS_VtkCellIterator::next() +{ + vtkIdType id = _vtkIdList->GetId(_index++); + return _mesh->FindNode(id); +} diff --git a/src/SMDS/SMDS_VtkCellIterator.hxx b/src/SMDS/SMDS_VtkCellIterator.hxx new file mode 100644 index 000000000..f73985162 --- /dev/null +++ b/src/SMDS/SMDS_VtkCellIterator.hxx @@ -0,0 +1,24 @@ +#ifndef _SMDS_VTKCELLITERATOR_HXX_ +#define _SMDS_VTKCELLITERATOR_HXX_ + +#include "SMDS_ElemIterator.hxx" +#include "SMDS_Mesh.hxx" + +#include +#include + +class SMDS_VtkCellIterator : public SMDS_ElemIterator +{ +public: + SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId); + virtual bool more(); + virtual const SMDS_MeshElement* next(); +protected: + SMDS_Mesh* _mesh; + int _cellId; + int _index; + int _nbNodes; + vtkIdList* _vtkIdList; +}; + +#endif diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx new file mode 100644 index 000000000..733564bbf --- /dev/null +++ b/src/SMDS/SMDS_VtkVolume.cxx @@ -0,0 +1,116 @@ + +#include "SMDS_VtkVolume.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_Mesh.hxx" +#include "SMDS_VtkCellIterator.hxx" + +#include "utilities.h" + +#include + + +SMDS_VtkVolume::SMDS_VtkVolume() +{ +} + +SMDS_VtkVolume::SMDS_VtkVolume(std::vector nodeIds, SMDS_Mesh* mesh) +{ + init(nodeIds, mesh); +} + +void SMDS_VtkVolume::init(std::vector nodeIds, SMDS_Mesh* mesh) +{ + vtkUnstructuredGrid* grid = mesh->getGrid(); + myMeshId = mesh->getMeshId(); + myVtkID = grid->InsertNextLinkedCell(GetType(), nodeIds.size(), &nodeIds[0]); +} + +bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], + const int nbNodes) +{ + // utilise dans SMDS_Mesh + return true; +} + +SMDS_VtkVolume::~SMDS_VtkVolume() +{ +} + +void SMDS_VtkVolume::Print(ostream & OS) const +{ + OS << "volume <" << GetID() << "> : "; +} + +int SMDS_VtkVolume::NbFaces() const +{ + switch(NbNodes()) + { + case 4: return 4; + case 5: return 5; + case 6: return 5; + case 8: return 6; + default: MESSAGE("invalid number of nodes"); + } + return 0; +} + +int SMDS_VtkVolume::NbNodes() const +{ + vtkUnstructuredGrid* grid =SMDS_Mesh::_meshList[myMeshId]->getGrid(); + int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); + return nbPoints; +} + +int SMDS_VtkVolume::NbEdges() const +{ + switch(NbNodes()) + { + case 4: return 6; + case 5: return 8; + case 6: return 9; + case 8: return 12; + default: MESSAGE("invalid number of nodes"); + } + return 0; +} + +SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const +{ + switch(type) + { + case SMDSAbs_Node: + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID)); + default: + MESSAGE("ERROR : Iterator not implemented"); + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); + } +} + +SMDSAbs_ElementType SMDS_VtkVolume::GetType() const +{ + return SMDSAbs_Volume; +} + +/*! + * \brief Return node by its index + * \param ind - node index + * \retval const SMDS_MeshNode* - the node + */ +const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const +{ + return 0; +} + +SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const +{ + SMDSAbs_EntityType aType = SMDSEntity_Tetra; + switch(NbNodes()) + { + case 4: aType = SMDSEntity_Tetra; break; + case 5: aType = SMDSEntity_Pyramid; break; + case 6: aType = SMDSEntity_Penta; break; + case 8: + default: aType = SMDSEntity_Hexa; break; + } + return aType; +} diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx new file mode 100644 index 000000000..f58bb3a6a --- /dev/null +++ b/src/SMDS/SMDS_VtkVolume.hxx @@ -0,0 +1,39 @@ +#ifndef _SMDS_VTKVOLUME_HXX_ +#define _SMDS_VTKVOLUME_HXX_ + +#include "SMESH_SMDS.hxx" + +#include "SMDS_MeshVolume.hxx" +#include +#include + +class SMDS_EXPORT SMDS_VtkVolume:public SMDS_MeshVolume +{ +public: + SMDS_VtkVolume(); + SMDS_VtkVolume(std::vector nodeIds, SMDS_Mesh* mesh); + ~SMDS_VtkVolume(); + void init(std::vector nodeIds, SMDS_Mesh* mesh); + bool ChangeNodes(const SMDS_MeshNode* nodes[], + const int nbNodes); + + void Print(std::ostream & OS) const; + int NbFaces() const; + int NbNodes() const; + int NbEdges() const; + virtual SMDSAbs_ElementType GetType() const; + virtual SMDSAbs_EntityType GetEntityType() const; + + /*! + * \brief Return node by its index + * \param ind - node index + * \retval const SMDS_MeshNode* - the node + */ + virtual const SMDS_MeshNode* GetNode(const int ind) const; + +protected: + SMDS_ElemIteratorPtr + elementsIterator(SMDSAbs_ElementType type) const; +}; + +#endif