From: prascle Date: Fri, 22 Jan 2010 15:02:34 +0000 (+0000) Subject: PR: mesh and visu hexa no copy X-Git-Tag: smds_memimp_V5_1_3~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ea70fb08091e0a2ea837d77cd4785c07eba5a823;p=modules%2Fsmesh.git PR: mesh and visu hexa no copy --- diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index e7ef139a4..0d0520667 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -147,60 +147,65 @@ SMESH_VisualObjDef::~SMESH_VisualObjDef() //================================================================================= vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID ) { - TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID); - return i == myVTK2SMDSNodes.end() ? -1 : i->second; +// TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID); +// return i == myVTK2SMDSNodes.end() ? -1 : i->second; + return theVTKID; } vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID ) { - TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID); - return i == mySMDS2VTKNodes.end() ? -1 : i->second; +// TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID); +// return i == mySMDS2VTKNodes.end() ? -1 : i->second; + return theObjID; } vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID ) { - TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID); - return i == myVTK2SMDSElems.end() ? -1 : i->second; +// TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID); +// return i == myVTK2SMDSElems.end() ? -1 : i->second; + return this->GetMesh()->fromVtkToSmds(theVTKID); } vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) { - TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID); - return i == mySMDS2VTKElems.end() ? -1 : i->second; +// TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID); +// return i == mySMDS2VTKElems.end() ? -1 : i->second; + return this->GetMesh()->fromSmdsToVtk(theObjID); } //================================================================================= // function : SMESH_VisualObjDef::createPoints // purpose : Create points from nodes //================================================================================= -void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) -{ - if ( thePoints == 0 ) - return; - - TEntityList aNodes; - vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes ); - thePoints->SetNumberOfPoints( nbNodes ); - - int nbPoints = 0; - - TEntityList::const_iterator anIter; - for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter ) - { - const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter); - if ( aNode != 0 ) - { - thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() ); - int anId = aNode->GetID(); - mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) ); - myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) ); - nbPoints++; - } - } - if ( nbPoints != nbNodes ) - thePoints->SetNumberOfPoints( nbPoints ); -} +//void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) +//{ +// if ( thePoints == 0 ) +// return; +// +// TEntityList aNodes; +// vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes ); +// thePoints->SetNumberOfPoints( nbNodes ); +// +// int nbPoints = 0; +// +// TEntityList::const_iterator anIter; +// for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter ) +// { +// const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter); +// if ( aNode != 0 ) +// { +// thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() ); +// int anId = aNode->GetID(); +// mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) ); +// myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) ); +// nbPoints++; +// } +// } +// +// if ( nbPoints != nbNodes ) +// thePoints->SetNumberOfPoints( nbPoints ); +//} //================================================================================= // function : buildPrs @@ -208,29 +213,30 @@ void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) //================================================================================= void SMESH_VisualObjDef::buildPrs() { - try - { - mySMDS2VTKNodes.clear(); - myVTK2SMDSNodes.clear(); - mySMDS2VTKElems.clear(); - myVTK2SMDSElems.clear(); - - if ( IsNodePrs() ) - buildNodePrs(); - else - buildElemPrs(); - } - catch(...) - { - mySMDS2VTKNodes.clear(); - myVTK2SMDSNodes.clear(); - mySMDS2VTKElems.clear(); - myVTK2SMDSElems.clear(); - - myGrid->SetPoints( 0 ); - myGrid->SetCells( 0, 0, 0 ); - throw; - } +// try +// { +// mySMDS2VTKNodes.clear(); +// myVTK2SMDSNodes.clear(); +// mySMDS2VTKElems.clear(); +// myVTK2SMDSElems.clear(); +// +// if ( IsNodePrs() ) +// buildNodePrs(); +// else +// buildElemPrs(); +// } +// catch(...) +// { +// mySMDS2VTKNodes.clear(); +// myVTK2SMDSNodes.clear(); +// mySMDS2VTKElems.clear(); +// myVTK2SMDSElems.clear(); +// +// myGrid->SetPoints( 0 ); +// myGrid->SetCells( 0, 0, 0 ); +// throw; +// } + myGrid = GetMesh()->getGrid(); if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<GetNumberOfCells() ); if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" ); @@ -240,19 +246,20 @@ void SMESH_VisualObjDef::buildPrs() // function : buildNodePrs // purpose : create VTK cells for nodes //================================================================================= -void SMESH_VisualObjDef::buildNodePrs() -{ - // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, - // so check remaining memory size for safety - SMDS_Mesh::CheckMemory(); // PAL16631 - vtkPoints* aPoints = vtkPoints::New(); - createPoints( aPoints ); - SMDS_Mesh::CheckMemory(); - myGrid->SetPoints( aPoints ); - aPoints->Delete(); - myGrid->SetCells( 0, 0, 0 ); -} +//void SMESH_VisualObjDef::buildNodePrs() +//{ +// // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, +// // so check remaining memory size for safety +// SMDS_Mesh::CheckMemory(); // PAL16631 +// vtkPoints* aPoints = vtkPoints::New(); +// createPoints( aPoints ); +// SMDS_Mesh::CheckMemory(); +// myGrid->SetPoints( aPoints ); +// aPoints->Delete(); +// +// myGrid->SetCells( 0, 0, 0 ); +//} //================================================================================= // function : buildElemPrs @@ -284,199 +291,199 @@ namespace{ } -void SMESH_VisualObjDef::buildElemPrs() -{ - // Create points - - vtkPoints* aPoints = vtkPoints::New(); - createPoints( aPoints ); - myGrid->SetPoints( aPoints ); - aPoints->Delete(); - - if ( MYDEBUG ) - MESSAGE("Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints()); - - // Calculate cells size - - static SMDSAbs_ElementType aTypes[ 4 ] = - { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; - - // get entity data - map nbEnts; - map anEnts; - - for ( int i = 0; i <= 3; i++ ) - nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); - - // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, - // so check remaining memory size for safety - SMDS_Mesh::CheckMemory(); // PAL16631 - - vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ]; - - for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes - { - if ( nbEnts[ aTypes[ i ] ] ) - { - const TEntityList& aList = anEnts[ aTypes[ i ] ]; - TEntityList::const_iterator anIter; - for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) - aCellsSize += (*anIter)->NbNodes() + 1; - } - } - - vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] + - nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; - - if ( MYDEBUG ) - MESSAGE( "Update - aNbCells = "<X()<<","<Y()<<","<Z()<<")"< 0) { - for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++) - SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]); - } - break; - } - default: - for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){ - const SMDS_MeshElement* aNode = aNodesIter->next(); - anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] ); - } - } - - aConnectivity->InsertNextCell( anIdList ); - aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) ); - - iElem++; - } - } - SMDS_Mesh::CheckMemory(); // PAL16631 - } - - // Insert cells in grid - - VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); - aCellLocationsArray->SetNumberOfComponents( 1 ); - aCellLocationsArray->SetNumberOfTuples( aNbCells ); - - SMDS_Mesh::CheckMemory(); // PAL16631 - - aConnectivity->InitTraversal(); - for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) - aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); - - myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); - - aCellLocationsArray->Delete(); - aCellTypesArray->Delete(); - aConnectivity->Delete(); - anIdList->Delete(); - - SMDS_Mesh::CheckMemory(); // PAL16631 -} +//void SMESH_VisualObjDef::buildElemPrs() +//{ +// // Create points +// +// vtkPoints* aPoints = vtkPoints::New(); +// createPoints( aPoints ); +// myGrid->SetPoints( aPoints ); +// aPoints->Delete(); +// +// if ( MYDEBUG ) +// MESSAGE("Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints()); +// +// // Calculate cells size +// +// static SMDSAbs_ElementType aTypes[ 4 ] = +// { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; +// +// // get entity data +// map nbEnts; +// map anEnts; +// +// for ( int i = 0; i <= 3; i++ ) +// nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); +// +// // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, +// // so check remaining memory size for safety +// SMDS_Mesh::CheckMemory(); // PAL16631 +// +// vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ]; +// +// for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes +// { +// if ( nbEnts[ aTypes[ i ] ] ) +// { +// const TEntityList& aList = anEnts[ aTypes[ i ] ]; +// TEntityList::const_iterator anIter; +// for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) +// aCellsSize += (*anIter)->NbNodes() + 1; +// } +// } +// +// vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] + +// nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; +// +// if ( MYDEBUG ) +// MESSAGE( "Update - aNbCells = "<X()<<","<Y()<<","<Z()<<")"< 0) { +// for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++) +// SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]); +// } +// break; +// } +// default: +// for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){ +// const SMDS_MeshElement* aNode = aNodesIter->next(); +// anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] ); +// } +// } +// +// aConnectivity->InsertNextCell( anIdList ); +// aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) ); +// +// iElem++; +// } +// } +// SMDS_Mesh::CheckMemory(); // PAL16631 +// } +// +// // Insert cells in grid +// +// VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); +// aCellLocationsArray->SetNumberOfComponents( 1 ); +// aCellLocationsArray->SetNumberOfTuples( aNbCells ); +// +// SMDS_Mesh::CheckMemory(); // PAL16631 +// +// aConnectivity->InitTraversal(); +// for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) +// aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); +// +// myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); +// +// aCellLocationsArray->Delete(); +// aCellTypesArray->Delete(); +// aConnectivity->Delete(); +// anIdList->Delete(); +// +// SMDS_Mesh::CheckMemory(); // PAL16631 +//} //================================================================================= // function : GetEdgeNodes diff --git a/src/OBJECT/SMESH_ObjectDef.h b/src/OBJECT/SMESH_ObjectDef.h index 82f540913..ac0bd30c1 100644 --- a/src/OBJECT/SMESH_ObjectDef.h +++ b/src/OBJECT/SMESH_ObjectDef.h @@ -85,17 +85,17 @@ public: protected: - void createPoints( vtkPoints* ); +// void createPoints( vtkPoints* ); void buildPrs(); - void buildNodePrs(); - void buildElemPrs(); +// void buildNodePrs(); +// void buildElemPrs(); private: - TMapOfIds mySMDS2VTKNodes; - TMapOfIds myVTK2SMDSNodes; - TMapOfIds mySMDS2VTKElems; - TMapOfIds myVTK2SMDSElems; +// TMapOfIds mySMDS2VTKNodes; +// TMapOfIds myVTK2SMDSNodes; +// TMapOfIds mySMDS2VTKElems; +// TMapOfIds myVTK2SMDSElems; vtkUnstructuredGrid* myGrid; }; diff --git a/src/SMDS/Makefile.am b/src/SMDS/Makefile.am index 54234dab8..39837410d 100644 --- a/src/SMDS/Makefile.am +++ b/src/SMDS/Makefile.am @@ -29,6 +29,7 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files salomeinclude_HEADERS = \ + ObjectPool.hxx \ SMDS_TypeOfPosition.hxx \ SMDSAbs_ElementType.hxx \ SMDS_EdgePosition.hxx \ @@ -36,10 +37,12 @@ salomeinclude_HEADERS = \ SMDS_FacePosition.hxx \ SMDS_Mesh.hxx \ SMDS_Mesh0DElement.hxx \ + SMDS_LinearEdge.hxx \ SMDS_MeshEdge.hxx \ SMDS_MeshElement.hxx \ SMDS_MeshElement.cxx \ SMDS_MeshElementIDFactory.hxx \ + SMDS_MeshCell.hxx \ SMDS_MeshFace.hxx \ SMDS_MeshGroup.hxx \ SMDS_MeshIDFactory.hxx \ @@ -54,6 +57,8 @@ salomeinclude_HEADERS = \ SMDS_IteratorOfElements.hxx \ SMDS_VolumeOfFaces.hxx \ SMDS_VolumeOfNodes.hxx \ + SMDS_VtkEdge.hxx \ + SMDS_VtkFace.hxx \ SMDS_VtkVolume.hxx \ SMDS_VtkCellIterator.hxx \ SMDS_PolyhedralVolumeOfNodes.hxx \ @@ -83,6 +88,7 @@ dist_libSMDS_la_SOURCES = \ SMDS_VertexPosition.cxx \ SMDS_MeshNode.cxx \ SMDS_Mesh0DElement.cxx \ + SMDS_LinearEdge.cxx \ SMDS_MeshEdge.cxx \ SMDS_MeshFace.cxx \ SMDS_MeshVolume.cxx \ @@ -94,6 +100,8 @@ dist_libSMDS_la_SOURCES = \ SMDS_IteratorOfElements.cxx \ SMDS_VolumeOfFaces.cxx \ SMDS_VolumeOfNodes.cxx \ + SMDS_VtkEdge.cxx \ + SMDS_VtkFace.cxx \ SMDS_VtkVolume.cxx \ SMDS_VtkCellIterator.cxx \ SMDS_PolyhedralVolumeOfNodes.cxx \ diff --git a/src/SMDS/ObjectPool.hxx b/src/SMDS/ObjectPool.hxx index a4111b181..d800bc4ee 100644 --- a/src/SMDS/ObjectPool.hxx +++ b/src/SMDS/ObjectPool.hxx @@ -1,4 +1,3 @@ - #ifndef _OBJECTPOOL_HXX_ #define _OBJECTPOOL_HXX_ @@ -6,7 +5,7 @@ #include #include -template class ObjectPool +template class ObjectPool { private: @@ -18,20 +17,20 @@ private: int getNextFree() { - for (int i=_nextFree; i< _maxAvail; i++) + for (int i = _nextFree; i < _maxAvail; i++) if (_freeList[i] == true) - { - return i; - break; - } + { + return i; + break; + } return _maxAvail; } void checkDelete(int chunkId) { - int i0 = _chunkSize*chunkId; - int i1 =_chunkSize*(chunkId+1); - for (int i=i0; i < i1; i++) + int i0 = _chunkSize * chunkId; + int i1 = _chunkSize * (chunkId + 1); + for (int i = i0; i < i1; i++) if (_freeList[i] == false) return; std::cerr << "a chunk to delete" << std::endl; @@ -52,8 +51,8 @@ public: virtual ~ObjectPool() { - for (int i=0; i<_chunkList.size(); i++) - delete [] _chunkList[i]; + for (int i = 0; i < _chunkList.size(); i++) + delete[] _chunkList[i]; } X* getNew() @@ -61,45 +60,56 @@ public: X *obj = 0; _nextFree = getNextFree(); if (_nextFree == _maxAvail) - { - X* newChunk = new X[_chunkSize]; - _chunkList.push_back(newChunk); - _freeList.insert(_freeList.end(), _chunkSize, true); - _maxAvail += _chunkSize; - _freeList[_nextFree] = false; - obj = newChunk; // &newChunk[0]; - } + { + X* newChunk = new X[_chunkSize]; + _chunkList.push_back(newChunk); + _freeList.insert(_freeList.end(), _chunkSize, true); + _maxAvail += _chunkSize; + _freeList[_nextFree] = false; + obj = newChunk; // &newChunk[0]; + } else - { - int chunkId = _nextFree/_chunkSize; - int rank = _nextFree - chunkId*_chunkSize; - _freeList[_nextFree] = false; - obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank]; - } + { + int chunkId = _nextFree / _chunkSize; + int rank = _nextFree - chunkId * _chunkSize; + _freeList[_nextFree] = false; + obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank]; + } //obj->init(); return obj; } void destroy(X* obj) { - long adrobj = (long)(obj); - for (int i=0; i< _chunkList.size(); i++) + long adrobj = (long) (obj); + for (int i = 0; i < _chunkList.size(); i++) { X* chunk = _chunkList[i]; - long adrmin = (long)(chunk); - if (adrobj < adrmin) continue; - long adrmax = (long)(chunk + _chunkSize); - if (adrobj >= adrmax) continue; - int rank = (adrobj -adrmin)/sizeof(X); - int toFree = i*_chunkSize + rank; + long adrmin = (long) (chunk); + if (adrobj < adrmin) + continue; + long adrmax = (long) (chunk + _chunkSize); + if (adrobj >= adrmax) + continue; + int rank = (adrobj - adrmin) / sizeof(X); + int toFree = i * _chunkSize + rank; _freeList[toFree] = true; - if (toFree < _nextFree) _nextFree = toFree; + if (toFree < _nextFree) + _nextFree = toFree; //obj->clean(); //checkDelete(i); compactage non fait break; } } +// void destroy(int toFree) +// { +// // no control 0<= toFree < _freeList.size() +// _freeList[toFree] = true; +// if (toFree < _nextFree) +// _nextFree = toFree; +// } + }; #endif diff --git a/src/SMDS/SMDS_FaceOfEdges.hxx b/src/SMDS/SMDS_FaceOfEdges.hxx index cd6521398..1b9a1d7d4 100644 --- a/src/SMDS/SMDS_FaceOfEdges.hxx +++ b/src/SMDS/SMDS_FaceOfEdges.hxx @@ -46,7 +46,7 @@ class SMDS_EXPORT SMDS_FaceOfEdges:public SMDS_MeshFace const SMDS_MeshEdge* edge4); SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const; + virtual SMDSAbs_EntityType GetEntityType() const; int NbNodes() const; int NbEdges() const; int NbFaces() const; diff --git a/src/SMDS/SMDS_LinearEdge.cxx b/src/SMDS/SMDS_LinearEdge.cxx new file mode 100644 index 000000000..017f74cfa --- /dev/null +++ b/src/SMDS/SMDS_LinearEdge.cxx @@ -0,0 +1,155 @@ +// Copyright (C) 2007-2008 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 +// +// 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. +// +// 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 +// +// SMESH SMDS : implementaion of Salome mesh data structure +// File : SMDS_LinearEdge.cxx +// Author : Jean-Michel BOULCOURT +// Module : SMESH +// +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + +#include "SMDS_LinearEdge.hxx" +#include "SMDS_IteratorOfElements.hxx" +#include "SMDS_MeshNode.hxx" +#include "utilities.h" + +using namespace std; + +//======================================================================= +//function : SMDS_LinearEdge +//purpose : +//======================================================================= + +SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2) +{ + //MESSAGE("SMDS_LinearEdge " << GetID()); + myNodes[0]=node1; + myNodes[1]=node2; +} + +//======================================================================= +//function : Print +//purpose : +//======================================================================= + +void SMDS_LinearEdge::Print(ostream & OS) const +{ + OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] << + ") " << endl; +} + +int SMDS_LinearEdge::NbNodes() const +{ + return 2; +} + +int SMDS_LinearEdge::NbEdges() const +{ + return 1; +} + +class SMDS_LinearEdge_MyNodeIterator:public SMDS_ElemIterator +{ + const SMDS_MeshNode *const* myNodes; + int myIndex; + public: + SMDS_LinearEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes): + myNodes(nodes),myIndex(0) {} + + bool more() + { + return myIndex<2; + } + + const SMDS_MeshElement* next() + { + myIndex++; + return myNodes[myIndex-1]; + } +}; + +SMDS_ElemIteratorPtr SMDS_LinearEdge:: + elementsIterator(SMDSAbs_ElementType type) const +{ + switch(type) + { + case SMDSAbs_Edge: + return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); + case SMDSAbs_Node: + return SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes)); + default: + return SMDS_ElemIteratorPtr + (new SMDS_IteratorOfElements + (this,type, SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes)))); + } +} + +bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2) +{ + int id11=e1.myNodes[0]->GetID(); + int id21=e2.myNodes[0]->GetID(); + int id12=e1.myNodes[1]->GetID(); + int id22=e2.myNodes[1]->GetID(); + int tmp; + + if(id11>=id12) + { + tmp=id11; + id11=id12; + id12=tmp; + } + if(id21>=id22) + { + tmp=id21; + id21=id22; + id22=tmp; + } + + if(id11 + +class SMDS_EXPORT SMDS_LinearEdge:public SMDS_MeshEdge +{ + + public: + SMDS_LinearEdge(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2); + bool ChangeNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2); + void Print(std::ostream & OS) const; + + virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; } + int NbNodes() const; + int NbEdges() const; + friend bool operator<(const SMDS_LinearEdge& e1, const SMDS_LinearEdge& e2); + + /*! + * \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; + + protected: + const SMDS_MeshNode* myNodes[3]; + +}; +#endif diff --git a/src/SMDS/SMDS_Mesh.cxx b/src/SMDS/SMDS_Mesh.cxx index b61334849..f5d44ed8a 100644 --- a/src/SMDS/SMDS_Mesh.cxx +++ b/src/SMDS/SMDS_Mesh.cxx @@ -48,7 +48,7 @@ using namespace std; #include #endif -// number of added entitis to check memory after +// number of added entities to check memory after #define CHECKMEMORY_INTERVAL 1000 vector SMDS_Mesh::_meshList = vector(); @@ -116,7 +116,7 @@ SMDS_Mesh::SMDS_Mesh() myHasConstructionEdges(false), myHasConstructionFaces(false), myHasInverseElements(true), myNodeMin(0), myNodeMax(0), myCellLinksSize(0), - myNodePool(0), myVolumePool(0) + myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0) { myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector MESSAGE("myMeshId=" << myMeshId); @@ -130,6 +130,8 @@ SMDS_Mesh::SMDS_Mesh() myElementIDFactory->SetMesh(this); _meshList.push_back(this); myNodePool = new ObjectPool(SMDS_Mesh::chunkSize); + myEdgePool = new ObjectPool(SMDS_Mesh::chunkSize); + myFacePool = new ObjectPool(SMDS_Mesh::chunkSize); myVolumePool = new ObjectPool(SMDS_Mesh::chunkSize); myNodes.clear(); @@ -157,6 +159,8 @@ SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent) myHasConstructionEdges(false), myHasConstructionFaces(false), myHasInverseElements(true), myNodePool(parent->myNodePool), + myEdgePool(parent->myEdgePool), + myFacePool(parent->myFacePool), myVolumePool(parent->myVolumePool) { } @@ -295,10 +299,17 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1, int ID) { if ( !n1 || !n2 ) return 0; + SMDS_MeshEdge * edge = 0; - //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); - //MESSAGE("AddEdgeWithID " << ID) - SMDS_MeshEdge * edge=new SMDS_MeshEdge(n1,n2); + // --- retreive nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(n1->getId()); + nodeIds.push_back(n2->getId()); + + SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); + edgevtk->init(nodeIds, this); + edge = edgevtk; adjustmyCellsCapacity(ID); myCells[ID] = edge; myInfo.myNbEdges++; @@ -346,7 +357,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1, int ID) { //MESSAGE("AddFaceWithID " << ID) - SMDS_MeshFace * face=createTriangle(n1, n2, n3); + SMDS_MeshFace * face=createTriangle(n1, n2, n3, myElementIDFactory->GetFreeID()); if (face && !registerElement(ID, face)) { RemoveElement(face, false); @@ -565,7 +576,17 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, return NULL; } else { - volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4); + // --- retrieve nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(n1->getId()); + nodeIds.push_back(n3->getId()); // order SMDS-->VTK + nodeIds.push_back(n2->getId()); + nodeIds.push_back(n4->getId()); + + SMDS_VtkVolume *volvtk = myVolumePool->getNew(); + volvtk->init(nodeIds, this); + volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbTetras++; @@ -656,7 +677,18 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, return NULL; } else { - volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5); + // --- retrieve nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(n1->getId()); + nodeIds.push_back(n4->getId()); + nodeIds.push_back(n3->getId()); + nodeIds.push_back(n2->getId()); + nodeIds.push_back(n5->getId()); + + SMDS_VtkVolume *volvtk = myVolumePool->getNew(); + volvtk->init(nodeIds, this); + volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbPyramids++; @@ -752,7 +784,19 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, return NULL; } else { - volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6); + // --- retrieve nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(n1->getId()); + nodeIds.push_back(n3->getId()); + nodeIds.push_back(n2->getId()); + nodeIds.push_back(n4->getId()); + nodeIds.push_back(n6->getId()); + nodeIds.push_back(n5->getId()); + + SMDS_VtkVolume *volvtk = myVolumePool->getNew(); + volvtk->init(nodeIds, this); + volume = volvtk; adjustmyCellsCapacity(ID); myCells[ID] = volume; myInfo.myNbPrisms++; @@ -860,17 +904,17 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1, return NULL; } else { - // --- retreive nodes ID + // --- retrieve nodes ID vector nodeIds; nodeIds.clear(); nodeIds.push_back(n1->getId()); - nodeIds.push_back(n2->getId()); - nodeIds.push_back(n3->getId()); nodeIds.push_back(n4->getId()); + nodeIds.push_back(n3->getId()); + nodeIds.push_back(n2->getId()); nodeIds.push_back(n5->getId()); - nodeIds.push_back(n6->getId()); - nodeIds.push_back(n7->getId()); nodeIds.push_back(n8->getId()); + nodeIds.push_back(n7->getId()); + nodeIds.push_back(n6->getId()); SMDS_VtkVolume *volvtk = myVolumePool->getNew(); volvtk->init(nodeIds, this); @@ -1174,7 +1218,7 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element) element->myMeshId = myMeshId; SMDS_MeshCell *cell = dynamic_cast(element); - assert(cell); + MYASSERT(cell); int vtkId = cell->getVtkId(); if (vtkId == -1) vtkId = myElementIDFactory->SetInVtkGrid(element); @@ -1204,18 +1248,22 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element) /////////////////////////////////////////////////////////////////////////////// const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const { - if (ID <0 || ID >= myNodes.size()) - return NULL; + if (ID < 0 || ID >= myNodes.size()) + { + MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size()); + return 0; + } return (const SMDS_MeshNode *)myNodes[ID]; } /////////////////////////////////////////////////////////////////////////////// -///Create a triangle and add it to the current mesh. This methode do not bind a +///Create a triangle and add it to the current mesh. This method do not bind an ///ID to the create triangle. /////////////////////////////////////////////////////////////////////////////// SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2, - const SMDS_MeshNode * node3) + const SMDS_MeshNode * node3, + int ID) { if ( !node1 || !node2 || !node3) return 0; // if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); @@ -1226,7 +1274,7 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, edge2=FindEdgeOrCreate(node2,node3); edge3=FindEdgeOrCreate(node3,node1); - int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element + //int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3); adjustmyCellsCapacity(ID); myCells[ID] = face; @@ -1235,8 +1283,17 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1, } else { - int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element - SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3); + // --- retrieve nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(node1->getId()); + nodeIds.push_back(node2->getId()); + nodeIds.push_back(node3->getId()); + + SMDS_MeshFace * face = 0; + SMDS_VtkFace *facevtk = myFacePool->getNew(); + facevtk->init(nodeIds, this); + face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; myInfo.myNbTriangles++; @@ -1273,8 +1330,18 @@ SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1, } else { - //MESSAGE("createQuadrangle " << ID); - SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4); + // --- retrieve nodes ID + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(node1->getId()); + nodeIds.push_back(node2->getId()); + nodeIds.push_back(node3->getId()); + nodeIds.push_back(node4->getId()); + + SMDS_MeshFace * face = 0; + SMDS_VtkFace *facevtk = myFacePool->getNew(); + facevtk->init(nodeIds, this); + face = facevtk; adjustmyCellsCapacity(ID); myCells[ID] = face; myInfo.myNbQuadrangles++; @@ -1375,6 +1442,7 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, const SMDS_MeshNode * nodes[], const int nbnodes) { + MYASSERT(0); // REVOIR LES TYPES // keep current nodes of elem set oldNodes; SMDS_ElemIteratorPtr itn = element->nodesIterator(); @@ -1396,7 +1464,7 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element, } case SMDSAbs_Edge: { if ( nbnodes == 2 ) { - if ( SMDS_MeshEdge* edge = dynamic_cast( elem )) + if ( SMDS_VtkEdge* edge = dynamic_cast( elem )) Ok = edge->ChangeNodes( nodes[0], nodes[1] ); } else if ( nbnodes == 3 ) { @@ -1610,7 +1678,14 @@ SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1, //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory(); int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element adjustmyCellsCapacity(ID); - toReturn=new SMDS_MeshEdge(node1,node2); + vector nodeIds; + nodeIds.clear(); + nodeIds.push_back(node1->getId()); + nodeIds.push_back(node2->getId()); + + SMDS_VtkEdge *edgevtk = myEdgePool->getNew(); + edgevtk->init(nodeIds, this); + toReturn = edgevtk; myCells[ID] = toReturn; myInfo.myNbEdges++; } @@ -1708,7 +1783,8 @@ SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1, SMDS_MeshFace * toReturn=NULL; toReturn = const_cast(FindFace(node1,node2,node3)); if(toReturn==NULL) { - toReturn = createTriangle(node1,node2,node3); + int ID = myElementIDFactory->GetFreeID(); + toReturn = createTriangle(node1,node2,node3, ID); } return toReturn; } @@ -1892,7 +1968,10 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1, const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const { if ((IDelem < 0) || IDelem >= myCells.size()) - return 0; + { + MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size()); + return 0; + } return myCells[IDelem]; } @@ -2441,7 +2520,9 @@ static set * intersectionOfSets( } /////////////////////////////////////////////////////////////////////////////// -/// Return the list of finit elements owning the given element +/// Return the list of finite elements owning the given element: elements +/// containing all the nodes of the given element, for instance faces and +/// volumes containing a given edge. /////////////////////////////////////////////////////////////////////////////// static set * getFinitElements(const SMDS_MeshElement * element) { @@ -2453,16 +2534,24 @@ static set * getFinitElements(const SMDS_MeshElement * int i=0; while(itNodes->more()) { - const SMDS_MeshNode * n=static_cast(itNodes->next()); + const SMDS_MeshElement* node = itNodes->next(); + MYASSERT(node); + const SMDS_MeshNode * n=static_cast(node); SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); //initSet[i]=set(); while(itFe->more()) - initSet[i].insert(itFe->next()); + { + const SMDS_MeshElement* elem = itFe->next(); + MYASSERT(elem); + initSet[i].insert(elem); + + } i++; } set *retSet=intersectionOfSets(initSet, numberOfSets); + MESSAGE("nb elems " << i << " intersection " << retSet->size()); delete [] initSet; return retSet; } @@ -2577,8 +2666,8 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, /////////////////////////////////////////////////////////////////////////////// ///@param elem The element to delete -///@param removedElems contains all removed elements -///@param removedNodes contains all removed nodes +///@param removedElems to be filled with all removed elements +///@param removedNodes to be filled with all removed nodes ///@param removenodes if true remaining nodes will be removed /////////////////////////////////////////////////////////////////////////////// void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, @@ -2586,6 +2675,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, list& removedNodes, bool removenodes) { + MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes); // get finite elements built on elem set * s1; if (elem->GetType() == SMDSAbs_0DElement || @@ -2638,7 +2728,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, switch((*it)->GetType()) { case SMDSAbs_Node: - MESSAGE("Internal Error: This should not happen"); + MYASSERT("Internal Error: This should not happen"); break; case SMDSAbs_0DElement: myCells[(*it)->GetID()] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ? @@ -2660,6 +2750,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, //MESSAGE( "SMDS: RM elem " << (*it)->GetID() ); removedElems.push_back( (*it) ); myElementIDFactory->ReleaseID((*it)->GetID()); + MYASSERT("problem delete elem") delete (*it); it++; } @@ -2675,6 +2766,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, myInfo.myNbNodes--; myNodeIDFactory->ReleaseID((*it)->GetID()); removedNodes.push_back( (*it) ); + MYASSERT("problem delete node") delete *it; it++; } @@ -2690,16 +2782,19 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem, /////////////////////////////////////////////////////////////////////////////// void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) { + int elemId = elem->GetID(); + //MESSAGE("SMDS_Mesh::RemoveFreeElement " << elemId); SMDSAbs_ElementType aType = elem->GetType(); + SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem); if (aType == SMDSAbs_Node) { // only free node can be removed by this method - const SMDS_MeshNode* n = static_cast(elem); + const SMDS_MeshNode* n = static_cast(todest); SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator(); if (!itFe->more()) { // free node - myNodes[elem->GetID()] = 0; + myNodes[elemId] = 0; myInfo.myNbNodes--; - myNodeIDFactory->ReleaseID(elem->GetID()); - delete elem; + myNodePool->destroy(static_cast(todest)); + myNodeIDFactory->ReleaseID(elemId); } } else { if (hasConstructionEdges() || hasConstructionFaces()) @@ -2715,28 +2810,31 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem) } // in meshes without descendants elements are always free - switch (aType) { + switch (aType) { case SMDSAbs_0DElement: - myCells[elem->GetID()] = 0; + myCells[elemId] = 0; myInfo.remove(elem); + delete elem; break; case SMDSAbs_Edge: - myCells[elem->GetID()] = 0; + myCells[elemId] = 0; myInfo.RemoveEdge(elem); + myEdgePool->destroy(static_cast(todest)); break; case SMDSAbs_Face: - myCells[elem->GetID()] = 0; + myCells[elemId] = 0; myInfo.RemoveFace(elem); + myFacePool->destroy(static_cast(todest)); break; case SMDSAbs_Volume: - myCells[elem->GetID()] = 0; + myCells[elemId] = 0; myInfo.RemoveVolume(elem); + myVolumePool->destroy(static_cast(todest)); break; default: break; } - myElementIDFactory->ReleaseID(elem->GetID()); - delete elem; + myElementIDFactory->ReleaseID(elemId); } } diff --git a/src/SMDS/SMDS_Mesh.hxx b/src/SMDS/SMDS_Mesh.hxx index 438053d73..e471ca99a 100644 --- a/src/SMDS/SMDS_Mesh.hxx +++ b/src/SMDS/SMDS_Mesh.hxx @@ -39,6 +39,8 @@ #include "SMDS_MeshInfo.hxx" #include "SMDS_ElemIterator.hxx" #include "SMDS_VolumeOfNodes.hxx" +#include "SMDS_VtkEdge.hxx" +#include "SMDS_VtkFace.hxx" #include "SMDS_VtkVolume.hxx" #include "ObjectPool.hxx" @@ -48,6 +50,9 @@ #include #include +#include "Utils_SALOME_Exception.hxx" +#define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified")); + class vtkUnstructuredGrid; class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{ @@ -558,7 +563,8 @@ public: typedef std::vector SetOfCells; void updateNodeMinMax(); - inline int fromVtkToSmds(int vtkid) { return myVtkIndex[vtkid]; }; + inline int fromVtkToSmds(int vtkid) { MYASSERT(vtkid>=0); return myVtkIndex[vtkid]; }; + inline int fromSmdsToVtk(int smdsid) { MYASSERT(smdsid>=0); return myIDElements[smdsid]; }; void incrementNodesCapacity(int nbNodes); void incrementCellsCapacity(int nbCells); @@ -572,7 +578,8 @@ private: 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, @@ -615,6 +622,8 @@ private: //! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new ObjectPool* myVolumePool; + ObjectPool* myFacePool; + ObjectPool* myEdgePool; //! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape SetOfNodes myNodes; diff --git a/src/SMDS/SMDS_Mesh0DElement.cxx b/src/SMDS/SMDS_Mesh0DElement.cxx index 4eb47238d..f661b1137 100644 --- a/src/SMDS/SMDS_Mesh0DElement.cxx +++ b/src/SMDS/SMDS_Mesh0DElement.cxx @@ -81,6 +81,11 @@ SMDSAbs_ElementType SMDS_Mesh0DElement::GetType() const return SMDSAbs_0DElement; } +vtkIdType SMDS_Mesh0DElement::GetVtkType() const +{ + return VTK_VERTEX; +} + //======================================================================= //function : elementsIterator //purpose : diff --git a/src/SMDS/SMDS_Mesh0DElement.hxx b/src/SMDS/SMDS_Mesh0DElement.hxx index 5807c3844..cf7896d02 100644 --- a/src/SMDS/SMDS_Mesh0DElement.hxx +++ b/src/SMDS/SMDS_Mesh0DElement.hxx @@ -40,6 +40,7 @@ class SMDS_EXPORT SMDS_Mesh0DElement: public SMDS_MeshCell void Print (std::ostream & OS) const; SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() const; SMDSAbs_EntityType GetEntityType() const {return SMDSEntity_0D;} int NbNodes() const; int NbEdges() const; diff --git a/src/SMDS/SMDS_MeshEdge.cxx b/src/SMDS/SMDS_MeshEdge.cxx index 96112df91..fc1e3c55a 100644 --- a/src/SMDS/SMDS_MeshEdge.cxx +++ b/src/SMDS/SMDS_MeshEdge.cxx @@ -1,160 +1,11 @@ -// Copyright (C) 2007-2008 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 -// -// 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. -// -// 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 -// -// SMESH SMDS : implementaion of Salome mesh data structure -// File : SMDS_MeshEdge.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -// -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif - #include "SMDS_MeshEdge.hxx" -#include "SMDS_IteratorOfElements.hxx" -#include "SMDS_MeshNode.hxx" -#include "utilities.h" - -using namespace std; - -//======================================================================= -//function : SMDS_MeshEdge -//purpose : -//======================================================================= - -SMDS_MeshEdge::SMDS_MeshEdge(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2) -{ - //MESSAGE("SMDS_MeshEdge " << GetID()); - myNodes[0]=node1; - myNodes[1]=node2; -} - -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_MeshEdge::Print(ostream & OS) const -{ - OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] << - ") " << endl; -} - -int SMDS_MeshEdge::NbNodes() const -{ - return 2; -} - -int SMDS_MeshEdge::NbEdges() const -{ - return 1; -} SMDSAbs_ElementType SMDS_MeshEdge::GetType() const { return SMDSAbs_Edge; } -class SMDS_MeshEdge_MyNodeIterator:public SMDS_ElemIterator -{ - const SMDS_MeshNode *const* myNodes; - int myIndex; - public: - SMDS_MeshEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes): - myNodes(nodes),myIndex(0) {} - - bool more() - { - return myIndex<2; - } - - const SMDS_MeshElement* next() - { - myIndex++; - return myNodes[myIndex-1]; - } -}; - -SMDS_ElemIteratorPtr SMDS_MeshEdge:: - elementsIterator(SMDSAbs_ElementType type) const -{ - switch(type) - { - case SMDSAbs_Edge: - return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); - case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_MeshEdge_MyNodeIterator(myNodes)); - default: - return SMDS_ElemIteratorPtr - (new SMDS_IteratorOfElements - (this,type, SMDS_ElemIteratorPtr(new SMDS_MeshEdge_MyNodeIterator(myNodes)))); - } -} - -bool operator<(const SMDS_MeshEdge & e1, const SMDS_MeshEdge & e2) -{ - int id11=e1.myNodes[0]->GetID(); - int id21=e2.myNodes[0]->GetID(); - int id12=e1.myNodes[1]->GetID(); - int id22=e2.myNodes[1]->GetID(); - int tmp; - - if(id11>=id12) - { - tmp=id11; - id11=id12; - id12=tmp; - } - if(id21>=id22) - { - tmp=id21; - id21=id22; - id22=tmp; - } - - if(id11 class SMDS_EXPORT SMDS_MeshEdge:public SMDS_MeshCell { - + public: - SMDS_MeshEdge(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2); - bool ChangeNodes(const SMDS_MeshNode * node1, - const SMDS_MeshNode * node2); - void Print(std::ostream & OS) const; - - virtual SMDSAbs_ElementType GetType() const; - virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; } - int NbNodes() const; - int NbEdges() const; - friend bool operator<(const SMDS_MeshEdge& e1, const SMDS_MeshEdge& e2); - - /*! - * \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; - - protected: - const SMDS_MeshNode* myNodes[3]; - + SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() const; }; #endif diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index 014293912..9fea64cea 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -36,6 +36,9 @@ #include #include +#include +#include + //typedef unsigned short UShortType; typedef short ShortType; @@ -50,6 +53,7 @@ class SMDS_Mesh; */ // ============================================================ + class SMDS_EXPORT SMDS_MeshElement:public SMDS_MeshObject { public: @@ -66,6 +70,7 @@ public: ///Return the type of the current element virtual SMDSAbs_ElementType GetType() const = 0; + virtual vtkIdType GetVtkType() const = 0; virtual bool IsPoly() const { return false; }; virtual bool IsQuadratic() const; //! Return type of entity diff --git a/src/SMDS/SMDS_MeshElementIDFactory.cxx b/src/SMDS/SMDS_MeshElementIDFactory.cxx index f5f3c37c7..412159a38 100644 --- a/src/SMDS/SMDS_MeshElementIDFactory.cxx +++ b/src/SMDS/SMDS_MeshElementIDFactory.cxx @@ -127,7 +127,9 @@ SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID) //======================================================================= void SMDS_MeshElementIDFactory::ReleaseID(const int ID) { + int vtkId = myMesh->myIDElements[ID]; myMesh->myIDElements[ID] = -1; + myMesh->myVtkIndex[vtkId] = -1; SMDS_MeshIDFactory::ReleaseID(ID); if (ID == myMax) myMax = 0; diff --git a/src/SMDS/SMDS_MeshFace.cxx b/src/SMDS/SMDS_MeshFace.cxx index a4a19f03f..a3219e870 100644 --- a/src/SMDS/SMDS_MeshFace.cxx +++ b/src/SMDS/SMDS_MeshFace.cxx @@ -27,3 +27,8 @@ SMDSAbs_ElementType SMDS_MeshFace::GetType() const { return SMDSAbs_Face; } + +vtkIdType SMDS_MeshFace::GetVtkType() const +{ + return VTK_POLY_LINE; // --- must be reimplemented in derived classes +} diff --git a/src/SMDS/SMDS_MeshFace.hxx b/src/SMDS/SMDS_MeshFace.hxx index 3a1fa1b29..8013e70e3 100644 --- a/src/SMDS/SMDS_MeshFace.hxx +++ b/src/SMDS/SMDS_MeshFace.hxx @@ -34,6 +34,7 @@ class SMDS_EXPORT SMDS_MeshFace:public SMDS_MeshCell { public: SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() const; }; #endif diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 55a90c5cc..f7fe97cd3 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -64,6 +64,7 @@ void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, do myID = id; myMeshId = meshId; myShapeId = shapeId; + myIdInShape = -1; //MESSAGE("Node " << myID << " (" << x << ", " << y << ", " << z << ")"); SMDS_Mesh* mesh = SMDS_Mesh::_meshList[myMeshId]; vtkUnstructuredGrid * grid = mesh->getGrid(); @@ -118,8 +119,10 @@ SMDS_MeshNode::~SMDS_MeshNode() void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) { - MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID()); - SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myID, parent->GetID()); // -PR- GetVtkID ? + //MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID()); + const SMDS_MeshCell* cell = dynamic_cast(parent); + MYASSERT(cell); + SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myID, cell->getVtkId()); } //======================================================================= @@ -299,6 +302,11 @@ SMDSAbs_ElementType SMDS_MeshNode::GetType() const return SMDSAbs_Node; } +vtkIdType SMDS_MeshNode::GetVtkType() const +{ + return VTK_VERTEX; +} + //======================================================================= //function : AddInverseElement //purpose : diff --git a/src/SMDS/SMDS_MeshNode.hxx b/src/SMDS/SMDS_MeshNode.hxx index ffe1c499e..1e778e655 100644 --- a/src/SMDS/SMDS_MeshNode.hxx +++ b/src/SMDS/SMDS_MeshNode.hxx @@ -57,6 +57,7 @@ public: void SetPosition(const SMDS_PositionPtr& aPos); const SMDS_PositionPtr& GetPosition() const; SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() const; SMDSAbs_EntityType GetEntityType() const {return SMDSEntity_Node;} int NbNodes() const; void setXYZ(double x, double y, double z); diff --git a/src/SMDS/SMDS_MeshVolume.cxx b/src/SMDS/SMDS_MeshVolume.cxx index 574b5b0ff..d0b1433b6 100644 --- a/src/SMDS/SMDS_MeshVolume.cxx +++ b/src/SMDS/SMDS_MeshVolume.cxx @@ -35,3 +35,7 @@ SMDSAbs_ElementType SMDS_MeshVolume::GetType() const return SMDSAbs_Volume; } +vtkIdType SMDS_MeshVolume::GetVtkType() const +{ + return VTK_CONVEX_POINT_SET; // --- must be reimplemented in derived classes +} diff --git a/src/SMDS/SMDS_MeshVolume.hxx b/src/SMDS/SMDS_MeshVolume.hxx index 03f44d355..e3eea3f97 100644 --- a/src/SMDS/SMDS_MeshVolume.hxx +++ b/src/SMDS/SMDS_MeshVolume.hxx @@ -35,5 +35,6 @@ class SMDS_EXPORT SMDS_MeshVolume:public SMDS_MeshCell public: SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() const; }; #endif diff --git a/src/SMDS/SMDS_QuadraticEdge.cxx b/src/SMDS/SMDS_QuadraticEdge.cxx index 147b62bf6..a232bc998 100644 --- a/src/SMDS/SMDS_QuadraticEdge.cxx +++ b/src/SMDS/SMDS_QuadraticEdge.cxx @@ -40,7 +40,7 @@ using namespace std; SMDS_QuadraticEdge::SMDS_QuadraticEdge(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2, const SMDS_MeshNode * node12) - :SMDS_MeshEdge(node1,node2) + :SMDS_LinearEdge(node1,node2) { myNodes[2]=node12; } diff --git a/src/SMDS/SMDS_QuadraticEdge.hxx b/src/SMDS/SMDS_QuadraticEdge.hxx index cdab680e2..f2be6e135 100644 --- a/src/SMDS/SMDS_QuadraticEdge.hxx +++ b/src/SMDS/SMDS_QuadraticEdge.hxx @@ -28,10 +28,10 @@ #include "SMESH_SMDS.hxx" -#include "SMDS_MeshEdge.hxx" +#include "SMDS_LinearEdge.hxx" #include -class SMDS_EXPORT SMDS_QuadraticEdge: public SMDS_MeshEdge +class SMDS_EXPORT SMDS_QuadraticEdge: public SMDS_LinearEdge { public: diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index 99bd56fb6..7a2b682a1 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -43,6 +43,9 @@ SMDS_CellLinks::~SMDS_CellLinks() { } +/*! initialize an SMDS_CellLinks instance instead of a vtkCellLinks instance + * + */ void SMDS_UnstructuredGrid::BuildLinks() { // Remove the old links if they are already built diff --git a/src/SMDS/SMDS_VolumeOfFaces.hxx b/src/SMDS/SMDS_VolumeOfFaces.hxx index 95b262faa..3c9ca131e 100644 --- a/src/SMDS/SMDS_VolumeOfFaces.hxx +++ b/src/SMDS/SMDS_VolumeOfFaces.hxx @@ -54,7 +54,7 @@ class SMDS_EXPORT SMDS_VolumeOfFaces:public SMDS_MeshVolume const SMDS_MeshFace * face5, const SMDS_MeshFace * face6); - virtual SMDSAbs_EntityType GetEntityType() const; + virtual SMDSAbs_EntityType GetEntityType() const; void Print(std::ostream & OS) const; int NbFaces() const; diff --git a/src/SMDS/SMDS_VtkCellIterator.cxx b/src/SMDS/SMDS_VtkCellIterator.cxx index 82d5460cd..497f649aa 100644 --- a/src/SMDS/SMDS_VtkCellIterator.cxx +++ b/src/SMDS/SMDS_VtkCellIterator.cxx @@ -1,12 +1,57 @@ - #include "SMDS_VtkCellIterator.hxx" -SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId): - _mesh(mesh), _cellId(vtkCellId), _index(0) -{ +SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) : + _mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType) +{ vtkUnstructuredGrid* grid = _mesh->getGrid(); - _vtkIdList = grid->GetCell(_cellId)->GetPointIds(); + _vtkIdList = vtkIdList::New(); + grid->GetCellPoints(_cellId, _vtkIdList); _nbNodes = _vtkIdList->GetNumberOfIds(); + vtkIdType tempid; + switch (_type) + { + case SMDSEntity_Tetra: + { + tempid = _vtkIdList->GetId(1); + _vtkIdList->SetId(1, _vtkIdList->GetId(2)); + _vtkIdList->SetId(2, tempid); + break; + } + case SMDSEntity_Pyramid: + { + tempid = _vtkIdList->GetId(1); + _vtkIdList->SetId(1, _vtkIdList->GetId(3)); + _vtkIdList->SetId(3, tempid); + break; + } + case SMDSEntity_Penta: + { + tempid = _vtkIdList->GetId(1); + _vtkIdList->SetId(1, _vtkIdList->GetId(2)); + _vtkIdList->SetId(2, tempid); + tempid = _vtkIdList->GetId(4); + _vtkIdList->SetId(4, _vtkIdList->GetId(5)); + _vtkIdList->SetId(5, tempid); + break; + } + case SMDSEntity_Hexa: + { + tempid = _vtkIdList->GetId(1); + _vtkIdList->SetId(1, _vtkIdList->GetId(3)); + _vtkIdList->SetId(3, tempid); + tempid = _vtkIdList->GetId(5); + _vtkIdList->SetId(5, _vtkIdList->GetId(7)); + _vtkIdList->SetId(7, tempid); + break; + } + default: + break; + } +} + +SMDS_VtkCellIterator::~SMDS_VtkCellIterator() +{ + _vtkIdList->Delete(); } bool SMDS_VtkCellIterator::more() diff --git a/src/SMDS/SMDS_VtkCellIterator.hxx b/src/SMDS/SMDS_VtkCellIterator.hxx index f73985162..9051ce000 100644 --- a/src/SMDS/SMDS_VtkCellIterator.hxx +++ b/src/SMDS/SMDS_VtkCellIterator.hxx @@ -3,6 +3,7 @@ #include "SMDS_ElemIterator.hxx" #include "SMDS_Mesh.hxx" +#include "SMDSAbs_ElementType.hxx" #include #include @@ -10,7 +11,8 @@ class SMDS_VtkCellIterator : public SMDS_ElemIterator { public: - SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId); + SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType); + virtual ~SMDS_VtkCellIterator(); virtual bool more(); virtual const SMDS_MeshElement* next(); protected: @@ -18,6 +20,7 @@ protected: int _cellId; int _index; int _nbNodes; + SMDSAbs_EntityType _type; vtkIdList* _vtkIdList; }; diff --git a/src/SMDS/SMDS_VtkEdge.cxx b/src/SMDS/SMDS_VtkEdge.cxx new file mode 100644 index 000000000..d35f63542 --- /dev/null +++ b/src/SMDS/SMDS_VtkEdge.cxx @@ -0,0 +1,86 @@ +#include "SMDS_VtkEdge.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_Mesh.hxx" +#include "SMDS_VtkCellIterator.hxx" + +#include "utilities.h" + +#include + +using namespace std; + +SMDS_VtkEdge::SMDS_VtkEdge() +{ +} + +SMDS_VtkEdge::SMDS_VtkEdge(std::vector nodeIds, SMDS_Mesh* mesh) +{ + init(nodeIds, mesh); +} + +SMDS_VtkEdge::~SMDS_VtkEdge() +{ +} + +void SMDS_VtkEdge::init(std::vector nodeIds, SMDS_Mesh* mesh) +{ + vtkUnstructuredGrid* grid = mesh->getGrid(); + myIdInShape = -1; + myMeshId = mesh->getMeshId(); + myVtkID = grid->InsertNextLinkedCell(VTK_LINE, nodeIds.size(), &nodeIds[0]); +} + +bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1, + const SMDS_MeshNode * node2) +{ + return true; +} + +void SMDS_VtkEdge::Print(std::ostream & OS) const +{ + OS << "edge <" << GetID() << "> : "; +} + +int SMDS_VtkEdge::NbNodes() const +{ + return 2; +} + +int SMDS_VtkEdge::NbEdges() const +{ + return 1; +} + +SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const +{ + return SMDSEntity_Edge; +} + +vtkIdType SMDS_VtkEdge::GetVtkType() const +{ + return VTK_LINE; +} + +/*! + * \brief Return node by its index + * \param ind - node index + * \retval const SMDS_MeshNode* - the node + */ +const SMDS_MeshNode* +SMDS_VtkEdge::GetNode(const int ind) const +{ + return 0; +} + +SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const +{ + switch (type) + { + case SMDSAbs_Node: + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator( + SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); + default: + MESSAGE("ERROR : Iterator not implemented"); + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + } +} diff --git a/src/SMDS/SMDS_VtkEdge.hxx b/src/SMDS/SMDS_VtkEdge.hxx new file mode 100644 index 000000000..a87ed3ff3 --- /dev/null +++ b/src/SMDS/SMDS_VtkEdge.hxx @@ -0,0 +1,33 @@ +#ifndef _SMDS_VTKEDGE_HXX_ +#define _SMDS_VTKEDGE_HXX_ + +#include "SMESH_SMDS.hxx" + +#include "SMDS_MeshEdge.hxx" +#include +#include + +class SMDS_EXPORT SMDS_VtkEdge: public SMDS_MeshEdge +{ + +public: + SMDS_VtkEdge(); + SMDS_VtkEdge(std::vector nodeIds, SMDS_Mesh* mesh); + ~SMDS_VtkEdge(); + void init(std::vector nodeIds, SMDS_Mesh* mesh); + bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2); + + void Print(std::ostream & OS) const; + int NbNodes() const; + int NbEdges() const; + + virtual vtkIdType GetVtkType() const; + virtual SMDSAbs_EntityType GetEntityType() const; + virtual const SMDS_MeshNode* GetNode(const int ind) const; + +protected: + SMDS_ElemIteratorPtr + elementsIterator(SMDSAbs_ElementType type) const; + +}; +#endif diff --git a/src/SMDS/SMDS_VtkFace.cxx b/src/SMDS/SMDS_VtkFace.cxx new file mode 100644 index 000000000..57ff907f4 --- /dev/null +++ b/src/SMDS/SMDS_VtkFace.cxx @@ -0,0 +1,104 @@ +#include "SMDS_VtkFace.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_Mesh.hxx" +#include "SMDS_VtkCellIterator.hxx" + +#include "utilities.h" + +#include + +using namespace std; + +SMDS_VtkFace::SMDS_VtkFace() +{ +} + +SMDS_VtkFace::SMDS_VtkFace(std::vector nodeIds, SMDS_Mesh* mesh) +{ + init(nodeIds, mesh); +} + +SMDS_VtkFace::~SMDS_VtkFace() +{ +} + +void SMDS_VtkFace::init(std::vector nodeIds, SMDS_Mesh* mesh) +{ + vtkUnstructuredGrid* grid = mesh->getGrid(); + myIdInShape = -1; + myMeshId = mesh->getMeshId(); + vtkIdType aType = VTK_TRIANGLE; + if (nodeIds.size() == 4) + aType = VTK_QUAD; + myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); +} + +bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes) +{ + return true; +} + +void SMDS_VtkFace::Print(std::ostream & OS) const +{ + OS << "edge <" << GetID() << "> : "; +} + +int SMDS_VtkFace::NbEdges() const +{ + return NbNodes(); +} + +int SMDS_VtkFace::NbFaces() const +{ + return 1; +} + +int SMDS_VtkFace::NbNodes() const +{ + vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); + int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints(); + return nbPoints; +} + +/*! + * \brief Return node by its index + * \param ind - node index + * \retval const SMDS_MeshNode* - the node + */ +const SMDS_MeshNode* +SMDS_VtkFace::GetNode(const int ind) const +{ + return 0; +} + +SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const +{ + int nbNodes = NbNodes(); + if (nbNodes == 3) + return SMDSEntity_Triangle; + else + return SMDSEntity_Quadrangle; +} + +vtkIdType SMDS_VtkFace::GetVtkType() const +{ + int nbNodes = NbNodes(); + if (nbNodes == 3) + return VTK_TRIANGLE; + else + return VTK_QUAD; + +} + +SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const +{ + switch (type) + { + case SMDSAbs_Node: + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); + default: + MESSAGE("ERROR : Iterator not implemented"); + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + } +} + diff --git a/src/SMDS/SMDS_VtkFace.hxx b/src/SMDS/SMDS_VtkFace.hxx new file mode 100644 index 000000000..08897bc79 --- /dev/null +++ b/src/SMDS/SMDS_VtkFace.hxx @@ -0,0 +1,33 @@ +#ifndef _SMDS_VTKFACE_HXX_ +#define _SMDS_VTKFACE_HXX_ + +#include "SMESH_SMDS.hxx" + +#include "SMDS_MeshFace.hxx" +#include +#include + +class SMDS_EXPORT SMDS_VtkFace: public SMDS_MeshFace +{ +public: + SMDS_VtkFace(); + SMDS_VtkFace(std::vector nodeIds, SMDS_Mesh* mesh); + ~SMDS_VtkFace(); + void init(std::vector nodeIds, SMDS_Mesh* mesh); + bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes); + + void Print(std::ostream & OS) const; + int NbEdges() const; + int NbFaces() const; + int NbNodes() const; + + virtual vtkIdType GetVtkType() const; + virtual SMDSAbs_EntityType GetEntityType() const; + virtual const SMDS_MeshNode* GetNode(const int ind) const; + +protected: + SMDS_ElemIteratorPtr + elementsIterator(SMDSAbs_ElementType type) const; +}; + +#endif diff --git a/src/SMDS/SMDS_VtkVolume.cxx b/src/SMDS/SMDS_VtkVolume.cxx index 733564bbf..aa0b5d79b 100644 --- a/src/SMDS/SMDS_VtkVolume.cxx +++ b/src/SMDS/SMDS_VtkVolume.cxx @@ -21,8 +21,18 @@ SMDS_VtkVolume::SMDS_VtkVolume(std::vector nodeIds, SMDS_Mesh* mesh) void SMDS_VtkVolume::init(std::vector nodeIds, SMDS_Mesh* mesh) { vtkUnstructuredGrid* grid = mesh->getGrid(); + myIdInShape = -1; myMeshId = mesh->getMeshId(); - myVtkID = grid->InsertNextLinkedCell(GetType(), nodeIds.size(), &nodeIds[0]); + vtkIdType aType = VTK_TETRA; + switch(nodeIds.size()) + { + case 4: aType = VTK_TETRA; break; + case 5: aType = VTK_PYRAMID; break; + case 6: aType = VTK_WEDGE; break; + case 8: + default: aType = VTK_HEXAHEDRON; break; + } + myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]); } bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], @@ -79,7 +89,7 @@ SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) switch(type) { case SMDSAbs_Node: - return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID)); + return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType())); default: MESSAGE("ERROR : Iterator not implemented"); return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); @@ -110,7 +120,21 @@ SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const case 5: aType = SMDSEntity_Pyramid; break; case 6: aType = SMDSEntity_Penta; break; case 8: - default: aType = SMDSEntity_Hexa; break; + default: aType = SMDSEntity_Hexa; break; } return aType; } + +vtkIdType SMDS_VtkVolume::GetVtkType() const +{ + vtkIdType aType = VTK_TETRA; + switch(NbNodes()) + { + case 4: aType = VTK_TETRA; break; + case 5: aType = VTK_PYRAMID; break; + case 6: aType = VTK_WEDGE; break; + case 8: + default: aType = VTK_HEXAHEDRON; break; + } + return aType; +} diff --git a/src/SMDS/SMDS_VtkVolume.hxx b/src/SMDS/SMDS_VtkVolume.hxx index f58bb3a6a..683bfb1d7 100644 --- a/src/SMDS/SMDS_VtkVolume.hxx +++ b/src/SMDS/SMDS_VtkVolume.hxx @@ -21,14 +21,9 @@ public: int NbFaces() const; int NbNodes() const; int NbEdges() const; - virtual SMDSAbs_ElementType GetType() const; + virtual SMDSAbs_ElementType GetType() const; + virtual vtkIdType GetVtkType() 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: diff --git a/src/SMESHDS/SMESHDS_SubMesh.cxx b/src/SMESHDS/SMESHDS_SubMesh.cxx index d8c4d1eae..6093089a4 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.cxx +++ b/src/SMESHDS/SMESHDS_SubMesh.cxx @@ -66,9 +66,10 @@ bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDele { // if ( !IsComplexSubmesh() && NbElements() ) { - if (!isElemDeleted) // alive element has valid ID and can be found + if (!isElemDeleted) // alive element has valid ID and can be found { int idInSubShape = ME->getIdInShape(); + //MESSAGE("SMESHDS_SubMesh::RemoveElement " << idInSubShape << " " << ME->GetID()); assert(idInSubShape >= 0); assert(idInSubShape < myElements.size()); myElements[idInSubShape] = 0; // this vector entry is no more used @@ -117,6 +118,7 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted) if (!isNodeDeleted) // alive node has valid ID and can be found { int idInSubShape = N->getIdInShape(); + //MESSAGE("SMESHDS_SubMesh::RemoveNode " << idInSubShape << " " << N->GetID()); assert(idInSubShape >= 0); assert(idInSubShape < myNodes.size()); myNodes[idInSubShape] = 0; // this vector entry is no more used @@ -175,14 +177,27 @@ int SMESHDS_SubMesh::NbNodes() const // class MySetIterator // ===================== -template class MySetIterator: - public SMDS_SetIterator + template class MySetIterator : public SMDS_Iterator { - typedef SMDS_SetIterator TFather; - public: - MySetIterator(const TSET& s):TFather(s.begin(),s.end()) - { - } +protected: + typename TSET::const_iterator _it, _end; +public: + MySetIterator(const TSET& table) + : _it(table.begin()), _end(table.end()) + { + } + + virtual bool more() + { + while((_it != _end) && (*_it == 0)) + _it++; + return (_it != _end); + } + + virtual ELEM next() + { + return *_it++; + } }; // ===================== @@ -258,7 +273,7 @@ SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const if ( IsComplexSubmesh() ) return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes )); - return SMDS_ElemIteratorPtr(new MySetIterator(myElements)); + return SMDS_ElemIteratorPtr(new MySetIterator >(myElements)); } //======================================================================= @@ -271,7 +286,7 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const if ( IsComplexSubmesh() ) return SMDS_NodeIteratorPtr( new MyNodeIterator( mySubMeshes )); - return SMDS_NodeIteratorPtr(new MySetIterator(myNodes)); + return SMDS_NodeIteratorPtr(new MySetIterator >(myNodes)); } //======================================================================= diff --git a/src/SMESHDS/SMESHDS_SubMesh.hxx b/src/SMESHDS/SMESHDS_SubMesh.hxx index 90ed79e20..ca5e3098d 100644 --- a/src/SMESHDS/SMESHDS_SubMesh.hxx +++ b/src/SMESHDS/SMESHDS_SubMesh.hxx @@ -69,10 +69,8 @@ class SMESHDS_EXPORT SMESHDS_SubMesh private: - typedef std::vector TElemSet; - - TElemSet myElements; - TElemSet myNodes; + std::vector myElements; + std::vector myNodes; int myUnusedIdNodes; int myUnusedIdElements; diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx index 7b5db1430..d19fa7d1f 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx @@ -350,24 +350,24 @@ namespace SMESH MESSAGE ( "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB << ", usedMB=" << usedMB ); #endif - bool continu = false; - if ( usedMB * 10 > freeMB ) - // even dont try to show - SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_NO_MESH_VISUALIZATION")); - else - // there is a chance to succeed - continu = SUIT_MessageBox::warning - (SMESHGUI::desktop(), - QObject::tr("SMESH_WRN_WARNING"), - QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes; - if ( !continu ) { - // remove the corresponding actors from all views - RemoveVisualObjectWithActors( theEntry ); - aVisualObj.reset(); - } +// bool continu = false; +// if ( usedMB * 10 > freeMB ) +// // even dont try to show +// SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"), +// QObject::tr("SMESH_NO_MESH_VISUALIZATION")); +// else +// // there is a chance to succeed +// continu = SUIT_MessageBox::warning +// (SMESHGUI::desktop(), +// QObject::tr("SMESH_WRN_WARNING"), +// QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"), +// SUIT_MessageBox::Yes | SUIT_MessageBox::No, +// SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes; +// if ( !continu ) { +// // remove the corresponding actors from all views +// RemoveVisualObjectWithActors( theEntry ); +// aVisualObj.reset(); +// } } } diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 000bc95e8..a5bc40799 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -27,7 +27,7 @@ #include "SMESH_MeshEditor_i.hxx" #include "SMDS_Mesh0DElement.hxx" -#include "SMDS_MeshEdge.hxx" +#include "SMDS_LinearEdge.hxx" #include "SMDS_MeshFace.hxx" #include "SMDS_MeshVolume.hxx" #include "SMDS_PolyhedralVolumeOfNodes.hxx" @@ -3663,7 +3663,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x, TIDSortedElemSet::iterator nIt = linkedNodes.begin(); for ( ; nIt != linkedNodes.end(); ++nIt ) { - SMDS_MeshEdge edge( node, cast2Node( *nIt )); + SMDS_LinearEdge edge( node, cast2Node( *nIt )); tmpMesh.Copy( &edge ); } // move copied node