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
|
#include <VrmlConverter_DeflectionCurve.ixx>
#include <gp_Pnt.hxx>
#include <gp_Circ.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <Bnd_Box.hxx>
#include <Precision.hxx>
#include <TColgp_HArray1OfVec.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <Vrml_Material.hxx>
#include <VrmlConverter_LineAspect.hxx>
#include <Vrml_Separator.hxx>
#include <Vrml_Coordinate3.hxx>
#include <Vrml_IndexedLineSet.hxx>
#include <Precision.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <BndLib_Add3dCurve.hxx>
//==================================================================
// function: FindLimits
// purpose:
//==================================================================
static void FindLimits(const Adaptor3d_Curve& aCurve,
const Standard_Real aLimit,
Standard_Real& First,
Standard_Real& Last)
{
First = aCurve.FirstParameter();
Last = aCurve.LastParameter();
Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
if (firstInf || lastInf) {
gp_Pnt P1,P2;
Standard_Real delta = 1;
if (firstInf && lastInf) {
do {
delta *= 2;
First = - delta;
Last = delta;
aCurve.D0(First,P1);
aCurve.D0(Last,P2);
} while (P1.Distance(P2) < aLimit);
}
else if (firstInf) {
aCurve.D0(Last,P2);
do {
delta *= 2;
First = Last - delta;
aCurve.D0(First,P1);
} while (P1.Distance(P2) < aLimit);
}
else if (lastInf) {
aCurve.D0(First,P1);
do {
delta *= 2;
Last = First + delta;
aCurve.D0(Last,P2);
} while (P1.Distance(P2) < aLimit);
}
}
}
//==================================================================
// function: DrawCurve
// purpose:
//==================================================================
static void DrawCurve (Adaptor3d_Curve& aCurve,
const Standard_Real TheDeflection,
const Standard_Real U1,
const Standard_Real U2,
const Handle(VrmlConverter_Drawer)& aDrawer, // for passsing of LineAspect
Standard_OStream& anOStream)
{
Standard_Integer i;
Standard_Boolean key = Standard_False;
Handle(TColgp_HArray1OfVec) HAV1;
Handle(TColStd_HArray1OfInteger) HAI1;
switch (aCurve.GetType()) {
case GeomAbs_Line:
{
gp_Vec V;
key = Standard_True;
HAV1 = new TColgp_HArray1OfVec(1, 2);
HAI1 = new TColStd_HArray1OfInteger(1,3);
// array of coordinates of line
gp_Pnt p = aCurve.Value(U1);
V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
HAV1->SetValue(1,V);
p = aCurve.Value(U2);
V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
HAV1->SetValue(2,V);
// array of indexes of line
HAI1->SetValue(1,0);
HAI1->SetValue(2,1);
HAI1->SetValue(3,-1);
}
break;
case GeomAbs_Circle:
{
Standard_Real Radius = aCurve.Circle().Radius();
if (!Precision::IsInfinite(Radius)) {
Standard_Real DU = Sqrt(8.0 * TheDeflection / Radius);
Standard_Integer N = Standard_Integer(Abs( U2 - U1) / DU);
if ( N > 0) {
gp_Vec V;
key = Standard_True;
HAV1 = new TColgp_HArray1OfVec(1, N+1);
HAI1 = new TColStd_HArray1OfInteger(1,N+2);
DU = (U2-U1) / N;
Standard_Real U;
gp_Pnt p;
for (Standard_Integer Index = 1; Index <= N+1; Index++) {
U = U1 + (Index - 1) * DU;
p = aCurve.Value(U);
V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
HAV1->SetValue(Index,V);
HAI1->SetValue(Index,Index-1);
}
/*
if( HAV1->Value(1).IsEqual( HAV1->Value(N+1),Precision::Confusion(), Precision::Angular() ) )
{
HAI1->SetValue(N+1, 0);
}
*/
HAI1->SetValue(HAI1->Upper(),-1);
}
}
}
break;
default:
{
GCPnts_QuasiUniformDeflection Algo(aCurve,TheDeflection,U1,U2);
if(Algo.IsDone()){
Standard_Integer NumberOfPoints = Algo.NbPoints();
if (NumberOfPoints > 0) {
gp_Vec V;
key = Standard_True;
HAV1 = new TColgp_HArray1OfVec(1, NumberOfPoints);
HAI1 = new TColStd_HArray1OfInteger(1,NumberOfPoints+1);
gp_Pnt p;
for (i=1;i<=NumberOfPoints;i++) {
p = Algo.Value(i);
V.SetX(p.X()); V.SetY(p.Y()); V.SetZ(p.Z());
HAV1->SetValue(i,V);
}
for (i=HAI1->Lower(); i < HAI1->Upper(); i++)
{
HAI1->SetValue(i,i-1);
}
HAI1->SetValue(HAI1->Upper(),-1);
}
}
//else
//cannot draw with respect to a maximal chordial deviation
}
}
//cout << " Array HAI1 - coordIndex " << endl;
//
//for ( i=HAI1->Lower(); i <= HAI1->Upper(); i++ )
// {
// cout << HAI1->Value(i) << endl;
// }
if (key) {
// creation of Vrml objects
Handle(VrmlConverter_LineAspect) LA = new VrmlConverter_LineAspect;
LA = aDrawer->LineAspect();
// Separator 1 {
Vrml_Separator SE1;
SE1.Print(anOStream);
// Material
if (LA->HasMaterial()){
Handle(Vrml_Material) M;
M = LA->Material();
M->Print(anOStream);
}
// Coordinate3
Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV1);
C3->Print(anOStream);
// IndexedLineSet
Vrml_IndexedLineSet ILS;
ILS.SetCoordIndex(HAI1);
ILS.Print(anOStream);
// Separator 1 }
SE1.Print(anOStream);
}
}
//==================================================================
// function: GetDeflection
// purpose:
//==================================================================
static Standard_Real GetDeflection(const Adaptor3d_Curve& aCurve,
const Standard_Real U1,
const Standard_Real U2,
const Handle(VrmlConverter_Drawer)& aDrawer) {
Standard_Real theRequestedDeflection;
if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE
{
Bnd_Box box;
BndLib_Add3dCurve::Add(aCurve, U1, U2, Precision::Confusion(), box);
Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal;
box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
if (!(box.IsOpenXmin() || box.IsOpenXmax() ||
box.IsOpenYmin() || box.IsOpenYmax() ||
box.IsOpenZmin() || box.IsOpenZmax()))
{
diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin));
diagonal = Max(diagonal, Precision::Confusion());
theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
}
else
{
diagonal =1000000.;
theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
}
// cout << "diagonal = " << diagonal << endl;
// cout << "theRequestedDeflection = " << theRequestedDeflection << endl;
}
else
{
theRequestedDeflection = aDrawer->MaximalChordialDeviation();
}
return theRequestedDeflection;
}
//==================================================================
// function: Add
// purpose: 1
//==================================================================
void VrmlConverter_DeflectionCurve::Add(Standard_OStream& anOStream,
Adaptor3d_Curve& aCurve,
const Handle(VrmlConverter_Drawer)& aDrawer)
{
Standard_Real V1, V2;
Standard_Real aLimit = aDrawer->MaximalParameterValue();
FindLimits(aCurve, aLimit, V1, V2);
Standard_Real theRequestedDeflection = GetDeflection(aCurve, V1, V2, aDrawer);
DrawCurve(aCurve,
theRequestedDeflection,
V1 , V2, aDrawer, anOStream);
}
//==================================================================
// function: Add
// purpose: 2
//==================================================================
void VrmlConverter_DeflectionCurve::Add(Standard_OStream& anOStream,
Adaptor3d_Curve& aCurve,
const Standard_Real U1,
const Standard_Real U2,
const Handle(VrmlConverter_Drawer)& aDrawer)
{
Standard_Real V1 = U1;
Standard_Real V2 = U2;
if (Precision::IsNegativeInfinite(V1)) V1 = -aDrawer->MaximalParameterValue();
if (Precision::IsPositiveInfinite(V2)) V2 = aDrawer->MaximalParameterValue();
Standard_Real theRequestedDeflection = GetDeflection(aCurve, V1, V2, aDrawer);
DrawCurve(aCurve,
theRequestedDeflection,
V1 , V2, aDrawer, anOStream);
}
//==================================================================
// function: Add
// purpose: 3
//==================================================================
void VrmlConverter_DeflectionCurve::Add(Standard_OStream& anOStream,
Adaptor3d_Curve& aCurve,
const Standard_Real aDeflection,
const Standard_Real aLimit)
{
Standard_Real V1, V2;
FindLimits(aCurve, aLimit, V1, V2);
Handle(VrmlConverter_Drawer) aDrawer = new VrmlConverter_Drawer;
Handle(VrmlConverter_LineAspect) la = new VrmlConverter_LineAspect;
aDrawer->SetLineAspect(la);
DrawCurve(aCurve,
aDeflection,
V1 , V2, aDrawer, anOStream);
}
//==================================================================
// function: Add
// purpose: 4
//==================================================================
void VrmlConverter_DeflectionCurve::Add(Standard_OStream& anOStream,
Adaptor3d_Curve& aCurve,
const Standard_Real aDeflection,
const Handle(VrmlConverter_Drawer)& aDrawer)
{
Standard_Real aLimit = aDrawer->MaximalParameterValue();
Standard_Real V1, V2;
FindLimits(aCurve, aLimit, V1, V2);
DrawCurve(aCurve,
aDeflection,
V1 , V2, aDrawer, anOStream);
}
//==================================================================
// function: Add
// purpose: 5
//==================================================================
void VrmlConverter_DeflectionCurve::Add(Standard_OStream& anOStream,
Adaptor3d_Curve& aCurve,
const Standard_Real U1,
const Standard_Real U2,
const Standard_Real aDeflection)
{
Handle(VrmlConverter_Drawer) aDrawer = new VrmlConverter_Drawer;
Handle(VrmlConverter_LineAspect) la = new VrmlConverter_LineAspect;
aDrawer->SetLineAspect(la);
DrawCurve(aCurve,
aDeflection,
U1 , U2, aDrawer, anOStream);
}
|