1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Adaptor2d_Curve2d.hxx>
16 #include <Adaptor3d_IsoCurve.hxx>
17 #include <Bnd_Box.hxx>
18 #include <Bnd_Box2d.hxx>
19 #include <BndLib_Add2dCurve.hxx>
20 #include <BndLib_AddSurface.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <GCPnts_QuasiUniformDeflection.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <Hatch_Hatcher.hxx>
26 #include <Precision.hxx>
27 #include <StdPrs_ToolRFace.hxx>
28 #include <Vrml_Material.hxx>
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>
35 //==================================================================
36 // function: GetDeflection
38 //==================================================================
39 static Standard_Real GetDeflection(const Handle(BRepAdaptor_Surface)& aFace,
40 const Handle (VrmlConverter_Drawer)& aDrawer) {
42 Standard_Real theRequestedDeflection;
43 if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE
46 BndLib_AddSurface::Add(aFace->Surface(), Precision::Confusion(), box);
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()))
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;
61 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
63 // std::cout << "diagonal = " << diagonal << std::endl;
64 // std::cout << "theRequestedDeflection = " << theRequestedDeflection << std::endl;
68 theRequestedDeflection = aDrawer->MaximalChordialDeviation();
70 return theRequestedDeflection;
73 //=========================================================================
76 //=========================================================================
77 void VrmlConverter_WFDeflectionRestrictedFace::Add
78 (Standard_OStream& anOStream,
79 const Handle(BRepAdaptor_Surface)& aFace,
80 const Standard_Boolean DrawUIso,
81 const Standard_Boolean DrawVIso,
82 const Standard_Real Deflection,
83 const Standard_Integer NBUiso,
84 const Standard_Integer NBViso,
85 const Handle(VrmlConverter_Drawer)& aDrawer)
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();
95 Standard_Real aLimit = aDrawer->MaximalParameterValue();
97 // compute bounds of the restriction
98 Standard_Real UMin,UMax,VMin,VMax;
107 Hatch_Hatcher isobuild(1.e-5,ToolRst.IsOriented());
108 Standard_Boolean UClosed = aFace->IsUClosed();
109 Standard_Boolean VClosed = aFace->IsVClosed();
112 UMin = UMin + ( UMax - UMin) /1000.;
113 UMax = UMax - ( UMax - UMin) /1000.;
117 VMin = VMin + ( VMax - VMin) /1000.;
118 VMax = VMax - ( VMax - VMin) /1000.;
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);
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);
143 Standard_Real U1, U2;
145 for (ToolRst.Init(); ToolRst.More(); ToolRst.Next()) {
146 TopAbs_Orientation Orient = ToolRst.Orientation();
147 const Adaptor2d_Curve2d* TheRCurve = &ToolRst.Value();
148 if (TheRCurve->GetType() != GeomAbs_Line) {
149 GCPnts_QuasiUniformDeflection UDP(*TheRCurve, Deflection);
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++) {
157 dummypnt = UDP.Value(i);
158 P2.SetCoord(dummypnt.X(), dummypnt.Y());
159 if(Orient == TopAbs_FORWARD )
160 isobuild.Trim(P1,P2);
162 isobuild.Trim(P2,P1);
167 std::cout << "Cannot evaluate curve on surface"<<std::endl;
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);
178 isobuild.Trim(P2,P1);
184 Adaptor3d_IsoCurve anIso;
186 Standard_Integer NumberOfLines = isobuild.NbLines();
188 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
189 latmp->SetMaterial(aDrawer->LineAspect()->Material());
190 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
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());
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());
202 Handle(VrmlConverter_LineAspect) laU = new VrmlConverter_LineAspect;
203 Handle(VrmlConverter_LineAspect) laV = new VrmlConverter_LineAspect;
205 laU = aDrawer->UIsoAspect();
206 laV = aDrawer->VIsoAspect();
212 Standard_Boolean flag = Standard_False; // to check a call of Vrml_Separator.Print(anOStream)
214 SE1.Print(anOStream);
219 if (laU->HasMaterial()){
221 Handle(Vrml_Material) MU;
222 MU = laU->Material();
224 MU->Print(anOStream);
225 laU->SetHasMaterial(Standard_False);
227 flag = Standard_True;
229 SE2.Print(anOStream);
231 aDrawer->SetLineAspect(laU);
233 for (i = 1; i <= NumberOfLines; i++) {
234 if (isobuild.IsXLine(i))
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);
241 b1 = b1 == RealFirst() ? - aLimit : b1;
242 b2 = b2 == RealLast() ? aLimit : b2;
244 anIso.Load(GeomAbs_IsoU,Coord,b1,b2);
246 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
252 SE2.Print(anOStream);
253 flag = Standard_False;
260 if (laV->HasMaterial()){
262 Handle(Vrml_Material) MV;
263 MV = laV->Material();
265 MV->Print(anOStream);
266 laV->SetHasMaterial(Standard_False);
267 flag = Standard_True;
270 SE3.Print(anOStream);
273 aDrawer->SetLineAspect(laV);
275 for (i = 1; i <= NumberOfLines; i++) {
276 if (isobuild.IsYLine(i))
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);
283 b1 = b1 == RealFirst() ? - aLimit : b1;
284 b2 = b2 == RealLast() ? aLimit : b2;
286 anIso.Load(GeomAbs_IsoV,Coord,b1,b2);
288 VrmlConverter_DeflectionCurve::Add(anOStream, anIso, Deflection, aDrawer);
295 SE3.Print(anOStream);
296 flag = Standard_False;
302 SE1.Print(anOStream);
304 aDrawer->SetLineAspect(latmp);
305 aDrawer->SetUIsoAspect(iautmp);
306 aDrawer->SetVIsoAspect(iavtmp);
309 //=========================================================================
312 //=========================================================================
313 void VrmlConverter_WFDeflectionRestrictedFace::Add
314 (Standard_OStream& anOStream,
315 const Handle(BRepAdaptor_Surface)& aFace,
316 const Handle (VrmlConverter_Drawer)& aDrawer){
318 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
320 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
321 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
323 VrmlConverter_WFDeflectionRestrictedFace::Add (
336 //=========================================================================
339 //=========================================================================
340 void VrmlConverter_WFDeflectionRestrictedFace::AddUIso
341 (Standard_OStream& anOStream,
342 const Handle(BRepAdaptor_Surface)& aFace,
343 const Handle (VrmlConverter_Drawer)& aDrawer) {
345 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
347 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
348 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
349 VrmlConverter_WFDeflectionRestrictedFace::Add (
361 //=========================================================================
364 //=========================================================================
365 void VrmlConverter_WFDeflectionRestrictedFace::AddVIso
366 (Standard_OStream& anOStream,
367 const Handle(BRepAdaptor_Surface)& aFace,
368 const Handle (VrmlConverter_Drawer)& aDrawer) {
370 Standard_Real Deflection = GetDeflection(aFace, aDrawer);
372 Standard_Integer finu = aDrawer->UIsoAspect()->Number();
373 Standard_Integer finv = aDrawer->VIsoAspect()->Number();
374 VrmlConverter_WFDeflectionRestrictedFace::Add (