1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementation of Salome mesh data structure
24 // File : SMDS_MeshVolume.cxx
25 // Author : Jean-Michel BOULCOURT
29 #include "SMDS_MeshVolume.hxx"
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMDS_VtkCellIterator.hxx"
35 #include <boost/make_shared.hpp>
38 void SMDS_MeshVolume::init( const std::vector<const SMDS_MeshNode*>& nodes,
39 const std::vector<int>& nbNodesPerFace )
41 std::vector<vtkIdType> ptIds;
42 ptIds.reserve( nodes.size() + nbNodesPerFace.size() + 1 );
44 size_t nbFaces = nbNodesPerFace.size();
45 for ( size_t iN = 0, iF = 0; iF < nbFaces; iF++ )
47 int nf = nbNodesPerFace[iF];
49 for (int n = 0; n < nf; n++)
50 ptIds.push_back( nodes[ iN++ ]->GetVtkID() );
53 int vtkID = getGrid()->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
57 void SMDS_MeshVolume::init( const std::vector<vtkIdType>& vtkNodeIds )
59 SMDSAbs_EntityType aType = SMDSEntity_Tetra;
60 switch ( vtkNodeIds.size()) // cases are in order of usage frequency
62 case 4: aType = SMDSEntity_Tetra; break;
63 case 5: aType = SMDSEntity_Pyramid; break;
64 case 8: aType = SMDSEntity_Hexa; break;
65 case 6: aType = SMDSEntity_Penta; break;
66 case 10: aType = SMDSEntity_Quad_Tetra; break;
67 case 20: aType = SMDSEntity_Quad_Hexa; break;
68 case 13: aType = SMDSEntity_Quad_Pyramid; break;
69 case 27: aType = SMDSEntity_TriQuad_Hexa; break;
70 case 15: aType = SMDSEntity_Quad_Penta; break;
71 case 18: aType = SMDSEntity_BiQuad_Penta; break;
72 case 12: aType = SMDSEntity_Hexagonal_Prism; break;
73 default: throw SALOME_Exception("wrong volume nodes");
75 SMDS_MeshCell::init( aType, vtkNodeIds );
78 bool SMDS_MeshVolume::ChangeNodes(const std::vector<const SMDS_MeshNode*>& nodes,
79 const std::vector<int>& quantities) const
85 vtkIdType const *tmp(nullptr);
86 getGrid()->GetFaceStream( GetVtkID(), nFaces, tmp );
87 vtkIdType *ptIds = const_cast<vtkIdType*>( tmp );
89 // stream size and nb faces should not change
91 if ((int) quantities.size() != nFaces )
95 size_t id = 0, nbPoints = 0;
96 for ( int i = 0; i < nFaces; i++ )
98 int nodesInFace = ptIds[id];
99 nbPoints += nodesInFace;
100 id += (nodesInFace + 1);
102 if ( nodes.size() != nbPoints )
108 size_t iP = 0, iN = 0;
109 for ( size_t i = 0; i < quantities.size(); ++i )
111 ptIds[ iP++ ] = quantities[ i ]; // nb face nodes
112 for ( int j = 0; j < quantities[ i ]; ++j )
113 ptIds[ iP++ ] = nodes[ iN++ ]->GetVtkID();
118 const SMDS_MeshNode* SMDS_MeshVolume::GetNode(const int ind) const
121 return SMDS_MeshCell::GetNode( ind );
123 vtkIdType nFaces = 0;
124 vtkIdType const *ptIds(nullptr);
125 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
126 int id = 0, nbPoints = 0;
127 for (int i = 0; i < nFaces; i++)
129 int nodesInFace = ptIds[id];
130 if ( ind < nbPoints + nodesInFace )
131 return GetMesh()->FindNodeVtk( ptIds[ 1 + ind + i ]);
132 nbPoints += nodesInFace;
133 id += (nodesInFace + 1);
137 int SMDS_MeshVolume::NbNodes() const
140 return SMDS_MeshCell::NbNodes();
142 vtkIdType nFaces = 0;
143 vtkIdType const *ptIds(nullptr);
144 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
145 int id = 0, nbPoints = 0;
146 for (int i = 0; i < nFaces; i++)
148 int nodesInFace = ptIds[id];
149 nbPoints += nodesInFace;
150 id += (nodesInFace + 1);
155 int SMDS_MeshVolume::NbFaces() const
158 return SMDS_MeshCell::NbFaces();
160 vtkIdType nFaces = 0;
161 vtkIdType const *ptIds(nullptr);
162 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
166 int SMDS_MeshVolume::NbEdges() const
169 return SMDS_MeshCell::NbEdges();
171 vtkIdType nFaces = 0;
172 vtkIdType const *ptIds(nullptr);
173 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
174 int id = 0, nbEdges = 0;
175 for (int i = 0; i < nFaces; i++)
177 int edgesInFace = ptIds[id];
178 id += (edgesInFace + 1);
179 nbEdges += edgesInFace;
181 nbEdges = nbEdges / 2;
185 int SMDS_MeshVolume::GetNodeIndex( const SMDS_MeshNode* node ) const
188 return SMDS_MeshCell::GetNodeIndex( node );
190 vtkIdType nFaces = 0;
191 vtkIdType const *ptIds(nullptr);
192 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
194 for (int iF = 0; iF < nFaces; iF++)
196 int nodesInFace = ptIds[id];
197 for ( vtkIdType i = 0; i < nodesInFace; ++i )
198 if ( ptIds[id+i+1] == node->GetVtkID() )
200 id += (nodesInFace + 1);
204 bool SMDS_MeshVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
209 bool SMDS_MeshVolume::IsMediumNode(const SMDS_MeshNode* node) const
212 return SMDS_MeshCell::IsMediumNode( node );
217 int SMDS_MeshVolume::NbCornerNodes() const
220 return SMDS_MeshCell::NbCornerNodes();
225 int SMDS_MeshVolume::NbFaceNodes (const int face_ind) const
228 return SMDS_VolumeTool( this ).NbFaceNodes( face_ind-1 );
230 vtkIdType nFaces = 0;
231 vtkIdType const *ptIds(nullptr);
232 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
233 int id = 0, nbNodes = 0;
234 for (int i = 0; i < nFaces; i++)
236 int nodesInFace = ptIds[id];
237 id += (nodesInFace + 1);
238 if (i == face_ind - 1)
240 nbNodes = nodesInFace;
247 const SMDS_MeshNode* SMDS_MeshVolume::GetFaceNode (const int face_ind, const int node_ind) const
250 return SMDS_VolumeTool( this ).GetFaceNodes( face_ind-1 )[ node_ind - 1 ];
252 vtkIdType nFaces = 0;
253 vtkIdType const *ptIds(nullptr);
254 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds);
256 for (int i = 0; i < nFaces; i++)
258 int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
259 if (i == face_ind - 1) // first face is number 1
261 if ((node_ind > 0) && (node_ind <= nodesInFace))
262 return GetMesh()->FindNodeVtk(ptIds[id + node_ind]); // ptIds[id+1] : first node
264 id += (nodesInFace + 1);
269 std::vector<int> SMDS_MeshVolume::GetQuantities() const
271 std::vector<int> quantities;
274 vtkIdType nFaces = 0;
275 vtkIdType const *ptIds(nullptr);
276 getGrid()->GetFaceStream( GetVtkID(), nFaces, ptIds );
278 for (int i = 0; i < nFaces; i++)
280 int nodesInFace = ptIds[id]; // nodeIds in ptIds[id+1 .. id+nodesInFace]
281 quantities.push_back( nodesInFace );
282 id += (nodesInFace + 1);
288 ///////////////////////////////////////////////////////////////////////////////
289 /// Create an iterator which iterate on nodes owned by the element.
290 ///////////////////////////////////////////////////////////////////////////////
291 SMDS_ElemIteratorPtr SMDS_MeshVolume::nodesIterator() const
294 return SMDS_MeshCell::nodesIterator();
296 return boost::make_shared< SMDS_VtkCellIteratorPolyH<> >( GetMesh(), GetVtkID(), GetEntityType());
299 ///////////////////////////////////////////////////////////////////////////////
300 /// Create an iterator which iterate on nodes owned by the element.
301 ///////////////////////////////////////////////////////////////////////////////
302 SMDS_NodeIteratorPtr SMDS_MeshVolume::nodeIterator() const
305 return SMDS_MeshCell::nodeIterator();
307 return boost::make_shared< SMDS_VtkCellIteratorPolyH< SMDS_NodeIterator> >( GetMesh(), GetVtkID(), GetEntityType());