1 // Created on: 2011-10-14
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-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 __IVTKOCC_SHAPEMESHER_H__
17 #define __IVTKOCC_SHAPEMESHER_H__
19 #include <IVtkOCC_Shape.hxx>
20 #include <IVtk_IShapeMesher.hxx>
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopTools_ShapeMapHasher.hxx>
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;
35 class IVtkOCC_ShapeMesher;
36 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
38 //! @class IVtkOCC_ShapeMesher
39 //! @brief OCC implementation of IMesher interface.
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
49 Standard_EXPORT IVtkOCC_ShapeMesher();
52 Standard_EXPORT virtual ~IVtkOCC_ShapeMesher();
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;
62 //! Returns relative deviation coefficient used by this algorithm.
63 //! @return relative deviation coefficient
64 Standard_EXPORT Standard_Real GetDeviationCoeff() const;
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;
73 //! Executes the mesh generation algorithms. To be defined in implementation class.
74 Standard_EXPORT virtual void internalBuild() Standard_OVERRIDE;
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();
83 //! Adds all the edges (free and non-free) to IPolyData.
86 //! Adds the point coordinates, connectivity info and
87 //! sub-shape ID for the OCCT vertex.
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);
95 //! Adds the point coordinates and a polyline for the OCCT edge.
96 //! Note that the edge should be triangulated in advance.
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);
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);
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);
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,
135 gp_Trsf theTransformation,
136 const IVtk_MeshType theMeshType);
138 //! Get the IShape as OCC implementation
139 const IVtkOCC_Shape::Handle GetShapeObj() const;
141 DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
144 IVtk_ShapeTypeMap myEdgesTypes;
147 #endif // __IVTKOCC_SHAPEMESHER_H__