0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / VrmlConverter / VrmlConverter_WFDeflectionRestrictedFace.cxx
CommitLineData
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 <Adaptor2d_Curve2d.hxx>
7fd59977 16#include <Adaptor3d_IsoCurve.hxx>
42cf5bc1 17#include <Bnd_Box.hxx>
7fd59977 18#include <Bnd_Box2d.hxx>
19#include <BndLib_Add2dCurve.hxx>
42cf5bc1 20#include <BndLib_AddSurface.hxx>
c22b52d6 21#include <BRepAdaptor_Surface.hxx>
42cf5bc1 22#include <GCPnts_QuasiUniformDeflection.hxx>
23#include <gp_Pnt.hxx>
24#include <gp_Pnt2d.hxx>
25#include <Hatch_Hatcher.hxx>
7fd59977 26#include <Precision.hxx>
42cf5bc1 27#include <StdPrs_ToolRFace.hxx>
7fd59977 28#include <Vrml_Material.hxx>
42cf5bc1 29#include <Vrml_Separator.hxx>
30#include <VrmlConverter_DeflectionCurve.hxx>
31#include <VrmlConverter_Drawer.hxx>
32#include <VrmlConverter_IsoAspect.hxx>
33#include <VrmlConverter_WFDeflectionRestrictedFace.hxx>
7fd59977 34
35//==================================================================
36// function: GetDeflection
37// purpose:
38//==================================================================
c22b52d6 39static Standard_Real GetDeflection(const Handle(BRepAdaptor_Surface)& aFace,
7fd59977 40 const Handle (VrmlConverter_Drawer)& aDrawer) {
41
42 Standard_Real theRequestedDeflection;
43 if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE
44 {
45 Bnd_Box box;
46 BndLib_AddSurface::Add(aFace->Surface(), Precision::Confusion(), box);
47
48 Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal;
49 box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
50 if (!(box.IsOpenXmin() || box.IsOpenXmax() ||
51 box.IsOpenYmin() || box.IsOpenYmax() ||
52 box.IsOpenZmin() || box.IsOpenZmax()))
53 {
54 diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin));
55 diagonal = Max(diagonal, Precision::Confusion());
56 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
57 }
58 else
59 {
60 diagonal =1000000.;
61 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
62 }
04232180 63// std::cout << "diagonal = " << diagonal << std::endl;
64// std::cout << "theRequestedDeflection = " << theRequestedDeflection << std::endl;
7fd59977 65 }
66 else
67 {
68 theRequestedDeflection = aDrawer->MaximalChordialDeviation();
69 }
70 return theRequestedDeflection;
71}
72
73//=========================================================================
74// function: Add 1
75// purpose
76//=========================================================================
77void VrmlConverter_WFDeflectionRestrictedFace::Add
78 (Standard_OStream& anOStream,
c22b52d6 79 const Handle(BRepAdaptor_Surface)& aFace,
7fd59977 80 const Standard_Boolean DrawUIso,
81 const Standard_Boolean DrawVIso,
09324e85 82 const Standard_Real Deflection,
7fd59977 83 const Standard_Integer NBUiso,
84 const Standard_Integer NBViso,
85 const Handle(VrmlConverter_Drawer)& aDrawer)
86{
87
88 StdPrs_ToolRFace ToolRst (aFace);
89 Standard_Real UF, UL, VF, VL;
90 UF = aFace->FirstUParameter();
91 UL = aFace->LastUParameter();
92 VF = aFace->FirstVParameter();
93 VL = aFace->LastVParameter();
94
95 Standard_Real aLimit = aDrawer->MaximalParameterValue();
96
97 // compute bounds of the restriction
98 Standard_Real UMin,UMax,VMin,VMax;
99 Standard_Integer i;
100
101 UMin = UF;
102 UMax = UL;
103 VMin = VF;
104 VMax = VL;
105
106 // load the isos
107 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
108 Standard_Boolean UClosed = aFace->IsUClosed();
109 Standard_Boolean VClosed = aFace->IsVClosed();
110
111 if ( ! UClosed ) {
112 UMin = UMin + ( UMax - UMin) /1000.;
113 UMax = UMax - ( UMax - UMin) /1000.;
114 }
115
116 if ( ! VClosed ) {
117 VMin = VMin + ( VMax - VMin) /1000.;
118 VMax = VMax - ( VMax - VMin) /1000.;
119 }
120
121 if (DrawUIso){
122 if (NBUiso > 0) {
123 UClosed = Standard_False;
124 Standard_Real du= UClosed ? (UMax-UMin)/NBUiso : (UMax-UMin)/(1+NBUiso);
125 for (i=1; i<=NBUiso;i++){
126 isobuild.AddXLine(UMin+du*i);
127 }
128 }
129 }
130 if (DrawVIso){
131 if ( NBViso > 0) {
132 VClosed = Standard_False;
133 Standard_Real dv= VClosed ?(VMax-VMin)/NBViso : (VMax-VMin)/(1+NBViso);
134 for (i=1; i<=NBViso;i++){
135 isobuild.AddYLine(VMin+dv*i);
136 }
137 }
138 }
139
140
141 // trim the isos
142 gp_Pnt2d P1,P2;
143 Standard_Real U1, U2;
144 gp_Pnt dummypnt;
145 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
146 TopAbs_Orientation Orient = ToolRst.Orientation();
4ba5491a 147 const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
7fd59977 148 if (TheRCurve->GetType() != GeomAbs_Line) {
149 GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
150 if (UDP.IsDone()) {
151 Standard_Integer NumberOfPoints = UDP.NbPoints();
152 if ( NumberOfPoints >= 2 ) {
153 dummypnt = UDP.Value(1);
154 P2.SetCoord(dummypnt.X(), dummypnt.Y());
155 for (i = 2; i <= NumberOfPoints; i++) {
156 P1 = P2;
157 dummypnt = UDP.Value(i);
158 P2.SetCoord(dummypnt.X(), dummypnt.Y());
159 if(Orient == TopAbs_FORWARD )
160 isobuild.Trim(P1,P2);
161 else
162 isobuild.Trim(P2,P1);
163 }
164 }
165 }
166 else {
04232180 167 std::cout << "Cannot evaluate curve on surface"<<std::endl;
7fd59977 168 }
169 }
170 else {
171 U1 = TheRCurve->FirstParameter();
172 U2 = TheRCurve->LastParameter();
173 P1 = TheRCurve->Value(U1);
174 P2 = TheRCurve->Value(U2);
175 if(Orient == TopAbs_FORWARD )
176 isobuild.Trim(P1,P2);
177 else
178 isobuild.Trim(P2,P1);
179 }
7fd59977 180 }
181
182 // draw the isos
183
184 Adaptor3d_IsoCurve anIso;
185 anIso.Load(aFace);
186 Standard_Integer NumberOfLines = isobuild.NbLines();
187
188 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
189 latmp->SetMaterial(aDrawer->LineAspect()->Material());
190 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
191
192 Handle(VrmlConverter_IsoAspect) iautmp = new VrmlConverter_IsoAspect;
193 iautmp->SetMaterial(aDrawer->UIsoAspect()->Material());
194 iautmp->SetHasMaterial(aDrawer->UIsoAspect()->HasMaterial());
195 iautmp->SetNumber(aDrawer->UIsoAspect()->Number());
196
197 Handle(VrmlConverter_IsoAspect) iavtmp = new VrmlConverter_IsoAspect;
198 iavtmp->SetMaterial(aDrawer->VIsoAspect()->Material());
199 iavtmp->SetHasMaterial(aDrawer->VIsoAspect()->HasMaterial());
200 iavtmp->SetNumber(aDrawer->VIsoAspect()->Number());
201
202 Handle(VrmlConverter_LineAspect) laU = new VrmlConverter_LineAspect;
203 Handle(VrmlConverter_LineAspect) laV = new VrmlConverter_LineAspect;
204
205 laU = aDrawer->UIsoAspect();
206 laV = aDrawer->VIsoAspect();
207
208 Vrml_Separator SE1;
209 Vrml_Separator SE2;
210 Vrml_Separator SE3;
211
212 Standard_Boolean flag = Standard_False; // to check a call of Vrml_Separator.Print(anOStream)
213
214 SE1.Print(anOStream);
215
216 if (DrawUIso) {
217 if (NBUiso > 0) {
218
219 if (laU->HasMaterial()){
220
221 Handle(Vrml_Material) MU;
222 MU = laU->Material();
223
224 MU->Print(anOStream);
225 laU->SetHasMaterial(Standard_False);
226
227 flag = Standard_True;
228 // Separator 2 {
229 SE2.Print(anOStream);
230 }
231 aDrawer->SetLineAspect(laU);
232
233 for (i = 1; i <= NumberOfLines; i++) {
234 if (isobuild.IsXLine(i))
235 {
236 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
237 Standard_Real Coord = isobuild.Coordinate(i);
238 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
239 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
240
241 b1 = b1 == RealFirst() ? - aLimit : b1;
242 b2 = b2 == RealLast() ? aLimit : b2;
243
244 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
245
246 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
247 }
248 }
249 }
250 if (flag){
251 // Separator 2 }
252 SE2.Print(anOStream);
253 flag = Standard_False;
254 }
255 }
256 }
257
258 if (DrawVIso) {
259 if ( NBViso > 0) {
260 if (laV->HasMaterial()){
261
262 Handle(Vrml_Material) MV;
263 MV = laV->Material();
264
265 MV->Print(anOStream);
266 laV->SetHasMaterial(Standard_False);
267 flag = Standard_True;
268
269 // Separator 3 {
270 SE3.Print(anOStream);
271 }
272
273 aDrawer->SetLineAspect(laV);
274
275 for (i = 1; i <= NumberOfLines; i++) {
276 if (isobuild.IsYLine(i))
277 {
278 Standard_Integer NumberOfIntervals = isobuild.NbIntervals(i);
279 Standard_Real Coord = isobuild.Coordinate(i);
280 for (Standard_Integer j = 1; j <= NumberOfIntervals; j++) {
281 Standard_Real b1=isobuild.Start(i,j),b2=isobuild.End(i,j);
282
283 b1 = b1 == RealFirst() ? - aLimit : b1;
284 b2 = b2 == RealLast() ? aLimit : b2;
285
286 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
287
288 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
289 }
290 }
291 }
292
293 if (flag){
294 // Separator 3 }
295 SE3.Print(anOStream);
296 flag = Standard_False;
297 }
298 }
299 }
300
301 // Separator 1 }
302 SE1.Print(anOStream);
303
304 aDrawer->SetLineAspect(latmp);
305 aDrawer->SetUIsoAspect(iautmp);
306 aDrawer->SetVIsoAspect(iavtmp);
307}
308
309//=========================================================================
310// function: Add 2
311// purpose
312//=========================================================================
313void VrmlConverter_WFDeflectionRestrictedFace::Add
314 (Standard_OStream& anOStream,
c22b52d6 315 const Handle(BRepAdaptor_Surface)& aFace,
7fd59977 316 const Handle (VrmlConverter_Drawer)& aDrawer){
317
09324e85 318 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 319
320 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
321 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
322
323 VrmlConverter_WFDeflectionRestrictedFace::Add (
324 anOStream,
325 aFace,
326 Standard_True,
327 Standard_True,
328 Deflection,
329 finu,
330 finv,
331 aDrawer);
332
333}
334
335
336//=========================================================================
337// function: AddUIso
338// purpose
339//=========================================================================
340void VrmlConverter_WFDeflectionRestrictedFace::AddUIso
341 (Standard_OStream& anOStream,
c22b52d6 342 const Handle(BRepAdaptor_Surface)& aFace,
7fd59977 343 const Handle (VrmlConverter_Drawer)& aDrawer) {
344
09324e85 345 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 346
347 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
348 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
349 VrmlConverter_WFDeflectionRestrictedFace::Add (
350 anOStream,
351 aFace,
352 Standard_True,
353 Standard_False,
354 Deflection,
355 finu,
356 finv,
357 aDrawer);
358}
359
360
361//=========================================================================
362// function: AddVIso
363// purpose
364//=========================================================================
365void VrmlConverter_WFDeflectionRestrictedFace::AddVIso
366 (Standard_OStream& anOStream,
c22b52d6 367 const Handle(BRepAdaptor_Surface)& aFace,
7fd59977 368 const Handle (VrmlConverter_Drawer)& aDrawer) {
369
09324e85 370 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
7fd59977 371
372 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
373 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
374 VrmlConverter_WFDeflectionRestrictedFace::Add (
375 anOStream,
376 aFace,
377 Standard_False,
378 Standard_True,
379 Deflection,
380 finu,
381 finv,
382 aDrawer);
383}