Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:32

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 /**
0036  * Algorithm converting one shape or a set of shapes to VrmlData_Scene.
0037  */
0038 
0039 class VrmlData_ShapeConvert 
0040 {
0041  public:
0042 
0043   typedef struct {
0044     TCollection_AsciiString Name;
0045     TopoDS_Shape            Shape;
0046     Handle(VrmlData_Node)   Node;
0047   } ShapeData;
0048 
0049   // ---------- PUBLIC METHODS ----------
0050 
0051 
0052   /**
0053    * Constructor.
0054    * @param theScene
0055    *   Scene receiving all Vrml data.
0056    * @param theScale
0057    *   Scale factor, considering that VRML standard specifies coordinates in
0058    *   meters. So if your data are in mm, you should provide theScale=0.001
0059    */
0060   inline VrmlData_ShapeConvert (VrmlData_Scene&     theScene,
0061                                 const Standard_Real theScale = 1.)
0062     : myScene (theScene),
0063       myScale (theScale),
0064       myDeflection(0.0),
0065       myDeflAngle(0.0)
0066   {}
0067 
0068   /**
0069    * Add one shape to the internal list, may be called several times with
0070    * different shapes.
0071    */
0072   Standard_EXPORT void AddShape (const TopoDS_Shape& theShape,
0073                                  const char *        theName = 0L);
0074 
0075   /**
0076    * Convert all accumulated shapes and store them in myScene.
0077    * The internal data structures are cleared in the end of conversion.
0078    * @param theExtractFaces
0079    *   If True,  converter extracst faces from the shapes. 
0080    * @param theExtractEdges
0081    *   If True,  converter extracts edges from the shapes.
0082    * @param theDeflection 
0083    *   Deflection for tessellation of geometrical lines/surfaces. Existing mesh
0084    *   is used if its deflection is smaller than the one given by this
0085    *   parameter.
0086    * @param theDeflAngle 
0087    *   Angular deflection for tessellation of geometrical lines. 
0088    */
0089   Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces,
0090                 const Standard_Boolean theExtractEdges,
0091                                 const Standard_Real    theDeflection = 0.01,
0092                 const Standard_Real    theDeflAngle = 20.*M_PI/180.);
0093                                 //this value of theDeflAngle is used by default 
0094                                 //for tesselation while shading (Drawer->HLRAngle())
0095 
0096   /**
0097    * Add all shapes start from given document with colors and names to the internal structure
0098    */
0099   Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc);
0100 
0101  protected:
0102   // ---------- PROTECTED METHODS ----------
0103 
0104   Handle(VrmlData_Geometry) triToIndexedFaceSet
0105                                 (const Handle(Poly_Triangulation)&,
0106                                  const TopoDS_Face&,
0107                                  const Handle(VrmlData_Coordinate)&);
0108 
0109   Handle(VrmlData_Geometry) polToIndexedLineSet
0110                                 (const Handle(Poly_Polygon3D)&);
0111 
0112   Handle(VrmlData_Appearance) defaultMaterialFace () const;
0113 
0114   Handle(VrmlData_Appearance) defaultMaterialEdge () const;
0115 
0116   Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape& theShape,
0117                                            const TopAbs_ShapeEnum theShapeType,
0118                                            TopLoc_Location& theLoc);
0119 
0120   void addAssembly (const Handle(VrmlData_Group)& theParent,
0121                     const TDF_Label& theLabel,
0122                     const Handle(TDocStd_Document)& theDoc,
0123                     const Standard_Boolean theNeedCreateGroup);
0124 
0125   void addInstance (const Handle(VrmlData_Group)& theParent,
0126                     const TDF_Label& theLabel,
0127                     const Handle(TDocStd_Document)& theDoc);
0128 
0129   void addShape (const Handle(VrmlData_Group)& theParent,
0130                  const TDF_Label& theLabel,
0131                  const Handle(TDocStd_Document)& theDoc);
0132 
0133   Handle(VrmlData_Appearance) makeMaterialFromStyle (const XCAFPrs_Style& theStyle,
0134                                                      const TDF_Label& theAttribLab) const;
0135 
0136  private:
0137   // ---------- PRIVATE FIELDS ----------
0138 
0139   VrmlData_Scene&                       myScene;
0140   Standard_Real                         myScale;
0141   NCollection_List <ShapeData>          myShapes;
0142 
0143   Standard_Real myDeflection;
0144   Standard_Real myDeflAngle;
0145   NCollection_DataMap <TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap;
0146 
0147   // ---------- PRIVATE METHODS ----------
0148   void operator= (const VrmlData_ShapeConvert&);
0149 };
0150 
0151 #endif