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 <Bnd_Box.hxx>
16 #include <BRep_Tool.hxx>
17 #include <BRepAdaptor_Curve.hxx>
18 #include <BRepAdaptor_HSurface.hxx>
19 #include <BRepBndLib.hxx>
21 #include <Poly_PolygonOnTriangulation.hxx>
22 #include <Precision.hxx>
23 #include <StdPrs_ShapeTool.hxx>
24 #include <TColgp_HArray1OfVec.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <Vrml_Coordinate3.hxx>
27 #include <Vrml_Material.hxx>
28 #include <Vrml_PointSet.hxx>
29 #include <Vrml_Separator.hxx>
30 #include <VrmlConverter_DeflectionCurve.hxx>
31 #include <VrmlConverter_Drawer.hxx>
32 #include <VrmlConverter_IsoAspect.hxx>
33 #include <VrmlConverter_LineAspect.hxx>
34 #include <VrmlConverter_PointAspect.hxx>
35 #include <VrmlConverter_WFDeflectionRestrictedFace.hxx>
36 #include <VrmlConverter_WFDeflectionShape.hxx>
38 //=========================================================================
41 //=========================================================================
42 void VrmlConverter_WFDeflectionShape::Add( Standard_OStream& anOStream,
43 const TopoDS_Shape& aShape,
44 const Handle (VrmlConverter_Drawer)& aDrawer)
47 StdPrs_ShapeTool Tool(aShape);
49 Standard_Real theRequestedDeflection;
50 if(aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) // TOD_RELATIVE, TOD_ABSOLUTE
53 BRepBndLib::AddClose(aShape, box);
55 Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax, diagonal;
56 box.Get( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
57 if (!(box.IsOpenXmin() || box.IsOpenXmax() ||
58 box.IsOpenYmin() || box.IsOpenYmax() ||
59 box.IsOpenZmin() || box.IsOpenZmax()))
62 diagonal = Sqrt ((Xmax - Xmin)*( Xmax - Xmin) + ( Ymax - Ymin)*( Ymax - Ymin) + ( Zmax - Zmin)*( Zmax - Zmin));
63 diagonal = Max(diagonal, Precision::Confusion());
64 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
69 theRequestedDeflection = aDrawer->DeviationCoefficient() * diagonal;
75 theRequestedDeflection = aDrawer->MaximalChordialDeviation();
77 //== Is not used to reach the same wireframe representation with VRML#2.0
78 /*if (aDrawer->UIsoAspect()->Number() != 0 ||
79 aDrawer->VIsoAspect()->Number() != 0 ) {
81 BRepAdaptor_Surface S;
82 Standard_Boolean isoU, isoV;
83 for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){
84 isoU = (aDrawer->UIsoAspect()->Number() != 0);
85 isoV = (aDrawer->VIsoAspect()->Number() != 0);
86 if (Tool.HasSurface()) {
87 if (Tool.IsPlanarFace()) {
88 isoU = (isoU && aDrawer->IsoOnPlane());
89 isoV = (isoV && aDrawer->IsoOnPlane());
92 S.Initialize(Tool.GetFace());
93 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
94 VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS,
96 theRequestedDeflection,
97 aDrawer->UIsoAspect()->Number(),
98 aDrawer->VIsoAspect()->Number(),
107 if (aDrawer->UIsoAspect()->Number() != 0) {
109 BRepAdaptor_Surface S;
110 for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){
111 Standard_Boolean isoU = Standard_True;
112 if (Tool.HasSurface()) {
113 if (Tool.IsPlanarFace()) isoU = aDrawer->IsoOnPlane();
115 S.Initialize(Tool.GetFace());
116 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
117 VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS,
118 isoU, Standard_False,
119 theRequestedDeflection,
120 aDrawer->UIsoAspect()->Number(),
128 if (aDrawer->VIsoAspect()->Number() != 0) {
130 BRepAdaptor_Surface S;
131 for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){
132 Standard_Boolean isoV = Standard_True;
133 if (Tool.HasSurface()) {
134 if (Tool.IsPlanarFace()) isoV = aDrawer->IsoOnPlane();
136 S.Initialize(Tool.GetFace());
137 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S);
138 VrmlConverter_WFDeflectionRestrictedFace::Add(anOStream, HS,
139 Standard_False, isoV,
140 theRequestedDeflection,
142 aDrawer->VIsoAspect()->Number(),
151 Standard_Integer qnt=0;
152 for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve())
157 Handle(Poly_PolygonOnTriangulation) aPT;
158 Handle(Poly_Triangulation) aT;
161 // std::cout << "Quantity of Curves = " << qnt << std::endl;
163 // Wire (without any neighbour)
165 if (aDrawer->WireDraw()) {
168 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
169 latmp->SetMaterial(aDrawer->LineAspect()->Material());
170 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
172 aDrawer->SetLineAspect(aDrawer->WireAspect());
174 for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){
175 if (Tool.Neighbours() == 0) {
176 if (Tool.HasCurve()) {
177 BRepAdaptor_Curve C(Tool.GetCurve());
178 BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL);
179 if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters())
180 VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer);
182 VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer);
186 aDrawer->SetLineAspect(latmp);
192 if (aDrawer->FreeBoundaryDraw()) {
195 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
196 latmp->SetMaterial(aDrawer->LineAspect()->Material());
197 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
199 aDrawer->SetLineAspect(aDrawer->FreeBoundaryAspect());
201 for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){
202 if (Tool.Neighbours() == 1) {
203 if (Tool.HasCurve()) {
204 BRepAdaptor_Curve C(Tool.GetCurve());
205 BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL);
206 if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters())
207 VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer);
209 VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer);
213 aDrawer->SetLineAspect(latmp);
216 // end of Free boundaries
218 // Unfree boundaries;
219 if (aDrawer->UnFreeBoundaryDraw()) {
222 Handle(VrmlConverter_LineAspect) latmp = new VrmlConverter_LineAspect;
223 latmp->SetMaterial(aDrawer->LineAspect()->Material());
224 latmp->SetHasMaterial(aDrawer->LineAspect()->HasMaterial());
226 aDrawer->SetLineAspect(aDrawer->UnFreeBoundaryAspect());
228 for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){
229 if (Tool.Neighbours() >= 2) {
230 if (Tool.HasCurve()) {
231 BRepAdaptor_Curve C(Tool.GetCurve());
232 BRep_Tool::PolygonOnTriangulation(Tool.GetCurve(), aPT, aT, aL);
233 if (!aPT.IsNull() && !aT.IsNull() && aPT->HasParameters())
234 VrmlConverter_DeflectionCurve::Add(anOStream, C, aPT->Parameters(), aPT->NbNodes(), aDrawer);
236 VrmlConverter_DeflectionCurve::Add(anOStream, C, theRequestedDeflection, aDrawer);
240 aDrawer->SetLineAspect(latmp);
243 // end of Unfree boundaries
248 for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex())
253 // std::cout << "Quantity of Vertexes = " << qnt << std::endl;
257 Handle(TColgp_HArray1OfVec) HAV = new TColgp_HArray1OfVec(1,qnt);
260 Standard_Integer i=0;
262 for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex())
265 P = BRep_Tool::Pnt(Tool.GetVertex());
266 V.SetX(P.X()); V.SetY(P.Y()); V.SetZ(P.Z());
270 Handle(VrmlConverter_PointAspect) PA = new VrmlConverter_PointAspect;
271 PA = aDrawer->PointAspect();
275 SEP.Print(anOStream);
278 if (PA->HasMaterial()){
280 Handle(Vrml_Material) MP;
283 MP->Print(anOStream);
286 Handle(Vrml_Coordinate3) C3 = new Vrml_Coordinate3(HAV);
287 C3->Print(anOStream);
294 SEP.Print(anOStream);