d369c2d5ae9aa28ecda0f3122454fcf9d62dfde8
[occt.git] / src / IVtkOCC / IVtkOCC_ShapeMesher.hxx
1 // Created on: 2011-10-14 
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-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 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef __IVTKOCC_SHAPEMESHER_H__
17 #define __IVTKOCC_SHAPEMESHER_H__
18
19 #include <IVtkOCC_Shape.hxx>
20 #include <IVtk_IShapeMesher.hxx>
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopTools_ShapeMapHasher.hxx>
28
29 typedef NCollection_DataMap <TopoDS_Shape, IVtk_MeshType, TopTools_ShapeMapHasher> IVtk_ShapeTypeMap;
30 typedef NCollection_Sequence <gp_Pnt> IVtk_Polyline;
31 typedef NCollection_List <IVtk_Polyline> IVtk_PolylineList;
32
33 class Prs3d_Drawer;
34
35 class IVtkOCC_ShapeMesher;
36 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
37
38 //! @class IVtkOCC_ShapeMesher 
39 //! @brief OCC implementation of IMesher interface.
40 //!
41 //! Mesher produces shape data using implementation of IShapeData interface for
42 //! VTK and then result can be retrieved from this implementation as a vtkPolyData:
43 //! @image html doc/img/image002.gif
44 //! Then the resulting vtkPolyData can be used for initialization of VTK pipeline.
45 class IVtkOCC_ShapeMesher : public IVtk_IShapeMesher
46 {
47 public:
48   //! Main constructor.
49   Standard_EXPORT IVtkOCC_ShapeMesher();
50
51   //! Destructor.
52   Standard_EXPORT virtual ~IVtkOCC_ShapeMesher();
53
54   //! Returns absolute deflection used by this algorithm.
55   //! This value is calculated on the basis of the shape's bounding box.
56   //! Zero might be returned in case if the underlying OCCT shape 
57   //! is empty or invalid. Thus check the returned value before
58   //! passing it to OCCT meshing algorithms!
59   //! @return absolute deflection value
60   Standard_EXPORT Standard_Real GetDeflection() const;
61
62   //! Returns relative deviation coefficient used by this algorithm.
63   //! @return relative deviation coefficient
64   Standard_EXPORT Standard_Real GetDeviationCoeff() const;
65
66   //! Returns deviation angle used by this algorithm.
67   //! This is the maximum allowed angle between the normals to the 
68   //! curve/surface and the normals to polyline/faceted representation.
69   //! @return deviation angle (in radians)
70   Standard_EXPORT Standard_Real GetDeviationAngle() const;
71
72 protected:
73   //! Executes the mesh generation algorithms. To be defined in implementation class.
74   Standard_EXPORT virtual void internalBuild() Standard_OVERRIDE;
75
76 private:
77
78   //! Extracts free vertices from the shape (i.e. those not belonging to any edge)
79   //! and passes the geometry to IPolyData. 
80   //! Each vertex is associated with its sub-shape ID.
81   void addFreeVertices();
82
83   //! Adds all the edges (free and non-free) to IPolyData.
84   void addEdges();
85
86   //! Adds the point coordinates, connectivity info and
87   //! sub-shape ID for the OCCT vertex.
88   //!
89   //! @param theVertex OCCT vertex to be added to the mesh
90   //! @param theShapeId global point ID needed for connectivity data creation
91   void addVertex (const TopoDS_Vertex& theVertex,
92                   const IVtk_IdType    theShapeId,
93                   const IVtk_MeshType  theMeshType);
94
95   //! Adds the point coordinates and a polyline for the OCCT edge.
96   //! Note that the edge should be triangulated in advance.
97   //!
98   //! @param theEdge OCCT edge to be meshed
99   //! @param theShapeId the edge's subshape ID
100   //! @see IVtkOCC_ShapeMesher::meshShape
101   void addEdge (const TopoDS_Edge&   theEdge,
102                 const IVtk_IdType    theShapeId,
103                 const IVtk_MeshType  theMeshType);
104
105   //! Generates wireframe representation of the given TopoDS_Face object
106   //! with help of OCCT algorithms. The resulting polylines are passed to IPolyData
107   //! interface and associated with the given sub-shape ID.
108   //! @param [in] theFace TopoDS_Face object to build wireframe representation for
109   //! @param [in] theShapeId The face' sub-shape ID
110   //! @param [in] theDeflection curve deflection
111   void addWFFace (const TopoDS_Face&  theFace,
112                   const IVtk_IdType   theShapeId,
113                   const Standard_Real theDeflection);
114
115   //! Creates shaded representation of the given TopoDS_Face object
116   //! starting from OCCT triangulation that should be created in advance. 
117   //! The resulting triangles are passed to IPolyData
118   //! interface and associated with the given sub-shape ID.
119   //! @param [in] theFace    TopoDS_Face object to build shaded representation for
120   //! @param [in] theShapeId the face' sub-shape ID
121   //! @see IVtkOCC_ShapeMesher::meshShape, IVtkOCC_ShapeMesher::addEdge
122   void addShadedFace (const TopoDS_Face&  theFace,
123                       const IVtk_IdType   theShapeId);
124
125   //! Internal helper method that unpacks the input arrays of points and 
126   //! connectivity and creates the polyline using IPolyData interface.
127   //! Optionally, the transformation specified through the last argument
128   //! can be applied to each point's coordinates (noTransform == true).
129   //! The polyline is associated with the given sub-shape ID.
130   void processPolyline (Standard_Integer               theNbNodes,
131                         const TColgp_Array1OfPnt&      thePoints,
132                         const TColStd_Array1OfInteger& thePointIds, 
133                         const IVtk_IdType              theOcctId,
134                         bool                           theNoTransform,
135                         gp_Trsf                        theTransformation,
136                         const IVtk_MeshType            theMeshType);
137
138   //! Get the IShape as OCC implementation
139   const IVtkOCC_Shape::Handle GetShapeObj() const;
140
141   DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
142
143 private:
144   IVtk_ShapeTypeMap myEdgesTypes;
145 };
146
147 #endif //  __IVTKOCC_SHAPEMESHER_H__