Salome HOME
PR: display hexahedron
[modules/smesh.git] / src / SMDS / SMDS_VtkVolume.cxx
1
2 #include "SMDS_VtkVolume.hxx"
3 #include "SMDS_MeshNode.hxx"
4 #include "SMDS_Mesh.hxx"
5 #include "SMDS_VtkCellIterator.hxx"
6
7 #include "utilities.h"
8
9 #include <vector>
10
11
12 SMDS_VtkVolume::SMDS_VtkVolume()
13 {
14 }
15
16 SMDS_VtkVolume::SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
17 {
18   init(nodeIds, mesh);
19 }
20
21 void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
22 {
23   vtkUnstructuredGrid* grid = mesh->getGrid();
24   myMeshId = mesh->getMeshId();
25   myVtkID = grid->InsertNextLinkedCell(GetType(), nodeIds.size(), &nodeIds[0]);
26 }
27
28 bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[],
29                                  const int            nbNodes)
30 {
31   // utilise dans SMDS_Mesh
32   return true;
33 }
34
35 SMDS_VtkVolume::~SMDS_VtkVolume()
36 {
37 }
38
39 void SMDS_VtkVolume::Print(ostream & OS) const
40 {
41   OS << "volume <" << GetID() << "> : ";
42 }
43
44 int SMDS_VtkVolume::NbFaces() const
45 {
46   switch(NbNodes())
47     {
48     case 4: return 4;
49     case 5: return 5;
50     case 6: return 5;
51     case 8: return 6;
52     default: MESSAGE("invalid number of nodes");
53     }
54   return 0;
55 }
56
57 int SMDS_VtkVolume::NbNodes() const
58 {
59   vtkUnstructuredGrid* grid =SMDS_Mesh::_meshList[myMeshId]->getGrid();
60   int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
61   return nbPoints;
62 }
63
64 int SMDS_VtkVolume::NbEdges() const
65 {
66   switch(NbNodes())
67     {
68     case 4: return 6;
69     case 5: return 8;
70     case 6: return 9;
71     case 8: return 12;
72     default: MESSAGE("invalid number of nodes");
73     }
74   return 0;
75 }
76
77 SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type) const
78 {
79   switch(type)
80     {
81     case SMDSAbs_Node:
82       return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID));
83     default:
84       MESSAGE("ERROR : Iterator not implemented");
85       return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
86     }
87 }
88
89 SMDSAbs_ElementType SMDS_VtkVolume::GetType() const
90 {
91   return SMDSAbs_Volume;
92 }
93
94 /*!
95  * \brief Return node by its index
96  * \param ind - node index
97  * \retval const SMDS_MeshNode* - the node
98  */
99 const SMDS_MeshNode* SMDS_VtkVolume::GetNode(const int ind) const
100 {
101   return 0;
102 }
103
104 SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
105 {
106   SMDSAbs_EntityType aType = SMDSEntity_Tetra;
107   switch(NbNodes())
108     {
109     case 4: aType = SMDSEntity_Tetra;   break;
110     case 5: aType = SMDSEntity_Pyramid; break;
111     case 6: aType = SMDSEntity_Penta;   break;
112     case 8:
113     default: aType = SMDSEntity_Hexa;    break;
114     }
115   return aType;
116 }