Salome HOME
Fix GetNodeIndex() for polygon
[modules/smesh.git] / src / SMDS / SMDS_VtkVolume.cxx
index 3db0ba03ba7ce9549c07a631b98cd4a8bf6b293a..7acdbf37c110daff9dae1c5bdc6632384225e5b2 100644 (file)
@@ -448,6 +448,41 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const
   const std::vector<int>& interlace = SMDS_MeshCell::fromVtkOrder( VTKCellType( aVtkType ));
   return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( pts[ interlace.empty() ? ind : interlace[ind]] );
 }
+/*!
+ * \brief Check if a node belongs to the element
+ * \param node - the node to check
+ * \retval int - node index within the element, -1 if not found
+ */
+int SMDS_VtkVolume::GetNodeIndex( const SMDS_MeshNode* node ) const
+{
+  vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
+  const  vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
+  if ( aVtkType == VTK_POLYHEDRON)
+  {
+    vtkIdType nFaces = 0;
+    vtkIdType* ptIds = 0;
+    grid->GetFaceStream(this->myVtkID, nFaces, ptIds);
+    int id = 0;
+    for (int iF = 0; iF < nFaces; iF++)
+    {
+      int nodesInFace = ptIds[id];
+      for ( vtkIdType i = 0; i < nodesInFace; ++i )
+        if ( ptIds[id+i+1] == node->getVtkId() )
+          return id+i-iF;
+      id += (nodesInFace + 1);
+    }
+    return -1;
+  }
+  vtkIdType npts, *pts;
+  grid->GetCellPoints( this->myVtkID, npts, pts );
+  for ( vtkIdType i = 0; i < npts; ++i )
+    if ( pts[i] == node->getVtkId() )
+    {
+      const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( aVtkType ));
+      return interlace.empty() ? i : interlace[i];
+    }
+  return -1;
+}
 
 bool SMDS_VtkVolume::IsQuadratic() const
 {