1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Adaptor2d_HCurve2d.hxx>
17 #include <Adaptor3d_HVertex.hxx>
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_HCurve2d.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepTopAdaptor_HVertex.hxx>
23 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
26 #include <Standard_Type.hxx>
27 #include <TopoDS_Vertex.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(BRepTopAdaptor_HVertex,Adaptor3d_HVertex)
31 BRepTopAdaptor_HVertex::BRepTopAdaptor_HVertex
32 (const TopoDS_Vertex& V,
33 const Handle(BRepAdaptor_HCurve2d)& C):
37 gp_Pnt2d BRepTopAdaptor_HVertex::Value ()
39 // return myCurve->Value(Parameter(myCurve));
40 return gp_Pnt2d(RealFirst(),RealFirst()); // do nothing
43 Standard_Real BRepTopAdaptor_HVertex::Parameter
44 (const Handle(Adaptor2d_HCurve2d)& C)
46 Handle(BRepAdaptor_HCurve2d) brhc =
47 Handle(BRepAdaptor_HCurve2d)::DownCast(C);
48 return BRep_Tool::Parameter(myVtx,
49 ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Edge(),
50 ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Face());
54 Standard_Real BRepTopAdaptor_HVertex::Resolution
55 (const Handle(Adaptor2d_HCurve2d)& C)
57 Handle(BRepAdaptor_HCurve2d) brhc =
58 Handle(BRepAdaptor_HCurve2d)::DownCast(C);
59 const TopoDS_Face& F = ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Face();
60 BRepAdaptor_Surface S(F,0);
61 Standard_Real tv = BRep_Tool::Tolerance(myVtx);
62 Standard_Real pp, p = BRep_Tool::Parameter
64 ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Edge(),
65 ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Face());
66 TopAbs_Orientation Or = Orientation();
67 gp_Pnt2d p2d; gp_Vec2d v2d;
71 S.D1(p2d.X(),p2d.Y(),P,DU,DV);
72 DC.SetLinearForm(v2d.X(),DU,v2d.Y(),DV);
73 Standard_Real ResUV, mag = DC.Magnitude();
75 Standard_Real URes = S.UResolution(tv);
76 Standard_Real VRes = S.VResolution(tv);
77 Standard_Real tURes = C->Resolution(URes);
78 Standard_Real tVRes = C->Resolution(VRes);
79 Standard_Real ResUV1 = Max(tURes, tVRes);
87 // for lack of better options limit the parametric solution to
88 // 10 million*tolerance of the point
90 if(tv > 1.e7*mag) ResUV = 1.e7;
94 if (Or == TopAbs_REVERSED) pp = p+ResUV;
97 Standard_Real UMin=C->FirstParameter();
98 Standard_Real UMax=C->LastParameter();
103 S.D0(p2d.X(),p2d.Y(),P1);
105 Standard_Real Dist=P.Distance(P1);
106 if ((Dist>1e-12) && ((Dist > 1.1*tv) || (Dist< 0.8*tv))) {
107 // Refine if possible
109 if (Or == TopAbs_REVERSED) pp = p+tv/Dist;
116 S.D1(p2d.X(),p2d.Y(),P1,DU,DV);
117 DC.SetLinearForm(v2d.X(),DU,v2d.Y(),DV);
118 Dist1 = P.Distance(P1);
119 if (Abs(Dist1-tv) < Abs(Dist-tv)) {
120 // Take the result of interpolation
125 mag = DC.Magnitude();
126 if(tv > 1.e7*mag) mag = tv*1.e-7;
127 if (Or == TopAbs_REVERSED) pp = p+tv/mag;
134 S.D0(p2d.X(),p2d.Y(),P1);
135 Dist1 = P.Distance(P1);
136 if (Abs(Dist1-tv) < Abs(Dist-tv)) {
137 // Take the new estimation
143 return Min(ResUV, ResUV1);
147 TopAbs_Orientation BRepTopAdaptor_HVertex::Orientation ()
149 return myVtx.Orientation();
152 Standard_Boolean BRepTopAdaptor_HVertex::IsSame
153 (const Handle(Adaptor3d_HVertex)& Other)
155 Handle(BRepTopAdaptor_HVertex) brhv =
156 Handle(BRepTopAdaptor_HVertex)::DownCast(Other);
157 return myVtx.IsSame(brhv->Vertex());