- for (TopExp_Explorer exp(F, TopAbs_WIRE); exp.More(); exp.Next())
- {
- const TopoDS_Wire & W = TopoDS::Wire(exp.Current());
- if (!OW.IsSame(W))
- {
- LoadPoints(aMesh, F, W, uvslf, m, mefistoToDS);
- //SCRUTE(m);
- }
- }
-// SCRUTE(nudslf[nblf]);
-// for (int i=0; i<=nblf; i++)
-// {
-// MESSAGE(" -+- " <<i<< " "<< nudslf[i]);
-// }
-// for (int i=0; i<nudslf[nblf]; i++)
-// {
-// MESSAGE(" -+- " <<i<< " "<< uvslf[i]);
-// }
-// SCRUTE(nutysu);
-// SCRUTE(aretmx);
-// SCRUTE(nblf);
-
- MESSAGE("MEFISTO triangulation ...");
- uvst = NULL;
- nust = NULL;
- aptrte(nutysu, aretmx,
- nblf, nudslf, uvslf, nbpti, uvpti, nbst, uvst, nbt, nust, ierr);
-
- if (ierr == 0)
- {
- MESSAGE("... End Triangulation Generated Triangle Number " << nbt);
- MESSAGE(" Node Number " << nbst);
- //SCRUTE(nbst);
- //SCRUTE(nbt);
- StoreResult(aMesh, nbst, uvst, nbt, nust, F,
- faceIsForward, mefistoToDS);
- isOk = true;
- }
- else
- {
- MESSAGE("Error in Triangulation");
- isOk = false;
- }
- if (nudslf != NULL)
- delete[]nudslf;
- if (uvslf != NULL)
- delete[]uvslf;
- if (uvst != NULL)
- delete[]uvst;
- if (nust != NULL)
- delete[]nust;
- return isOk;
+//=======================================================================
+//function : fixCommonVertexUV
+//purpose :
+//=======================================================================
+
+static bool fixCommonVertexUV (gp_Pnt2d & theUV,
+ const TopoDS_Vertex& theV,
+ const TopoDS_Wire& theW,
+ const TopoDS_Wire& theOW,
+ const TopoDS_Face& theF,
+ const TopTools_IndexedDataMapOfShapeListOfShape & theVWMap,
+ SMESH_Mesh & theMesh,
+ bool CreateQuadratic)
+{
+ if( theW.IsSame( theOW ) ||
+ !theVWMap.Contains( theV )) return false;
+
+ // check if there is another wire sharing theV
+ const TopTools_ListOfShape& WList = theVWMap.FindFromKey( theV );
+ TopTools_ListIteratorOfListOfShape aWIt;
+ for ( aWIt.Initialize( WList ); aWIt.More(); aWIt.Next() )
+ if ( !theW.IsSame( aWIt.Value() ))
+ break;
+ if ( !aWIt.More() ) return false;
+
+ TopTools_ListOfShape EList;
+ list< double > UList;
+
+ // find edges of theW sharing theV
+ // and find 2d normal to them at theV
+ gp_Vec2d N(0.,0.);
+ TopoDS_Iterator itE( theW );
+ for ( ; itE.More(); itE.Next() )
+ {
+ const TopoDS_Edge& E = TopoDS::Edge( itE.Value() );
+ TopoDS_Iterator itV( E );
+ for ( ; itV.More(); itV.Next() )
+ {
+ const TopoDS_Vertex & V = TopoDS::Vertex( itV.Value() );
+ if ( !V.IsSame( theV ))
+ continue;
+ EList.Append( E );
+ Standard_Real u = BRep_Tool::Parameter( V, E );
+ UList.push_back( u );
+ double f, l;
+ Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
+ gp_Vec2d d1;
+ gp_Pnt2d p;
+ C2d->D1( u, p, d1 );
+ gp_Vec2d n( d1.Y(), -d1.X() );
+ if ( E.Orientation() == TopAbs_REVERSED )
+ n.Reverse();
+ N += n.Normalized();
+ }
+ }
+
+ // define step size by which to move theUV
+
+ gp_Pnt2d nextUV; // uv of next node on edge, most distant of the four
+ double maxDist = -DBL_MAX;
+ TopTools_ListIteratorOfListOfShape aEIt (EList);
+ list< double >::iterator aUIt = UList.begin();
+ for ( ; aEIt.More(); aEIt.Next(), aUIt++ )
+ {
+ const TopoDS_Edge& E = TopoDS::Edge( aEIt.Value() );
+ double f, l;
+ Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, theF, f, l);
+
+ double umin = DBL_MAX, umax = -DBL_MAX;
+ SMDS_NodeIteratorPtr nIt = theMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes();
+ if ( !nIt->more() ) // no nodes on edge, only on vertices
+ {
+ umin = l;
+ umax = f;
+ }
+ else {
+ while ( nIt->more() ) {
+ const SMDS_MeshNode* node = nIt->next();
+ // check if node is medium
+ if ( CreateQuadratic && SMESH_MesherHelper::IsMedium( node, SMDSAbs_Edge ))
+ continue;
+ const SMDS_EdgePosition* epos =
+ static_cast<const SMDS_EdgePosition*>(node->GetPosition().get());
+ double u = epos->GetUParameter();
+ if ( u < umin )
+ umin = u;
+ if ( u > umax )
+ umax = u;
+ }
+ }
+ bool isFirstCommon = ( *aUIt == f );
+ gp_Pnt2d uv = C2d->Value( isFirstCommon ? umin : umax );
+ double dist = theUV.SquareDistance( uv );
+ if ( dist > maxDist ) {
+ maxDist = dist;
+ nextUV = uv;
+ }
+ }
+ R2 uv0, uv1, uv2;
+ uv0.x = theUV.X(); uv0.y = theUV.Y();
+ uv1.x = nextUV.X(); uv1.y = nextUV.Y();
+ uv2.x = uv0.x; uv2.y = uv0.y;
+ if ( fixOverlappedLinkUV( uv0, uv1, uv2 ))
+ {
+ double step = theUV.Distance( gp_Pnt2d( uv0.x, uv0.y ));
+
+ // move theUV along the normal by the step
+
+ N *= step;
+
+ MESSAGE("--fixCommonVertexUV move(" << theUV.X() << " " << theUV.Y()
+ << ") by (" << N.X() << " " << N.Y() << ")"
+ << endl << "--- MAX DIST " << maxDist);
+
+ theUV.SetXY( theUV.XY() + N.XY() );
+
+ return true;
+ }
+ return false;