0030520: VIS - IVtkTools_ShapePicker::GetPickPosition() returns incorrect point
[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),
c7854818 56 myDeflection (0.0)
913a4c4a 57 {
58 myNbIsos[0] = theNbUIsos;
59 myNbIsos[1] = theNbVIsos;
60 }
61
62 virtual ~IVtkOCC_ShapeMesher() { }
63
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;
71
72 //! Returns relative deviation coefficient used by this algorithm.
73 //! @return relative deviation coefficient
74 Standard_Real GetDeviationCoeff() const
75 {
76 return myDevCoeff;
77 }
78
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
84 {
85 return myDevAngle;
86 }
87
88protected:
89 //! Executes the mesh generation algorithms. To be defined in implementation class.
c7854818 90 Standard_EXPORT virtual void internalBuild() Standard_OVERRIDE;
913a4c4a 91
92private:
93 //! Internal method, generates OCCT triangulation starting from TopoDS_Shape
94 //! @see IVtkOCC_ShapeMesher::addEdge, IVtkOCC_ShapeMesher::addShadedFace
95 void meshShape();
96
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();
101
102 //! Adds all the edges (free and non-free) to IPolyData.
103 void addEdges();
104
105 //! Adds wireframe representations of all faces to IPolyData.
106 void addWireFrameFaces();
107
108 //! Adds shaded representations of all faces to IPolyData.
109 void addShadedFaces();
110
111 //! Adds the point coordinates, connectivity info and
112 //! sub-shape ID for the OCCT vertex.
113 //!
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);
119
120 //! Adds the point coordinates and a polyline for the OCCT edge.
121 //! Note that the edge should be triangulated in advance.
122 //!
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);
129
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);
137
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);
147
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.
151 //!
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);
164
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,
174 bool theNoTransform,
175 gp_Trsf theTransformation,
176 const IVtk_MeshType theMeshType);
177
178 //! Get the IShape as OCC implementation
179 const IVtkOCC_Shape::Handle GetShapeObj() const;
180
92efcf78 181 DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapeMesher,IVtk_IShapeMesher)
913a4c4a 182
183private:
184 IVtk_ShapeTypeMap myEdgesTypes;
185 Standard_Real myDevCoeff;
186 Standard_Real myDevAngle;
187 mutable Standard_Real myDeflection;
913a4c4a 188 Standard_Integer myNbIsos[2];
189};
190
191#endif // __IVTKOCC_SHAPEMESHER_H__