+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<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)
+ {
+ //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.empty() ? 0 : &cellList[0];
+ myNcells = cellList.size();
+ //MESSAGE("myNcells="<<myNcells);
+ }
+
+ bool more()
+ {
+ //MESSAGE("iter " << iter << " ncells " << myNcells);
+ return (iter < myNcells);
+ }
+
+ const SMDS_MeshElement* next()
+ {
+ int vtkId = myCells[iter];
+ int smdsId = myMesh->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<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)
+ {
+ //MESSAGE("myNcells " << myNcells);
+ for (; iter<ncells; iter++)
+ {
+ 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);
+ }
+ 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;
+}
+
+double* SMDS_MeshNode::getCoord() const
+{
+ return SMDS_Mesh::_meshList[myMeshId]->getGrid()->GetPoint(myVtkID);
+}
+
+double SMDS_MeshNode::X() const
+{
+ double *coord = getCoord();
+ return coord[0];
+}
+
+double SMDS_MeshNode::Y() const
+{
+ double *coord = getCoord();
+ return coord[1];
+}
+
+double SMDS_MeshNode::Z() const
+{
+ double *coord = getCoord();
+ return coord[2];
+}
+
+//================================================================================
+/*!
+ * \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
+{
+ return SMDSAbs_Node;
+}
+
+vtkIdType SMDS_MeshNode::GetVtkType() const
+{
+ return VTK_VERTEX;
+}
+
+//=======================================================================
+//function : AddInverseElement
+//purpose :
+//=======================================================================
+void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME)
+{
+ const SMDS_MeshCell *cell = dynamic_cast<const SMDS_MeshCell*> (ME);
+ assert(cell);
+ SMDS_UnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
+ vtkCellLinks *Links = grid->GetCellLinks();
+ Links->ResizeCellList(myVtkID, 1);
+ Links->AddCellReference(cell->getVtkId(), myVtkID);
+}
+
+//=======================================================================
+//function : ClearInverseElements
+//purpose :
+//=======================================================================
+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);
+}
+
+//================================================================================
+/*!
+ * \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; i<l.ncells; i++)
+ {
+ const SMDS_MeshElement* elem = mesh->FindElement(mesh->fromVtkToSmds(l.cells[i]));
+ if (elem->GetType() == type)
+ nb++;
+ }
+ return nb;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// To be used with STL set
+///////////////////////////////////////////////////////////////////////////////
+bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2)