0025936: Reusable data structure for 2D tesselation (3- and 4-nodal mesh)
[occt.git] / src / BRepMesh / BRepMesh_ShapeTool.hxx
1 // Copyright (c) 2013 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #ifndef _BRepMesh_ShapeTool_HeaderFile
16 #define _BRepMesh_ShapeTool_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Macro.hxx>
21 #include <Handle_BRepAdaptor_HSurface.hxx>
22 #include <BRepMesh_FaceAttribute.hxx>
23 #include <BRepMesh.hxx>
24 #include <Poly_Triangulation.hxx>
25
26 class TopoDS_Face;
27 class TopoDS_Edge;
28 class Bnd_Box;
29 class TopoDS_Vertex;
30 class gp_XY;
31 class gp_Pnt2d;
32
33 class BRepMesh_ShapeTool
34 {
35 public:
36
37   DEFINE_STANDARD_ALLOC
38   
39   //! Returns maximum tolerance of the given face.
40   //! Considers tolerances of edges and vertices contained in the given face.
41   Standard_EXPORT static Standard_Real MaxFaceTolerance(
42     const TopoDS_Face& theFace);
43
44   //! Gets the maximum dimension of the given bounding box.
45   //! If the given bounding box is void leaves the resulting value unchanged.
46   //! @param theBox bounding box to be processed.
47   //! @param theMaxDimension maximum dimension of the given box.
48   Standard_EXPORT static void BoxMaxDimension(const Bnd_Box& theBox,
49                                               Standard_Real& theMaxDimension);
50
51   //! Returns relative deflection for edge with respect to shape size.
52   //! @param theEdge edge for which relative deflection should be computed.
53   //! @param theDeflection absolute deflection.
54   //! @param theMaxShapeSize maximum size of a shape.
55   //! @param theAdjustmentCoefficient coefficient of adjustment between maximum 
56   //! size of shape and calculated relative deflection.
57   //! @return relative deflection for the edge.
58   Standard_EXPORT static Standard_Real RelativeEdgeDeflection(
59     const TopoDS_Edge&  theEdge,
60     const Standard_Real theDeflection,
61     const Standard_Real theMaxShapeSize,
62     Standard_Real&      theAdjustmentCoefficient);
63
64   //! Checks 2d representations of 3d point with the 
65   //! given index for equality to avoid duplications.
66   //! @param theIndexOfPnt3d index of 3d point with which 2d 
67   //! representation should be associated.
68   //! @param thePnt2d 2d representation of the point with the 
69   //! given index.
70   //! @param theVertex vertex corresponded to 3d point with the 
71   //! given index. Used to extract vertex tolerance in 3d space.
72   //! @param theMinDistance minimum distance between vertices 
73   //! regarding which they could be treated as distinct ones.
74   //! This value is defined by mesher using parameters given by
75   //! user in connection with shape metrics.
76   //! @param theFaceAttribute attributes contining data calculated
77   //! according to face geomtry and define limits of face in parametric 
78   //! space. If defined, will be used instead of surface parameter.
79   //! @param theLocation2dMap map of 2d representations of 3d points.
80   //! @return given 2d point in case if 3d poind does not alredy have 
81   //! the similar representation, otherwice 2d point corresponding to 
82   //! existing representation will be returned.
83   Standard_EXPORT static gp_XY FindUV(
84     const Standard_Integer                theIndexOfPnt3d,
85     const gp_Pnt2d&                       thePnt2d,
86     const TopoDS_Vertex&                  theVertex,
87     const Standard_Real                   theMinDistance,
88     const Handle(BRepMesh_FaceAttribute)& theFaceAttribute);
89
90   //! Stores the given triangulation into the given face.
91   //! @param theFace face to be updated by triangulation.
92   //! @param theTriangulation triangulation to be stored into the face.
93   Standard_EXPORT static void AddInFace(
94     const TopoDS_Face&          theFace,
95     Handle(Poly_Triangulation)& theTriangulation);
96
97   //! Nullifies triangulation stored in the face.
98   //! @param theFace face to be updated by null triangulation.
99   Standard_EXPORT static void NullifyFace(const TopoDS_Face& theFace);
100
101   //! Nullifies polygon on triangulation stored in the edge.
102   //! @param theEdge edge to be updated by null polygon.
103   //! @param theTriangulation triangulation the given edge is associated to.
104   //! @param theLocation face location.
105   Standard_EXPORT static void NullifyEdge(
106     const TopoDS_Edge&                theEdge,
107     const Handle(Poly_Triangulation)& theTriangulation,
108     const TopLoc_Location&            theLocation);
109
110   //! Updates the given edge by the given tessellated representation.
111   //! @param theEdge edge to be updated.
112   //! @param thePolygon tessellated representation of the edge to be stored.
113   //! @param theTriangulation triangulation the given edge is associated to.
114   //! @param theLocation face location.
115   Standard_EXPORT static void UpdateEdge(
116     const TopoDS_Edge&                         theEdge,
117     const Handle(Poly_PolygonOnTriangulation)& thePolygon,
118     const Handle(Poly_Triangulation)&          theTriangulation,
119     const TopLoc_Location&                     theLocation);
120
121   //! Updates the given seam edge by the given tessellated representations.
122   //! @param theEdge edge to be updated.
123   //! @param thePolygon1 tessellated representation corresponding to
124   //! forward direction of the seam edge.
125   //! @param thePolygon2 tessellated representation corresponding to
126   //! reversed direction of the seam edge.
127   //! @param theTriangulation triangulation the given edge is associated to.
128   //! @param theLocation face location.
129   Standard_EXPORT static void UpdateEdge(
130     const TopoDS_Edge&                         theEdge,
131     const Handle(Poly_PolygonOnTriangulation)& thePolygon1,
132     const Handle(Poly_PolygonOnTriangulation)& thePolygon2,
133     const Handle(Poly_Triangulation)&          theTriangulation,
134     const TopLoc_Location&                     theLocation);
135
136   //! Applies location to the given point and return result.
137   //! @param thePnt point to be transformed.
138   //! @param theLoc location to be applied.
139   Standard_EXPORT static gp_Pnt UseLocation(const gp_Pnt&          thePnt,
140                                             const TopLoc_Location& theLoc);
141
142   //! Checks is the given edge degenerated.
143   //! Checks geometrical parameters in case if IsDegenerated flag is not set.
144   //! @param theEdge edge to be checked.
145   //! @param theFace face within which parametric space edge will be checked
146   //! for geometrical degenerativity.
147   Standard_EXPORT static Standard_Boolean IsDegenerated(
148     const TopoDS_Edge& theEdge,
149     const TopoDS_Face& theFace);
150 };
151
152 #endif