X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshNode.cxx;h=4e5e21fe64fcd0461185ba346a56ced9fadeaff6;hp=20bce63695892d324ac8962a3daa3706a4ffa370;hb=2c607013a23bd4e7ba07e72e0c04dee2c1209cff;hpb=888669652e8ebdff0161e485913c1d3b93e4b5dc diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 20bce6369..4e5e21fe6 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -1,38 +1,85 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 // -// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// SMESH SMDS : implementaion 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_Mesh.hxx" +#include + +#include "utilities.h" +#include "Utils_SALOME_Exception.hxx" +#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(double x, double y, double z): - myX(x), myY(y), myZ(z), - myPosition(SMDS_SpacePosition::originSpacePosition()) +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); +} + +void SMDS_MeshNode::init(int id, int meshId, int shapeId, 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(); + vtkPoints *points = grid->GetPoints(); + points->InsertPoint(myVtkID, x, y, z); + SMDS_CellLinks *cellLinks = dynamic_cast(grid->GetCellLinks()); + assert(cellLinks); + if (myVtkID >= cellLinks->GetLinksSize()) + cellLinks->ResizeL(myVtkID+SMDS_Mesh::chunkSize); +} + +SMDS_MeshNode::~SMDS_MeshNode() +{ + nbNodes--; + if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() ) + delete myPosition, myPosition = 0; } //======================================================================= @@ -42,7 +89,10 @@ SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z): void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) { - myInverseElements.erase(parent); + //MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID()); + const SMDS_MeshCell* cell = dynamic_cast(parent); + MYASSERT(cell); + SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, cell->getVtkId()); } //======================================================================= @@ -52,8 +102,8 @@ void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) void SMDS_MeshNode::Print(ostream & OS) const { - OS << "Node <" << GetID() << "> : X = " << myX << " Y = " - << myY << " Z = " << myZ << endl; + OS << "Node <" << myID << "> : X = " << X() << " Y = " + << Y() << " Z = " << Z() << endl; } //======================================================================= @@ -61,9 +111,13 @@ void SMDS_MeshNode::Print(ostream & OS) const //purpose : //======================================================================= -void SMDS_MeshNode::SetPosition(SMDS_Position * aPos) +void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos) { - myPosition = aPos; + if ( myPosition && + myPosition != SMDS_SpacePosition::originSpacePosition() && + myPosition != aPos ) + delete myPosition; + myPosition = aPos; } //======================================================================= @@ -71,126 +125,188 @@ void SMDS_MeshNode::SetPosition(SMDS_Position * aPos) //purpose : //======================================================================= -SMDS_Position *SMDS_MeshNode::GetPosition() -{ - return myPosition; -} - -const SMDS_Position *SMDS_MeshNode::GetPosition() const -{ - return myPosition; -} -/** -*/ -SMDS_Iterator * SMDS_MeshNode:: - GetInverseElementIterator() const -{ - class SMDS_InverseElementIterator:public SMDS_Iterator - { - const set& mySet; - set::iterator myIterator; - public: - SMDS_InverseElementIterator(const set& s):mySet(s) - { - myIterator=mySet.begin(); - } - - bool more() - { - return myIterator!=mySet.end(); - } - - const SMDS_MeshElement* next() - { - const SMDS_MeshElement* current=*myIterator; - myIterator++; - return current; - } - }; - return new SMDS_InverseElementIterator(myInverseElements); -} - -SMDS_Iterator * SMDS_MeshNode:: - elementsIterator(SMDSAbs_ElementType type) const -{ - // Same as GetInverseElementIterator but the create iterator only return - // wanted type elements. - class MyIterator:public SMDS_Iterator - { - set mySet; - set::iterator myIterator; - public: - MyIterator(SMDSAbs_ElementType type, - const set& s) - { - const SMDS_MeshElement * e; - bool toInsert; - set::iterator it=s.begin(); - while(it!=s.end()) - { - e=*it; - switch(type) - { - case SMDSAbs_Edge: toInsert=true; break; - case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break; - case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break; - } - if(toInsert) mySet.insert(e); - it++; - } - myIterator=mySet.begin(); - } - - bool more() - { - return myIterator!=mySet.end(); - } - - const SMDS_MeshElement* next() - { - const SMDS_MeshElement* current=*myIterator; - myIterator++; - return current; - } - }; - - if(type==SMDSAbs_Node) - return SMDS_MeshElement::elementsIterator(SMDSAbs_Node); - else - return new SMDS_IteratorOfElements(this,type, - new MyIterator(type, myInverseElements)); +const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const +{ + return myPosition; +} + +//======================================================================= +/*! + * \brief Iterator on list of elements + */ +//======================================================================= + +class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator +{ +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) + { + //MESSAGE("SMDS_MeshNode_MyInvIterator : ncells " << myNcells); + cellList.clear(); + if (type == SMDSAbs_All) + for (int i = 0; i < ncells; i++) + cellList.push_back(cells[i]); + else for (int i = 0; i < ncells; i++) + { + int vtkId = cells[i]; + int smdsId = myMesh->fromVtkToSmds(vtkId); + const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); + if (elem->GetType() == type) + { + //MESSAGE("Add element vtkId " << vtkId << " " << elem->GetType()) + cellList.push_back(vtkId); + } + } + myCells = &cellList[0]; + myNcells = cellList.size(); + //MESSAGE("myNcells="<fromVtkToSmds(vtkId); + const SMDS_MeshElement* elem = myMesh->FindElement(smdsId); + if (!elem) + { + MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element"); + throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element"); + } + //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId << " " << elem->GetType()); + iter++; + return elem; + } +}; + +SMDS_ElemIteratorPtr SMDS_MeshNode:: + GetInverseElementIterator(SMDSAbs_ElementType type) const +{ + vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); + //MESSAGE("myID " << myID << " ncells " << l.ncells); + return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], l.cells, l.ncells, type)); +} + +// 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) + { + //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); + } + myNcells = myFiltCells.size(); + //MESSAGE("myNcells " << myNcells); + iter = 0; + //MESSAGE("SMDS_MeshNode_MyIterator (filter) " << ncells << " " << myNcells); + } + + bool more() + { + return (iter< myNcells); + } + + const SMDS_MeshElement* next() + { + const SMDS_MeshElement* elem = myFiltCells[iter]; + iter++; + return elem; + } +}; + +SMDS_ElemIteratorPtr SMDS_MeshNode:: + elementsIterator(SMDSAbs_ElementType type) 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)); + } } int SMDS_MeshNode::NbNodes() const { - return 1; + return 1; +} + +double* SMDS_MeshNode::getCoord() const +{ + return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID); } double SMDS_MeshNode::X() const { - return myX; + double *coord = getCoord(); + return coord[0]; } double SMDS_MeshNode::Y() const { - return myY; + double *coord = getCoord(); + return coord[1]; } double SMDS_MeshNode::Z() const { - return myZ; + double *coord = getCoord(); + return coord[2]; } +//* resize the vtkPoints structure every SMDS_Mesh::chunkSize points void SMDS_MeshNode::setXYZ(double x, double y, double z) { - myX=x; - myY=y; - myZ=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 { - return SMDSAbs_Node; + return SMDSAbs_Node; +} + +vtkIdType SMDS_MeshNode::GetVtkType() const +{ + return VTK_VERTEX; } //======================================================================= @@ -199,7 +315,12 @@ SMDSAbs_ElementType SMDS_MeshNode::GetType() const //======================================================================= void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) { - myInverseElements.insert(ME); + 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); } //======================================================================= @@ -208,12 +329,37 @@ void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) //======================================================================= void SMDS_MeshNode::ClearInverseElements() { - myInverseElements.clear(); + SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0); } bool SMDS_MeshNode::emptyInverseElements() { - return myInverseElements.empty(); + vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetCellLinks()->GetLink(myVtkID); + return (l.ncells == 0); +} + +//================================================================================ +/*! + * \brief Count inverse elements of given type + */ +//================================================================================ + +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; iFindElement(mesh->fromVtkToSmds(l.cells[i])); + if (elem->GetType() == type) + nb++; + } + return nb; } /////////////////////////////////////////////////////////////////////////////// @@ -221,14 +367,14 @@ bool SMDS_MeshNode::emptyInverseElements() /////////////////////////////////////////////////////////////////////////////// bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2) { - return e1.GetID()