1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <ShapeAnalysis_TransferParameters.ixx>
19 #include <Geom_Curve.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <ShapeAnalysis_Edge.hxx>
22 #include <TColStd_HArray1OfReal.hxx>
23 #include <BRep_Tool.hxx>
25 #include <ShapeBuild_Edge.hxx>
28 //=======================================================================
29 //function : ShapeAnalysis_TransferParameters
31 //=======================================================================
33 ShapeAnalysis_TransferParameters::ShapeAnalysis_TransferParameters()
40 //=======================================================================
41 //function : ShapeAnalysis_TransferParameters
43 //=======================================================================
45 ShapeAnalysis_TransferParameters::ShapeAnalysis_TransferParameters(const TopoDS_Edge& E,
51 //=======================================================================
54 //=======================================================================
56 void ShapeAnalysis_TransferParameters::Init(const TopoDS_Edge& E, const TopoDS_Face& F)
60 Standard_Real l,f,l2d,f2d;
63 ShapeAnalysis_Edge sae;
64 Handle(Geom_Curve) curve3d;// = BRep_Tool::Curve (E,f,l);
65 sae.Curve3d ( E, curve3d, f, l ,Standard_False);
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 );
76 if ( curve3d.IsNull() || curve2d.IsNull() ) return;
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;
84 //=======================================================================
85 //function : SetMaxTolerance
87 //=======================================================================
89 void ShapeAnalysis_TransferParameters::SetMaxTolerance( const Standard_Real maxtol )
91 myMaxTolerance = maxtol;
95 //=======================================================================
98 //=======================================================================
101 Handle(TColStd_HSequenceOfReal) ShapeAnalysis_TransferParameters::Perform
102 (const Handle(TColStd_HSequenceOfReal)& Params,
103 const Standard_Boolean To2d)
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));
113 //=======================================================================
116 //=======================================================================
118 Standard_Real ShapeAnalysis_TransferParameters::Perform(const Standard_Real Param,
119 const Standard_Boolean To2d)
121 Standard_Real NewParam;
123 NewParam = myShift + Param*myScale;
125 NewParam = -myShift/myScale + Param*1./myScale;
130 //=======================================================================
131 //function : TransferRange
133 //=======================================================================
135 void ShapeAnalysis_TransferParameters::TransferRange(TopoDS_Edge& newEdge,
136 const Standard_Real prevPar,
137 const Standard_Real currPar,
138 const Standard_Boolean Is2d)
142 Standard_Real span2d = myLast2d - myFirst2d;
143 Standard_Real tmp1,tmp2;
144 if(prevPar > currPar) {
152 Standard_Real alpha = (tmp1-myFirst2d) / span2d;
153 Standard_Real beta = (tmp2 - myFirst2d) / span2d;
154 sbe.CopyRanges(newEdge,myEdge, alpha, beta);
157 Standard_Real alpha = (prevPar-myFirst)/(myLast - myFirst);
158 Standard_Real beta = (currPar - myFirst)/(myLast - myFirst);
159 sbe.CopyRanges(newEdge,myEdge, alpha, beta);
164 //=======================================================================
165 //function : IsSameRange
167 //=======================================================================
169 Standard_Boolean ShapeAnalysis_TransferParameters::IsSameRange() const
171 return myShift == 0. && myScale == 1.;