1 // Copyright (C) 2007-2010 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.
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 // File : SMDS_VolumeTool.cxx
24 // Created : Tue Jul 13 12:22:13 2004
25 // Author : Edward AGAPOV (eap)
28 #pragma warning(disable:4786)
31 #include "SMDS_VolumeTool.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_VtkVolume.hxx"
36 #include "SMDS_Mesh.hxx"
38 #include "utilities.h"
46 // ======================================================
47 // Node indices in faces depending on volume orientation
48 // making most faces normals external
49 // ======================================================
57 // N0 +---|---+ N1 TETRAHEDRON
65 static int Tetra_F [4][4] = { // FORWARD == EXTERNAL
66 { 0, 1, 2, 0 }, // All faces have external normals
70 static int Tetra_R [4][4] = { // REVERSED
71 { 0, 1, 2, 0 }, // All faces but a bottom have external normals
75 static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL)
76 { 0, 2, 1, 0 }, // All faces have external normals
80 static int Tetra_nbN [] = { 3, 3, 3, 3 };
85 static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL
86 { 0, 1, 2, 3, 0 }, // All faces have external normals
91 static int Pyramid_R [5][5] = { // REVERSED
92 { 0, 1, 2, 3, 0 }, // All faces but a bottom have external normals
97 static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL)
98 { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals
103 static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 };
114 // | / \ | PENTAHEDRON
120 static int Penta_F [5][5] = { // FORWARD
121 { 0, 1, 2, 0, 0 }, // Top face has an internal normal, other - external
122 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
126 static int Penta_R [5][5] = { // REVERSED
127 { 0, 1, 2, 0, 0 }, // Bottom face has an internal normal, other - external
128 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
132 static int Penta_FE [5][5] = { // FORWARD -> EXTERNAL
138 static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL
144 static int Penta_nbN [] = { 3, 3, 4, 4, 4 };
151 // N4+----------+N7 |
152 // | | | | HEXAHEDRON
155 // | N1+------|---+N2
161 static int Hexa_F [6][5] = { // FORWARD
162 { 0, 1, 2, 3, 0 }, // opposite faces are neighbouring,
163 { 4, 5, 6, 7, 4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external
164 { 1, 0, 4, 5, 1 }, // same index nodes of opposite faces are linked
168 // static int Hexa_R [6][5] = { // REVERSED
169 // { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
170 // { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal
171 // { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked
172 // { 2, 6, 7, 3, 2 },
173 // { 0, 4, 7, 3, 0 },
174 // { 1, 5, 6, 2, 1 }};
175 static int Hexa_FE [6][5] = { // FORWARD -> EXTERNAL
176 { 0, 1, 2, 3, 0 } , // opposite faces are neighbouring,
177 { 4, 7, 6, 5, 4 }, // all face normals are external,
178 { 0, 4, 5, 1, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
182 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
183 { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
184 { 4, 5, 6, 7, 4 }, // all face normals are external,
185 { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
189 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
198 // N0 +---|---+ N1 TETRAHEDRON
206 static int QuadTetra_F [4][7] = { // FORWARD == EXTERNAL
207 { 0, 4, 1, 5, 2, 6, 0 }, // All faces have external normals
208 { 0, 7, 3, 8, 1, 4, 0 },
209 { 1, 8, 3, 9, 2, 5, 1 },
210 { 0, 6, 2, 9, 3, 7, 0 }};
211 static int QuadTetra_R [4][7] = { // REVERSED
212 { 0, 4, 1, 5, 2, 6, 0 }, // All faces but a bottom have external normals
213 { 0, 4, 1, 8, 3, 7, 0 },
214 { 1, 5, 2, 9, 3, 8, 1 },
215 { 0, 7, 3, 9, 2, 6, 0 }};
216 static int QuadTetra_RE [4][7] = { // REVERSED -> FORWARD (EXTERNAL)
217 { 0, 6, 2, 5, 1, 4, 0 }, // All faces have external normals
218 { 0, 4, 1, 8, 3, 7, 0 },
219 { 1, 5, 2, 9, 3, 8, 1 },
220 { 0, 7, 3, 9, 2, 6, 0 }};
221 static int QuadTetra_nbN [] = { 6, 6, 6, 6 };
231 // | | 9 - middle point for (0,4) etc.
244 static int QuadPyram_F [5][9] = { // FORWARD == EXTERNAL
245 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces have external normals
246 { 0, 9, 4, 10,1, 5, 0, 4, 4 },
247 { 1, 10,4, 11,2, 6, 1, 4, 4 },
248 { 2, 11,4, 12,3, 7, 2, 4, 4 },
249 { 3, 12,4, 9, 0, 8, 3, 4, 4 }};
250 static int QuadPyram_R [5][9] = { // REVERSED
251 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces but a bottom have external normals
252 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
253 { 1, 6, 2, 11,4, 10,1, 4, 4 },
254 { 2, 7, 3, 12,4, 11,2, 4, 4 },
255 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
256 static int QuadPyram_RE [5][9] = { // REVERSED -> FORWARD (EXTERNAL)
257 { 0, 8, 3, 7, 2, 6, 1, 5, 0 }, // All faces but a bottom have external normals
258 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
259 { 1, 6, 2, 11,4, 10,1, 4, 4 },
260 { 2, 7, 3, 12,4, 11,2, 4, 4 },
261 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
262 static int QuadPyram_nbN [] = { 8, 6, 6, 6, 6 };
289 static int QuadPenta_F [5][9] = { // FORWARD
290 { 0, 6, 1, 7, 2, 8, 0, 0, 0 }, // Top face has an internal normal, other - external
291 { 3, 9, 4, 10,5, 11,3, 3, 3 }, // 0 is bottom, 1 is top face
292 { 0, 8, 2, 14,5, 11,3, 12,0 },
293 { 1, 13,4, 10,5, 14,2, 7, 1 },
294 { 0, 12,3, 9, 4, 13,1, 6, 0 }};
295 static int QuadPenta_R [5][9] = { // REVERSED
296 { 0, 6, 1, 7, 2, 8, 0, 0, 0 }, // Bottom face has an internal normal, other - external
297 { 3, 9, 4, 10,5, 11,3, 3, 3 }, // 0 is bottom, 1 is top face
298 { 0, 12,3, 11,5, 14,2, 8, 0 },
299 { 1, 7, 2, 14,5, 10,4, 13,1 },
300 { 0, 6, 1, 13,4, 9, 3, 12,0 }};
301 static int QuadPenta_FE [5][9] = { // FORWARD -> EXTERNAL
302 { 0, 6, 1, 7, 2, 8, 0, 0, 0 },
303 { 3,11, 5, 10,4, 9, 3, 3, 3 },
304 { 0, 8, 2, 14,5, 11,3, 12,0 },
305 { 1, 13,4, 10,5, 14,2, 7, 1 },
306 { 0, 12,3, 9, 4, 13,1, 6, 0 }};
307 static int QuadPenta_RE [5][9] = { // REVERSED -> EXTERNAL
308 { 0, 8, 2, 7, 1, 6, 0, 0, 0 },
309 { 3, 9, 4, 10,5, 11,3, 3, 3 },
310 { 0, 12,3, 11,5, 14,2, 8, 0 },
311 { 1, 7, 2, 14,5, 10,4, 13,1 },
312 { 0, 6, 1, 13,4, 9, 3, 12,0 }};
313 static int QuadPenta_nbN [] = { 6, 6, 8, 8, 8 };
321 // N4+-----+-----+N7 | QUADRATIC
322 // | | 15 | | HEXAHEDRON
331 // | N1+-----+-|---+N2
338 static int QuadHexa_F [6][9] = { // FORWARD
339 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // opposite faces are neighbouring,
340 { 4, 12,5, 13,6, 14,7, 15,4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external
341 { 1, 8, 0, 16,4, 12,5, 17,1 }, // same index nodes of opposite faces are linked
342 { 2, 10,3, 19,7, 14,6, 18,2 },
343 { 0, 11,3, 19,7, 15,4, 16,0 },
344 { 1, 9, 2, 18,6, 13,5, 17,1 }};
345 // static int Hexa_R [6][5] = { // REVERSED
346 // { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
347 // { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal
348 // { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked
349 // { 2, 6, 7, 3, 2 },
350 // { 0, 4, 7, 3, 0 },
351 // { 1, 5, 6, 2, 1 }};
352 static int QuadHexa_FE [6][9] = { // FORWARD -> EXTERNAL
353 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // opposite faces are neighbouring,
354 { 4, 15,7, 14,6, 13,5, 12,4 }, // all face normals are external,
355 { 0, 16,4, 12,5, 17,1, 8, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
356 { 3, 10,2, 18,6, 14,7, 19,3 },
357 { 0, 11,3, 19,7, 15,4, 16,0 },
358 { 1, 17,5, 13,6, 18,2, 9, 1 }};
359 static int QuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
360 { 0, 11,3, 10,2, 9, 1, 8, 0 }, // opposite faces are neighbouring,
361 { 4, 12,5, 13,6, 14,7, 15,4 }, // all face normals are external,
362 { 0, 8, 1, 17,5, 12,4, 16,0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
363 { 3, 19,7, 14,6, 18,2, 10,3 },
364 { 0, 16,4, 15,7, 19,3, 11,0 },
365 { 1, 9, 2, 18,6, 13,5, 17,1 }};
366 static int QuadHexa_nbN [] = { 8, 8, 8, 8, 8, 8 };
369 // ========================================================
370 // to perform some calculations without linkage to CASCADE
371 // ========================================================
378 XYZ() { x = 0; y = 0; z = 0; }
379 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
380 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
381 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
382 inline XYZ operator-( const XYZ& other );
383 inline XYZ Crossed( const XYZ& other );
384 inline double Dot( const XYZ& other );
385 inline double Magnitude();
387 inline XYZ XYZ::operator-( const XYZ& Right ) {
388 return XYZ(x - Right.x, y - Right.y, z - Right.z);
390 inline XYZ XYZ::Crossed( const XYZ& Right ) {
391 return XYZ (y * Right.z - z * Right.y,
392 z * Right.x - x * Right.z,
393 x * Right.y - y * Right.x);
395 inline double XYZ::Dot( const XYZ& Other ) {
396 return(x * Other.x + y * Other.y + z * Other.z);
398 inline double XYZ::Magnitude() {
399 return sqrt (x * x + y * y + z * z);
403 //=======================================================================
404 //function : SMDS_VolumeTool
406 //=======================================================================
408 SMDS_VolumeTool::SMDS_VolumeTool ()
411 myVolForward( true ),
413 myVolumeNbNodes( 0 ),
414 myVolumeNodes( NULL ),
415 myExternalFaces( false ),
418 myFaceNodeIndices( NULL ),
421 //MESSAGE("******************************************************** SMDS_VolumeToo");
424 //=======================================================================
425 //function : SMDS_VolumeTool
427 //=======================================================================
429 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume)
432 myVolForward( true ),
434 myVolumeNbNodes( 0 ),
435 myVolumeNodes( NULL ),
436 myExternalFaces( false ),
439 myFaceNodeIndices( NULL ),
442 //MESSAGE("******************************************************** SMDS_VolumeToo");
446 //=======================================================================
447 //function : SMDS_VolumeTool
449 //=======================================================================
451 SMDS_VolumeTool::~SMDS_VolumeTool()
453 if ( myVolumeNodes != NULL ) delete [] myVolumeNodes;
454 if ( myFaceNodes != NULL ) delete [] myFaceNodes;
456 myFaceNodeIndices = NULL;
457 myVolumeNodes = myFaceNodes = NULL;
460 //=======================================================================
461 //function : SetVolume
462 //purpose : Set volume to iterate on
463 //=======================================================================
465 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume)
473 if (myVolumeNodes != NULL) {
474 delete [] myVolumeNodes;
475 myVolumeNodes = NULL;
478 myExternalFaces = false;
482 myFaceNodeIndices = NULL;
483 if (myFaceNodes != NULL) {
484 delete [] myFaceNodes;
488 if ( theVolume && theVolume->GetType() == SMDSAbs_Volume )
490 myVolume = theVolume;
492 myNbFaces = theVolume->NbFaces();
493 myVolumeNbNodes = theVolume->NbNodes();
497 myVolumeNodes = new const SMDS_MeshNode* [myVolumeNbNodes];
498 SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator();
499 while ( nodeIt->more() ) {
500 myVolumeNodes[ iNode++ ] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
503 if (myVolume->IsPoly()) {
504 myPolyedre = dynamic_cast<const SMDS_VtkVolume*>( myVolume );
506 MESSAGE("Warning: bad volumic element");
511 switch ( myVolumeNbNodes ) {
520 // define volume orientation
522 GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
523 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
524 int topNodeIndex = myVolume->NbCornerNodes() - 1;
525 while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
526 const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
527 XYZ upDir (topNode->X() - botNode->X(),
528 topNode->Y() - botNode->Y(),
529 topNode->Z() - botNode->Z() );
530 myVolForward = ( botNormal.Dot( upDir ) < 0 );
538 return ( myVolume != 0 );
541 //=======================================================================
543 //purpose : Inverse volume
544 //=======================================================================
546 #define SWAP_NODES(nodes,i1,i2) \
548 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
549 nodes[ i1 ] = nodes[ i2 ]; \
552 void SMDS_VolumeTool::Inverse ()
554 if ( !myVolume ) return;
556 if (myVolume->IsPoly()) {
557 MESSAGE("Warning: attempt to inverse polyhedral volume");
561 myVolForward = !myVolForward;
564 // inverse top and bottom faces
565 switch ( myVolumeNbNodes ) {
567 SWAP_NODES( myVolumeNodes, 1, 2 );
570 SWAP_NODES( myVolumeNodes, 1, 3 );
573 SWAP_NODES( myVolumeNodes, 1, 2 );
574 SWAP_NODES( myVolumeNodes, 4, 5 );
577 SWAP_NODES( myVolumeNodes, 1, 3 );
578 SWAP_NODES( myVolumeNodes, 5, 7 );
582 SWAP_NODES( myVolumeNodes, 1, 2 );
583 SWAP_NODES( myVolumeNodes, 4, 6 );
584 SWAP_NODES( myVolumeNodes, 8, 9 );
587 SWAP_NODES( myVolumeNodes, 1, 3 );
588 SWAP_NODES( myVolumeNodes, 5, 8 );
589 SWAP_NODES( myVolumeNodes, 6, 7 );
590 SWAP_NODES( myVolumeNodes, 10, 12 );
593 SWAP_NODES( myVolumeNodes, 1, 2 );
594 SWAP_NODES( myVolumeNodes, 4, 5 );
595 SWAP_NODES( myVolumeNodes, 6, 8 );
596 SWAP_NODES( myVolumeNodes, 9, 11 );
597 SWAP_NODES( myVolumeNodes, 13, 14 );
600 SWAP_NODES( myVolumeNodes, 1, 3 );
601 SWAP_NODES( myVolumeNodes, 5, 7 );
602 SWAP_NODES( myVolumeNodes, 8, 11 );
603 SWAP_NODES( myVolumeNodes, 9, 10 );
604 SWAP_NODES( myVolumeNodes, 12, 15 );
605 SWAP_NODES( myVolumeNodes, 13, 14 );
606 SWAP_NODES( myVolumeNodes, 17, 19 );
612 //=======================================================================
613 //function : GetVolumeType
615 //=======================================================================
617 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
623 // static const VolumeType types[] = {
624 // TETRA, // myVolumeNbNodes = 4
625 // PYRAM, // myVolumeNbNodes = 5
626 // PENTA, // myVolumeNbNodes = 6
627 // UNKNOWN, // myVolumeNbNodes = 7
628 // HEXA // myVolumeNbNodes = 8
630 // return types[ myVolumeNbNodes - 4 ];
631 switch(myVolumeNbNodes) {
632 case 4: return TETRA; break;
633 case 5: return PYRAM; break;
634 case 6: return PENTA; break;
635 case 8: return HEXA; break;
636 case 10: return QUAD_TETRA; break;
637 case 13: return QUAD_PYRAM; break;
638 case 15: return QUAD_PENTA; break;
639 case 20: return QUAD_HEXA; break;
647 //=======================================================================
648 //function : getTetraVolume
650 //=======================================================================
652 static double getTetraVolume(const SMDS_MeshNode* n1,
653 const SMDS_MeshNode* n2,
654 const SMDS_MeshNode* n3,
655 const SMDS_MeshNode* n4)
673 double Q1 = -(X1-X2)*(Y3*Z4-Y4*Z3);
674 double Q2 = (X1-X3)*(Y2*Z4-Y4*Z2);
675 double R1 = -(X1-X4)*(Y2*Z3-Y3*Z2);
676 double R2 = -(X2-X3)*(Y1*Z4-Y4*Z1);
677 double S1 = (X2-X4)*(Y1*Z3-Y3*Z1);
678 double S2 = -(X3-X4)*(Y1*Z2-Y2*Z1);
680 return (Q1+Q2+R1+R2+S1+S2)/6.0;
683 //=======================================================================
685 //purpose : Return element volume
686 //=======================================================================
688 double SMDS_VolumeTool::GetSize() const
694 if ( myVolume->IsPoly() )
699 SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myPolyedre->getMeshId()];
700 // split a polyhedron into tetrahedrons
702 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
704 me->GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
705 SMDS_MeshNode *bcNode = mesh->AddNode( baryCenter.x, baryCenter.y, baryCenter.z );
707 for ( int f = 0; f < NbFaces(); ++f )
709 bool externalFace = me->IsFaceExternal( f ); // it calls setFace()
710 for ( int n = 2; n < myFaceNbNodes; ++n )
712 double Vn = getTetraVolume( myFaceNodes[ 0 ],
716 /// cout <<"++++ " << Vn << " nodes " <<myFaceNodes[ 0 ]->GetID() << " " <<myFaceNodes[ n-1 ]->GetID() << " " <<myFaceNodes[ n ]->GetID() << " < " << V << endl;
717 V += externalFace ? -Vn : Vn;
720 mesh->RemoveNode(bcNode);
724 const static int ind[] = {
725 0, 1, 3, 6, 11, 19, 32, 46, 66};
726 const static int vtab[][4] = {
743 // quadratic tetrahedron
768 // quadratic pentahedron
785 // quadratic hexahedron
810 int type = GetVolumeType();
812 int n2 = ind[type+1];
814 for (int i = n1; i < n2; i++) {
815 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
816 myVolumeNodes[ vtab[i][1] ],
817 myVolumeNodes[ vtab[i][2] ],
818 myVolumeNodes[ vtab[i][3] ]);
824 //=======================================================================
825 //function : GetBaryCenter
827 //=======================================================================
829 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
835 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
836 X += myVolumeNodes[ i ]->X();
837 Y += myVolumeNodes[ i ]->Y();
838 Z += myVolumeNodes[ i ]->Z();
840 X /= myVolumeNbNodes;
841 Y /= myVolumeNbNodes;
842 Z /= myVolumeNbNodes;
847 //================================================================================
849 * \brief Classify a point
850 * \param tol - thickness of faces
852 //================================================================================
854 bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol)
856 // LIMITATION: for convex volumes only
858 for ( int iF = 0; iF < myNbFaces; ++iF )
861 if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
863 if ( !IsFaceExternal( iF ))
864 faceNormal = XYZ() - faceNormal; // reverse
866 XYZ face2p( p - XYZ( myFaceNodes[0] ));
867 if ( face2p.Dot( faceNormal ) > tol )
873 //=======================================================================
874 //function : SetExternalNormal
875 //purpose : Node order will be so that faces normals are external
876 //=======================================================================
878 void SMDS_VolumeTool::SetExternalNormal ()
880 myExternalFaces = true;
884 //=======================================================================
885 //function : NbFaceNodes
886 //purpose : Return number of nodes in the array of face nodes
887 //=======================================================================
889 int SMDS_VolumeTool::NbFaceNodes( int faceIndex )
891 if ( !setFace( faceIndex ))
893 return myFaceNbNodes;
896 //=======================================================================
897 //function : GetFaceNodes
898 //purpose : Return pointer to the array of face nodes.
899 // To comfort link iteration, the array
900 // length == NbFaceNodes( faceIndex ) + 1 and
901 // the last node == the first one.
902 //=======================================================================
904 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex )
906 if ( !setFace( faceIndex ))
911 //=======================================================================
912 //function : GetFaceNodesIndices
913 //purpose : Return pointer to the array of face nodes indices
914 // To comfort link iteration, the array
915 // length == NbFaceNodes( faceIndex ) + 1 and
916 // the last node index == the first one.
917 //=======================================================================
919 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex )
921 if ( !setFace( faceIndex ))
924 if (myVolume->IsPoly())
926 myPolyIndices.resize( myFaceNbNodes + 1 );
927 myFaceNodeIndices = & myPolyIndices[0];
928 for ( int i = 0; i <= myFaceNbNodes; ++i )
929 myFaceNodeIndices[i] = myVolume->GetNodeIndex( myFaceNodes[i] );
931 return myFaceNodeIndices;
934 //=======================================================================
935 //function : GetFaceNodes
936 //purpose : Return a set of face nodes.
937 //=======================================================================
939 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
940 set<const SMDS_MeshNode*>& theFaceNodes )
942 if ( !setFace( faceIndex ))
945 theFaceNodes.clear();
946 int iNode, nbNode = myFaceNbNodes;
947 for ( iNode = 0; iNode < nbNode; iNode++ )
948 theFaceNodes.insert( myFaceNodes[ iNode ]);
953 //=======================================================================
954 //function : IsFaceExternal
955 //purpose : Check normal orientation of a returned face
956 //=======================================================================
958 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex )
960 if ( myExternalFaces || !myVolume )
963 if (myVolume->IsPoly()) {
964 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
965 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
966 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
967 XYZ insideVec (baryCenter - p0);
968 if (insideVec.Dot(aNormal) > 0)
973 switch ( myVolumeNbNodes ) {
978 // only the bottom of a reversed tetrahedron can be internal
979 return ( myVolForward || faceIndex != 0 );
982 // in a forward pentahedron, the top is internal, in a reversed one - bottom
983 return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
986 // in a forward hexahedron, even face normal is external, odd - internal
987 bool odd = faceIndex % 2;
988 return ( myVolForward ? !odd : odd );
995 //=======================================================================
996 //function : GetFaceNormal
997 //purpose : Return a normal to a face
998 //=======================================================================
1000 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z)
1002 if ( !setFace( faceIndex ))
1005 XYZ p1 ( myFaceNodes[0] );
1006 XYZ p2 ( myFaceNodes[1] );
1007 XYZ p3 ( myFaceNodes[2] );
1008 XYZ aVec12( p2 - p1 );
1009 XYZ aVec13( p3 - p1 );
1010 XYZ cross = aVec12.Crossed( aVec13 );
1012 //if ( myFaceNbNodes == 4 ) {
1013 if ( myFaceNbNodes >3 ) {
1014 XYZ p4 ( myFaceNodes[3] );
1015 XYZ aVec14( p4 - p1 );
1016 XYZ cross2 = aVec13.Crossed( aVec14 );
1017 cross.x += cross2.x;
1018 cross.y += cross2.y;
1019 cross.z += cross2.z;
1022 double size = cross.Magnitude();
1023 if ( size <= DBL_MIN )
1033 //================================================================================
1035 * \brief Return barycenter of a face
1037 //================================================================================
1039 bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z)
1041 if ( !setFace( faceIndex ))
1045 for ( int i = 0; i < myFaceNbNodes; ++i )
1047 X += myFaceNodes[i]->X() / myFaceNbNodes;
1048 Y += myFaceNodes[i]->Y() / myFaceNbNodes;
1049 Z += myFaceNodes[i]->Z() / myFaceNbNodes;
1054 //=======================================================================
1055 //function : GetFaceArea
1056 //purpose : Return face area
1057 //=======================================================================
1059 double SMDS_VolumeTool::GetFaceArea( int faceIndex )
1061 if (myVolume->IsPoly()) {
1062 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
1066 if ( !setFace( faceIndex ))
1069 XYZ p1 ( myFaceNodes[0] );
1070 XYZ p2 ( myFaceNodes[1] );
1071 XYZ p3 ( myFaceNodes[2] );
1072 XYZ aVec12( p2 - p1 );
1073 XYZ aVec13( p3 - p1 );
1074 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
1076 if ( myFaceNbNodes == 4 ) {
1077 XYZ p4 ( myFaceNodes[3] );
1078 XYZ aVec14( p4 - p1 );
1079 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
1084 //=======================================================================
1085 //function : GetOppFaceIndex
1086 //purpose : Return index of the opposite face if it exists, else -1.
1087 //=======================================================================
1089 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
1092 if (myVolume->IsPoly()) {
1093 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
1097 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
1098 switch ( myVolumeNbNodes ) {
1100 if ( faceIndex == 0 || faceIndex == 1 )
1101 ind = 1 - faceIndex;
1104 ind = faceIndex + ( faceIndex % 2 ? -1 : 1 );
1112 //=======================================================================
1113 //function : IsLinked
1114 //purpose : return true if theNode1 is linked with theNode2
1115 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1116 //=======================================================================
1118 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
1119 const SMDS_MeshNode* theNode2,
1120 const bool theIgnoreMediumNodes) const
1125 if (myVolume->IsPoly()) {
1127 MESSAGE("Warning: bad volumic element");
1130 bool isLinked = false;
1132 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
1133 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
1135 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
1136 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
1138 if (curNode == theNode1 || curNode == theNode2) {
1139 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
1140 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
1142 if ((curNode == theNode1 && nextNode == theNode2) ||
1143 (curNode == theNode2 && nextNode == theNode1)) {
1152 // find nodes indices
1153 int i1 = -1, i2 = -1;
1154 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1155 if ( myVolumeNodes[ i ] == theNode1 )
1157 else if ( myVolumeNodes[ i ] == theNode2 )
1160 return IsLinked( i1, i2 );
1163 //=======================================================================
1164 //function : IsLinked
1165 //purpose : return true if the node with theNode1Index is linked
1166 // with the node with theNode2Index
1167 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1168 //=======================================================================
1170 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
1171 const int theNode2Index,
1172 bool theIgnoreMediumNodes) const
1174 if ( myVolume->IsPoly() ) {
1175 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
1178 int minInd = min( theNode1Index, theNode2Index );
1179 int maxInd = max( theNode1Index, theNode2Index );
1181 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
1184 SMDSAbs_EntityType type = myVolume->GetEntityType();
1185 if ( myVolume->IsQuadratic() )
1187 int firstMediumInd = myVolume->NbCornerNodes();
1188 if ( minInd >= firstMediumInd )
1189 return false; // medium nodes are not linked
1190 if ( maxInd < firstMediumInd ) // both nodes are corners
1191 if ( theIgnoreMediumNodes )
1192 type = SMDSAbs_EntityType( int(type)-1 ); // check linkage of corner nodes
1194 return false; // corner nodes are not linked directly in a quadratic cell
1198 case SMDSEntity_Tetra:
1200 case SMDSEntity_Hexa:
1201 switch ( maxInd - minInd ) {
1202 case 1: return minInd != 3;
1203 case 3: return minInd == 0 || minInd == 4;
1204 case 4: return true;
1208 case SMDSEntity_Pyramid:
1211 switch ( maxInd - minInd ) {
1213 case 3: return true;
1217 case SMDSEntity_Penta:
1218 switch ( maxInd - minInd ) {
1219 case 1: return minInd != 2;
1220 case 2: return minInd == 0 || minInd == 3;
1221 case 3: return true;
1225 case SMDSEntity_Quad_Tetra:
1228 case 0: if( maxInd==4 || maxInd==6 || maxInd==7 ) return true;
1229 case 1: if( maxInd==4 || maxInd==5 || maxInd==8 ) return true;
1230 case 2: if( maxInd==5 || maxInd==6 || maxInd==9 ) return true;
1231 case 3: if( maxInd==7 || maxInd==8 || maxInd==9 ) return true;
1236 case SMDSEntity_Quad_Hexa:
1239 case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
1240 case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
1241 case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
1242 case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
1243 case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
1244 case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
1245 case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
1246 case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
1251 case SMDSEntity_Quad_Pyramid:
1254 case 0: if( maxInd==5 || maxInd==8 || maxInd==9 ) return true;
1255 case 1: if( maxInd==5 || maxInd==6 || maxInd==10 ) return true;
1256 case 2: if( maxInd==6 || maxInd==7 || maxInd==11 ) return true;
1257 case 3: if( maxInd==7 || maxInd==8 || maxInd==12 ) return true;
1258 case 4: if( maxInd==9 || maxInd==10 || maxInd==11 || maxInd==12 ) return true;
1263 case SMDSEntity_Quad_Penta:
1266 case 0: if( maxInd==6 || maxInd==8 || maxInd==12 ) return true;
1267 case 1: if( maxInd==6 || maxInd==7 || maxInd==13 ) return true;
1268 case 2: if( maxInd==7 || maxInd==8 || maxInd==14 ) return true;
1269 case 3: if( maxInd==9 || maxInd==11 || maxInd==12 ) return true;
1270 case 4: if( maxInd==9 || maxInd==10 || maxInd==13 ) return true;
1271 case 5: if( maxInd==10 || maxInd==11 || maxInd==14 ) return true;
1281 //=======================================================================
1282 //function : GetNodeIndex
1283 //purpose : Return an index of theNode
1284 //=======================================================================
1286 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
1289 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1290 if ( myVolumeNodes[ i ] == theNode )
1297 //================================================================================
1299 * \brief Fill vector with boundary faces existing in the mesh
1300 * \param faces - vector of found nodes
1301 * \retval int - nb of found faces
1303 //================================================================================
1305 int SMDS_VolumeTool::GetAllExistingFaces(vector<const SMDS_MeshElement*> & faces)
1308 faces.reserve( NbFaces() );
1309 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1310 const SMDS_MeshFace* face = 0;
1311 const SMDS_MeshNode** nodes = GetFaceNodes( iF );
1312 switch ( NbFaceNodes( iF )) {
1314 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
1316 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
1318 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
1319 nodes[3], nodes[4], nodes[5]); break;
1321 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
1322 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1325 faces.push_back( face );
1327 return faces.size();
1331 //================================================================================
1333 * \brief Fill vector with boundary edges existing in the mesh
1334 * \param edges - vector of found edges
1335 * \retval int - nb of found faces
1337 //================================================================================
1339 int SMDS_VolumeTool::GetAllExistingEdges(vector<const SMDS_MeshElement*> & edges) const
1342 edges.reserve( myVolumeNbNodes * 2 );
1343 for ( int i = 0; i < myVolumeNbNodes; ++i ) {
1344 for ( int j = i + 1; j < myVolumeNbNodes; ++j ) {
1345 if ( IsLinked( i, j )) {
1346 const SMDS_MeshElement* edge =
1347 SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
1349 edges.push_back( edge );
1353 return edges.size();
1356 //=======================================================================
1357 //function : IsFreeFace
1358 //purpose : check that only one volume is build on the face nodes
1359 //=======================================================================
1361 bool SMDS_VolumeTool::IsFreeFace( int faceIndex )
1363 const int free = true;
1365 if (!setFace( faceIndex ))
1368 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
1369 int nbFaceNodes = myFaceNbNodes;
1371 // evaluate nb of face nodes shared by other volume
1372 int maxNbShared = -1;
1373 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
1374 TElemIntMap volNbShared;
1375 TElemIntMap::iterator vNbIt;
1376 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1377 const SMDS_MeshNode* n = nodes[ iNode ];
1378 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator();
1379 while ( eIt->more() ) {
1380 const SMDS_MeshElement* elem = eIt->next();
1381 if ( elem != myVolume && elem->GetType() == SMDSAbs_Volume ) {
1383 vNbIt = volNbShared.find( elem );
1384 if ( vNbIt == volNbShared.end() ) {
1385 volNbShared.insert ( TElemIntMap::value_type( elem, nbShared ));
1388 nbShared = ++(*vNbIt).second;
1390 if ( nbShared > maxNbShared )
1391 maxNbShared = nbShared;
1395 if ( maxNbShared < 3 )
1396 return free; // is free
1398 // find volumes laying on the opposite side of the face
1399 // and sharing all nodes
1400 XYZ intNormal; // internal normal
1401 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
1402 if ( IsFaceExternal( faceIndex ))
1403 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
1404 XYZ p0 ( nodes[0] ), baryCenter;
1405 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
1406 int nbShared = (*vNbIt).second;
1407 if ( nbShared >= 3 ) {
1408 SMDS_VolumeTool volume( (*vNbIt).first );
1409 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
1410 XYZ intNormal2( baryCenter - p0 );
1411 if ( intNormal.Dot( intNormal2 ) < 0 )
1412 continue; // opposite side
1414 // remove a volume from volNbShared map
1415 volNbShared.erase( vNbIt-- );
1418 // here volNbShared contains only volumes laying on the
1419 // opposite side of the face
1420 if ( volNbShared.empty() ) {
1421 return free; // is free
1424 // check if the whole area of a face is shared
1425 bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
1426 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
1427 SMDS_VolumeTool volume( (*vNbIt).first );
1428 bool prevLinkShared = false;
1429 int nbSharedLinks = 0;
1430 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1431 bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
1434 if ( linkShared && prevLinkShared &&
1435 volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
1436 isShared[ iNode ] = true;
1437 prevLinkShared = linkShared;
1439 if ( nbSharedLinks == nbFaceNodes )
1440 return !free; // is not free
1441 if ( nbFaceNodes == 4 ) {
1442 // check traingle parts 1 & 3
1443 if ( isShared[1] && isShared[3] )
1444 return !free; // is not free
1445 // check triangle parts 0 & 2;
1446 // 0 part could not be checked in the loop; check it here
1447 if ( isShared[2] && prevLinkShared &&
1448 volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
1449 volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
1450 return !free; // is not free
1456 //=======================================================================
1457 //function : GetFaceIndex
1458 //purpose : Return index of a face formed by theFaceNodes
1459 //=======================================================================
1461 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes )
1463 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1464 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
1465 int nbFaceNodes = NbFaceNodes( iFace );
1466 set<const SMDS_MeshNode*> nodeSet;
1467 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1468 nodeSet.insert( nodes[ iNode ] );
1469 if ( theFaceNodes == nodeSet )
1475 //=======================================================================
1476 //function : GetFaceIndex
1477 //purpose : Return index of a face formed by theFaceNodes
1478 //=======================================================================
1480 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
1482 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1483 const int* nodes = GetFaceNodesIndices( iFace );
1484 int nbFaceNodes = NbFaceNodes( iFace );
1486 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1487 nodeSet.insert( nodes[ iNode ] );
1488 if ( theFaceNodesIndices == nodeSet )
1494 //=======================================================================
1495 //function : setFace
1497 //=======================================================================
1499 bool SMDS_VolumeTool::setFace( int faceIndex )
1504 if ( myCurFace == faceIndex )
1509 if ( faceIndex < 0 || faceIndex >= NbFaces() )
1512 if (myFaceNodes != NULL) {
1513 delete [] myFaceNodes;
1517 if (myVolume->IsPoly()) {
1519 MESSAGE("Warning: bad volumic element");
1523 // check orientation
1524 bool isGoodOri = true;
1525 if (myExternalFaces)
1526 isGoodOri = IsFaceExternal( faceIndex );
1530 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
1531 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1533 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1534 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
1536 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1537 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, myFaceNbNodes - iNode);
1539 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
1543 // choose face node indices
1544 switch ( myVolumeNbNodes ) {
1546 myFaceNbNodes = Tetra_nbN[ faceIndex ];
1547 if ( myExternalFaces )
1548 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_RE[ faceIndex ];
1550 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_R[ faceIndex ];
1553 myFaceNbNodes = Pyramid_nbN[ faceIndex ];
1554 if ( myExternalFaces )
1555 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_RE[ faceIndex ];
1557 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_R[ faceIndex ];
1560 myFaceNbNodes = Penta_nbN[ faceIndex ];
1561 if ( myExternalFaces )
1562 myFaceNodeIndices = myVolForward ? Penta_FE[ faceIndex ] : Penta_RE[ faceIndex ];
1564 myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ];
1567 myFaceNbNodes = Hexa_nbN[ faceIndex ];
1568 if ( myExternalFaces )
1569 myFaceNodeIndices = myVolForward ? Hexa_FE[ faceIndex ] : Hexa_RE[ faceIndex ];
1571 myFaceNodeIndices = Hexa_F[ faceIndex ];
1574 myFaceNbNodes = QuadTetra_nbN[ faceIndex ];
1575 if ( myExternalFaces )
1576 myFaceNodeIndices = myVolForward ? QuadTetra_F[ faceIndex ] : QuadTetra_RE[ faceIndex ];
1578 myFaceNodeIndices = myVolForward ? QuadTetra_F[ faceIndex ] : QuadTetra_R[ faceIndex ];
1581 myFaceNbNodes = QuadPyram_nbN[ faceIndex ];
1582 if ( myExternalFaces )
1583 myFaceNodeIndices = myVolForward ? QuadPyram_F[ faceIndex ] : QuadPyram_RE[ faceIndex ];
1585 myFaceNodeIndices = myVolForward ? QuadPyram_F[ faceIndex ] : QuadPyram_R[ faceIndex ];
1588 myFaceNbNodes = QuadPenta_nbN[ faceIndex ];
1589 if ( myExternalFaces )
1590 myFaceNodeIndices = myVolForward ? QuadPenta_FE[ faceIndex ] : QuadPenta_RE[ faceIndex ];
1592 myFaceNodeIndices = myVolForward ? QuadPenta_F[ faceIndex ] : QuadPenta_R[ faceIndex ];
1595 myFaceNbNodes = QuadHexa_nbN[ faceIndex ];
1596 if ( myExternalFaces )
1597 myFaceNodeIndices = myVolForward ? QuadHexa_FE[ faceIndex ] : QuadHexa_RE[ faceIndex ];
1599 myFaceNodeIndices = QuadHexa_F[ faceIndex ];
1606 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1607 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
1608 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
1609 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
1612 myCurFace = faceIndex;
1617 //=======================================================================
1618 //function : GetType
1619 //purpose : return VolumeType by nb of nodes in a volume
1620 //=======================================================================
1622 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
1624 switch ( nbNodes ) {
1625 case 4: return TETRA;
1626 case 5: return PYRAM;
1627 case 6: return PENTA;
1628 case 8: return HEXA;
1629 case 10: return QUAD_TETRA;
1630 case 13: return QUAD_PYRAM;
1631 case 15: return QUAD_PENTA;
1632 case 20: return QUAD_HEXA;
1633 default:return UNKNOWN;
1637 //=======================================================================
1638 //function : NbFaces
1639 //purpose : return nb of faces by volume type
1640 //=======================================================================
1642 int SMDS_VolumeTool::NbFaces( VolumeType type )
1646 case QUAD_TETRA: return 4;
1648 case QUAD_PYRAM: return 5;
1650 case QUAD_PENTA: return 5;
1652 case QUAD_HEXA : return 6;
1657 //================================================================================
1659 * \brief Useful to know nb of corner nodes of a quadratic volume
1660 * \param type - volume type
1661 * \retval int - nb of corner nodes
1663 //================================================================================
1665 int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
1669 case QUAD_TETRA: return 4;
1671 case QUAD_PYRAM: return 5;
1673 case QUAD_PENTA: return 6;
1675 case QUAD_HEXA : return 8;
1682 //=======================================================================
1683 //function : GetFaceNodesIndices
1684 //purpose : Return the array of face nodes indices
1685 // To comfort link iteration, the array
1686 // length == NbFaceNodes( faceIndex ) + 1 and
1687 // the last node index == the first one.
1688 //=======================================================================
1690 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1695 case TETRA: return Tetra_F[ faceIndex ];
1696 case PYRAM: return Pyramid_F[ faceIndex ];
1697 case PENTA: return external ? Penta_FE[ faceIndex ] : Penta_F[ faceIndex ];
1698 case HEXA: return external ? Hexa_FE[ faceIndex ] : Hexa_F[ faceIndex ];
1699 case QUAD_TETRA: return QuadTetra_F[ faceIndex ];
1700 case QUAD_PYRAM: return QuadPyram_F[ faceIndex ];
1701 case QUAD_PENTA: return external ? QuadPenta_FE[ faceIndex ] : QuadPenta_F[ faceIndex ];
1702 case QUAD_HEXA: return external ? QuadHexa_FE[ faceIndex ] : QuadHexa_F[ faceIndex ];
1708 //=======================================================================
1709 //function : NbFaceNodes
1710 //purpose : Return number of nodes in the array of face nodes
1711 //=======================================================================
1713 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1717 case TETRA: return Tetra_nbN[ faceIndex ];
1718 case PYRAM: return Pyramid_nbN[ faceIndex ];
1719 case PENTA: return Penta_nbN[ faceIndex ];
1720 case HEXA: return Hexa_nbN[ faceIndex ];
1721 case QUAD_TETRA: return QuadTetra_nbN[ faceIndex ];
1722 case QUAD_PYRAM: return QuadPyram_nbN[ faceIndex ];
1723 case QUAD_PENTA: return QuadPenta_nbN[ faceIndex ];
1724 case QUAD_HEXA: return QuadHexa_nbN[ faceIndex ];
1730 //=======================================================================
1732 //purpose : return element
1733 //=======================================================================
1735 const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
1737 return static_cast<const SMDS_MeshVolume*>( myVolume );
1740 //=======================================================================
1742 //purpose : return element ID
1743 //=======================================================================
1745 int SMDS_VolumeTool::ID() const
1747 return myVolume ? myVolume->GetID() : 0;