Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-15 08:30:52

0001 // Created on: 2007-08-04
0002 // Created by: Alexander GRIGORIEV
0003 // Copyright (c) 2007-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef VrmlData_ShapeConvert_HeaderFile
0017 #define VrmlData_ShapeConvert_HeaderFile
0018 
0019 #include <VrmlData_Geometry.hxx>
0020 #include <VrmlData_Group.hxx>
0021 #include <NCollection_List.hxx>
0022 #include <NCollection_DataMap.hxx>
0023 #include <TopoDS_Shape.hxx>
0024 
0025 class VrmlData_Scene;
0026 class VrmlData_Coordinate;
0027 class TopoDS_Face;
0028 class Poly_Polygon3D;
0029 class Poly_Triangulation;
0030 class XCAFPrs_Style;
0031 class TDocStd_Document;
0032 class TDF_Label;
0033 
0034 /**
0035  * Algorithm converting one shape or a set of shapes to VrmlData_Scene.
0036  */
0037 
0038 class VrmlData_ShapeConvert
0039 {
0040 public:
0041   typedef struct
0042   {
0043     TCollection_AsciiString Name;
0044     TopoDS_Shape            Shape;
0045     Handle(VrmlData_Node)   Node;
0046   } ShapeData;
0047 
0048   // ---------- PUBLIC METHODS ----------
0049 
0050   /**
0051    * Constructor.
0052    * @param theScene
0053    *   Scene receiving all Vrml data.
0054    * @param theScale
0055    *   Scale factor, considering that VRML standard specifies coordinates in
0056    *   meters. So if your data are in mm, you should provide theScale=0.001
0057    */
0058   inline VrmlData_ShapeConvert(VrmlData_Scene& theScene, const Standard_Real theScale = 1.)
0059       : myScene(theScene),
0060         myScale(theScale),
0061         myDeflection(0.0),
0062         myDeflAngle(0.0)
0063   {
0064   }
0065 
0066   /**
0067    * Add one shape to the internal list, may be called several times with
0068    * different shapes.
0069    */
0070   Standard_EXPORT void AddShape(const TopoDS_Shape& theShape, const char* theName = 0L);
0071 
0072   /**
0073    * Convert all accumulated shapes and store them in myScene.
0074    * The internal data structures are cleared in the end of conversion.
0075    * @param theExtractFaces
0076    *   If True,  converter extracst faces from the shapes.
0077    * @param theExtractEdges
0078    *   If True,  converter extracts edges from the shapes.
0079    * @param theDeflection
0080    *   Deflection for tessellation of geometrical lines/surfaces. Existing mesh
0081    *   is used if its deflection is smaller than the one given by this
0082    *   parameter.
0083    * @param theDeflAngle
0084    *   Angular deflection for tessellation of geometrical lines.
0085    */
0086   Standard_EXPORT void Convert(const Standard_Boolean theExtractFaces,
0087                                const Standard_Boolean theExtractEdges,
0088                                const Standard_Real    theDeflection = 0.01,
0089                                const Standard_Real    theDeflAngle  = 20. * M_PI / 180.);
0090   // this value of theDeflAngle is used by default
0091   // for tessellation while shading (Drawer->HLRAngle())
0092 
0093   /**
0094    * Add all shapes start from given document with colors and names to the internal structure
0095    */
0096   Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc);
0097 
0098 protected:
0099   // ---------- PROTECTED METHODS ----------
0100 
0101   Handle(VrmlData_Geometry) triToIndexedFaceSet(const Handle(Poly_Triangulation)&,
0102                                                 const TopoDS_Face&,
0103                                                 const Handle(VrmlData_Coordinate)&);
0104 
0105   Handle(VrmlData_Geometry) polToIndexedLineSet(const Handle(Poly_Polygon3D)&);
0106 
0107   Handle(VrmlData_Appearance) defaultMaterialFace() const;
0108 
0109   Handle(VrmlData_Appearance) defaultMaterialEdge() const;
0110 
0111   Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape&    theShape,
0112                                            const TopAbs_ShapeEnum theShapeType,
0113                                            TopLoc_Location&       theLoc);
0114 
0115   void addAssembly(const Handle(VrmlData_Group)&   theParent,
0116                    const TDF_Label&                theLabel,
0117                    const Handle(TDocStd_Document)& theDoc,
0118                    const Standard_Boolean          theNeedCreateGroup);
0119 
0120   void addInstance(const Handle(VrmlData_Group)&   theParent,
0121                    const TDF_Label&                theLabel,
0122                    const Handle(TDocStd_Document)& theDoc);
0123 
0124   void addShape(const Handle(VrmlData_Group)&   theParent,
0125                 const TDF_Label&                theLabel,
0126                 const Handle(TDocStd_Document)& theDoc);
0127 
0128   Handle(VrmlData_Appearance) makeMaterialFromStyle(const XCAFPrs_Style& theStyle,
0129                                                     const TDF_Label&     theAttribLab) const;
0130 
0131 private:
0132   // ---------- PRIVATE FIELDS ----------
0133 
0134   VrmlData_Scene&             myScene;
0135   Standard_Real               myScale;
0136   NCollection_List<ShapeData> myShapes;
0137 
0138   Standard_Real                                                myDeflection;
0139   Standard_Real                                                myDeflAngle;
0140   NCollection_DataMap<TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap;
0141 
0142   // ---------- PRIVATE METHODS ----------
0143   void operator=(const VrmlData_ShapeConvert&);
0144 };
0145 
0146 #endif