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 | |
c22b52d6 | 16 | #include <Adaptor2d_Curve2d.hxx> |
42cf5bc1 | 17 | #include <Adaptor3d_HVertex.hxx> |
18 | #include <BRep_Tool.hxx> | |
c22b52d6 | 19 | #include <BRepAdaptor_Curve2d.hxx> |
7fd59977 | 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, | |
c22b52d6 | 33 | const Handle(BRepAdaptor_Curve2d)& C): |
7fd59977 | 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 | |
c22b52d6 | 44 | (const Handle(Adaptor2d_Curve2d)& C) |
7fd59977 | 45 | { |
c22b52d6 | 46 | Handle(BRepAdaptor_Curve2d) brhc = Handle(BRepAdaptor_Curve2d)::DownCast(C); |
47 | return BRep_Tool::Parameter (myVtx, brhc->Edge(), brhc->Face()); | |
7fd59977 | 48 | } |
49 | ||
50 | ||
51 | Standard_Real BRepTopAdaptor_HVertex::Resolution | |
c22b52d6 | 52 | (const Handle(Adaptor2d_Curve2d)& C) |
7fd59977 | 53 | { |
c22b52d6 | 54 | Handle(BRepAdaptor_Curve2d) brhc = Handle(BRepAdaptor_Curve2d)::DownCast(C); |
55 | const TopoDS_Face& F = brhc->Face(); | |
7fd59977 | 56 | BRepAdaptor_Surface S(F,0); |
57 | Standard_Real tv = BRep_Tool::Tolerance(myVtx); | |
c22b52d6 | 58 | Standard_Real pp, p = BRep_Tool::Parameter (myVtx, brhc->Edge(), brhc->Face()); |
7fd59977 | 59 | TopAbs_Orientation Or = Orientation(); |
60 | gp_Pnt2d p2d; gp_Vec2d v2d; | |
61 | C->D1(p,p2d,v2d); | |
62 | gp_Pnt P, P1; | |
63 | gp_Vec DU, DV, DC; | |
64 | S.D1(p2d.X(),p2d.Y(),P,DU,DV); | |
65 | DC.SetLinearForm(v2d.X(),DU,v2d.Y(),DV); | |
66 | Standard_Real ResUV, mag = DC.Magnitude(); | |
67 | ||
68 | Standard_Real URes = S.UResolution(tv); | |
69 | Standard_Real VRes = S.VResolution(tv); | |
70 | Standard_Real tURes = C->Resolution(URes); | |
71 | Standard_Real tVRes = C->Resolution(VRes); | |
72 | Standard_Real ResUV1 = Max(tURes, tVRes); | |
73 | ||
74 | if(mag<1e-12) { | |
75 | ||
76 | return(ResUV1); | |
77 | ||
78 | } | |
79 | ||
0d969553 Y |
80 | // for lack of better options limit the parametric solution to |
81 | // 10 million*tolerance of the point | |
7fd59977 | 82 | |
83 | if(tv > 1.e7*mag) ResUV = 1.e7; | |
84 | else ResUV = tv/mag; | |
85 | ||
0d969553 | 86 | // Control |
7fd59977 | 87 | if (Or == TopAbs_REVERSED) pp = p+ResUV; |
88 | else pp = p-ResUV; | |
89 | ||
90 | Standard_Real UMin=C->FirstParameter(); | |
91 | Standard_Real UMax=C->LastParameter(); | |
92 | if(pp>UMax) pp=UMax; | |
93 | if(pp<UMin) pp=UMin; | |
94 | ||
95 | C->D0(pp, p2d); | |
96 | S.D0(p2d.X(),p2d.Y(),P1); | |
97 | ||
98 | Standard_Real Dist=P.Distance(P1); | |
99 | if ((Dist>1e-12) && ((Dist > 1.1*tv) || (Dist< 0.8*tv))) { | |
0d969553 | 100 | // Refine if possible |
7fd59977 | 101 | Standard_Real Dist1; |
102 | if (Or == TopAbs_REVERSED) pp = p+tv/Dist; | |
103 | else pp = p-tv/Dist; | |
104 | ||
105 | if(pp>UMax) pp=UMax; | |
106 | if(pp<UMin) pp=UMin; | |
107 | ||
108 | C->D1(pp, p2d, v2d); | |
109 | S.D1(p2d.X(),p2d.Y(),P1,DU,DV); | |
110 | DC.SetLinearForm(v2d.X(),DU,v2d.Y(),DV); | |
111 | Dist1 = P.Distance(P1); | |
112 | if (Abs(Dist1-tv) < Abs(Dist-tv)) { | |
0d969553 | 113 | // Take the result of interpolation |
7fd59977 | 114 | ResUV = tv/Dist; |
115 | Dist = Dist1; | |
116 | } | |
117 | ||
118 | mag = DC.Magnitude(); | |
119 | if(tv > 1.e7*mag) mag = tv*1.e-7; | |
120 | if (Or == TopAbs_REVERSED) pp = p+tv/mag; | |
121 | else pp = p-tv/mag; | |
122 | ||
123 | if(pp>UMax) pp=UMax; | |
124 | if(pp<UMin) pp=UMin; | |
125 | ||
126 | C->D0(pp, p2d); | |
127 | S.D0(p2d.X(),p2d.Y(),P1); | |
128 | Dist1 = P.Distance(P1); | |
129 | if (Abs(Dist1-tv) < Abs(Dist-tv)) { | |
0d969553 | 130 | // Take the new estimation |
7fd59977 | 131 | ResUV = tv/mag; |
132 | Dist = Dist1; | |
133 | } | |
134 | } | |
135 | ||
136 | return Min(ResUV, ResUV1); | |
137 | } | |
138 | ||
139 | ||
140 | TopAbs_Orientation BRepTopAdaptor_HVertex::Orientation () | |
141 | { | |
142 | return myVtx.Orientation(); | |
143 | } | |
144 | ||
145 | Standard_Boolean BRepTopAdaptor_HVertex::IsSame | |
146 | (const Handle(Adaptor3d_HVertex)& Other) | |
147 | { | |
148 | Handle(BRepTopAdaptor_HVertex) brhv = | |
149 | Handle(BRepTopAdaptor_HVertex)::DownCast(Other); | |
150 | return myVtx.IsSame(brhv->Vertex()); | |
151 | } | |
152 |