973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
7fd59977 |
15 | #include <BRep_Tool.hxx> |
42cf5bc1 |
16 | #include <Geom2d_Curve.hxx> |
17 | #include <Geom_Curve.hxx> |
7fd59977 |
18 | #include <gp.hxx> |
42cf5bc1 |
19 | #include <ShapeAnalysis_Edge.hxx> |
20 | #include <ShapeAnalysis_TransferParameters.hxx> |
7fd59977 |
21 | #include <ShapeBuild_Edge.hxx> |
42cf5bc1 |
22 | #include <Standard_Type.hxx> |
23 | #include <TColStd_HArray1OfReal.hxx> |
24 | #include <TopoDS_Edge.hxx> |
25 | #include <TopoDS_Face.hxx> |
7fd59977 |
26 | |
25e59720 |
27 | IMPLEMENT_STANDARD_RTTIEXT(ShapeAnalysis_TransferParameters,Standard_Transient) |
92efcf78 |
28 | |
7fd59977 |
29 | //======================================================================= |
30 | //function : ShapeAnalysis_TransferParameters |
31 | //purpose : |
32 | //======================================================================= |
7fd59977 |
33 | ShapeAnalysis_TransferParameters::ShapeAnalysis_TransferParameters() |
34 | { |
35 | myScale = 1.; |
36 | myShift = 0.; |
37 | } |
38 | |
39 | |
40 | //======================================================================= |
41 | //function : ShapeAnalysis_TransferParameters |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | ShapeAnalysis_TransferParameters::ShapeAnalysis_TransferParameters(const TopoDS_Edge& E, |
46 | const TopoDS_Face& F) |
47 | { |
48 | Init(E,F); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Init |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void ShapeAnalysis_TransferParameters::Init(const TopoDS_Edge& E, const TopoDS_Face& F) |
57 | { |
58 | myScale = 1.; |
59 | myShift = 0.; |
5cbfdb41 |
60 | Standard_Real l,f,l2d = 0.0,f2d = 0.0; |
7fd59977 |
61 | TopLoc_Location L; |
62 | myEdge = E; |
63 | ShapeAnalysis_Edge sae; |
64 | Handle(Geom_Curve) curve3d;// = BRep_Tool::Curve (E,f,l); |
65 | sae.Curve3d ( E, curve3d, f, l ,Standard_False); |
66 | myFirst = f; |
67 | myLast = l; |
68 | Handle(Geom2d_Curve) curve2d;// = BRep_Tool::CurveOnSurface (E, F, f2d,l2d); |
69 | // ShapeAnalysis_Edge sae; |
70 | if (! F.IsNull() ) { // process free edges |
71 | sae.PCurve ( E, F, curve2d, f2d, l2d,Standard_False ); |
72 | } |
73 | myFirst2d = f2d; |
74 | myLast2d = l2d; |
75 | myFace = F; |
76 | if ( curve3d.IsNull() || curve2d.IsNull() ) return; |
77 | |
78 | Standard_Real ln2d = l2d - f2d; |
79 | Standard_Real ln3d = l - f; |
80 | myScale = ( ln3d <= gp::Resolution() ? 1. : ln2d / ln3d ); |
81 | myShift = f2d - f * myScale; |
82 | } |
83 | |
84 | //======================================================================= |
85 | //function : SetMaxTolerance |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | void ShapeAnalysis_TransferParameters::SetMaxTolerance( const Standard_Real maxtol ) |
90 | { |
91 | myMaxTolerance = maxtol; |
92 | } |
93 | |
94 | |
95 | //======================================================================= |
96 | //function : Perform |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | |
101 | Handle(TColStd_HSequenceOfReal) ShapeAnalysis_TransferParameters::Perform |
102 | (const Handle(TColStd_HSequenceOfReal)& Params, |
103 | const Standard_Boolean To2d) |
104 | { |
105 | Handle(TColStd_HSequenceOfReal) res = new TColStd_HSequenceOfReal; |
106 | for (Standard_Integer i = 1 ; i <= Params->Length(); i++) |
107 | res->Append(Perform(Params->Value(i),To2d)); |
108 | return res; |
109 | |
110 | } |
111 | |
112 | |
113 | //======================================================================= |
114 | //function : Perform |
115 | //purpose : |
116 | //======================================================================= |
117 | |
118 | Standard_Real ShapeAnalysis_TransferParameters::Perform(const Standard_Real Param, |
119 | const Standard_Boolean To2d) |
120 | { |
121 | Standard_Real NewParam; |
122 | if(To2d) |
123 | NewParam = myShift + Param*myScale; |
124 | else |
125 | NewParam = -myShift/myScale + Param*1./myScale; |
126 | return NewParam; |
127 | } |
128 | |
129 | |
130 | //======================================================================= |
131 | //function : TransferRange |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | void ShapeAnalysis_TransferParameters::TransferRange(TopoDS_Edge& newEdge, |
136 | const Standard_Real prevPar, |
137 | const Standard_Real currPar, |
138 | const Standard_Boolean Is2d) |
139 | { |
140 | ShapeBuild_Edge sbe; |
141 | if(Is2d) { |
142 | Standard_Real span2d = myLast2d - myFirst2d; |
143 | Standard_Real tmp1,tmp2; |
144 | if(prevPar > currPar) { |
145 | tmp1 = currPar; |
146 | tmp2 = prevPar; |
147 | } |
148 | else { |
149 | tmp1 = prevPar; |
150 | tmp2 = currPar; |
151 | } |
152 | Standard_Real alpha = (tmp1-myFirst2d) / span2d; |
153 | Standard_Real beta = (tmp2 - myFirst2d) / span2d; |
154 | sbe.CopyRanges(newEdge,myEdge, alpha, beta); |
155 | } |
156 | else { |
157 | Standard_Real alpha = (prevPar-myFirst)/(myLast - myFirst); |
158 | Standard_Real beta = (currPar - myFirst)/(myLast - myFirst); |
159 | sbe.CopyRanges(newEdge,myEdge, alpha, beta); |
160 | } |
161 | } |
162 | |
163 | |
164 | //======================================================================= |
165 | //function : IsSameRange |
166 | //purpose : |
167 | //======================================================================= |
168 | |
169 | Standard_Boolean ShapeAnalysis_TransferParameters::IsSameRange() const |
170 | { |
171 | return myShift == 0. && myScale == 1.; |
172 | } |