+#include "SMDS_Mesh.hxx"
+#include "SMDS_VolumeTool.hxx"
+#include "SMDS_VtkCellIterator.hxx"
+
+#include <boost/make_shared.hpp>
+
+// init a polyherdon
+void SMDS_MeshVolume::init( const std::vector<const SMDS_MeshNode*>& nodes,
+ const std::vector<int>& nbNodesPerFace )
+{
+ std::vector<vtkIdType> ptIds;
+ ptIds.reserve( nodes.size() + nbNodesPerFace.size() + 1 );
+
+ size_t nbFaces = nbNodesPerFace.size();
+ for ( size_t iN = 0, iF = 0; iF < nbFaces; iF++ )
+ {
+ int nf = nbNodesPerFace[iF];
+ ptIds.push_back(nf);
+ for (int n = 0; n < nf; n++)
+ ptIds.push_back( nodes[ iN++ ]->GetVtkID() );
+ }
+
+ int vtkID = getGrid()->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
+ setVtkID( vtkID );
+}
+
+void SMDS_MeshVolume::init( const std::vector<vtkIdType>& vtkNodeIds )
+{
+ SMDSAbs_EntityType aType = SMDSEntity_Tetra;
+ switch ( vtkNodeIds.size()) // cases are in order of usage frequency
+ {
+ case 4: aType = SMDSEntity_Tetra; break;
+ case 5: aType = SMDSEntity_Pyramid; break;
+ case 8: aType = SMDSEntity_Hexa; break;
+ case 6: aType = SMDSEntity_Penta; break;
+ case 10: aType = SMDSEntity_Quad_Tetra; break;
+ case 20: aType = SMDSEntity_Quad_Hexa; break;
+ case 13: aType = SMDSEntity_Quad_Pyramid; break;
+ case 27: aType = SMDSEntity_TriQuad_Hexa; break;
+ case 15: aType = SMDSEntity_Quad_Penta; break;
+ case 18: aType = SMDSEntity_BiQuad_Penta; break;
+ case 12: aType = SMDSEntity_Hexagonal_Prism; break;
+ default: throw SALOME_Exception("wrong volume nodes");
+ }
+ SMDS_MeshCell::init( aType, vtkNodeIds );
+}
+
+const SMDS_MeshNode* SMDS_MeshVolume::GetNode(const int ind) const
+{
+ if ( !IsPoly() )
+ return SMDS_MeshCell::GetNode( ind );
+
+ vtkIdType nFaces = 0;
+ vtkIdType* ptIds = 0;
+ getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
+ int id = 0, nbPoints = 0;
+ for (int i = 0; i < nFaces; i++)
+ {
+ int nodesInFace = ptIds[id];
+ if ( ind < nbPoints + nodesInFace )
+ return GetMesh()->FindNodeVtk( ptIds[ ind + i ]);
+ nbPoints += nodesInFace;
+ id += (nodesInFace + 1);
+ }
+ return 0;
+}
+int SMDS_MeshVolume::NbNodes() const
+{
+ if ( !IsPoly() )
+ return SMDS_MeshCell::NbNodes();
+
+ vtkIdType nFaces = 0;
+ vtkIdType* ptIds = 0;
+ getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
+ int id = 0, nbPoints = 0;
+ for (int i = 0; i < nFaces; i++)
+ {
+ int nodesInFace = ptIds[id];
+ nbPoints += nodesInFace;
+ id += (nodesInFace + 1);
+ }
+ return nbPoints;
+}
+
+int SMDS_MeshVolume::NbFaces() const
+{
+ if ( !IsPoly() )
+ return SMDS_MeshCell::NbFaces();
+
+ vtkIdType nFaces = 0;
+ vtkIdType* ptIds = 0;
+ getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
+ return nFaces;
+
+}
+int SMDS_MeshVolume::NbEdges() const