1 // Copyright (C) 2007-2013 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
135 // | N1+------|---+N2
141 static int Hexa_F [6][5] = { // FORWARD
143 { 4, 7, 6, 5, 4 }, // all face normals are external
148 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
150 { 4, 5, 6, 7, 4 }, // all face normals are external
155 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
156 static int Hexa_oppF[] = { 1, 0, 4, 5, 2, 3 }; // oppopsite facet indices
175 static int HexPrism_F [8][7] = { // FORWARD
176 { 0, 1, 2, 3, 4, 5, 0 },
177 { 6,11,10, 9, 8, 7, 6 },
178 { 0, 6, 7, 1, 0, 0, 0 },
179 { 1, 7, 8, 2, 1, 1, 1 },
180 { 2, 8, 9, 3, 2, 2, 2 },
181 { 3, 9,10, 4, 3, 3, 3 },
182 { 4,10,11, 5, 4, 4, 4 },
183 { 5,11, 6, 0, 5, 5, 5 }};
184 static int HexPrism_RE [8][7] = { // REVERSED -> EXTERNAL
185 { 0, 5, 4, 3, 2, 1, 0 },
186 { 6,11,10, 9, 8, 7, 6 },
187 { 0, 6, 7, 1, 0, 0, 0 },
188 { 1, 7, 8, 2, 1, 1, 1 },
189 { 2, 8, 9, 3, 2, 2, 2 },
190 { 3, 9,10, 4, 3, 3, 3 },
191 { 4,10,11, 5, 4, 4, 4 },
192 { 5,11, 6, 0, 5, 5, 5 }};
193 static int HexPrism_nbN [] = { 6, 6, 4, 4, 4, 4, 4, 4 };
202 // N0 +---|---+ N1 TETRAHEDRON
210 static int QuadTetra_F [4][7] = { // FORWARD
211 { 0, 4, 1, 5, 2, 6, 0 }, // All faces have external normals
212 { 0, 7, 3, 8, 1, 4, 0 },
213 { 1, 8, 3, 9, 2, 5, 1 },
214 { 0, 6, 2, 9, 3, 7, 0 }};
215 static int QuadTetra_RE [4][7] = { // REVERSED -> FORWARD (EXTERNAL)
216 { 0, 6, 2, 5, 1, 4, 0 }, // All faces have external normals
217 { 0, 4, 1, 8, 3, 7, 0 },
218 { 1, 5, 2, 9, 3, 8, 1 },
219 { 0, 7, 3, 9, 2, 6, 0 }};
220 static int QuadTetra_nbN [] = { 6, 6, 6, 6 };
230 // | | 9 - middle point for (0,4) etc.
243 static int QuadPyram_F [5][9] = { // FORWARD
244 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces have external normals
245 { 0, 9, 4, 10,1, 5, 0, 4, 4 },
246 { 1, 10,4, 11,2, 6, 1, 4, 4 },
247 { 2, 11,4, 12,3, 7, 2, 4, 4 },
248 { 3, 12,4, 9, 0, 8, 3, 4, 4 }};
249 static int QuadPyram_RE [5][9] = { // REVERSED -> FORWARD (EXTERNAL)
250 { 0, 8, 3, 7, 2, 6, 1, 5, 0 }, // All faces but a bottom have external normals
251 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
252 { 1, 6, 2, 11,4, 10,1, 4, 4 },
253 { 2, 7, 3, 12,4, 11,2, 4, 4 },
254 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
255 static int QuadPyram_nbN [] = { 8, 6, 6, 6, 6 };
279 static int QuadPenta_F [5][9] = { // FORWARD
280 { 0, 6, 1, 7, 2, 8, 0, 0, 0 },
281 { 3, 11,5, 10,4, 9, 3, 3, 3 },
282 { 0, 12,3, 9, 4, 13,1, 6, 0 },
283 { 1, 13,4, 10,5, 14,2, 7, 1 },
284 { 0, 8, 2, 14,5, 11,3, 12,0 }};
285 static int QuadPenta_RE [5][9] = { // REVERSED -> EXTERNAL
286 { 0, 8, 2, 7, 1, 6, 0, 0, 0 },
287 { 3, 9, 4, 10,5, 11,3, 3, 3 },
288 { 0, 6, 1, 13,4, 9, 3, 12,0 },
289 { 1, 7, 2, 14,5, 10,4, 13,1 },
290 { 0, 12,3, 11,5, 14,2, 8, 0 }};
291 static int QuadPenta_nbN [] = { 6, 6, 8, 8, 8 };
295 // N5+-----+-----+N6 +-----+-----+
297 // 12+ | 14+ | + | +25 + |
299 // N4+-----+-----+N7 | QUADRATIC +-----+-----+ | Central nodes
300 // | | 15 | | HEXAHEDRON | | | | of tri-quadratic
301 // | | | | | | | | HEXAHEDRON
302 // | 17+ | +18 | + 22+ | +
304 // | | | | | + | 26+ | + |
306 // 16+ | +19 | + | +24 + |
309 // | N1+-----+-|---+N2 | +-----+-|---+
311 // | +8 | +10 | + 20+ | +
313 // N0+-----+-----+N3 +-----+-----+
316 static int QuadHexa_F [6][9] = { // FORWARD
317 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // all face normals are external,
318 { 4, 15,7, 14,6, 13,5, 12,4 },
319 { 0, 16,4, 12,5, 17,1, 8, 0 },
320 { 1, 17,5, 13,6, 18,2, 9, 1 },
321 { 3, 10,2, 18,6, 14,7, 19,3 },
322 { 0, 11,3, 19,7, 15,4, 16,0 }};
323 static int QuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
324 { 0, 11,3, 10,2, 9, 1, 8, 0 }, // all face normals are external
325 { 4, 12,5, 13,6, 14,7, 15,4 },
326 { 0, 8, 1, 17,5, 12,4, 16,0 },
327 { 1, 9, 2, 18,6, 13,5, 17,1 },
328 { 3, 19,7, 14,6, 18,2, 10,3 },
329 { 0, 16,4, 15,7, 19,3, 11,0 }};
330 static int QuadHexa_nbN [] = { 8, 8, 8, 8, 8, 8 };
332 static int TriQuadHexa_F [6][9] = { // FORWARD
333 { 0, 8, 1, 9, 2, 10,3, 11, 20 }, // all face normals are external
334 { 4, 15,7, 14,6, 13,5, 12, 25 },
335 { 0, 16,4, 12,5, 17,1, 8, 21 },
336 { 1, 17,5, 13,6, 18,2, 9, 22 },
337 { 3, 10,2, 18,6, 14,7, 19, 23 },
338 { 0, 11,3, 19,7, 15,4, 16, 24 }};
339 static int TriQuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
340 { 0, 11,3, 10,2, 9, 1, 8, 20 }, // opposite faces are neighbouring,
341 { 4, 12,5, 13,6, 14,7, 15, 25 }, // all face normals are external
342 { 0, 8, 1, 17,5, 12,4, 16, 21 },
343 { 1, 9, 2, 18,6, 13,5, 17, 22 },
344 { 3, 19,7, 14,6, 18,2, 10, 23 },
345 { 0, 16,4, 15,7, 19,3, 11, 24 }};
346 static int TriQuadHexa_nbN [] = { 9, 9, 9, 9, 9, 9 };
349 // ========================================================
350 // to perform some calculations without linkage to CASCADE
351 // ========================================================
358 XYZ() { x = 0; y = 0; z = 0; }
359 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
360 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
361 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
362 inline XYZ operator-( const XYZ& other );
363 inline XYZ operator+( const XYZ& other );
364 inline XYZ Crossed( const XYZ& other );
365 inline double Dot( const XYZ& other );
366 inline double Magnitude();
367 inline double SquareMagnitude();
369 inline XYZ XYZ::operator-( const XYZ& Right ) {
370 return XYZ(x - Right.x, y - Right.y, z - Right.z);
372 inline XYZ XYZ::operator+( const XYZ& Right ) {
373 return XYZ(x + Right.x, y + Right.y, z + Right.z);
375 inline XYZ XYZ::Crossed( const XYZ& Right ) {
376 return XYZ (y * Right.z - z * Right.y,
377 z * Right.x - x * Right.z,
378 x * Right.y - y * Right.x);
380 inline double XYZ::Dot( const XYZ& Other ) {
381 return(x * Other.x + y * Other.y + z * Other.z);
383 inline double XYZ::Magnitude() {
384 return sqrt (x * x + y * y + z * z);
386 inline double XYZ::SquareMagnitude() {
387 return (x * x + y * y + z * z);
390 //================================================================================
392 * \brief Return linear type corresponding to a quadratic one
394 //================================================================================
396 SMDS_VolumeTool::VolumeType quadToLinear(SMDS_VolumeTool::VolumeType quadType)
398 SMDS_VolumeTool::VolumeType linType = SMDS_VolumeTool::VolumeType( int(quadType)-4 );
399 const int nbCornersByQuad = SMDS_VolumeTool::NbCornerNodes( quadType );
400 if ( SMDS_VolumeTool::NbCornerNodes( linType ) == nbCornersByQuad )
404 for ( ; iLin < SMDS_VolumeTool::NB_VOLUME_TYPES; ++iLin )
405 if ( SMDS_VolumeTool::NbCornerNodes( SMDS_VolumeTool::VolumeType( iLin )) == nbCornersByQuad)
406 return SMDS_VolumeTool::VolumeType( iLin );
408 return SMDS_VolumeTool::UNKNOWN;
413 //=======================================================================
414 //function : SMDS_VolumeTool
416 //=======================================================================
418 SMDS_VolumeTool::SMDS_VolumeTool ()
419 : myVolumeNodes( NULL ),
425 //=======================================================================
426 //function : SMDS_VolumeTool
428 //=======================================================================
430 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume,
431 const bool ignoreCentralNodes)
432 : myVolumeNodes( NULL ),
435 Set( theVolume, ignoreCentralNodes );
438 //=======================================================================
439 //function : SMDS_VolumeTool
441 //=======================================================================
443 SMDS_VolumeTool::~SMDS_VolumeTool()
445 if ( myVolumeNodes != NULL ) delete [] myVolumeNodes;
446 if ( myFaceNodes != NULL ) delete [] myFaceNodes;
448 myFaceNodeIndices = NULL;
449 myVolumeNodes = myFaceNodes = NULL;
452 //=======================================================================
453 //function : SetVolume
454 //purpose : Set volume to iterate on
455 //=======================================================================
457 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume,
458 const bool ignoreCentralNodes)
463 myIgnoreCentralNodes = ignoreCentralNodes;
468 if (myVolumeNodes != NULL) {
469 delete [] myVolumeNodes;
470 myVolumeNodes = NULL;
472 myPolyIndices.clear();
474 myExternalFaces = false;
476 myAllFacesNodeIndices_F = 0;
477 //myAllFacesNodeIndices_FE = 0;
478 myAllFacesNodeIndices_RE = 0;
479 myAllFacesNbNodes = 0;
483 myFaceNodeIndices = NULL;
484 if (myFaceNodes != NULL) {
485 delete [] myFaceNodes;
490 if ( !theVolume || theVolume->GetType() != SMDSAbs_Volume )
493 myVolume = theVolume;
494 if (myVolume->IsPoly())
495 myPolyedre = dynamic_cast<const SMDS_VtkVolume*>( myVolume );
497 myNbFaces = theVolume->NbFaces();
498 myVolumeNbNodes = theVolume->NbNodes();
502 myVolumeNodes = new const SMDS_MeshNode* [myVolumeNbNodes];
503 SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator();
504 while ( nodeIt->more() )
505 myVolumeNodes[ iNode++ ] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
509 return ( myVolume = 0 );
513 // define volume orientation
515 GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
516 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
517 int topNodeIndex = myVolume->NbCornerNodes() - 1;
518 while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
519 const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
520 XYZ upDir (topNode->X() - botNode->X(),
521 topNode->Y() - botNode->Y(),
522 topNode->Z() - botNode->Z() );
523 myVolForward = ( botNormal.Dot( upDir ) < 0 );
526 myCurFace = -1; // previous setFace(0) didn't take myVolForward into account
531 //=======================================================================
533 //purpose : Inverse volume
534 //=======================================================================
536 #define SWAP_NODES(nodes,i1,i2) \
538 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
539 nodes[ i1 ] = nodes[ i2 ]; \
542 void SMDS_VolumeTool::Inverse ()
544 if ( !myVolume ) return;
546 if (myVolume->IsPoly()) {
547 MESSAGE("Warning: attempt to inverse polyhedral volume");
551 myVolForward = !myVolForward;
554 // inverse top and bottom faces
555 switch ( myVolumeNbNodes ) {
557 SWAP_NODES( myVolumeNodes, 1, 2 );
560 SWAP_NODES( myVolumeNodes, 1, 3 );
563 SWAP_NODES( myVolumeNodes, 1, 2 );
564 SWAP_NODES( myVolumeNodes, 4, 5 );
567 SWAP_NODES( myVolumeNodes, 1, 3 );
568 SWAP_NODES( myVolumeNodes, 5, 7 );
571 SWAP_NODES( myVolumeNodes, 1, 5 );
572 SWAP_NODES( myVolumeNodes, 2, 4 );
573 SWAP_NODES( myVolumeNodes, 7, 11 );
574 SWAP_NODES( myVolumeNodes, 8, 10 );
578 SWAP_NODES( myVolumeNodes, 1, 2 );
579 SWAP_NODES( myVolumeNodes, 4, 6 );
580 SWAP_NODES( myVolumeNodes, 8, 9 );
583 SWAP_NODES( myVolumeNodes, 1, 3 );
584 SWAP_NODES( myVolumeNodes, 5, 8 );
585 SWAP_NODES( myVolumeNodes, 6, 7 );
586 SWAP_NODES( myVolumeNodes, 10, 12 );
589 SWAP_NODES( myVolumeNodes, 1, 2 );
590 SWAP_NODES( myVolumeNodes, 4, 5 );
591 SWAP_NODES( myVolumeNodes, 6, 8 );
592 SWAP_NODES( myVolumeNodes, 9, 11 );
593 SWAP_NODES( myVolumeNodes, 13, 14 );
596 SWAP_NODES( myVolumeNodes, 1, 3 );
597 SWAP_NODES( myVolumeNodes, 5, 7 );
598 SWAP_NODES( myVolumeNodes, 8, 11 );
599 SWAP_NODES( myVolumeNodes, 9, 10 );
600 SWAP_NODES( myVolumeNodes, 12, 15 );
601 SWAP_NODES( myVolumeNodes, 13, 14 );
602 SWAP_NODES( myVolumeNodes, 17, 19 );
605 SWAP_NODES( myVolumeNodes, 1, 3 );
606 SWAP_NODES( myVolumeNodes, 5, 7 );
607 SWAP_NODES( myVolumeNodes, 8, 11 );
608 SWAP_NODES( myVolumeNodes, 9, 10 );
609 SWAP_NODES( myVolumeNodes, 12, 15 );
610 SWAP_NODES( myVolumeNodes, 13, 14 );
611 SWAP_NODES( myVolumeNodes, 17, 19 );
612 SWAP_NODES( myVolumeNodes, 21, 24 );
613 SWAP_NODES( myVolumeNodes, 22, 23 );
619 //=======================================================================
620 //function : GetVolumeType
622 //=======================================================================
624 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
629 switch( myVolumeNbNodes ) {
630 case 4: return TETRA;
631 case 5: return PYRAM;
632 case 6: return PENTA;
634 case 12: return HEX_PRISM;
635 case 10: return QUAD_TETRA;
636 case 13: return QUAD_PYRAM;
637 case 15: return QUAD_PENTA;
638 case 20: return QUAD_HEXA;
639 case 27: return QUAD_HEXA;
646 //=======================================================================
647 //function : getTetraVolume
649 //=======================================================================
651 static double getTetraVolume(const SMDS_MeshNode* n1,
652 const SMDS_MeshNode* n2,
653 const SMDS_MeshNode* n3,
654 const SMDS_MeshNode* n4)
672 double Q1 = -(X1-X2)*(Y3*Z4-Y4*Z3);
673 double Q2 = (X1-X3)*(Y2*Z4-Y4*Z2);
674 double R1 = -(X1-X4)*(Y2*Z3-Y3*Z2);
675 double R2 = -(X2-X3)*(Y1*Z4-Y4*Z1);
676 double S1 = (X2-X4)*(Y1*Z3-Y3*Z1);
677 double S2 = -(X3-X4)*(Y1*Z2-Y2*Z1);
679 return (Q1+Q2+R1+R2+S1+S2)/6.0;
682 //=======================================================================
684 //purpose : Return element volume
685 //=======================================================================
687 double SMDS_VolumeTool::GetSize() const
693 if ( myVolume->IsPoly() )
698 // split a polyhedron into tetrahedrons
700 int saveCurFace = myCurFace;
701 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
702 for ( int f = 0; f < NbFaces(); ++f )
705 XYZ area (0,0,0), p1( myFaceNodes[0] );
706 for ( int n = 0; n < myFaceNbNodes; ++n )
708 XYZ p2( myFaceNodes[ n+1 ]);
709 area = area + p1.Crossed( p2 );
715 if ( saveCurFace > -1 && saveCurFace != myCurFace )
716 me->setFace( myCurFace );
720 const static int ind[] = {
721 0, 1, 3, 6, 11, 23, 31, 44, 58, 78 };
722 const static int vtab[][4] = { // decomposition into tetra in the order of enum VolumeType
755 // quadratic tetrahedron
780 // quadratic pentahedron
797 // quadratic hexahedron
822 int type = GetVolumeType();
824 int n2 = ind[type+1];
826 for (int i = n1; i < n2; i++) {
827 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
828 myVolumeNodes[ vtab[i][1] ],
829 myVolumeNodes[ vtab[i][2] ],
830 myVolumeNodes[ vtab[i][3] ]);
836 //=======================================================================
837 //function : GetBaryCenter
839 //=======================================================================
841 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
847 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
848 X += myVolumeNodes[ i ]->X();
849 Y += myVolumeNodes[ i ]->Y();
850 Z += myVolumeNodes[ i ]->Z();
852 X /= myVolumeNbNodes;
853 Y /= myVolumeNbNodes;
854 Z /= myVolumeNbNodes;
859 //================================================================================
861 * \brief Classify a point
862 * \param tol - thickness of faces
864 //================================================================================
866 bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol) const
868 // LIMITATION: for convex volumes only
870 for ( int iF = 0; iF < myNbFaces; ++iF )
873 if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
875 if ( !IsFaceExternal( iF ))
876 faceNormal = XYZ() - faceNormal; // reverse
878 XYZ face2p( p - XYZ( myFaceNodes[0] ));
879 if ( face2p.Dot( faceNormal ) > tol )
885 //=======================================================================
886 //function : SetExternalNormal
887 //purpose : Node order will be so that faces normals are external
888 //=======================================================================
890 void SMDS_VolumeTool::SetExternalNormal ()
892 myExternalFaces = true;
896 //=======================================================================
897 //function : NbFaceNodes
898 //purpose : Return number of nodes in the array of face nodes
899 //=======================================================================
901 int SMDS_VolumeTool::NbFaceNodes( int faceIndex ) const
903 if ( !setFace( faceIndex ))
905 return myFaceNbNodes;
908 //=======================================================================
909 //function : GetFaceNodes
910 //purpose : Return pointer to the array of face nodes.
911 // To comfort link iteration, the array
912 // length == NbFaceNodes( faceIndex ) + 1 and
913 // the last node == the first one.
914 //=======================================================================
916 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex ) const
918 if ( !setFace( faceIndex ))
923 //=======================================================================
924 //function : GetFaceNodesIndices
925 //purpose : Return pointer to the array of face nodes indices
926 // To comfort link iteration, the array
927 // length == NbFaceNodes( faceIndex ) + 1 and
928 // the last node index == the first one.
929 //=======================================================================
931 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) const
933 if ( !setFace( faceIndex ))
938 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
939 me->myPolyIndices.resize( myFaceNbNodes + 1 );
940 me->myFaceNodeIndices = & me->myPolyIndices[0];
941 for ( int i = 0; i <= myFaceNbNodes; ++i )
942 me->myFaceNodeIndices[i] = myVolume->GetNodeIndex( myFaceNodes[i] );
944 return myFaceNodeIndices;
947 //=======================================================================
948 //function : GetFaceNodes
949 //purpose : Return a set of face nodes.
950 //=======================================================================
952 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
953 set<const SMDS_MeshNode*>& theFaceNodes ) const
955 if ( !setFace( faceIndex ))
958 theFaceNodes.clear();
959 theFaceNodes.insert( myFaceNodes, myFaceNodes + myFaceNbNodes );
964 //=======================================================================
965 //function : IsFaceExternal
966 //purpose : Check normal orientation of a given face
967 //=======================================================================
969 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const
971 if ( myExternalFaces || !myVolume )
974 if (myVolume->IsPoly()) {
975 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
976 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
977 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
978 XYZ insideVec (baryCenter - p0);
979 if (insideVec.Dot(aNormal) > 0)
984 // switch ( myVolumeNbNodes ) {
989 // // only the bottom of a reversed tetrahedron can be internal
990 // return ( myVolForward || faceIndex != 0 );
994 // // in a forward prism, the top is internal, in a reversed one - bottom
995 // return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
999 // // in a forward hexahedron, even face normal is external, odd - internal
1000 // bool odd = faceIndex % 2;
1001 // return ( myVolForward ? !odd : odd );
1009 //=======================================================================
1010 //function : GetFaceNormal
1011 //purpose : Return a normal to a face
1012 //=======================================================================
1014 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const
1016 if ( !setFace( faceIndex ))
1019 const int iQuad = ( myFaceNbNodes > 6 && !myPolyedre ) ? 2 : 1;
1020 XYZ p1 ( myFaceNodes[0*iQuad] );
1021 XYZ p2 ( myFaceNodes[1*iQuad] );
1022 XYZ p3 ( myFaceNodes[2*iQuad] );
1023 XYZ aVec12( p2 - p1 );
1024 XYZ aVec13( p3 - p1 );
1025 XYZ cross = aVec12.Crossed( aVec13 );
1027 if ( myFaceNbNodes >3*iQuad ) {
1028 XYZ p4 ( myFaceNodes[3*iQuad] );
1029 XYZ aVec14( p4 - p1 );
1030 XYZ cross2 = aVec13.Crossed( aVec14 );
1031 cross = cross + cross2;
1034 double size = cross.Magnitude();
1035 if ( size <= numeric_limits<double>::min() )
1045 //================================================================================
1047 * \brief Return barycenter of a face
1049 //================================================================================
1051 bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const
1053 if ( !setFace( faceIndex ))
1057 for ( int i = 0; i < myFaceNbNodes; ++i )
1059 X += myFaceNodes[i]->X() / myFaceNbNodes;
1060 Y += myFaceNodes[i]->Y() / myFaceNbNodes;
1061 Z += myFaceNodes[i]->Z() / myFaceNbNodes;
1066 //=======================================================================
1067 //function : GetFaceArea
1068 //purpose : Return face area
1069 //=======================================================================
1071 double SMDS_VolumeTool::GetFaceArea( int faceIndex ) const
1073 if (myVolume->IsPoly()) {
1074 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
1078 if ( !setFace( faceIndex ))
1081 XYZ p1 ( myFaceNodes[0] );
1082 XYZ p2 ( myFaceNodes[1] );
1083 XYZ p3 ( myFaceNodes[2] );
1084 XYZ aVec12( p2 - p1 );
1085 XYZ aVec13( p3 - p1 );
1086 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
1088 if ( myFaceNbNodes == 4 ) {
1089 XYZ p4 ( myFaceNodes[3] );
1090 XYZ aVec14( p4 - p1 );
1091 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
1096 //================================================================================
1098 * \brief Return index of the node located at face center of a quadratic element like HEX27
1100 //================================================================================
1102 int SMDS_VolumeTool::GetCenterNodeIndex( int faceIndex ) const
1104 if ( myAllFacesNbNodes && myVolumeNbNodes == 27 ) // classic element with 27 nodes
1106 switch ( faceIndex ) {
1110 return faceIndex + 19;
1116 //=======================================================================
1117 //function : GetOppFaceIndex
1118 //purpose : Return index of the opposite face if it exists, else -1.
1119 //=======================================================================
1121 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
1125 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
1129 const int nbHoriFaces = 2;
1131 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
1132 switch ( myVolumeNbNodes ) {
1135 if ( faceIndex == 0 || faceIndex == 1 )
1136 ind = 1 - faceIndex;
1140 if ( faceIndex <= 1 ) // top or bottom
1141 ind = 1 - faceIndex;
1143 const int nbSideFaces = myAllFacesNbNodes[0];
1144 ind = ( faceIndex - nbHoriFaces + nbSideFaces/2 ) % nbSideFaces + nbHoriFaces;
1149 ind = GetOppFaceIndexOfHex( faceIndex );
1157 //=======================================================================
1158 //function : GetOppFaceIndexOfHex
1159 //purpose : Return index of the opposite face of the hexahedron
1160 //=======================================================================
1162 int SMDS_VolumeTool::GetOppFaceIndexOfHex( int faceIndex )
1164 return Hexa_oppF[ faceIndex ];
1167 //=======================================================================
1168 //function : IsLinked
1169 //purpose : return true if theNode1 is linked with theNode2
1170 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1171 //=======================================================================
1173 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
1174 const SMDS_MeshNode* theNode2,
1175 const bool theIgnoreMediumNodes) const
1180 if (myVolume->IsPoly()) {
1182 MESSAGE("Warning: bad volumic element");
1185 bool isLinked = false;
1187 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
1188 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
1190 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
1191 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
1193 if (curNode == theNode1 || curNode == theNode2) {
1194 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
1195 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
1197 if ((curNode == theNode1 && nextNode == theNode2) ||
1198 (curNode == theNode2 && nextNode == theNode1)) {
1207 // find nodes indices
1208 int i1 = -1, i2 = -1, nbFound = 0;
1209 for ( int i = 0; i < myVolumeNbNodes && nbFound < 2; i++ )
1211 if ( myVolumeNodes[ i ] == theNode1 )
1213 else if ( myVolumeNodes[ i ] == theNode2 )
1216 return IsLinked( i1, i2 );
1219 //=======================================================================
1220 //function : IsLinked
1221 //purpose : return true if the node with theNode1Index is linked
1222 // with the node with theNode2Index
1223 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1224 //=======================================================================
1226 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
1227 const int theNode2Index,
1228 bool theIgnoreMediumNodes) const
1230 if ( myVolume->IsPoly() ) {
1231 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
1234 int minInd = min( theNode1Index, theNode2Index );
1235 int maxInd = max( theNode1Index, theNode2Index );
1237 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
1240 VolumeType type = GetVolumeType();
1241 if ( myVolume->IsQuadratic() )
1243 int firstMediumInd = myVolume->NbCornerNodes();
1244 if ( minInd >= firstMediumInd )
1245 return false; // both nodes are medium - not linked
1246 if ( maxInd < firstMediumInd ) // both nodes are corners
1248 if ( theIgnoreMediumNodes )
1249 type = quadToLinear(type); // to check linkage of corner nodes only
1251 return false; // corner nodes are not linked directly in a quadratic cell
1259 switch ( maxInd - minInd ) {
1260 case 1: return minInd != 3;
1261 case 3: return minInd == 0 || minInd == 4;
1262 case 4: return true;
1269 switch ( maxInd - minInd ) {
1271 case 3: return true;
1276 switch ( maxInd - minInd ) {
1277 case 1: return minInd != 2;
1278 case 2: return minInd == 0 || minInd == 3;
1279 case 3: return true;
1286 case 0: if( maxInd==4 || maxInd==6 || maxInd==7 ) return true;
1287 case 1: if( maxInd==4 || maxInd==5 || maxInd==8 ) return true;
1288 case 2: if( maxInd==5 || maxInd==6 || maxInd==9 ) return true;
1289 case 3: if( maxInd==7 || maxInd==8 || maxInd==9 ) return true;
1297 case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
1298 case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
1299 case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
1300 case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
1301 case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
1302 case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
1303 case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
1304 case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
1312 case 0: if( maxInd==5 || maxInd==8 || maxInd==9 ) return true;
1313 case 1: if( maxInd==5 || maxInd==6 || maxInd==10 ) return true;
1314 case 2: if( maxInd==6 || maxInd==7 || maxInd==11 ) return true;
1315 case 3: if( maxInd==7 || maxInd==8 || maxInd==12 ) return true;
1316 case 4: if( maxInd==9 || maxInd==10 || maxInd==11 || maxInd==12 ) return true;
1324 case 0: if( maxInd==6 || maxInd==8 || maxInd==12 ) return true;
1325 case 1: if( maxInd==6 || maxInd==7 || maxInd==13 ) return true;
1326 case 2: if( maxInd==7 || maxInd==8 || maxInd==14 ) return true;
1327 case 3: if( maxInd==9 || maxInd==11 || maxInd==12 ) return true;
1328 case 4: if( maxInd==9 || maxInd==10 || maxInd==13 ) return true;
1329 case 5: if( maxInd==10 || maxInd==11 || maxInd==14 ) return true;
1336 const int diff = maxInd-minInd;
1337 if ( diff > 6 ) return false;// not linked top and bottom
1338 if ( diff == 6 ) return true; // linked top and bottom
1339 return diff == 1 || diff == 7;
1346 //=======================================================================
1347 //function : GetNodeIndex
1348 //purpose : Return an index of theNode
1349 //=======================================================================
1351 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
1354 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1355 if ( myVolumeNodes[ i ] == theNode )
1362 //================================================================================
1364 * \brief Fill vector with boundary faces existing in the mesh
1365 * \param faces - vector of found nodes
1366 * \retval int - nb of found faces
1368 //================================================================================
1370 int SMDS_VolumeTool::GetAllExistingFaces(vector<const SMDS_MeshElement*> & faces) const
1373 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1374 const SMDS_MeshFace* face = 0;
1375 const SMDS_MeshNode** nodes = GetFaceNodes( iF );
1376 switch ( NbFaceNodes( iF )) {
1378 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
1380 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
1382 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
1383 nodes[3], nodes[4], nodes[5]); break;
1385 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
1386 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1389 faces.push_back( face );
1391 return faces.size();
1395 //================================================================================
1397 * \brief Fill vector with boundary edges existing in the mesh
1398 * \param edges - vector of found edges
1399 * \retval int - nb of found faces
1401 //================================================================================
1403 int SMDS_VolumeTool::GetAllExistingEdges(vector<const SMDS_MeshElement*> & edges) const
1406 edges.reserve( myVolumeNbNodes * 2 );
1407 for ( int i = 0; i < myVolumeNbNodes-1; ++i ) {
1408 for ( int j = i + 1; j < myVolumeNbNodes; ++j ) {
1409 if ( IsLinked( i, j )) {
1410 const SMDS_MeshElement* edge =
1411 SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
1413 edges.push_back( edge );
1417 return edges.size();
1420 //================================================================================
1422 * \brief Return minimal square distance between connected corner nodes
1424 //================================================================================
1426 double SMDS_VolumeTool::MinLinearSize2() const
1428 double minSize = 1e+100;
1429 int iQ = myVolume->IsQuadratic() ? 2 : 1;
1431 // store current face data
1432 int curFace = myCurFace, nbN = myFaceNbNodes;
1433 int* ind = myFaceNodeIndices;
1434 myFaceNodeIndices = NULL;
1435 const SMDS_MeshNode** nodes = myFaceNodes;
1438 // it seems that compute distance twice is faster than organization of a sole computing
1440 for ( int iF = 0; iF < myNbFaces; ++iF )
1443 for ( int iN = 0; iN < myFaceNbNodes; iN += iQ )
1445 XYZ n1( myFaceNodes[ iN ]);
1446 XYZ n2( myFaceNodes[(iN + iQ) % myFaceNbNodes]);
1447 minSize = std::min( minSize, (n1 - n2).SquareMagnitude());
1450 // restore current face data
1451 myCurFace = curFace;
1452 myFaceNbNodes = nbN;
1453 myFaceNodeIndices = ind;
1454 delete [] myFaceNodes; myFaceNodes = nodes;
1459 //================================================================================
1461 * \brief Return maximal square distance between connected corner nodes
1463 //================================================================================
1465 double SMDS_VolumeTool::MaxLinearSize2() const
1467 double maxSize = -1e+100;
1468 int iQ = myVolume->IsQuadratic() ? 2 : 1;
1470 // store current face data
1471 int curFace = myCurFace, nbN = myFaceNbNodes;
1472 int* ind = myFaceNodeIndices;
1473 myFaceNodeIndices = NULL;
1474 const SMDS_MeshNode** nodes = myFaceNodes;
1477 // it seems that compute distance twice is faster than organization of a sole computing
1479 for ( int iF = 0; iF < myNbFaces; ++iF )
1482 for ( int iN = 0; iN < myFaceNbNodes; iN += iQ )
1484 XYZ n1( myFaceNodes[ iN ]);
1485 XYZ n2( myFaceNodes[(iN + iQ) % myFaceNbNodes]);
1486 maxSize = std::max( maxSize, (n1 - n2).SquareMagnitude());
1489 // restore current face data
1490 myCurFace = curFace;
1491 myFaceNbNodes = nbN;
1492 myFaceNodeIndices = ind;
1493 delete [] myFaceNodes; myFaceNodes = nodes;
1498 //================================================================================
1500 * \brief fast check that only one volume is build on the face nodes
1502 //================================================================================
1504 bool SMDS_VolumeTool::IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
1506 const bool isFree = true;
1508 if (!setFace( faceIndex ))
1511 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
1513 // a set of facet nodes w/o medium ones and w/o nodes[0]
1514 set< const SMDS_MeshElement* > nodeSet;
1515 const int di = myVolume->IsQuadratic() ? 2 : 1;
1516 for ( int i = di; i < myFaceNbNodes; i += di )
1517 nodeSet.insert( nodes[i] );
1519 SMDS_ElemIteratorPtr eIt = nodes[0]->GetInverseElementIterator( SMDSAbs_Volume );
1520 SMDS_ElemIteratorPtr nIt;
1521 while ( eIt->more() ) {
1522 const SMDS_MeshElement* vol = eIt->next();
1523 if ( vol != myVolume ) {
1524 size_t nbShared = 0;
1525 if ( const SMDS_VtkVolume* v = dynamic_cast< const SMDS_VtkVolume* >( vol ))
1526 nIt = v->uniqueNodesIterator();
1528 nIt = vol->nodesIterator();
1529 while ( nIt->more() )
1530 if (( nbShared += nodeSet.count( nIt->next() )) == nodeSet.size() )
1532 if ( otherVol ) *otherVol = vol;
1537 if ( otherVol ) *otherVol = 0;
1541 //================================================================================
1543 * \brief Thorough check that only one volume is build on the face nodes
1545 //================================================================================
1547 bool SMDS_VolumeTool::IsFreeFaceAdv( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
1549 const bool isFree = true;
1551 if (!setFace( faceIndex ))
1554 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
1555 const int nbFaceNodes = myFaceNbNodes;
1557 // evaluate nb of face nodes shared by other volumes
1558 int maxNbShared = -1;
1559 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
1560 TElemIntMap volNbShared;
1561 TElemIntMap::iterator vNbIt;
1562 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1563 const SMDS_MeshNode* n = nodes[ iNode ];
1564 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1565 while ( eIt->more() ) {
1566 const SMDS_MeshElement* elem = eIt->next();
1567 if ( elem != myVolume ) {
1568 vNbIt = volNbShared.insert( make_pair( elem, 0 )).first;
1570 if ( vNbIt->second > maxNbShared )
1571 maxNbShared = vNbIt->second;
1575 if ( maxNbShared < 3 )
1576 return isFree; // is free
1578 // find volumes laying on the opposite side of the face
1579 // and sharing all nodes
1580 XYZ intNormal; // internal normal
1581 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
1582 if ( IsFaceExternal( faceIndex ))
1583 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
1584 XYZ p0 ( nodes[0] ), baryCenter;
1585 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); ) {
1586 const int& nbShared = (*vNbIt).second;
1587 if ( nbShared >= 3 ) {
1588 SMDS_VolumeTool volume( (*vNbIt).first );
1589 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
1590 XYZ intNormal2( baryCenter - p0 );
1591 if ( intNormal.Dot( intNormal2 ) < 0 ) {
1593 if ( nbShared >= nbFaceNodes )
1595 // a volume shares the whole facet
1596 if ( otherVol ) *otherVol = vNbIt->first;
1603 // remove a volume from volNbShared map
1604 volNbShared.erase( vNbIt++ );
1607 // here volNbShared contains only volumes laying on the opposite side of
1608 // the face and sharing 3 or more but not all face nodes with myVolume
1609 if ( volNbShared.size() < 2 ) {
1610 return isFree; // is free
1613 // check if the whole area of a face is shared
1614 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1616 const SMDS_MeshNode* n = nodes[ iNode ];
1617 // check if n is shared by one of volumes of volNbShared
1618 bool isShared = false;
1619 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1620 while ( eIt->more() && !isShared )
1621 isShared = volNbShared.count( eIt->next() );
1625 if ( otherVol ) *otherVol = volNbShared.begin()->first;
1628 // if ( !myVolume->IsPoly() )
1630 // bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
1631 // for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
1632 // SMDS_VolumeTool volume( (*vNbIt).first );
1633 // bool prevLinkShared = false;
1634 // int nbSharedLinks = 0;
1635 // for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1636 // bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
1637 // if ( linkShared )
1639 // if ( linkShared && prevLinkShared &&
1640 // volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
1641 // isShared[ iNode ] = true;
1642 // prevLinkShared = linkShared;
1644 // if ( nbSharedLinks == nbFaceNodes )
1645 // return !free; // is not free
1646 // if ( nbFaceNodes == 4 ) {
1647 // // check traingle parts 1 & 3
1648 // if ( isShared[1] && isShared[3] )
1649 // return !free; // is not free
1650 // // check triangle parts 0 & 2;
1651 // // 0 part could not be checked in the loop; check it here
1652 // if ( isShared[2] && prevLinkShared &&
1653 // volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
1654 // volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
1655 // return !free; // is not free
1662 //=======================================================================
1663 //function : GetFaceIndex
1664 //purpose : Return index of a face formed by theFaceNodes
1665 //=======================================================================
1667 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes,
1668 const int theFaceIndexHint ) const
1670 if ( theFaceIndexHint >= 0 )
1672 int nbNodes = NbFaceNodes( theFaceIndexHint );
1673 if ( nbNodes == (int) theFaceNodes.size() )
1675 const SMDS_MeshNode** nodes = GetFaceNodes( theFaceIndexHint );
1677 if ( theFaceNodes.count( nodes[ nbNodes-1 ]))
1682 return theFaceIndexHint;
1685 for ( int iFace = 0; iFace < myNbFaces; iFace++ )
1687 if ( iFace == theFaceIndexHint )
1689 int nbNodes = NbFaceNodes( iFace );
1690 if ( nbNodes == (int) theFaceNodes.size() )
1692 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
1694 if ( theFaceNodes.count( nodes[ nbNodes-1 ]))
1705 //=======================================================================
1706 //function : GetFaceIndex
1707 //purpose : Return index of a face formed by theFaceNodes
1708 //=======================================================================
1710 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
1712 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1713 const int* nodes = GetFaceNodesIndices( iFace );
1714 int nbFaceNodes = NbFaceNodes( iFace );
1716 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1717 nodeSet.insert( nodes[ iNode ] );
1718 if ( theFaceNodesIndices == nodeSet )
1724 //=======================================================================
1725 //function : setFace
1727 //=======================================================================
1729 bool SMDS_VolumeTool::setFace( int faceIndex ) const
1734 if ( myCurFace == faceIndex )
1739 if ( faceIndex < 0 || faceIndex >= NbFaces() )
1742 if (myFaceNodes != NULL) {
1743 delete [] myFaceNodes;
1747 if (myVolume->IsPoly())
1750 MESSAGE("Warning: bad volumic element");
1756 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
1757 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1758 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1759 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
1760 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
1762 // check orientation
1763 if (myExternalFaces)
1765 myCurFace = faceIndex; // avoid infinite recursion in IsFaceExternal()
1766 myExternalFaces = false; // force normal computation by IsFaceExternal()
1767 if ( !IsFaceExternal( faceIndex ))
1768 for ( int i = 0, j = myFaceNbNodes; i < j; ++i, --j )
1769 std::swap( myFaceNodes[i], myFaceNodes[j] );
1770 myExternalFaces = true;
1775 if ( !myAllFacesNodeIndices_F )
1777 // choose data for an element type
1778 switch ( myVolumeNbNodes ) {
1780 myAllFacesNodeIndices_F = &Tetra_F [0][0];
1781 //myAllFacesNodeIndices_FE = &Tetra_F [0][0];
1782 myAllFacesNodeIndices_RE = &Tetra_RE[0][0];
1783 myAllFacesNbNodes = Tetra_nbN;
1784 myMaxFaceNbNodes = sizeof(Tetra_F[0])/sizeof(Tetra_F[0][0]);
1787 myAllFacesNodeIndices_F = &Pyramid_F [0][0];
1788 //myAllFacesNodeIndices_FE = &Pyramid_F [0][0];
1789 myAllFacesNodeIndices_RE = &Pyramid_RE[0][0];
1790 myAllFacesNbNodes = Pyramid_nbN;
1791 myMaxFaceNbNodes = sizeof(Pyramid_F[0])/sizeof(Pyramid_F[0][0]);
1794 myAllFacesNodeIndices_F = &Penta_F [0][0];
1795 //myAllFacesNodeIndices_FE = &Penta_FE[0][0];
1796 myAllFacesNodeIndices_RE = &Penta_RE[0][0];
1797 myAllFacesNbNodes = Penta_nbN;
1798 myMaxFaceNbNodes = sizeof(Penta_F[0])/sizeof(Penta_F[0][0]);
1801 myAllFacesNodeIndices_F = &Hexa_F [0][0];
1802 ///myAllFacesNodeIndices_FE = &Hexa_FE[0][0];
1803 myAllFacesNodeIndices_RE = &Hexa_RE[0][0];
1804 myAllFacesNbNodes = Hexa_nbN;
1805 myMaxFaceNbNodes = sizeof(Hexa_F[0])/sizeof(Hexa_F[0][0]);
1808 myAllFacesNodeIndices_F = &QuadTetra_F [0][0];
1809 //myAllFacesNodeIndices_FE = &QuadTetra_F [0][0];
1810 myAllFacesNodeIndices_RE = &QuadTetra_RE[0][0];
1811 myAllFacesNbNodes = QuadTetra_nbN;
1812 myMaxFaceNbNodes = sizeof(QuadTetra_F[0])/sizeof(QuadTetra_F[0][0]);
1815 myAllFacesNodeIndices_F = &QuadPyram_F [0][0];
1816 //myAllFacesNodeIndices_FE = &QuadPyram_F [0][0];
1817 myAllFacesNodeIndices_RE = &QuadPyram_RE[0][0];
1818 myAllFacesNbNodes = QuadPyram_nbN;
1819 myMaxFaceNbNodes = sizeof(QuadPyram_F[0])/sizeof(QuadPyram_F[0][0]);
1822 myAllFacesNodeIndices_F = &QuadPenta_F [0][0];
1823 //myAllFacesNodeIndices_FE = &QuadPenta_FE[0][0];
1824 myAllFacesNodeIndices_RE = &QuadPenta_RE[0][0];
1825 myAllFacesNbNodes = QuadPenta_nbN;
1826 myMaxFaceNbNodes = sizeof(QuadPenta_F[0])/sizeof(QuadPenta_F[0][0]);
1830 myAllFacesNodeIndices_F = &QuadHexa_F [0][0];
1831 //myAllFacesNodeIndices_FE = &QuadHexa_FE[0][0];
1832 myAllFacesNodeIndices_RE = &QuadHexa_RE[0][0];
1833 myAllFacesNbNodes = QuadHexa_nbN;
1834 myMaxFaceNbNodes = sizeof(QuadHexa_F[0])/sizeof(QuadHexa_F[0][0]);
1835 if ( !myIgnoreCentralNodes && myVolumeNbNodes == 27 )
1837 myAllFacesNodeIndices_F = &TriQuadHexa_F [0][0];
1838 //myAllFacesNodeIndices_FE = &TriQuadHexa_FE[0][0];
1839 myAllFacesNodeIndices_RE = &TriQuadHexa_RE[0][0];
1840 myAllFacesNbNodes = TriQuadHexa_nbN;
1841 myMaxFaceNbNodes = sizeof(TriQuadHexa_F[0])/sizeof(TriQuadHexa_F[0][0]);
1845 myAllFacesNodeIndices_F = &HexPrism_F [0][0];
1846 //myAllFacesNodeIndices_FE = &HexPrism_FE[0][0];
1847 myAllFacesNodeIndices_RE = &HexPrism_RE[0][0];
1848 myAllFacesNbNodes = HexPrism_nbN;
1849 myMaxFaceNbNodes = sizeof(HexPrism_F[0])/sizeof(HexPrism_F[0][0]);
1855 myFaceNbNodes = myAllFacesNbNodes[ faceIndex ];
1856 // if ( myExternalFaces )
1857 // myFaceNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_FE + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
1859 // myFaceNodeIndices = (int*)( myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes );
1860 myFaceNodeIndices = (int*)( myVolForward ? myAllFacesNodeIndices_F + faceIndex*myMaxFaceNbNodes : myAllFacesNodeIndices_RE + faceIndex*myMaxFaceNbNodes );
1863 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1864 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
1865 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
1866 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
1869 myCurFace = faceIndex;
1874 //=======================================================================
1875 //function : GetType
1876 //purpose : return VolumeType by nb of nodes in a volume
1877 //=======================================================================
1879 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
1881 switch ( nbNodes ) {
1882 case 4: return TETRA;
1883 case 5: return PYRAM;
1884 case 6: return PENTA;
1885 case 8: return HEXA;
1886 case 10: return QUAD_TETRA;
1887 case 13: return QUAD_PYRAM;
1888 case 15: return QUAD_PENTA;
1890 case 27: return QUAD_HEXA;
1891 case 12: return HEX_PRISM;
1892 default:return UNKNOWN;
1896 //=======================================================================
1897 //function : NbFaces
1898 //purpose : return nb of faces by volume type
1899 //=======================================================================
1901 int SMDS_VolumeTool::NbFaces( VolumeType type )
1905 case QUAD_TETRA: return 4;
1907 case QUAD_PYRAM: return 5;
1909 case QUAD_PENTA: return 5;
1911 case QUAD_HEXA : return 6;
1912 case HEX_PRISM : return 8;
1917 //================================================================================
1919 * \brief Useful to know nb of corner nodes of a quadratic volume
1920 * \param type - volume type
1921 * \retval int - nb of corner nodes
1923 //================================================================================
1925 int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
1929 case QUAD_TETRA: return 4;
1931 case QUAD_PYRAM: return 5;
1933 case QUAD_PENTA: return 6;
1935 case QUAD_HEXA : return 8;
1936 case HEX_PRISM : return 12;
1943 //=======================================================================
1944 //function : GetFaceNodesIndices
1945 //purpose : Return the array of face nodes indices
1946 // To comfort link iteration, the array
1947 // length == NbFaceNodes( faceIndex ) + 1 and
1948 // the last node index == the first one.
1949 //=======================================================================
1951 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1956 case TETRA: return Tetra_F[ faceIndex ];
1957 case PYRAM: return Pyramid_F[ faceIndex ];
1958 case PENTA: return external ? Penta_F[ faceIndex ] : Penta_F[ faceIndex ];
1959 case HEXA: return external ? Hexa_F[ faceIndex ] : Hexa_F[ faceIndex ];
1960 case QUAD_TETRA: return QuadTetra_F[ faceIndex ];
1961 case QUAD_PYRAM: return QuadPyram_F[ faceIndex ];
1962 case QUAD_PENTA: return external ? QuadPenta_F[ faceIndex ] : QuadPenta_F[ faceIndex ];
1963 // what about SMDSEntity_TriQuad_Hexa?
1964 case QUAD_HEXA: return external ? QuadHexa_F[ faceIndex ] : QuadHexa_F[ faceIndex ];
1965 case HEX_PRISM: return external ? HexPrism_F[ faceIndex ] : HexPrism_F[ faceIndex ];
1971 //=======================================================================
1972 //function : NbFaceNodes
1973 //purpose : Return number of nodes in the array of face nodes
1974 //=======================================================================
1976 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1980 case TETRA: return Tetra_nbN[ faceIndex ];
1981 case PYRAM: return Pyramid_nbN[ faceIndex ];
1982 case PENTA: return Penta_nbN[ faceIndex ];
1983 case HEXA: return Hexa_nbN[ faceIndex ];
1984 case QUAD_TETRA: return QuadTetra_nbN[ faceIndex ];
1985 case QUAD_PYRAM: return QuadPyram_nbN[ faceIndex ];
1986 case QUAD_PENTA: return QuadPenta_nbN[ faceIndex ];
1987 // what about SMDSEntity_TriQuad_Hexa?
1988 case QUAD_HEXA: return QuadHexa_nbN[ faceIndex ];
1989 case HEX_PRISM: return HexPrism_nbN[ faceIndex ];
1995 //=======================================================================
1996 //function : Element
1997 //purpose : return element
1998 //=======================================================================
2000 const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
2002 return static_cast<const SMDS_MeshVolume*>( myVolume );
2005 //=======================================================================
2007 //purpose : return element ID
2008 //=======================================================================
2010 int SMDS_VolumeTool::ID() const
2012 return myVolume ? myVolume->GetID() : 0;