Salome HOME
SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_02/C1
[modules/smesh.git] / src / SMDS / SMDS_VtkVolume.cxx
index de9174e0b6273d8f62e90b4ff02ad583797a1bac..f97e31969e2b531b2d7091d7fae5d53b0ac1bd88 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2010-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -366,7 +366,6 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetFaceNode(const int face_ind, const int n
 std::vector<int> SMDS_VtkVolume::GetQuantities() const
 {
   vector<int> quantities;
-  quantities.clear();
   SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myMeshId];
   vtkUnstructuredGrid* grid = mesh->getGrid();
   vtkIdType aVtkType = grid->GetCellType(this->myVtkID);
@@ -404,14 +403,14 @@ SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type)
   }
 }
 
-SMDS_ElemIteratorPtr SMDS_VtkVolume::nodesIteratorToUNV() const
+SMDS_NodeIteratorPtr SMDS_VtkVolume::nodesIteratorToUNV() const
 {
-  return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
+  return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
 }
 
-SMDS_ElemIteratorPtr SMDS_VtkVolume::interlacedNodesElemIterator() const
+SMDS_NodeIteratorPtr SMDS_VtkVolume::interlacedNodesIterator() const
 {
-  return SMDS_ElemIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
+  return SMDS_NodeIteratorPtr(new SMDS_VtkCellIteratorToUNV(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
 }
 
 SMDSAbs_ElementType SMDS_VtkVolume::GetType() const
@@ -428,11 +427,62 @@ const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const
 {
   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
   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, nbPoints = 0;
+    for (int i = 0; i < nFaces; i++)
+    {
+      int nodesInFace = ptIds[id];
+      if ( ind < nbPoints + nodesInFace )
+        return SMDS_Mesh::_meshList[myMeshId]->FindNodeVtk( ptIds[ ind + i ]);
+      nbPoints += nodesInFace;
+      id += (nodesInFace + 1);
+    }
+    return 0;
+  }
   vtkIdType npts, *pts;
   grid->GetCellPoints( this->myVtkID, npts, pts );
   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
 {
@@ -507,7 +557,6 @@ bool SMDS_VtkVolume::IsMediumNode(const SMDS_MeshNode* node) const
 int SMDS_VtkVolume::NbCornerNodes() const
 {
   vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
-  int            nbN = grid->GetCell(myVtkID)->GetNumberOfPoints();
   vtkIdType aVtkType = grid->GetCellType(myVtkID);
   switch (aVtkType)
   {
@@ -518,7 +567,7 @@ int SMDS_VtkVolume::NbCornerNodes() const
   case VTK_TRIQUADRATIC_HEXAHEDRON: return 8;
   default:;
   }
-  return nbN;
+  return NbNodes();
 }
 
 SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
@@ -670,6 +719,6 @@ int SMDS_VtkVolume::NbUniqueNodes() const
  */
 SMDS_ElemIteratorPtr SMDS_VtkVolume::uniqueNodesIterator() const
 {
-  MESSAGE("uniqueNodesIterator");
+  //MESSAGE("uniqueNodesIterator");
   return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
 }