Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
b311480e | 14 | |
7fd59977 | 15 | |
42cf5bc1 | 16 | #include <Adaptor2d_HCurve2d.hxx> |
17 | #include <Adaptor3d_HVertex.hxx> | |
18 | #include <BRep_Tool.hxx> | |
7fd59977 | 19 | #include <BRepAdaptor_HCurve2d.hxx> |
20 | #include <BRepAdaptor_Surface.hxx> | |
42cf5bc1 | 21 | #include <BRepTopAdaptor_HVertex.hxx> |
7fd59977 | 22 | #include <gp_Pnt.hxx> |
7fd59977 | 23 | #include <gp_Pnt2d.hxx> |
42cf5bc1 | 24 | #include <gp_Vec.hxx> |
7fd59977 | 25 | #include <gp_Vec2d.hxx> |
42cf5bc1 | 26 | #include <Standard_Type.hxx> |
27 | #include <TopoDS_Vertex.hxx> | |
7fd59977 | 28 | |
92efcf78 | 29 | IMPLEMENT_STANDARD_RTTIEXT(BRepTopAdaptor_HVertex,Adaptor3d_HVertex) |
30 | ||
7fd59977 | 31 | BRepTopAdaptor_HVertex::BRepTopAdaptor_HVertex |
32 | (const TopoDS_Vertex& V, | |
33 | const Handle(BRepAdaptor_HCurve2d)& C): | |
34 | myVtx(V),myCurve(C) | |
35 | {} | |
36 | ||
37 | gp_Pnt2d BRepTopAdaptor_HVertex::Value () | |
38 | { | |
39 | // return myCurve->Value(Parameter(myCurve)); | |
0d969553 | 40 | return gp_Pnt2d(RealFirst(),RealFirst()); // do nothing |
7fd59977 | 41 | } |
42 | ||
43 | Standard_Real BRepTopAdaptor_HVertex::Parameter | |
44 | (const Handle(Adaptor2d_HCurve2d)& C) | |
45 | { | |
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()); | |
51 | } | |
52 | ||
53 | ||
54 | Standard_Real BRepTopAdaptor_HVertex::Resolution | |
55 | (const Handle(Adaptor2d_HCurve2d)& C) | |
56 | { | |
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 | |
63 | (myVtx, | |
64 | ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Edge(), | |
65 | ((BRepAdaptor_Curve2d *)&(brhc->Curve2d()))->Face()); | |
66 | TopAbs_Orientation Or = Orientation(); | |
67 | gp_Pnt2d p2d; gp_Vec2d v2d; | |
68 | C->D1(p,p2d,v2d); | |
69 | gp_Pnt P, P1; | |
70 | gp_Vec DU, DV, DC; | |
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(); | |
74 | ||
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); | |
80 | ||
81 | if(mag<1e-12) { | |
82 | ||
83 | return(ResUV1); | |
84 | ||
85 | } | |
86 | ||
0d969553 Y |
87 | // for lack of better options limit the parametric solution to |
88 | // 10 million*tolerance of the point | |
7fd59977 | 89 | |
90 | if(tv > 1.e7*mag) ResUV = 1.e7; | |
91 | else ResUV = tv/mag; | |
92 | ||
0d969553 | 93 | // Control |
7fd59977 | 94 | if (Or == TopAbs_REVERSED) pp = p+ResUV; |
95 | else pp = p-ResUV; | |
96 | ||
97 | Standard_Real UMin=C->FirstParameter(); | |
98 | Standard_Real UMax=C->LastParameter(); | |
99 | if(pp>UMax) pp=UMax; | |
100 | if(pp<UMin) pp=UMin; | |
101 | ||
102 | C->D0(pp, p2d); | |
103 | S.D0(p2d.X(),p2d.Y(),P1); | |
104 | ||
105 | Standard_Real Dist=P.Distance(P1); | |
106 | if ((Dist>1e-12) && ((Dist > 1.1*tv) || (Dist< 0.8*tv))) { | |
0d969553 | 107 | // Refine if possible |
7fd59977 | 108 | Standard_Real Dist1; |
109 | if (Or == TopAbs_REVERSED) pp = p+tv/Dist; | |
110 | else pp = p-tv/Dist; | |
111 | ||
112 | if(pp>UMax) pp=UMax; | |
113 | if(pp<UMin) pp=UMin; | |
114 | ||
115 | C->D1(pp, p2d, v2d); | |
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)) { | |
0d969553 | 120 | // Take the result of interpolation |
7fd59977 | 121 | ResUV = tv/Dist; |
122 | Dist = Dist1; | |
123 | } | |
124 | ||
125 | mag = DC.Magnitude(); | |
126 | if(tv > 1.e7*mag) mag = tv*1.e-7; | |
127 | if (Or == TopAbs_REVERSED) pp = p+tv/mag; | |
128 | else pp = p-tv/mag; | |
129 | ||
130 | if(pp>UMax) pp=UMax; | |
131 | if(pp<UMin) pp=UMin; | |
132 | ||
133 | C->D0(pp, p2d); | |
134 | S.D0(p2d.X(),p2d.Y(),P1); | |
135 | Dist1 = P.Distance(P1); | |
136 | if (Abs(Dist1-tv) < Abs(Dist-tv)) { | |
0d969553 | 137 | // Take the new estimation |
7fd59977 | 138 | ResUV = tv/mag; |
139 | Dist = Dist1; | |
140 | } | |
141 | } | |
142 | ||
143 | return Min(ResUV, ResUV1); | |
144 | } | |
145 | ||
146 | ||
147 | TopAbs_Orientation BRepTopAdaptor_HVertex::Orientation () | |
148 | { | |
149 | return myVtx.Orientation(); | |
150 | } | |
151 | ||
152 | Standard_Boolean BRepTopAdaptor_HVertex::IsSame | |
153 | (const Handle(Adaptor3d_HVertex)& Other) | |
154 | { | |
155 | Handle(BRepTopAdaptor_HVertex) brhv = | |
156 | Handle(BRepTopAdaptor_HVertex)::DownCast(Other); | |
157 | return myVtx.IsSame(brhv->Vertex()); | |
158 | } | |
159 |