-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 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
// 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 <vtkUnstructuredGrid.h>
+#include "SMDS_SetIterator.hxx"
+#include "SMDS_SpacePosition.hxx"
-#include "utilities.h"
-#include "Utils_SALOME_Exception.hxx"
+#include <utilities.h>
+#include <Utils_SALOME_Exception.hxx>
#include <cassert>
+#include <smIdType.hxx>
-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 <boost/make_shared.hpp>
-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);
- SMDS_UnstructuredGrid * grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
+ SMDS_UnstructuredGrid * grid = getGrid();
vtkPoints *points = grid->GetPoints();
- points->InsertPoint(myVtkID, x, y, z);
- grid->GetLinks()->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() );
}
//=======================================================================
void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem)
{
- if ( SMDS_Mesh::_meshList[myMeshId]->getGrid()->HasLinks() )
- SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, elem->getVtkId());
+ if ( getGrid()->HasLinks() )
+ getGrid()->RemoveReferenceToCell( GetVtkID(), elem->GetVtkID());
}
//=======================================================================
void SMDS_MeshNode::Print(ostream & OS) const
{
- OS << "Node <" << myID << "> : X = " << X() << " Y = "
+ OS << "Node <" << GetID() << "> : X = " << X() << " Y = "
<< Y() << " Z = " << Z() << endl;
}
//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 );
}
//=======================================================================
*/
//=======================================================================
-class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator
+namespace
{
-private:
- SMDS_Mesh* myMesh;
- vtkIdType* myCells;
- int myNcells;
- SMDSAbs_ElementType myType;
- int iter;
- vector<vtkIdType> 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<vtkIdType> 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()->GetLinks()->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<SMDS_MeshElement*> 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 (; iter<ncells; iter++)
+ typedef typename ELEM_ITERATOR::value_type element_type;
+ const SMDS_MeshNode* myNode;
+
+ Iterator( const SMDS_MeshNode* n ): myNode( n ) {}
+
+ virtual bool more()
{
- int vtkId = myCells[iter];
- int smdsId = myMesh->fromVtkToSmds(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<element_type>( 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()->GetLinks()->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
/*!
* \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 )
{
- SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
- vtkCellLinks *Links = grid->GetLinks();
- Links->ResizeCellList(myVtkID, 1);
- Links->AddCellReference(ME->getVtkId(), myVtkID);
+ SMDS_UnstructuredGrid* grid = getGrid();
+ if ( grid->HasLinks() )
+ {
+ vtkCellLinks *Links = grid->GetLinks();
+ Links->ResizeCellList( GetVtkID(), 1 );
+ Links->AddCellReference( elem->GetVtkID(), GetVtkID() );
+ }
}
//=======================================================================
//=======================================================================
void SMDS_MeshNode::ClearInverseElements()
{
- SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0);
-}
-
-bool SMDS_MeshNode::emptyInverseElements()
-{
- vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID);
- return (l.ncells == 0);
+ getGrid()->ResizeCellList( GetVtkID(), 0);
}
//================================================================================
int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
{
- vtkCellLinks::Link l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID);
-
- if ( type == SMDSAbs_All )
- return l.ncells;
-
int nb = 0;
- SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId];
- for (int i=0; i<l.ncells; i++)
+ SMDS_Mesh *mesh = GetMesh();
+ if ( mesh->NbElements() > 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()<e2.getVtkId();
- /*if(e1.myX<e2.myX) return true;
- else if(e1.myX==e2.myX)
+ if ( type == SMDSAbs_All )
+ return l.ncells;
+
+ for ( int i = 0; i < l.ncells; i++ )
{
- if(e1.myY<e2.myY) return true;
- else if(e1.myY==e2.myY) return (e1.myZ<e2.myZ);
- else return false;
+ const SMDS_MeshElement* elem = mesh->FindElement( mesh->FromVtkToSmds( l.cells[i] ));
+ nb += ( elem->GetType() == type );
}
- else return false;*/
+ }
+ return nb;
}
-