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