#endif
#include "SMDS_MeshNode.hxx"
-
-#include "SMDS_ElementFactory.hxx"
-#include "SMDS_Mesh.hxx"
-#include "SMDS_SetIterator.hxx"
#include "SMDS_SpacePosition.hxx"
+#include "SMDS_IteratorOfElements.hxx"
+#include "SMDS_Mesh.hxx"
+#include <vtkUnstructuredGrid.h>
-#include <utilities.h>
-#include <Utils_SALOME_Exception.hxx>
+#include "utilities.h"
+#include "Utils_SALOME_Exception.hxx"
#include <cassert>
-#include <boost/make_shared.hpp>
+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);
+}
-void SMDS_MeshNode::init(double x, double y, double z)
+void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, double z)
{
- SMDS_UnstructuredGrid * grid = getGrid();
+ SMDS_MeshElement::init(id, meshId, shapeId);
+ myVtkID = id - 1;
+ assert(myVtkID >= 0);
+ SMDS_UnstructuredGrid * grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
vtkPoints *points = grid->GetPoints();
- points->InsertPoint( GetVtkID(), x, y, z );
+ points->InsertPoint(myVtkID, x, y, z);
if ( grid->HasLinks() )
- grid->GetLinks()->ResizeForPoint( GetVtkID() );
+ grid->GetLinks()->ResizeForPoint( myVtkID );
+}
+
+SMDS_MeshNode::~SMDS_MeshNode()
+{
+ nbNodes--;
+ if ( myPosition && myPosition != SMDS_SpacePosition::originSpacePosition() )
+ delete myPosition, myPosition = 0;
}
//=======================================================================
void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * elem)
{
- if ( getGrid()->HasLinks() )
- getGrid()->RemoveReferenceToCell( GetVtkID(), elem->GetVtkID());
+ if ( SMDS_Mesh::_meshList[myMeshId]->getGrid()->HasLinks() )
+ SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myVtkID, elem->getVtkId());
}
//=======================================================================
void SMDS_MeshNode::Print(ostream & OS) const
{
- OS << "Node <" << GetID() << "> : X = " << X() << " Y = "
+ OS << "Node <" << myID << "> : X = " << X() << " Y = "
<< Y() << " Z = " << Z() << endl;
}
//purpose :
//=======================================================================
-void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos, int shapeID)
+void SMDS_MeshNode::SetPosition(const SMDS_PositionPtr& aPos)
{
- myHolder->SetPosition( this, aPos, shapeID );
+ if ( myPosition &&
+ myPosition != SMDS_SpacePosition::originSpacePosition() &&
+ myPosition != aPos )
+ delete myPosition;
+ myPosition = aPos;
}
//=======================================================================
//function : GetPosition
-//purpose : Return a position of this node on shape
-//warning : result is std::unique_ptr !
+//purpose :
//=======================================================================
-SMDS_PositionPtr SMDS_MeshNode::GetPosition() const
+const SMDS_PositionPtr& SMDS_MeshNode::GetPosition() const
{
- return myHolder->GetPosition( this );
+ return myPosition;
}
//=======================================================================
*/
//=======================================================================
-namespace
+class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator
{
- struct InverseIterator: public SMDS_ElemIterator
+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)
{
- 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 )
{
- if ( ncells )
+ cellList.reserve( ncells );
+ if (type == SMDSAbs_All)
{
- myCellList.reserve( ncells );
- if (type == SMDSAbs_All)
- {
- myCellList.assign( cells, cells + ncells );
- }
- else
+ cellList.assign( cells, cells + ncells );
+ }
+ else
+ {
+ for (int i = 0; i < ncells; i++)
{
- 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)
{
- int vtkId = cells[i];
- int smdsId = myMesh->FromVtkToSmds( vtkId );
- const SMDS_MeshElement* elem = myMesh->FindElement( smdsId );
- if ( elem->GetType() == type )
- {
- myCellList.push_back(vtkId);
- }
+ cellList.push_back(vtkId);
}
}
}
+ myCells = cellList.empty() ? 0 : &cellList[0];
+ myNcells = cellList.size();
}
+ }
- bool more()
- {
- return ( myIter < myCellList.size() );
- }
-
- const SMDS_MeshElement* next()
- {
- int vtkId = myCellList[ myIter++ ];
- int 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;
- }
- };
-
- //=======================================================================
- /*!
- * \brief Iterator on a node
- */
- //=======================================================================
-
- template< class ELEM_ITERATOR >
- struct Iterator : public ELEM_ITERATOR
+ bool more()
{
- typedef typename ELEM_ITERATOR::value_type element_type;
- const SMDS_MeshNode* myNode;
-
- Iterator( const SMDS_MeshNode* n ): myNode( n ) {}
+ return (iter < myNcells);
+ }
- virtual bool more()
- {
- return myNode;
- }
- virtual element_type next()
+ const SMDS_MeshElement* next()
+ {
+ int vtkId = myCells[iter];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (!elem)
{
- element_type res = static_cast<element_type>( myNode );
- myNode = 0;
- return res;
+ MESSAGE("SMDS_MeshNode_MyInvIterator problem Null element");
+ throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element");
}
- };
-}
+ iter++;
+ return elem;
+ }
+};
SMDS_ElemIteratorPtr SMDS_MeshNode::GetInverseElementIterator(SMDSAbs_ElementType type) const
{
- if ( GetMesh()->NbElements() > 0 ) // avoid building links
+ if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links
{
- vtkCellLinks::Link& l = getGrid()->GetLinks()->GetLink( GetVtkID() );
- return boost::make_shared< InverseIterator >( GetMesh(), l.cells, l.ncells, type );
+ 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));
}
else
{
- return boost::make_shared< InverseIterator >();
+ return SMDS_ElemIteratorPtr(new SMDS_MeshNode_MyInvIterator(SMDS_Mesh::_meshList[myMeshId], 0, 0, type));
}
}
-SMDS_ElemIteratorPtr SMDS_MeshNode::nodesIterator() const
-{
- return boost::make_shared< Iterator< SMDS_ElemIterator > >( this );
-}
-
-SMDS_NodeIteratorPtr SMDS_MeshNode::nodeIterator() const
+SMDS_ElemIteratorPtr SMDS_MeshNode::elementsIterator(SMDSAbs_ElementType type) const
{
- return boost::make_shared< Iterator< SMDS_NodeIterator > >( this );
+ if ( type == SMDSAbs_Node )
+ return SMDS_MeshElement::elementsIterator( SMDSAbs_Node );
+ else
+ return GetInverseElementIterator( type );
}
-const SMDS_MeshNode* SMDS_MeshNode::GetNode(const int ind) const
+int SMDS_MeshNode::NbNodes() const
{
- return ind == 0 ? this : 0;
+ return 1;
}
double* SMDS_MeshNode::getCoord() const
{
- return getGrid()->GetPoint( GetVtkID() );
+ return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID);
}
double SMDS_MeshNode::X() const
void SMDS_MeshNode::GetXYZ(double xyz[3]) const
{
- return getGrid()->GetPoint( GetVtkID(), xyz );
+ return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID,xyz);
}
//================================================================================
-void SMDS_MeshNode::setXYZ( double x, double y, double z )
+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
+{
+ return SMDSAbs_Node;
+}
+
+vtkIdType SMDS_MeshNode::GetVtkType() const
{
- vtkPoints *points = getGrid()->GetPoints();
- points->InsertPoint( GetVtkID(), x, y, z );
- //GetMesh()->adjustBoundingBox(x, y, z);
- GetMesh()->setMyModified();
+ return VTK_VERTEX;
}
//=======================================================================
//function : AddInverseElement
//purpose :
//=======================================================================
-void SMDS_MeshNode::AddInverseElement( const SMDS_MeshElement* elem )
+void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
{
- SMDS_UnstructuredGrid* grid = getGrid();
+ SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
if ( grid->HasLinks() )
{
vtkCellLinks *Links = grid->GetLinks();
- Links->ResizeCellList( GetVtkID(), 1 );
- Links->AddCellReference( elem->GetVtkID(), GetVtkID() );
+ Links->ResizeCellList(myVtkID, 1);
+ Links->AddCellReference(ME->getVtkId(), myVtkID);
}
}
//=======================================================================
void SMDS_MeshNode::ClearInverseElements()
{
- getGrid()->ResizeCellList( GetVtkID(), 0);
+ SMDS_Mesh::_meshList[myMeshId]->getGrid()->ResizeCellList(myVtkID, 0);
}
//================================================================================
int SMDS_MeshNode::NbInverseElements(SMDSAbs_ElementType type) const
{
int nb = 0;
- SMDS_Mesh *mesh = GetMesh();
- if ( mesh->NbElements() > 0 ) // avoid building links
+ if ( SMDS_Mesh::_meshList[myMeshId]->NbElements() > 0 ) // avoid building links
{
- vtkCellLinks::Link& l = mesh->GetGrid()->GetLinks()->GetLink( GetVtkID() );
+ vtkCellLinks::Link& l = SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetLinks()->GetLink(myVtkID);
if ( type == SMDSAbs_All )
return l.ncells;
+ SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId];
for ( int i = 0; i < l.ncells; i++ )
{
- const SMDS_MeshElement* elem = mesh->FindElement( mesh->FromVtkToSmds( l.cells[i] ));
+ const SMDS_MeshElement* elem = mesh->FindElement( mesh->fromVtkToSmds( l.cells[i] ));
nb += ( elem->GetType() == type );
}
}