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 //=======================================================================
376 //function : GetVolumeType
378 //=======================================================================
380 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
386 static const VolumeType types[] = {
387 TETRA, // myVolumeNbNodes = 4
388 PYRAM, // myVolumeNbNodes = 5
389 PENTA, // myVolumeNbNodes = 6
390 UNKNOWN, // myVolumeNbNodes = 7
391 HEXA // myVolumeNbNodes = 8
393 return types[ myVolumeNbNodes - 4 ];
399 //=======================================================================
400 //function : getTetraVolume
402 //=======================================================================
404 static double getTetraVolume(const SMDS_MeshNode* n1,
405 const SMDS_MeshNode* n2,
406 const SMDS_MeshNode* n3,
407 const SMDS_MeshNode* n4)
425 double Q1 = -(X1-X2)*(Y3*Z4-Y4*Z3);
426 double Q2 = (X1-X3)*(Y2*Z4-Y4*Z2);
427 double R1 = -(X1-X4)*(Y2*Z3-Y3*Z2);
428 double R2 = -(X2-X3)*(Y1*Z4-Y4*Z1);
429 double S1 = (X2-X4)*(Y1*Z3-Y3*Z1);
430 double S2 = -(X3-X4)*(Y1*Z2-Y2*Z1);
432 return (Q1+Q2+R1+R2+S1+S2)/6.0;
435 //=======================================================================
437 //purpose : Return element volume
438 //=======================================================================
440 double SMDS_VolumeTool::GetSize() const
446 if ( myVolume->IsPoly() )
451 // split a polyhedron into tetrahedrons
453 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
455 me->GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
456 SMDS_MeshNode bcNode ( baryCenter.x, baryCenter.y, baryCenter.z );
458 for ( int f = 0; f < NbFaces(); ++f )
460 bool externalFace = me->IsFaceExternal( f ); // it calls setFace()
461 for ( int n = 2; n < myFaceNbNodes; ++n )
463 double Vn = getTetraVolume( myFaceNodes[ 0 ],
467 /// cout <<"++++ " << Vn << " nodes " <<myFaceNodes[ 0 ]->GetID() << " " <<myFaceNodes[ n-1 ]->GetID() << " " <<myFaceNodes[ n ]->GetID() << " < " << V << endl;
468 V += externalFace ? -Vn : Vn;
474 const static int ind[] = {
476 const static int vtab[][4] = {
494 int type = GetVolumeType();
496 int n2 = ind[type+1];
498 for (int i = n1; i < n2; i++)
500 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
501 myVolumeNodes[ vtab[i][1] ],
502 myVolumeNodes[ vtab[i][2] ],
503 myVolumeNodes[ vtab[i][3] ]);
509 //=======================================================================
510 //function : GetBaryCenter
512 //=======================================================================
514 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
520 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
521 X += myVolumeNodes[ i ]->X();
522 Y += myVolumeNodes[ i ]->Y();
523 Z += myVolumeNodes[ i ]->Z();
525 X /= myVolumeNbNodes;
526 Y /= myVolumeNbNodes;
527 Z /= myVolumeNbNodes;
532 //=======================================================================
533 //function : SetExternalNormal
534 //purpose : Node order will be so that faces normals are external
535 //=======================================================================
537 void SMDS_VolumeTool::SetExternalNormal ()
539 myExternalFaces = true;
543 //=======================================================================
544 //function : NbFaceNodes
545 //purpose : Return number of nodes in the array of face nodes
546 //=======================================================================
548 int SMDS_VolumeTool::NbFaceNodes( int faceIndex )
550 if ( !setFace( faceIndex ))
552 return myFaceNbNodes;
555 //=======================================================================
556 //function : GetFaceNodes
557 //purpose : Return pointer to the array of face nodes.
558 // To comfort link iteration, the array
559 // length == NbFaceNodes( faceIndex ) + 1 and
560 // the last node == the first one.
561 //=======================================================================
563 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex )
565 if ( !setFace( faceIndex ))
570 //=======================================================================
571 //function : GetFaceNodesIndices
572 //purpose : Return pointer to the array of face nodes indices
573 // To comfort link iteration, the array
574 // length == NbFaceNodes( faceIndex ) + 1 and
575 // the last node index == the first one.
576 //=======================================================================
578 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex )
580 if (myVolume->IsPoly()) {
581 MESSAGE("Warning: attempt to obtain FaceNodesIndices of polyhedral volume");
584 if ( !setFace( faceIndex ))
586 return myFaceNodeIndices;
589 //=======================================================================
590 //function : GetFaceNodes
591 //purpose : Return a set of face nodes.
592 //=======================================================================
594 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
595 set<const SMDS_MeshNode*>& theFaceNodes )
597 if ( !setFace( faceIndex ))
600 theFaceNodes.clear();
601 int iNode, nbNode = myFaceNbNodes;
602 for ( iNode = 0; iNode < nbNode; iNode++ )
603 theFaceNodes.insert( myFaceNodes[ iNode ]);
608 //=======================================================================
609 //function : IsFaceExternal
610 //purpose : Check normal orientation of a returned face
611 //=======================================================================
613 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex )
615 if ( myExternalFaces || !myVolume )
618 if (myVolume->IsPoly()) {
619 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
620 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
621 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
622 XYZ insideVec (baryCenter - p0);
623 if (insideVec.Dot(aNormal) > 0)
628 switch ( myVolumeNbNodes ) {
631 // only the bottom of a reversed tetrahedron can be internal
632 return ( myVolForward || faceIndex != 0 );
634 // in a forward pentahedron, the top is internal, in a reversed one - bottom
635 return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
637 // in a forward hexahedron, even face normal is external, odd - internal
638 bool odd = faceIndex % 2;
639 return ( myVolForward ? !odd : odd );
646 //=======================================================================
647 //function : GetFaceNormal
648 //purpose : Return a normal to a face
649 //=======================================================================
651 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z)
653 if ( !setFace( faceIndex ))
656 XYZ p1 ( myFaceNodes[0] );
657 XYZ p2 ( myFaceNodes[1] );
658 XYZ p3 ( myFaceNodes[2] );
659 XYZ aVec12( p2 - p1 );
660 XYZ aVec13( p3 - p1 );
661 XYZ cross = aVec12.Crossed( aVec13 );
663 if ( myFaceNbNodes == 4 ) {
664 XYZ p4 ( myFaceNodes[3] );
665 XYZ aVec14( p4 - p1 );
666 XYZ cross2 = aVec13.Crossed( aVec14 );
672 double size = cross.Magnitude();
673 if ( size <= DBL_MIN )
683 //=======================================================================
684 //function : GetFaceArea
685 //purpose : Return face area
686 //=======================================================================
688 double SMDS_VolumeTool::GetFaceArea( int faceIndex )
690 if (myVolume->IsPoly()) {
691 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
695 if ( !setFace( faceIndex ))
698 XYZ p1 ( myFaceNodes[0] );
699 XYZ p2 ( myFaceNodes[1] );
700 XYZ p3 ( myFaceNodes[2] );
701 XYZ aVec12( p2 - p1 );
702 XYZ aVec13( p3 - p1 );
703 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
705 if ( myFaceNbNodes == 4 ) {
706 XYZ p4 ( myFaceNodes[3] );
707 XYZ aVec14( p4 - p1 );
708 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
713 //=======================================================================
714 //function : GetOppFaceIndex
715 //purpose : Return index of the opposite face if it exists, else -1.
716 //=======================================================================
718 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
721 if (myVolume->IsPoly()) {
722 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
726 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
727 switch ( myVolumeNbNodes ) {
729 if ( faceIndex == 0 || faceIndex == 1 )
733 ind = faceIndex + ( faceIndex % 2 ? -1 : 1 );
741 //=======================================================================
742 //function : IsLinked
743 //purpose : return true if theNode1 is linked with theNode2
744 //=======================================================================
746 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
747 const SMDS_MeshNode* theNode2) const
752 if (myVolume->IsPoly()) {
754 MESSAGE("Warning: bad volumic element");
757 bool isLinked = false;
759 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
760 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
762 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
763 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
765 if (curNode == theNode1 || curNode == theNode2) {
766 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
767 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
769 if ((curNode == theNode1 && nextNode == theNode2) ||
770 (curNode == theNode2 && nextNode == theNode1)) {
779 // find nodes indices
780 int i1 = -1, i2 = -1;
781 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
782 if ( myVolumeNodes[ i ] == theNode1 )
784 else if ( myVolumeNodes[ i ] == theNode2 )
787 return IsLinked( i1, i2 );
790 //=======================================================================
791 //function : IsLinked
792 //purpose : return true if the node with theNode1Index is linked
793 // with the node with theNode2Index
794 //=======================================================================
796 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
797 const int theNode2Index) const
799 if (myVolume->IsPoly()) {
800 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
803 int minInd = theNode1Index < theNode2Index ? theNode1Index : theNode2Index;
804 int maxInd = theNode1Index < theNode2Index ? theNode2Index : theNode1Index;
806 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
809 switch ( myVolumeNbNodes ) {
815 switch ( maxInd - minInd ) {
822 switch ( maxInd - minInd ) {
823 case 1: return minInd != 2;
824 case 2: return minInd == 0 || minInd == 3;
830 switch ( maxInd - minInd ) {
831 case 1: return minInd != 3;
832 case 3: return minInd == 0 || minInd == 4;
842 //=======================================================================
843 //function : GetNodeIndex
844 //purpose : Return an index of theNode
845 //=======================================================================
847 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
850 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
851 if ( myVolumeNodes[ i ] == theNode )
858 //=======================================================================
859 //function : IsFreeFace
860 //purpose : check that only one volume is build on the face nodes
861 //=======================================================================
863 bool SMDS_VolumeTool::IsFreeFace( int faceIndex )
865 const int free = true;
867 if (!setFace( faceIndex ))
870 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
871 int nbFaceNodes = myFaceNbNodes;
873 // evaluate nb of face nodes shared by other volume
874 int maxNbShared = -1;
875 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
876 TElemIntMap volNbShared;
877 TElemIntMap::iterator vNbIt;
878 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
880 const SMDS_MeshNode* n = nodes[ iNode ];
881 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator();
882 while ( eIt->more() ) {
883 const SMDS_MeshElement* elem = eIt->next();
884 if ( elem != myVolume && elem->GetType() == SMDSAbs_Volume ) {
886 vNbIt = volNbShared.find( elem );
887 if ( vNbIt == volNbShared.end() )
888 volNbShared.insert ( TElemIntMap::value_type( elem, nbShared ));
890 nbShared = ++(*vNbIt).second;
891 if ( nbShared > maxNbShared )
892 maxNbShared = nbShared;
896 if ( maxNbShared < 3 )
897 return free; // is free
899 // find volumes laying on the opposite side of the face
900 // and sharing all nodes
901 XYZ intNormal; // internal normal
902 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
903 if ( IsFaceExternal( faceIndex ))
904 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
905 XYZ p0 ( nodes[0] ), baryCenter;
906 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ )
908 int nbShared = (*vNbIt).second;
909 if ( nbShared >= 3 ) {
910 SMDS_VolumeTool volume( (*vNbIt).first );
911 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
912 XYZ intNormal2( baryCenter - p0 );
913 if ( intNormal.Dot( intNormal2 ) < 0 )
914 continue; // opposite side
916 // remove a volume from volNbShared map
917 volNbShared.erase( vNbIt );
919 // here volNbShared contains only volumes laying on the
920 // opposite side of the face
921 if ( volNbShared.empty() )
922 return free; // is free
924 // check if the whole area of a face is shared
925 bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
926 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ )
928 SMDS_VolumeTool volume( (*vNbIt).first );
929 bool prevLinkShared = false;
930 int nbSharedLinks = 0;
931 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
933 bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
936 if ( linkShared && prevLinkShared &&
937 volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
938 isShared[ iNode ] = true;
939 prevLinkShared = linkShared;
941 if ( nbSharedLinks == nbFaceNodes )
942 return !free; // is not free
943 if ( nbFaceNodes == 4 ) {
944 // check traingle parts 1 & 3
945 if ( isShared[1] && isShared[3] )
946 return !free; // is not free
947 // check triangle parts 0 & 2;
948 // 0 part could not be checked in the loop; check it here
949 if ( isShared[2] && prevLinkShared &&
950 volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
951 volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
952 return !free; // is not free
958 //=======================================================================
959 //function : GetFaceIndex
960 //purpose : Return index of a face formed by theFaceNodes
961 //=======================================================================
963 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes )
965 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
966 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
967 int nbFaceNodes = NbFaceNodes( iFace );
968 set<const SMDS_MeshNode*> nodeSet;
969 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
970 nodeSet.insert( nodes[ iNode ] );
971 if ( theFaceNodes == nodeSet )
977 //=======================================================================
978 //function : GetFaceIndex
979 //purpose : Return index of a face formed by theFaceNodes
980 //=======================================================================
982 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
984 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
985 const int* nodes = GetFaceNodesIndices( iFace );
986 int nbFaceNodes = NbFaceNodes( iFace );
988 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
989 nodeSet.insert( nodes[ iNode ] );
990 if ( theFaceNodesIndices == nodeSet )
996 //=======================================================================
999 //=======================================================================
1001 bool SMDS_VolumeTool::setFace( int faceIndex )
1006 if ( myCurFace == faceIndex )
1011 if ( faceIndex < 0 || faceIndex >= NbFaces() )
1014 if (myFaceNodes != NULL) {
1015 delete [] myFaceNodes;
1019 if (myVolume->IsPoly()) {
1021 MESSAGE("Warning: bad volumic element");
1025 // check orientation
1026 bool isGoodOri = true;
1027 if (myExternalFaces)
1028 isGoodOri = IsFaceExternal( faceIndex );
1032 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
1033 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1035 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1036 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
1038 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1039 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, myFaceNbNodes - iNode);
1041 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
1044 // choose face node indices
1045 switch ( myVolumeNbNodes ) {
1047 myFaceNbNodes = Tetra_nbN[ faceIndex ];
1048 if ( myExternalFaces )
1049 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_RE[ faceIndex ];
1051 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_R[ faceIndex ];
1054 myFaceNbNodes = Pyramid_nbN[ faceIndex ];
1055 if ( myExternalFaces )
1056 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_RE[ faceIndex ];
1058 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_R[ faceIndex ];
1061 myFaceNbNodes = Penta_nbN[ faceIndex ];
1062 if ( myExternalFaces )
1063 myFaceNodeIndices = myVolForward ? Penta_FE[ faceIndex ] : Penta_RE[ faceIndex ];
1065 myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ];
1068 myFaceNbNodes = Hexa_nbN[ faceIndex ];
1069 if ( myExternalFaces )
1070 myFaceNodeIndices = myVolForward ? Hexa_FE[ faceIndex ] : Hexa_RE[ faceIndex ];
1072 myFaceNodeIndices = Hexa_F[ faceIndex ];
1079 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1080 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
1081 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
1082 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
1085 myCurFace = faceIndex;
1090 //=======================================================================
1091 //function : GetType
1092 //purpose : return VolumeType by nb of nodes in a volume
1093 //=======================================================================
1095 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
1097 switch ( nbNodes ) {
1098 case 4: return TETRA;
1099 case 5: return PYRAM;
1100 case 6: return PENTA;
1101 case 8: return HEXA;
1102 default:return UNKNOWN;
1106 //=======================================================================
1107 //function : NbFaces
1108 //purpose : return nb of faces by volume type
1109 //=======================================================================
1111 int SMDS_VolumeTool::NbFaces( VolumeType type )
1114 case TETRA: return 4;
1115 case PYRAM: return 5;
1116 case PENTA: return 5;
1117 case HEXA : return 6;
1122 //=======================================================================
1123 //function : GetFaceNodesIndices
1124 //purpose : Return the array of face nodes indices
1125 // To comfort link iteration, the array
1126 // length == NbFaceNodes( faceIndex ) + 1 and
1127 // the last node index == the first one.
1128 //=======================================================================
1130 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1135 case TETRA: return Tetra_F[ faceIndex ];
1136 case PYRAM: return Pyramid_F[ faceIndex ];
1137 case PENTA: return external ? Penta_FE[ faceIndex ] : Penta_F[ faceIndex ];
1138 case HEXA: return external ? Hexa_FE[ faceIndex ] : Hexa_F[ faceIndex ];
1144 //=======================================================================
1145 //function : NbFaceNodes
1146 //purpose : Return number of nodes in the array of face nodes
1147 //=======================================================================
1149 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1153 case TETRA: return Tetra_nbN[ faceIndex ];
1154 case PYRAM: return Pyramid_nbN[ faceIndex ];
1155 case PENTA: return Penta_nbN[ faceIndex ];
1156 case HEXA: return Hexa_nbN[ faceIndex ];