0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / GCPnts / GCPnts_TangentialDeflection.cxx
CommitLineData
b311480e 1// Created on: 1996-11-08
2// Created by: Jean Claude VAUTHIER
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <Adaptor2d_Curve2d.hxx>
19#include <Adaptor3d_Curve.hxx>
20#include <GCPnts_TangentialDeflection.hxx>
21#include <gp_Pnt.hxx>
7fd59977 22#include <gp_Pnt2d.hxx>
23#include <gp_Vec.hxx>
24#include <gp_Vec2d.hxx>
25#include <gp_XYZ.hxx>
26#include <Precision.hxx>
42cf5bc1 27#include <Standard_ConstructionError.hxx>
28#include <Standard_OutOfRange.hxx>
fa89e082 29#include <TColStd_Array1OfReal.hxx>
7fd59977 30
31inline static void D0 (const Adaptor3d_Curve& C, const Standard_Real U, gp_Pnt& P)
32{
33 C.D0 (U, P);
34}
35
36inline static void D2 (const Adaptor3d_Curve& C, const Standard_Real U,
37 gp_Pnt& P, gp_Vec& V1, gp_Vec& V2)
38{
39 C.D2 (U, P, V1, V2);
40}
41
42
43static void D0 (const Adaptor2d_Curve2d& C, const Standard_Real U, gp_Pnt& PP)
44{
45 Standard_Real X, Y;
46 gp_Pnt2d P;
47 C.D0 (U, P);
48 P.Coord (X, Y);
49 PP.SetCoord (X, Y, 0.0);
50}
51
52static void D2 (const Adaptor2d_Curve2d& C, const Standard_Real U,
53 gp_Pnt& PP, gp_Vec& VV1, gp_Vec& VV2)
54{
55 Standard_Real X, Y;
56 gp_Pnt2d P;
57 gp_Vec2d V1,V2;
58 C.D2 (U, P, V1, V2);
59 P.Coord (X, Y);
60 PP.SetCoord (X, Y, 0.0);
61 V1.Coord (X, Y);
62 VV1.SetCoord (X, Y, 0.0);
63 V2.Coord (X, Y);
64 VV2.SetCoord (X, Y, 0.0);
65}
66
9c1519c4 67static Standard_Real EstimAngl(const gp_Pnt& P1, const gp_Pnt& Pm, const gp_Pnt& P2)
68{
69 gp_Vec V1(P1, Pm), V2(Pm, P2);
70 Standard_Real L = V1.Magnitude() * V2.Magnitude();
71 //
72 if(L > gp::Resolution())
73 {
74 return V1.CrossMagnitude(V2)/L;
75 }
76 else
77 {
78 return 0.;
79 }
80}
81
82
fa89e082 83// Return number of interval of continuity on which theParam is located.
84// Last parameter is used to increase search speed.
85static Standard_Integer getIntervalIdx(const Standard_Real theParam,
86 TColStd_Array1OfReal& theIntervs,
87 const Standard_Integer thePreviousIdx)
88{
89 Standard_Integer anIdx;
90 for(anIdx = thePreviousIdx; anIdx < theIntervs.Upper(); anIdx++)
91 {
92 if (theParam >= theIntervs(anIdx) &&
93 theParam <= theIntervs(anIdx + 1)) // Inside of anIdx interval.
94 {
95 break;
96 }
97 }
98 return anIdx;
99}
9c1519c4 100//
7fd59977 101//=======================================================================
102//function : CPnts_TangentialDeflection
103//purpose :
104//=======================================================================
105
106GCPnts_TangentialDeflection::GCPnts_TangentialDeflection () { }
107
108//=======================================================================
109//function : AddPoint
110//purpose :
111//=======================================================================
112
113Standard_Integer GCPnts_TangentialDeflection::AddPoint
114 (const gp_Pnt& thePnt,
115 const Standard_Real theParam,
116 const Standard_Boolean theIsReplace)
117{
118 const Standard_Real tol = Precision::PConfusion();
119 Standard_Integer index = -1;
120 const Standard_Integer nb = parameters.Length();
121 for ( Standard_Integer i = 1; index == -1 && i <= nb; i++ )
122 {
123 Standard_Real dist = parameters.Value( i ) - theParam;
124 if ( fabs( dist ) <= tol )
125 {
126 index = i;
127 if ( theIsReplace )
128 {
129 points.ChangeValue(i) = thePnt;
130 parameters.ChangeValue(i) = theParam;
131 }
132 }
133 else if ( dist > tol )
134 {
135 points.InsertBefore( i, thePnt );
136 parameters.InsertBefore( i, theParam );
137 index = i;
138 }
139 }
140 if ( index == -1 )
141 {
142 points.Append( thePnt );
143 parameters.Append( theParam );
144 index = parameters.Length();
145 }
146 return index;
147}
148
74da0216 149//=======================================================================
150//function : ArcAngularStep
151//purpose :
152//=======================================================================
153Standard_Real GCPnts_TangentialDeflection::ArcAngularStep(
154 const Standard_Real theRadius,
155 const Standard_Real theLinearDeflection,
156 const Standard_Real theAngularDeflection,
157 const Standard_Real theMinLength)
158{
159 Standard_ConstructionError_Raise_if(theRadius < 0.0, "Negative radius");
160
161 const Standard_Real aPrecision = Precision::Confusion();
162
163 Standard_Real Du = 0.0, aMinSizeAng = 0.0;
164 if (theRadius > aPrecision)
165 {
166 Du = Max(1.0 - (theLinearDeflection / theRadius), 0.0);
167
168 // It is not suitable to consider min size greater than 1/4 arc len.
169 if (theMinLength > aPrecision)
170 aMinSizeAng = Min(theMinLength / theRadius, M_PI_2);
171 }
172 Du = 2.0 * ACos(Du);
173 Du = Max(Min(Du, theAngularDeflection), aMinSizeAng);
174 return Du;
175}
7fd59977 176
177#include <Geom_BezierCurve.hxx>
178#include <Geom_BSplineCurve.hxx>
179#include <gp_Circ.hxx>
9c1519c4 180#include <GCPnts_DistFunction.hxx>
9bf3ef83 181
7fd59977 182#define TheCurve Adaptor3d_Curve
183#define Handle_TheBezierCurve Handle(Geom_BezierCurve)
184#define Handle_TheBSplineCurve Handle(Geom_BSplineCurve)
9c1519c4 185#define TheMaxCurvLinDist GCPnts_DistFunction
186#define TheMaxCurvLinDistMV GCPnts_DistFunctionMV
9bf3ef83 187#include "GCPnts_TangentialDeflection.pxx"
7fd59977 188#undef Handle_TheBezierCurve
189#undef Handle_TheBSplineCurve
190#undef TheCurve
9c1519c4 191#undef TheMaxCurvLinDist
192#undef TheMaxCurvLinDistMV
7fd59977 193
194
195#include <Geom2d_BezierCurve.hxx>
196#include <Geom2d_BSplineCurve.hxx>
197#include <gp_Circ2d.hxx>
9c1519c4 198#include <GCPnts_DistFunction2d.hxx>
7fd59977 199#define TheCurve Adaptor2d_Curve2d
200#define Handle_TheBezierCurve Handle(Geom2d_BezierCurve)
201#define Handle_TheBSplineCurve Handle(Geom2d_BSplineCurve)
9c1519c4 202#define TheMaxCurvLinDist GCPnts_DistFunction2d
203#define TheMaxCurvLinDistMV GCPnts_DistFunction2dMV
9bf3ef83 204#include "GCPnts_TangentialDeflection.pxx"
7fd59977 205#undef Handle_TheBezierCurve
206#undef Handle_TheBSplineCurve
207#undef TheCurve
9c1519c4 208#undef TheMaxCurvLinDist
209#undef TheMaxCurvLinDistMV