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 <BRepAdaptor_HSurface.hxx>
20 #include <IVtkOCC_Shape.hxx>
21 #include <IVtk_IShapeMesher.hxx>
22 #include <TColgp_Array1OfPnt.hxx>
23 #include <TColgp_SequenceOfPnt.hxx>
24 #include <TColStd_Array1OfInteger.hxx>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_ShapeMapHasher.hxx>
33 typedef NCollection_DataMap <TopoDS_Shape, IVtk_MeshType, TopTools_ShapeMapHasher> IVtk_ShapeTypeMap;
34 typedef NCollection_Sequence <gp_Pnt> IVtk_Polyline;
35 typedef NCollection_List <IVtk_Polyline> IVtk_PolylineList;
37 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapeMesher, IVtk_IShapeMesher )
39 //! @class IVtkOCC_ShapeMesher
40 //! @brief OCC implementation of IMesher interface.
42 //! Mesher produces shape data using implementation of IShapeData interface for
43 //! VTK and then result can be retrieved from this implementation as a vtkPolyData:
44 //! @image html doc/img/image002.gif
45 //! Then the resulting vtkPolyData can be used for initialization of VTK pipeline.
46 class IVtkOCC_ShapeMesher : public IVtk_IShapeMesher
49 IVtkOCC_ShapeMesher (const Standard_Real& theDevCoeff = 0.0001,
50 const Standard_Real& theDevAngle = 12.0 * M_PI / 180.0,
51 const Standard_Integer theNbUIsos = 1,
52 const Standard_Integer theNbVIsos = 1)
53 : myDevCoeff (theDevCoeff),
54 myDevAngle (theDevAngle),
58 myNbIsos[0] = theNbUIsos;
59 myNbIsos[1] = theNbVIsos;
62 virtual ~IVtkOCC_ShapeMesher() { }
64 //! Returns absolute deflection used by this algorithm.
65 //! This value is calculated on the basis of the shape's bounding box.
66 //! Zero might be returned in case if the underlying OCCT shape
67 //! is empty or invalid. Thus check the returned value before
68 //! passing it to OCCT meshing algorithms!
69 //! @return absolute deflection value
70 Standard_EXPORT Standard_Real GetDeflection() const;
72 //! Returns relative deviation coefficient used by this algorithm.
73 //! @return relative deviation coefficient
74 Standard_Real GetDeviationCoeff() const
79 //! Returns deviation angle used by this algorithm.
80 //! This is the maximum allowed angle between the normals to the
81 //! curve/surface and the normals to polyline/faceted representation.
82 //! @return deviation angle (in radians)
83 Standard_Real GetDeviationAngle() const
89 //! Executes the mesh generation algorithms. To be defined in implementation class.
90 Standard_EXPORT virtual void internalBuild();
93 //! Internal method, generates OCCT triangulation starting from TopoDS_Shape
94 //! @see IVtkOCC_ShapeMesher::addEdge, IVtkOCC_ShapeMesher::addShadedFace
97 //! Extracts free vertices from the shape (i.e. those not belonging to any edge)
98 //! and passes the geometry to IPolyData.
99 //! Each vertex is associated with its sub-shape ID.
100 void addFreeVertices();
102 //! Adds all the edges (free and non-free) to IPolyData.
105 //! Adds wireframe representations of all faces to IPolyData.
106 void addWireFrameFaces();
108 //! Adds shaded representations of all faces to IPolyData.
109 void addShadedFaces();
111 //! Adds the point coordinates, connectivity info and
112 //! sub-shape ID for the OCCT vertex.
114 //! @param theVertex OCCT vertex to be added to the mesh
115 //! @param theShapeId global point ID needed for connectivity data creation
116 void addVertex (const TopoDS_Vertex& theVertex,
117 const IVtk_IdType theShapeId,
118 const IVtk_MeshType theMeshType);
120 //! Adds the point coordinates and a polyline for the OCCT edge.
121 //! Note that the edge should be triangulated in advance.
123 //! @param theEdge OCCT edge to be meshed
124 //! @param theShapeId the edge's subshape ID
125 //! @see IVtkOCC_ShapeMesher::meshShape
126 void addEdge (const TopoDS_Edge& theEdge,
127 const IVtk_IdType theShapeId,
128 const IVtk_MeshType theMeshType);
130 //! Generates wireframe representation of the given TopoDS_Face object
131 //! with help of OCCT algorithms. The resulting polylines are passed to IPolyData
132 //! interface and associated with the given sub-shape ID.
133 //! @param [in] faceToMesh TopoDS_Face object to build wireframe representation for.
134 //! @param [in] shapeId The face' sub-shape ID
135 void addWFFace (const TopoDS_Face& theFace,
136 const IVtk_IdType theShapeId);
138 //! Creates shaded representation of the given TopoDS_Face object
139 //! starting from OCCT triangulation that should be created in advance.
140 //! The resulting triangles are passed to IPolyData
141 //! interface and associated with the given sub-shape ID.
142 //! @param [in] faceToMesh TopoDS_Face object to build shaded representation for.
143 //! @param [in] shapeId The face' sub-shape ID
144 //! @see IVtkOCC_ShapeMesher::meshShape, IVtkOCC_ShapeMesher::addEdge
145 void addShadedFace (const TopoDS_Face& theFace,
146 const IVtk_IdType theShapeId);
148 //! Internal function, builds polylines for boundary edges
149 //! and isolines of the face. It has been made a class method in order
150 //! to facilitate passing deflection, etc. here.
152 //! @param [in] theFace surface adaptor for the face
153 //! @param [in] theIsDrawUIso if equal to Standard_True, U isolines are built
154 //! @param [in] theIsDrawVIso if equal to Standard_True, V isolines are built
155 //! @param [in] theNBUiso number of U isolines
156 //! @param [in] theNBViso number of V isolines
157 //! @param [out] thePolylines container for the generated polylines
158 void buildIsoLines (const Handle(BRepAdaptor_HSurface)& theFace,
159 const Standard_Boolean theIsDrawUIso,
160 const Standard_Boolean theIsDrawVIso,
161 const Standard_Integer theNBUiso,
162 const Standard_Integer theNBViso,
163 IVtk_PolylineList& thePolylines);
165 //! Internal helper method that unpacks the input arrays of points and
166 //! connectivity and creates the polyline using IPolyData interface.
167 //! Optionally, the transformation specified through the last argument
168 //! can be applied to each point's coordinates (noTransform == true).
169 //! The polyline is associated with the given sub-shape ID.
170 void processPolyline (Standard_Integer theNbNodes,
171 const TColgp_Array1OfPnt& thePoints,
172 const TColStd_Array1OfInteger& thePointIds,
173 const IVtk_IdType theOcctId,
175 gp_Trsf theTransformation,
176 const IVtk_MeshType theMeshType);
178 //! Get the IShape as OCC implementation
179 const IVtkOCC_Shape::Handle GetShapeObj() const;
181 DEFINE_STANDARD_RTTI(IVtkOCC_ShapeMesher, IVtk_IShapeMesher)
184 IVtk_ShapeTypeMap myEdgesTypes;
185 Standard_Real myDevCoeff;
186 Standard_Real myDevAngle;
187 mutable Standard_Real myDeflection;
188 IVtk_PointId myPointId;
189 Standard_Integer myNbIsos[2];
192 #endif // __IVTKOCC_SHAPEMESHER_H__