0024428: Implementation of LGPL license
[occt.git] / src / VrmlData / VrmlData_ShapeConvert.hxx
1 // Created on: 2007-08-04
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef VrmlData_ShapeConvert_HeaderFile
17 #define VrmlData_ShapeConvert_HeaderFile
18
19 #include <VrmlData_Geometry.hxx>
20 #include <VrmlData_Appearance.hxx>
21 #include <NCollection_List.hxx>
22 #include <TopoDS_Shape.hxx>
23
24 class VrmlData_Scene;
25 class TopoDS_Face;
26 class Handle_Poly_Triangulation;
27 class Handle_Poly_Polygon3D;
28 class Handle_VrmlData_Coordinate;
29 /**
30  * Algorithm converting one shape or a set of shapes to VrmlData_Scene.
31  */
32
33 class VrmlData_ShapeConvert 
34 {
35  public:
36
37   typedef struct {
38     TCollection_AsciiString Name;
39     TopoDS_Shape            Shape;
40     Handle(VrmlData_Node)   Node;
41   } ShapeData;
42
43   // ---------- PUBLIC METHODS ----------
44
45
46   /**
47    * Constructor.
48    * @param theScene
49    *   Scene receiving all Vrml data.
50    * @param theScale
51    *   Scale factor, considering that VRML standard specifies coordinates in
52    *   meters. So if your data are in mm, you should provide theScale=0.001
53    */
54   inline VrmlData_ShapeConvert (VrmlData_Scene&     theScene,
55                                 const Standard_Real theScale = 1.)
56     : myScene (theScene),
57       myScale (theScale)
58   {}
59
60   /**
61    * Add one shape to the internal list, may be called several times with
62    * different shapes.
63    */
64   Standard_EXPORT void AddShape (const TopoDS_Shape& theShape,
65                                  const char *        theName = 0L);
66
67   /**
68    * Convert all accumulated shapes and store them in myScene.
69    * The internal data structures are cleared in the end of convertion.
70    * @param theExtractFaces
71    *   If True,  converter extracst faces from the shapes. 
72    * @param theExtractEdges
73    *   If True,  converter extracts edges from the shapes.
74    * @param theDeflection 
75    *   Deflection for tessellation of geometrical lines/surfaces. Existing mesh
76    *   is used if its deflection is smaller than the one given by this
77    *   parameter.
78    * @param theDeflAngle 
79    *   Angular deflection for tessellation of geometrical lines. 
80    */
81   Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces,
82                                 const Standard_Boolean theExtractEdges,
83                                 const Standard_Real    theDeflection = 0.01,
84                                 const Standard_Real    theDeflAngle = 20.*M_PI/180.);
85                                 //this value of theDeflAngle is used by default 
86                                 //for tesselation while shading (Drawer->HLRAngle())
87  protected:
88   // ---------- PROTECTED METHODS ----------
89
90   Handle_VrmlData_Geometry triToIndexedFaceSet
91                                 (const Handle_Poly_Triangulation&,
92                                  const TopoDS_Face&,
93                                  const Handle_VrmlData_Coordinate&);
94
95   Handle_VrmlData_Geometry polToIndexedLineSet
96                                 (const Handle_Poly_Polygon3D&);
97
98   Handle_VrmlData_Appearance defaultMaterialFace () const;
99
100   Handle_VrmlData_Appearance defaultMaterialEdge () const;
101
102  private:
103   // ---------- PRIVATE FIELDS ----------
104
105   VrmlData_Scene&                       myScene;
106   Standard_Real                         myScale;
107   NCollection_List <ShapeData>          myShapes;
108   // ---------- PRIVATE METHODS ----------
109   void operator= (const VrmlData_ShapeConvert&);
110 };
111
112 #endif