1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
// File: IntTools.cxx
// Created: Tue Aug 1 09:24:34 2000
// Author: Peter KURNEV
// <pkv@irinox>
#include <IntTools.ixx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <BRep_Tool.hxx>
#include <IntTools_Root.hxx>
#include <IntTools_Array1OfRoots.hxx>
#include <IntTools_Compare.hxx>
#include <IntTools_QuickSort.hxx>
#include <IntTools_Root.hxx>
#include <gce_MakeCirc.hxx>
#include <gp_Circ.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <IntTools_CArray1OfReal.hxx>
#include <TColStd_ListOfReal.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <TColStd_ListIteratorOfListOfReal.hxx>
#include <gce_ErrorType.hxx>
//=======================================================================
//function : IntTools::GetRadius
//purpose :
//=======================================================================
Standard_Integer IntTools::GetRadius(const BRepAdaptor_Curve& C,
const Standard_Real t1,
const Standard_Real t3,
Standard_Real& aR)
{
GeomAbs_CurveType aType=C.GetType();
if (aType==GeomAbs_Line) {
return 1;
}
if (aType==GeomAbs_Circle) {
gp_Circ aCrc=C.Circle();
aR=aCrc.Radius();
return 0;
}
Standard_Real t2;
gp_Pnt P1, P2, P3;
t2=0.5*(t1+t3);
P1=C.Value(t1);
P2=C.Value(t2);
P3=C.Value(t3);
//
//
gce_MakeCirc aMakeCirc(P1, P2, P3);
gce_ErrorType anErrorType;
anErrorType=aMakeCirc.Status();
if (!aMakeCirc.IsDone()) {
if (anErrorType==gce_ConfusedPoints ||
anErrorType==gce_IntersectionError ||
anErrorType==gce_ColinearPoints) {//modified by NIZNHY-PKV Fri Sep 24 09:54:05 2004ft
return 2;
}
return -1;
}
//
//
gp_Circ aCirc=aMakeCirc.Value();
aR=aCirc.Radius();
return 0;
}
//=======================================================================
//function : PrepareArgs
//purpose :
//=======================================================================
Standard_Integer IntTools::PrepareArgs(BRepAdaptor_Curve& C,
const Standard_Real Tmax,
const Standard_Real Tmin,
const Standard_Integer Discret,
const Standard_Real Deflection,
IntTools_CArray1OfReal& anArgs)
{
TColStd_ListOfReal aPars;
Standard_Real dt, tCurrent, tNext, aR, anAbsDeflection;
Standard_Integer ip, i, j, aNbDeflectionPoints, aDiscretBis;
Standard_Boolean aRFlag;
GeomAbs_CurveType aCurveType;
aCurveType=C.GetType();
dt=(Tmax-Tmin)/Discret;
aRFlag=(dt > 1.e-5);
for (i=1; i<=Discret; i++) {
tCurrent=Tmin+(i-1)*dt;
aPars.Append(tCurrent);
tNext=tCurrent+dt;
if (i==Discret)
tNext=Tmax;
///////////////////////////////////////////////////
if (!aRFlag) {
continue;
}
if (aCurveType==GeomAbs_BSplineCurve||
aCurveType==GeomAbs_BezierCurve ||
aCurveType==GeomAbs_Ellipse ||
aCurveType==GeomAbs_OtherCurve) { //modified by NIZNHY-PKV Fri Sep 24 09:52:42 2004ft
continue;
}
//
ip=IntTools::GetRadius (C, tCurrent, tNext, aR);
if (ip<0) {
return 1;
}
//
if (!ip) {
anAbsDeflection=Deflection*aR;
GCPnts_QuasiUniformDeflection anUD;
anUD.Initialize (C, anAbsDeflection, tCurrent, tNext);
if (!anUD.IsDone()) {
return 2;
}
aNbDeflectionPoints=anUD.NbPoints();
if (aNbDeflectionPoints > 2) {
aNbDeflectionPoints--;
for (j=2; j<=aNbDeflectionPoints; j++) {
tCurrent=anUD.Parameter(j);
aPars.Append(tCurrent);
}
}
}
}
aPars.Append(Tmax);
aDiscretBis=aPars.Extent();
anArgs.Resize(aDiscretBis);
TColStd_ListIteratorOfListOfReal anIt(aPars);
for (i=0; anIt.More(); anIt.Next(), i++) {
anArgs(i)=anIt.Value();
}
return 0;
}
//=======================================================================
//function : IntTools::Length
//purpose :
//=======================================================================
Standard_Real IntTools::Length (const TopoDS_Edge& anEdge)
{
Standard_Real aLength=0;
if (!BRep_Tool::Degenerated(anEdge) &&
BRep_Tool::IsGeometric(anEdge)) {
GProp_GProps Temp;
BRepGProp::LinearProperties(anEdge, Temp);
aLength = Temp.Mass();
}
return aLength;
}
//=======================================================================
//function : RemoveIdenticalRoots
//purpose :
//=======================================================================
void IntTools::RemoveIdenticalRoots(IntTools_SequenceOfRoots& aSR,
const Standard_Real anEpsT)
{
Standard_Integer aNbRoots, j, k;
Standard_Real anEpsT2=0.5*anEpsT;
aNbRoots=aSR.Length();
for (j=1; j<=aNbRoots; j++) {
const IntTools_Root& aRj=aSR(j);
for (k=j+1; k<=aNbRoots; k++) {
const IntTools_Root& aRk=aSR(k);
if (fabs (aRj.Root()-aRk.Root()) < anEpsT2) {
aSR.Remove(k);
aNbRoots=aSR.Length();
}
}
}
}
//=======================================================================
//function : SortRoots
//purpose :
//=======================================================================
void IntTools::SortRoots(IntTools_SequenceOfRoots& mySequenceOfRoots,
const Standard_Real myEpsT)
{
Standard_Integer j, aNbRoots;
aNbRoots=mySequenceOfRoots.Length();
IntTools_Array1OfRoots anArray1OfRoots(1, aNbRoots);
IntTools_Compare aComparator(myEpsT);
for (j=1; j<=aNbRoots; j++) {
anArray1OfRoots(j)=mySequenceOfRoots(j);
}
IntTools_QuickSort::Sort(anArray1OfRoots, aComparator);
mySequenceOfRoots.Clear();
for (j=1; j<=aNbRoots; j++) {
mySequenceOfRoots.Append(anArray1OfRoots(j));
}
}
//=======================================================================
//function :FindRootStates
//purpose :
//=======================================================================
void IntTools::FindRootStates(IntTools_SequenceOfRoots& mySequenceOfRoots,
const Standard_Real myEpsNull)
{
Standard_Integer aType, j, aNbRoots;
Standard_Real t1, t2, f1, f2, absf2;
aNbRoots=mySequenceOfRoots.Length();
for (j=1; j<=aNbRoots; j++) {
IntTools_Root& aR=mySequenceOfRoots.ChangeValue(j);
aR.Interval (t1, t2, f1, f2);
aType=aR.Type();
switch (aType) {
case 0: // Simple Root
if (f1>0. && f2<0.) {
aR.SetStateBefore(TopAbs_OUT);
aR.SetStateAfter (TopAbs_IN);
}
else {
aR.SetStateBefore(TopAbs_IN);
aR.SetStateAfter (TopAbs_OUT);
}
break;
case 1: // Complete 0;
aR.SetStateBefore(TopAbs_ON);
aR.SetStateAfter (TopAbs_ON);
break;
case 2: // Smart;
absf2=fabs(f2);
if (absf2 < myEpsNull) {
aR.SetStateAfter (TopAbs_ON);
if (f1>0.) {
aR.SetStateBefore(TopAbs_OUT);
}
else {
aR.SetStateBefore(TopAbs_IN);
}
}
else {
aR.SetStateBefore(TopAbs_ON);
if (f2>0.) {
aR.SetStateAfter (TopAbs_OUT);
}
else {
aR.SetStateAfter (TopAbs_IN);
}
}
default: break;
} // switch (aType)
}
}
#include <GeomAdaptor_Curve.hxx>
#include <gp_Pnt.hxx>
#include <ElCLib.hxx>
#include <gp_Lin.hxx>
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Hypr.hxx>
#include <gp_Parab.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
//=======================================================================
//function :Parameter
//purpose :
//=======================================================================
Standard_Integer IntTools::Parameter (const gp_Pnt& aP,
const Handle(Geom_Curve)& aCurve,
Standard_Real& aParameter)
{
Standard_Real aFirst, aLast;
GeomAbs_CurveType aCurveType;
aFirst=aCurve->FirstParameter();
aLast =aCurve->LastParameter ();
GeomAdaptor_Curve aGAC;
aGAC.Load (aCurve, aFirst, aLast);
aCurveType=aGAC.GetType();
switch (aCurveType){
case GeomAbs_Line:
{
gp_Lin aLin=aGAC.Line();
aParameter=ElCLib::Parameter (aLin, aP);
return 0;
}
case GeomAbs_Circle:
{
gp_Circ aCircle=aGAC.Circle();
aParameter=ElCLib::Parameter (aCircle, aP);
return 0;
}
case GeomAbs_Ellipse:
{
gp_Elips aElips=aGAC.Ellipse();
aParameter=ElCLib::Parameter (aElips, aP);
return 0;
}
case GeomAbs_Hyperbola:
{
gp_Hypr aHypr=aGAC.Hyperbola();
aParameter=ElCLib::Parameter (aHypr, aP);
return 0;
}
case GeomAbs_Parabola:
{
gp_Parab aParab=aGAC.Parabola();
aParameter=ElCLib::Parameter (aParab, aP);
return 0;
}
case GeomAbs_BezierCurve:
case GeomAbs_BSplineCurve:
{
GeomAPI_ProjectPointOnCurve aProjector;
aProjector.Init(aP, aCurve, aFirst, aLast);
Standard_Integer aNbPoints=aProjector.NbPoints();
if (aNbPoints) {
aParameter=aProjector.LowerDistanceParameter();
return 0;
}
else {
return 2;
}
break;
}
default:
break;
}
return 1;
}
|