1 // Copyright (C) 2007-2011 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 // ======================================================
50 // For all elements, 0-th face is bottom based on the first nodes.
51 // For prismatic elements (tetra,hexa,prisms), 1-th face is a top one.
52 // For all elements, side faces follow order of bottom nodes
53 // ======================================================
61 // N0 +---|---+ N1 TETRAHEDRON
69 static int Tetra_F [4][4] = { // FORWARD == EXTERNAL
70 { 0, 1, 2, 0 }, // All faces have external normals
74 static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL)
75 { 0, 2, 1, 0 }, // All faces have external normals
79 static int Tetra_nbN [] = { 3, 3, 3, 3 };
84 static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL
85 { 0, 1, 2, 3, 0 }, // All faces have external normals
91 static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL)
92 { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals
97 static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 };
108 // | / \ | PENTAHEDRON
114 static int Penta_F [5][5] = { // FORWARD
115 { 0, 1, 2, 0, 0 }, // All faces have external normals
116 { 3, 5, 4, 3, 3 }, // 0 is bottom, 1 is top face
120 static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL
126 static int Penta_nbN [] = { 3, 3, 4, 4, 4 };
133 // N4+----------+N7 |
134 // | | | | HEXAHEDRON
137 // | N1+------|---+N2
143 static int Hexa_F [6][5] = { // FORWARD
145 { 4, 7, 6, 5, 4 }, // all face normals are external
150 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
152 { 4, 5, 6, 7, 4 }, // all face normals are external
157 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
176 static int HexPrism_F [8][7] = { // FORWARD
177 { 0, 1, 2, 3, 4, 5, 0 },
178 { 6,11,10, 9, 8, 7, 6 },
179 { 0, 6, 7, 1, 0, 0, 0 },
180 { 1, 7, 8, 2, 1, 1, 1 },
181 { 2, 8, 9, 3, 2, 2, 2 },
182 { 3, 9,10, 4, 3, 3, 3 },
183 { 4,10,11, 5, 4, 4, 4 },
184 { 5,11, 6, 0, 5, 5, 5 }};
185 static int HexPrism_RE [8][7] = { // REVERSED -> EXTERNAL
186 { 0, 5, 4, 3, 2, 1, 0 },
187 { 6,11,10, 9, 8, 7, 6 },
188 { 0, 6, 7, 1, 0, 0, 0 },
189 { 1, 7, 8, 2, 1, 1, 1 },
190 { 2, 8, 9, 3, 2, 2, 2 },
191 { 3, 9,10, 4, 3, 3, 3 },
192 { 4,10,11, 5, 4, 4, 4 },
193 { 5,11, 6, 0, 5, 5, 5 }};
194 static int HexPrism_nbN [] = { 6, 6, 4, 4, 4, 4, 4, 4 };
203 // N0 +---|---+ N1 TETRAHEDRON
211 static int QuadTetra_F [4][7] = { // FORWARD
212 { 0, 4, 1, 5, 2, 6, 0 }, // All faces have external normals
213 { 0, 7, 3, 8, 1, 4, 0 },
214 { 1, 8, 3, 9, 2, 5, 1 },
215 { 0, 6, 2, 9, 3, 7, 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
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_RE [5][9] = { // REVERSED -> FORWARD (EXTERNAL)
251 { 0, 8, 3, 7, 2, 6, 1, 5, 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_nbN [] = { 8, 6, 6, 6, 6 };
280 static int QuadPenta_F [5][9] = { // FORWARD
281 { 0, 6, 1, 7, 2, 8, 0, 0, 0 },
282 { 3,11, 5, 10,4, 9, 3, 3, 3 },
283 { 0, 12,3, 9, 4, 13,1, 6, 0 },
284 { 1, 13,4, 10,5, 14,2, 7, 1 },
285 { 0, 8, 2, 14,5, 11,3, 12,0 }};
286 static int QuadPenta_RE [5][9] = { // REVERSED -> EXTERNAL
287 { 0, 8, 2, 7, 1, 6, 0, 0, 0 },
288 { 3, 9, 4, 10,5, 11,3, 3, 3 },
289 { 0, 6, 1, 13,4, 9, 3, 12,0 },
290 { 1, 7, 2, 14,5, 10,4, 13,1 },
291 { 0, 12,3, 11,5, 14,2, 8, 0 }};
292 static int QuadPenta_nbN [] = { 6, 6, 8, 8, 8 };
300 // N4+-----+-----+N7 | QUADRATIC
301 // | | 15 | | HEXAHEDRON
310 // | N1+-----+-|---+N2
317 static int QuadHexa_F [6][9] = { // FORWARD
318 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // all face normals are external,
319 { 4, 15,7, 14,6, 13,5, 12,4 },
320 { 0, 16,4, 12,5, 17,1, 8, 0 },
321 { 1, 17,5, 13,6, 18,2, 9, 1 },
322 { 3, 10,2, 18,6, 14,7, 19,3 },
323 { 0, 11,3, 19,7, 15,4, 16,0 }};
324 static int QuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
325 { 0, 11,3, 10,2, 9, 1, 8, 0 }, // all face normals are external
326 { 4, 12,5, 13,6, 14,7, 15,4 },
327 { 0, 8, 1, 17,5, 12,4, 16,0 },
328 { 1, 9, 2, 18,6, 13,5, 17,1 },
329 { 3, 19,7, 14,6, 18,2, 10,3 },
330 { 0, 16,4, 15,7, 19,3, 11,0 }};
331 static int QuadHexa_nbN [] = { 8, 8, 8, 8, 8, 8 };
333 static int TriQuadHexa_F [6][9] = { // FORWARD
334 { 0, 8, 1, 9, 2, 10,3, 11, 20 }, // all face normals are external
335 { 4, 15,7, 14,6, 13,5, 12, 25 },
336 { 0, 16,4, 12,5, 17,1, 8, 21 },
337 { 1, 17,5, 13,6, 18,2, 9, 22 },
338 { 3, 10,2, 18,6, 14,7, 19, 23 },
339 { 0, 11,3, 19,7, 15,4, 16, 24 }};
340 static int TriQuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
341 { 0, 11,3, 10,2, 9, 1, 8, 20 }, // opposite faces are neighbouring,
342 { 4, 12,5, 13,6, 14,7, 15, 25 }, // all face normals are external
343 { 0, 8, 1, 17,5, 12,4, 16, 21 },
344 { 1, 9, 2, 18,6, 13,5, 17, 22 },
345 { 3, 19,7, 14,6, 18,2, 10, 23 },
346 { 0, 16,4, 15,7, 19,3, 11, 24 }};
347 static int TriQuadHexa_nbN [] = { 9, 9, 9, 9, 9, 9 };
350 // ========================================================
351 // to perform some calculations without linkage to CASCADE
352 // ========================================================
359 XYZ() { x = 0; y = 0; z = 0; }
360 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
361 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
362 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
363 inline XYZ operator-( const XYZ& other );
364 inline XYZ operator+( const XYZ& other );
365 inline XYZ Crossed( const XYZ& other );
366 inline double Dot( const XYZ& other );
367 inline double Magnitude();
368 inline double SquareMagnitude();
370 inline XYZ XYZ::operator-( const XYZ& Right ) {
371 return XYZ(x - Right.x, y - Right.y, z - Right.z);
373 inline XYZ XYZ::operator+( const XYZ& Right ) {
374 return XYZ(x + Right.x, y + Right.y, z + Right.z);
376 inline XYZ XYZ::Crossed( const XYZ& Right ) {
377 return XYZ (y * Right.z - z * Right.y,
378 z * Right.x - x * Right.z,
379 x * Right.y - y * Right.x);
381 inline double XYZ::Dot( const XYZ& Other ) {
382 return(x * Other.x + y * Other.y + z * Other.z);
384 inline double XYZ::Magnitude() {
385 return sqrt (x * x + y * y + z * z);
387 inline double XYZ::SquareMagnitude() {
388 return (x * x + y * y + z * z);
391 //================================================================================
393 * \brief Return linear type corresponding to a quadratic one
395 //================================================================================
397 SMDS_VolumeTool::VolumeType quadToLinear(SMDS_VolumeTool::VolumeType quadType)
399 SMDS_VolumeTool::VolumeType linType = SMDS_VolumeTool::VolumeType( int(quadType)-4 );
400 const int nbCornersByQuad = SMDS_VolumeTool::NbCornerNodes( quadType );
401 if ( SMDS_VolumeTool::NbCornerNodes( linType ) == nbCornersByQuad )
405 for ( ; iLin < SMDS_VolumeTool::NB_VOLUME_TYPES; ++iLin )
406 if ( SMDS_VolumeTool::NbCornerNodes( SMDS_VolumeTool::VolumeType( iLin )) == nbCornersByQuad)
407 return SMDS_VolumeTool::VolumeType( iLin );
409 return SMDS_VolumeTool::UNKNOWN;
414 //=======================================================================
415 //function : SMDS_VolumeTool
417 //=======================================================================
419 SMDS_VolumeTool::SMDS_VolumeTool ()
420 : myVolumeNodes( NULL ),
426 //=======================================================================
427 //function : SMDS_VolumeTool
429 //=======================================================================
431 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
432 const bool ignoreCentralNodes)
433 : myVolumeNodes( NULL ),
436 Set( theVolume, ignoreCentralNodes );
439 //=======================================================================
440 //function : SMDS_VolumeTool
442 //=======================================================================
444 SMDS_VolumeTool::~SMDS_VolumeTool()
446 if ( myVolumeNodes != NULL ) delete [] myVolumeNodes;
447 if ( myFaceNodes != NULL ) delete [] myFaceNodes;
449 myFaceNodeIndices = NULL;
450 myVolumeNodes = myFaceNodes = NULL;
453 //=======================================================================
454 //function : SetVolume
455 //purpose : Set volume to iterate on
456 //=======================================================================
458 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume,
459 const bool ignoreCentralNodes)
464 myIgnoreCentralNodes = ignoreCentralNodes;
469 if (myVolumeNodes != NULL) {
470 delete [] myVolumeNodes;
471 myVolumeNodes = NULL;
473 myPolyIndices.clear();
475 myExternalFaces = false;
477 myAllFacesNodeIndices_F = 0;
478 //myAllFacesNodeIndices_FE = 0;
479 myAllFacesNodeIndices_RE = 0;
480 myAllFacesNbNodes = 0;
484 myFaceNodeIndices = NULL;
485 if (myFaceNodes != NULL) {
486 delete [] myFaceNodes;
491 if ( !theVolume || theVolume->GetType() != SMDSAbs_Volume )
494 myVolume = theVolume;
495 if (myVolume->IsPoly())
496 myPolyedre = dynamic_cast<const SMDS_VtkVolume*>( myVolume );
498 myNbFaces = theVolume->NbFaces();
499 myVolumeNbNodes = theVolume->NbNodes();
503 myVolumeNodes = new const SMDS_MeshNode* [myVolumeNbNodes];
504 SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator();
505 while ( nodeIt->more() )
506 myVolumeNodes[ iNode++ ] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
510 return ( myVolume = 0 );
514 // define volume orientation
516 GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
517 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
518 int topNodeIndex = myVolume->NbCornerNodes() - 1;
519 while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
520 const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
521 XYZ upDir (topNode->X() - botNode->X(),
522 topNode->Y() - botNode->Y(),
523 topNode->Z() - botNode->Z() );
524 myVolForward = ( botNormal.Dot( upDir ) < 0 );
529 //=======================================================================
531 //purpose : Inverse volume
532 //=======================================================================
534 #define SWAP_NODES(nodes,i1,i2) \
536 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
537 nodes[ i1 ] = nodes[ i2 ]; \
540 void SMDS_VolumeTool::Inverse ()
542 if ( !myVolume ) return;
544 if (myVolume->IsPoly()) {
545 MESSAGE("Warning: attempt to inverse polyhedral volume");
549 myVolForward = !myVolForward;
552 // inverse top and bottom faces
553 switch ( myVolumeNbNodes ) {
555 SWAP_NODES( myVolumeNodes, 1, 2 );
558 SWAP_NODES( myVolumeNodes, 1, 3 );
561 SWAP_NODES( myVolumeNodes, 1, 2 );
562 SWAP_NODES( myVolumeNodes, 4, 5 );
565 SWAP_NODES( myVolumeNodes, 1, 3 );
566 SWAP_NODES( myVolumeNodes, 5, 7 );
569 SWAP_NODES( myVolumeNodes, 1, 5 );
570 SWAP_NODES( myVolumeNodes, 2, 4 );
571 SWAP_NODES( myVolumeNodes, 7, 11 );
572 SWAP_NODES( myVolumeNodes, 8, 10 );
576 SWAP_NODES( myVolumeNodes, 1, 2 );
577 SWAP_NODES( myVolumeNodes, 4, 6 );
578 SWAP_NODES( myVolumeNodes, 8, 9 );
581 SWAP_NODES( myVolumeNodes, 1, 3 );
582 SWAP_NODES( myVolumeNodes, 5, 8 );
583 SWAP_NODES( myVolumeNodes, 6, 7 );
584 SWAP_NODES( myVolumeNodes, 10, 12 );
587 SWAP_NODES( myVolumeNodes, 1, 2 );
588 SWAP_NODES( myVolumeNodes, 4, 5 );
589 SWAP_NODES( myVolumeNodes, 6, 8 );
590 SWAP_NODES( myVolumeNodes, 9, 11 );
591 SWAP_NODES( myVolumeNodes, 13, 14 );
594 SWAP_NODES( myVolumeNodes, 1, 3 );
595 SWAP_NODES( myVolumeNodes, 5, 7 );
596 SWAP_NODES( myVolumeNodes, 8, 11 );
597 SWAP_NODES( myVolumeNodes, 9, 10 );
598 SWAP_NODES( myVolumeNodes, 12, 15 );
599 SWAP_NODES( myVolumeNodes, 13, 14 );
600 SWAP_NODES( myVolumeNodes, 17, 19 );
603 SWAP_NODES( myVolumeNodes, 1, 3 );
604 SWAP_NODES( myVolumeNodes, 5, 7 );
605 SWAP_NODES( myVolumeNodes, 8, 11 );
606 SWAP_NODES( myVolumeNodes, 9, 10 );
607 SWAP_NODES( myVolumeNodes, 12, 15 );
608 SWAP_NODES( myVolumeNodes, 13, 14 );
609 SWAP_NODES( myVolumeNodes, 17, 19 );
610 SWAP_NODES( myVolumeNodes, 21, 24 );
611 SWAP_NODES( myVolumeNodes, 22, 23 );
617 //=======================================================================
618 //function : GetVolumeType
620 //=======================================================================
622 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
627 switch( myVolumeNbNodes ) {
628 case 4: return TETRA;
629 case 5: return PYRAM;
630 case 6: return PENTA;
632 case 12: return HEX_PRISM;
633 case 10: return QUAD_TETRA;
634 case 13: return QUAD_PYRAM;
635 case 15: return QUAD_PENTA;
636 case 20: return QUAD_HEXA;
637 case 27: return QUAD_HEXA;
644 //=======================================================================
645 //function : getTetraVolume
647 //=======================================================================
649 static double getTetraVolume(const SMDS_MeshNode* n1,
650 const SMDS_MeshNode* n2,
651 const SMDS_MeshNode* n3,
652 const SMDS_MeshNode* n4)
670 double Q1 = -(X1-X2)*(Y3*Z4-Y4*Z3);
671 double Q2 = (X1-X3)*(Y2*Z4-Y4*Z2);
672 double R1 = -(X1-X4)*(Y2*Z3-Y3*Z2);
673 double R2 = -(X2-X3)*(Y1*Z4-Y4*Z1);
674 double S1 = (X2-X4)*(Y1*Z3-Y3*Z1);
675 double S2 = -(X3-X4)*(Y1*Z2-Y2*Z1);
677 return (Q1+Q2+R1+R2+S1+S2)/6.0;
680 //=======================================================================
682 //purpose : Return element volume
683 //=======================================================================
685 double SMDS_VolumeTool::GetSize() const
691 if ( myVolume->IsPoly() )
696 // split a polyhedron into tetrahedrons
698 int saveCurFace = myCurFace;
699 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
700 for ( int f = 0; f < NbFaces(); ++f )
703 XYZ area (0,0,0), p1( myFaceNodes[0] );
704 for ( int n = 0; n < myFaceNbNodes; ++n )
706 XYZ p2( myFaceNodes[ n+1 ]);
707 area = area + p1.Crossed( p2 );
713 if ( saveCurFace > -1 && saveCurFace != myCurFace )
714 me->setFace( myCurFace );
718 const static int ind[] = {
719 0, 1, 3, 6, 11, 23, 31, 44, 58, 78 };
720 const static int vtab[][4] = { // decomposition into tetra in the order of enum VolumeType
753 // quadratic tetrahedron
778 // quadratic pentahedron
795 // quadratic hexahedron
820 int type = GetVolumeType();
822 int n2 = ind[type+1];
824 for (int i = n1; i < n2; i++) {
825 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
826 myVolumeNodes[ vtab[i][1] ],
827 myVolumeNodes[ vtab[i][2] ],
828 myVolumeNodes[ vtab[i][3] ]);
834 //=======================================================================
835 //function : GetBaryCenter
837 //=======================================================================
839 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
845 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
846 X += myVolumeNodes[ i ]->X();
847 Y += myVolumeNodes[ i ]->Y();
848 Z += myVolumeNodes[ i ]->Z();
850 X /= myVolumeNbNodes;
851 Y /= myVolumeNbNodes;
852 Z /= myVolumeNbNodes;
857 //================================================================================
859 * \brief Classify a point
860 * \param tol - thickness of faces
862 //================================================================================
864 bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol) const
866 // LIMITATION: for convex volumes only
868 for ( int iF = 0; iF < myNbFaces; ++iF )
871 if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
873 if ( !IsFaceExternal( iF ))
874 faceNormal = XYZ() - faceNormal; // reverse
876 XYZ face2p( p - XYZ( myFaceNodes[0] ));
877 if ( face2p.Dot( faceNormal ) > tol )
883 //=======================================================================
884 //function : SetExternalNormal
885 //purpose : Node order will be so that faces normals are external
886 //=======================================================================
888 void SMDS_VolumeTool::SetExternalNormal ()
890 myExternalFaces = true;
894 //=======================================================================
895 //function : NbFaceNodes
896 //purpose : Return number of nodes in the array of face nodes
897 //=======================================================================
899 int SMDS_VolumeTool::NbFaceNodes( int faceIndex ) const
901 if ( !setFace( faceIndex ))
903 return myFaceNbNodes;
906 //=======================================================================
907 //function : GetFaceNodes
908 //purpose : Return pointer to the array of face nodes.
909 // To comfort link iteration, the array
910 // length == NbFaceNodes( faceIndex ) + 1 and
911 // the last node == the first one.
912 //=======================================================================
914 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex ) const
916 if ( !setFace( faceIndex ))
921 //=======================================================================
922 //function : GetFaceNodesIndices
923 //purpose : Return pointer to the array of face nodes indices
924 // To comfort link iteration, the array
925 // length == NbFaceNodes( faceIndex ) + 1 and
926 // the last node index == the first one.
927 //=======================================================================
929 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) const
931 if ( !setFace( faceIndex ))
936 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
937 me->myPolyIndices.resize( myFaceNbNodes + 1 );
938 me->myFaceNodeIndices = & me->myPolyIndices[0];
939 for ( int i = 0; i <= myFaceNbNodes; ++i )
940 me->myFaceNodeIndices[i] = myVolume->GetNodeIndex( myFaceNodes[i] );
942 return myFaceNodeIndices;
945 //=======================================================================
946 //function : GetFaceNodes
947 //purpose : Return a set of face nodes.
948 //=======================================================================
950 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
951 set<const SMDS_MeshNode*>& theFaceNodes ) const
953 if ( !setFace( faceIndex ))
956 theFaceNodes.clear();
957 theFaceNodes.insert( myFaceNodes, myFaceNodes + myFaceNbNodes );
962 //=======================================================================
963 //function : IsFaceExternal
964 //purpose : Check normal orientation of a given face
965 //=======================================================================
967 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const
969 if ( myExternalFaces || !myVolume )
972 if (myVolume->IsPoly()) {
973 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
974 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
975 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
976 XYZ insideVec (baryCenter - p0);
977 if (insideVec.Dot(aNormal) > 0)
982 // switch ( myVolumeNbNodes ) {
987 // // only the bottom of a reversed tetrahedron can be internal
988 // return ( myVolForward || faceIndex != 0 );
992 // // in a forward prism, the top is internal, in a reversed one - bottom
993 // return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
997 // // in a forward hexahedron, even face normal is external, odd - internal
998 // bool odd = faceIndex % 2;
999 // return ( myVolForward ? !odd : odd );
1007 //=======================================================================
1008 //function : GetFaceNormal
1009 //purpose : Return a normal to a face
1010 //=======================================================================
1012 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const
1014 if ( !setFace( faceIndex ))
1017 XYZ p1 ( myFaceNodes[0] );
1018 XYZ p2 ( myFaceNodes[1] );
1019 XYZ p3 ( myFaceNodes[2] );
1020 XYZ aVec12( p2 - p1 );
1021 XYZ aVec13( p3 - p1 );
1022 XYZ cross = aVec12.Crossed( aVec13 );
1024 //if ( myFaceNbNodes == 4 ) {
1025 if ( myFaceNbNodes >3 ) {
1026 XYZ p4 ( myFaceNodes[3] );
1027 XYZ aVec14( p4 - p1 );
1028 XYZ cross2 = aVec13.Crossed( aVec14 );
1029 cross = cross + cross2;
1032 double size = cross.Magnitude();
1033 if ( size <= numeric_limits<double>::min() )
1043 //================================================================================
1045 * \brief Return barycenter of a face
1047 //================================================================================
1049 bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const
1051 if ( !setFace( faceIndex ))
1055 for ( int i = 0; i < myFaceNbNodes; ++i )
1057 X += myFaceNodes[i]->X() / myFaceNbNodes;
1058 Y += myFaceNodes[i]->Y() / myFaceNbNodes;
1059 Z += myFaceNodes[i]->Z() / myFaceNbNodes;
1064 //=======================================================================
1065 //function : GetFaceArea
1066 //purpose : Return face area
1067 //=======================================================================
1069 double SMDS_VolumeTool::GetFaceArea( int faceIndex ) const
1071 if (myVolume->IsPoly()) {
1072 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
1076 if ( !setFace( faceIndex ))
1079 XYZ p1 ( myFaceNodes[0] );
1080 XYZ p2 ( myFaceNodes[1] );
1081 XYZ p3 ( myFaceNodes[2] );
1082 XYZ aVec12( p2 - p1 );
1083 XYZ aVec13( p3 - p1 );
1084 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
1086 if ( myFaceNbNodes == 4 ) {
1087 XYZ p4 ( myFaceNodes[3] );
1088 XYZ aVec14( p4 - p1 );
1089 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
1094 //================================================================================
1096 * \brief Return index of the node located at face center of a quadratic element like HEX27
1098 //================================================================================
1100 int SMDS_VolumeTool::GetCenterNodeIndex( int faceIndex ) const
1102 if ( myAllFacesNbNodes && myVolumeNbNodes == 27 ) // classic element with 27 nodes
1104 switch ( faceIndex ) {
1108 return faceIndex + 19;
1114 //=======================================================================
1115 //function : GetOppFaceIndex
1116 //purpose : Return index of the opposite face if it exists, else -1.
1117 //=======================================================================
1119 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
1123 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
1127 const int nbHoriFaces = 2;
1129 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
1130 switch ( myVolumeNbNodes ) {
1133 if ( faceIndex == 0 || faceIndex == 1 )
1134 ind = 1 - faceIndex;
1138 if ( faceIndex <= 1 ) // top or bottom
1139 ind = 1 - faceIndex;
1141 const int nbSideFaces = myAllFacesNbNodes[0];
1142 ind = ( faceIndex - nbHoriFaces + nbSideFaces/2 ) % nbSideFaces + nbHoriFaces;
1147 if ( faceIndex <= 1 ) // top or bottom
1148 ind = 1 - faceIndex;
1150 const int nbSideFaces = myAllFacesNbNodes[0] / 2;
1151 ind = ( faceIndex - nbHoriFaces + nbSideFaces/2 ) % nbSideFaces + nbHoriFaces;
1160 //=======================================================================
1161 //function : IsLinked
1162 //purpose : return true if theNode1 is linked with theNode2
1163 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1164 //=======================================================================
1166 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
1167 const SMDS_MeshNode* theNode2,
1168 const bool theIgnoreMediumNodes) const
1173 if (myVolume->IsPoly()) {
1175 MESSAGE("Warning: bad volumic element");
1178 bool isLinked = false;
1180 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
1181 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
1183 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
1184 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
1186 if (curNode == theNode1 || curNode == theNode2) {
1187 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
1188 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
1190 if ((curNode == theNode1 && nextNode == theNode2) ||
1191 (curNode == theNode2 && nextNode == theNode1)) {
1200 // find nodes indices
1201 int i1 = -1, i2 = -1, nbFound = 0;
1202 for ( int i = 0; i < myVolumeNbNodes && nbFound < 2; i++ )
1204 if ( myVolumeNodes[ i ] == theNode1 )
1206 else if ( myVolumeNodes[ i ] == theNode2 )
1209 return IsLinked( i1, i2 );
1212 //=======================================================================
1213 //function : IsLinked
1214 //purpose : return true if the node with theNode1Index is linked
1215 // with the node with theNode2Index
1216 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1217 //=======================================================================
1219 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
1220 const int theNode2Index,
1221 bool theIgnoreMediumNodes) const
1223 if ( myVolume->IsPoly() ) {
1224 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
1227 int minInd = min( theNode1Index, theNode2Index );
1228 int maxInd = max( theNode1Index, theNode2Index );
1230 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
1233 VolumeType type = GetVolumeType();
1234 if ( myVolume->IsQuadratic() )
1236 int firstMediumInd = myVolume->NbCornerNodes();
1237 if ( minInd >= firstMediumInd )
1238 return false; // both nodes are medium - not linked
1239 if ( maxInd < firstMediumInd ) // both nodes are corners
1241 if ( theIgnoreMediumNodes )
1242 type = quadToLinear(type); // to check linkage of corner nodes only
1244 return false; // corner nodes are not linked directly in a quadratic cell
1252 switch ( maxInd - minInd ) {
1253 case 1: return minInd != 3;
1254 case 3: return minInd == 0 || minInd == 4;
1255 case 4: return true;
1262 switch ( maxInd - minInd ) {
1264 case 3: return true;
1269 switch ( maxInd - minInd ) {
1270 case 1: return minInd != 2;
1271 case 2: return minInd == 0 || minInd == 3;
1272 case 3: return true;
1279 case 0: if( maxInd==4 || maxInd==6 || maxInd==7 ) return true;
1280 case 1: if( maxInd==4 || maxInd==5 || maxInd==8 ) return true;
1281 case 2: if( maxInd==5 || maxInd==6 || maxInd==9 ) return true;
1282 case 3: if( maxInd==7 || maxInd==8 || maxInd==9 ) return true;
1290 case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
1291 case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
1292 case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
1293 case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
1294 case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
1295 case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
1296 case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
1297 case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
1305 case 0: if( maxInd==5 || maxInd==8 || maxInd==9 ) return true;
1306 case 1: if( maxInd==5 || maxInd==6 || maxInd==10 ) return true;
1307 case 2: if( maxInd==6 || maxInd==7 || maxInd==11 ) return true;
1308 case 3: if( maxInd==7 || maxInd==8 || maxInd==12 ) return true;
1309 case 4: if( maxInd==9 || maxInd==10 || maxInd==11 || maxInd==12 ) return true;
1317 case 0: if( maxInd==6 || maxInd==8 || maxInd==12 ) return true;
1318 case 1: if( maxInd==6 || maxInd==7 || maxInd==13 ) return true;
1319 case 2: if( maxInd==7 || maxInd==8 || maxInd==14 ) return true;
1320 case 3: if( maxInd==9 || maxInd==11 || maxInd==12 ) return true;
1321 case 4: if( maxInd==9 || maxInd==10 || maxInd==13 ) return true;
1322 case 5: if( maxInd==10 || maxInd==11 || maxInd==14 ) return true;
1329 const int diff = maxInd-minInd;
1330 if ( diff > 6 ) return false;// not linked top and bottom
1331 if ( diff == 6 ) return true; // linked top and bottom
1332 return diff == 1 || diff == 7;
1339 //=======================================================================
1340 //function : GetNodeIndex
1341 //purpose : Return an index of theNode
1342 //=======================================================================
1344 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
1347 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1348 if ( myVolumeNodes[ i ] == theNode )
1355 //================================================================================
1357 * \brief Fill vector with boundary faces existing in the mesh
1358 * \param faces - vector of found nodes
1359 * \retval int - nb of found faces
1361 //================================================================================
1363 int SMDS_VolumeTool::GetAllExistingFaces(vector<const SMDS_MeshElement*> & faces) const
1366 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1367 const SMDS_MeshFace* face = 0;
1368 const SMDS_MeshNode** nodes = GetFaceNodes( iF );
1369 switch ( NbFaceNodes( iF )) {
1371 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
1373 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
1375 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
1376 nodes[3], nodes[4], nodes[5]); break;
1378 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
1379 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1382 faces.push_back( face );
1384 return faces.size();
1388 //================================================================================
1390 * \brief Fill vector with boundary edges existing in the mesh
1391 * \param edges - vector of found edges
1392 * \retval int - nb of found faces
1394 //================================================================================
1396 int SMDS_VolumeTool::GetAllExistingEdges(vector<const SMDS_MeshElement*> & edges) const
1399 edges.reserve( myVolumeNbNodes * 2 );
1400 for ( int i = 0; i < myVolumeNbNodes-1; ++i ) {
1401 for ( int j = i + 1; j < myVolumeNbNodes; ++j ) {
1402 if ( IsLinked( i, j )) {
1403 const SMDS_MeshElement* edge =
1404 SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
1406 edges.push_back( edge );
1410 return edges.size();
1413 //================================================================================
1415 * \brief Return minimal square distance between connected corner nodes
1417 //================================================================================
1419 double SMDS_VolumeTool::MinLinearSize2() const
1421 double minSize = 1e+100;
1422 int iQ = myVolume->IsQuadratic() ? 2 : 1;
1424 // store current face data
1425 int curFace = myCurFace, nbN = myFaceNbNodes;
1426 int* ind = myFaceNodeIndices;
1427 myFaceNodeIndices = NULL;
1428 const SMDS_MeshNode** nodes = myFaceNodes;
1431 // it seems that compute distance twice is faster than organization of a sole computing
1433 for ( int iF = 0; iF < myNbFaces; ++iF )
1436 for ( int iN = 0; iN < myFaceNbNodes; iN += iQ )
1438 XYZ n1( myFaceNodes[ iN ]);
1439 XYZ n2( myFaceNodes[(iN + iQ) % myFaceNbNodes]);
1440 minSize = std::min( minSize, (n1 - n2).SquareMagnitude());
1443 // restore current face data
1444 myCurFace = curFace;
1445 myFaceNbNodes = nbN;
1446 myFaceNodeIndices = ind;
1447 delete [] myFaceNodes; myFaceNodes = nodes;
1452 //================================================================================
1454 * \brief check that only one volume is build on the face nodes
1456 * If a face is shared by one of <ignoreVolumes>, it is considered free
1458 //================================================================================
1460 bool SMDS_VolumeTool::IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
1462 const bool isFree = true;
1464 if (!setFace( faceIndex ))
1467 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
1468 const int nbFaceNodes = myFaceNbNodes;
1470 // evaluate nb of face nodes shared by other volumes
1471 int maxNbShared = -1;
1472 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
1473 TElemIntMap volNbShared;
1474 TElemIntMap::iterator vNbIt;
1475 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1476 const SMDS_MeshNode* n = nodes[ iNode ];
1477 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1478 while ( eIt->more() ) {
1479 const SMDS_MeshElement* elem = eIt->next();
1480 if ( elem != myVolume ) {
1481 vNbIt = volNbShared.insert( make_pair( elem, 0 )).first;
1483 if ( vNbIt->second > maxNbShared )
1484 maxNbShared = vNbIt->second;
1488 if ( maxNbShared < 3 )
1489 return isFree; // is free
1491 // find volumes laying on the opposite side of the face
1492 // and sharing all nodes
1493 XYZ intNormal; // internal normal
1494 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
1495 if ( IsFaceExternal( faceIndex ))
1496 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
1497 XYZ p0 ( nodes[0] ), baryCenter;
1498 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); ) {
1499 const int& nbShared = (*vNbIt).second;
1500 if ( nbShared >= 3 ) {
1501 SMDS_VolumeTool volume( (*vNbIt).first );
1502 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
1503 XYZ intNormal2( baryCenter - p0 );
1504 if ( intNormal.Dot( intNormal2 ) < 0 ) {
1506 if ( nbShared >= nbFaceNodes )
1508 // a volume shares the whole facet
1509 if ( otherVol ) *otherVol = vNbIt->first;
1516 // remove a volume from volNbShared map
1517 volNbShared.erase( vNbIt++ );
1520 // here volNbShared contains only volumes laying on the opposite side of
1521 // the face and sharing 3 or more but not all face nodes with myVolume
1522 if ( volNbShared.size() < 2 ) {
1523 return isFree; // is free
1526 // check if the whole area of a face is shared
1527 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1529 const SMDS_MeshNode* n = nodes[ iNode ];
1530 // check if n is shared by one of volumes of volNbShared
1531 bool isShared = false;
1532 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1533 while ( eIt->more() && !isShared )
1534 isShared = volNbShared.count( eIt->next() );
1538 if ( otherVol ) *otherVol = volNbShared.begin()->first;
1541 // if ( !myVolume->IsPoly() )
1543 // bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
1544 // for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
1545 // SMDS_VolumeTool volume( (*vNbIt).first );
1546 // bool prevLinkShared = false;
1547 // int nbSharedLinks = 0;
1548 // for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1549 // bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
1550 // if ( linkShared )
1552 // if ( linkShared && prevLinkShared &&
1553 // volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
1554 // isShared[ iNode ] = true;
1555 // prevLinkShared = linkShared;
1557 // if ( nbSharedLinks == nbFaceNodes )
1558 // return !free; // is not free
1559 // if ( nbFaceNodes == 4 ) {
1560 // // check traingle parts 1 & 3
1561 // if ( isShared[1] && isShared[3] )
1562 // return !free; // is not free
1563 // // check triangle parts 0 & 2;
1564 // // 0 part could not be checked in the loop; check it here
1565 // if ( isShared[2] && prevLinkShared &&
1566 // volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
1567 // volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
1568 // return !free; // is not free
1575 //=======================================================================
1576 //function : GetFaceIndex
1577 //purpose : Return index of a face formed by theFaceNodes
1578 //=======================================================================
1580 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes ) const
1582 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1583 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
1584 int nbFaceNodes = NbFaceNodes( iFace );
1585 set<const SMDS_MeshNode*> nodeSet;
1586 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1587 nodeSet.insert( nodes[ iNode ] );
1588 if ( theFaceNodes == nodeSet )
1594 //=======================================================================
1595 //function : GetFaceIndex
1596 //purpose : Return index of a face formed by theFaceNodes
1597 //=======================================================================
1599 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
1601 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1602 const int* nodes = GetFaceNodesIndices( iFace );
1603 int nbFaceNodes = NbFaceNodes( iFace );
1605 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1606 nodeSet.insert( nodes[ iNode ] );
1607 if ( theFaceNodesIndices == nodeSet )
1613 //=======================================================================
1614 //function : setFace
1616 //=======================================================================
1618 bool SMDS_VolumeTool::setFace( int faceIndex ) const
1623 if ( myCurFace == faceIndex )
1628 if ( faceIndex < 0 || faceIndex >= NbFaces() )
1631 if (myFaceNodes != NULL) {
1632 delete [] myFaceNodes;
1636 if (myVolume->IsPoly())
1639 MESSAGE("Warning: bad volumic element");
1645 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
1646 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1647 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1648 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
1649 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
1651 // check orientation
1652 if (myExternalFaces)
1654 myCurFace = faceIndex; // avoid infinite recursion in IsFaceExternal()
1655 myExternalFaces = false; // force normal computation by IsFaceExternal()
1656 if ( !IsFaceExternal( faceIndex ))
1657 for ( int i = 0, j = myFaceNbNodes; i < j; ++i, --j )
1658 std::swap( myFaceNodes[i], myFaceNodes[j] );
1659 myExternalFaces = true;
1664 if ( !myAllFacesNodeIndices_F )
1666 // choose data for an element type
1667 switch ( myVolumeNbNodes ) {
1669 myAllFacesNodeIndices_F = &Tetra_F [0][0];
1670 //myAllFacesNodeIndices_FE = &Tetra_F [0][0];
1671 myAllFacesNodeIndices_RE = &Tetra_RE[0][0];
1672 myAllFacesNbNodes = Tetra_nbN;
1673 myMaxFaceNbNodes = sizeof(Tetra_F[0])/sizeof(Tetra_F[0][0]);
1676 myAllFacesNodeIndices_F = &Pyramid_F [0][0];
1677 //myAllFacesNodeIndices_FE = &Pyramid_F [0][0];
1678 myAllFacesNodeIndices_RE = &Pyramid_RE[0][0];
1679 myAllFacesNbNodes = Pyramid_nbN;
1680 myMaxFaceNbNodes = sizeof(Pyramid_F[0])/sizeof(Pyramid_F[0][0]);
1683 myAllFacesNodeIndices_F = &Penta_F [0][0];
1684 //myAllFacesNodeIndices_FE = &Penta_FE[0][0];
1685 myAllFacesNodeIndices_RE = &Penta_RE[0][0];
1686 myAllFacesNbNodes = Penta_nbN;
1687 myMaxFaceNbNodes = sizeof(Penta_F[0])/sizeof(Penta_F[0][0]);
1690 myAllFacesNodeIndices_F = &Hexa_F [0][0];
1691 ///myAllFacesNodeIndices_FE = &Hexa_FE[0][0];
1692 myAllFacesNodeIndices_RE = &Hexa_RE[0][0];
1693 myAllFacesNbNodes = Hexa_nbN;
1694 myMaxFaceNbNodes = sizeof(Hexa_F[0])/sizeof(Hexa_F[0][0]);
1697 myAllFacesNodeIndices_F = &QuadTetra_F [0][0];
1698 //myAllFacesNodeIndices_FE = &QuadTetra_F [0][0];
1699 myAllFacesNodeIndices_RE = &QuadTetra_RE[0][0];
1700 myAllFacesNbNodes = QuadTetra_nbN;
1701 myMaxFaceNbNodes = sizeof(QuadTetra_F[0])/sizeof(QuadTetra_F[0][0]);
1704 myAllFacesNodeIndices_F = &QuadPyram_F [0][0];
1705 //myAllFacesNodeIndices_FE = &QuadPyram_F [0][0];
1706 myAllFacesNodeIndices_RE = &QuadPyram_RE[0][0];
1707 myAllFacesNbNodes = QuadPyram_nbN;
1708 myMaxFaceNbNodes = sizeof(QuadPyram_F[0])/sizeof(QuadPyram_F[0][0]);
1711 myAllFacesNodeIndices_F = &QuadPenta_F [0][0];
1712 //myAllFacesNodeIndices_FE = &QuadPenta_FE[0][0];
1713 myAllFacesNodeIndices_RE = &QuadPenta_RE[0][0];
1714 myAllFacesNbNodes = QuadPenta_nbN;
1715 myMaxFaceNbNodes = sizeof(QuadPenta_F[0])/sizeof(QuadPenta_F[0][0]);
1719 myAllFacesNodeIndices_F = &QuadHexa_F [0][0];
1720 //myAllFacesNodeIndices_FE = &QuadHexa_FE[0][0];
1721 myAllFacesNodeIndices_RE = &QuadHexa_RE[0][0];
1722 myAllFacesNbNodes = QuadHexa_nbN;
1723 myMaxFaceNbNodes = sizeof(QuadHexa_F[0])/sizeof(QuadHexa_F[0][0]);
1724 if ( !myIgnoreCentralNodes && myVolumeNbNodes == 27 )
1726 myAllFacesNodeIndices_F = &TriQuadHexa_F [0][0];
1727 //myAllFacesNodeIndices_FE = &TriQuadHexa_FE[0][0];
1728 myAllFacesNodeIndices_RE = &TriQuadHexa_RE[0][0];
1729 myAllFacesNbNodes = TriQuadHexa_nbN;
1730 myMaxFaceNbNodes = sizeof(TriQuadHexa_F[0])/sizeof(TriQuadHexa_F[0][0]);
1734 myAllFacesNodeIndices_F = &HexPrism_F [0][0];
1735 //myAllFacesNodeIndices_FE = &HexPrism_FE[0][0];
1736 myAllFacesNodeIndices_RE = &HexPrism_RE[0][0];
1737 myAllFacesNbNodes = HexPrism_nbN;
1738 myMaxFaceNbNodes = sizeof(HexPrism_F[0])/sizeof(HexPrism_F[0][0]);
1744 myFaceNbNodes = myAllFacesNbNodes[ faceIndex ];
1745 // if ( myExternalFaces )
1746 // myFaceNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_FE + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
1748 // myFaceNodeIndices = (int*)( myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes );
1749 myFaceNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
1752 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1753 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
1754 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
1755 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
1758 myCurFace = faceIndex;
1763 //=======================================================================
1764 //function : GetType
1765 //purpose : return VolumeType by nb of nodes in a volume
1766 //=======================================================================
1768 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
1770 switch ( nbNodes ) {
1771 case 4: return TETRA;
1772 case 5: return PYRAM;
1773 case 6: return PENTA;
1774 case 8: return HEXA;
1775 case 10: return QUAD_TETRA;
1776 case 13: return QUAD_PYRAM;
1777 case 15: return QUAD_PENTA;
1779 case 27: return QUAD_HEXA;
1780 case 12: return HEX_PRISM;
1781 default:return UNKNOWN;
1785 //=======================================================================
1786 //function : NbFaces
1787 //purpose : return nb of faces by volume type
1788 //=======================================================================
1790 int SMDS_VolumeTool::NbFaces( VolumeType type )
1794 case QUAD_TETRA: return 4;
1796 case QUAD_PYRAM: return 5;
1798 case QUAD_PENTA: return 5;
1800 case QUAD_HEXA : return 6;
1801 case HEX_PRISM : return 8;
1806 //================================================================================
1808 * \brief Useful to know nb of corner nodes of a quadratic volume
1809 * \param type - volume type
1810 * \retval int - nb of corner nodes
1812 //================================================================================
1814 int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
1818 case QUAD_TETRA: return 4;
1820 case QUAD_PYRAM: return 5;
1822 case QUAD_PENTA: return 6;
1824 case QUAD_HEXA : return 8;
1825 case HEX_PRISM : return 12;
1832 //=======================================================================
1833 //function : GetFaceNodesIndices
1834 //purpose : Return the array of face nodes indices
1835 // To comfort link iteration, the array
1836 // length == NbFaceNodes( faceIndex ) + 1 and
1837 // the last node index == the first one.
1838 //=======================================================================
1840 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1845 case TETRA: return Tetra_F[ faceIndex ];
1846 case PYRAM: return Pyramid_F[ faceIndex ];
1847 case PENTA: return external ? Penta_F[ faceIndex ] : Penta_F[ faceIndex ];
1848 case HEXA: return external ? Hexa_F[ faceIndex ] : Hexa_F[ faceIndex ];
1849 case QUAD_TETRA: return QuadTetra_F[ faceIndex ];
1850 case QUAD_PYRAM: return QuadPyram_F[ faceIndex ];
1851 case QUAD_PENTA: return external ? QuadPenta_F[ faceIndex ] : QuadPenta_F[ faceIndex ];
1852 // what about SMDSEntity_TriQuad_Hexa?
1853 case QUAD_HEXA: return external ? QuadHexa_F[ faceIndex ] : QuadHexa_F[ faceIndex ];
1854 case HEX_PRISM: return external ? HexPrism_F[ faceIndex ] : HexPrism_F[ faceIndex ];
1860 //=======================================================================
1861 //function : NbFaceNodes
1862 //purpose : Return number of nodes in the array of face nodes
1863 //=======================================================================
1865 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1869 case TETRA: return Tetra_nbN[ faceIndex ];
1870 case PYRAM: return Pyramid_nbN[ faceIndex ];
1871 case PENTA: return Penta_nbN[ faceIndex ];
1872 case HEXA: return Hexa_nbN[ faceIndex ];
1873 case QUAD_TETRA: return QuadTetra_nbN[ faceIndex ];
1874 case QUAD_PYRAM: return QuadPyram_nbN[ faceIndex ];
1875 case QUAD_PENTA: return QuadPenta_nbN[ faceIndex ];
1876 // what about SMDSEntity_TriQuad_Hexa?
1877 case QUAD_HEXA: return QuadHexa_nbN[ faceIndex ];
1878 case HEX_PRISM: return HexPrism_nbN[ faceIndex ];
1884 //=======================================================================
1885 //function : Element
1886 //purpose : return element
1887 //=======================================================================
1889 const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
1891 return static_cast<const SMDS_MeshVolume*>( myVolume );
1894 //=======================================================================
1896 //purpose : return element ID
1897 //=======================================================================
1899 int SMDS_VolumeTool::ID() const
1901 return myVolume ? myVolume->GetID() : 0;