1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
20 // File : SMESH_Pattern.hxx
21 // Created : Mon Aug 2 10:30:00 2004
22 // Author : Edward AGAPOV (eap)
24 #include "SMESH_Block.hxx"
26 #include <BRepTools.hxx>
27 #include <BRepTools_WireExplorer.hxx>
28 #include <BRep_Tool.hxx>
29 #include <Extrema_ExtPC.hxx>
30 #include <Extrema_POnCurv.hxx>
31 #include <GeomAdaptor_Curve.hxx>
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopLoc_Location.hxx>
35 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopoDS_Wire.hxx>
42 #include <gp_Trsf.hxx>
44 #include <math_FunctionSetRoot.hxx>
46 #include "SMDS_MeshNode.hxx"
47 #include "SMDS_MeshVolume.hxx"
48 #include "SMDS_VolumeTool.hxx"
49 #include "utilities.h"
57 //=======================================================================
58 //function : SMESH_Block::TEdge::GetU
60 //=======================================================================
62 double SMESH_Block::TEdge::GetU( const gp_XYZ& theParams ) const
64 double u = theParams.Coord( myCoordInd );
65 if ( myC3d.IsNull() ) // if mesh block
67 return ( 1 - u ) * myFirst + u * myLast;
70 //=======================================================================
71 //function : SMESH_Block::TEdge::Point
73 //=======================================================================
75 gp_XYZ SMESH_Block::TEdge::Point( const gp_XYZ& theParams ) const
77 double u = GetU( theParams );
79 if ( myC3d.IsNull() ) // if mesh block
80 return myNodes[0] * ( 1 - u ) + myNodes[1] * u;
82 gp_XYZ p = myC3d->Value( u ).XYZ();
83 if ( myTrsf.Form() != gp_Identity )
84 myTrsf.Transforms( p );
88 //=======================================================================
89 //function : SMESH_Block::TFace::GetCoefs
90 //purpose : return coefficients for addition of [0-3]-th edge and vertex
91 //=======================================================================
93 void SMESH_Block::TFace::GetCoefs(int iE,
94 const gp_XYZ& theParams,
98 double dU = theParams.Coord( GetUInd() );
99 double dV = theParams.Coord( GetVInd() );
102 Ecoef = ( 1 - dV ); // u0
103 Vcoef = ( 1 - dU ) * ( 1 - dV ); break; // 00
106 Vcoef = dU * ( 1 - dV ); break; // 10
108 Ecoef = ( 1 - dU ); // 0v
109 Vcoef = dU * dV ; break; // 11
112 Vcoef = ( 1 - dU ) * dV ; break; // 01
117 //=======================================================================
118 //function : SMESH_Block::TFace::GetUV
120 //=======================================================================
122 gp_XY SMESH_Block::TFace::GetUV( const gp_XYZ& theParams ) const
125 for ( int iE = 0; iE < 4; iE++ ) // loop on 4 edges
127 double Ecoef = 0, Vcoef = 0;
128 GetCoefs( iE, theParams, Ecoef, Vcoef );
130 double u = theParams.Coord( myCoordInd[ iE ] );
131 u = ( 1 - u ) * myFirst[ iE ] + u * myLast[ iE ];
132 uv += Ecoef * myC2d[ iE ]->Value( u ).XY();
134 uv -= Vcoef * myCorner[ iE ];
139 //=======================================================================
140 //function : SMESH_Block::TFace::Point
142 //=======================================================================
144 gp_XYZ SMESH_Block::TFace::Point( const gp_XYZ& theParams ) const
147 if ( myS.IsNull() ) // if mesh block
149 for ( int iE = 0; iE < 4; iE++ ) // loop on 4 edges
151 double Ecoef = 0, Vcoef = 0;
152 GetCoefs( iE, theParams, Ecoef, Vcoef );
154 double u = theParams.Coord( myCoordInd[ iE ] );
157 case 1: i1 = 3; i2 = 2; break;
158 case 2: i1 = 1; i2 = 2; break;
159 case 3: i1 = 0; i2 = 3; break;
161 p += Ecoef * ( myNodes[ i1 ] * ( 1 - u ) + myNodes[ i2 ] * u );
163 p -= Vcoef * myNodes[ iE ];
169 gp_XY uv = GetUV( theParams );
170 p = myS->Value( uv.X(), uv.Y() ).XYZ();
171 if ( myTrsf.Form() != gp_Identity )
172 myTrsf.Transforms( p );
177 //=======================================================================
178 //function : GetShapeCoef
180 //=======================================================================
182 double* SMESH_Block::GetShapeCoef (const int theShapeID)
184 static double shapeCoef[][3] = {
185 // V000, V100, V010, V110
186 { -1,-1,-1 }, { 1,-1,-1 }, { -1, 1,-1 }, { 1, 1,-1 },
187 // V001, V101, V011, V111,
188 { -1,-1, 1 }, { 1,-1, 1 }, { -1, 1, 1 }, { 1, 1, 1 },
189 // Ex00, Ex10, Ex01, Ex11,
190 { 0,-1,-1 }, { 0, 1,-1 }, { 0,-1, 1 }, { 0, 1, 1 },
191 // E0y0, E1y0, E0y1, E1y1,
192 { -1, 0,-1 }, { 1, 0,-1 }, { -1, 0, 1 }, { 1, 0, 1 },
193 // E00z, E10z, E01z, E11z,
194 { -1,-1, 0 }, { 1,-1, 0 }, { -1, 1, 0 }, { 1, 1, 0 },
195 // Fxy0, Fxy1, Fx0z, Fx1z, F0yz, F1yz,
196 { 0, 0,-1 }, { 0, 0, 1 }, { 0,-1, 0 }, { 0, 1, 0 }, { -1, 0, 0 }, { 1, 0, 0 },
200 if ( theShapeID < ID_V000 || theShapeID > ID_F1yz )
201 return shapeCoef[ ID_Shell - 1 ];
203 return shapeCoef[ theShapeID - 1 ];
206 //=======================================================================
207 //function : ShellPoint
208 //purpose : return coordinates of a point in shell
209 //=======================================================================
211 bool SMESH_Block::ShellPoint( const gp_XYZ& theParams, gp_XYZ& thePoint ) const
213 thePoint.SetCoord( 0., 0., 0. );
214 for ( int shapeID = ID_V000; shapeID < ID_Shell; shapeID++ )
217 double* coefs = GetShapeCoef( shapeID );
219 for ( int iCoef = 0; iCoef < 3; iCoef++ ) {
220 if ( coefs[ iCoef ] != 0 ) {
221 if ( coefs[ iCoef ] < 0 )
222 k *= ( 1. - theParams.Coord( iCoef + 1 ));
224 k *= theParams.Coord( iCoef + 1 );
229 if ( shapeID < ID_Ex00 ) // vertex
230 VertexPoint( shapeID, Ps );
231 else if ( shapeID < ID_Fxy0 ) { // edge
232 EdgePoint( shapeID, theParams, Ps );
235 FacePoint( shapeID, theParams, Ps );
242 //=======================================================================
243 //function : NbVariables
245 //=======================================================================
247 Standard_Integer SMESH_Block::NbVariables() const
252 //=======================================================================
253 //function : NbEquations
255 //=======================================================================
257 Standard_Integer SMESH_Block::NbEquations() const
262 //=======================================================================
265 //=======================================================================
267 Standard_Boolean SMESH_Block::Value(const math_Vector& theXYZ, math_Vector& theFxyz)
269 gp_XYZ P, params( theXYZ(1), theXYZ(2), theXYZ(3) );
270 if ( params.IsEqual( myParam, DBL_MIN )) { // same param
271 theFxyz( 1 ) = myValues[ 0 ];
274 ShellPoint( params, P );
275 gp_Vec dP( P - myPoint );
276 theFxyz(1) = SQRT_FUNC ? dP.SquareMagnitude() : dP.Magnitude();
281 //=======================================================================
282 //function : Derivatives
284 //=======================================================================
286 Standard_Boolean SMESH_Block::Derivatives(const math_Vector& XYZ,math_Matrix& Df)
288 MESSAGE( "SMESH_Block::Derivatives()");
290 return Values(XYZ,F,Df);
293 //=======================================================================
296 //=======================================================================
298 Standard_Boolean SMESH_Block::Values(const math_Vector& theXYZ,
299 math_Vector& theFxyz,
302 // MESSAGE( endl<<"SMESH_Block::Values( "<<theXYZ(1)<<", "<<theXYZ(2)<<", "<<theXYZ(3)<<")");
304 gp_XYZ P, params( theXYZ(1), theXYZ(2), theXYZ(3) );
305 if ( params.IsEqual( myParam, DBL_MIN )) { // same param
306 theFxyz( 1 ) = myValues[ 0 ];
307 theDf( 1,1 ) = myValues[ 1 ];
308 theDf( 1,2 ) = myValues[ 2 ];
309 theDf( 1,3 ) = myValues[ 3 ];
313 ShellPoint( params, P );
314 //myNbIterations++; // how many time call ShellPoint()
316 gp_Vec dP( P - myPoint );
317 theFxyz(1) = SQRT_FUNC ? dP.SquareMagnitude() : dP.Magnitude();
318 if ( theFxyz(1) < 1e-6 ) {
327 if ( theFxyz(1) < myValues[0] ) // a better guess
329 // 3 partial derivatives
331 for ( int iP = 1; iP <= 3; iP++ ) {
333 params.SetCoord( iP, theXYZ( iP ) + 0.001 );
334 ShellPoint( params, Pi );
335 params.SetCoord( iP, theXYZ( iP ) ); // restore params
336 gp_Vec dPi ( P, Pi );
337 double mag = dPi.Magnitude();
342 for ( int iP = 0; iP < 3; iP++ ) {
343 if ( iP == myFaceIndex )
344 theDf( 1, iP + 1 ) = myFaceParam;
346 // like IntAna_IntConicQuad::Perform (const gp_Lin& L, const gp_Pln& P)
347 // where L is (P -> myPoint), P is defined by the 2 other derivative direction
348 int iPrev = ( iP ? iP - 1 : 2 );
349 int iNext = ( iP == 2 ? 0 : iP + 1 );
350 gp_Vec plnNorm = drv[ iPrev ].Crossed( drv [ iNext ] );
351 double Direc = plnNorm * drv[ iP ];
352 if ( Abs(Direc) <= DBL_MIN )
353 theDf( 1, iP + 1 ) = dP * drv[ iP ];
355 double Dis = plnNorm * P - plnNorm * myPoint;
356 theDf( 1, iP + 1 ) = Dis/Direc;
360 //myNbIterations +=3; // how many time call ShellPoint()
362 // store better values
364 myValues[0]= theFxyz(1);
365 myValues[1]= theDf(1,1);
366 myValues[2]= theDf(1,2);
367 myValues[3]= theDf(1,3);
369 // SCRUTE( theFxyz(1) );
370 // SCRUTE( theDf( 1,1 ));
371 // SCRUTE( theDf( 1,2 ));
372 // SCRUTE( theDf( 1,3 ));
378 //=======================================================================
379 //function : ComputeParameters
380 //purpose : compute point parameters in the block
381 //=======================================================================
383 bool SMESH_Block::ComputeParameters(const gp_Pnt& thePoint,
385 const int theShapeID)
387 if ( VertexParameters( theShapeID, theParams ))
390 if ( IsEdgeID( theShapeID )) {
391 TEdge& e = myEdge[ theShapeID - ID_Ex00 ];
392 GeomAdaptor_Curve curve( e.myC3d );
393 double f = Min( e.myFirst, e.myLast ), l = Max( e.myFirst, e.myLast );
394 Extrema_ExtPC anExtPC( thePoint, curve, f, l );
395 int i, nb = anExtPC.IsDone() ? anExtPC.NbExt() : 0;
396 for ( i = 1; i <= nb; i++ ) {
397 if ( anExtPC.IsMin( i ))
398 return EdgeParameters( theShapeID, anExtPC.Point( i ).Parameter(), theParams );
403 // MESSAGE( endl<<"SMESH_Block::ComputeParameters( "
404 // <<thePoint.X()<<", "<<thePoint.Y()<<", "<<thePoint.Z()<<")");
405 myPoint = thePoint.XYZ();
407 myParam.SetCoord( -1,-1,-1 );
410 const bool isOnFace = IsFaceID( theShapeID );
411 double * coef = GetShapeCoef( theShapeID );
414 math_Vector start( 1, 3, 0.0 );
415 if ( !myGridComputed )
417 // define the first guess by thePoint projection on lines
418 // connecting vertices
419 bool needGrid = false;
420 gp_XYZ par000( 0, 0, 0 ), par111( 1, 1, 1 );
421 double zero = DBL_MIN * DBL_MIN;
422 for ( int iEdge = 0, iParam = 1; iParam <= 3 && !needGrid; iParam++ )
424 if ( isOnFace && coef[ iParam - 1 ] != 0 ) {
428 for ( int iE = 0; iE < 4; iE++, iEdge++ ) { // loop on 4 parallel edges
429 gp_Pnt p0 = myEdge[ iEdge ].Point( par000 );
430 gp_Pnt p1 = myEdge[ iEdge ].Point( par111 );
431 gp_Vec v01( p0, p1 ), v0P( p0, thePoint );
432 double len2 = v01.SquareMagnitude();
435 par = v0P.Dot( v01 ) / len2;
436 if ( par < 0 || par > 1 ) {
441 start( iParam ) += par;
443 start( iParam ) /= 4.;
446 // compute nodes of 3 x 3 x 3 grid
448 for ( double x = 0.25; x < 0.9; x += 0.25 )
449 for ( double y = 0.25; y < 0.9; y += 0.25 )
450 for ( double z = 0.25; z < 0.9; z += 0.25 ) {
451 TxyzPair & prmPtn = my3x3x3GridNodes[ iNode++ ];
452 prmPtn.first.SetCoord( x, y, z );
453 ShellPoint( prmPtn.first, prmPtn.second );
455 myGridComputed = true;
458 if ( myGridComputed ) {
459 double minDist = DBL_MAX;
460 gp_XYZ* bestParam = 0;
461 for ( int iNode = 0; iNode < 27; iNode++ ) {
462 TxyzPair & prmPtn = my3x3x3GridNodes[ iNode ];
463 double dist = ( thePoint.XYZ() - prmPtn.second ).SquareModulus();
464 if ( dist < minDist ) {
466 bestParam = & prmPtn.first;
469 start( 1 ) = bestParam->X();
470 start( 2 ) = bestParam->Y();
471 start( 3 ) = bestParam->Z();
474 int myFaceIndex = -1;
476 // put a point on the face
477 for ( int iCoord = 0; iCoord < 3; iCoord++ )
478 if ( coef[ iCoord ] ) {
479 myFaceIndex = iCoord;
480 myFaceParam = ( coef[ myFaceIndex ] < 0.5 ) ? 0.0 : 1.0;
481 start( iCoord + 1 ) = myFaceParam;
484 math_Vector low ( 1, 3, 0.0 );
485 math_Vector up ( 1, 3, 1.0 );
486 math_Vector tol ( 1, 3, 1e-4 );
487 math_FunctionSetRoot paramSearch( *this, tol );
490 while ( myValues[0] > 1e-1 && nbLoops++ < 10 ) {
491 paramSearch.Perform ( *this, start, low, up );
492 if ( !paramSearch.IsDone() ) {
493 //MESSAGE( " !paramSearch.IsDone() " );
496 //MESSAGE( " NB ITERATIONS: " << paramSearch.NbIterations() );
498 start( 1 ) = myParam.X();
499 start( 2 ) = myParam.Y();
500 start( 3 ) = myParam.Z();
501 //MESSAGE( "Distance: " << ( SQRT_FUNC ? sqrt(myValues[0]) : myValues[0] ));
503 // MESSAGE( endl << myParam.X() << " " << myParam.Y() << " " << myParam.Z() << endl);
504 // mySumDist += myValues[0];
505 // MESSAGE( " TOTAL NB ITERATIONS: " << myNbIterations <<
506 // " DIST: " << ( SQRT_FUNC ? sqrt(mySumDist) : mySumDist ));
514 //=======================================================================
515 //function : VertexParameters
516 //purpose : return parameters of a vertex given by TShapeID
517 //=======================================================================
519 bool SMESH_Block::VertexParameters(const int theVertexID, gp_XYZ& theParams)
521 switch ( theVertexID ) {
522 case ID_V000: theParams.SetCoord(0., 0., 0.); return true;
523 case ID_V100: theParams.SetCoord(1., 0., 0.); return true;
524 case ID_V110: theParams.SetCoord(1., 1., 0.); return true;
525 case ID_V010: theParams.SetCoord(0., 1., 0.); return true;
531 //=======================================================================
532 //function : EdgeParameters
533 //purpose : return parameters of a point given by theU on edge
534 //=======================================================================
536 bool SMESH_Block::EdgeParameters(const int theEdgeID, const double theU, gp_XYZ& theParams)
538 if ( IsEdgeID( theEdgeID )) {
539 vector< int > vertexVec;
540 GetEdgeVertexIDs( theEdgeID, vertexVec );
541 VertexParameters( vertexVec[0], theParams );
542 TEdge& e = myEdge[ theEdgeID - ID_Ex00 ];
543 double param = ( theU - e.myFirst ) / ( e.myLast - e.myFirst );
544 theParams.SetCoord( e.myCoordInd, param );
550 //=======================================================================
551 //function : GetStateNumber
553 //=======================================================================
555 Standard_Integer SMESH_Block::GetStateNumber ()
557 // MESSAGE( endl<<"SMESH_Block::GetStateNumber( "<<myParam.X()<<", "<<
558 // myParam.Y()<<", "<<myParam.Z()<<") DISTANCE: " << myValues[0]);
559 return myValues[0] < 1e-1;
562 //=======================================================================
563 //function : DumpShapeID
564 //purpose : debug an id of a block sub-shape
565 //=======================================================================
567 #define CASEDUMP(id,strm) case id: strm << #id; break;
569 ostream& SMESH_Block::DumpShapeID (const int id, ostream& stream)
572 CASEDUMP( ID_V000, stream );
573 CASEDUMP( ID_V100, stream );
574 CASEDUMP( ID_V010, stream );
575 CASEDUMP( ID_V110, stream );
576 CASEDUMP( ID_V001, stream );
577 CASEDUMP( ID_V101, stream );
578 CASEDUMP( ID_V011, stream );
579 CASEDUMP( ID_V111, stream );
580 CASEDUMP( ID_Ex00, stream );
581 CASEDUMP( ID_Ex10, stream );
582 CASEDUMP( ID_Ex01, stream );
583 CASEDUMP( ID_Ex11, stream );
584 CASEDUMP( ID_E0y0, stream );
585 CASEDUMP( ID_E1y0, stream );
586 CASEDUMP( ID_E0y1, stream );
587 CASEDUMP( ID_E1y1, stream );
588 CASEDUMP( ID_E00z, stream );
589 CASEDUMP( ID_E10z, stream );
590 CASEDUMP( ID_E01z, stream );
591 CASEDUMP( ID_E11z, stream );
592 CASEDUMP( ID_Fxy0, stream );
593 CASEDUMP( ID_Fxy1, stream );
594 CASEDUMP( ID_Fx0z, stream );
595 CASEDUMP( ID_Fx1z, stream );
596 CASEDUMP( ID_F0yz, stream );
597 CASEDUMP( ID_F1yz, stream );
598 CASEDUMP( ID_Shell, stream );
599 default: stream << "ID_INVALID";
604 //=======================================================================
605 //function : GetShapeIDByParams
606 //purpose : define an id of the block sub-shape by normlized point coord
607 //=======================================================================
609 int SMESH_Block::GetShapeIDByParams ( const gp_XYZ& theCoord )
611 // id ( 0 - 26 ) computation:
613 // vertex ( 0 - 7 ) : id = 1*x + 2*y + 4*z
615 // edge || X ( 8 - 11 ) : id = 8 + 1*y + 2*z
616 // edge || Y ( 12 - 15 ): id = 1*x + 12 + 2*z
617 // edge || Z ( 16 - 19 ): id = 1*x + 2*y + 16
619 // face || XY ( 20 - 21 ): id = 8 + 12 + 1*z - 0
620 // face || XZ ( 22 - 23 ): id = 8 + 1*y + 16 - 2
621 // face || YZ ( 24 - 25 ): id = 1*x + 12 + 16 - 4
623 static int iAddBnd[] = { 1, 2, 4 };
624 static int iAddNotBnd[] = { 8, 12, 16 };
625 static int iFaceSubst[] = { 0, 2, 4 };
629 for ( int iCoord = 0; iCoord < 3; iCoord++ )
631 double val = theCoord.Coord( iCoord + 1 );
634 else if ( val == 1.0 )
635 id += iAddBnd[ iOnBoundary++ ];
637 id += iAddNotBnd[ iCoord ];
639 if ( iOnBoundary == 1 ) // face
640 id -= iFaceSubst[ (id - 20) / 4 ];
641 else if ( iOnBoundary == 0 ) // shell
644 if ( id > 26 || id < 0 ) {
645 MESSAGE( "GetShapeIDByParams() = " << id
646 <<" "<< theCoord.X() <<" "<< theCoord.Y() <<" "<< theCoord.Z() );
649 return id + 1; // shape ids start at 1
653 //=======================================================================
654 //function : getOrderedEdges
655 //purpose : return nb wires and a list of oredered edges
656 //=======================================================================
658 static int getOrderedEdges (const TopoDS_Face& theFace,
659 const TopoDS_Vertex& theFirstVertex,
660 list< TopoDS_Edge >& theEdges,
661 list< int > & theNbVertexInWires)
663 // put wires in a list, so that an outer wire comes first
664 list<TopoDS_Wire> aWireList;
665 TopoDS_Wire anOuterWire = BRepTools::OuterWire( theFace );
666 aWireList.push_back( anOuterWire );
667 for ( TopoDS_Iterator wIt (theFace); wIt.More(); wIt.Next() )
668 if ( !anOuterWire.IsSame( wIt.Value() ))
669 aWireList.push_back( TopoDS::Wire( wIt.Value() ));
671 // loop on edges of wires
672 theNbVertexInWires.clear();
673 list<TopoDS_Wire>::iterator wlIt = aWireList.begin();
674 for ( ; wlIt != aWireList.end(); wlIt++ )
677 BRepTools_WireExplorer wExp( *wlIt, theFace );
678 for ( iE = 0; wExp.More(); wExp.Next(), iE++ )
680 TopoDS_Edge edge = wExp.Current();
681 edge = TopoDS::Edge( edge.Oriented( wExp.Orientation() ));
682 theEdges.push_back( edge );
684 theNbVertexInWires.push_back( iE );
686 if ( wlIt == aWireList.begin() && theEdges.size() > 1 ) { // the outer wire
687 // orient closed edges
688 list< TopoDS_Edge >::iterator eIt, eIt2;
689 for ( eIt = theEdges.begin(); eIt != theEdges.end(); eIt++ )
691 TopoDS_Edge& edge = *eIt;
692 if ( TopExp::FirstVertex( edge ).IsSame( TopExp::LastVertex( edge ) ))
695 bool isNext = ( eIt2 == theEdges.begin() );
696 TopoDS_Edge edge2 = isNext ? *(++eIt2) : *(--eIt2);
698 Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( edge, theFace, f1,l1 );
699 Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( edge2, theFace, f2,l2 );
700 gp_Pnt2d pf = c1->Value( edge.Orientation() == TopAbs_FORWARD ? f1 : l1 );
701 gp_Pnt2d pl = c1->Value( edge.Orientation() == TopAbs_FORWARD ? l1 : f1 );
702 bool isFirst = ( edge2.Orientation() == TopAbs_FORWARD ? isNext : !isNext );
703 gp_Pnt2d p2 = c2->Value( isFirst ? f2 : l2 );
704 isFirst = ( p2.SquareDistance( pf ) < p2.SquareDistance( pl ));
705 if ( isNext ? isFirst : !isFirst )
709 // rotate theEdges until it begins from theFirstVertex
710 if ( ! theFirstVertex.IsNull() )
711 while ( !theFirstVertex.IsSame( TopExp::FirstVertex( theEdges.front(), true )))
713 theEdges.splice(theEdges.end(), theEdges,
714 theEdges.begin(), ++ theEdges.begin());
715 if ( iE++ > theNbVertexInWires.back() )
716 break; // break infinite loop
721 return aWireList.size();
724 //=======================================================================
725 //function : LoadMeshBlock
726 //purpose : prepare to work with theVolume
727 //=======================================================================
729 #define gpXYZ(n) gp_XYZ(n->X(),n->Y(),n->Z())
731 bool SMESH_Block::LoadMeshBlock(const SMDS_MeshVolume* theVolume,
732 const int theNode000Index,
733 const int theNode001Index,
734 vector<const SMDS_MeshNode*>& theOrderedNodes)
736 MESSAGE(" ::LoadMeshBlock()");
740 myGridComputed = false;
742 SMDS_VolumeTool vTool;
743 if (!vTool.Set( theVolume ) || vTool.NbNodes() != 8 ||
744 !vTool.IsLinked( theNode000Index, theNode001Index )) {
745 MESSAGE(" Bad arguments ");
748 vTool.SetExternalNormal();
749 // In terms of indices used for access to nodes and faces in SMDS_VolumeTool:
750 int V000, V100, V010, V110, V001, V101, V011, V111; // 8 vertices
751 int Fxy0, Fxy1; // bottom and top faces
753 vector<int> vFxy0, vFxy1;
755 V000 = theNode000Index;
756 V001 = theNode001Index;
758 // get faces sharing V000 and V001
759 list<int> fV000, fV001;
761 for ( iF = 0; iF < vTool.NbFaces(); ++iF ) {
762 const int* nid = vTool.GetFaceNodesIndices( iF );
763 for ( iN = 0; iN < 4; ++iN )
764 if ( nid[ iN ] == V000 ) {
765 fV000.push_back( iF );
766 } else if ( nid[ iN ] == V001 ) {
767 fV001.push_back( iF );
771 // find the bottom (Fxy0), the top (Fxy1) faces
772 list<int>::iterator fIt1, fIt2, Fxy0Pos;
773 for ( fIt1 = fV000.begin(); fIt1 != fV000.end(); fIt1++) {
774 fIt2 = std::find( fV001.begin(), fV001.end(), *fIt1 );
775 if ( fIt2 != fV001.end() ) { // *fIt1 is in the both lists
776 fV001.erase( fIt2 ); // erase Fx0z or F0yz from fV001
777 } else { // *fIt1 is in fV000 only
778 Fxy0Pos = fIt1; // points to Fxy0
782 Fxy1 = fV001.front();
783 const SMDS_MeshNode** nn = vTool.GetNodes();
785 // find bottom veritices, their order is that a face normal is external
787 const int* nid = vTool.GetFaceNodesIndices( Fxy0 );
788 for ( i = 0; i < 4; ++i )
789 if ( nid[ i ] == V000 )
791 for ( iN = 0; iN < 4; ++iN, ++i ) {
793 vFxy0[ iN ] = nid[ i ];
795 // find top veritices, their order is that a face normal is external
797 nid = vTool.GetFaceNodesIndices( Fxy1 );
798 for ( i = 0; i < 4; ++i )
799 if ( nid[ i ] == V001 )
801 for ( iN = 0; iN < 4; ++iN, ++i ) {
803 vFxy1[ iN ] = nid[ i ];
805 // find indices of the rest veritices
813 // set points coordinates
814 myPnt[ ID_V000 - 1 ] = gpXYZ( nn[ V000 ] );
815 myPnt[ ID_V100 - 1 ] = gpXYZ( nn[ V100 ] );
816 myPnt[ ID_V010 - 1 ] = gpXYZ( nn[ V010 ] );
817 myPnt[ ID_V110 - 1 ] = gpXYZ( nn[ V110 ] );
818 myPnt[ ID_V001 - 1 ] = gpXYZ( nn[ V001 ] );
819 myPnt[ ID_V101 - 1 ] = gpXYZ( nn[ V101 ] );
820 myPnt[ ID_V011 - 1 ] = gpXYZ( nn[ V011 ] );
821 myPnt[ ID_V111 - 1 ] = gpXYZ( nn[ V111 ] );
823 // fill theOrderedNodes
824 theOrderedNodes.resize( 8 );
825 theOrderedNodes[ 0 ] = nn[ V000 ];
826 theOrderedNodes[ 1 ] = nn[ V100 ];
827 theOrderedNodes[ 2 ] = nn[ V010 ];
828 theOrderedNodes[ 3 ] = nn[ V110 ];
829 theOrderedNodes[ 4 ] = nn[ V001 ];
830 theOrderedNodes[ 5 ] = nn[ V101 ];
831 theOrderedNodes[ 6 ] = nn[ V011 ];
832 theOrderedNodes[ 7 ] = nn[ V111 ];
835 myEdge[ ID_Ex00 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ];
836 myEdge[ ID_Ex00 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V100 - 1 ];
838 myEdge[ ID_Ex10 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V010 - 1 ];
839 myEdge[ ID_Ex10 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V110 - 1 ];
841 myEdge[ ID_Ex01 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V001 - 1 ];
842 myEdge[ ID_Ex01 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V101 - 1 ];
844 myEdge[ ID_Ex11 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V011 - 1 ];
845 myEdge[ ID_Ex11 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ];
847 myEdge[ ID_E0y0 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ];
848 myEdge[ ID_E0y0 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V010 - 1 ];
850 myEdge[ ID_E1y0 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V100 - 1 ];
851 myEdge[ ID_E1y0 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V110 - 1 ];
853 myEdge[ ID_E0y1 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V001 - 1 ];
854 myEdge[ ID_E0y1 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V011 - 1 ];
856 myEdge[ ID_E1y1 - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V101 - 1 ];
857 myEdge[ ID_E1y1 - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ];
859 myEdge[ ID_E00z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V000 - 1 ];
860 myEdge[ ID_E00z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V001 - 1 ];
862 myEdge[ ID_E10z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V100 - 1 ];
863 myEdge[ ID_E10z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V101 - 1 ];
865 myEdge[ ID_E01z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V010 - 1 ];
866 myEdge[ ID_E01z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V011 - 1 ];
868 myEdge[ ID_E11z - ID_Ex00 ].myNodes[ 0 ] = myPnt[ ID_V110 - 1 ];
869 myEdge[ ID_E11z - ID_Ex00 ].myNodes[ 1 ] = myPnt[ ID_V111 - 1 ];
871 for ( iE = ID_Ex00; iE <= ID_E11z; ++iE )
872 myEdge[ iE - ID_Ex00 ].myCoordInd = GetCoordIndOnEdge( iE );
874 // fill faces corners
875 for ( iF = ID_Fxy0; iF < ID_Shell; ++iF )
877 TFace& tFace = myFace[ iF - ID_Fxy0 ];
878 vector< int > edgeIdVec(4, -1);
879 GetFaceEdgesIDs( iF, edgeIdVec );
880 tFace.myNodes[ 0 ] = myEdge[ edgeIdVec [ 0 ] - ID_Ex00 ].myNodes[ 1 ];
881 tFace.myNodes[ 1 ] = myEdge[ edgeIdVec [ 0 ] - ID_Ex00 ].myNodes[ 0 ];
882 tFace.myNodes[ 2 ] = myEdge[ edgeIdVec [ 1 ] - ID_Ex00 ].myNodes[ 0 ];
883 tFace.myNodes[ 3 ] = myEdge[ edgeIdVec [ 1 ] - ID_Ex00 ].myNodes[ 1 ];
884 tFace.myCoordInd[ 0 ] = GetCoordIndOnEdge( edgeIdVec[ 0 ] );
885 tFace.myCoordInd[ 1 ] = GetCoordIndOnEdge( edgeIdVec[ 1 ] );
886 tFace.myCoordInd[ 2 ] = GetCoordIndOnEdge( edgeIdVec[ 2 ] );
887 tFace.myCoordInd[ 3 ] = GetCoordIndOnEdge( edgeIdVec[ 3 ] );
893 //=======================================================================
894 //function : LoadBlockShapes
895 //purpose : add sub-shapes of theBlock to theShapeIDMap so that they get
896 // IDs acoording to enum TShapeID
897 //=======================================================================
899 bool SMESH_Block::LoadBlockShapes(const TopoDS_Shell& theShell,
900 const TopoDS_Vertex& theVertex000,
901 const TopoDS_Vertex& theVertex001,
902 TopTools_IndexedMapOfOrientedShape& theShapeIDMap )
904 MESSAGE(" ::LoadBlockShapes()");
909 myGridComputed = false;
912 TopoDS_Shape V000, V100, V010, V110, V001, V101, V011, V111;
914 TopoDS_Shape Ex00, Ex10, Ex01, Ex11;
915 TopoDS_Shape E0y0, E1y0, E0y1, E1y1;
916 TopoDS_Shape E00z, E10z, E01z, E11z;
918 TopoDS_Shape Fxy0, Fx0z, F0yz, Fxy1, Fx1z, F1yz;
920 // nb of faces bound to a vertex in TopTools_IndexedDataMapOfShapeListOfShape
921 // filled by TopExp::MapShapesAndAncestors()
922 const int NB_FACES_BY_VERTEX = 6;
924 TopTools_IndexedDataMapOfShapeListOfShape vfMap;
925 TopExp::MapShapesAndAncestors( myShell, TopAbs_VERTEX, TopAbs_FACE, vfMap );
926 if ( vfMap.Extent() != 8 ) {
927 MESSAGE(" Wrong nb of vertices in the block: " << vfMap.Extent() );
934 if ( V000.IsNull() ) {
935 // find vertex 000 - the one with smallest coordinates
936 double minVal = DBL_MAX, minX, val;
937 for ( int i = 1; i <= 8; i++ ) {
938 const TopoDS_Vertex& v = TopoDS::Vertex( vfMap.FindKey( i ));
939 gp_Pnt P = BRep_Tool::Pnt( v );
940 val = P.X() + P.Y() + P.Z();
941 if ( val < minVal || ( val == minVal && P.X() < minX )) {
947 // find vertex 001 - the one on the most vertical edge passing through V000
948 TopTools_IndexedDataMapOfShapeListOfShape veMap;
949 TopExp::MapShapesAndAncestors( myShell, TopAbs_VERTEX, TopAbs_EDGE, veMap );
950 gp_Vec dir001 = gp::DZ();
951 gp_Pnt p000 = BRep_Tool::Pnt( TopoDS::Vertex( V000 ));
952 double maxVal = -DBL_MAX;
953 TopTools_ListIteratorOfListOfShape eIt ( veMap.FindFromKey( V000 ));
954 for ( ; eIt.More(); eIt.Next() ) {
955 const TopoDS_Edge& e = TopoDS::Edge( eIt.Value() );
956 TopoDS_Vertex v = TopExp::FirstVertex( e );
957 if ( v.IsSame( V000 ))
958 v = TopExp::LastVertex( e );
959 val = dir001 * gp_Vec( p000, BRep_Tool::Pnt( v )).Normalized();
960 if ( val > maxVal ) {
967 // find the bottom (Fxy0), Fx0z and F0yz faces
969 const TopTools_ListOfShape& f000List = vfMap.FindFromKey( V000 );
970 const TopTools_ListOfShape& f001List = vfMap.FindFromKey( V001 );
971 if (f000List.Extent() != NB_FACES_BY_VERTEX ||
972 f001List.Extent() != NB_FACES_BY_VERTEX ) {
973 MESSAGE(" LoadBlockShapes() " << f000List.Extent() << " " << f001List.Extent());
976 TopTools_ListIteratorOfListOfShape f001It, f000It ( f000List );
977 int i, j, iFound1, iFound2;
978 for ( j = 0; f000It.More(); f000It.Next(), j++ )
980 if ( NB_FACES_BY_VERTEX == 6 && j % 2 ) continue; // each face encounters twice
981 const TopoDS_Shape& F = f000It.Value();
982 for ( i = 0, f001It.Initialize( f001List ); f001It.More(); f001It.Next(), i++ ) {
983 if ( NB_FACES_BY_VERTEX == 6 && i % 2 ) continue; // each face encounters twice
984 if ( F.IsSame( f001It.Value() ))
987 if ( f001It.More() ) // Fx0z or F0yz found
988 if ( Fx0z.IsNull() ) {
995 else // F is the bottom face
998 if ( Fxy0.IsNull() || Fx0z.IsNull() || F0yz.IsNull() ) {
999 MESSAGE( Fxy0.IsNull() <<" "<< Fx0z.IsNull() <<" "<< F0yz.IsNull() );
1003 // choose the top face (Fxy1)
1004 for ( i = 0, f001It.Initialize( f001List ); f001It.More(); f001It.Next(), i++ ) {
1005 if ( NB_FACES_BY_VERTEX == 6 && i % 2 ) continue; // each face encounters twice
1006 if ( i != iFound1 && i != iFound2 )
1009 Fxy1 = f001It.Value();
1010 if ( Fxy1.IsNull() ) {
1011 MESSAGE(" LoadBlockShapes() error ");
1015 // find bottom edges and veritices
1016 list< TopoDS_Edge > eList;
1017 list< int > nbVertexInWires;
1018 getOrderedEdges( TopoDS::Face( Fxy0 ), TopoDS::Vertex( V000 ), eList, nbVertexInWires );
1019 if ( nbVertexInWires.size() != 1 || nbVertexInWires.front() != 4 ) {
1020 MESSAGE(" LoadBlockShapes() error ");
1023 list< TopoDS_Edge >::iterator elIt = eList.begin();
1024 for ( i = 0; elIt != eList.end(); elIt++, i++ )
1026 case 0: E0y0 = *elIt; V010 = TopExp::LastVertex( *elIt, true ); break;
1027 case 1: Ex10 = *elIt; V110 = TopExp::LastVertex( *elIt, true ); break;
1028 case 2: E1y0 = *elIt; V100 = TopExp::LastVertex( *elIt, true ); break;
1029 case 3: Ex00 = *elIt; break;
1032 if ( i != 4 || E0y0.IsNull() || Ex10.IsNull() || E1y0.IsNull() || Ex00.IsNull() ) {
1033 MESSAGE(" LoadBlockShapes() error, eList.size()=" << eList.size());
1038 // find top edges and veritices
1040 getOrderedEdges( TopoDS::Face( Fxy1 ), TopoDS::Vertex( V001 ), eList, nbVertexInWires );
1041 if ( nbVertexInWires.size() != 1 || nbVertexInWires.front() != 4 ) {
1042 MESSAGE(" LoadBlockShapes() error ");
1045 for ( i = 0, elIt = eList.begin(); elIt != eList.end(); elIt++, i++ )
1047 case 0: Ex01 = *elIt; V101 = TopExp::LastVertex( *elIt, true ); break;
1048 case 1: E1y1 = *elIt; V111 = TopExp::LastVertex( *elIt, true ); break;
1049 case 2: Ex11 = *elIt; V011 = TopExp::LastVertex( *elIt, true ); break;
1050 case 3: E0y1 = *elIt; break;
1053 if ( i != 4 || Ex01.IsNull() || E1y1.IsNull() || Ex11.IsNull() || E0y1.IsNull() ) {
1054 MESSAGE(" LoadBlockShapes() error, eList.size()=" << eList.size());
1058 // swap Fx0z and F0yz if necessary
1059 TopExp_Explorer exp( Fx0z, TopAbs_VERTEX );
1060 for ( ; exp.More(); exp.Next() ) // Fx0z shares V101 and V100
1061 if ( V101.IsSame( exp.Current() ) || V100.IsSame( exp.Current() ))
1062 break; // V101 or V100 found
1063 if ( !exp.More() ) { // not found
1064 TopoDS_Shape f = Fx0z; Fx0z = F0yz; F0yz = f;
1067 // find Fx1z and F1yz faces
1068 const TopTools_ListOfShape& f111List = vfMap.FindFromKey( V111 );
1069 const TopTools_ListOfShape& f110List = vfMap.FindFromKey( V110 );
1070 if (f111List.Extent() != NB_FACES_BY_VERTEX ||
1071 f110List.Extent() != NB_FACES_BY_VERTEX ) {
1072 MESSAGE(" LoadBlockShapes() " << f111List.Extent() << " " << f110List.Extent());
1075 TopTools_ListIteratorOfListOfShape f111It, f110It ( f110List);
1076 for ( j = 0 ; f110It.More(); f110It.Next(), j++ ) {
1077 if ( NB_FACES_BY_VERTEX == 6 && j % 2 ) continue; // each face encounters twice
1078 const TopoDS_Shape& F = f110It.Value();
1079 for ( i = 0, f111It.Initialize( f111List ); f111It.More(); f111It.Next(), i++ ) {
1080 if ( NB_FACES_BY_VERTEX == 6 && i % 2 ) continue; // each face encounters twice
1081 if ( F.IsSame( f111It.Value() )) { // Fx1z or F1yz found
1082 if ( Fx1z.IsNull() )
1089 if ( Fx1z.IsNull() || F1yz.IsNull() ) {
1090 MESSAGE(" LoadBlockShapes() error ");
1094 // swap Fx1z and F1yz if necessary
1095 for ( exp.Init( Fx1z, TopAbs_VERTEX ); exp.More(); exp.Next() )
1096 if ( V010.IsSame( exp.Current() ) || V011.IsSame( exp.Current() ))
1098 if ( !exp.More() ) {
1099 TopoDS_Shape f = Fx1z; Fx1z = F1yz; F1yz = f;
1102 // find vertical edges
1103 for ( exp.Init( Fx0z, TopAbs_EDGE ); exp.More(); exp.Next() ) {
1104 const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
1105 const TopoDS_Shape& vFirst = TopExp::FirstVertex( edge, true );
1106 if ( vFirst.IsSame( V001 ))
1108 else if ( vFirst.IsSame( V100 ))
1111 if ( E00z.IsNull() || E10z.IsNull() ) {
1112 MESSAGE(" LoadBlockShapes() error ");
1115 for ( exp.Init( Fx1z, TopAbs_EDGE ); exp.More(); exp.Next() ) {
1116 const TopoDS_Edge& edge = TopoDS::Edge( exp.Current() );
1117 const TopoDS_Shape& vFirst = TopExp::FirstVertex( edge, true );
1118 if ( vFirst.IsSame( V111 ))
1120 else if ( vFirst.IsSame( V010 ))
1123 if ( E01z.IsNull() || E11z.IsNull() ) {
1124 MESSAGE(" LoadBlockShapes() error ");
1128 // load shapes in theShapeIDMap
1130 theShapeIDMap.Clear();
1132 theShapeIDMap.Add(V000.Oriented( TopAbs_FORWARD ));
1133 theShapeIDMap.Add(V100.Oriented( TopAbs_FORWARD ));
1134 theShapeIDMap.Add(V010.Oriented( TopAbs_FORWARD ));
1135 theShapeIDMap.Add(V110.Oriented( TopAbs_FORWARD ));
1136 theShapeIDMap.Add(V001.Oriented( TopAbs_FORWARD ));
1137 theShapeIDMap.Add(V101.Oriented( TopAbs_FORWARD ));
1138 theShapeIDMap.Add(V011.Oriented( TopAbs_FORWARD ));
1139 theShapeIDMap.Add(V111.Oriented( TopAbs_FORWARD ));
1141 theShapeIDMap.Add(Ex00);
1142 theShapeIDMap.Add(Ex10);
1143 theShapeIDMap.Add(Ex01);
1144 theShapeIDMap.Add(Ex11);
1146 theShapeIDMap.Add(E0y0);
1147 theShapeIDMap.Add(E1y0);
1148 theShapeIDMap.Add(E0y1);
1149 theShapeIDMap.Add(E1y1);
1151 theShapeIDMap.Add(E00z);
1152 theShapeIDMap.Add(E10z);
1153 theShapeIDMap.Add(E01z);
1154 theShapeIDMap.Add(E11z);
1156 theShapeIDMap.Add(Fxy0);
1157 theShapeIDMap.Add(Fxy1);
1158 theShapeIDMap.Add(Fx0z);
1159 theShapeIDMap.Add(Fx1z);
1160 theShapeIDMap.Add(F0yz);
1161 theShapeIDMap.Add(F1yz);
1163 theShapeIDMap.Add(myShell);
1165 if ( theShapeIDMap.Extent() != 27 ) {
1166 MESSAGE("LoadBlockShapes() " << theShapeIDMap.Extent() );
1170 // store shapes geometry
1171 for ( int shapeID = 1; shapeID < theShapeIDMap.Extent(); shapeID++ )
1173 const TopoDS_Shape& S = theShapeIDMap( shapeID );
1174 switch ( S.ShapeType() )
1176 case TopAbs_VERTEX: {
1178 if ( shapeID > ID_V111 ) {
1179 MESSAGE(" shapeID =" << shapeID );
1182 myPnt[ shapeID - ID_V000 ] =
1183 BRep_Tool::Pnt( TopoDS::Vertex( S )).XYZ();
1188 const TopoDS_Edge& edge = TopoDS::Edge( S );
1189 if ( shapeID < ID_Ex00 || shapeID > ID_E11z || edge.IsNull() ) {
1190 MESSAGE(" shapeID =" << shapeID );
1193 TEdge& tEdge = myEdge[ shapeID - ID_Ex00 ];
1194 tEdge.myCoordInd = GetCoordIndOnEdge( shapeID );
1195 TopLoc_Location loc;
1196 tEdge.myC3d = BRep_Tool::Curve( edge, loc, tEdge.myFirst, tEdge.myLast );
1197 if ( !IsForwardEdge( edge, theShapeIDMap ))
1198 Swap( tEdge.myFirst, tEdge.myLast );
1204 const TopoDS_Face& face = TopoDS::Face( S );
1205 if ( shapeID < ID_Fxy0 || shapeID > ID_F1yz || face.IsNull() ) {
1206 MESSAGE(" shapeID =" << shapeID );
1209 TFace& tFace = myFace[ shapeID - ID_Fxy0 ];
1211 vector< int > edgeIdVec(4, -1);
1212 GetFaceEdgesIDs( shapeID, edgeIdVec );
1213 for ( int iE = 0; iE < 4; iE++ ) // loop on 4 edges
1215 const TopoDS_Edge& edge = TopoDS::Edge( theShapeIDMap( edgeIdVec[ iE ]));
1216 tFace.myCoordInd[ iE ] = GetCoordIndOnEdge( edgeIdVec[ iE ] );
1218 BRep_Tool::CurveOnSurface( edge, face, tFace.myFirst[iE], tFace.myLast[iE] );
1219 if ( !IsForwardEdge( edge, theShapeIDMap ))
1220 Swap( tFace.myFirst[ iE ], tFace.myLast[ iE ] );
1223 tFace.myCorner[ 0 ] = tFace.myC2d[ 0 ]->Value( tFace.myFirst[0] ).XY();
1224 tFace.myCorner[ 1 ] = tFace.myC2d[ 0 ]->Value( tFace.myLast[0] ).XY();
1225 tFace.myCorner[ 2 ] = tFace.myC2d[ 1 ]->Value( tFace.myLast[1] ).XY();
1226 tFace.myCorner[ 3 ] = tFace.myC2d[ 1 ]->Value( tFace.myFirst[1] ).XY();
1228 TopLoc_Location loc;
1229 tFace.myS = BRep_Tool::Surface( face, loc );
1235 } // loop on shapes in theShapeIDMap
1240 //=======================================================================
1241 //function : GetFaceEdgesIDs
1242 //purpose : return edges IDs in the order u0, u1, 0v, 1v
1243 // u0 means "|| u, v == 0"
1244 //=======================================================================
1246 void SMESH_Block::GetFaceEdgesIDs (const int faceID, vector< int >& edgeVec )
1248 edgeVec.resize( 4 );
1251 edgeVec[ 0 ] = ID_Ex00;
1252 edgeVec[ 1 ] = ID_Ex10;
1253 edgeVec[ 2 ] = ID_E0y0;
1254 edgeVec[ 3 ] = ID_E1y0;
1257 edgeVec[ 0 ] = ID_Ex01;
1258 edgeVec[ 1 ] = ID_Ex11;
1259 edgeVec[ 2 ] = ID_E0y1;
1260 edgeVec[ 3 ] = ID_E1y1;
1263 edgeVec[ 0 ] = ID_Ex00;
1264 edgeVec[ 1 ] = ID_Ex01;
1265 edgeVec[ 2 ] = ID_E00z;
1266 edgeVec[ 3 ] = ID_E10z;
1269 edgeVec[ 0 ] = ID_Ex10;
1270 edgeVec[ 1 ] = ID_Ex11;
1271 edgeVec[ 2 ] = ID_E01z;
1272 edgeVec[ 3 ] = ID_E11z;
1275 edgeVec[ 0 ] = ID_E0y0;
1276 edgeVec[ 1 ] = ID_E0y1;
1277 edgeVec[ 2 ] = ID_E00z;
1278 edgeVec[ 3 ] = ID_E01z;
1281 edgeVec[ 0 ] = ID_E1y0;
1282 edgeVec[ 1 ] = ID_E1y1;
1283 edgeVec[ 2 ] = ID_E10z;
1284 edgeVec[ 3 ] = ID_E11z;
1287 MESSAGE(" GetFaceEdgesIDs(), wrong face ID: " << faceID );
1291 //=======================================================================
1292 //function : GetEdgeVertexIDs
1293 //purpose : return vertex IDs of an edge
1294 //=======================================================================
1296 void SMESH_Block::GetEdgeVertexIDs (const int edgeID, vector< int >& vertexVec )
1298 vertexVec.resize( 2 );
1302 vertexVec[ 0 ] = ID_V000;
1303 vertexVec[ 1 ] = ID_V100;
1306 vertexVec[ 0 ] = ID_V010;
1307 vertexVec[ 1 ] = ID_V110;
1310 vertexVec[ 0 ] = ID_V001;
1311 vertexVec[ 1 ] = ID_V101;
1314 vertexVec[ 0 ] = ID_V011;
1315 vertexVec[ 1 ] = ID_V111;
1319 vertexVec[ 0 ] = ID_V000;
1320 vertexVec[ 1 ] = ID_V010;
1323 vertexVec[ 0 ] = ID_V100;
1324 vertexVec[ 1 ] = ID_V110;
1327 vertexVec[ 0 ] = ID_V001;
1328 vertexVec[ 1 ] = ID_V011;
1331 vertexVec[ 0 ] = ID_V101;
1332 vertexVec[ 1 ] = ID_V111;
1336 vertexVec[ 0 ] = ID_V000;
1337 vertexVec[ 1 ] = ID_V001;
1340 vertexVec[ 0 ] = ID_V100;
1341 vertexVec[ 1 ] = ID_V101;
1344 vertexVec[ 0 ] = ID_V010;
1345 vertexVec[ 1 ] = ID_V011;
1348 vertexVec[ 0 ] = ID_V110;
1349 vertexVec[ 1 ] = ID_V111;
1352 MESSAGE(" GetEdgeVertexIDs(), wrong edge ID: " << edgeID );