1 // Created on: 2007-08-04
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef VrmlData_ShapeConvert_HeaderFile
17 #define VrmlData_ShapeConvert_HeaderFile
19 #include <VrmlData_Geometry.hxx>
20 #include <VrmlData_Appearance.hxx>
21 #include <VrmlData_Group.hxx>
22 #include <NCollection_List.hxx>
23 #include <NCollection_DataMap.hxx>
24 #include <TopoDS_Shape.hxx>
27 class VrmlData_Coordinate;
30 class Poly_Triangulation;
31 class XCAFDoc_ColorTool;
32 class TDocStd_Document;
37 * Algorithm converting one shape or a set of shapes to VrmlData_Scene.
40 class VrmlData_ShapeConvert
45 TCollection_AsciiString Name;
47 Handle(VrmlData_Node) Node;
50 // ---------- PUBLIC METHODS ----------
56 * Scene receiving all Vrml data.
58 * Scale factor, considering that VRML standard specifies coordinates in
59 * meters. So if your data are in mm, you should provide theScale=0.001
61 inline VrmlData_ShapeConvert (VrmlData_Scene& theScene,
62 const Standard_Real theScale = 1.)
68 * Add one shape to the internal list, may be called several times with
71 Standard_EXPORT void AddShape (const TopoDS_Shape& theShape,
72 const char * theName = 0L);
75 * Convert all accumulated shapes and store them in myScene.
76 * The internal data structures are cleared in the end of convertion.
77 * @param theExtractFaces
78 * If True, converter extracst faces from the shapes.
79 * @param theExtractEdges
80 * If True, converter extracts edges from the shapes.
81 * @param theDeflection
82 * Deflection for tessellation of geometrical lines/surfaces. Existing mesh
83 * is used if its deflection is smaller than the one given by this
86 * Angular deflection for tessellation of geometrical lines.
88 Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces,
89 const Standard_Boolean theExtractEdges,
90 const Standard_Real theDeflection = 0.01,
91 const Standard_Real theDeflAngle = 20.*M_PI/180.);
92 //this value of theDeflAngle is used by default
93 //for tesselation while shading (Drawer->HLRAngle())
96 * Add all shapes start from given document with colors and names to the internal structure
98 Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc);
101 // ---------- PROTECTED METHODS ----------
103 Handle(VrmlData_Geometry) triToIndexedFaceSet
104 (const Handle(Poly_Triangulation)&,
106 const Handle(VrmlData_Coordinate)&);
108 Handle(VrmlData_Geometry) polToIndexedLineSet
109 (const Handle(Poly_Polygon3D)&);
111 Handle(VrmlData_Appearance) defaultMaterialFace () const;
113 Handle(VrmlData_Appearance) defaultMaterialEdge () const;
115 Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape& theShape,
116 const TopAbs_ShapeEnum theShapeType,
117 TopLoc_Location& theLoc);
119 void addAssembly (const Handle(VrmlData_Group)& theParent,
120 const TDF_Label& theLabel,
121 const Handle(TDocStd_Document)& theDoc,
122 const Standard_Boolean theNeedCreateGroup);
124 void addInstance (const Handle(VrmlData_Group)& theParent,
125 const TDF_Label& theLabel,
126 const Handle(TDocStd_Document)& theDoc);
128 void addShape (const Handle(VrmlData_Group)& theParent,
129 const TDF_Label& theLabel,
130 const Handle(TDocStd_Document)& theDoc);
132 Handle(VrmlData_Appearance) makeMaterialFromColor(const TDF_Label& theColorL,
133 const Handle(XCAFDoc_ColorTool)& theColorTool) const;
137 // ---------- PRIVATE FIELDS ----------
139 VrmlData_Scene& myScene;
140 Standard_Real myScale;
141 NCollection_List <ShapeData> myShapes;
143 Standard_Real myDeflection;
144 Standard_Real myDeflAngle;
145 NCollection_DataMap <TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap;
147 // ---------- PRIVATE METHODS ----------
148 void operator= (const VrmlData_ShapeConvert&);