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_Pattern.hxx"
26 #include <BRepTools.hxx>
27 #include <BRepTools_WireExplorer.hxx>
28 #include <BRep_Tool.hxx>
29 #include <Bnd_Box.hxx>
30 #include <Bnd_Box2d.hxx>
32 #include <Extrema_GenExtPS.hxx>
33 #include <Extrema_POnSurf.hxx>
34 #include <Geom2d_Curve.hxx>
35 #include <GeomAdaptor_Surface.hxx>
36 #include <Geom_Curve.hxx>
37 #include <Geom_Surface.hxx>
38 #include <IntAna2d_AnaIntersection.hxx>
39 #include <TopAbs_ShapeEnum.hxx>
41 #include <TopLoc_Location.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Face.hxx>
45 #include <TopoDS_Iterator.hxx>
46 #include <TopoDS_Shell.hxx>
47 #include <TopoDS_Vertex.hxx>
48 #include <TopoDS_Wire.hxx>
50 #include <gp_Lin2d.hxx>
51 #include <gp_Pnt2d.hxx>
52 #include <gp_Trsf.hxx>
56 #include "SMDS_EdgePosition.hxx"
57 #include "SMDS_FacePosition.hxx"
58 #include "SMDS_MeshElement.hxx"
59 #include "SMDS_MeshFace.hxx"
60 #include "SMDS_MeshNode.hxx"
61 #include "SMDS_VolumeTool.hxx"
62 #include "SMESHDS_Group.hxx"
63 #include "SMESHDS_Mesh.hxx"
64 #include "SMESHDS_SubMesh.hxx"
65 #include "SMESH_Block.hxx"
66 #include "SMESH_Mesh.hxx"
67 #include "SMESH_MeshEditor.hxx"
68 #include "SMESH_subMesh.hxx"
70 #include "utilities.h"
74 typedef map< const SMDS_MeshElement*, int > TNodePointIDMap;
76 //=======================================================================
77 //function : SMESH_Pattern
79 //=======================================================================
81 SMESH_Pattern::SMESH_Pattern ()
84 //=======================================================================
87 //=======================================================================
89 static inline int getInt( const char * theSring )
91 if ( *theSring < '0' || *theSring > '9' )
95 int val = strtol( theSring, &ptr, 10 );
96 if ( ptr == theSring ||
97 // there must not be neither '.' nor ',' nor 'E' ...
98 (*ptr != ' ' && *ptr != '\n' && *ptr != '\0'))
104 //=======================================================================
105 //function : getDouble
107 //=======================================================================
109 static inline double getDouble( const char * theSring )
112 return strtod( theSring, &ptr );
115 //=======================================================================
116 //function : readLine
117 //purpose : Put token starting positions in theFields until '\n' or '\0'
118 // Return the number of the found tokens
119 //=======================================================================
121 static int readLine (list <const char*> & theFields,
122 const char* & theLineBeg,
123 const bool theClearFields )
125 if ( theClearFields )
130 /* switch ( symbol ) { */
131 /* case white-space: */
132 /* look for a non-space symbol; */
133 /* case string-end: */
136 /* case comment beginning: */
137 /* skip all till a line-end; */
139 /* put its position in theFields, skip till a white-space;*/
145 bool stopReading = false;
148 bool isNumber = false;
149 switch ( *theLineBeg )
151 case ' ': // white space
156 case '\n': // a line ends
157 stopReading = ( nbRead > 0 );
162 while ( *theLineBeg != '\n' && *theLineBeg != '\0' );
166 case '\0': // file ends
169 case '-': // real number
174 isNumber = isNumber || ( *theLineBeg >= '0' && *theLineBeg <= '9' );
176 theFields.push_back( theLineBeg );
179 while (*theLineBeg != ' ' &&
180 *theLineBeg != '\n' &&
181 *theLineBeg != '\0');
185 return 0; // incorrect file format
191 } while ( !stopReading );
196 //=======================================================================
198 //purpose : Load a pattern from <theFile>
199 //=======================================================================
201 bool SMESH_Pattern::Load (const char* theFileContents)
203 MESSAGE("Load( file ) ");
207 // ! This is a comment
208 // NB_POINTS ! 1 integer - the number of points in the pattern.
209 // X1 Y1 [Z1] ! 2 or 3 reals - nodes coordinates within 2D or 3D domain:
210 // X2 Y2 [Z2] ! the pattern dimention is defined by the number of coordinates
212 // [ ID1 ID2 ... IDn ] ! Indices of key-points for a 2D pattern (only).
213 // ! elements description goes after all
214 // ID1 ID2 ... IDn ! 2-4 or 4-8 integers - nodal connectivity of a 2D or 3D element.
219 const char* lineBeg = theFileContents;
220 list <const char*> fields;
221 const bool clearFields = true;
223 // NB_POINTS ! 1 integer - the number of points in the pattern.
225 if ( readLine( fields, lineBeg, clearFields ) != 1 ) {
226 MESSAGE("Error reading NB_POINTS");
227 return setErrorCode( ERR_READ_NB_POINTS );
229 int nbPoints = getInt( fields.front() );
231 // X1 Y1 [Z1] ! 2 or 3 reals - nodes coordinates within 2D or 3D domain:
233 // read the first point coordinates to define pattern dimention
234 int dim = readLine( fields, lineBeg, clearFields );
240 MESSAGE("Error reading points: wrong nb of coordinates");
241 return setErrorCode( ERR_READ_POINT_COORDS );
243 if ( nbPoints <= dim ) {
244 MESSAGE(" Too few points ");
245 return setErrorCode( ERR_READ_TOO_FEW_POINTS );
248 // read the rest points
250 for ( iPoint = 1; iPoint < nbPoints; iPoint++ )
251 if ( readLine( fields, lineBeg, !clearFields ) != dim ) {
252 MESSAGE("Error reading points : wrong nb of coordinates ");
253 return setErrorCode( ERR_READ_POINT_COORDS );
255 // store point coordinates
256 myPoints.resize( nbPoints );
257 list <const char*>::iterator fIt = fields.begin();
258 for ( iPoint = 0; iPoint < nbPoints; iPoint++ )
260 TPoint & p = myPoints[ iPoint ];
261 for ( int iCoord = 1; iCoord <= dim; iCoord++, fIt++ )
263 double coord = getDouble( *fIt );
264 if ( !myIs2D && ( coord < 0.0 || coord > 1.0 )) {
265 MESSAGE("Error reading 3D points, value should be in [0,1]: " << coord);
267 return setErrorCode( ERR_READ_3D_COORD );
269 p.myInitXYZ.SetCoord( iCoord, coord );
271 p.myInitUV.SetCoord( iCoord, coord );
275 // [ ID1 ID2 ... IDn ] ! Indices of key-points for a 2D pattern (only).
278 if ( readLine( fields, lineBeg, clearFields ) == 0 ) {
279 MESSAGE("Error: missing key-points");
281 return setErrorCode( ERR_READ_NO_KEYPOINT );
284 for ( fIt = fields.begin(); fIt != fields.end(); fIt++ )
286 int pointIndex = getInt( *fIt );
287 if ( pointIndex >= nbPoints || pointIndex < 0 ) {
288 MESSAGE("Error: invalid point index " << pointIndex );
290 return setErrorCode( ERR_READ_BAD_INDEX );
292 if ( idSet.insert( pointIndex ).second ) // unique?
293 myKeyPointIDs.push_back( pointIndex );
297 // ID1 ID2 ... IDn ! 2-4 or 4-8 integers - nodal connectivity of a 2D or 3D element.
299 while ( readLine( fields, lineBeg, clearFields ))
301 myElemPointIDs.push_back( TElemDef() );
302 TElemDef& elemPoints = myElemPointIDs.back();
303 for ( fIt = fields.begin(); fIt != fields.end(); fIt++ )
305 int pointIndex = getInt( *fIt );
306 if ( pointIndex >= nbPoints || pointIndex < 0 ) {
307 MESSAGE("Error: invalid point index " << pointIndex );
309 return setErrorCode( ERR_READ_BAD_INDEX );
311 elemPoints.push_back( pointIndex );
313 // check the nb of nodes in element
315 switch ( elemPoints.size() ) {
316 case 3: if ( !myIs2D ) Ok = false; break;
320 case 8: if ( myIs2D ) Ok = false; break;
324 MESSAGE("Error: wrong nb of nodes in element " << elemPoints.size() );
326 return setErrorCode( ERR_READ_ELEM_POINTS );
329 if ( myElemPointIDs.empty() ) {
330 MESSAGE("Error: no elements");
332 return setErrorCode( ERR_READ_NO_ELEMS );
335 findBoundaryPoints(); // sort key-points
337 return setErrorCode( ERR_OK );
340 //=======================================================================
342 //purpose : Save the loaded pattern into the file <theFileName>
343 //=======================================================================
345 bool SMESH_Pattern::Save (ostream& theFile)
347 MESSAGE(" ::Save(file) " );
349 MESSAGE(" Pattern not loaded ");
350 return setErrorCode( ERR_SAVE_NOT_LOADED );
353 theFile << "!!! SALOME Mesh Pattern file" << endl;
354 theFile << "!!!" << endl;
355 theFile << "!!! Nb of points:" << endl;
356 theFile << myPoints.size() << endl;
360 // theFile.width( 8 );
361 // theFile.setf(ios::fixed);// use 123.45 floating notation
362 // theFile.setf(ios::right);
363 // theFile.flags( theFile.flags() & ~ios::showpoint); // do not show trailing zeros
364 // theFile.setf(ios::showpoint); // do not show trailing zeros
365 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
366 for ( int i = 0; pVecIt != myPoints.end(); pVecIt++, i++ ) {
367 const gp_XYZ & xyz = (*pVecIt).myInitXYZ;
368 theFile << " " << setw( width ) << xyz.X() << " " << setw( width ) << xyz.Y();
369 if ( !myIs2D ) theFile << " " << setw( width ) << xyz.Z();
370 theFile << " !- " << i << endl; // point id to ease reading by a human being
374 theFile << "!!! Indices of " << myKeyPointIDs.size() << " key-points:" << endl;
375 list< int >::const_iterator kpIt = myKeyPointIDs.begin();
376 for ( ; kpIt != myKeyPointIDs.end(); kpIt++ )
377 theFile << " " << *kpIt;
378 if ( !myKeyPointIDs.empty() )
382 theFile << "!!! Indices of points of " << myElemPointIDs.size() << " elements:" << endl;
383 list<TElemDef >::const_iterator epIt = myElemPointIDs.begin();
384 for ( ; epIt != myElemPointIDs.end(); epIt++ )
386 const TElemDef & elemPoints = *epIt;
387 TElemDef::const_iterator iIt = elemPoints.begin();
388 for ( ; iIt != elemPoints.end(); iIt++ )
389 theFile << " " << *iIt;
395 return setErrorCode( ERR_OK );
398 //=======================================================================
399 //function : sortBySize
400 //purpose : sort theListOfList by size
401 //=======================================================================
403 template<typename T> struct TSizeCmp {
404 bool operator ()( const list < T > & l1, const list < T > & l2 )
405 const { return l1.size() < l2.size(); }
408 template<typename T> void sortBySize( list< list < T > > & theListOfList )
410 if ( theListOfList.size() > 2 ) {
411 TSizeCmp< T > SizeCmp;
412 theListOfList.sort( SizeCmp );
416 //=======================================================================
417 //function : getOrderedEdges
418 //purpose : return nb wires and a list of oredered edges
419 //=======================================================================
421 static int getOrderedEdges (const TopoDS_Face& theFace,
422 const TopoDS_Vertex& theFirstVertex,
423 list< TopoDS_Edge >& theEdges,
424 list< int > & theNbVertexInWires)
426 // put wires in a list, so that an outer wire comes first
427 list<TopoDS_Wire> aWireList;
428 TopoDS_Wire anOuterWire = BRepTools::OuterWire( theFace );
429 aWireList.push_back( anOuterWire );
430 for ( TopoDS_Iterator wIt (theFace); wIt.More(); wIt.Next() )
431 if ( !anOuterWire.IsSame( wIt.Value() ))
432 aWireList.push_back( TopoDS::Wire( wIt.Value() ));
434 // loop on edges of wires
435 theNbVertexInWires.clear();
436 list<TopoDS_Wire>::iterator wlIt = aWireList.begin();
437 for ( ; wlIt != aWireList.end(); wlIt++ )
440 BRepTools_WireExplorer wExp( *wlIt, theFace );
441 for ( iE = 0; wExp.More(); wExp.Next(), iE++ )
443 TopoDS_Edge edge = wExp.Current();
444 edge = TopoDS::Edge( edge.Oriented( wExp.Orientation() ));
445 theEdges.push_back( edge );
447 theNbVertexInWires.push_back( iE );
449 if ( wlIt == aWireList.begin() && theEdges.size() > 1 ) { // the outer wire
450 // orient closed edges
451 list< TopoDS_Edge >::iterator eIt, eIt2;
452 for ( eIt = theEdges.begin(); eIt != theEdges.end(); eIt++ )
454 TopoDS_Edge& edge = *eIt;
455 if ( TopExp::FirstVertex( edge ).IsSame( TopExp::LastVertex( edge ) ))
458 bool isNext = ( eIt2 == theEdges.begin() );
459 TopoDS_Edge edge2 = isNext ? *(++eIt2) : *(--eIt2);
461 Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( edge, theFace, f1,l1 );
462 Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( edge2, theFace, f2,l2 );
463 gp_Pnt2d pf = c1->Value( edge.Orientation() == TopAbs_FORWARD ? f1 : l1 );
464 gp_Pnt2d pl = c1->Value( edge.Orientation() == TopAbs_FORWARD ? l1 : f1 );
465 bool isFirst = ( edge2.Orientation() == TopAbs_FORWARD ? isNext : !isNext );
466 gp_Pnt2d p2 = c2->Value( isFirst ? f2 : l2 );
467 isFirst = ( p2.SquareDistance( pf ) < p2.SquareDistance( pl ));
468 if ( isNext ? isFirst : !isFirst )
472 // rotate theEdges until it begins from theFirstVertex
473 if ( ! theFirstVertex.IsNull() )
474 while ( !theFirstVertex.IsSame( TopExp::FirstVertex( theEdges.front(), true )))
476 theEdges.splice(theEdges.end(), theEdges,
477 theEdges.begin(), ++ theEdges.begin());
478 if ( iE++ > theNbVertexInWires.back() )
479 break; // break infinite loop
484 return aWireList.size();
487 //=======================================================================
490 //=======================================================================
492 static gp_XY project (const SMDS_MeshNode* theNode,
493 Extrema_GenExtPS & theProjectorPS)
495 gp_Pnt P( theNode->X(), theNode->Y(), theNode->Z() );
496 theProjectorPS.Perform( P );
497 if ( !theProjectorPS.IsDone() ) {
498 MESSAGE( "SMESH_Pattern: point projection FAILED");
501 double u, v, minVal = DBL_MAX;
502 for ( int i = theProjectorPS.NbExt(); i > 0; i-- )
503 if ( theProjectorPS.Value( i ) < minVal ) {
504 minVal = theProjectorPS.Value( i );
505 theProjectorPS.Point( i ).Parameter( u, v );
507 return gp_XY( u, v );
510 //=======================================================================
511 //function : isMeshBoundToShape
512 //purpose : return true if all 2d elements are bound to shape
513 //=======================================================================
515 static bool isMeshBoundToShape(SMESH_Mesh* theMesh)
517 // check faces binding
518 SMESHDS_Mesh * aMeshDS = theMesh->GetMeshDS();
519 SMESHDS_SubMesh * aMainSubMesh = aMeshDS->MeshElements( aMeshDS->ShapeToMesh() );
520 if ( aMeshDS->NbFaces() != aMainSubMesh->NbElements() )
523 // check face nodes binding
524 SMDS_FaceIteratorPtr fIt = aMeshDS->facesIterator();
525 while ( fIt->more() )
527 SMDS_ElemIteratorPtr nIt = fIt->next()->nodesIterator();
528 while ( nIt->more() )
530 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nIt->next() );
531 SMDS_PositionPtr pos = node->GetPosition();
532 if ( !pos || !pos->GetShapeId() )
539 //=======================================================================
541 //purpose : Create a pattern from the mesh built on <theFace>.
542 // <theProject>==true makes override nodes positions
543 // on <theFace> computed by mesher
544 //=======================================================================
546 bool SMESH_Pattern::Load (SMESH_Mesh* theMesh,
547 const TopoDS_Face& theFace,
550 MESSAGE(" ::Load(face) " );
554 SMESHDS_Mesh * aMeshDS = theMesh->GetMeshDS();
555 SMESHDS_SubMesh * fSubMesh = aMeshDS->MeshElements( theFace );
557 int nbNodes = ( !fSubMesh ? 0 : fSubMesh->NbNodes() );
558 int nbElems = ( !fSubMesh ? 0 : fSubMesh->NbElements() );
559 if ( nbElems == 0 && aMeshDS->NbFaces() == 0 )
561 MESSAGE( "No elements bound to the face");
562 return setErrorCode( ERR_LOAD_EMPTY_SUBMESH );
565 TopoDS_Face face = TopoDS::Face( theFace.Oriented( TopAbs_FORWARD ));
567 // check that face is not closed
569 list<TopoDS_Edge> eList;
570 getOrderedEdges( face, bidon, eList, myNbKeyPntInBoundary );
571 list<TopoDS_Edge>::iterator elIt = eList.begin();
572 for ( ; elIt != eList.end() ; elIt++ )
573 if ( BRep_Tool::IsClosed( *elIt , face ))
574 return setErrorCode( ERR_LOADF_CLOSED_FACE );
577 Extrema_GenExtPS projector;
578 GeomAdaptor_Surface aSurface( BRep_Tool::Surface( face ));
579 if ( theProject || nbElems == 0 )
580 projector.Initialize( aSurface, 20,20, 1e-5,1e-5 );
583 TNodePointIDMap nodePointIDMap;
585 if ( nbElems == 0 || (theProject &&
586 theMesh->IsMainShape( face ) &&
587 !isMeshBoundToShape( theMesh )))
589 MESSAGE("Project the whole mesh");
590 // ---------------------------------------------------------------
591 // The case where the whole mesh is projected to theFace
592 // ---------------------------------------------------------------
594 // put nodes of all faces in the nodePointIDMap and fill myElemPointIDs
595 SMDS_FaceIteratorPtr fIt = aMeshDS->facesIterator();
596 while ( fIt->more() )
598 myElemPointIDs.push_back( TElemDef() );
599 TElemDef& elemPoints = myElemPointIDs.back();
600 SMDS_ElemIteratorPtr nIt = fIt->next()->nodesIterator();
601 while ( nIt->more() )
603 const SMDS_MeshElement* node = nIt->next();
604 TNodePointIDMap::iterator nIdIt = nodePointIDMap.find( node );
605 if ( nIdIt == nodePointIDMap.end() )
607 elemPoints.push_back( iPoint );
608 nodePointIDMap.insert( make_pair( node, iPoint++ ));
611 elemPoints.push_back( (*nIdIt).second );
614 myPoints.resize( iPoint );
616 // project all nodes of 2d elements to theFace
617 TNodePointIDMap::iterator nIdIt = nodePointIDMap.begin();
618 for ( ; nIdIt != nodePointIDMap.end(); nIdIt++ )
620 const SMDS_MeshNode* node =
621 static_cast<const SMDS_MeshNode*>( (*nIdIt).first );
622 TPoint * p = & myPoints[ (*nIdIt).second ];
623 p->myInitUV = project( node, projector );
624 p->myInitXYZ.SetCoord( p->myInitUV.X(), p->myInitUV.Y(), 0 );
626 // find key-points: the points most close to UV of vertices
627 TopExp_Explorer vExp( face, TopAbs_VERTEX );
628 set<int> foundIndices;
629 for ( ; vExp.More(); vExp.Next() ) {
630 const TopoDS_Vertex v = TopoDS::Vertex( vExp.Current() );
631 gp_Pnt2d uv = BRep_Tool::Parameters( v, face );
632 double minDist = DBL_MAX;
634 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
635 for ( iPoint = 0; pVecIt != myPoints.end(); pVecIt++, iPoint++ ) {
636 double dist = uv.SquareDistance( (*pVecIt).myInitUV );
637 if ( dist < minDist ) {
642 if ( foundIndices.insert( index ).second ) // unique?
643 myKeyPointIDs.push_back( index );
645 myIsBoundaryPointsFound = false;
650 // ---------------------------------------------------------------------
651 // The case where a pattern is being made from the mesh built by mesher
652 // ---------------------------------------------------------------------
654 // Load shapes in the consequent order and count nb of points
657 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ ) {
658 myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true ));
659 SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( *elIt );
661 nbNodes += eSubMesh->NbNodes() + 1;
664 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
665 myShapeIDMap.Add( *elIt );
667 myShapeIDMap.Add( face );
669 myPoints.resize( nbNodes );
671 // Load U of points on edges
673 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
675 TopoDS_Edge & edge = *elIt;
676 list< TPoint* > & ePoints = getShapePoints( edge );
678 Handle(Geom2d_Curve) C2d;
680 C2d = BRep_Tool::CurveOnSurface( edge, face, f, l );
681 bool isForward = ( edge.Orientation() == TopAbs_FORWARD );
683 // the forward key-point
684 TopoDS_Shape v = TopExp::FirstVertex( edge, true );
685 list< TPoint* > & vPoint = getShapePoints( v );
686 if ( vPoint.empty() )
688 SMESHDS_SubMesh * vSubMesh = aMeshDS->MeshElements( v );
689 if ( vSubMesh && vSubMesh->NbNodes() ) {
690 myKeyPointIDs.push_back( iPoint );
691 SMDS_NodeIteratorPtr nIt = vSubMesh->GetNodes();
692 const SMDS_MeshNode* node = nIt->next();
693 nodePointIDMap.insert( make_pair( node, iPoint ));
695 TPoint* keyPoint = &myPoints[ iPoint++ ];
696 vPoint.push_back( keyPoint );
698 keyPoint->myInitUV = project( node, projector );
700 keyPoint->myInitUV = C2d->Value( isForward ? f : l ).XY();
701 keyPoint->myInitXYZ.SetCoord (keyPoint->myInitUV.X(), keyPoint->myInitUV.Y(), 0);
704 if ( !vPoint.empty() )
705 ePoints.push_back( vPoint.front() );
708 SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edge );
709 if ( eSubMesh && eSubMesh->NbNodes() )
711 // loop on nodes of an edge: sort them by param on edge
712 typedef map < double, const SMDS_MeshNode* > TParamNodeMap;
713 TParamNodeMap paramNodeMap;
714 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
715 while ( nIt->more() )
717 const SMDS_MeshNode* node =
718 static_cast<const SMDS_MeshNode*>( nIt->next() );
719 const SMDS_EdgePosition* epos =
720 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
721 double u = epos->GetUParameter();
722 paramNodeMap.insert( TParamNodeMap::value_type( u, node ));
724 // put U in [0,1] so that the first key-point has U==0
726 TParamNodeMap::iterator unIt = paramNodeMap.begin();
727 TParamNodeMap::reverse_iterator unRIt = paramNodeMap.rbegin();
728 while ( unIt != paramNodeMap.end() )
730 TPoint* p = & myPoints[ iPoint ];
731 ePoints.push_back( p );
732 const SMDS_MeshNode* node = isForward ? (*unIt).second : (*unRIt).second;
733 nodePointIDMap.insert ( make_pair( node, iPoint ));
736 p->myInitUV = project( node, projector );
738 double u = isForward ? (*unIt).first : (*unRIt).first;
739 p->myInitU = isForward ? (( u - f ) / du ) : ( 1.0 - ( u - f ) / du );
740 p->myInitUV = C2d->Value( u ).XY();
742 p->myInitXYZ.SetCoord( p->myInitUV.X(), p->myInitUV.Y(), 0 );
747 // the reverse key-point
748 v = TopExp::LastVertex( edge, true ).Reversed();
749 list< TPoint* > & vPoint2 = getShapePoints( v );
750 if ( vPoint2.empty() )
752 SMESHDS_SubMesh * vSubMesh = aMeshDS->MeshElements( v );
753 if ( vSubMesh && vSubMesh->NbNodes() ) {
754 myKeyPointIDs.push_back( iPoint );
755 SMDS_NodeIteratorPtr nIt = vSubMesh->GetNodes();
756 const SMDS_MeshNode* node = nIt->next();
757 nodePointIDMap.insert( make_pair( node, iPoint ));
759 TPoint* keyPoint = &myPoints[ iPoint++ ];
760 vPoint2.push_back( keyPoint );
762 keyPoint->myInitUV = project( node, projector );
764 keyPoint->myInitUV = C2d->Value( isForward ? l : f ).XY();
765 keyPoint->myInitXYZ.SetCoord( keyPoint->myInitUV.X(), keyPoint->myInitUV.Y(), 0 );
768 if ( !vPoint2.empty() )
769 ePoints.push_back( vPoint2.front() );
771 // compute U of edge-points
774 double totalDist = 0;
775 list< TPoint* >::iterator pIt = ePoints.begin();
776 TPoint* prevP = *pIt;
777 prevP->myInitU = totalDist;
778 for ( pIt++; pIt != ePoints.end(); pIt++ ) {
780 totalDist += ( p->myInitUV - prevP->myInitUV ).Modulus();
781 p->myInitU = totalDist;
784 if ( totalDist > DBL_MIN)
785 for ( pIt = ePoints.begin(); pIt != ePoints.end(); pIt++ ) {
787 p->myInitU /= totalDist;
790 } // loop on edges of a wire
792 // Load in-face points and elements
794 if ( fSubMesh && fSubMesh->NbElements() )
796 list< TPoint* > & fPoints = getShapePoints( face );
797 SMDS_NodeIteratorPtr nIt = fSubMesh->GetNodes();
798 while ( nIt->more() )
800 const SMDS_MeshNode* node =
801 static_cast<const SMDS_MeshNode*>( nIt->next() );
802 nodePointIDMap.insert( make_pair( node, iPoint ));
803 TPoint* p = &myPoints[ iPoint++ ];
804 fPoints.push_back( p );
806 p->myInitUV = project( node, projector );
808 const SMDS_FacePosition* pos =
809 static_cast<const SMDS_FacePosition*>(node->GetPosition().get());
810 p->myInitUV.SetCoord( pos->GetUParameter(), pos->GetVParameter() );
812 p->myInitXYZ.SetCoord( p->myInitUV.X(), p->myInitUV.Y(), 0 );
815 SMDS_ElemIteratorPtr elemIt = fSubMesh->GetElements();
816 while ( elemIt->more() ) {
817 SMDS_ElemIteratorPtr nIt = elemIt->next()->nodesIterator();
818 myElemPointIDs.push_back( TElemDef() );
819 TElemDef& elemPoints = myElemPointIDs.back();
820 while ( nIt->more() )
821 elemPoints.push_back( nodePointIDMap[ nIt->next() ]);
825 myIsBoundaryPointsFound = true;
828 // Assure that U range is proportional to V range
831 vector< TPoint >::iterator pVecIt = myPoints.begin();
832 for ( ; pVecIt != myPoints.end(); pVecIt++ )
833 bndBox.Add( gp_Pnt2d( (*pVecIt).myInitUV ));
834 double minU, minV, maxU, maxV;
835 bndBox.Get( minU, minV, maxU, maxV );
836 double dU = maxU - minU, dV = maxV - minV;
837 if ( dU <= DBL_MIN || dV <= DBL_MIN ) {
839 return setErrorCode( ERR_LOADF_NARROW_FACE );
841 double ratio = dU / dV, maxratio = 3, scale;
843 if ( ratio > maxratio ) {
844 scale = ratio / maxratio;
847 else if ( ratio < 1./maxratio ) {
848 scale = maxratio / ratio;
853 for ( pVecIt = myPoints.begin(); pVecIt != myPoints.end(); pVecIt++ ) {
854 TPoint & p = *pVecIt;
855 p.myInitUV.SetCoord( iCoord, p.myInitUV.Coord( iCoord ) * scale );
856 p.myInitXYZ.SetCoord( p.myInitUV.X(), p.myInitUV.Y(), 0 );
859 if ( myElemPointIDs.empty() ) {
860 MESSAGE( "No elements bound to the face");
861 return setErrorCode( ERR_LOAD_EMPTY_SUBMESH );
864 return setErrorCode( ERR_OK );
867 //=======================================================================
868 //function : computeUVOnEdge
869 //purpose : compute coordinates of points on theEdge
870 //=======================================================================
872 void SMESH_Pattern::computeUVOnEdge (const TopoDS_Edge& theEdge,
873 const list< TPoint* > & ePoints )
875 bool isForward = ( theEdge.Orientation() == TopAbs_FORWARD );
877 Handle(Geom2d_Curve) C2d =
878 BRep_Tool::CurveOnSurface( theEdge, TopoDS::Face( myShape ), f, l );
880 ePoints.back()->myInitU = 1.0;
881 list< TPoint* >::const_iterator pIt = ePoints.begin();
882 for ( pIt++; pIt != ePoints.end(); pIt++ )
884 TPoint* point = *pIt;
886 double du = ( isForward ? point->myInitU : 1 - point->myInitU );
887 point->myU = ( f * ( 1 - du ) + l * du );
889 point->myUV = C2d->Value( point->myU ).XY();
893 //=======================================================================
894 //function : intersectIsolines
896 //=======================================================================
898 static bool intersectIsolines(const gp_XY& uv11, const gp_XY& uv12, const double r1,
899 const gp_XY& uv21, const gp_XY& uv22, const double r2,
903 gp_XY loc1 = uv11 * ( 1 - r1 ) + uv12 * r1;
904 gp_XY loc2 = uv21 * ( 1 - r2 ) + uv22 * r2;
905 resUV = 0.5 * ( loc1 + loc2 );
906 isDeformed = ( loc1 - loc2 ).SquareModulus() > 1e-8;
907 // double len1 = ( uv11 - uv12 ).Modulus();
908 // double len2 = ( uv21 - uv22 ).Modulus();
909 // resUV = loc1 * len2 / ( len1 + len2 ) + loc2 * len1 / ( len1 + len2 );
913 // gp_Lin2d line1( uv11, uv12 - uv11 );
914 // gp_Lin2d line2( uv21, uv22 - uv21 );
915 // double angle = Abs( line1.Angle( line2 ) );
917 // IntAna2d_AnaIntersection inter;
918 // inter.Perform( line1.Normal( loc1 ), line2.Normal( loc2 ) );
919 // if ( inter.IsDone() && inter.NbPoints() == 1 )
921 // gp_Pnt2d interUV = inter.Point(1).Value();
922 // resUV += interUV.XY();
923 // inter.Perform( line1, line2 );
924 // interUV = inter.Point(1).Value();
925 // resUV += interUV.XY();
932 //=======================================================================
933 //function : compUVByIsoIntersection
935 //=======================================================================
937 bool SMESH_Pattern::compUVByIsoIntersection (const list< list< TPoint* > >& theBndPoints,
938 const gp_XY& theInitUV,
940 bool & theIsDeformed )
942 // compute UV by intersection of 2 iso lines
943 //gp_Lin2d isoLine[2];
944 gp_XY uv1[2], uv2[2];
946 const double zero = DBL_MIN;
947 for ( int iIso = 0; iIso < 2; iIso++ )
949 // to build an iso line:
950 // find 2 pairs of consequent edge-points such that the range of their
951 // initial parameters encloses the in-face point initial parameter
952 gp_XY UV[2], initUV[2];
953 int nbUV = 0, iCoord = iIso + 1;
954 double initParam = theInitUV.Coord( iCoord );
956 list< list< TPoint* > >::const_iterator bndIt = theBndPoints.begin();
957 for ( ; bndIt != theBndPoints.end(); bndIt++ )
959 const list< TPoint* > & bndPoints = * bndIt;
960 TPoint* prevP = bndPoints.back(); // this is the first point
961 list< TPoint* >::const_iterator pIt = bndPoints.begin();
962 bool coincPrev = false;
963 // loop on the edge-points
964 for ( ; pIt != bndPoints.end(); pIt++ )
966 double paramDiff = initParam - (*pIt)->myInitUV.Coord( iCoord );
967 double prevParamDiff = initParam - prevP->myInitUV.Coord( iCoord );
968 double sumOfDiff = Abs(prevParamDiff) + Abs(paramDiff);
969 if (!coincPrev && // ignore if initParam coincides with prev point param
970 sumOfDiff > zero && // ignore if both points coincide with initParam
971 prevParamDiff * paramDiff <= zero )
973 // find UV in parametric space of theFace
974 double r = Abs(prevParamDiff) / sumOfDiff;
975 gp_XY uvInit = (*pIt)->myInitUV * r + prevP->myInitUV * ( 1 - r );
978 // throw away uv most distant from <theInitUV>
979 gp_XY vec0 = initUV[0] - theInitUV;
980 gp_XY vec1 = initUV[1] - theInitUV;
981 gp_XY vec = uvInit - theInitUV;
982 bool isBetween = ( vec0 * vec1 < 0 ); // is theInitUV between initUV[0] and initUV[1]
983 double dist0 = vec0.SquareModulus();
984 double dist1 = vec1.SquareModulus();
985 double dist = vec .SquareModulus();
986 if ( !isBetween || dist < dist0 || dist < dist1 ) {
987 i = ( dist0 < dist1 ? 1 : 0 );
988 if ( isBetween && vec.Dot( i ? vec1 : vec0 ) < 0 )
989 i = 3; // theInitUV must remain between
993 initUV[ i ] = uvInit;
994 UV[ i ] = (*pIt)->myUV * r + prevP->myUV * ( 1 - r );
996 coincPrev = ( Abs(paramDiff) <= zero );
1003 if ( nbUV < 2 || (UV[0]-UV[1]).SquareModulus() <= DBL_MIN*DBL_MIN ) {
1004 MESSAGE(" consequent edge-points not found, nb UV found: " << nbUV <<
1005 ", for point: " << theInitUV.X() <<" " << theInitUV.Y() );
1006 return setErrorCode( ERR_APPLF_BAD_TOPOLOGY );
1008 // an iso line should be normal to UV[0] - UV[1] direction
1009 // and be located at the same relative distance as from initial ends
1010 //gp_Lin2d iso( UV[0], UV[0] - UV[1] );
1012 (initUV[0]-theInitUV).Modulus() / (initUV[0]-initUV[1]).Modulus();
1013 //gp_Pnt2d isoLoc = UV[0] * ( 1 - r ) + UV[1] * r;
1014 //isoLine[ iIso ] = iso.Normal( isoLoc );
1015 uv1[ iIso ] = UV[0];
1016 uv2[ iIso ] = UV[1];
1019 if ( !intersectIsolines( uv1[0], uv2[0], ratio[0],
1020 uv1[1], uv2[1], ratio[1], theUV, theIsDeformed )) {
1021 MESSAGE(" Cant intersect isolines for a point "<<theInitUV.X()<<", "<<theInitUV.Y());
1022 return setErrorCode( ERR_APPLF_BAD_TOPOLOGY );
1029 // ==========================================================
1030 // structure representing a node of a grid of iso-poly-lines
1031 // ==========================================================
1038 gp_Dir2d myDir[2]; // boundary tangent dir for boundary nodes, iso dir for internal ones
1039 TIsoNode* myNext[4]; // order: (iDir=0,isForward=0), (1,0), (0,1), (1,1)
1040 TIsoNode* myBndNodes[4]; // order: (iDir=0,i=0), (1,0), (0,1), (1,1)
1041 TIsoNode(double initU, double initV):
1042 myInitUV( initU, initV ), myUV( 1e100, 1e100 ), myIsMovable(true)
1043 { myNext[0] = myNext[1] = myNext[2] = myNext[3] = 0; }
1044 bool IsUVComputed() const
1045 { return myUV.X() != 1e100; }
1046 bool IsMovable() const
1047 { return myIsMovable && myNext[0] && myNext[1] && myNext[2] && myNext[3]; }
1048 void SetNotMovable()
1049 { myIsMovable = false; }
1050 void SetBoundaryNode(TIsoNode* node, int iDir, int i)
1051 { myBndNodes[ iDir + i * 2 ] = node; }
1052 TIsoNode* GetBoundaryNode(int iDir, int i)
1053 { return myBndNodes[ iDir + i * 2 ]; }
1054 void SetNext(TIsoNode* node, int iDir, int isForward)
1055 { myNext[ iDir + isForward * 2 ] = node; }
1056 TIsoNode* GetNext(int iDir, int isForward)
1057 { return myNext[ iDir + isForward * 2 ]; }
1060 //=======================================================================
1061 //function : getNextNode
1063 //=======================================================================
1065 static inline TIsoNode* getNextNode(const TIsoNode* node, int dir )
1067 TIsoNode* n = node->myNext[ dir ];
1068 if ( n && !n->IsUVComputed()/* && node->IsMovable()*/ ) {
1069 n = 0;//node->myBndNodes[ dir ];
1070 // MESSAGE("getNextNode: use bnd for node "<<
1071 // node->myInitUV.X()<<" "<<node->myInitUV.Y());
1075 //=======================================================================
1076 //function : checkQuads
1077 //purpose : check if newUV destortes quadrangles around node,
1078 // and if ( crit == FIX_OLD ) fix newUV in this case
1079 //=======================================================================
1081 enum { CHECK_NEW_IN, CHECK_NEW_OK, FIX_OLD };
1083 static bool checkQuads (const TIsoNode* node,
1085 const bool reversed,
1086 const int crit = FIX_OLD,
1087 double fixSize = 0.)
1089 gp_XY oldUV = node->myUV, oldUVFixed[4], oldUVImpr[4];
1090 int nbOldFix = 0, nbOldImpr = 0;
1091 double newBadRate = 0, oldBadRate = 0;
1092 bool newIsOk = true, newIsIn = true, oldIsIn = true, oldIsOk = true;
1093 int i, dir1 = 0, dir2 = 3;
1094 for ( ; dir1 < 4; dir1++, dir2++ ) // loop on 4 quadrangles around <node>
1096 if ( dir2 > 3 ) dir2 = 0;
1098 // walking counterclockwise around a quad,
1099 // nodes are in the order: node, n[0], n[1], n[2]
1100 n[0] = getNextNode( node, dir1 );
1101 n[2] = getNextNode( node, dir2 );
1102 if ( !n[0] || !n[2] ) continue;
1103 n[1] = getNextNode( n[0], dir2 );
1104 if ( !n[1] ) n[1] = getNextNode( n[2], dir1 );
1105 bool isTriangle = ( !n[1] );
1107 TIsoNode* tmp = n[0]; n[0] = n[2]; n[2] = tmp;
1109 // if ( fixSize != 0 ) {
1110 // cout<<"NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<" UV: "<<node->myUV.X()<<" "<<node->myUV.Y()<<endl;
1111 // cout<<"\t0: "<<n[0]->myInitUV.X()<<" "<<n[0]->myInitUV.Y()<<" UV: "<<n[0]->myUV.X()<<" "<<n[0]->myUV.Y()<<endl;
1112 // cout<<"\t1: "<<n[1]->myInitUV.X()<<" "<<n[1]->myInitUV.Y()<<" UV: "<<n[1]->myUV.X()<<" "<<n[1]->myUV.Y()<<endl;
1113 // cout<<"\t2: "<<n[2]->myInitUV.X()<<" "<<n[2]->myInitUV.Y()<<" UV: "<<n[2]->myUV.X()<<" "<<n[2]->myUV.Y()<<endl;
1115 // check if a quadrangle is degenerated
1117 ((( n[0]->myUV - n[1]->myUV ).SquareModulus() <= DBL_MIN ) ||
1118 (( n[2]->myUV - n[1]->myUV ).SquareModulus() <= DBL_MIN )))
1121 ( n[0]->myUV - n[2]->myUV ).SquareModulus() <= DBL_MIN )
1124 // find min size of the diagonal node-n[1]
1125 double minDiag = fixSize;
1126 if ( minDiag == 0. ) {
1127 double maxLen2 = ( node->myUV - n[0]->myUV ).SquareModulus();
1128 if ( !isTriangle ) {
1129 maxLen2 = Max( maxLen2, ( n[0]->myUV - n[1]->myUV ).SquareModulus() );
1130 maxLen2 = Max( maxLen2, ( n[1]->myUV - n[2]->myUV ).SquareModulus() );
1132 maxLen2 = Max( maxLen2, ( n[2]->myUV - node->myUV ).SquareModulus() );
1133 minDiag = sqrt( maxLen2 ) * PI / 60.; // ~ maxLen * Sin( 3 deg )
1136 // check if newUV is behind 3 dirs: n[0]-n[1], n[1]-n[2] and n[0]-n[2]
1137 // ( behind means "to the right of")
1139 // 1. newUV is not behind 01 and 12 dirs
1140 // 2. or newUV is not behind 02 dir and n[2] is convex
1141 bool newIn[3] = { true, true, true }, newOk[3] = { true, true, true };
1142 bool wasIn[3] = { true, true, true }, wasOk[3] = { true, true, true };
1143 gp_Vec2d moveVec[3], outVec[3];
1144 for ( i = isTriangle ? 2 : 0; i < 3; i++ )
1146 bool isDiag = ( i == 2 );
1147 if ( isDiag && newOk[0] && newOk[1] && !isTriangle )
1151 sideDir = gp_Vec2d( n[0]->myUV, n[2]->myUV );
1153 sideDir = gp_Vec2d( n[i]->myUV, n[i+1]->myUV );
1155 gp_Vec2d outDir( sideDir.Y(), -sideDir.X() ); // to the right
1157 gp_Vec2d newDir( n[i]->myUV, newUV );
1158 gp_Vec2d oldDir( n[i]->myUV, oldUV );
1160 if ( newIsOk ) newOk[i] = ( outDir * newDir < -minDiag );
1161 if ( newIsIn ) newIn[i] = ( outDir * newDir < 0 );
1162 if ( crit == FIX_OLD ) {
1163 wasIn[i] = ( outDir * oldDir < 0 );
1164 wasOk[i] = ( outDir * oldDir < -minDiag );
1166 newBadRate += outDir * newDir;
1168 oldBadRate += outDir * oldDir;
1171 double oldDist = - outDir * oldDir;//, l2 = outDir * newDir;
1172 // double r = ( l1 - minDiag ) / ( l1 + l2 );
1173 // moveVec[i] = r * gp_Vec2d( node->myUV, newUV );
1174 moveVec[i] = ( oldDist - minDiag ) * outDir;
1179 // check if n[2] is convex
1182 convex = ( outVec[0] * gp_Vec2d( n[1]->myUV, n[2]->myUV ) < 0 );
1184 bool isNewOk = ( newOk[0] && newOk[1] ) || ( newOk[2] && convex );
1185 bool isNewIn = ( newIn[0] && newIn[1] ) || ( newIn[2] && convex );
1186 newIsOk = ( newIsOk && isNewOk );
1187 newIsIn = ( newIsIn && isNewIn );
1189 if ( crit != FIX_OLD ) {
1190 if ( crit == CHECK_NEW_OK && !newIsOk ) break;
1191 if ( crit == CHECK_NEW_IN && !newIsIn ) break;
1195 bool isOldIn = ( wasIn[0] && wasIn[1] ) || ( wasIn[2] && convex );
1196 bool isOldOk = ( wasOk[0] && wasOk[1] ) || ( wasOk[2] && convex );
1197 oldIsIn = ( oldIsIn && isOldIn );
1198 oldIsOk = ( oldIsOk && isOldIn );
1201 if ( !isOldIn ) { // node is outside a quadrangle
1202 // move newUV inside a quadrangle
1203 //MESSAGE("Quad "<< dir1 << " WAS IN " << wasIn[0]<<" "<<wasIn[1]<<" "<<wasIn[2]);
1204 // node and newUV are outside: push newUV inside
1206 if ( convex || isTriangle ) {
1207 uv = 0.5 * ( n[0]->myUV + n[2]->myUV ) - minDiag * outVec[2].XY();
1210 gp_Vec2d out = outVec[0].Normalized() + outVec[1].Normalized();
1211 double outSize = out.Magnitude();
1212 if ( outSize > DBL_MIN )
1215 out.SetCoord( -outVec[1].Y(), outVec[1].X() );
1216 uv = n[1]->myUV - minDiag * out.XY();
1218 oldUVFixed[ nbOldFix++ ] = uv;
1219 //node->myUV = newUV;
1221 else if ( !isOldOk ) {
1222 // try to fix old UV: move node inside as less as possible
1223 //MESSAGE("Quad "<< dir1 << " old is BAD, try to fix old, minDiag: "<< minDiag);
1224 gp_XY uv1, uv2 = node->myUV;
1225 for ( i = isTriangle ? 2 : 0; i < 3; i++ ) // mark not computed vectors
1227 moveVec[ i ].SetCoord( 1, 2e100); // not use this vector
1228 while ( !isOldOk ) {
1229 // find the least moveVec
1231 double minMove2 = 1e100;
1232 for ( i = isTriangle ? 2 : 0; i < 3; i++ )
1234 if ( moveVec[i].Coord(1) < 1e100 ) {
1235 double move2 = moveVec[i].SquareMagnitude();
1236 if ( move2 < minMove2 ) {
1245 // move node to newUV
1246 uv1 = node->myUV + moveVec[ iMin ].XY();
1247 uv2 += moveVec[ iMin ].XY();
1248 moveVec[ iMin ].SetCoord( 1, 2e100); // not use this vector more
1249 // check if uv1 is ok
1250 for ( i = isTriangle ? 2 : 0; i < 3; i++ )
1251 wasOk[i] = ( outVec[i] * gp_Vec2d( n[i]->myUV, uv1 ) < -minDiag );
1252 isOldOk = ( wasOk[0] && wasOk[1] ) || ( wasOk[2] && convex );
1254 oldUVImpr[ nbOldImpr++ ] = uv1;
1256 // check if uv2 is ok
1257 for ( i = isTriangle ? 2 : 0; i < 3; i++ )
1258 wasOk[i] = ( outVec[i] * gp_Vec2d( n[i]->myUV, uv2 ) < -minDiag );
1259 isOldOk = ( wasOk[0] && wasOk[1] ) || ( wasOk[2] && convex );
1261 oldUVImpr[ nbOldImpr++ ] = uv2;
1266 } // loop on 4 quadrangles around <node>
1268 if ( crit == CHECK_NEW_OK )
1270 if ( crit == CHECK_NEW_IN )
1279 if ( oldIsIn && nbOldImpr ) {
1280 // MESSAGE(" Try to improve UV, init: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<
1281 // " uv: "<<oldUV.X()<<" "<<oldUV.Y() );
1282 gp_XY uv = oldUVImpr[ 0 ];
1283 for ( int i = 1; i < nbOldImpr; i++ )
1284 uv += oldUVImpr[ i ];
1286 if ( checkQuads( node, uv, reversed, CHECK_NEW_OK )) {
1291 //MESSAGE(" Cant improve UV, uv: "<<uv.X()<<" "<<uv.Y());
1294 if ( !oldIsIn && nbOldFix ) {
1295 // MESSAGE(" Try to fix UV, init: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<
1296 // " uv: "<<oldUV.X()<<" "<<oldUV.Y() );
1297 gp_XY uv = oldUVFixed[ 0 ];
1298 for ( int i = 1; i < nbOldFix; i++ )
1299 uv += oldUVFixed[ i ];
1301 if ( checkQuads( node, uv, reversed, CHECK_NEW_IN )) {
1306 //MESSAGE(" Cant fix UV, uv: "<<uv.X()<<" "<<uv.Y());
1309 if ( newIsIn && oldIsIn )
1310 newUV = ( newBadRate < oldBadRate ) ? newUV : oldUV;
1311 else if ( !newIsIn )
1318 //=======================================================================
1319 //function : compUVByElasticIsolines
1320 //purpose : compute UV as nodes of iso-poly-lines consisting of
1321 // segments keeping relative size as in the pattern
1322 //=======================================================================
1323 //#define DEB_COMPUVBYELASTICISOLINES
1324 bool SMESH_Pattern::
1325 compUVByElasticIsolines(const list< list< TPoint* > >& theBndPoints,
1326 const list< TPoint* >& thePntToCompute)
1328 //cout << "============================== KEY POINTS =============================="<<endl;
1329 // list< int >::iterator kpIt = myKeyPointIDs.begin();
1330 // for ( ; kpIt != myKeyPointIDs.end(); kpIt++ ) {
1331 // TPoint& p = myPoints[ *kpIt ];
1332 // cout << "INIT: " << p.myInitUV.X() << " " << p.myInitUV.Y() <<
1333 // " UV: " << p.myUV.X() << " " << p.myUV.Y() << endl;
1335 //cout << "=============================="<<endl;
1337 // Define parameters of iso-grid nodes in U and V dir
1339 set< double > paramSet[ 2 ];
1340 list< list< TPoint* > >::const_iterator pListIt;
1341 list< TPoint* >::const_iterator pIt;
1342 for ( pListIt = theBndPoints.begin(); pListIt != theBndPoints.end(); pListIt++ ) {
1343 const list< TPoint* > & pList = * pListIt;
1344 for ( pIt = pList.begin(); pIt != pList.end(); pIt++ ) {
1345 paramSet[0].insert( (*pIt)->myInitUV.X() );
1346 paramSet[1].insert( (*pIt)->myInitUV.Y() );
1349 for ( pIt = thePntToCompute.begin(); pIt != thePntToCompute.end(); pIt++ ) {
1350 paramSet[0].insert( (*pIt)->myInitUV.X() );
1351 paramSet[1].insert( (*pIt)->myInitUV.Y() );
1353 // unite close parameters and split too long segments
1356 for ( iDir = 0; iDir < 2; iDir++ )
1358 set< double > & params = paramSet[ iDir ];
1359 double range = ( *params.rbegin() - *params.begin() );
1360 double toler = range / 1e6;
1361 tol[ iDir ] = toler;
1362 // double maxSegment = range / params.size() / 2.;
1364 // set< double >::iterator parIt = params.begin();
1365 // double prevPar = *parIt;
1366 // for ( parIt++; parIt != params.end(); parIt++ )
1368 // double segLen = (*parIt) - prevPar;
1369 // if ( segLen < toler )
1370 // ;//params.erase( prevPar ); // unite
1371 // else if ( segLen > maxSegment )
1372 // params.insert( prevPar + 0.5 * segLen ); // split
1373 // prevPar = (*parIt);
1377 // Make nodes of a grid of iso-poly-lines
1379 list < TIsoNode > nodes;
1380 typedef list < TIsoNode *> TIsoLine;
1381 map < double, TIsoLine > isoMap[ 2 ];
1383 set< double > & params0 = paramSet[ 0 ];
1384 set< double >::iterator par0It = params0.begin();
1385 for ( ; par0It != params0.end(); par0It++ )
1387 TIsoLine & isoLine0 = isoMap[0][ *par0It ]; // vertical isoline with const U
1388 set< double > & params1 = paramSet[ 1 ];
1389 set< double >::iterator par1It = params1.begin();
1390 for ( ; par1It != params1.end(); par1It++ )
1392 nodes.push_back( TIsoNode( *par0It, *par1It ) );
1393 isoLine0.push_back( & nodes.back() );
1394 isoMap[1][ *par1It ].push_back( & nodes.back() );
1398 // Compute intersections of boundaries with iso-lines:
1399 // only boundary nodes will have computed UV so far
1402 list< list< TPoint* > >::const_iterator bndIt = theBndPoints.begin();
1403 list< TIsoNode* > bndNodes; // nodes corresponding to outer theBndPoints
1404 for ( ; bndIt != theBndPoints.end(); bndIt++ )
1406 const list< TPoint* > & bndPoints = * bndIt;
1407 TPoint* prevP = bndPoints.back(); // this is the first point
1408 list< TPoint* >::const_iterator pIt = bndPoints.begin();
1409 // loop on the edge-points
1410 for ( ; pIt != bndPoints.end(); pIt++ )
1412 TPoint* point = *pIt;
1413 for ( iDir = 0; iDir < 2; iDir++ )
1415 const int iCoord = iDir + 1;
1416 const int iOtherCoord = 2 - iDir;
1417 double par1 = prevP->myInitUV.Coord( iCoord );
1418 double par2 = point->myInitUV.Coord( iCoord );
1419 double parDif = par2 - par1;
1420 if ( Abs( parDif ) <= DBL_MIN )
1422 // find iso-lines intersecting a bounadry
1423 double toler = tol[ 1 - iDir ];
1424 double minPar = Min ( par1, par2 );
1425 double maxPar = Max ( par1, par2 );
1426 map < double, TIsoLine >& isos = isoMap[ iDir ];
1427 map < double, TIsoLine >::iterator isoIt = isos.begin();
1428 for ( ; isoIt != isos.end(); isoIt++ )
1430 double isoParam = (*isoIt).first;
1431 if ( isoParam < minPar || isoParam > maxPar )
1433 double r = ( isoParam - par1 ) / parDif;
1434 gp_XY uv = ( 1 - r ) * prevP->myUV + r * point->myUV;
1435 gp_XY initUV = ( 1 - r ) * prevP->myInitUV + r * point->myInitUV;
1436 double otherPar = initUV.Coord( iOtherCoord ); // along isoline
1437 // find existing node with otherPar or insert a new one
1438 TIsoLine & isoLine = (*isoIt).second;
1440 TIsoLine::iterator nIt = isoLine.begin();
1441 for ( ; nIt != isoLine.end(); nIt++ ) {
1442 nodePar = (*nIt)->myInitUV.Coord( iOtherCoord );
1443 if ( nodePar >= otherPar )
1447 if ( Abs( nodePar - otherPar ) <= toler )
1448 node = ( nIt == isoLine.end() ) ? isoLine.back() : (*nIt);
1450 nodes.push_back( TIsoNode( initUV.X(), initUV.Y() ) );
1451 node = & nodes.back();
1452 isoLine.insert( nIt, node );
1454 node->SetNotMovable();
1456 uvBnd.Add( gp_Pnt2d( uv ));
1457 // cout << "bnd: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<" UV: "<<node->myUV.X()<<" "<<node->myUV.Y()<<endl;
1459 gp_XY tgt( point->myUV - prevP->myUV );
1460 if ( ::IsEqual( r, 1. ))
1461 node->myDir[ 0 ] = tgt;
1462 else if ( ::IsEqual( r, 0. ))
1463 node->myDir[ 1 ] = tgt;
1465 node->myDir[ 1 ] = node->myDir[ 0 ] = tgt;
1466 // keep boundary nodes corresponding to boundary points
1467 if ( bndIt == theBndPoints.begin() && ::IsEqual( r, 1. ))
1468 if ( bndNodes.empty() || bndNodes.back() != node )
1469 bndNodes.push_back( node );
1470 } // loop on isolines
1471 } // loop on 2 directions
1473 } // loop on boundary points
1474 } // loop on boundaries
1476 // Define orientation
1478 // find the point with the least X
1479 double leastX = DBL_MAX;
1480 TIsoNode * leftNode;
1481 list < TIsoNode >::iterator nodeIt = nodes.begin();
1482 for ( ; nodeIt != nodes.end(); nodeIt++ ) {
1483 TIsoNode & node = *nodeIt;
1484 if ( node.IsUVComputed() && node.myUV.X() < leastX ) {
1485 leastX = node.myUV.X();
1488 // if ( node.IsUVComputed() ) {
1489 // cout << "bndNode INIT: " << node.myInitUV.X()<<" "<<node.myInitUV.Y()<<" UV: "<<
1490 // node.myUV.X()<<" "<<node.myUV.Y()<<endl<<
1491 // " dir0: "<<node.myDir[0].X()<<" "<<node.myDir[0].Y() <<
1492 // " dir1: "<<node.myDir[1].X()<<" "<<node.myDir[1].Y() << endl;
1495 bool reversed = ( leftNode->myDir[0].Y() + leftNode->myDir[1].Y() > 0 );
1496 //SCRUTE( reversed );
1498 // Prepare internal nodes:
1500 // 2. compute ratios
1501 // 3. find boundary nodes for each node
1502 // 4. remove nodes out of the boundary
1503 for ( iDir = 0; iDir < 2; iDir++ )
1505 const int iCoord = 2 - iDir; // coord changing along an isoline
1506 map < double, TIsoLine >& isos = isoMap[ iDir ];
1507 map < double, TIsoLine >::iterator isoIt = isos.begin();
1508 for ( ; isoIt != isos.end(); isoIt++ )
1510 TIsoLine & isoLine = (*isoIt).second;
1511 bool firstCompNodeFound = false;
1512 TIsoLine::iterator lastCompNodePos, nPrevIt, nIt, nNextIt, nIt2;
1513 nPrevIt = nIt = nNextIt = isoLine.begin();
1515 nNextIt++; nNextIt++;
1516 while ( nIt != isoLine.end() )
1518 // 1. connect prev - cur
1519 TIsoNode* node = *nIt, * prevNode = *nPrevIt;
1520 if ( !firstCompNodeFound && prevNode->IsUVComputed() ) {
1521 firstCompNodeFound = true;
1522 lastCompNodePos = nPrevIt;
1524 if ( firstCompNodeFound ) {
1525 node->SetNext( prevNode, iDir, 0 );
1526 prevNode->SetNext( node, iDir, 1 );
1529 if ( nNextIt != isoLine.end() ) {
1530 double par1 = prevNode->myInitUV.Coord( iCoord );
1531 double par2 = node->myInitUV.Coord( iCoord );
1532 double par3 = (*nNextIt)->myInitUV.Coord( iCoord );
1533 node->myRatio[ iDir ] = ( par2 - par1 ) / ( par3 - par1 );
1535 // 3. find boundary nodes
1536 if ( node->IsUVComputed() )
1537 lastCompNodePos = nIt;
1538 else if ( firstCompNodeFound && nNextIt != isoLine.end() ) {
1539 TIsoNode* bndNode1 = *lastCompNodePos, *bndNode2 = 0;
1540 for ( nIt2 = nNextIt; nIt2 != isoLine.end(); nIt2++ )
1541 if ( (*nIt2)->IsUVComputed() )
1543 if ( nIt2 != isoLine.end() ) {
1545 node->SetBoundaryNode( bndNode1, iDir, 0 );
1546 node->SetBoundaryNode( bndNode2, iDir, 1 );
1547 // cout << "--------------------------------------------------"<<endl;
1548 // cout << "bndNode1: " << bndNode1->myUV.X()<<" "<<bndNode1->myUV.Y()<<endl<<
1549 // " dir0: "<<bndNode1->myDir[0].X()<<" "<<bndNode1->myDir[0].Y() <<
1550 // " dir1: "<<bndNode1->myDir[1].X()<<" "<<bndNode1->myDir[1].Y() << endl;
1551 // cout << "bndNode2: " << bndNode2->myUV.X()<<" "<<bndNode2->myUV.Y()<<endl<<
1552 // " dir0: "<<bndNode2->myDir[0].X()<<" "<<bndNode2->myDir[0].Y() <<
1553 // " dir1: "<<bndNode2->myDir[1].X()<<" "<<bndNode2->myDir[1].Y() << endl;
1557 if ( nNextIt != isoLine.end() ) nNextIt++;
1558 // 4. remove nodes out of the boundary
1559 if ( !firstCompNodeFound )
1560 isoLine.pop_front();
1561 } // loop on isoLine nodes
1563 // remove nodes after the boundary
1564 // for ( nIt = ++lastCompNodePos; nIt != isoLine.end(); nIt++ )
1565 // (*nIt)->SetNotMovable();
1566 isoLine.erase( ++lastCompNodePos, isoLine.end() );
1567 } // loop on isolines
1568 } // loop on 2 directions
1570 // Compute local isoline direction for internal nodes
1573 map < double, TIsoLine >& isos = isoMap[ 0 ]; // vertical isolines with const U
1574 map < double, TIsoLine >::iterator isoIt = isos.begin();
1575 for ( ; isoIt != isos.end(); isoIt++ )
1577 TIsoLine & isoLine = (*isoIt).second;
1578 TIsoLine::iterator nIt = isoLine.begin();
1579 for ( ; nIt != isoLine.end(); nIt++ )
1581 TIsoNode* node = *nIt;
1582 if ( node->IsUVComputed() || !node->IsMovable() )
1584 gp_Vec2d aTgt[2], aNorm[2];
1587 for ( iDir = 0; iDir < 2; iDir++ )
1589 TIsoNode* bndNode1 = node->GetBoundaryNode( iDir, 0 );
1590 TIsoNode* bndNode2 = node->GetBoundaryNode( iDir, 1 );
1591 if ( !bndNode1 || !bndNode2 ) {
1595 const int iCoord = 2 - iDir; // coord changing along an isoline
1596 double par1 = bndNode1->myInitUV.Coord( iCoord );
1597 double par2 = node->myInitUV.Coord( iCoord );
1598 double par3 = bndNode2->myInitUV.Coord( iCoord );
1599 ratio[ iDir ] = ( par2 - par1 ) / ( par3 - par1 );
1601 gp_Vec2d tgt1( bndNode1->myDir[0].XY() + bndNode1->myDir[1].XY() );
1602 gp_Vec2d tgt2( bndNode2->myDir[0].XY() + bndNode2->myDir[1].XY() );
1603 if ( bool( iDir ) == reversed ) tgt2.Reverse(); // along perpend. isoline
1604 else tgt1.Reverse();
1605 //cout<<" tgt: " << tgt1.X()<<" "<<tgt1.Y()<<" | "<< tgt2.X()<<" "<<tgt2.Y()<<endl;
1607 if ( ratio[ iDir ] < 0.5 )
1608 aNorm[ iDir ] = gp_Vec2d( -tgt1.Y(), tgt1.X() ); // rotate tgt to the left
1610 aNorm[ iDir ] = gp_Vec2d( -tgt2.Y(), tgt2.X() );
1612 aNorm[ iDir ].Reverse(); // along iDir isoline
1614 double angle = tgt1.Angle( tgt2 ); // [-PI, PI]
1615 // maybe angle is more than |PI|
1616 if ( Abs( angle ) > PI / 2. ) {
1617 // check direction of the last but one perpendicular isoline
1618 TIsoNode* prevNode = bndNode2->GetNext( iDir, 0 );
1619 bndNode1 = prevNode->GetBoundaryNode( 1 - iDir, 0 );
1620 bndNode2 = prevNode->GetBoundaryNode( 1 - iDir, 1 );
1621 gp_Vec2d isoDir( bndNode1->myUV, bndNode2->myUV );
1622 if ( isoDir * tgt2 < 0 )
1624 double angle2 = tgt1.Angle( isoDir );
1625 //cout << " isoDir: "<< isoDir.X() <<" "<<isoDir.Y() << " ANGLE: "<< angle << " "<<angle2<<endl;
1626 if (angle2 * angle < 0 && // check the sign of an angle close to PI
1627 Abs ( Abs ( angle ) - PI ) <= PI / 180. ) {
1628 //MESSAGE("REVERSE ANGLE");
1631 if ( Abs( angle2 ) > Abs( angle ) ||
1632 ( angle2 * angle < 0 && Abs( angle2 ) > Abs( angle - angle2 ))) {
1633 //MESSAGE("Add PI");
1634 // cout << "NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<endl;
1635 // cout <<"ISO: " << isoParam << " " << (*iso2It).first << endl;
1636 // cout << "bndNode1: " << bndNode1->myUV.X()<<" "<<bndNode1->myUV.Y()<< endl;
1637 // cout << "bndNode2: " << bndNode2->myUV.X()<<" "<<bndNode2->myUV.Y()<<endl;
1638 // cout <<" tgt: " << tgt1.X()<<" "<<tgt1.Y()<<" "<< tgt2.X()<<" "<<tgt2.Y()<<endl;
1639 angle += ( angle < 0 ) ? 2. * PI : -2. * PI;
1642 aTgt[ iDir ] = tgt1.Rotated( angle * ratio[ iDir ] ).XY();
1646 for ( iDir = 0; iDir < 2; iDir++ )
1648 aTgt[iDir].Normalize();
1649 aNorm[1-iDir].Normalize();
1650 double r = Abs ( ratio[iDir] - 0.5 ) * 2.0; // [0,1] - distance from the middle
1653 node->myDir[iDir] = //aTgt[iDir];
1654 aNorm[1-iDir] * r + aTgt[iDir] * ( 1. - r );
1656 // cout << "NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<endl;
1657 // cout <<" tgt: " << tgt1.X()<<" "<<tgt1.Y()<<" - "<< tgt2.X()<<" "<<tgt2.Y()<<endl;
1658 // cout << " isoDir: "<< node->myDir[0].X() <<" "<<node->myDir[0].Y()<<" | "
1659 // << node->myDir[1].X() <<" "<<node->myDir[1].Y()<<endl;
1661 } // loop on iso nodes
1662 } // loop on isolines
1664 // Find nodes to start computing UV from
1666 list< TIsoNode* > startNodes;
1667 list< TIsoNode* >::iterator nIt = bndNodes.end();
1668 TIsoNode* node = *(--nIt);
1669 TIsoNode* prevNode = *(--nIt);
1670 for ( nIt = bndNodes.begin(); nIt != bndNodes.end(); nIt++ )
1672 TIsoNode* nextNode = *nIt;
1673 gp_Vec2d initTgt1( prevNode->myInitUV, node->myInitUV );
1674 gp_Vec2d initTgt2( node->myInitUV, nextNode->myInitUV );
1675 double initAngle = initTgt1.Angle( initTgt2 );
1676 double angle = node->myDir[0].Angle( node->myDir[1] );
1677 if ( reversed ) angle = -angle;
1678 if ( initAngle > angle && initAngle - angle > PI / 2.1 ) {
1679 // find a close internal node
1680 TIsoNode* nClose = 0;
1681 list< TIsoNode* > testNodes;
1682 testNodes.push_back( node );
1683 list< TIsoNode* >::iterator it = testNodes.begin();
1684 for ( ; !nClose && it != testNodes.end(); it++ )
1686 for (int i = 0; i < 4; i++ )
1688 nClose = (*it)->myNext[ i ];
1690 if ( !nClose->IsUVComputed() )
1693 testNodes.push_back( nClose );
1699 startNodes.push_back( nClose );
1700 // cout << "START: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<" UV: "<<
1701 // node->myUV.X()<<" "<<node->myUV.Y()<<endl<<
1702 // "initAngle: " << initAngle << " angle: " << angle << endl;
1703 // cout <<" init tgt: " << initTgt1.X()<<" "<<initTgt1.Y()<<" | "<< initTgt2.X()<<" "<<initTgt2.Y()<<endl;
1704 // cout << " tgt: "<< node->myDir[ 0 ].X() <<" "<<node->myDir[ 0 ].Y()<<" | "<<
1705 // node->myDir[ 1 ].X() <<" "<<node->myDir[ 1 ].Y()<<endl;
1706 // cout << "CLOSE: "<<nClose->myInitUV.X()<<" "<<nClose->myInitUV.Y()<<endl;
1712 // Compute starting UV of internal nodes
1714 list < TIsoNode* > internNodes;
1715 bool needIteration = true;
1716 if ( startNodes.empty() ) {
1717 MESSAGE( " Starting UV by compUVByIsoIntersection()");
1718 needIteration = false;
1719 map < double, TIsoLine >& isos = isoMap[ 0 ];
1720 map < double, TIsoLine >::iterator isoIt = isos.begin();
1721 for ( ; isoIt != isos.end(); isoIt++ )
1723 TIsoLine & isoLine = (*isoIt).second;
1724 TIsoLine::iterator nIt = isoLine.begin();
1725 for ( ; !needIteration && nIt != isoLine.end(); nIt++ )
1727 TIsoNode* node = *nIt;
1728 if ( !node->IsUVComputed() && node->IsMovable() ) {
1729 internNodes.push_back( node );
1731 if ( !compUVByIsoIntersection(theBndPoints, node->myInitUV,
1732 node->myUV, needIteration ))
1733 node->myUV = node->myInitUV;
1737 if ( needIteration )
1738 for ( nIt = bndNodes.begin(); nIt != bndNodes.end(); nIt++ )
1740 TIsoNode* node = *nIt, *nClose = 0;
1741 list< TIsoNode* > testNodes;
1742 testNodes.push_back( node );
1743 list< TIsoNode* >::iterator it = testNodes.begin();
1744 for ( ; !nClose && it != testNodes.end(); it++ )
1746 for (int i = 0; i < 4; i++ )
1748 nClose = (*it)->myNext[ i ];
1750 if ( !nClose->IsUVComputed() && nClose->IsMovable() )
1753 testNodes.push_back( nClose );
1759 startNodes.push_back( nClose );
1763 double aMin[2], aMax[2], step[2];
1764 uvBnd.Get( aMin[0], aMin[1], aMax[0], aMax[1] );
1765 double minUvSize = Min ( aMax[0]-aMin[0], aMax[1]-aMin[1] );
1766 step[0] = minUvSize / paramSet[ 0 ].size() / 10;
1767 step[1] = minUvSize / paramSet[ 1 ].size() / 10;
1768 //cout << "STEPS: " << step[0] << " " << step[1]<< endl;
1770 for ( nIt = startNodes.begin(); nIt != startNodes.end(); nIt++ )
1772 TIsoNode* prevN[2], *node = *nIt;
1773 if ( node->IsUVComputed() || !node->IsMovable() )
1775 gp_XY newUV( 0, 0 ), sumDir( 0, 0 );
1776 int nbComp = 0, nbPrev = 0;
1777 for ( iDir = 0; iDir < 2; iDir++ )
1779 TIsoNode* prevNode1 = 0, *prevNode2 = 0;
1780 TIsoNode* n = node->GetNext( iDir, 0 );
1781 if ( n->IsUVComputed() )
1784 startNodes.push_back( n );
1785 n = node->GetNext( iDir, 1 );
1786 if ( n->IsUVComputed() )
1789 startNodes.push_back( n );
1791 prevNode1 = prevNode2;
1794 if ( prevNode1 ) nbPrev++;
1795 if ( prevNode2 ) nbPrev++;
1798 double prevPar = prevNode1->myInitUV.Coord( 2 - iDir );
1799 double par = node->myInitUV.Coord( 2 - iDir );
1800 bool isEnd = ( prevPar > par );
1801 // dir = node->myDir[ 1 - iDir ].XY() * ( isEnd ? -1. : 1. );
1802 //cout << "__________"<<endl<< "NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<endl;
1803 TIsoNode* bndNode = node->GetBoundaryNode( iDir, isEnd );
1804 gp_XY tgt( bndNode->myDir[0].XY() + bndNode->myDir[1].XY() );
1805 dir.SetCoord( 1, tgt.Y() * ( reversed ? 1 : -1 ));
1806 dir.SetCoord( 2, tgt.X() * ( reversed ? -1 : 1 ));
1807 //cout << "bndNode UV: " << bndNode->myUV.X()<<" "<<bndNode->myUV.Y()<< endl;
1808 // cout << " tgt: "<< bndNode->myDir[ 0 ].X() <<" "<<bndNode->myDir[ 0 ].Y()<<" | "<<
1809 // bndNode->myDir[ 1 ].X() <<" "<<bndNode->myDir[ 1 ].Y()<<endl;
1810 //cout << "prevNode UV: " << prevNode1->myUV.X()<<" "<<prevNode1->myUV.Y()<<
1811 //" par: " << prevPar << endl;
1812 // cout <<" tgt: " << tgt.X()<<" "<<tgt.Y()<<endl;
1813 //cout << " DIR: "<< dir.X() <<" "<<dir.Y()<<endl;
1815 //cout << "____2next______"<<endl<< "NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<endl;
1816 gp_XY & uv1 = prevNode1->myUV;
1817 gp_XY & uv2 = prevNode2->myUV;
1818 // dir = ( uv2 - uv1 );
1819 // double len = dir.Modulus();
1820 // if ( len > DBL_MIN )
1821 // dir /= len * 0.5;
1822 double r = node->myRatio[ iDir ];
1823 newUV += uv1 * ( 1 - r ) + uv2 * r;
1826 newUV += prevNode1->myUV + dir * step[ iDir ];
1829 prevN[ iDir ] = prevNode1;
1835 //cout << "NODE: "<<node->myInitUV.X()<<" "<<node->myInitUV.Y()<<endl;
1837 // check if a quadrangle is not distorted
1839 //int crit = ( nbPrev == 4 ) ? FIX_OLD : CHECK_NEW_IN;
1840 if ( !checkQuads( node, newUV, reversed, FIX_OLD, step[0] + step[1] )) {
1841 //cout <<" newUV: " << node->myUV.X() << " "<<node->myUV.Y() << " nbPrev: "<<nbPrev<< endl;
1842 // cout << "_FIX_INIT_ fixedUV: " << newUV.X() << " "<<newUV.Y() << endl;
1846 internNodes.push_back( node );
1851 static int maxNbIter = 100;
1852 #ifdef DEB_COMPUVBYELASTICISOLINES
1854 bool useNbMoveNode = 0;
1855 static int maxNbNodeMove = 100;
1858 if ( !useNbMoveNode )
1859 maxNbIter = ( maxNbIter < 0 ) ? 100 : -1;
1864 if ( !needIteration) break;
1865 #ifdef DEB_COMPUVBYELASTICISOLINES
1866 if ( nbIter >= maxNbIter ) break;
1869 list < TIsoNode* >::iterator nIt = internNodes.begin();
1870 for ( ; nIt != internNodes.end(); nIt++ ) {
1871 #ifdef DEB_COMPUVBYELASTICISOLINES
1873 cout << nbNodeMove <<" =================================================="<<endl;
1875 TIsoNode * node = *nIt;
1879 for ( iDir = 0; iDir < 2; iDir++ )
1881 gp_XY & uv1 = node->GetNext( iDir, 0 )->myUV;
1882 gp_XY & uv2 = node->GetNext( iDir, 1 )->myUV;
1883 double r = node->myRatio[ iDir ];
1884 loc[ iDir ] = uv1 * ( 1 - r ) + uv2 * r;
1885 // line[ iDir ].SetLocation( loc[ iDir ] );
1886 // line[ iDir ].SetDirection( node->myDir[ iDir ] );
1889 double locR[2] = { 0, 0 };
1890 for ( iDir = 0; iDir < 2; iDir++ )
1892 const int iCoord = 2 - iDir; // coord changing along an isoline
1893 TIsoNode* bndNode1 = node->GetBoundaryNode( iDir, 0 );
1894 TIsoNode* bndNode2 = node->GetBoundaryNode( iDir, 1 );
1895 double par1 = bndNode1->myInitUV.Coord( iCoord );
1896 double par2 = node->myInitUV.Coord( iCoord );
1897 double par3 = bndNode2->myInitUV.Coord( iCoord );
1898 double r = ( par2 - par1 ) / ( par3 - par1 );
1899 r = Abs ( r - 0.5 ) * 2.0; // [0,1] - distance from the middle
1900 locR[ iDir ] = ( 1 - r * r ) * 0.25;
1902 //locR[0] = locR[1] = 0.25;
1903 // intersect the 2 lines and move a node
1904 //IntAna2d_AnaIntersection inter( line[0], line[1] );
1905 if ( /*inter.IsDone() && inter.NbPoints() ==*/ 1 )
1907 // double intR = 1 - locR[0] - locR[1];
1908 // gp_XY newUV = inter.Point(1).Value().XY();
1909 // if ( !checkQuads( node, newUV, reversed, CHECK_NEW_IN ))
1910 // newUV = ( locR[0] * loc[0] + locR[1] * loc[1] ) / ( 1 - intR );
1912 // newUV = intR * newUV + locR[0] * loc[0] + locR[1] * loc[1];
1913 gp_XY newUV = 0.5 * ( loc[0] + loc[1] );
1914 // avoid parallel isolines intersection
1915 checkQuads( node, newUV, reversed );
1917 maxMove = Max( maxMove, ( newUV - node->myUV ).SquareModulus());
1919 } // intersection found
1920 #ifdef DEB_COMPUVBYELASTICISOLINES
1921 if (useNbMoveNode && ++nbNodeMove >= maxNbNodeMove ) break;
1923 } // loop on internal nodes
1924 #ifdef DEB_COMPUVBYELASTICISOLINES
1925 if (useNbMoveNode && nbNodeMove >= maxNbNodeMove ) break;
1927 } while ( maxMove > 1e-8 && nbIter++ < maxNbIter );
1929 MESSAGE( "compUVByElasticIsolines(): Nb iterations " << nbIter << " dist: " << sqrt( maxMove ));
1931 if ( nbIter >= maxNbIter && sqrt(maxMove) > minUvSize * 0.05 ) {
1932 MESSAGE( "compUVByElasticIsolines() failed: "<<sqrt(maxMove)<<">"<<minUvSize * 0.05);
1933 #ifndef DEB_COMPUVBYELASTICISOLINES
1938 // Set computed UV to points
1940 for ( pIt = thePntToCompute.begin(); pIt != thePntToCompute.end(); pIt++ ) {
1941 TPoint* point = *pIt;
1942 //gp_XY oldUV = point->myUV;
1943 double minDist = DBL_MAX;
1944 list < TIsoNode >::iterator nIt = nodes.begin();
1945 for ( ; nIt != nodes.end(); nIt++ ) {
1946 double dist = ( (*nIt).myInitUV - point->myInitUV ).SquareModulus();
1947 if ( dist < minDist ) {
1949 point->myUV = (*nIt).myUV;
1959 //=======================================================================
1960 //function : setFirstEdge
1961 //purpose : choose the best first edge of theWire; return the summary distance
1962 // between point UV computed by isolines intersection and
1963 // eventual UV got from edge p-curves
1964 //=======================================================================
1966 //#define DBG_SETFIRSTEDGE
1967 double SMESH_Pattern::setFirstEdge (list< TopoDS_Edge > & theWire, int theFirstEdgeID)
1969 int iE, nbEdges = theWire.size();
1973 // Transform UVs computed by iso to fit bnd box of a wire
1975 // max nb of points on an edge
1977 int eID = theFirstEdgeID;
1978 for ( iE = 0; iE < nbEdges; iE++ )
1979 maxNbPnt = Max ( maxNbPnt, getShapePoints( eID++ ).size() );
1981 // compute bnd boxes
1982 TopoDS_Face face = TopoDS::Face( myShape );
1983 Bnd_Box2d bndBox, eBndBox;
1984 eID = theFirstEdgeID;
1985 list< TopoDS_Edge >::iterator eIt;
1986 list< TPoint* >::iterator pIt;
1987 for ( eIt = theWire.begin(); eIt != theWire.end(); eIt++ )
1989 // UV by isos stored in TPoint.myXYZ
1990 list< TPoint* > & ePoints = getShapePoints( eID++ );
1991 for ( pIt = ePoints.begin(); pIt != ePoints.end(); pIt++ ) {
1993 bndBox.Add( gp_Pnt2d( p->myXYZ.X(), p->myXYZ.Y() ));
1995 // UV by an edge p-curve
1997 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface( *eIt, face, f, l );
1998 double dU = ( l - f ) / ( maxNbPnt - 1 );
1999 for ( int i = 0; i < maxNbPnt; i++ )
2000 eBndBox.Add( C2d->Value( f + i * dU ));
2003 // transform UVs by isos
2004 double minPar[2], maxPar[2], eMinPar[2], eMaxPar[2];
2005 bndBox.Get( minPar[0], minPar[1], maxPar[0], maxPar[1] );
2006 eBndBox.Get( eMinPar[0], eMinPar[1], eMaxPar[0], eMaxPar[1] );
2007 #ifdef DBG_SETFIRSTEDGE
2008 cout << "EDGES: X: " << eMinPar[0] << " - " << eMaxPar[0] << " Y: "
2009 << eMinPar[1] << " - " << eMaxPar[1] << endl;
2011 for ( int iC = 1, i = 0; i < 2; iC++, i++ ) // loop on 2 coordinates
2013 double dMin = eMinPar[i] - minPar[i];
2014 double dMax = eMaxPar[i] - maxPar[i];
2015 double dPar = maxPar[i] - minPar[i];
2016 eID = theFirstEdgeID;
2017 for ( iE = 0; iE < nbEdges; iE++ ) // loop on edges of a boundary
2019 list< TPoint* > & ePoints = getShapePoints( eID++ );
2020 for ( pIt = ++ePoints.begin(); pIt != ePoints.end(); pIt++ ) // loop on edge points
2022 double par = (*pIt)->myXYZ.Coord( iC );
2023 double r = ( par - minPar[i] ) / dPar;
2024 par += ( 1 - r ) * dMin + r * dMax;
2025 (*pIt)->myXYZ.SetCoord( iC, par );
2031 double minDist = DBL_MAX;
2032 for ( iE = 0 ; iE < nbEdges; iE++ )
2034 #ifdef DBG_SETFIRSTEDGE
2035 cout << " VARIANT " << iE << endl;
2037 // evaluate the distance between UV computed by the 2 methods:
2038 // by isos intersection ( myXYZ ) and by edge p-curves ( myUV )
2040 int eID = theFirstEdgeID;
2041 for ( eIt = theWire.begin(); eIt != theWire.end(); eIt++ )
2043 list< TPoint* > & ePoints = getShapePoints( eID++ );
2044 computeUVOnEdge( *eIt, ePoints );
2045 for ( pIt = ++ePoints.begin(); pIt != ePoints.end(); pIt++ ) {
2047 dist += ( p->myUV - gp_XY( p->myXYZ.X(), p->myXYZ.Y() )).SquareModulus();
2048 #ifdef DBG_SETFIRSTEDGE
2049 cout << " ISO : ( " << p->myXYZ.X() << ", "<< p->myXYZ.Y() << " ) PCURVE : ( " <<
2050 p->myUV.X() << ", " << p->myUV.Y() << ") " << endl;
2054 #ifdef DBG_SETFIRSTEDGE
2055 cout << "dist -- " << dist << endl;
2057 if ( dist < minDist ) {
2059 eBest = theWire.front();
2061 // check variant with another first edge
2062 theWire.splice( theWire.begin(), theWire, --theWire.end(), theWire.end() );
2064 // put the best first edge to the theWire front
2065 if ( eBest != theWire.front() ) {
2066 eIt = find ( theWire.begin(), theWire.end(), eBest );
2067 theWire.splice( theWire.begin(), theWire, eIt, theWire.end() );
2073 //=======================================================================
2074 //function : sortSameSizeWires
2075 //purpose : sort wires in theWireList from theFromWire until theToWire,
2076 // the wires are set in the order to correspond to the order
2077 // of boundaries; after sorting, edges in the wires are put
2078 // in a good order, point UVs on edges are computed and points
2079 // are appended to theEdgesPointsList
2080 //=======================================================================
2082 bool SMESH_Pattern::sortSameSizeWires (TListOfEdgesList & theWireList,
2083 const TListOfEdgesList::iterator& theFromWire,
2084 const TListOfEdgesList::iterator& theToWire,
2085 const int theFirstEdgeID,
2086 list< list< TPoint* > >& theEdgesPointsList )
2088 TopoDS_Face F = TopoDS::Face( myShape );
2089 int iW, nbWires = 0;
2090 TListOfEdgesList::iterator wlIt = theFromWire;
2091 while ( wlIt++ != theToWire )
2094 // Recompute key-point UVs by isolines intersection,
2095 // compute CG of key-points for each wire and bnd boxes of GCs
2098 gp_XY orig( gp::Origin2d().XY() );
2099 vector< gp_XY > vGcVec( nbWires, orig ), gcVec( nbWires, orig );
2100 Bnd_Box2d bndBox, vBndBox;
2101 int eID = theFirstEdgeID;
2102 list< TopoDS_Edge >::iterator eIt;
2103 for ( iW = 0, wlIt = theFromWire; wlIt != theToWire; wlIt++, iW++ )
2105 list< TopoDS_Edge > & wire = *wlIt;
2106 for ( eIt = wire.begin(); eIt != wire.end(); eIt++ )
2108 list< TPoint* > & ePoints = getShapePoints( eID++ );
2109 TPoint* p = ePoints.front();
2110 if ( !compUVByIsoIntersection( theEdgesPointsList, p->myInitUV, p->myUV, aBool )) {
2111 MESSAGE("cant sortSameSizeWires()");
2114 gcVec[iW] += p->myUV;
2115 bndBox.Add( gp_Pnt2d( p->myUV ));
2116 TopoDS_Vertex V = TopExp::FirstVertex( *eIt, true );
2117 gp_Pnt2d vXY = BRep_Tool::Parameters( V, F );
2118 vGcVec[iW] += vXY.XY();
2120 // keep the computed UV to compare against by setFirstEdge()
2121 p->myXYZ.SetCoord( p->myUV.X(), p->myUV.Y(), 0. );
2123 gcVec[iW] /= nbWires;
2124 vGcVec[iW] /= nbWires;
2125 // cout << " Wire " << iW << " iso: " << gcVec[iW].X() << " " << gcVec[iW].Y() << endl <<
2126 // " \t vertex: " << vGcVec[iW].X() << " " << vGcVec[iW].Y() << endl;
2129 // Transform GCs computed by isos to fit in bnd box of GCs by vertices
2131 double minPar[2], maxPar[2], vMinPar[2], vMaxPar[2];
2132 bndBox.Get( minPar[0], minPar[1], maxPar[0], maxPar[1] );
2133 vBndBox.Get( vMinPar[0], vMinPar[1], vMaxPar[0], vMaxPar[1] );
2134 for ( int iC = 1, i = 0; i < 2; iC++, i++ ) // loop on 2 coordinates
2136 double dMin = vMinPar[i] - minPar[i];
2137 double dMax = vMaxPar[i] - maxPar[i];
2138 double dPar = maxPar[i] - minPar[i];
2139 if ( Abs( dPar ) <= DBL_MIN )
2141 for ( iW = 0; iW < nbWires; iW++ ) { // loop on GCs of wires
2142 double par = gcVec[iW].Coord( iC );
2143 double r = ( par - minPar[i] ) / dPar;
2144 par += ( 1 - r ) * dMin + r * dMax;
2145 gcVec[iW].SetCoord( iC, par );
2149 // Define boundary - wire correspondence by GC closeness
2151 TListOfEdgesList tmpWList;
2152 tmpWList.splice( tmpWList.end(), theWireList, theFromWire, theToWire );
2153 typedef map< int, TListOfEdgesList::iterator > TIntWirePosMap;
2154 TIntWirePosMap bndIndWirePosMap;
2155 vector< bool > bndFound( nbWires, false );
2156 for ( iW = 0, wlIt = tmpWList.begin(); iW < nbWires; iW++, wlIt++ )
2158 // cout << " TRSF Wire " << iW << " iso: " << gcVec[iW].X() << " " << gcVec[iW].Y() << endl <<
2159 // " \t vertex: " << vGcVec[iW].X() << " " << vGcVec[iW].Y() << endl;
2160 double minDist = DBL_MAX;
2161 gp_XY & wGc = vGcVec[ iW ];
2163 for ( int iB = 0; iB < nbWires; iB++ ) {
2164 if ( bndFound[ iB ] ) continue;
2165 double dist = ( wGc - gcVec[ iB ] ).SquareModulus();
2166 if ( dist < minDist ) {
2171 bndFound[ bIndex ] = true;
2172 bndIndWirePosMap.insert( TIntWirePosMap::value_type( bIndex, wlIt ));
2177 TIntWirePosMap::iterator bIndWPosIt = bndIndWirePosMap.begin();
2178 eID = theFirstEdgeID;
2179 for ( ; bIndWPosIt != bndIndWirePosMap.end(); bIndWPosIt++ )
2181 TListOfEdgesList::iterator wirePos = (*bIndWPosIt).second;
2182 list < TopoDS_Edge > & wire = ( *wirePos );
2184 // choose the best first edge of a wire
2185 setFirstEdge( wire, eID );
2187 // compute eventual UV and fill theEdgesPointsList
2188 theEdgesPointsList.push_back( list< TPoint* >() );
2189 list< TPoint* > & edgesPoints = theEdgesPointsList.back();
2190 for ( eIt = wire.begin(); eIt != wire.end(); eIt++ )
2192 list< TPoint* > & ePoints = getShapePoints( eID++ );
2193 computeUVOnEdge( *eIt, ePoints );
2194 edgesPoints.insert( edgesPoints.end(), ePoints.begin(), (--ePoints.end()));
2196 // put wire back to theWireList
2198 theWireList.splice( theToWire, tmpWList, wlIt, wirePos );
2204 //=======================================================================
2206 //purpose : Compute nodes coordinates applying
2207 // the loaded pattern to <theFace>. The first key-point
2208 // will be mapped into <theVertexOnKeyPoint1>
2209 //=======================================================================
2211 bool SMESH_Pattern::Apply (const TopoDS_Face& theFace,
2212 const TopoDS_Vertex& theVertexOnKeyPoint1,
2213 const bool theReverse)
2215 MESSAGE(" ::Apply(face) " );
2216 TopoDS_Face face = theReverse ? TopoDS::Face( theFace.Reversed() ) : theFace;
2217 if ( !setShapeToMesh( face ))
2220 // find points on edges, it fills myNbKeyPntInBoundary
2221 if ( !findBoundaryPoints() )
2224 // Define the edges order so that the first edge starts at
2225 // theVertexOnKeyPoint1
2227 list< TopoDS_Edge > eList;
2228 list< int > nbVertexInWires;
2229 int nbWires = getOrderedEdges( face, theVertexOnKeyPoint1, eList, nbVertexInWires);
2230 if ( !theVertexOnKeyPoint1.IsSame( TopExp::FirstVertex( eList.front(), true )))
2232 MESSAGE( " theVertexOnKeyPoint1 not found in the outer wire ");
2233 return setErrorCode( ERR_APPLF_BAD_VERTEX );
2235 // check nb wires and edges
2236 list< int > l1 = myNbKeyPntInBoundary, l2 = nbVertexInWires;
2237 l1.sort(); l2.sort();
2240 MESSAGE( "Wrong nb vertices in wires" );
2241 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
2244 // here shapes get IDs, for the outer wire IDs are OK
2245 list<TopoDS_Edge>::iterator elIt = eList.begin();
2246 for ( ; elIt != eList.end(); elIt++ ) {
2247 myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true ));
2248 if ( BRep_Tool::IsClosed( *elIt, theFace ) )
2249 myShapeIDMap.Add( TopExp::LastVertex( *elIt, true ));
2251 int nbVertices = myShapeIDMap.Extent();
2253 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
2254 myShapeIDMap.Add( *elIt );
2256 myShapeIDMap.Add( face );
2258 if ( myShapeIDToPointsMap.size() != myShapeIDMap.Extent()/* + nbSeamShapes*/ ) {
2259 MESSAGE( myShapeIDToPointsMap.size() <<" != " << myShapeIDMap.Extent());
2260 return setErrorCode( ERR_APPLF_INTERNAL_EEROR );
2263 // points on edges to be used for UV computation of in-face points
2264 list< list< TPoint* > > edgesPointsList;
2265 edgesPointsList.push_back( list< TPoint* >() );
2266 list< TPoint* > * edgesPoints = & edgesPointsList.back();
2267 list< TPoint* >::iterator pIt;
2269 // compute UV of points on the outer wire
2270 int iE, nbEdgesInOuterWire = nbVertexInWires.front();
2271 for (iE = 0, elIt = eList.begin();
2272 iE < nbEdgesInOuterWire && elIt != eList.end();
2275 list< TPoint* > & ePoints = getShapePoints( *elIt );
2277 computeUVOnEdge( *elIt, ePoints );
2278 // collect on-edge points (excluding the last one)
2279 edgesPoints->insert( edgesPoints->end(), ePoints.begin(), --ePoints.end());
2282 // If there are several wires, define the order of edges of inner wires:
2283 // compute UV of inner edge-points using 2 methods: the one for in-face points
2284 // and the one for on-edge points and then choose the best edge order
2285 // by the best correspondance of the 2 results
2288 // compute UV of inner edge-points using the method for in-face points
2289 // and devide eList into a list of separate wires
2291 list< list< TopoDS_Edge > > wireList;
2292 list<TopoDS_Edge>::iterator eIt = elIt;
2293 list<int>::iterator nbEIt = nbVertexInWires.begin();
2294 for ( nbEIt++; nbEIt != nbVertexInWires.end(); nbEIt++ )
2296 int nbEdges = *nbEIt;
2297 wireList.push_back( list< TopoDS_Edge >() );
2298 list< TopoDS_Edge > & wire = wireList.back();
2299 for ( iE = 0 ; iE < nbEdges; eIt++, iE++ )
2301 list< TPoint* > & ePoints = getShapePoints( *eIt );
2302 pIt = ePoints.begin();
2303 for ( pIt++; pIt != ePoints.end(); pIt++ ) {
2305 if ( !compUVByIsoIntersection( edgesPointsList, p->myInitUV, p->myUV, aBool )) {
2306 MESSAGE("cant Apply(face)");
2309 // keep the computed UV to compare against by setFirstEdge()
2310 p->myXYZ.SetCoord( p->myUV.X(), p->myUV.Y(), 0. );
2312 wire.push_back( *eIt );
2315 // remove inner edges from eList
2316 eList.erase( elIt, eList.end() );
2318 // sort wireList by nb edges in a wire
2319 sortBySize< TopoDS_Edge > ( wireList );
2321 // an ID of the first edge of a boundary
2322 int id1 = nbVertices + nbEdgesInOuterWire + 1;
2323 // if ( nbSeamShapes > 0 )
2324 // id1 += 2; // 2 vertices more
2326 // find points - edge correspondence for wires of unique size,
2327 // edge order within a wire should be defined only
2329 list< list< TopoDS_Edge > >::iterator wlIt = wireList.begin();
2330 while ( wlIt != wireList.end() )
2332 list< TopoDS_Edge >& wire = (*wlIt);
2333 int nbEdges = wire.size();
2335 if ( wlIt == wireList.end() || (*wlIt).size() != nbEdges ) // a unique size wire
2337 // choose the best first edge of a wire
2338 setFirstEdge( wire, id1 );
2340 // compute eventual UV and collect on-edge points
2341 edgesPointsList.push_back( list< TPoint* >() );
2342 edgesPoints = & edgesPointsList.back();
2344 for ( eIt = wire.begin(); eIt != wire.end(); eIt++ )
2346 list< TPoint* > & ePoints = getShapePoints( eID++ );
2347 computeUVOnEdge( *eIt, ePoints );
2348 edgesPoints->insert( edgesPoints->end(), ePoints.begin(), (--ePoints.end()));
2354 // find boundary - wire correspondence for several wires of same size
2356 id1 = nbVertices + nbEdgesInOuterWire + 1;
2357 wlIt = wireList.begin();
2358 while ( wlIt != wireList.end() )
2360 int nbSameSize = 0, nbEdges = (*wlIt).size();
2361 list< list< TopoDS_Edge > >::iterator wlIt2 = wlIt;
2363 while ( wlIt2 != wireList.end() && (*wlIt2).size() == nbEdges ) { // a same size wire
2367 if ( nbSameSize > 0 )
2368 if (!sortSameSizeWires(wireList, wlIt, wlIt2, id1, edgesPointsList))
2371 id1 += nbEdges * ( nbSameSize + 1 );
2374 // add well-ordered edges to eList
2376 for ( wlIt = wireList.begin(); wlIt != wireList.end(); wlIt++ )
2378 list< TopoDS_Edge >& wire = (*wlIt);
2379 eList.splice( eList.end(), wire, wire.begin(), wire.end() );
2382 // re-fill myShapeIDMap - all shapes get good IDs
2384 myShapeIDMap.Clear();
2385 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
2386 myShapeIDMap.Add( TopExp::FirstVertex( *elIt, true ));
2387 for ( elIt = eList.begin(); elIt != eList.end(); elIt++ )
2388 myShapeIDMap.Add( *elIt );
2389 myShapeIDMap.Add( face );
2391 } // there are inner wires
2393 // Compute XYZ of on-edge points
2395 TopLoc_Location loc;
2396 for ( iE = nbVertices + 1, elIt = eList.begin(); elIt != eList.end(); elIt++ )
2399 Handle(Geom_Curve) C3d = BRep_Tool::Curve( *elIt, loc, f, l );
2400 const gp_Trsf & aTrsf = loc.Transformation();
2401 list< TPoint* > & ePoints = getShapePoints( iE++ );
2402 pIt = ePoints.begin();
2403 for ( pIt++; pIt != ePoints.end(); pIt++ )
2405 TPoint* point = *pIt;
2406 point->myXYZ = C3d->Value( point->myU );
2407 if ( !loc.IsIdentity() )
2408 aTrsf.Transforms( point->myXYZ.ChangeCoord() );
2412 // Compute UV and XYZ of in-face points
2414 // try to use a simple algo
2415 list< TPoint* > & fPoints = getShapePoints( face );
2416 bool isDeformed = false;
2417 for ( pIt = fPoints.begin(); !isDeformed && pIt != fPoints.end(); pIt++ )
2418 if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV,
2419 (*pIt)->myUV, isDeformed )) {
2420 MESSAGE("cant Apply(face)");
2423 // try to use a complex algo if it is a difficult case
2424 if ( isDeformed && !compUVByElasticIsolines( edgesPointsList, fPoints ))
2426 for ( ; pIt != fPoints.end(); pIt++ ) // continue with the simple algo
2427 if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV,
2428 (*pIt)->myUV, isDeformed )) {
2429 MESSAGE("cant Apply(face)");
2434 Handle(Geom_Surface) aSurface = BRep_Tool::Surface( face, loc );
2435 const gp_Trsf & aTrsf = loc.Transformation();
2436 for ( pIt = fPoints.begin(); pIt != fPoints.end(); pIt++ )
2438 TPoint * point = *pIt;
2439 point->myXYZ = aSurface->Value( point->myUV.X(), point->myUV.Y() );
2440 if ( !loc.IsIdentity() )
2441 aTrsf.Transforms( point->myXYZ.ChangeCoord() );
2444 myIsComputed = true;
2446 return setErrorCode( ERR_OK );
2449 //=======================================================================
2451 //purpose : Compute nodes coordinates applying
2452 // the loaded pattern to <theFace>. The first key-point
2453 // will be mapped into <theNodeIndexOnKeyPoint1>-th node
2454 //=======================================================================
2456 bool SMESH_Pattern::Apply (const SMDS_MeshFace* theFace,
2457 const int theNodeIndexOnKeyPoint1,
2458 const bool theReverse)
2460 // MESSAGE(" ::Apply(MeshFace) " );
2462 if ( !IsLoaded() ) {
2463 MESSAGE( "Pattern not loaded" );
2464 return setErrorCode( ERR_APPL_NOT_LOADED );
2467 // check nb of nodes
2468 if (theFace->NbNodes() != myNbKeyPntInBoundary.front() ) {
2469 MESSAGE( myKeyPointIDs.size() << " != " << theFace->NbNodes() );
2470 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
2473 // find points on edges, it fills myNbKeyPntInBoundary
2474 if ( !findBoundaryPoints() )
2477 // check that there are no holes in a pattern
2478 if (myNbKeyPntInBoundary.size() > 1 ) {
2479 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
2482 // Define the nodes order
2484 list< const SMDS_MeshNode* > nodes;
2485 list< const SMDS_MeshNode* >::iterator n = nodes.end();
2486 SMDS_ElemIteratorPtr noIt = theFace->nodesIterator();
2488 while ( noIt->more() ) {
2489 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( noIt->next() );
2490 nodes.push_back( node );
2491 if ( iSub++ == theNodeIndexOnKeyPoint1 )
2494 if ( n != nodes.end() ) {
2496 if ( n != --nodes.end() )
2497 nodes.splice( nodes.begin(), nodes, ++n, nodes.end() );
2500 else if ( n != nodes.begin() )
2501 nodes.splice( nodes.end(), nodes, nodes.begin(), n );
2503 list< gp_XYZ > xyzList;
2504 myOrderedNodes.resize( theFace->NbNodes() );
2505 for ( iSub = 0, n = nodes.begin(); n != nodes.end(); ++n ) {
2506 xyzList.push_back( gp_XYZ( (*n)->X(), (*n)->Y(), (*n)->Z() ));
2507 myOrderedNodes[ iSub++] = *n;
2510 // Define a face plane
2512 list< gp_XYZ >::iterator xyzIt = xyzList.begin();
2513 gp_Pnt P ( *xyzIt++ );
2514 gp_Vec Vx( P, *xyzIt++ ), N;
2516 N = Vx ^ gp_Vec( P, *xyzIt++ );
2517 } while ( N.SquareMagnitude() <= DBL_MIN && xyzIt != xyzList.end() );
2518 if ( N.SquareMagnitude() <= DBL_MIN )
2519 return setErrorCode( ERR_APPLF_BAD_FACE_GEOM );
2520 gp_Ax2 pos( P, N, Vx );
2522 // Compute UV of key-points on a plane
2523 for ( xyzIt = xyzList.begin(), iSub = 1; xyzIt != xyzList.end(); xyzIt++, iSub++ )
2525 gp_Vec vec ( pos.Location(), *xyzIt );
2526 TPoint* p = getShapePoints( iSub ).front();
2527 p->myUV.SetX( vec * pos.XDirection() );
2528 p->myUV.SetY( vec * pos.YDirection() );
2532 // points on edges to be used for UV computation of in-face points
2533 list< list< TPoint* > > edgesPointsList;
2534 edgesPointsList.push_back( list< TPoint* >() );
2535 list< TPoint* > * edgesPoints = & edgesPointsList.back();
2536 list< TPoint* >::iterator pIt;
2538 // compute UV and XYZ of points on edges
2540 for ( xyzIt = xyzList.begin(); xyzIt != xyzList.end(); iSub++ )
2542 gp_XYZ& xyz1 = *xyzIt++;
2543 gp_XYZ& xyz2 = ( xyzIt != xyzList.end() ) ? *xyzIt : xyzList.front();
2545 list< TPoint* > & ePoints = getShapePoints( iSub );
2546 ePoints.back()->myInitU = 1.0;
2547 list< TPoint* >::const_iterator pIt = ++ePoints.begin();
2548 while ( *pIt != ePoints.back() )
2551 p->myXYZ = xyz1 * ( 1 - p->myInitU ) + xyz2 * p->myInitU;
2552 gp_Vec vec ( pos.Location(), p->myXYZ );
2553 p->myUV.SetX( vec * pos.XDirection() );
2554 p->myUV.SetY( vec * pos.YDirection() );
2556 // collect on-edge points (excluding the last one)
2557 edgesPoints->insert( edgesPoints->end(), ePoints.begin(), --ePoints.end());
2560 // Compute UV and XYZ of in-face points
2562 // try to use a simple algo to compute UV
2563 list< TPoint* > & fPoints = getShapePoints( iSub );
2564 bool isDeformed = false;
2565 for ( pIt = fPoints.begin(); !isDeformed && pIt != fPoints.end(); pIt++ )
2566 if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV,
2567 (*pIt)->myUV, isDeformed )) {
2568 MESSAGE("cant Apply(face)");
2571 // try to use a complex algo if it is a difficult case
2572 if ( isDeformed && !compUVByElasticIsolines( edgesPointsList, fPoints ))
2574 for ( ; pIt != fPoints.end(); pIt++ ) // continue with the simple algo
2575 if ( !compUVByIsoIntersection( edgesPointsList, (*pIt)->myInitUV,
2576 (*pIt)->myUV, isDeformed )) {
2577 MESSAGE("cant Apply(face)");
2582 for ( pIt = fPoints.begin(); pIt != fPoints.end(); pIt++ )
2584 (*pIt)->myXYZ = ElSLib::PlaneValue( (*pIt)->myUV.X(), (*pIt)->myUV.Y(), pos );
2587 myIsComputed = true;
2589 return setErrorCode( ERR_OK );
2592 //=======================================================================
2593 //function : undefinedXYZ
2595 //=======================================================================
2597 static const gp_XYZ& undefinedXYZ()
2599 static gp_XYZ xyz( 1.e100, 0., 0. );
2603 //=======================================================================
2604 //function : isDefined
2606 //=======================================================================
2608 inline static bool isDefined(const gp_XYZ& theXYZ)
2610 return theXYZ.X() < 1.e100;
2613 //=======================================================================
2615 //purpose : Compute nodes coordinates applying
2616 // the loaded pattern to <theFaces>. The first key-point
2617 // will be mapped into <theNodeIndexOnKeyPoint1>-th node
2618 //=======================================================================
2620 bool SMESH_Pattern::Apply (std::set<const SMDS_MeshFace*>& theFaces,
2621 const int theNodeIndexOnKeyPoint1,
2622 const bool theReverse)
2624 MESSAGE(" ::Apply(set<MeshFace>) " );
2626 if ( !IsLoaded() ) {
2627 MESSAGE( "Pattern not loaded" );
2628 return setErrorCode( ERR_APPL_NOT_LOADED );
2631 // find points on edges, it fills myNbKeyPntInBoundary
2632 if ( !findBoundaryPoints() )
2635 // check that there are no holes in a pattern
2636 if (myNbKeyPntInBoundary.size() > 1 ) {
2637 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
2642 myElemXYZIDs.clear();
2643 myXYZIdToNodeMap.clear();
2645 myIdsOnBoundary.clear();
2646 myReverseConnectivity.clear();
2648 myXYZ.resize( myPoints.size() * theFaces.size(), undefinedXYZ() );
2649 myElements.reserve( theFaces.size() );
2651 // to find point index
2652 map< TPoint*, int > pointIndex;
2653 for ( int i = 0; i < myPoints.size(); i++ )
2654 pointIndex.insert( make_pair( & myPoints[ i ], i ));
2656 int ind1 = 0; // lowest point index for a face
2658 // apply to each face in theFaces set
2659 set<const SMDS_MeshFace*>::iterator face = theFaces.begin();
2660 for ( ; face != theFaces.end(); ++face )
2662 if ( !Apply( *face, theNodeIndexOnKeyPoint1, theReverse )) {
2663 MESSAGE( "Failed on " << *face );
2666 myElements.push_back( *face );
2668 // store computed points belonging to elements
2669 list< TElemDef >::iterator ll = myElemPointIDs.begin();
2670 for ( ; ll != myElemPointIDs.end(); ++ll )
2672 myElemXYZIDs.push_back(TElemDef());
2673 TElemDef& xyzIds = myElemXYZIDs.back();
2674 TElemDef& pIds = *ll;
2675 for ( TElemDef::iterator id = pIds.begin(); id != pIds.end(); id++ ) {
2676 int pIndex = *id + ind1;
2677 xyzIds.push_back( pIndex );
2678 myXYZ[ pIndex ] = myPoints[ *id ].myXYZ.XYZ();
2679 myReverseConnectivity[ pIndex ].push_back( & xyzIds );
2682 // put points on links to myIdsOnBoundary,
2683 // they will be used to sew new elements on adjacent refined elements
2684 int nbNodes = (*face)->NbNodes(), eID = nbNodes + 1;
2685 for ( int i = 0; i < nbNodes; i++ )
2687 list< TPoint* > & linkPoints = getShapePoints( eID++ );
2688 const SMDS_MeshNode* n1 = myOrderedNodes[ i ];
2689 const SMDS_MeshNode* n2 = myOrderedNodes[ i + 1 == nbNodes ? 0 : i + 1 ];
2690 // make a link and a node set
2691 TNodeSet linkSet, node1Set;
2692 linkSet.insert( n1 );
2693 linkSet.insert( n2 );
2694 node1Set.insert( n1 );
2695 list< TPoint* >::iterator p = linkPoints.begin();
2697 // map the first link point to n1
2698 int nId = pointIndex[ *p ] + ind1;
2699 myXYZIdToNodeMap[ nId ] = n1;
2700 list< list< int > >& groups = myIdsOnBoundary[ node1Set ];
2701 groups.push_back(list< int > ());
2702 groups.back().push_back( nId );
2704 // add the linkSet to the map
2705 list< list< int > >& groups = myIdsOnBoundary[ linkSet ];
2706 groups.push_back(list< int > ());
2707 list< int >& indList = groups.back();
2708 // add points to the map excluding the end points
2709 for ( p++; *p != linkPoints.back(); p++ )
2710 indList.push_back( pointIndex[ *p ] + ind1 );
2712 ind1 += myPoints.size();
2715 return !myElemXYZIDs.empty();
2718 //=======================================================================
2720 //purpose : Compute nodes coordinates applying
2721 // the loaded pattern to <theVolumes>. The (0,0,0) key-point
2722 // will be mapped into <theNode000Index>-th node. The
2723 // (0,0,1) key-point will be mapped into <theNode000Index>-th
2725 //=======================================================================
2727 bool SMESH_Pattern::Apply (std::set<const SMDS_MeshVolume*> & theVolumes,
2728 const int theNode000Index,
2729 const int theNode001Index)
2731 MESSAGE(" ::Apply(set<MeshVolumes>) " );
2733 if ( !IsLoaded() ) {
2734 MESSAGE( "Pattern not loaded" );
2735 return setErrorCode( ERR_APPL_NOT_LOADED );
2738 // bind ID to points
2739 if ( !findBoundaryPoints() )
2742 // check that there are no holes in a pattern
2743 if (myNbKeyPntInBoundary.size() > 1 ) {
2744 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
2749 myElemXYZIDs.clear();
2750 myXYZIdToNodeMap.clear();
2752 myIdsOnBoundary.clear();
2753 myReverseConnectivity.clear();
2755 myXYZ.resize( myPoints.size() * theVolumes.size(), undefinedXYZ() );
2756 myElements.reserve( theVolumes.size() );
2758 // to find point index
2759 map< TPoint*, int > pointIndex;
2760 for ( int i = 0; i < myPoints.size(); i++ )
2761 pointIndex.insert( make_pair( & myPoints[ i ], i ));
2763 int ind1 = 0; // lowest point index for an element
2765 // apply to each element in theVolumes set
2766 set<const SMDS_MeshVolume*>::iterator vol = theVolumes.begin();
2767 for ( ; vol != theVolumes.end(); ++vol )
2769 if ( !Apply( *vol, theNode000Index, theNode001Index )) {
2770 MESSAGE( "Failed on " << *vol );
2773 myElements.push_back( *vol );
2775 // store computed points belonging to elements
2776 list< TElemDef >::iterator ll = myElemPointIDs.begin();
2777 for ( ; ll != myElemPointIDs.end(); ++ll )
2779 myElemXYZIDs.push_back(TElemDef());
2780 TElemDef& xyzIds = myElemXYZIDs.back();
2781 TElemDef& pIds = *ll;
2782 for ( TElemDef::iterator id = pIds.begin(); id != pIds.end(); id++ ) {
2783 int pIndex = *id + ind1;
2784 xyzIds.push_back( pIndex );
2785 myXYZ[ pIndex ] = myPoints[ *id ].myXYZ.XYZ();
2786 myReverseConnectivity[ pIndex ].push_back( & xyzIds );
2789 // put points on edges and faces to myIdsOnBoundary,
2790 // they will be used to sew new elements on adjacent refined elements
2791 for ( int Id = SMESH_Block::ID_V000; Id <= SMESH_Block::ID_F1yz; Id++ )
2793 // make a set of sub-points
2795 vector< int > subIDs;
2796 if ( SMESH_Block::IsVertexID( Id )) {
2797 subNodes.insert( myOrderedNodes[ Id - 1 ]);
2799 else if ( SMESH_Block::IsEdgeID( Id )) {
2800 SMESH_Block::GetEdgeVertexIDs( Id, subIDs );
2801 subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]);
2802 subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]);
2805 SMESH_Block::GetFaceEdgesIDs( Id, subIDs );
2806 int e1 = subIDs[ 0 ], e2 = subIDs[ 1 ];
2807 SMESH_Block::GetEdgeVertexIDs( e1, subIDs );
2808 subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]);
2809 subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]);
2810 SMESH_Block::GetEdgeVertexIDs( e2, subIDs );
2811 subNodes.insert( myOrderedNodes[ subIDs.front() - 1 ]);
2812 subNodes.insert( myOrderedNodes[ subIDs.back() - 1 ]);
2815 list< TPoint* > & points = getShapePoints( Id );
2816 list< TPoint* >::iterator p = points.begin();
2817 list< list< int > >& groups = myIdsOnBoundary[ subNodes ];
2818 groups.push_back(list< int > ());
2819 list< int >& indList = groups.back();
2820 for ( ; p != points.end(); p++ )
2821 indList.push_back( pointIndex[ *p ] + ind1 );
2822 if ( subNodes.size() == 1 ) // vertex case
2823 myXYZIdToNodeMap[ indList.back() ] = myOrderedNodes[ Id - 1 ];
2825 ind1 += myPoints.size();
2828 return !myElemXYZIDs.empty();
2831 //=======================================================================
2833 //purpose : Create a pattern from the mesh built on <theBlock>
2834 //=======================================================================
2836 bool SMESH_Pattern::Load (SMESH_Mesh* theMesh,
2837 const TopoDS_Shell& theBlock)
2839 MESSAGE(" ::Load(volume) " );
2842 SMESHDS_Mesh * aMeshDS = theMesh->GetMeshDS();
2844 // load shapes in myShapeIDMap
2846 TopoDS_Vertex v1, v2;
2847 if ( !block.LoadBlockShapes( theBlock, v1, v2, myShapeIDMap ))
2848 return setErrorCode( ERR_LOADV_BAD_SHAPE );
2851 int nbNodes = 0, shapeID;
2852 for ( shapeID = 1; shapeID <= myShapeIDMap.Extent(); shapeID++ )
2854 const TopoDS_Shape& S = myShapeIDMap( shapeID );
2855 SMESHDS_SubMesh * aSubMesh = aMeshDS->MeshElements( S );
2857 nbNodes += aSubMesh->NbNodes();
2859 myPoints.resize( nbNodes );
2861 // load U of points on edges
2862 TNodePointIDMap nodePointIDMap;
2864 for ( shapeID = 1; shapeID <= myShapeIDMap.Extent(); shapeID++ )
2866 const TopoDS_Shape& S = myShapeIDMap( shapeID );
2867 list< TPoint* > & shapePoints = getShapePoints( shapeID );
2868 SMESHDS_SubMesh * aSubMesh = aMeshDS->MeshElements( S );
2869 if ( ! aSubMesh ) continue;
2870 SMDS_NodeIteratorPtr nIt = aSubMesh->GetNodes();
2871 if ( !nIt->more() ) continue;
2873 // store a node and a point
2874 while ( nIt->more() ) {
2875 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nIt->next() );
2876 nodePointIDMap.insert( make_pair( node, iPoint ));
2877 if ( block.IsVertexID( shapeID ))
2878 myKeyPointIDs.push_back( iPoint );
2879 TPoint* p = & myPoints[ iPoint++ ];
2880 shapePoints.push_back( p );
2881 p->myXYZ.SetCoord( node->X(), node->Y(), node->Z() );
2882 p->myInitXYZ.SetCoord( 0,0,0 );
2884 list< TPoint* >::iterator pIt = shapePoints.begin();
2887 switch ( S.ShapeType() )
2892 for ( ; pIt != shapePoints.end(); pIt++ ) {
2893 double * coef = block.GetShapeCoef( shapeID );
2894 for ( int iCoord = 1; iCoord <= 3; iCoord++ )
2895 if ( coef[ iCoord - 1] > 0 )
2896 (*pIt)->myInitXYZ.SetCoord( iCoord, 1. );
2898 if ( S.ShapeType() == TopAbs_VERTEX )
2901 const TopoDS_Edge& edge = TopoDS::Edge( S );
2903 BRep_Tool::Range( edge, f, l );
2904 int iCoord = SMESH_Block::GetCoordIndOnEdge( shapeID );
2905 bool isForward = SMESH_Block::IsForwardEdge( edge, myShapeIDMap );
2906 pIt = shapePoints.begin();
2907 nIt = aSubMesh->GetNodes();
2908 for ( ; nIt->more(); pIt++ )
2910 const SMDS_MeshNode* node =
2911 static_cast<const SMDS_MeshNode*>( nIt->next() );
2912 const SMDS_EdgePosition* epos =
2913 static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
2914 double u = ( epos->GetUParameter() - f ) / ( l - f );
2915 (*pIt)->myInitXYZ.SetCoord( iCoord, isForward ? u : 1 - u );
2920 for ( ; pIt != shapePoints.end(); pIt++ )
2922 if ( !block.ComputeParameters( (*pIt)->myXYZ, (*pIt)->myInitXYZ, shapeID )) {
2923 MESSAGE( "!block.ComputeParameters()" );
2924 return setErrorCode( ERR_LOADV_COMPUTE_PARAMS );
2928 } // loop on block sub-shapes
2932 SMESHDS_SubMesh * aSubMesh = aMeshDS->MeshElements( theBlock );
2935 SMDS_ElemIteratorPtr elemIt = aSubMesh->GetElements();
2936 while ( elemIt->more() ) {
2937 SMDS_ElemIteratorPtr nIt = elemIt->next()->nodesIterator();
2938 myElemPointIDs.push_back( TElemDef() );
2939 TElemDef& elemPoints = myElemPointIDs.back();
2940 while ( nIt->more() )
2941 elemPoints.push_back( nodePointIDMap[ nIt->next() ]);
2945 myIsBoundaryPointsFound = true;
2947 return setErrorCode( ERR_OK );
2950 //=======================================================================
2952 //purpose : Compute nodes coordinates applying
2953 // the loaded pattern to <theBlock>. The (0,0,0) key-point
2954 // will be mapped into <theVertex000>. The (0,0,1)
2955 // fifth key-point will be mapped into <theVertex001>.
2956 //=======================================================================
2958 bool SMESH_Pattern::Apply (const TopoDS_Shell& theBlock,
2959 const TopoDS_Vertex& theVertex000,
2960 const TopoDS_Vertex& theVertex001)
2962 MESSAGE(" ::Apply(volume) " );
2964 if (!findBoundaryPoints() || // bind ID to points
2965 !setShapeToMesh( theBlock )) // check theBlock is a suitable shape
2968 SMESH_Block block; // bind ID to shape
2969 if (!block.LoadBlockShapes( theBlock, theVertex000, theVertex001, myShapeIDMap ))
2970 return setErrorCode( ERR_APPLV_BAD_SHAPE );
2972 // compute XYZ of points on shapes
2974 for ( int shapeID = 1; shapeID <= myShapeIDMap.Extent(); shapeID++ )
2976 list< TPoint* > & shapePoints = getShapePoints( shapeID );
2977 list< TPoint* >::iterator pIt = shapePoints.begin();
2978 const TopoDS_Shape& S = myShapeIDMap( shapeID );
2979 switch ( S.ShapeType() )
2981 case TopAbs_VERTEX: {
2983 for ( ; pIt != shapePoints.end(); pIt++ )
2984 block.VertexPoint( shapeID, (*pIt)->myXYZ.ChangeCoord() );
2989 for ( ; pIt != shapePoints.end(); pIt++ )
2990 block.EdgePoint( shapeID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
2995 for ( ; pIt != shapePoints.end(); pIt++ )
2996 block.FacePoint( shapeID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
3000 for ( ; pIt != shapePoints.end(); pIt++ )
3001 block.ShellPoint( (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
3003 } // loop on block sub-shapes
3005 myIsComputed = true;
3007 return setErrorCode( ERR_OK );
3010 //=======================================================================
3012 //purpose : Compute nodes coordinates applying
3013 // the loaded pattern to <theVolume>. The (0,0,0) key-point
3014 // will be mapped into <theNode000Index>-th node. The
3015 // (0,0,1) key-point will be mapped into <theNode000Index>-th
3017 //=======================================================================
3019 bool SMESH_Pattern::Apply (const SMDS_MeshVolume* theVolume,
3020 const int theNode000Index,
3021 const int theNode001Index)
3023 //MESSAGE(" ::Apply(MeshVolume) " );
3025 if (!findBoundaryPoints()) // bind ID to points
3028 SMESH_Block block; // bind ID to shape
3029 if (!block.LoadMeshBlock( theVolume, theNode000Index, theNode001Index, myOrderedNodes ))
3030 return setErrorCode( ERR_APPLV_BAD_SHAPE );
3031 // compute XYZ of points on shapes
3033 for ( int ID = SMESH_Block::ID_V000; ID <= SMESH_Block::ID_Shell; ID++ )
3035 list< TPoint* > & shapePoints = getShapePoints( ID );
3036 list< TPoint* >::iterator pIt = shapePoints.begin();
3038 if ( block.IsVertexID( ID ))
3039 for ( ; pIt != shapePoints.end(); pIt++ ) {
3040 block.VertexPoint( ID, (*pIt)->myXYZ.ChangeCoord() );
3042 else if ( block.IsEdgeID( ID ))
3043 for ( ; pIt != shapePoints.end(); pIt++ ) {
3044 block.EdgePoint( ID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
3046 else if ( block.IsFaceID( ID ))
3047 for ( ; pIt != shapePoints.end(); pIt++ ) {
3048 block.FacePoint( ID, (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
3051 for ( ; pIt != shapePoints.end(); pIt++ )
3052 block.ShellPoint( (*pIt)->myInitXYZ, (*pIt)->myXYZ.ChangeCoord() );
3053 } // loop on block sub-shapes
3055 myIsComputed = true;
3057 return setErrorCode( ERR_OK );
3060 //=======================================================================
3061 //function : mergePoints
3062 //purpose : Merge XYZ on edges and/or faces.
3063 //=======================================================================
3065 void SMESH_Pattern::mergePoints (const bool uniteGroups)
3067 map< TNodeSet, list< list< int > > >::iterator idListIt = myIdsOnBoundary.begin();
3068 for ( ; idListIt != myIdsOnBoundary.end(); idListIt++ )
3070 list<list< int > >& groups = idListIt->second;
3071 if ( groups.size() < 2 )
3075 const TNodeSet& nodes = idListIt->first;
3076 double tol2 = 1.e-10;
3077 if ( nodes.size() > 1 ) {
3079 TNodeSet::const_iterator n = nodes.begin();
3080 for ( ; n != nodes.end(); ++n )
3081 box.Add( gp_Pnt( (*n)->X(), (*n)->Y(), (*n)->Z() ));
3082 double x, y, z, X, Y, Z;
3083 box.Get( x, y, z, X, Y, Z );
3084 gp_Pnt p( x, y, z ), P( X, Y, Z );
3085 tol2 = 1.e-4 * p.SquareDistance( P );
3088 // to unite groups on link
3089 bool unite = ( uniteGroups && nodes.size() == 2 );
3090 map< double, int > distIndMap;
3091 const SMDS_MeshNode* node = *nodes.begin();
3092 gp_Pnt P( node->X(), node->Y(), node->Z() );
3094 // compare points, replace indices
3096 list< int >::iterator ind1, ind2;
3097 list< list< int > >::iterator grpIt1, grpIt2;
3098 for ( grpIt1 = groups.begin(); grpIt1 != groups.end(); grpIt1++ )
3100 list< int >& indices1 = *grpIt1;
3102 for ( grpIt2++; grpIt2 != groups.end(); grpIt2++ )
3104 list< int >& indices2 = *grpIt2;
3105 for ( ind1 = indices1.begin(); ind1 != indices1.end(); ind1++ )
3107 gp_XYZ& p1 = myXYZ[ *ind1 ];
3108 ind2 = indices2.begin();
3109 while ( ind2 != indices2.end() )
3111 gp_XYZ& p2 = myXYZ[ *ind2 ];
3112 //MESSAGE("COMP: " << *ind1 << " " << *ind2 << " X: " << p2.X() << " tol2: " << tol2);
3113 if ( ( p1 - p2 ).SquareModulus() <= tol2 )
3115 ASSERT( myReverseConnectivity.find( *ind2 ) != myReverseConnectivity.end() );
3116 list< TElemDef* > & elemXYZIDsList = myReverseConnectivity[ *ind2 ];
3117 list< TElemDef* >::iterator elemXYZIDs = elemXYZIDsList.begin();
3118 for ( ; elemXYZIDs != elemXYZIDsList.end(); elemXYZIDs++ )
3120 //MESSAGE( " Replace " << *ind2 << " with " << *ind1 );
3121 myXYZ[ *ind2 ] = undefinedXYZ();
3122 replace( (*elemXYZIDs)->begin(), (*elemXYZIDs)->end(), *ind2, *ind1 );
3124 ind2 = indices2.erase( ind2 );
3131 if ( unite ) { // sort indices using distIndMap
3132 for ( ind1 = indices1.begin(); ind1 != indices1.end(); ind1++ )
3134 ASSERT( isDefined( myXYZ[ *ind1 ] ));
3135 double dist = P.SquareDistance( myXYZ[ *ind1 ]);
3136 distIndMap.insert( make_pair( dist, *ind1 ));
3140 if ( unite ) { // put all sorted indices into the first group
3141 list< int >& g = groups.front();
3143 map< double, int >::iterator dist_ind = distIndMap.begin();
3144 for ( ; dist_ind != distIndMap.end(); dist_ind++ )
3145 g.push_back( dist_ind->second );
3147 } // loop on myIdsOnBoundary
3150 //=======================================================================
3151 //function : makePolyElements
3152 //purpose : prepare intermediate data to create Polygons and Polyhedrons
3153 //=======================================================================
3155 void SMESH_Pattern::
3156 makePolyElements(const vector< const SMDS_MeshNode* >& theNodes,
3157 const bool toCreatePolygons,
3158 const bool toCreatePolyedrs)
3160 myPolyElemXYZIDs.clear();
3161 myPolyElems.clear();
3162 myPolyElems.reserve( myIdsOnBoundary.size() );
3164 // make a set of refined elements
3165 set< const SMDS_MeshElement* > avoidSet, elemSet;
3166 avoidSet.insert( myElements.begin(), myElements.end() );
3168 map< TNodeSet, list< list< int > > >::iterator indListIt, nn_IdList;
3170 if ( toCreatePolygons )
3172 int lastFreeId = myXYZ.size();
3174 // loop on links of refined elements
3175 indListIt = myIdsOnBoundary.begin();
3176 for ( ; indListIt != myIdsOnBoundary.end(); indListIt++ )
3178 const TNodeSet & linkNodes = indListIt->first;
3179 if ( linkNodes.size() != 2 )
3180 continue; // skip face
3181 const SMDS_MeshNode* n1 = * linkNodes.begin();
3182 const SMDS_MeshNode* n2 = * linkNodes.rbegin();
3184 list<list< int > >& idGroups = indListIt->second; // ids of nodes to build
3185 if ( idGroups.empty() || idGroups.front().empty() )
3188 // find not refined face having n1-n2 link
3192 const SMDS_MeshElement* face =
3193 SMESH_MeshEditor::FindFaceInSet( n1, n2, elemSet, avoidSet );
3196 avoidSet.insert ( face );
3197 myPolyElems.push_back( face );
3199 // some links of <face> are split;
3200 // make list of xyz for <face>
3201 myPolyElemXYZIDs.push_back(TElemDef());
3202 TElemDef & faceNodeIds = myPolyElemXYZIDs.back();
3203 // loop on links of a <face>
3204 SMDS_ElemIteratorPtr nIt = face->nodesIterator();
3205 int i = 0, nbNodes = face->NbNodes();
3206 vector<const SMDS_MeshNode*> nodes( nbNodes + 1 );
3207 while ( nIt->more() )
3208 nodes[ i++ ] = static_cast<const SMDS_MeshNode*>( nIt->next() );
3209 nodes[ i ] = nodes[ 0 ];
3210 for ( i = 0; i < nbNodes; ++i )
3212 // look for point mapped on a link
3213 TNodeSet faceLinkNodes;
3214 faceLinkNodes.insert( nodes[ i ] );
3215 faceLinkNodes.insert( nodes[ i + 1 ] );
3216 if ( faceLinkNodes == linkNodes )
3217 nn_IdList = indListIt;
3219 nn_IdList = myIdsOnBoundary.find( faceLinkNodes );
3220 // add face point ids
3221 faceNodeIds.push_back( ++lastFreeId );
3222 myXYZIdToNodeMap.insert( make_pair( lastFreeId, nodes[ i ]));
3223 if ( nn_IdList != myIdsOnBoundary.end() )
3225 // there are points mapped on a link
3226 list< int >& mappedIds = nn_IdList->second.front();
3227 if ( isReversed( nodes[ i ], mappedIds ))
3228 faceNodeIds.insert (faceNodeIds.end(),mappedIds.rbegin(), mappedIds.rend() );
3230 faceNodeIds.insert (faceNodeIds.end(),mappedIds.begin(), mappedIds.end() );
3232 } // loop on links of a <face>
3238 if ( myIs2D && idGroups.size() > 1 ) {
3240 // sew new elements on 2 refined elements sharing n1-n2 link
3242 list< int >& idsOnLink = idGroups.front();
3243 // temporarily add ids of link nodes to idsOnLink
3244 bool rev = isReversed( n1, idsOnLink );
3245 for ( int i = 0; i < 2; ++i )
3248 nodeSet.insert( i ? n2 : n1 );
3249 ASSERT( myIdsOnBoundary.find( nodeSet ) != myIdsOnBoundary.end() );
3250 list<list< int > >& groups = myIdsOnBoundary[ nodeSet ];
3251 int nodeId = groups.front().front();
3253 if ( rev ) append = !append;
3255 idsOnLink.push_back( nodeId );
3257 idsOnLink.push_front( nodeId );
3259 list< int >::iterator id = idsOnLink.begin();
3260 for ( ; id != idsOnLink.end(); ++id ) // loop on XYZ ids on a link
3262 list< TElemDef* >& elemDefs = myReverseConnectivity[ *id ]; // elems sharing id
3263 list< TElemDef* >::iterator pElemDef = elemDefs.begin();
3264 for ( ; pElemDef != elemDefs.end(); pElemDef++ ) // loop on elements sharing id
3266 TElemDef* pIdList = *pElemDef; // ptr on list of ids making element up
3267 // look for <id> in element definition
3268 TElemDef::iterator idDef = find( pIdList->begin(), pIdList->end(), *id );
3269 ASSERT ( idDef != pIdList->end() );
3270 // look for 2 neighbour ids of <id> in element definition
3271 for ( int prev = 0; prev < 2; ++prev ) {
3272 TElemDef::iterator idDef2 = idDef;
3274 idDef2 = ( idDef2 == pIdList->begin() ) ? --pIdList->end() : --idDef2;
3276 idDef2 = ( ++idDef2 == pIdList->end() ) ? pIdList->begin() : idDef2;
3277 // look for idDef2 on a link starting from id
3278 list< int >::iterator id2 = find( id, idsOnLink.end(), *idDef2 );
3279 if ( id2 != idsOnLink.end() && id != --id2 ) { // found not next to id
3280 // insert ids located on link between <id> and <id2>
3281 // into the element definition between idDef and idDef2
3283 for ( ; id2 != id; --id2 )
3284 pIdList->insert( idDef, *id2 );
3286 list< int >::iterator id1 = id;
3287 for ( ++id1, ++id2; id1 != id2; ++id1 )
3288 pIdList->insert( idDef2, *id1 );
3294 // remove ids of link nodes
3295 idsOnLink.pop_front();
3296 idsOnLink.pop_back();
3298 } // loop on myIdsOnBoundary
3299 } // if ( toCreatePolygons )
3301 if ( toCreatePolyedrs )
3303 // check volumes adjacent to the refined elements
3304 SMDS_VolumeTool volTool;
3305 vector<const SMDS_MeshElement*>::iterator refinedElem = myElements.begin();
3306 for ( ; refinedElem != myElements.end(); ++refinedElem )
3308 // loop on nodes of refinedElem
3309 SMDS_ElemIteratorPtr nIt = (*refinedElem)->nodesIterator();
3310 while ( nIt->more() ) {
3311 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nIt->next() );
3312 // loop on inverse elements of node
3313 SMDS_ElemIteratorPtr eIt = node->GetInverseElementIterator();
3314 while ( eIt->more() )
3316 const SMDS_MeshElement* elem = eIt->next();
3317 if ( !volTool.Set( elem ) || !avoidSet.insert( elem ).second )
3318 continue; // skip faces or refined elements
3319 // add polyhedron definition
3320 myPolyhedronQuantities.push_back(vector<int> ());
3321 myPolyElemXYZIDs.push_back(TElemDef());
3322 vector<int>& quantity = myPolyhedronQuantities.back();
3323 TElemDef & elemDef = myPolyElemXYZIDs.back();
3324 // get definitions of new elements on volume faces
3325 bool makePoly = false;
3326 for ( int iF = 0; iF < volTool.NbFaces(); ++iF )
3328 if ( getFacesDefinition(volTool.GetFaceNodes( iF ),
3329 volTool.NbFaceNodes( iF ),
3330 theNodes, elemDef, quantity))
3334 myPolyElems.push_back( elem );
3336 myPolyhedronQuantities.pop_back();
3337 myPolyElemXYZIDs.pop_back();
3345 //=======================================================================
3346 //function : getFacesDefinition
3347 //purpose : return faces definition for a volume face defined by theBndNodes
3348 //=======================================================================
3350 bool SMESH_Pattern::
3351 getFacesDefinition(const SMDS_MeshNode** theBndNodes,
3352 const int theNbBndNodes,
3353 const vector< const SMDS_MeshNode* >& theNodes,
3354 list< int >& theFaceDefs,
3355 vector<int>& theQuantity)
3357 bool makePoly = false;
3358 // cout << "FROM FACE NODES: " <<endl;
3359 // for ( int i = 0; i < theNbBndNodes; ++i )
3360 // cout << theBndNodes[ i ];
3362 set< const SMDS_MeshNode* > bndNodeSet;
3363 for ( int i = 0; i < theNbBndNodes; ++i )
3364 bndNodeSet.insert( theBndNodes[ i ]);
3366 map< TNodeSet, list< list< int > > >::iterator nn_IdList;
3368 // make a set of all nodes on a face
3370 if ( !myIs2D ) { // for 2D, merge only edges
3371 nn_IdList = myIdsOnBoundary.find( bndNodeSet );
3372 if ( nn_IdList != myIdsOnBoundary.end() ) {
3374 list< int > & faceIds = nn_IdList->second.front();
3375 ids.insert( faceIds.begin(), faceIds.end() );
3378 //bool hasIdsInFace = !ids.empty();
3380 // add ids on links and bnd nodes
3381 int lastFreeId = Max( myXYZIdToNodeMap.rbegin()->first, theNodes.size() );
3382 TElemDef faceDef; // definition for the case if there is no new adjacent volumes
3383 for ( int iN = 0; iN < theNbBndNodes; ++iN )
3385 // add id of iN-th bnd node
3387 nSet.insert( theBndNodes[ iN ] );
3388 nn_IdList = myIdsOnBoundary.find( nSet );
3389 int bndId = ++lastFreeId;
3390 if ( nn_IdList != myIdsOnBoundary.end() ) {
3391 bndId = nn_IdList->second.front().front();
3392 ids.insert( bndId );
3395 myXYZIdToNodeMap.insert( make_pair( bndId, theBndNodes[ iN ] ));
3396 faceDef.push_back( bndId );
3397 // add ids on a link
3399 linkNodes.insert( theBndNodes[ iN ]);
3400 linkNodes.insert( theBndNodes[ iN + 1 == theNbBndNodes ? 0 : iN + 1 ]);
3401 nn_IdList = myIdsOnBoundary.find( linkNodes );
3402 if ( nn_IdList != myIdsOnBoundary.end() ) {
3404 list< int > & linkIds = nn_IdList->second.front();
3405 ids.insert( linkIds.begin(), linkIds.end() );
3406 if ( isReversed( theBndNodes[ iN ], linkIds ))
3407 faceDef.insert( faceDef.end(), linkIds.begin(), linkIds.end() );
3409 faceDef.insert( faceDef.end(), linkIds.rbegin(), linkIds.rend() );
3413 // find faces definition of new volumes
3415 bool defsAdded = false;
3416 if ( !myIs2D ) { // for 2D, merge only edges
3417 SMDS_VolumeTool vol;
3418 set< TElemDef* > checkedVolDefs;
3419 set< int >::iterator id = ids.begin();
3420 for ( ; id != ids.end(); ++id )
3422 // definitions of volumes sharing id
3423 list< TElemDef* >& defList = myReverseConnectivity[ *id ];
3424 ASSERT( !defList.empty() );
3425 // loop on volume definitions
3426 list< TElemDef* >::iterator pIdList = defList.begin();
3427 for ( ; pIdList != defList.end(); ++pIdList)
3429 if ( !checkedVolDefs.insert( *pIdList ).second )
3430 continue; // skip already checked volume definition
3431 vector< int > idVec;
3432 idVec.reserve( (*pIdList)->size() );
3433 idVec.insert( idVec.begin(), (*pIdList)->begin(), (*pIdList)->end() );
3434 // loop on face defs of a volume
3435 SMDS_VolumeTool::VolumeType volType = vol.GetType( idVec.size() );
3436 if ( volType == SMDS_VolumeTool::UNKNOWN )
3438 int nbFaces = vol.NbFaces( volType );
3439 for ( int iF = 0; iF < nbFaces; ++iF )
3441 const int* nodeInds = vol.GetFaceNodesIndices( volType, iF, true );
3442 int iN, nbN = vol.NbFaceNodes( volType, iF );
3443 // check if all nodes of a faces are in <ids>
3445 for ( iN = 0; iN < nbN && all; ++iN ) {
3446 int nodeId = idVec[ nodeInds[ iN ]];
3447 all = ( ids.find( nodeId ) != ids.end() );
3450 // store a face definition
3451 for ( iN = 0; iN < nbN; ++iN ) {
3452 theFaceDefs.push_back( idVec[ nodeInds[ iN ]]);
3454 theQuantity.push_back( nbN );
3462 theQuantity.push_back( faceDef.size() );
3463 theFaceDefs.splice( theFaceDefs.end(), faceDef, faceDef.begin(), faceDef.end() );
3469 //=======================================================================
3470 //function : MakeMesh
3471 //purpose : Create nodes and elements in <theMesh> using nodes
3472 // coordinates computed by either of Apply...() methods
3473 //=======================================================================
3475 bool SMESH_Pattern::MakeMesh(SMESH_Mesh* theMesh,
3476 const bool toCreatePolygons,
3477 const bool toCreatePolyedrs)
3479 MESSAGE(" ::MakeMesh() " );
3480 if ( !myIsComputed )
3481 return setErrorCode( ERR_MAKEM_NOT_COMPUTED );
3483 mergePoints( toCreatePolygons );
3485 SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS();
3487 // clear elements and nodes existing on myShape
3489 if ( !myShape.IsNull() )
3491 SMESH_subMesh * aSubMesh = theMesh->GetSubMeshContaining( myShape );
3492 SMESHDS_SubMesh * aSubMeshDS = aMeshDS->MeshElements( myShape );
3494 aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
3495 else if ( aSubMeshDS )
3497 SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
3498 while ( eIt->more() )
3499 aMeshDS->RemoveElement( eIt->next() );
3500 SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes();
3501 while ( nIt->more() )
3502 aMeshDS->RemoveNode( static_cast<const SMDS_MeshNode*>( nIt->next() ));
3506 bool onMeshElements = ( !myElements.empty() );
3508 vector< const SMDS_MeshNode* > nodesVector; // i-th point/xyz -> node
3509 if ( onMeshElements )
3511 nodesVector.resize( Max( myXYZ.size(), myXYZIdToNodeMap.rbegin()->first ), 0 );
3512 map< int, const SMDS_MeshNode*>::iterator i_node = myXYZIdToNodeMap.begin();
3513 for ( ; i_node != myXYZIdToNodeMap.end(); i_node++ ) {
3514 nodesVector[ i_node->first ] = i_node->second;
3516 for ( int i = 0; i < myXYZ.size(); ++i ) {
3517 if ( !nodesVector[ i ] && isDefined( myXYZ[ i ] ) )
3518 nodesVector[ i ] = aMeshDS->AddNode (myXYZ[ i ].X(),
3525 nodesVector.resize( myPoints.size(), 0 );
3527 // to find point index
3528 map< TPoint*, int > pointIndex;
3529 for ( int i = 0; i < myPoints.size(); i++ )
3530 pointIndex.insert( make_pair( & myPoints[ i ], i ));
3532 // loop on sub-shapes of myShape: create nodes
3533 map< int, list< TPoint* > >::iterator idPointIt = myShapeIDToPointsMap.begin();
3534 for ( ; idPointIt != myShapeIDToPointsMap.end(); idPointIt++ )
3537 SMESHDS_SubMesh * subMeshDS = 0;
3538 if ( !myShapeIDMap.IsEmpty() ) {
3539 S = myShapeIDMap( idPointIt->first );
3540 subMeshDS = aMeshDS->MeshElements( S );
3542 list< TPoint* > & points = idPointIt->second;
3543 list< TPoint* >::iterator pIt = points.begin();
3544 for ( ; pIt != points.end(); pIt++ )
3546 TPoint* point = *pIt;
3547 int pIndex = pointIndex[ point ];
3548 if ( nodesVector [ pIndex ] )
3550 SMDS_MeshNode* node = aMeshDS->AddNode (point->myXYZ.X(),
3553 nodesVector [ pIndex ] = node;
3556 switch ( S.ShapeType() ) {
3557 case TopAbs_VERTEX: {
3558 aMeshDS->SetNodeOnVertex( node, TopoDS::Vertex( S ));
3562 aMeshDS->SetNodeOnEdge( node, TopoDS::Edge( S ));
3563 SMDS_EdgePosition* epos =
3564 dynamic_cast<SMDS_EdgePosition *>(node->GetPosition().get());
3565 epos->SetUParameter( point->myU );
3569 aMeshDS->SetNodeOnFace( node, TopoDS::Face( S ));
3570 SMDS_FacePosition* pos =
3571 dynamic_cast<SMDS_FacePosition *>(node->GetPosition().get());
3572 pos->SetUParameter( point->myUV.X() );
3573 pos->SetVParameter( point->myUV.Y() );
3577 aMeshDS->SetNodeInVolume( node, TopoDS::Shell( S ));
3586 if ( onMeshElements )
3588 // prepare data to create poly elements
3589 makePolyElements( nodesVector, toCreatePolygons, toCreatePolyedrs );
3592 createElements( theMesh, nodesVector, myElemXYZIDs, myElements );
3593 // sew old and new elements
3594 createElements( theMesh, nodesVector, myPolyElemXYZIDs, myPolyElems );
3598 createElements( theMesh, nodesVector, myElemPointIDs, myElements );
3601 // const map<int,SMESHDS_SubMesh*>& sm = aMeshDS->SubMeshes();
3602 // map<int,SMESHDS_SubMesh*>::const_iterator i_sm = sm.begin();
3603 // for ( ; i_sm != sm.end(); i_sm++ )
3605 // cout << " SM " << i_sm->first << " ";
3606 // TopAbs::Print( aMeshDS->IndexToShape( i_sm->first ).ShapeType(), cout)<< " ";
3607 // //SMDS_ElemIteratorPtr GetElements();
3608 // SMDS_NodeIteratorPtr nit = i_sm->second->GetNodes();
3609 // while ( nit->more() )
3610 // cout << nit->next()->GetID() << " ";
3613 return setErrorCode( ERR_OK );
3616 //=======================================================================
3617 //function : createElements
3618 //purpose : add elements to the mesh
3619 //=======================================================================
3621 void SMESH_Pattern::createElements(SMESH_Mesh* theMesh,
3622 const vector<const SMDS_MeshNode* >& theNodesVector,
3623 const list< TElemDef > & theElemNodeIDs,
3624 const vector<const SMDS_MeshElement*>& theElements)
3626 SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS();
3627 SMESH_MeshEditor editor( theMesh );
3629 bool onMeshElements = !theElements.empty();
3631 // shapes and groups theElements are on
3632 vector< int > shapeIDs;
3633 vector< list< SMESHDS_Group* > > groups;
3634 set< const SMDS_MeshNode* > shellNodes;
3635 if ( onMeshElements )
3637 shapeIDs.resize( theElements.size() );
3638 groups.resize( theElements.size() );
3639 const set<SMESHDS_GroupBase*>& allGroups = aMeshDS->GetGroups();
3640 set<SMESHDS_GroupBase*>::const_iterator grIt;
3641 for ( int i = 0; i < theElements.size(); i++ )
3643 shapeIDs[ i ] = editor.FindShape( theElements[ i ] );
3644 for ( grIt = allGroups.begin(); grIt != allGroups.end(); grIt++ ) {
3645 SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *grIt );
3646 if ( group && group->SMDSGroup().Contains( theElements[ i ] ))
3647 groups[ i ].push_back( group );
3650 // get all nodes bound to shells because their SpacePosition is not set
3651 // by SMESHDS_Mesh::SetNodeInVolume()
3652 TopoDS_Shape aMainShape = aMeshDS->ShapeToMesh();
3653 if ( !aMainShape.IsNull() ) {
3654 TopExp_Explorer shellExp( aMainShape, TopAbs_SHELL );
3655 for ( ; shellExp.More(); shellExp.Next() )
3657 SMESHDS_SubMesh * sm = aMeshDS->MeshElements( shellExp.Current() );
3659 SMDS_NodeIteratorPtr nIt = sm->GetNodes();
3660 while ( nIt->more() )
3661 shellNodes.insert( nIt->next() );
3666 // nb new elements per a refined element
3667 int nbNewElemsPerOld = 1;
3668 if ( onMeshElements )
3669 nbNewElemsPerOld = theElemNodeIDs.size() / theElements.size();
3673 list< TElemDef >::const_iterator enIt = theElemNodeIDs.begin();
3674 list< vector<int> >::iterator quantity = myPolyhedronQuantities.begin();
3675 for ( int iElem = 0; enIt != theElemNodeIDs.end(); enIt++, iElem++ )
3677 const TElemDef & elemNodeInd = *enIt;
3679 vector< const SMDS_MeshNode* > nodes( elemNodeInd.size() );
3680 TElemDef::const_iterator id = elemNodeInd.begin();
3682 for ( nbNodes = 0; id != elemNodeInd.end(); id++ ) {
3683 if ( *id < theNodesVector.size() )
3684 nodes[ nbNodes++ ] = theNodesVector[ *id ];
3686 nodes[ nbNodes++ ] = myXYZIdToNodeMap[ *id ];
3688 // dim of refined elem
3689 int elemIndex = iElem / nbNewElemsPerOld; // refined element index
3690 if ( onMeshElements ) {
3691 is2d = ( theElements[ elemIndex ]->GetType() == SMDSAbs_Face );
3694 const SMDS_MeshElement* elem = 0;
3696 switch ( nbNodes ) {
3698 elem = aMeshDS->AddFace( nodes[0], nodes[1], nodes[2] ); break;
3700 elem = aMeshDS->AddFace( nodes[0], nodes[1], nodes[2], nodes[3] ); break;
3702 elem = aMeshDS->AddPolygonalFace( nodes );
3706 switch ( nbNodes ) {
3708 elem = aMeshDS->AddVolume (nodes[0], nodes[1], nodes[2], nodes[3] ); break;
3710 elem = aMeshDS->AddVolume (nodes[0], nodes[1], nodes[2], nodes[3],
3713 elem = aMeshDS->AddVolume (nodes[0], nodes[1], nodes[2], nodes[3],
3714 nodes[4], nodes[5] ); break;
3716 elem = aMeshDS->AddVolume (nodes[0], nodes[1], nodes[2], nodes[3],
3717 nodes[4], nodes[5], nodes[6], nodes[7] ); break;
3719 elem = aMeshDS->AddPolyhedralVolume( nodes, *quantity++ );
3722 // set element on a shape
3723 if ( elem && onMeshElements ) // applied to mesh elements
3725 int shapeID = shapeIDs[ elemIndex ];
3726 if ( shapeID > 0 ) {
3727 aMeshDS->SetMeshElementOnShape( elem, shapeID );
3728 // set nodes on a shape
3729 TopoDS_Shape S = aMeshDS->IndexToShape( shapeID );
3730 if ( S.ShapeType() == TopAbs_SOLID ) {
3731 TopoDS_Iterator shellIt( S );
3732 if ( shellIt.More() )
3733 shapeID = aMeshDS->ShapeToIndex( shellIt.Value() );
3735 SMDS_ElemIteratorPtr noIt = elem->nodesIterator();
3736 while ( noIt->more() ) {
3737 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
3738 ( static_cast<const SMDS_MeshNode*>( noIt->next() ));
3739 if (!node->GetPosition()->GetShapeId() &&
3740 shellNodes.find( node ) == shellNodes.end() ) {
3741 if ( S.ShapeType() == TopAbs_FACE )
3742 aMeshDS->SetNodeOnFace( node, shapeID );
3744 aMeshDS->SetNodeInVolume( node, shapeID );
3745 shellNodes.insert( node );
3750 // add elem in groups
3751 list< SMESHDS_Group* >::iterator g = groups[ elemIndex ].begin();
3752 for ( ; g != groups[ elemIndex ].end(); ++g )
3753 (*g)->SMDSGroup().Add( elem );
3755 if ( elem && !myShape.IsNull() ) // applied to shape
3756 aMeshDS->SetMeshElementOnShape( elem, myShape );
3759 // make that SMESH_subMesh::_computeState == COMPUTE_OK
3760 // so that operations with hypotheses will erase the mesh being built
3762 SMESH_subMesh * subMesh;
3763 if ( !myShape.IsNull() ) {
3764 subMesh = theMesh->GetSubMeshContaining( myShape );
3766 subMesh->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
3768 if ( onMeshElements ) {
3769 list< int > elemIDs;
3770 for ( int i = 0; i < theElements.size(); i++ )
3772 subMesh = theMesh->GetSubMeshContaining( shapeIDs[ i ] );
3774 subMesh->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
3776 elemIDs.push_back( theElements[ i ]->GetID() );
3778 // remove refined elements
3779 editor.Remove( elemIDs, false );
3783 //=======================================================================
3784 //function : isReversed
3785 //purpose : check xyz ids order in theIdsList taking into account
3786 // theFirstNode on a link
3787 //=======================================================================
3789 bool SMESH_Pattern::isReversed(const SMDS_MeshNode* theFirstNode,
3790 const list< int >& theIdsList) const
3792 if ( theIdsList.size() < 2 )
3795 gp_Pnt Pf ( theFirstNode->X(), theFirstNode->Y(), theFirstNode->Z() );
3797 list<int>::const_iterator id = theIdsList.begin();
3798 for ( int i = 0; i < 2; ++i, ++id ) {
3799 if ( *id < myXYZ.size() )
3800 P[ i ] = myXYZ[ *id ];
3802 map< int, const SMDS_MeshNode*>::const_iterator i_n;
3803 i_n = myXYZIdToNodeMap.find( *id );
3804 ASSERT( i_n != myXYZIdToNodeMap.end() );
3805 const SMDS_MeshNode* n = i_n->second;
3806 P[ i ].SetCoord( n->X(), n->Y(), n->Z() );
3809 return Pf.SquareDistance( P[ 1 ] ) < Pf.SquareDistance( P[ 0 ] );
3813 //=======================================================================
3814 //function : arrangeBoundaries
3815 //purpose : if there are several wires, arrange boundaryPoints so that
3816 // the outer wire goes first and fix inner wires orientation
3817 // update myKeyPointIDs to correspond to the order of key-points
3818 // in boundaries; sort internal boundaries by the nb of key-points
3819 //=======================================================================
3821 void SMESH_Pattern::arrangeBoundaries (list< list< TPoint* > >& boundaryList)
3823 typedef list< list< TPoint* > >::iterator TListOfListIt;
3824 TListOfListIt bndIt;
3825 list< TPoint* >::iterator pIt;
3827 int nbBoundaries = boundaryList.size();
3828 if ( nbBoundaries > 1 )
3830 // sort boundaries by nb of key-points
3831 if ( nbBoundaries > 2 )
3833 // move boundaries in tmp list
3834 list< list< TPoint* > > tmpList;
3835 tmpList.splice( tmpList.begin(), boundaryList, boundaryList.begin(), boundaryList.end());
3836 // make a map nb-key-points to boundary-position-in-tmpList,
3837 // boundary-positions get ordered in it
3838 typedef map< int, TListOfListIt > TNbKpBndPosMap;
3839 TNbKpBndPosMap nbKpBndPosMap;
3840 bndIt = tmpList.begin();
3841 list< int >::iterator nbKpIt = myNbKeyPntInBoundary.begin();
3842 for ( ; nbKpIt != myNbKeyPntInBoundary.end(); nbKpIt++, bndIt++ ) {
3843 int nb = *nbKpIt * nbBoundaries;
3844 while ( nbKpBndPosMap.find ( nb ) != nbKpBndPosMap.end() )
3846 nbKpBndPosMap.insert( TNbKpBndPosMap::value_type( nb, bndIt ));
3848 // move boundaries back to boundaryList
3849 TNbKpBndPosMap::iterator nbKpBndPosIt = nbKpBndPosMap.begin();
3850 for ( ; nbKpBndPosIt != nbKpBndPosMap.end(); nbKpBndPosIt++ ) {
3851 TListOfListIt & bndPos2 = (*nbKpBndPosIt).second;
3852 TListOfListIt bndPos1 = bndPos2++;
3853 boundaryList.splice( boundaryList.end(), tmpList, bndPos1, bndPos2 );
3857 // Look for the outer boundary: the one with the point with the least X
3858 double leastX = DBL_MAX;
3859 TListOfListIt outerBndPos;
3860 for ( bndIt = boundaryList.begin(); bndIt != boundaryList.end(); bndIt++ )
3862 list< TPoint* >& boundary = (*bndIt);
3863 for ( pIt = boundary.begin(); pIt != boundary.end(); pIt++)
3865 TPoint* point = *pIt;
3866 if ( point->myInitXYZ.X() < leastX ) {
3867 leastX = point->myInitXYZ.X();
3868 outerBndPos = bndIt;
3873 if ( outerBndPos != boundaryList.begin() )
3874 boundaryList.splice( boundaryList.begin(), boundaryList, outerBndPos, ++outerBndPos );
3876 } // if nbBoundaries > 1
3878 // Check boundaries orientation and re-fill myKeyPointIDs
3880 set< TPoint* > keyPointSet;
3881 list< int >::iterator kpIt = myKeyPointIDs.begin();
3882 for ( ; kpIt != myKeyPointIDs.end(); kpIt++ )
3883 keyPointSet.insert( & myPoints[ *kpIt ]);
3884 myKeyPointIDs.clear();
3886 // update myNbKeyPntInBoundary also
3887 list< int >::iterator nbKpIt = myNbKeyPntInBoundary.begin();
3889 for ( bndIt = boundaryList.begin(); bndIt != boundaryList.end(); bndIt++, nbKpIt++ )
3891 // find the point with the least X
3892 double leastX = DBL_MAX;
3893 list< TPoint* >::iterator xpIt;
3894 list< TPoint* >& boundary = (*bndIt);
3895 for ( pIt = boundary.begin(); pIt != boundary.end(); pIt++)
3897 TPoint* point = *pIt;
3898 if ( point->myInitXYZ.X() < leastX ) {
3899 leastX = point->myInitXYZ.X();
3903 // find points next to the point with the least X
3904 TPoint* p = *xpIt, *pPrev, *pNext;
3905 if ( p == boundary.front() )
3906 pPrev = *(++boundary.rbegin());
3912 if ( p == boundary.back() )
3913 pNext = *(++boundary.begin());
3918 // vectors of boundary direction near <p>
3919 gp_Vec2d v1( pPrev->myInitUV, p->myInitUV ), v2( p->myInitUV, pNext->myInitUV );
3920 double sqMag1 = v1.SquareMagnitude(), sqMag2 = v2.SquareMagnitude();
3921 if ( sqMag1 > DBL_MIN && sqMag2 > DBL_MIN ) {
3922 double yPrev = v1.Y() / sqrt( sqMag1 );
3923 double yNext = v2.Y() / sqrt( sqMag2 );
3924 double sumY = yPrev + yNext;
3926 if ( bndIt == boundaryList.begin() ) // outer boundary
3934 // Put key-point IDs of a well-oriented boundary in myKeyPointIDs
3935 (*nbKpIt) = 0; // count nb of key-points again
3936 pIt = boundary.begin();
3937 for ( ; pIt != boundary.end(); pIt++)
3939 TPoint* point = *pIt;
3940 if ( keyPointSet.find( point ) == keyPointSet.end() )
3942 // find an index of a keypoint
3944 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
3945 for ( ; pVecIt != myPoints.end(); pVecIt++, index++ )
3946 if ( &(*pVecIt) == point )
3948 myKeyPointIDs.push_back( index );
3951 myKeyPointIDs.pop_back(); // remove the first key-point from the back
3954 } // loop on a list of boundaries
3956 ASSERT( myKeyPointIDs.size() == keyPointSet.size() );
3959 //=======================================================================
3960 //function : findBoundaryPoints
3961 //purpose : if loaded from file, find points to map on edges and faces and
3962 // compute their parameters
3963 //=======================================================================
3965 bool SMESH_Pattern::findBoundaryPoints()
3967 if ( myIsBoundaryPointsFound ) return true;
3969 MESSAGE(" findBoundaryPoints() ");
3973 set< TPoint* > pointsInElems;
3975 // Find free links of elements:
3976 // put links of all elements in a set and remove links encountered twice
3978 typedef pair< TPoint*, TPoint*> TLink;
3979 set< TLink > linkSet;
3980 list<TElemDef >::iterator epIt = myElemPointIDs.begin();
3981 for ( ; epIt != myElemPointIDs.end(); epIt++ )
3983 TElemDef & elemPoints = *epIt;
3984 TElemDef::iterator pIt = elemPoints.begin();
3985 int prevP = elemPoints.back();
3986 for ( ; pIt != elemPoints.end(); pIt++ ) {
3987 TPoint* p1 = & myPoints[ prevP ];
3988 TPoint* p2 = & myPoints[ *pIt ];
3989 TLink link(( p1 < p2 ? p1 : p2 ), ( p1 < p2 ? p2 : p1 ));
3990 ASSERT( link.first != link.second );
3991 pair<set< TLink >::iterator,bool> itUniq = linkSet.insert( link );
3992 if ( !itUniq.second )
3993 linkSet.erase( itUniq.first );
3996 pointsInElems.insert( p1 );
3999 // Now linkSet contains only free links,
4000 // find the points order that they have in boundaries
4002 // 1. make a map of key-points
4003 set< TPoint* > keyPointSet;
4004 list< int >::iterator kpIt = myKeyPointIDs.begin();
4005 for ( ; kpIt != myKeyPointIDs.end(); kpIt++ )
4006 keyPointSet.insert( & myPoints[ *kpIt ]);
4008 // 2. chain up boundary points
4009 list< list< TPoint* > > boundaryList;
4010 boundaryList.push_back( list< TPoint* >() );
4011 list< TPoint* > * boundary = & boundaryList.back();
4013 TPoint *point1, *point2, *keypoint1;
4014 kpIt = myKeyPointIDs.begin();
4015 point1 = keypoint1 = & myPoints[ *kpIt++ ];
4016 // loop on free links: look for the next point
4018 set< TLink >::iterator lIt = linkSet.begin();
4019 while ( lIt != linkSet.end() )
4021 if ( (*lIt).first == point1 )
4022 point2 = (*lIt).second;
4023 else if ( (*lIt).second == point1 )
4024 point2 = (*lIt).first;
4029 linkSet.erase( lIt );
4030 lIt = linkSet.begin();
4032 if ( keyPointSet.find( point2 ) == keyPointSet.end() ) // not a key-point
4034 boundary->push_back( point2 );
4036 else // a key-point found
4038 keyPointSet.erase( point2 ); // keyPointSet contains not found key-points only
4040 if ( point2 != keypoint1 ) // its not the boundary end
4042 boundary->push_back( point2 );
4044 else // the boundary end reached
4046 boundary->push_front( keypoint1 );
4047 boundary->push_back( keypoint1 );
4048 myNbKeyPntInBoundary.push_back( iKeyPoint );
4049 if ( keyPointSet.empty() )
4050 break; // all boundaries containing key-points are found
4052 // prepare to search for the next boundary
4053 boundaryList.push_back( list< TPoint* >() );
4054 boundary = & boundaryList.back();
4055 point2 = keypoint1 = (*keyPointSet.begin());
4059 } // loop on the free links set
4061 if ( boundary->empty() ) {
4062 MESSAGE(" a separate key-point");
4063 return setErrorCode( ERR_READ_BAD_KEY_POINT );
4066 // if there are several wires, arrange boundaryPoints so that
4067 // the outer wire goes first and fix inner wires orientation;
4068 // sort myKeyPointIDs to correspond to the order of key-points
4070 arrangeBoundaries( boundaryList );
4072 // Find correspondence shape ID - points,
4073 // compute points parameter on edge
4075 keyPointSet.clear();
4076 for ( kpIt = myKeyPointIDs.begin(); kpIt != myKeyPointIDs.end(); kpIt++ )
4077 keyPointSet.insert( & myPoints[ *kpIt ]);
4079 set< TPoint* > edgePointSet; // to find in-face points
4080 int vertexID = 1; // the first index in TopTools_IndexedMapOfShape
4081 int edgeID = myKeyPointIDs.size() + 1;
4083 list< list< TPoint* > >::iterator bndIt = boundaryList.begin();
4084 for ( ; bndIt != boundaryList.end(); bndIt++ )
4086 boundary = & (*bndIt);
4087 double edgeLength = 0;
4088 list< TPoint* >::iterator pIt = boundary->begin();
4089 getShapePoints( edgeID ).push_back( *pIt );
4090 getShapePoints( vertexID++ ).push_back( *pIt );
4091 for ( pIt++; pIt != boundary->end(); pIt++)
4093 list< TPoint* > & edgePoints = getShapePoints( edgeID );
4094 TPoint* prevP = edgePoints.empty() ? 0 : edgePoints.back();
4095 TPoint* point = *pIt;
4096 edgePointSet.insert( point );
4097 if ( keyPointSet.find( point ) == keyPointSet.end() ) // inside-edge point
4099 edgePoints.push_back( point );
4100 edgeLength += ( point->myInitUV - prevP->myInitUV ).Modulus();
4101 point->myInitU = edgeLength;
4105 // treat points on the edge which ends up: compute U [0,1]
4106 edgePoints.push_back( point );
4107 if ( edgePoints.size() > 2 ) {
4108 edgeLength += ( point->myInitUV - prevP->myInitUV ).Modulus();
4109 list< TPoint* >::iterator epIt = edgePoints.begin();
4110 for ( ; epIt != edgePoints.end(); epIt++ )
4111 (*epIt)->myInitU /= edgeLength;
4113 // begin the next edge treatment
4116 if ( point != boundary->front() ) { // not the first key-point again
4117 getShapePoints( edgeID ).push_back( point );
4118 getShapePoints( vertexID++ ).push_back( point );
4124 // find in-face points
4125 list< TPoint* > & facePoints = getShapePoints( edgeID );
4126 vector< TPoint >::iterator pVecIt = myPoints.begin();
4127 for ( ; pVecIt != myPoints.end(); pVecIt++ ) {
4128 TPoint* point = &(*pVecIt);
4129 if ( edgePointSet.find( point ) == edgePointSet.end() &&
4130 pointsInElems.find( point ) != pointsInElems.end())
4131 facePoints.push_back( point );
4138 // bind points to shapes according to point parameters
4139 vector< TPoint >::iterator pVecIt = myPoints.begin();
4140 for ( int i = 0; pVecIt != myPoints.end(); pVecIt++, i++ ) {
4141 TPoint* point = &(*pVecIt);
4142 int shapeID = SMESH_Block::GetShapeIDByParams( point->myInitXYZ );
4143 getShapePoints( shapeID ).push_back( point );
4144 // detect key-points
4145 if ( SMESH_Block::IsVertexID( shapeID ))
4146 myKeyPointIDs.push_back( i );
4150 myIsBoundaryPointsFound = true;
4151 return myIsBoundaryPointsFound;
4154 //=======================================================================
4156 //purpose : clear fields
4157 //=======================================================================
4159 void SMESH_Pattern::Clear()
4161 myIsComputed = myIsBoundaryPointsFound = false;
4164 myKeyPointIDs.clear();
4165 myElemPointIDs.clear();
4166 myShapeIDToPointsMap.clear();
4167 myShapeIDMap.Clear();
4169 myNbKeyPntInBoundary.clear();
4172 //=======================================================================
4173 //function : setShapeToMesh
4174 //purpose : set a shape to be meshed. Return True if meshing is possible
4175 //=======================================================================
4177 bool SMESH_Pattern::setShapeToMesh(const TopoDS_Shape& theShape)
4179 if ( !IsLoaded() ) {
4180 MESSAGE( "Pattern not loaded" );
4181 return setErrorCode( ERR_APPL_NOT_LOADED );
4184 TopAbs_ShapeEnum aType = theShape.ShapeType();
4185 bool dimOk = ( myIs2D ? aType == TopAbs_FACE : aType == TopAbs_SHELL );
4187 MESSAGE( "Pattern dimention mismatch" );
4188 return setErrorCode( ERR_APPL_BAD_DIMENTION );
4191 // check if a face is closed
4192 int nbNodeOnSeamEdge = 0;
4194 TopoDS_Face face = TopoDS::Face( theShape );
4195 TopExp_Explorer eExp( theShape, TopAbs_EDGE );
4196 for ( ; eExp.More() && nbNodeOnSeamEdge == 0; eExp.Next() )
4197 if ( BRep_Tool::IsClosed( TopoDS::Edge( eExp.Current() ), face ))
4198 nbNodeOnSeamEdge = 2;
4201 // check nb of vertices
4202 TopTools_IndexedMapOfShape vMap;
4203 TopExp::MapShapes( theShape, TopAbs_VERTEX, vMap );
4204 if ( vMap.Extent() + nbNodeOnSeamEdge != myKeyPointIDs.size() ) {
4205 MESSAGE( myKeyPointIDs.size() << " != " << vMap.Extent() );
4206 return setErrorCode( ERR_APPL_BAD_NB_VERTICES );
4209 myElements.clear(); // not refine elements
4210 myElemXYZIDs.clear();
4212 myShapeIDMap.Clear();
4217 //=======================================================================
4218 //function : GetMappedPoints
4219 //purpose : Return nodes coordinates computed by Apply() method
4220 //=======================================================================
4222 bool SMESH_Pattern::GetMappedPoints ( list< const gp_XYZ * > & thePoints ) const
4225 if ( !myIsComputed )
4228 if ( myElements.empty() ) { // applied to shape
4229 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
4230 for ( ; pVecIt != myPoints.end(); pVecIt++ )
4231 thePoints.push_back( & (*pVecIt).myXYZ.XYZ() );
4233 else { // applied to mesh elements
4234 const gp_XYZ * definedXYZ = & myPoints[ myKeyPointIDs.front() ].myXYZ.XYZ();
4235 vector<gp_XYZ>::const_iterator xyz = myXYZ.begin();
4236 for ( ; xyz != myXYZ.end(); ++xyz )
4237 if ( !isDefined( *xyz ))
4238 thePoints.push_back( definedXYZ );
4240 thePoints.push_back( & (*xyz) );
4242 return !thePoints.empty();
4246 //=======================================================================
4247 //function : GetPoints
4248 //purpose : Return nodes coordinates of the pattern
4249 //=======================================================================
4251 bool SMESH_Pattern::GetPoints ( list< const gp_XYZ * > & thePoints ) const
4258 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
4259 for ( ; pVecIt != myPoints.end(); pVecIt++ )
4260 thePoints.push_back( & (*pVecIt).myInitXYZ );
4262 return ( thePoints.size() > 0 );
4265 //=======================================================================
4266 //function : getShapePoints
4267 //purpose : return list of points located on theShape
4268 //=======================================================================
4270 list< SMESH_Pattern::TPoint* > &
4271 SMESH_Pattern::getShapePoints(const TopoDS_Shape& theShape)
4274 if ( !myShapeIDMap.Contains( theShape ))
4275 aShapeID = myShapeIDMap.Add( theShape );
4277 aShapeID = myShapeIDMap.FindIndex( theShape );
4279 return myShapeIDToPointsMap[ aShapeID ];
4282 //=======================================================================
4283 //function : getShapePoints
4284 //purpose : return list of points located on the shape
4285 //=======================================================================
4287 list< SMESH_Pattern::TPoint* > & SMESH_Pattern::getShapePoints(const int theShapeID)
4289 return myShapeIDToPointsMap[ theShapeID ];
4292 //=======================================================================
4293 //function : DumpPoints
4295 //=======================================================================
4297 void SMESH_Pattern::DumpPoints() const
4300 vector< TPoint >::const_iterator pVecIt = myPoints.begin();
4301 for ( int i = 0; pVecIt != myPoints.end(); pVecIt++, i++ )
4302 cout << i << ": " << *pVecIt;
4306 //=======================================================================
4307 //function : TPoint()
4309 //=======================================================================
4311 SMESH_Pattern::TPoint::TPoint()
4314 myInitXYZ.SetCoord(0,0,0);
4315 myInitUV.SetCoord(0.,0.);
4317 myXYZ.SetCoord(0,0,0);
4318 myUV.SetCoord(0.,0.);
4323 //=======================================================================
4324 //function : operator <<
4326 //=======================================================================
4328 ostream & operator <<(ostream & OS, const SMESH_Pattern::TPoint& p)
4330 gp_XYZ xyz = p.myInitXYZ;
4331 OS << "\tinit( xyz( " << xyz.X() << " " << xyz.Y() << " " << xyz.Z() << " )";
4332 gp_XY xy = p.myInitUV;
4333 OS << " uv( " << xy.X() << " " << xy.Y() << " )";
4334 double u = p.myInitU;
4335 OS << " u( " << u << " )) " << &p << endl;
4336 xyz = p.myXYZ.XYZ();
4337 OS << "\t ( xyz( " << xyz.X() << " " << xyz.Y() << " " << xyz.Z() << " )";
4339 OS << " uv( " << xy.X() << " " << xy.Y() << " )";
4341 OS << " u( " << u << " ))" << endl;