1 // File : SMDS_VolumeTool.cxx
2 // Created : Tue Jul 13 12:22:13 2004
3 // Author : Edward AGAPOV (eap)
4 // Copyright : Open CASCADE
7 #pragma warning(disable:4786)
10 #include "SMDS_VolumeTool.hxx"
12 #include "SMDS_MeshElement.hxx"
13 #include "SMDS_MeshNode.hxx"
14 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
16 #include "utilities.h"
24 // ======================================================
25 // Node indices in faces depending on volume orientation
26 // making most faces normals external
27 // ======================================================
35 // N0 +---|---+ N1 TETRAHEDRON
43 static int Tetra_F [4][4] = { // FORWARD == EXTERNAL
44 { 0, 1, 2, 0 }, // All faces have external normals
48 static int Tetra_R [4][4] = { // REVERSED
49 { 0, 1, 2, 0 }, // All faces but a bottom have external normals
53 static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL)
54 { 0, 2, 1, 0 }, // All faces have external normals
58 static int Tetra_nbN [] = { 3, 3, 3, 3 };
63 static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL
64 { 0, 1, 2, 3, 0 }, // All faces have external normals
69 static int Pyramid_R [5][5] = { // REVERSED
70 { 0, 1, 2, 3, 0 }, // All faces but a bottom have external normals
75 static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL)
76 { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals
81 static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 };
92 // | / \ | PENTAHEDRON
98 static int Penta_F [5][5] = { // FORWARD
99 { 0, 1, 2, 0, 0 }, // Top face has an internal normal, other - external
100 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
104 static int Penta_R [5][5] = { // REVERSED
105 { 0, 1, 2, 0, 0 }, // Bottom face has an internal normal, other - external
106 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
110 static int Penta_FE [5][5] = { // FORWARD -> EXTERNAL
116 static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL
122 static int Penta_nbN [] = { 3, 3, 4, 4, 4 };
129 // N4+----------+N7 |
130 // | | | | HEXAHEDRON
133 // | N1+------|---+N2
139 static int Hexa_F [6][5] = { // FORWARD
140 { 0, 1, 2, 3, 0 }, // opposite faces are neighbouring,
141 { 4, 5, 6, 7, 4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external
142 { 1, 0, 4, 5, 1 }, // same index nodes of opposite faces are linked
146 // static int Hexa_R [6][5] = { // REVERSED
147 // { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
148 // { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal
149 // { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked
150 // { 2, 6, 7, 3, 2 },
151 // { 0, 4, 7, 3, 0 },
152 // { 1, 5, 6, 2, 1 }};
153 static int Hexa_FE [6][5] = { // FORWARD -> EXTERNAL
154 { 0, 1, 2, 3, 0 } , // opposite faces are neighbouring,
155 { 4, 7, 6, 5, 4 }, // all face normals are external,
156 { 0, 4, 5, 1, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
160 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
161 { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
162 { 4, 5, 6, 7, 4 }, // all face normals are external,
163 { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
167 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
169 // ========================================================
170 // to perform some calculations without linkage to CASCADE
171 // ========================================================
176 XYZ() { x = 0; y = 0; z = 0; }
177 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
178 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
179 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
180 XYZ operator-( const XYZ& other );
181 XYZ Crossed( const XYZ& other );
182 double Dot( const XYZ& other );
185 XYZ XYZ::operator-( const XYZ& Right ) {
186 return XYZ(x - Right.x, y - Right.y, z - Right.z);
188 XYZ XYZ::Crossed( const XYZ& Right ) {
189 return XYZ (y * Right.z - z * Right.y,
190 z * Right.x - x * Right.z,
191 x * Right.y - y * Right.x);
193 double XYZ::Dot( const XYZ& Other ) {
194 return(x * Other.x + y * Other.y + z * Other.z);
196 double XYZ::Magnitude() {
197 return sqrt (x * x + y * y + z * z);
200 //=======================================================================
201 //function : SMDS_VolumeTool
203 //=======================================================================
205 SMDS_VolumeTool::SMDS_VolumeTool ()
208 myVolForward( true ),
210 myVolumeNbNodes( 0 ),
211 myVolumeNodes( NULL ),
212 myExternalFaces( false ),
215 myFaceNodeIndices( NULL ),
220 //=======================================================================
221 //function : SMDS_VolumeTool
223 //=======================================================================
225 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume)
228 myVolForward( true ),
230 myVolumeNbNodes( 0 ),
231 myVolumeNodes( NULL ),
232 myExternalFaces( false ),
235 myFaceNodeIndices( NULL ),
241 //=======================================================================
242 //function : SMDS_VolumeTool
244 //=======================================================================
246 SMDS_VolumeTool::~SMDS_VolumeTool()
248 if (myVolumeNodes != NULL) {
249 delete [] myVolumeNodes;
250 myVolumeNodes = NULL;
252 if (myFaceNodes != NULL) {
253 delete [] myFaceNodes;
258 //=======================================================================
259 //function : SetVolume
260 //purpose : Set volume to iterate on
261 //=======================================================================
263 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume)
271 if (myVolumeNodes != NULL) {
272 delete [] myVolumeNodes;
273 myVolumeNodes = NULL;
276 myExternalFaces = false;
280 myFaceNodeIndices = NULL;
281 if (myFaceNodes != NULL) {
282 delete [] myFaceNodes;
286 if ( theVolume && theVolume->GetType() == SMDSAbs_Volume )
288 myVolume = theVolume;
290 myNbFaces = theVolume->NbFaces();
291 myVolumeNbNodes = theVolume->NbNodes();
295 myVolumeNodes = new const SMDS_MeshNode* [myVolumeNbNodes];
296 SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator();
297 while ( nodeIt->more() ) {
298 myVolumeNodes[ iNode++ ] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
301 if (myVolume->IsPoly()) {
302 myPolyedre = static_cast<const SMDS_PolyhedralVolumeOfNodes*>( myVolume );
304 MESSAGE("Warning: bad volumic element");
308 switch ( myVolumeNbNodes ) {
313 // define volume orientation
315 GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
316 const SMDS_MeshNode* topNode = myVolumeNodes[ myVolumeNbNodes - 1 ];
317 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
318 XYZ upDir (topNode->X() - botNode->X(),
319 topNode->Y() - botNode->Y(),
320 topNode->Z() - botNode->Z() );
321 myVolForward = ( botNormal.Dot( upDir ) < 0 );
329 return ( myVolume != 0 );
332 //=======================================================================
334 //purpose : Inverse volume
335 //=======================================================================
337 #define SWAP_NODES(nodes,i1,i2) \
339 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
340 nodes[ i1 ] = nodes[ i2 ]; \
343 void SMDS_VolumeTool::Inverse ()
345 if ( !myVolume ) return;
347 if (myVolume->IsPoly()) {
348 MESSAGE("Warning: attempt to inverse polyhedral volume");
352 myVolForward = !myVolForward;
355 // inverse top and bottom faces
356 switch ( myVolumeNbNodes ) {
358 SWAP_NODES( myVolumeNodes, 1, 2 );
361 SWAP_NODES( myVolumeNodes, 1, 3 );
364 SWAP_NODES( myVolumeNodes, 1, 2 );
365 SWAP_NODES( myVolumeNodes, 4, 5 );
368 SWAP_NODES( myVolumeNodes, 1, 3 );
369 SWAP_NODES( myVolumeNodes, 5, 7 );
375 //=======================================================================
377 //purpose : Return element volume
378 //=======================================================================
380 double SMDS_VolumeTool::GetSize() const
385 //=======================================================================
386 //function : GetBaryCenter
388 //=======================================================================
390 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
396 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
397 X += myVolumeNodes[ i ]->X();
398 Y += myVolumeNodes[ i ]->Y();
399 Z += myVolumeNodes[ i ]->Z();
401 X /= myVolumeNbNodes;
402 Y /= myVolumeNbNodes;
403 Z /= myVolumeNbNodes;
408 //=======================================================================
409 //function : SetExternalNormal
410 //purpose : Node order will be so that faces normals are external
411 //=======================================================================
413 void SMDS_VolumeTool::SetExternalNormal ()
415 myExternalFaces = true;
419 //=======================================================================
420 //function : NbFaceNodes
421 //purpose : Return number of nodes in the array of face nodes
422 //=======================================================================
424 int SMDS_VolumeTool::NbFaceNodes( int faceIndex )
426 if ( !setFace( faceIndex ))
428 return myFaceNbNodes;
431 //=======================================================================
432 //function : GetFaceNodes
433 //purpose : Return pointer to the array of face nodes.
434 // To comfort link iteration, the array
435 // length == NbFaceNodes( faceIndex ) + 1 and
436 // the last node == the first one.
437 //=======================================================================
439 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex )
441 if ( !setFace( faceIndex ))
446 //=======================================================================
447 //function : GetFaceNodesIndices
448 //purpose : Return pointer to the array of face nodes indices
449 // To comfort link iteration, the array
450 // length == NbFaceNodes( faceIndex ) + 1 and
451 // the last node index == the first one.
452 //=======================================================================
454 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex )
456 if (myVolume->IsPoly()) {
457 MESSAGE("Warning: attempt to obtain FaceNodesIndices of polyhedral volume");
460 if ( !setFace( faceIndex ))
462 return myFaceNodeIndices;
465 //=======================================================================
466 //function : GetFaceNodes
467 //purpose : Return a set of face nodes.
468 //=======================================================================
470 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
471 set<const SMDS_MeshNode*>& theFaceNodes )
473 if ( !setFace( faceIndex ))
476 theFaceNodes.clear();
477 int iNode, nbNode = myFaceNbNodes;
478 for ( iNode = 0; iNode < nbNode; iNode++ )
479 theFaceNodes.insert( myFaceNodes[ iNode ]);
484 //=======================================================================
485 //function : IsFaceExternal
486 //purpose : Check normal orientation of a returned face
487 //=======================================================================
489 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex )
491 if ( myExternalFaces || !myVolume )
494 if (myVolume->IsPoly()) {
495 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
496 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
497 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
498 XYZ insideVec (baryCenter - p0);
499 if (insideVec.Dot(aNormal) > 0)
504 switch ( myVolumeNbNodes ) {
507 // only the bottom of a reversed tetrahedron can be internal
508 return ( myVolForward || faceIndex != 0 );
510 // in a forward pentahedron, the top is internal, in a reversed one - bottom
511 return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
513 // in a forward hexahedron, even face normal is external, odd - internal
514 bool odd = faceIndex % 2;
515 return ( myVolForward ? !odd : odd );
522 //=======================================================================
523 //function : GetFaceNormal
524 //purpose : Return a normal to a face
525 //=======================================================================
527 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z)
529 if ( !setFace( faceIndex ))
532 XYZ p1 ( myFaceNodes[0] );
533 XYZ p2 ( myFaceNodes[1] );
534 XYZ p3 ( myFaceNodes[2] );
535 XYZ aVec12( p2 - p1 );
536 XYZ aVec13( p3 - p1 );
537 XYZ cross = aVec12.Crossed( aVec13 );
539 if ( myFaceNbNodes == 4 ) {
540 XYZ p4 ( myFaceNodes[3] );
541 XYZ aVec14( p4 - p1 );
542 XYZ cross2 = aVec13.Crossed( aVec14 );
548 double size = cross.Magnitude();
549 if ( size <= DBL_MIN )
559 //=======================================================================
560 //function : GetFaceArea
561 //purpose : Return face area
562 //=======================================================================
564 double SMDS_VolumeTool::GetFaceArea( int faceIndex )
566 if (myVolume->IsPoly()) {
567 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
571 if ( !setFace( faceIndex ))
574 XYZ p1 ( myFaceNodes[0] );
575 XYZ p2 ( myFaceNodes[1] );
576 XYZ p3 ( myFaceNodes[2] );
577 XYZ aVec12( p2 - p1 );
578 XYZ aVec13( p3 - p1 );
579 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
581 if ( myFaceNbNodes == 4 ) {
582 XYZ p4 ( myFaceNodes[3] );
583 XYZ aVec14( p4 - p1 );
584 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
589 //=======================================================================
590 //function : GetOppFaceIndex
591 //purpose : Return index of the opposite face if it exists, else -1.
592 //=======================================================================
594 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
597 if (myVolume->IsPoly()) {
598 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
602 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
603 switch ( myVolumeNbNodes ) {
605 if ( faceIndex == 0 || faceIndex == 1 )
609 ind = faceIndex + ( faceIndex % 2 ? -1 : 1 );
617 //=======================================================================
618 //function : IsLinked
619 //purpose : return true if theNode1 is linked with theNode2
620 //=======================================================================
622 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
623 const SMDS_MeshNode* theNode2) const
628 if (myVolume->IsPoly()) {
630 MESSAGE("Warning: bad volumic element");
633 bool isLinked = false;
635 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
636 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
638 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
639 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
641 if (curNode == theNode1 || curNode == theNode2) {
642 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
643 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
645 if ((curNode == theNode1 && nextNode == theNode2) ||
646 (curNode == theNode2 && nextNode == theNode1)) {
655 // find nodes indices
656 int i1 = -1, i2 = -1;
657 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
658 if ( myVolumeNodes[ i ] == theNode1 )
660 else if ( myVolumeNodes[ i ] == theNode2 )
663 return IsLinked( i1, i2 );
666 //=======================================================================
667 //function : IsLinked
668 //purpose : return true if the node with theNode1Index is linked
669 // with the node with theNode2Index
670 //=======================================================================
672 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
673 const int theNode2Index) const
675 if (myVolume->IsPoly()) {
676 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
679 int minInd = theNode1Index < theNode2Index ? theNode1Index : theNode2Index;
680 int maxInd = theNode1Index < theNode2Index ? theNode2Index : theNode1Index;
682 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
685 switch ( myVolumeNbNodes ) {
691 switch ( maxInd - minInd ) {
698 switch ( maxInd - minInd ) {
699 case 1: return minInd != 2;
700 case 2: return minInd == 0 || minInd == 3;
706 switch ( maxInd - minInd ) {
707 case 1: return minInd != 3;
708 case 3: return minInd == 0 || minInd == 4;
718 //=======================================================================
719 //function : GetNodeIndex
720 //purpose : Return an index of theNode
721 //=======================================================================
723 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
726 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
727 if ( myVolumeNodes[ i ] == theNode )
734 //=======================================================================
735 //function : IsFreeFace
736 //purpose : check that only one volume is build on the face nodes
737 //=======================================================================
739 bool SMDS_VolumeTool::IsFreeFace( int faceIndex )
741 const int free = true;
743 if (!setFace( faceIndex ))
746 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
747 int nbFaceNodes = myFaceNbNodes;
749 // evaluate nb of face nodes shared by other volume
750 int maxNbShared = -1;
751 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
752 TElemIntMap volNbShared;
753 TElemIntMap::iterator vNbIt;
754 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
756 const SMDS_MeshNode* n = nodes[ iNode ];
757 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator();
758 while ( eIt->more() ) {
759 const SMDS_MeshElement* elem = eIt->next();
760 if ( elem != myVolume && elem->GetType() == SMDSAbs_Volume ) {
762 vNbIt = volNbShared.find( elem );
763 if ( vNbIt == volNbShared.end() )
764 volNbShared.insert ( TElemIntMap::value_type( elem, nbShared ));
766 nbShared = ++(*vNbIt).second;
767 if ( nbShared > maxNbShared )
768 maxNbShared = nbShared;
772 if ( maxNbShared < 3 )
773 return free; // is free
775 // find volumes laying on the opposite side of the face
776 // and sharing all nodes
777 XYZ intNormal; // internal normal
778 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
779 if ( IsFaceExternal( faceIndex ))
780 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
781 XYZ p0 ( nodes[0] ), baryCenter;
782 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ )
784 int nbShared = (*vNbIt).second;
785 if ( nbShared >= 3 ) {
786 SMDS_VolumeTool volume( (*vNbIt).first );
787 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
788 XYZ intNormal2( baryCenter - p0 );
789 if ( intNormal.Dot( intNormal2 ) < 0 )
790 continue; // opposite side
792 // remove a volume from volNbShared map
793 volNbShared.erase( vNbIt );
795 // here volNbShared contains only volumes laying on the
796 // opposite side of the face
797 if ( volNbShared.empty() )
798 return free; // is free
800 // check if the whole area of a face is shared
801 bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
802 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ )
804 SMDS_VolumeTool volume( (*vNbIt).first );
805 bool prevLinkShared = false;
806 int nbSharedLinks = 0;
807 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
809 bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
812 if ( linkShared && prevLinkShared &&
813 volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
814 isShared[ iNode ] = true;
815 prevLinkShared = linkShared;
817 if ( nbSharedLinks == nbFaceNodes )
818 return !free; // is not free
819 if ( nbFaceNodes == 4 ) {
820 // check traingle parts 1 & 3
821 if ( isShared[1] && isShared[3] )
822 return !free; // is not free
823 // check triangle parts 0 & 2;
824 // 0 part could not be checked in the loop; check it here
825 if ( isShared[2] && prevLinkShared &&
826 volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
827 volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
828 return !free; // is not free
834 //=======================================================================
835 //function : GetFaceIndex
836 //purpose : Return index of a face formed by theFaceNodes
837 //=======================================================================
839 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes )
841 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
842 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
843 int nbFaceNodes = NbFaceNodes( iFace );
844 set<const SMDS_MeshNode*> nodeSet;
845 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
846 nodeSet.insert( nodes[ iNode ] );
847 if ( theFaceNodes == nodeSet )
853 //=======================================================================
854 //function : GetFaceIndex
855 //purpose : Return index of a face formed by theFaceNodes
856 //=======================================================================
858 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
860 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
861 const int* nodes = GetFaceNodesIndices( iFace );
862 int nbFaceNodes = NbFaceNodes( iFace );
864 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
865 nodeSet.insert( nodes[ iNode ] );
866 if ( theFaceNodesIndices == nodeSet )
872 //=======================================================================
875 //=======================================================================
877 bool SMDS_VolumeTool::setFace( int faceIndex )
882 if ( myCurFace == faceIndex )
887 if ( faceIndex < 0 || faceIndex >= NbFaces() )
890 if (myFaceNodes != NULL) {
891 delete [] myFaceNodes;
895 if (myVolume->IsPoly()) {
897 MESSAGE("Warning: bad volumic element");
902 bool isGoodOri = true;
903 if (myExternalFaces) {
904 // get natural orientation
905 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
906 SMDS_VolumeTool vTool (myPolyedre);
907 vTool.GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
908 vTool.GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
909 XYZ insideVec (baryCenter - p0);
910 if (insideVec.Dot(aNormal) > 0)
916 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
917 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
919 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
920 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
922 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
923 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, myFaceNbNodes - iNode);
925 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
928 // choose face node indices
929 switch ( myVolumeNbNodes ) {
931 myFaceNbNodes = Tetra_nbN[ faceIndex ];
932 if ( myExternalFaces )
933 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_RE[ faceIndex ];
935 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_R[ faceIndex ];
938 myFaceNbNodes = Pyramid_nbN[ faceIndex ];
939 if ( myExternalFaces )
940 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_RE[ faceIndex ];
942 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_R[ faceIndex ];
945 myFaceNbNodes = Penta_nbN[ faceIndex ];
946 if ( myExternalFaces )
947 myFaceNodeIndices = myVolForward ? Penta_FE[ faceIndex ] : Penta_RE[ faceIndex ];
949 myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ];
952 myFaceNbNodes = Hexa_nbN[ faceIndex ];
953 if ( myExternalFaces )
954 myFaceNodeIndices = myVolForward ? Hexa_FE[ faceIndex ] : Hexa_RE[ faceIndex ];
956 myFaceNodeIndices = Hexa_F[ faceIndex ];
963 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
964 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
965 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
966 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
969 myCurFace = faceIndex;
974 //=======================================================================
976 //purpose : return VolumeType by nb of nodes in a volume
977 //=======================================================================
979 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
982 case 4: return TETRA;
983 case 5: return PYRAM;
984 case 6: return PENTA;
986 default:return UNKNOWN;
990 //=======================================================================
992 //purpose : return nb of faces by volume type
993 //=======================================================================
995 int SMDS_VolumeTool::NbFaces( VolumeType type )
998 case TETRA: return 4;
999 case PYRAM: return 5;
1000 case PENTA: return 5;
1001 case HEXA : return 6;
1006 //=======================================================================
1007 //function : GetFaceNodesIndices
1008 //purpose : Return the array of face nodes indices
1009 // To comfort link iteration, the array
1010 // length == NbFaceNodes( faceIndex ) + 1 and
1011 // the last node index == the first one.
1012 //=======================================================================
1014 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1019 case TETRA: return Tetra_F[ faceIndex ];
1020 case PYRAM: return Pyramid_F[ faceIndex ];
1021 case PENTA: return external ? Penta_FE[ faceIndex ] : Penta_F[ faceIndex ];
1022 case HEXA: return external ? Hexa_FE[ faceIndex ] : Hexa_F[ faceIndex ];
1028 //=======================================================================
1029 //function : NbFaceNodes
1030 //purpose : Return number of nodes in the array of face nodes
1031 //=======================================================================
1033 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1037 case TETRA: return Tetra_nbN[ faceIndex ];
1038 case PYRAM: return Pyramid_nbN[ faceIndex ];
1039 case PENTA: return Penta_nbN[ faceIndex ];
1040 case HEXA: return Hexa_nbN[ faceIndex ];