X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshNode.cxx;h=37d6b5b42eec3d93c631bae3b6d49346dbd254a3;hp=5499f8b7d7fd3db34b7868c4220137fdda5700c8;hb=d9f4b53e489dd5857db264ede6acded7b076c9f1;hpb=c98d9fcd7f02c1f1f5c24dd3e709ed75228d66c4 diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 5499f8b7d..37d6b5b42 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2022 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 @@ -20,65 +20,33 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SMESH SMDS : implementaion of Salome mesh data structure +// SMESH SMDS : implementation of Salome mesh data structure // #ifdef _MSC_VER #pragma warning(disable:4786) #endif #include "SMDS_MeshNode.hxx" -#include "SMDS_SpacePosition.hxx" -#include "SMDS_IteratorOfElements.hxx" + +#include "SMDS_ElementFactory.hxx" #include "SMDS_Mesh.hxx" -#include +#include "SMDS_SetIterator.hxx" +#include "SMDS_SpacePosition.hxx" -#include "utilities.h" -#include "Utils_SALOME_Exception.hxx" +#include +#include #include +#include -using namespace std; - -int SMDS_MeshNode::nbNodes =0; - -//======================================================================= -//function : SMDS_MeshNode -//purpose : -//======================================================================= -SMDS_MeshNode::SMDS_MeshNode() : - SMDS_MeshElement(-1, -1, 0), - myPosition(SMDS_SpacePosition::originSpacePosition()) -{ - nbNodes++; -} - -SMDS_MeshNode::SMDS_MeshNode(int id, int meshId, int shapeId, double x, double y, double z): - SMDS_MeshElement(id, meshId, shapeId), - myPosition(SMDS_SpacePosition::originSpacePosition()) -{ - nbNodes++; - init(id, meshId, shapeId, x, y ,z); -} +#include -void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, double z) +void SMDS_MeshNode::init(double x, double y, double z) { - SMDS_MeshElement::init(id, meshId, shapeId); - myVtkID = id -1; - assert(myVtkID >= 0); - //MESSAGE("Node " << myID << " " << myVtkID << " (" << x << ", " << y << ", " << z << ")"); - SMDS_Mesh* mesh = SMDS_Mesh::_meshList[myMeshId]; - SMDS_UnstructuredGrid * grid = mesh->getGrid(); + SMDS_UnstructuredGrid * grid = getGrid(); vtkPoints *points = grid->GetPoints(); - points->InsertPoint(myVtkID, x, y, z); - SMDS_CellLinks *cellLinks = dynamic_cast(grid->GetCellLinks()); - assert(cellLinks); - cellLinks->ResizeForPoint( myVtkID ); -} - -SMDS_MeshNode::~SMDS_MeshNode() -{ - nbNodes--; - if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() ) - delete myPosition, myPosition = 0; + points->InsertPoint( GetVtkID(), x, y, z ); + if ( grid->HasLinks() ) + grid->GetLinks()->ResizeForPoint( GetVtkID() ); } //======================================================================= @@ -86,12 +54,10 @@ SMDS_MeshNode::~SMDS_MeshNode() //purpose : //======================================================================= -void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) +void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem) { - //MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID()); - const SMDS_MeshCell* cell = dynamic_cast(parent); - MYASSERT(cell); - SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, cell->getVtkId()); + if ( getGrid()->HasLinks() ) + getGrid()->RemoveReferenceToCell( GetVtkID(), elem->GetVtkID()); } //======================================================================= @@ -101,7 +67,7 @@ void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) void SMDS_MeshNode::Print(ostream & OS) const { - OS << "Node <" << myID << "> : X = " << X() << " Y = " + OS << "Node <" << GetID() << "> : X = " << X() << " Y = " << Y() << " Z = " << Z() << endl; } @@ -110,23 +76,20 @@ void SMDS_MeshNode::Print(ostream & OS) const //purpose : //======================================================================= -void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos) +void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos, int shapeID) { - if ( myPosition && - myPosition != SMDS_SpacePosition::originSpacePosition() && - myPosition != aPos ) - delete myPosition; - myPosition = aPos; + myHolder->SetPosition( this, aPos, shapeID ); } //======================================================================= //function : GetPosition -//purpose : +//purpose : Return a position of this node on shape +//warning : result is std::unique_ptr ! //======================================================================= -const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const +SMDS_PositionPtr SMDS_MeshNode::GetPosition() const { - return myPosition; + return myHolder->GetPosition( this ); } //======================================================================= @@ -135,132 +98,120 @@ const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const */ //======================================================================= -class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator +namespace { -private: - SMDS_Mesh* myMesh; - vtkIdType* myCells; - int myNcells; - SMDSAbs_ElementType myType; - int iter; - vector cellList; - -public: - SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh, vtkIdType* cells, int ncells, SMDSAbs_ElementType type) : - myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0) + struct InverseIterator: public SMDS_ElemIterator { - cellList.reserve( ncells ); - if (type == SMDSAbs_All) - cellList.assign( cells, cells + ncells ); - else - for (int i = 0; i < ncells; i++) + const SMDS_Mesh* myMesh; + size_t myIter; + std::vector myCellList; + + InverseIterator(const SMDS_Mesh * mesh = 0, + const vtkIdType* cells = 0, + const int ncells = 0, + SMDSAbs_ElementType type = SMDSAbs_All) + : myMesh(mesh), myIter(0) + { + if ( ncells ) { - int vtkId = cells[i]; - int smdsId = myMesh->fromVtkToSmds(vtkId); - const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); - if (elem->GetType() == type) + myCellList.reserve( ncells ); + if (type == SMDSAbs_All) + { + myCellList.assign( cells, cells + ncells ); + } + else { - cellList.push_back(vtkId); + for (int i = 0; i < ncells; i++) + { + vtkIdType vtkId = cells[i]; + smIdType smdsId = myMesh->FromVtkToSmds( vtkId ); + const SMDS_MeshElement* elem = myMesh->FindElement( smdsId ); + if ( elem->GetType() == type ) + { + myCellList.push_back(vtkId); + } + } } } - myCells = cellList.empty() ? 0 : &cellList[0]; - myNcells = cellList.size(); - } + } - bool more() - { - return (iter < myNcells); - } + bool more() + { + return ( myIter < myCellList.size() ); + } - const SMDS_MeshElement* next() - { - int vtkId = myCells[iter]; - int smdsId = myMesh->fromVtkToSmds(vtkId); - const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); - if (!elem) + const SMDS_MeshElement* next() { - MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element"); - throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element"); + vtkIdType vtkId = myCellList[ myIter++ ]; + smIdType smdsId = myMesh->FromVtkToSmds( vtkId ); + const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); + if (!elem) + { + MESSAGE("InverseIterator problem Null element"); + throw SALOME_Exception("InverseIterator problem Null element"); + } + return elem; } - iter++; - return elem; - } -}; + }; -SMDS_ElemIteratorPtr SMDS_MeshNode::GetInverseElementIterator(SMDSAbs_ElementType type) const -{ - vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); - return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type)); -} + //======================================================================= + /*! + * \brief Iterator on a node + */ + //======================================================================= -// Same as GetInverseElementIterator but the create iterator only return -// wanted type elements. -class SMDS_MeshNode_MyIterator:public SMDS_ElemIterator -{ -private: - SMDS_Mesh* myMesh; - vtkIdType* myCells; - int myNcells; - SMDSAbs_ElementType myType; - int iter; - vector myFiltCells; - -public: - SMDS_MeshNode_MyIterator(SMDS_Mesh *mesh, - vtkIdType* cells, - int ncells, - SMDSAbs_ElementType type): - myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0) + template< class ELEM_ITERATOR > + struct Iterator : public ELEM_ITERATOR { - //MESSAGE("myNcells " << myNcells); - for (; iterfromVtkToSmds(vtkId); - //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId); - const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); - if (elem->GetType() == type) - myFiltCells.push_back((SMDS_MeshElement*)elem); + return myNode; } - myNcells = myFiltCells.size(); - //MESSAGE("myNcells " << myNcells); - iter = 0; - //MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells); - } + virtual element_type next() + { + element_type res = static_cast( myNode ); + myNode = 0; + return res; + } + }; +} - bool more() +SMDS_ElemIteratorPtr SMDS_MeshNode::GetInverseElementIterator(SMDSAbs_ElementType type) const +{ + if ( GetMesh()->NbElements() > 0 ) // avoid building links { - return (iter< myNcells); + vtkCellLinks::Link& l = getGrid()->GetLinks()->GetLink( GetVtkID() ); + return boost::make_shared< InverseIterator >( GetMesh(), l.cells, l.ncells, type ); } - - const SMDS_MeshElement* next() + else { - const SMDS_MeshElement* elem = myFiltCells[iter]; - iter++; - return elem; + return boost::make_shared< InverseIterator >(); } -}; +} -SMDS_ElemIteratorPtr SMDS_MeshNode:: -elementsIterator(SMDSAbs_ElementType type) const +SMDS_ElemIteratorPtr SMDS_MeshNode::nodesIterator() const { - if(type==SMDSAbs_Node) - return SMDS_MeshElement::elementsIterator(SMDSAbs_Node); - else - { - vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); - return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type)); - } + return boost::make_shared< Iterator< SMDS_ElemIterator > >( this ); } -int SMDS_MeshNode::NbNodes() const +SMDS_NodeIteratorPtr SMDS_MeshNode::nodeIterator() const { - return 1; + return boost::make_shared< Iterator< SMDS_NodeIterator > >( this ); +} + +const SMDS_MeshNode* SMDS_MeshNode::GetNode(const int ind) const +{ + return ind == 0 ? this : 0; } double* SMDS_MeshNode::getCoord() const { - return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID); + return getGrid()->GetPoint( GetVtkID() ); } double SMDS_MeshNode::X() const @@ -285,43 +236,35 @@ double SMDS_MeshNode::Z() const /*! * \brief thread safe getting coords */ -void SMDS_MeshNode::GetXYZ(double xyz[3]) const -{ - return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID,xyz); -} - -//* resize the vtkPoints structure every SMDS_Mesh::chunkSize points -void SMDS_MeshNode::setXYZ(double x, double y, double z) -{ - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; - vtkPoints *points = mesh->getGrid()->GetPoints(); - points->InsertPoint(myVtkID, x, y, z); - mesh->adjustBoundingBox(x, y, z); - mesh->setMyModified(); -} +//================================================================================ -SMDSAbs_ElementType SMDS_MeshNode::GetType() const +void SMDS_MeshNode::GetXYZ(double xyz[3]) const { - return SMDSAbs_Node; + return getGrid()->GetPoint( GetVtkID(), xyz ); } -vtkIdType SMDS_MeshNode::GetVtkType() const +//================================================================================ +void SMDS_MeshNode::setXYZ( double x, double y, double z ) { - return VTK_VERTEX; + vtkPoints *points = getGrid()->GetPoints(); + points->InsertPoint( GetVtkID(), x, y, z ); + //GetMesh()->adjustBoundingBox(x, y, z); + GetMesh()->setMyModified(); } //======================================================================= //function : AddInverseElement //purpose : //======================================================================= -void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) +void SMDS_MeshNode::AddInverseElement( const SMDS_MeshElement* elem ) { - const SMDS_MeshCell *cell = dynamic_cast (ME); - assert(cell); - SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid(); - vtkCellLinks *Links = grid->GetCellLinks(); - Links->ResizeCellList(myVtkID, 1); - Links->AddCellReference(cell->getVtkId(), myVtkID); + SMDS_UnstructuredGrid* grid = getGrid(); + if ( grid->HasLinks() ) + { + vtkCellLinks *Links = grid->GetLinks(); + Links->ResizeCellList( GetVtkID(), 1 ); + Links->AddCellReference( elem->GetVtkID(), GetVtkID() ); + } } //======================================================================= @@ -330,13 +273,7 @@ void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) //======================================================================= void SMDS_MeshNode::ClearInverseElements() { - SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0); -} - -bool SMDS_MeshNode::emptyInverseElements() -{ - vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); - return (l.ncells == 0); + getGrid()->ResizeCellList( GetVtkID(), 0); } //================================================================================ @@ -347,35 +284,20 @@ bool SMDS_MeshNode::emptyInverseElements() int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const { - vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); - - if ( type == SMDSAbs_All ) - return l.ncells; - int nb = 0; - SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId]; - for (int i=0; iNbElements() > 0 ) // avoid building links { - const SMDS_MeshElement* elem = mesh->FindElement(mesh->fromVtkToSmds(l.cells[i])); - if (elem->GetType() == type) - nb++; - } - return nb; -} + vtkCellLinks::Link& l = mesh->GetGrid()->GetLinks()->GetLink( GetVtkID() ); -/////////////////////////////////////////////////////////////////////////////// -/// To be used with STL set -/////////////////////////////////////////////////////////////////////////////// -bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2) -{ - return e1.getVtkId()FindElement( mesh->FromVtkToSmds( l.cells[i] )); + nb += ( elem->GetType() == type ); } - else return false;*/ + } + return nb; } -