1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMDS_VolumeTool.cxx
24 // Created : Tue Jul 13 12:22:13 2004
25 // Author : Edward AGAPOV (eap)
28 #pragma warning(disable:4786)
31 #include "SMDS_VolumeTool.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_VtkVolume.hxx"
36 #include "SMDS_Mesh.hxx"
38 #include "utilities.h"
46 // ======================================================
47 // Node indices in faces depending on volume orientation
48 // making most faces normals external
49 // ======================================================
57 // N0 +---|---+ N1 TETRAHEDRON
65 static int Tetra_F [4][4] = { // FORWARD == EXTERNAL
66 { 0, 1, 2, 0 }, // All faces have external normals
70 static int Tetra_R [4][4] = { // REVERSED
71 { 0, 1, 2, 0 }, // All faces but a bottom have external normals
75 static int Tetra_RE [4][4] = { // REVERSED -> FORWARD (EXTERNAL)
76 { 0, 2, 1, 0 }, // All faces have external normals
80 static int Tetra_nbN [] = { 3, 3, 3, 3 };
85 static int Pyramid_F [5][5] = { // FORWARD == EXTERNAL
86 { 0, 1, 2, 3, 0 }, // All faces have external normals
91 static int Pyramid_R [5][5] = { // REVERSED
92 { 0, 1, 2, 3, 0 }, // All faces but a bottom have external normals
97 static int Pyramid_RE [5][5] = { // REVERSED -> FORWARD (EXTERNAL)
98 { 0, 3, 2, 1, 0 }, // All faces but a bottom have external normals
103 static int Pyramid_nbN [] = { 4, 3, 3, 3, 3 };
114 // | / \ | PENTAHEDRON
120 static int Penta_F [5][5] = { // FORWARD
121 { 0, 1, 2, 0, 0 }, // Top face has an internal normal, other - external
122 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
126 static int Penta_R [5][5] = { // REVERSED
127 { 0, 1, 2, 0, 0 }, // Bottom face has an internal normal, other - external
128 { 3, 4, 5, 3, 3 }, // 0 is bottom, 1 is top face
132 static int Penta_FE [5][5] = { // FORWARD -> EXTERNAL
138 static int Penta_RE [5][5] = { // REVERSED -> EXTERNAL
144 static int Penta_nbN [] = { 3, 3, 4, 4, 4 };
151 // N4+----------+N7 |
152 // | | | | HEXAHEDRON
155 // | N1+------|---+N2
161 static int Hexa_F [6][5] = { // FORWARD
162 { 0, 1, 2, 3, 0 }, // opposite faces are neighbouring,
163 { 4, 5, 6, 7, 4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external
164 { 1, 0, 4, 5, 1 }, // same index nodes of opposite faces are linked
168 // static int Hexa_R [6][5] = { // REVERSED
169 // { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
170 // { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal
171 // { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked
172 // { 2, 6, 7, 3, 2 },
173 // { 0, 4, 7, 3, 0 },
174 // { 1, 5, 6, 2, 1 }};
175 static int Hexa_FE [6][5] = { // FORWARD -> EXTERNAL
176 { 0, 1, 2, 3, 0 } , // opposite faces are neighbouring,
177 { 4, 7, 6, 5, 4 }, // all face normals are external,
178 { 0, 4, 5, 1, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
182 static int Hexa_RE [6][5] = { // REVERSED -> EXTERNAL
183 { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
184 { 4, 5, 6, 7, 4 }, // all face normals are external,
185 { 0, 1, 5, 4, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
189 static int Hexa_nbN [] = { 4, 4, 4, 4, 4, 4 };
198 // N0 +---|---+ N1 TETRAHEDRON
206 static int QuadTetra_F [4][7] = { // FORWARD == EXTERNAL
207 { 0, 4, 1, 5, 2, 6, 0 }, // All faces have external normals
208 { 0, 7, 3, 8, 1, 4, 0 },
209 { 1, 8, 3, 9, 2, 5, 1 },
210 { 0, 6, 2, 9, 3, 7, 0 }};
211 static int QuadTetra_R [4][7] = { // REVERSED
212 { 0, 4, 1, 5, 2, 6, 0 }, // All faces but a bottom have external normals
213 { 0, 4, 1, 8, 3, 7, 0 },
214 { 1, 5, 2, 9, 3, 8, 1 },
215 { 0, 7, 3, 9, 2, 6, 0 }};
216 static int QuadTetra_RE [4][7] = { // REVERSED -> FORWARD (EXTERNAL)
217 { 0, 6, 2, 5, 1, 4, 0 }, // All faces have external normals
218 { 0, 4, 1, 8, 3, 7, 0 },
219 { 1, 5, 2, 9, 3, 8, 1 },
220 { 0, 7, 3, 9, 2, 6, 0 }};
221 static int QuadTetra_nbN [] = { 6, 6, 6, 6 };
231 // | | 9 - middle point for (0,4) etc.
244 static int QuadPyram_F [5][9] = { // FORWARD == EXTERNAL
245 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces have external normals
246 { 0, 9, 4, 10,1, 5, 0, 4, 4 },
247 { 1, 10,4, 11,2, 6, 1, 4, 4 },
248 { 2, 11,4, 12,3, 7, 2, 4, 4 },
249 { 3, 12,4, 9, 0, 8, 3, 4, 4 }};
250 static int QuadPyram_R [5][9] = { // REVERSED
251 { 0, 5, 1, 6, 2, 7, 3, 8, 0 }, // All faces but a bottom have external normals
252 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
253 { 1, 6, 2, 11,4, 10,1, 4, 4 },
254 { 2, 7, 3, 12,4, 11,2, 4, 4 },
255 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
256 static int QuadPyram_RE [5][9] = { // REVERSED -> FORWARD (EXTERNAL)
257 { 0, 8, 3, 7, 2, 6, 1, 5, 0 }, // All faces but a bottom have external normals
258 { 0, 5, 1, 10,4, 9, 0, 4, 4 },
259 { 1, 6, 2, 11,4, 10,1, 4, 4 },
260 { 2, 7, 3, 12,4, 11,2, 4, 4 },
261 { 3, 8, 0, 9, 4, 12,3, 4, 4 }};
262 static int QuadPyram_nbN [] = { 8, 6, 6, 6, 6 };
289 static int QuadPenta_F [5][9] = { // FORWARD
290 { 0, 6, 1, 7, 2, 8, 0, 0, 0 }, // Top face has an internal normal, other - external
291 { 3, 9, 4, 10,5, 11,3, 3, 3 }, // 0 is bottom, 1 is top face
292 { 0, 8, 2, 14,5, 11,3, 12,0 },
293 { 1, 13,4, 10,5, 14,2, 7, 1 },
294 { 0, 12,3, 9, 4, 13,1, 6, 0 }};
295 static int QuadPenta_R [5][9] = { // REVERSED
296 { 0, 6, 1, 7, 2, 8, 0, 0, 0 }, // Bottom face has an internal normal, other - external
297 { 3, 9, 4, 10,5, 11,3, 3, 3 }, // 0 is bottom, 1 is top face
298 { 0, 12,3, 11,5, 14,2, 8, 0 },
299 { 1, 7, 2, 14,5, 10,4, 13,1 },
300 { 0, 6, 1, 13,4, 9, 3, 12,0 }};
301 static int QuadPenta_FE [5][9] = { // FORWARD -> EXTERNAL
302 { 0, 6, 1, 7, 2, 8, 0, 0, 0 },
303 { 3,11, 5, 10,4, 9, 3, 3, 3 },
304 { 0, 8, 2, 14,5, 11,3, 12,0 },
305 { 1, 13,4, 10,5, 14,2, 7, 1 },
306 { 0, 12,3, 9, 4, 13,1, 6, 0 }};
307 static int QuadPenta_RE [5][9] = { // REVERSED -> EXTERNAL
308 { 0, 8, 2, 7, 1, 6, 0, 0, 0 },
309 { 3, 9, 4, 10,5, 11,3, 3, 3 },
310 { 0, 12,3, 11,5, 14,2, 8, 0 },
311 { 1, 7, 2, 14,5, 10,4, 13,1 },
312 { 0, 6, 1, 13,4, 9, 3, 12,0 }};
313 static int QuadPenta_nbN [] = { 6, 6, 8, 8, 8 };
321 // N4+-----+-----+N7 | QUADRATIC
322 // | | 15 | | HEXAHEDRON
331 // | N1+-----+-|---+N2
338 static int QuadHexa_F [6][9] = { // FORWARD
339 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // opposite faces are neighbouring,
340 { 4, 12,5, 13,6, 14,7, 15,4 }, // odd face(1,3,5) normal is internal, even(0,2,4) - external
341 { 1, 8, 0, 16,4, 12,5, 17,1 }, // same index nodes of opposite faces are linked
342 { 2, 10,3, 19,7, 14,6, 18,2 },
343 { 0, 11,3, 19,7, 15,4, 16,0 },
344 { 1, 9, 2, 18,6, 13,5, 17,1 }};
345 // static int Hexa_R [6][5] = { // REVERSED
346 // { 0, 3, 2, 1, 0 }, // opposite faces are neighbouring,
347 // { 4, 7, 6, 5, 4 }, // odd face(1,3,5) normal is external, even(0,2,4) - internal
348 // { 1, 5, 4, 0, 1 }, // same index nodes of opposite faces are linked
349 // { 2, 6, 7, 3, 2 },
350 // { 0, 4, 7, 3, 0 },
351 // { 1, 5, 6, 2, 1 }};
352 static int QuadHexa_FE [6][9] = { // FORWARD -> EXTERNAL
353 { 0, 8, 1, 9, 2, 10,3, 11,0 }, // opposite faces are neighbouring,
354 { 4, 15,7, 14,6, 13,5, 12,4 }, // all face normals are external,
355 { 0, 16,4, 12,5, 17,1, 8, 0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
356 { 3, 10,2, 18,6, 14,7, 19,3 },
357 { 0, 11,3, 19,7, 15,4, 16,0 },
358 { 1, 17,5, 13,6, 18,2, 9, 1 }};
359 static int QuadHexa_RE [6][9] = { // REVERSED -> EXTERNAL
360 { 0, 11,3, 10,2, 9, 1, 8, 0 }, // opposite faces are neighbouring,
361 { 4, 12,5, 13,6, 14,7, 15,4 }, // all face normals are external,
362 { 0, 8, 1, 17,5, 12,4, 16,0 }, // links in opposite faces: 0-0, 1-3, 2-2, 3-1
363 { 3, 19,7, 14,6, 18,2, 10,3 },
364 { 0, 16,4, 15,7, 19,3, 11,0 },
365 { 1, 9, 2, 18,6, 13,5, 17,1 }};
366 static int QuadHexa_nbN [] = { 8, 8, 8, 8, 8, 8 };
369 // ========================================================
370 // to perform some calculations without linkage to CASCADE
371 // ========================================================
378 XYZ() { x = 0; y = 0; z = 0; }
379 XYZ( double X, double Y, double Z ) { x = X; y = Y; z = Z; }
380 XYZ( const XYZ& other ) { x = other.x; y = other.y; z = other.z; }
381 XYZ( const SMDS_MeshNode* n ) { x = n->X(); y = n->Y(); z = n->Z(); }
382 inline XYZ operator-( const XYZ& other );
383 inline XYZ Crossed( const XYZ& other );
384 inline double Dot( const XYZ& other );
385 inline double Magnitude();
386 inline double SquareMagnitude();
388 inline XYZ XYZ::operator-( const XYZ& Right ) {
389 return XYZ(x - Right.x, y - Right.y, z - Right.z);
391 inline XYZ XYZ::Crossed( const XYZ& Right ) {
392 return XYZ (y * Right.z - z * Right.y,
393 z * Right.x - x * Right.z,
394 x * Right.y - y * Right.x);
396 inline double XYZ::Dot( const XYZ& Other ) {
397 return(x * Other.x + y * Other.y + z * Other.z);
399 inline double XYZ::Magnitude() {
400 return sqrt (x * x + y * y + z * z);
402 inline double XYZ::SquareMagnitude() {
403 return (x * x + y * y + z * z);
407 //=======================================================================
408 //function : SMDS_VolumeTool
410 //=======================================================================
412 SMDS_VolumeTool::SMDS_VolumeTool ()
415 myVolForward( true ),
417 myVolumeNbNodes( 0 ),
418 myVolumeNodes( NULL ),
419 myExternalFaces( false ),
422 myFaceNodeIndices( NULL ),
425 //MESSAGE("******************************************************** SMDS_VolumeToo");
428 //=======================================================================
429 //function : SMDS_VolumeTool
431 //=======================================================================
433 SMDS_VolumeTool::SMDS_VolumeTool (const SMDS_MeshElement* theVolume)
436 myVolForward( true ),
438 myVolumeNbNodes( 0 ),
439 myVolumeNodes( NULL ),
440 myExternalFaces( false ),
443 myFaceNodeIndices( NULL ),
446 //MESSAGE("******************************************************** SMDS_VolumeToo");
450 //=======================================================================
451 //function : SMDS_VolumeTool
453 //=======================================================================
455 SMDS_VolumeTool::~SMDS_VolumeTool()
457 if ( myVolumeNodes != NULL ) delete [] myVolumeNodes;
458 if ( myFaceNodes != NULL ) delete [] myFaceNodes;
460 myFaceNodeIndices = NULL;
461 myVolumeNodes = myFaceNodes = NULL;
464 //=======================================================================
465 //function : SetVolume
466 //purpose : Set volume to iterate on
467 //=======================================================================
469 bool SMDS_VolumeTool::Set (const SMDS_MeshElement* theVolume)
477 if (myVolumeNodes != NULL) {
478 delete [] myVolumeNodes;
479 myVolumeNodes = NULL;
482 myExternalFaces = false;
486 myFaceNodeIndices = NULL;
487 if (myFaceNodes != NULL) {
488 delete [] myFaceNodes;
492 if ( theVolume && theVolume->GetType() == SMDSAbs_Volume )
494 myVolume = theVolume;
496 myNbFaces = theVolume->NbFaces();
497 myVolumeNbNodes = theVolume->NbNodes();
501 myVolumeNodes = new const SMDS_MeshNode* [myVolumeNbNodes];
502 SMDS_ElemIteratorPtr nodeIt = myVolume->nodesIterator();
503 while ( nodeIt->more() ) {
504 myVolumeNodes[ iNode++ ] = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
507 if (myVolume->IsPoly()) {
508 myPolyedre = dynamic_cast<const SMDS_VtkVolume*>( myVolume );
510 MESSAGE("Warning: bad volumic element");
515 switch ( myVolumeNbNodes ) {
524 // define volume orientation
526 GetFaceNormal( 0, botNormal.x, botNormal.y, botNormal.z );
527 const SMDS_MeshNode* botNode = myVolumeNodes[ 0 ];
528 int topNodeIndex = myVolume->NbCornerNodes() - 1;
529 while ( !IsLinked( 0, topNodeIndex, /*ignoreMediumNodes=*/true )) --topNodeIndex;
530 const SMDS_MeshNode* topNode = myVolumeNodes[ topNodeIndex ];
531 XYZ upDir (topNode->X() - botNode->X(),
532 topNode->Y() - botNode->Y(),
533 topNode->Z() - botNode->Z() );
534 myVolForward = ( botNormal.Dot( upDir ) < 0 );
542 return ( myVolume != 0 );
545 //=======================================================================
547 //purpose : Inverse volume
548 //=======================================================================
550 #define SWAP_NODES(nodes,i1,i2) \
552 const SMDS_MeshNode* tmp = nodes[ i1 ]; \
553 nodes[ i1 ] = nodes[ i2 ]; \
556 void SMDS_VolumeTool::Inverse ()
558 if ( !myVolume ) return;
560 if (myVolume->IsPoly()) {
561 MESSAGE("Warning: attempt to inverse polyhedral volume");
565 myVolForward = !myVolForward;
568 // inverse top and bottom faces
569 switch ( myVolumeNbNodes ) {
571 SWAP_NODES( myVolumeNodes, 1, 2 );
574 SWAP_NODES( myVolumeNodes, 1, 3 );
577 SWAP_NODES( myVolumeNodes, 1, 2 );
578 SWAP_NODES( myVolumeNodes, 4, 5 );
581 SWAP_NODES( myVolumeNodes, 1, 3 );
582 SWAP_NODES( myVolumeNodes, 5, 7 );
586 SWAP_NODES( myVolumeNodes, 1, 2 );
587 SWAP_NODES( myVolumeNodes, 4, 6 );
588 SWAP_NODES( myVolumeNodes, 8, 9 );
591 SWAP_NODES( myVolumeNodes, 1, 3 );
592 SWAP_NODES( myVolumeNodes, 5, 8 );
593 SWAP_NODES( myVolumeNodes, 6, 7 );
594 SWAP_NODES( myVolumeNodes, 10, 12 );
597 SWAP_NODES( myVolumeNodes, 1, 2 );
598 SWAP_NODES( myVolumeNodes, 4, 5 );
599 SWAP_NODES( myVolumeNodes, 6, 8 );
600 SWAP_NODES( myVolumeNodes, 9, 11 );
601 SWAP_NODES( myVolumeNodes, 13, 14 );
604 SWAP_NODES( myVolumeNodes, 1, 3 );
605 SWAP_NODES( myVolumeNodes, 5, 7 );
606 SWAP_NODES( myVolumeNodes, 8, 11 );
607 SWAP_NODES( myVolumeNodes, 9, 10 );
608 SWAP_NODES( myVolumeNodes, 12, 15 );
609 SWAP_NODES( myVolumeNodes, 13, 14 );
610 SWAP_NODES( myVolumeNodes, 17, 19 );
616 //=======================================================================
617 //function : GetVolumeType
619 //=======================================================================
621 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetVolumeType() const
627 // static const VolumeType types[] = {
628 // TETRA, // myVolumeNbNodes = 4
629 // PYRAM, // myVolumeNbNodes = 5
630 // PENTA, // myVolumeNbNodes = 6
631 // UNKNOWN, // myVolumeNbNodes = 7
632 // HEXA // myVolumeNbNodes = 8
634 // return types[ myVolumeNbNodes - 4 ];
635 switch(myVolumeNbNodes) {
636 case 4: return TETRA; break;
637 case 5: return PYRAM; break;
638 case 6: return PENTA; break;
639 case 8: return HEXA; break;
640 case 10: return QUAD_TETRA; break;
641 case 13: return QUAD_PYRAM; break;
642 case 15: return QUAD_PENTA; break;
643 case 20: return QUAD_HEXA; break;
651 //=======================================================================
652 //function : getTetraVolume
654 //=======================================================================
656 static double getTetraVolume(const SMDS_MeshNode* n1,
657 const SMDS_MeshNode* n2,
658 const SMDS_MeshNode* n3,
659 const SMDS_MeshNode* n4)
677 double Q1 = -(X1-X2)*(Y3*Z4-Y4*Z3);
678 double Q2 = (X1-X3)*(Y2*Z4-Y4*Z2);
679 double R1 = -(X1-X4)*(Y2*Z3-Y3*Z2);
680 double R2 = -(X2-X3)*(Y1*Z4-Y4*Z1);
681 double S1 = (X2-X4)*(Y1*Z3-Y3*Z1);
682 double S2 = -(X3-X4)*(Y1*Z2-Y2*Z1);
684 return (Q1+Q2+R1+R2+S1+S2)/6.0;
687 //=======================================================================
689 //purpose : Return element volume
690 //=======================================================================
692 double SMDS_VolumeTool::GetSize() const
698 if ( myVolume->IsPoly() )
703 SMDS_Mesh *mesh = SMDS_Mesh::_meshList[myPolyedre->getMeshId()];
704 // split a polyhedron into tetrahedrons
706 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
708 me->GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
709 SMDS_MeshNode *bcNode = mesh->AddNode( baryCenter.x, baryCenter.y, baryCenter.z );
711 for ( int f = 0; f < NbFaces(); ++f )
713 bool externalFace = me->IsFaceExternal( f ); // it calls setFace()
714 for ( int n = 2; n < myFaceNbNodes; ++n )
716 double Vn = getTetraVolume( myFaceNodes[ 0 ],
720 /// cout <<"++++ " << Vn << " nodes " <<myFaceNodes[ 0 ]->GetID() << " " <<myFaceNodes[ n-1 ]->GetID() << " " <<myFaceNodes[ n ]->GetID() << " < " << V << endl;
721 V += externalFace ? -Vn : Vn;
724 mesh->RemoveNode(bcNode);
728 const static int ind[] = {
729 0, 1, 3, 6, 11, 19, 32, 46, 66};
730 const static int vtab[][4] = {
747 // quadratic tetrahedron
772 // quadratic pentahedron
789 // quadratic hexahedron
814 int type = GetVolumeType();
816 int n2 = ind[type+1];
818 for (int i = n1; i < n2; i++) {
819 V -= getTetraVolume( myVolumeNodes[ vtab[i][0] ],
820 myVolumeNodes[ vtab[i][1] ],
821 myVolumeNodes[ vtab[i][2] ],
822 myVolumeNodes[ vtab[i][3] ]);
828 //=======================================================================
829 //function : GetBaryCenter
831 //=======================================================================
833 bool SMDS_VolumeTool::GetBaryCenter(double & X, double & Y, double & Z) const
839 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
840 X += myVolumeNodes[ i ]->X();
841 Y += myVolumeNodes[ i ]->Y();
842 Z += myVolumeNodes[ i ]->Z();
844 X /= myVolumeNbNodes;
845 Y /= myVolumeNbNodes;
846 Z /= myVolumeNbNodes;
851 //================================================================================
853 * \brief Classify a point
854 * \param tol - thickness of faces
856 //================================================================================
858 bool SMDS_VolumeTool::IsOut(double X, double Y, double Z, double tol) const
860 // LIMITATION: for convex volumes only
862 for ( int iF = 0; iF < myNbFaces; ++iF )
865 if ( !GetFaceNormal( iF, faceNormal.x, faceNormal.y, faceNormal.z ))
867 if ( !IsFaceExternal( iF ))
868 faceNormal = XYZ() - faceNormal; // reverse
870 XYZ face2p( p - XYZ( myFaceNodes[0] ));
871 if ( face2p.Dot( faceNormal ) > tol )
877 //=======================================================================
878 //function : SetExternalNormal
879 //purpose : Node order will be so that faces normals are external
880 //=======================================================================
882 void SMDS_VolumeTool::SetExternalNormal ()
884 myExternalFaces = true;
888 //=======================================================================
889 //function : NbFaceNodes
890 //purpose : Return number of nodes in the array of face nodes
891 //=======================================================================
893 int SMDS_VolumeTool::NbFaceNodes( int faceIndex ) const
895 if ( !setFace( faceIndex ))
897 return myFaceNbNodes;
900 //=======================================================================
901 //function : GetFaceNodes
902 //purpose : Return pointer to the array of face nodes.
903 // To comfort link iteration, the array
904 // length == NbFaceNodes( faceIndex ) + 1 and
905 // the last node == the first one.
906 //=======================================================================
908 const SMDS_MeshNode** SMDS_VolumeTool::GetFaceNodes( int faceIndex ) const
910 if ( !setFace( faceIndex ))
915 //=======================================================================
916 //function : GetFaceNodesIndices
917 //purpose : Return pointer to the array of face nodes indices
918 // To comfort link iteration, the array
919 // length == NbFaceNodes( faceIndex ) + 1 and
920 // the last node index == the first one.
921 //=======================================================================
923 const int* SMDS_VolumeTool::GetFaceNodesIndices( int faceIndex ) const
925 if ( !setFace( faceIndex ))
928 if (myVolume->IsPoly())
930 SMDS_VolumeTool* me = const_cast< SMDS_VolumeTool* > ( this );
931 me->myPolyIndices.resize( myFaceNbNodes + 1 );
932 me->myFaceNodeIndices = & me->myPolyIndices[0];
933 for ( int i = 0; i <= myFaceNbNodes; ++i )
934 me->myFaceNodeIndices[i] = myVolume->GetNodeIndex( myFaceNodes[i] );
936 return myFaceNodeIndices;
939 //=======================================================================
940 //function : GetFaceNodes
941 //purpose : Return a set of face nodes.
942 //=======================================================================
944 bool SMDS_VolumeTool::GetFaceNodes (int faceIndex,
945 set<const SMDS_MeshNode*>& theFaceNodes ) const
947 if ( !setFace( faceIndex ))
950 theFaceNodes.clear();
951 int iNode, nbNode = myFaceNbNodes;
952 for ( iNode = 0; iNode < nbNode; iNode++ )
953 theFaceNodes.insert( myFaceNodes[ iNode ]);
958 //=======================================================================
959 //function : IsFaceExternal
960 //purpose : Check normal orientation of a given face
961 //=======================================================================
963 bool SMDS_VolumeTool::IsFaceExternal( int faceIndex ) const
965 if ( myExternalFaces || !myVolume )
968 if (myVolume->IsPoly()) {
969 XYZ aNormal, baryCenter, p0 (myPolyedre->GetFaceNode(faceIndex + 1, 1));
970 GetFaceNormal(faceIndex, aNormal.x, aNormal.y, aNormal.z);
971 GetBaryCenter(baryCenter.x, baryCenter.y, baryCenter.z);
972 XYZ insideVec (baryCenter - p0);
973 if (insideVec.Dot(aNormal) > 0)
978 switch ( myVolumeNbNodes ) {
983 // only the bottom of a reversed tetrahedron can be internal
984 return ( myVolForward || faceIndex != 0 );
987 // in a forward pentahedron, the top is internal, in a reversed one - bottom
988 return ( myVolForward ? faceIndex != 1 : faceIndex != 0 );
991 // in a forward hexahedron, even face normal is external, odd - internal
992 bool odd = faceIndex % 2;
993 return ( myVolForward ? !odd : odd );
1000 //=======================================================================
1001 //function : GetFaceNormal
1002 //purpose : Return a normal to a face
1003 //=======================================================================
1005 bool SMDS_VolumeTool::GetFaceNormal (int faceIndex, double & X, double & Y, double & Z) const
1007 if ( !setFace( faceIndex ))
1010 XYZ p1 ( myFaceNodes[0] );
1011 XYZ p2 ( myFaceNodes[1] );
1012 XYZ p3 ( myFaceNodes[2] );
1013 XYZ aVec12( p2 - p1 );
1014 XYZ aVec13( p3 - p1 );
1015 XYZ cross = aVec12.Crossed( aVec13 );
1017 //if ( myFaceNbNodes == 4 ) {
1018 if ( myFaceNbNodes >3 ) {
1019 XYZ p4 ( myFaceNodes[3] );
1020 XYZ aVec14( p4 - p1 );
1021 XYZ cross2 = aVec13.Crossed( aVec14 );
1022 cross.x += cross2.x;
1023 cross.y += cross2.y;
1024 cross.z += cross2.z;
1027 double size = cross.Magnitude();
1028 if ( size <= numeric_limits<double>::min() )
1038 //================================================================================
1040 * \brief Return barycenter of a face
1042 //================================================================================
1044 bool SMDS_VolumeTool::GetFaceBaryCenter (int faceIndex, double & X, double & Y, double & Z) const
1046 if ( !setFace( faceIndex ))
1050 for ( int i = 0; i < myFaceNbNodes; ++i )
1052 X += myFaceNodes[i]->X() / myFaceNbNodes;
1053 Y += myFaceNodes[i]->Y() / myFaceNbNodes;
1054 Z += myFaceNodes[i]->Z() / myFaceNbNodes;
1059 //=======================================================================
1060 //function : GetFaceArea
1061 //purpose : Return face area
1062 //=======================================================================
1064 double SMDS_VolumeTool::GetFaceArea( int faceIndex ) const
1066 if (myVolume->IsPoly()) {
1067 MESSAGE("Warning: attempt to obtain area of a face of polyhedral volume");
1071 if ( !setFace( faceIndex ))
1074 XYZ p1 ( myFaceNodes[0] );
1075 XYZ p2 ( myFaceNodes[1] );
1076 XYZ p3 ( myFaceNodes[2] );
1077 XYZ aVec12( p2 - p1 );
1078 XYZ aVec13( p3 - p1 );
1079 double area = aVec12.Crossed( aVec13 ).Magnitude() * 0.5;
1081 if ( myFaceNbNodes == 4 ) {
1082 XYZ p4 ( myFaceNodes[3] );
1083 XYZ aVec14( p4 - p1 );
1084 area += aVec14.Crossed( aVec13 ).Magnitude() * 0.5;
1089 //=======================================================================
1090 //function : GetOppFaceIndex
1091 //purpose : Return index of the opposite face if it exists, else -1.
1092 //=======================================================================
1094 int SMDS_VolumeTool::GetOppFaceIndex( int faceIndex ) const
1097 if (myVolume->IsPoly()) {
1098 MESSAGE("Warning: attempt to obtain opposite face on polyhedral volume");
1102 if ( faceIndex >= 0 && faceIndex < NbFaces() ) {
1103 switch ( myVolumeNbNodes ) {
1105 if ( faceIndex == 0 || faceIndex == 1 )
1106 ind = 1 - faceIndex;
1109 ind = faceIndex + ( faceIndex % 2 ? -1 : 1 );
1117 //=======================================================================
1118 //function : IsLinked
1119 //purpose : return true if theNode1 is linked with theNode2
1120 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1121 //=======================================================================
1123 bool SMDS_VolumeTool::IsLinked (const SMDS_MeshNode* theNode1,
1124 const SMDS_MeshNode* theNode2,
1125 const bool theIgnoreMediumNodes) const
1130 if (myVolume->IsPoly()) {
1132 MESSAGE("Warning: bad volumic element");
1135 bool isLinked = false;
1137 for (iface = 1; iface <= myNbFaces && !isLinked; iface++) {
1138 int inode, nbFaceNodes = myPolyedre->NbFaceNodes(iface);
1140 for (inode = 1; inode <= nbFaceNodes && !isLinked; inode++) {
1141 const SMDS_MeshNode* curNode = myPolyedre->GetFaceNode(iface, inode);
1143 if (curNode == theNode1 || curNode == theNode2) {
1144 int inextnode = (inode == nbFaceNodes) ? 1 : inode + 1;
1145 const SMDS_MeshNode* nextNode = myPolyedre->GetFaceNode(iface, inextnode);
1147 if ((curNode == theNode1 && nextNode == theNode2) ||
1148 (curNode == theNode2 && nextNode == theNode1)) {
1157 // find nodes indices
1158 int i1 = -1, i2 = -1;
1159 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1160 if ( myVolumeNodes[ i ] == theNode1 )
1162 else if ( myVolumeNodes[ i ] == theNode2 )
1165 return IsLinked( i1, i2 );
1168 //=======================================================================
1169 //function : IsLinked
1170 //purpose : return true if the node with theNode1Index is linked
1171 // with the node with theNode2Index
1172 // If theIgnoreMediumNodes then corner nodes of quadratic cell are considered linked as well
1173 //=======================================================================
1175 bool SMDS_VolumeTool::IsLinked (const int theNode1Index,
1176 const int theNode2Index,
1177 bool theIgnoreMediumNodes) const
1179 if ( myVolume->IsPoly() ) {
1180 return IsLinked(myVolumeNodes[theNode1Index], myVolumeNodes[theNode2Index]);
1183 int minInd = min( theNode1Index, theNode2Index );
1184 int maxInd = max( theNode1Index, theNode2Index );
1186 if ( minInd < 0 || maxInd > myVolumeNbNodes - 1 || maxInd == minInd )
1189 SMDSAbs_EntityType type = myVolume->GetEntityType();
1190 if ( myVolume->IsQuadratic() )
1192 int firstMediumInd = myVolume->NbCornerNodes();
1193 if ( minInd >= firstMediumInd )
1194 return false; // medium nodes are not linked
1195 if ( maxInd < firstMediumInd ) // both nodes are corners
1197 if ( theIgnoreMediumNodes )
1198 type = SMDSAbs_EntityType( int(type)-1 ); // check linkage of corner nodes
1200 return false; // corner nodes are not linked directly in a quadratic cell
1205 case SMDSEntity_Tetra:
1207 case SMDSEntity_Hexa:
1208 switch ( maxInd - minInd ) {
1209 case 1: return minInd != 3;
1210 case 3: return minInd == 0 || minInd == 4;
1211 case 4: return true;
1215 case SMDSEntity_Pyramid:
1218 switch ( maxInd - minInd ) {
1220 case 3: return true;
1224 case SMDSEntity_Penta:
1225 switch ( maxInd - minInd ) {
1226 case 1: return minInd != 2;
1227 case 2: return minInd == 0 || minInd == 3;
1228 case 3: return true;
1232 case SMDSEntity_Quad_Tetra:
1235 case 0: if( maxInd==4 || maxInd==6 || maxInd==7 ) return true;
1236 case 1: if( maxInd==4 || maxInd==5 || maxInd==8 ) return true;
1237 case 2: if( maxInd==5 || maxInd==6 || maxInd==9 ) return true;
1238 case 3: if( maxInd==7 || maxInd==8 || maxInd==9 ) return true;
1243 case SMDSEntity_Quad_Hexa:
1246 case 0: if( maxInd==8 || maxInd==11 || maxInd==16 ) return true;
1247 case 1: if( maxInd==8 || maxInd==9 || maxInd==17 ) return true;
1248 case 2: if( maxInd==9 || maxInd==10 || maxInd==18 ) return true;
1249 case 3: if( maxInd==10 || maxInd==11 || maxInd==19 ) return true;
1250 case 4: if( maxInd==12 || maxInd==15 || maxInd==16 ) return true;
1251 case 5: if( maxInd==12 || maxInd==13 || maxInd==17 ) return true;
1252 case 6: if( maxInd==13 || maxInd==14 || maxInd==18 ) return true;
1253 case 7: if( maxInd==14 || maxInd==15 || maxInd==19 ) return true;
1258 case SMDSEntity_Quad_Pyramid:
1261 case 0: if( maxInd==5 || maxInd==8 || maxInd==9 ) return true;
1262 case 1: if( maxInd==5 || maxInd==6 || maxInd==10 ) return true;
1263 case 2: if( maxInd==6 || maxInd==7 || maxInd==11 ) return true;
1264 case 3: if( maxInd==7 || maxInd==8 || maxInd==12 ) return true;
1265 case 4: if( maxInd==9 || maxInd==10 || maxInd==11 || maxInd==12 ) return true;
1270 case SMDSEntity_Quad_Penta:
1273 case 0: if( maxInd==6 || maxInd==8 || maxInd==12 ) return true;
1274 case 1: if( maxInd==6 || maxInd==7 || maxInd==13 ) return true;
1275 case 2: if( maxInd==7 || maxInd==8 || maxInd==14 ) return true;
1276 case 3: if( maxInd==9 || maxInd==11 || maxInd==12 ) return true;
1277 case 4: if( maxInd==9 || maxInd==10 || maxInd==13 ) return true;
1278 case 5: if( maxInd==10 || maxInd==11 || maxInd==14 ) return true;
1288 //=======================================================================
1289 //function : GetNodeIndex
1290 //purpose : Return an index of theNode
1291 //=======================================================================
1293 int SMDS_VolumeTool::GetNodeIndex(const SMDS_MeshNode* theNode) const
1296 for ( int i = 0; i < myVolumeNbNodes; i++ ) {
1297 if ( myVolumeNodes[ i ] == theNode )
1304 //================================================================================
1306 * \brief Fill vector with boundary faces existing in the mesh
1307 * \param faces - vector of found nodes
1308 * \retval int - nb of found faces
1310 //================================================================================
1312 int SMDS_VolumeTool::GetAllExistingFaces(vector<const SMDS_MeshElement*> & faces) const
1315 faces.reserve( NbFaces() );
1316 for ( int iF = 0; iF < NbFaces(); ++iF ) {
1317 const SMDS_MeshFace* face = 0;
1318 const SMDS_MeshNode** nodes = GetFaceNodes( iF );
1319 switch ( NbFaceNodes( iF )) {
1321 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2] ); break;
1323 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
1325 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2],
1326 nodes[3], nodes[4], nodes[5]); break;
1328 face = SMDS_Mesh::FindFace( nodes[0], nodes[1], nodes[2], nodes[3],
1329 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1332 faces.push_back( face );
1334 return faces.size();
1338 //================================================================================
1340 * \brief Fill vector with boundary edges existing in the mesh
1341 * \param edges - vector of found edges
1342 * \retval int - nb of found faces
1344 //================================================================================
1346 int SMDS_VolumeTool::GetAllExistingEdges(vector<const SMDS_MeshElement*> & edges) const
1349 edges.reserve( myVolumeNbNodes * 2 );
1350 for ( int i = 0; i < myVolumeNbNodes; ++i ) {
1351 for ( int j = i + 1; j < myVolumeNbNodes; ++j ) {
1352 if ( IsLinked( i, j )) {
1353 const SMDS_MeshElement* edge =
1354 SMDS_Mesh::FindEdge( myVolumeNodes[i], myVolumeNodes[j] );
1356 edges.push_back( edge );
1360 return edges.size();
1363 //================================================================================
1365 * \brief Return minimal square distance between connected corner nodes
1367 //================================================================================
1369 double SMDS_VolumeTool::MinLinearSize2() const
1371 double minSize = 1e+100;
1372 int iQ = myVolume->IsQuadratic() ? 2 : 1;
1374 // store current face data
1375 int curFace = myCurFace, nbN = myFaceNbNodes;
1376 int* ind = myFaceNodeIndices;
1377 myFaceNodeIndices = NULL;
1378 const SMDS_MeshNode** nodes = myFaceNodes;
1381 // it seems that compute distance twice is faster than organization of a sole computing
1383 for ( int iF = 0; iF < myNbFaces; ++iF )
1386 for ( int iN = 0; iN < myFaceNbNodes; iN += iQ )
1388 XYZ n1( myFaceNodes[ iN ]);
1389 XYZ n2( myFaceNodes[(iN + iQ) % myFaceNbNodes]);
1390 minSize = std::min( minSize, (n1 - n2).SquareMagnitude());
1393 // restore current face data
1394 myCurFace = curFace;
1395 myFaceNbNodes = nbN;
1396 myFaceNodeIndices = ind;
1397 delete [] myFaceNodes; myFaceNodes = nodes;
1402 //================================================================================
1404 * \brief check that only one volume is build on the face nodes
1406 * If a face is shared by one of <ignoreVolumes>, it is considered free
1408 //================================================================================
1410 bool SMDS_VolumeTool::IsFreeFace( int faceIndex, const SMDS_MeshElement** otherVol/*=0*/ ) const
1412 const bool isFree = true;
1414 if (!setFace( faceIndex ))
1417 const SMDS_MeshNode** nodes = GetFaceNodes( faceIndex );
1418 const int nbFaceNodes = myFaceNbNodes;
1420 // evaluate nb of face nodes shared by other volume
1421 int maxNbShared = -1;
1422 typedef map< const SMDS_MeshElement*, int > TElemIntMap;
1423 TElemIntMap volNbShared;
1424 TElemIntMap::iterator vNbIt;
1425 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1426 const SMDS_MeshNode* n = nodes[ iNode ];
1427 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1428 while ( eIt->more() ) {
1429 const SMDS_MeshElement* elem = eIt->next();
1430 if ( elem != myVolume ) {
1431 vNbIt = volNbShared.insert( make_pair( elem, 0 )).first;
1433 if ( vNbIt->second > maxNbShared )
1434 maxNbShared = vNbIt->second;
1438 if ( maxNbShared < 3 )
1439 return isFree; // is free
1441 // find volumes laying on the opposite side of the face
1442 // and sharing all nodes
1443 XYZ intNormal; // internal normal
1444 GetFaceNormal( faceIndex, intNormal.x, intNormal.y, intNormal.z );
1445 if ( IsFaceExternal( faceIndex ))
1446 intNormal = XYZ( -intNormal.x, -intNormal.y, -intNormal.z );
1447 XYZ p0 ( nodes[0] ), baryCenter;
1448 for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); ) {
1449 const int& nbShared = (*vNbIt).second;
1450 if ( nbShared >= 3 ) {
1451 SMDS_VolumeTool volume( (*vNbIt).first );
1452 volume.GetBaryCenter( baryCenter.x, baryCenter.y, baryCenter.z );
1453 XYZ intNormal2( baryCenter - p0 );
1454 if ( intNormal.Dot( intNormal2 ) < 0 ) {
1456 if ( nbShared >= nbFaceNodes )
1458 // a volume shares the whole facet
1459 if ( otherVol ) *otherVol = vNbIt->first;
1466 // remove a volume from volNbShared map
1467 volNbShared.erase( vNbIt++ );
1470 // here volNbShared contains only volumes laying on the opposite side of
1471 // the face and sharing 3 or more but not all face nodes with myVolume
1472 if ( volNbShared.size() < 2 ) {
1473 return isFree; // is free
1476 // check if the whole area of a face is shared
1477 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1479 const SMDS_MeshNode* n = nodes[ iNode ];
1480 // check if n is shared by one of volumes of volNbShared
1481 bool isShared = false;
1482 SMDS_ElemIteratorPtr eIt = n->GetInverseElementIterator( SMDSAbs_Volume );
1483 while ( eIt->more() && !isShared )
1484 isShared = volNbShared.count( eIt->next() );
1488 if ( otherVol ) *otherVol = volNbShared.begin()->first;
1491 // if ( !myVolume->IsPoly() )
1493 // bool isShared[] = { false, false, false, false }; // 4 triangle parts of a quadrangle
1494 // for ( vNbIt = volNbShared.begin(); vNbIt != volNbShared.end(); vNbIt++ ) {
1495 // SMDS_VolumeTool volume( (*vNbIt).first );
1496 // bool prevLinkShared = false;
1497 // int nbSharedLinks = 0;
1498 // for ( int iNode = 0; iNode < nbFaceNodes; iNode++ ) {
1499 // bool linkShared = volume.IsLinked( nodes[ iNode ], nodes[ iNode + 1] );
1500 // if ( linkShared )
1502 // if ( linkShared && prevLinkShared &&
1503 // volume.IsLinked( nodes[ iNode - 1 ], nodes[ iNode + 1] ))
1504 // isShared[ iNode ] = true;
1505 // prevLinkShared = linkShared;
1507 // if ( nbSharedLinks == nbFaceNodes )
1508 // return !free; // is not free
1509 // if ( nbFaceNodes == 4 ) {
1510 // // check traingle parts 1 & 3
1511 // if ( isShared[1] && isShared[3] )
1512 // return !free; // is not free
1513 // // check triangle parts 0 & 2;
1514 // // 0 part could not be checked in the loop; check it here
1515 // if ( isShared[2] && prevLinkShared &&
1516 // volume.IsLinked( nodes[ 0 ], nodes[ 1 ] ) &&
1517 // volume.IsLinked( nodes[ 1 ], nodes[ 3 ] ) )
1518 // return !free; // is not free
1525 //=======================================================================
1526 //function : GetFaceIndex
1527 //purpose : Return index of a face formed by theFaceNodes
1528 //=======================================================================
1530 int SMDS_VolumeTool::GetFaceIndex( const set<const SMDS_MeshNode*>& theFaceNodes ) const
1532 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1533 const SMDS_MeshNode** nodes = GetFaceNodes( iFace );
1534 int nbFaceNodes = NbFaceNodes( iFace );
1535 set<const SMDS_MeshNode*> nodeSet;
1536 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1537 nodeSet.insert( nodes[ iNode ] );
1538 if ( theFaceNodes == nodeSet )
1544 //=======================================================================
1545 //function : GetFaceIndex
1546 //purpose : Return index of a face formed by theFaceNodes
1547 //=======================================================================
1549 /*int SMDS_VolumeTool::GetFaceIndex( const set<int>& theFaceNodesIndices )
1551 for ( int iFace = 0; iFace < myNbFaces; iFace++ ) {
1552 const int* nodes = GetFaceNodesIndices( iFace );
1553 int nbFaceNodes = NbFaceNodes( iFace );
1555 for ( int iNode = 0; iNode < nbFaceNodes; iNode++ )
1556 nodeSet.insert( nodes[ iNode ] );
1557 if ( theFaceNodesIndices == nodeSet )
1563 //=======================================================================
1564 //function : setFace
1566 //=======================================================================
1568 bool SMDS_VolumeTool::setFace( int faceIndex ) const
1573 if ( myCurFace == faceIndex )
1578 if ( faceIndex < 0 || faceIndex >= NbFaces() )
1581 if (myFaceNodes != NULL) {
1582 delete [] myFaceNodes;
1586 if (myVolume->IsPoly()) {
1588 MESSAGE("Warning: bad volumic element");
1594 myFaceNbNodes = myPolyedre->NbFaceNodes(faceIndex + 1);
1595 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1596 for ( iNode = 0; iNode < myFaceNbNodes; iNode++ )
1597 myFaceNodes[ iNode ] = myPolyedre->GetFaceNode(faceIndex + 1, iNode + 1);
1598 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ]; // last = first
1600 // check orientation
1601 if (myExternalFaces)
1603 myCurFace = faceIndex; // avoid infinite recursion in IsFaceExternal()
1604 myExternalFaces = false; // force normal computation by IsFaceExternal()
1605 if ( !IsFaceExternal( faceIndex ))
1606 for ( int i = 0, j = myFaceNbNodes; i < j; ++i, --j )
1607 std::swap( myFaceNodes[i], myFaceNodes[j] );
1608 myExternalFaces = true;
1612 // choose face node indices
1613 switch ( myVolumeNbNodes ) {
1615 myFaceNbNodes = Tetra_nbN[ faceIndex ];
1616 if ( myExternalFaces )
1617 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_RE[ faceIndex ];
1619 myFaceNodeIndices = myVolForward ? Tetra_F[ faceIndex ] : Tetra_R[ faceIndex ];
1622 myFaceNbNodes = Pyramid_nbN[ faceIndex ];
1623 if ( myExternalFaces )
1624 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_RE[ faceIndex ];
1626 myFaceNodeIndices = myVolForward ? Pyramid_F[ faceIndex ] : Pyramid_R[ faceIndex ];
1629 myFaceNbNodes = Penta_nbN[ faceIndex ];
1630 if ( myExternalFaces )
1631 myFaceNodeIndices = myVolForward ? Penta_FE[ faceIndex ] : Penta_RE[ faceIndex ];
1633 myFaceNodeIndices = myVolForward ? Penta_F[ faceIndex ] : Penta_R[ faceIndex ];
1636 myFaceNbNodes = Hexa_nbN[ faceIndex ];
1637 if ( myExternalFaces )
1638 myFaceNodeIndices = myVolForward ? Hexa_FE[ faceIndex ] : Hexa_RE[ faceIndex ];
1640 myFaceNodeIndices = Hexa_F[ faceIndex ];
1643 myFaceNbNodes = QuadTetra_nbN[ faceIndex ];
1644 if ( myExternalFaces )
1645 myFaceNodeIndices = myVolForward ? QuadTetra_F[ faceIndex ] : QuadTetra_RE[ faceIndex ];
1647 myFaceNodeIndices = myVolForward ? QuadTetra_F[ faceIndex ] : QuadTetra_R[ faceIndex ];
1650 myFaceNbNodes = QuadPyram_nbN[ faceIndex ];
1651 if ( myExternalFaces )
1652 myFaceNodeIndices = myVolForward ? QuadPyram_F[ faceIndex ] : QuadPyram_RE[ faceIndex ];
1654 myFaceNodeIndices = myVolForward ? QuadPyram_F[ faceIndex ] : QuadPyram_R[ faceIndex ];
1657 myFaceNbNodes = QuadPenta_nbN[ faceIndex ];
1658 if ( myExternalFaces )
1659 myFaceNodeIndices = myVolForward ? QuadPenta_FE[ faceIndex ] : QuadPenta_RE[ faceIndex ];
1661 myFaceNodeIndices = myVolForward ? QuadPenta_F[ faceIndex ] : QuadPenta_R[ faceIndex ];
1664 myFaceNbNodes = QuadHexa_nbN[ faceIndex ];
1665 if ( myExternalFaces )
1666 myFaceNodeIndices = myVolForward ? QuadHexa_FE[ faceIndex ] : QuadHexa_RE[ faceIndex ];
1668 myFaceNodeIndices = QuadHexa_F[ faceIndex ];
1675 myFaceNodes = new const SMDS_MeshNode* [myFaceNbNodes + 1];
1676 for ( int iNode = 0; iNode < myFaceNbNodes; iNode++ )
1677 myFaceNodes[ iNode ] = myVolumeNodes[ myFaceNodeIndices[ iNode ]];
1678 myFaceNodes[ myFaceNbNodes ] = myFaceNodes[ 0 ];
1681 myCurFace = faceIndex;
1686 //=======================================================================
1687 //function : GetType
1688 //purpose : return VolumeType by nb of nodes in a volume
1689 //=======================================================================
1691 SMDS_VolumeTool::VolumeType SMDS_VolumeTool::GetType(int nbNodes)
1693 switch ( nbNodes ) {
1694 case 4: return TETRA;
1695 case 5: return PYRAM;
1696 case 6: return PENTA;
1697 case 8: return HEXA;
1698 case 10: return QUAD_TETRA;
1699 case 13: return QUAD_PYRAM;
1700 case 15: return QUAD_PENTA;
1701 case 20: return QUAD_HEXA;
1702 default:return UNKNOWN;
1706 //=======================================================================
1707 //function : NbFaces
1708 //purpose : return nb of faces by volume type
1709 //=======================================================================
1711 int SMDS_VolumeTool::NbFaces( VolumeType type )
1715 case QUAD_TETRA: return 4;
1717 case QUAD_PYRAM: return 5;
1719 case QUAD_PENTA: return 5;
1721 case QUAD_HEXA : return 6;
1726 //================================================================================
1728 * \brief Useful to know nb of corner nodes of a quadratic volume
1729 * \param type - volume type
1730 * \retval int - nb of corner nodes
1732 //================================================================================
1734 int SMDS_VolumeTool::NbCornerNodes(VolumeType type)
1738 case QUAD_TETRA: return 4;
1740 case QUAD_PYRAM: return 5;
1742 case QUAD_PENTA: return 6;
1744 case QUAD_HEXA : return 8;
1751 //=======================================================================
1752 //function : GetFaceNodesIndices
1753 //purpose : Return the array of face nodes indices
1754 // To comfort link iteration, the array
1755 // length == NbFaceNodes( faceIndex ) + 1 and
1756 // the last node index == the first one.
1757 //=======================================================================
1759 const int* SMDS_VolumeTool::GetFaceNodesIndices(VolumeType type,
1764 case TETRA: return Tetra_F[ faceIndex ];
1765 case PYRAM: return Pyramid_F[ faceIndex ];
1766 case PENTA: return external ? Penta_FE[ faceIndex ] : Penta_F[ faceIndex ];
1767 case HEXA: return external ? Hexa_FE[ faceIndex ] : Hexa_F[ faceIndex ];
1768 case QUAD_TETRA: return QuadTetra_F[ faceIndex ];
1769 case QUAD_PYRAM: return QuadPyram_F[ faceIndex ];
1770 case QUAD_PENTA: return external ? QuadPenta_FE[ faceIndex ] : QuadPenta_F[ faceIndex ];
1771 case QUAD_HEXA: return external ? QuadHexa_FE[ faceIndex ] : QuadHexa_F[ faceIndex ];
1777 //=======================================================================
1778 //function : NbFaceNodes
1779 //purpose : Return number of nodes in the array of face nodes
1780 //=======================================================================
1782 int SMDS_VolumeTool::NbFaceNodes(VolumeType type,
1786 case TETRA: return Tetra_nbN[ faceIndex ];
1787 case PYRAM: return Pyramid_nbN[ faceIndex ];
1788 case PENTA: return Penta_nbN[ faceIndex ];
1789 case HEXA: return Hexa_nbN[ faceIndex ];
1790 case QUAD_TETRA: return QuadTetra_nbN[ faceIndex ];
1791 case QUAD_PYRAM: return QuadPyram_nbN[ faceIndex ];
1792 case QUAD_PENTA: return QuadPenta_nbN[ faceIndex ];
1793 case QUAD_HEXA: return QuadHexa_nbN[ faceIndex ];
1799 //=======================================================================
1801 //purpose : return element
1802 //=======================================================================
1804 const SMDS_MeshVolume* SMDS_VolumeTool::Element() const
1806 return static_cast<const SMDS_MeshVolume*>( myVolume );
1809 //=======================================================================
1811 //purpose : return element ID
1812 //=======================================================================
1814 int SMDS_VolumeTool::ID() const
1816 return myVolume ? myVolume->GetID() : 0;