fc9b36d6 |
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 | #ifndef _BRepMesh_GeomTool_HeaderFile |
15 | #define _BRepMesh_GeomTool_HeaderFile |
16 | |
17 | #include <Standard.hxx> |
18 | #include <Standard_DefineAlloc.hxx> |
19 | #include <Standard_Macro.hxx> |
20 | #include <GCPnts_TangentialDeflection.hxx> |
21 | #include <GeomAbs_IsoType.hxx> |
fc9b36d6 |
22 | #include <TopoDS_Edge.hxx> |
74da0216 |
23 | #include <Precision.hxx> |
fc9b36d6 |
24 | |
25 | class BRepAdaptor_Curve; |
26 | class BRepAdaptor_HSurface; |
27 | class gp_Pnt; |
28 | class gp_Pnt2d; |
29 | class gp_Dir; |
30 | |
d315303d |
31 | //! Tool class accumulating common geometrical functions as well as |
32 | //! functionality using shape geometry to produce data necessary for |
33 | //! tessellation. |
34 | //! General aim is to calculate discretization points for the given |
35 | //! curve or iso curve of surface according to the specified parameters. |
fc9b36d6 |
36 | class BRepMesh_GeomTool |
37 | { |
38 | public: |
39 | |
40 | //! Enumerates states of segments intersection check. |
41 | enum IntFlag |
42 | { |
43 | NoIntersection, |
44 | Cross, |
45 | EndPointTouch, |
46 | PointOnSegment, |
47 | Glued, |
48 | Same |
49 | }; |
50 | |
51 | public: |
52 | |
53 | DEFINE_STANDARD_ALLOC |
54 | |
55 | //! Constructor. |
56 | //! Initiates discretization of the given geometric curve. |
848fa7e3 |
57 | //! @param theCurve curve to be discretized. |
58 | //! @param theFirstParam first parameter of the curve. |
59 | //! @param theLastParam last parameter of the curve. |
60 | //! @param theLinDeflection linear deflection. |
61 | //! @param theAngDeflection angular deflection. |
62 | //! @param theMinPointsNb minimum nuber of points to be produced. |
fc9b36d6 |
63 | Standard_EXPORT BRepMesh_GeomTool(const BRepAdaptor_Curve& theCurve, |
64 | const Standard_Real theFirstParam, |
65 | const Standard_Real theLastParam, |
66 | const Standard_Real theLinDeflection, |
67 | const Standard_Real theAngDeflection, |
74da0216 |
68 | const Standard_Integer theMinPointsNb = 2, |
69 | const Standard_Real theMinSize = Precision::Confusion()); |
fc9b36d6 |
70 | |
71 | //! Constructor. |
72 | //! Initiates discretization of geometric curve corresponding |
73 | //! to iso curve of the given surface. |
848fa7e3 |
74 | //! @param theSurface surface the iso curve to be taken from. |
75 | //! @param theIsoType type of iso curve to be used, U or V. |
76 | //! @param theParamIso parameter on the surface specifying the iso curve. |
77 | //! @param theFirstParam first parameter of the curve. |
78 | //! @param theLastParam last parameter of the curve. |
79 | //! @param theLinDeflection linear deflection. |
80 | //! @param theAngDeflection angular deflection. |
81 | //! @param theMinPointsNb minimum nuber of points to be produced. |
fc9b36d6 |
82 | Standard_EXPORT BRepMesh_GeomTool(const Handle(BRepAdaptor_HSurface)& theSurface, |
83 | const GeomAbs_IsoType theIsoType, |
84 | const Standard_Real theParamIso, |
85 | const Standard_Real theFirstParam, |
86 | const Standard_Real theLastParam, |
87 | const Standard_Real theLinDeflection, |
88 | const Standard_Real theAngDeflection, |
74da0216 |
89 | const Standard_Integer theMinPointsNb = 2, |
90 | const Standard_Real theMinSize = Precision::Confusion()); |
fc9b36d6 |
91 | |
92 | //! Adds point to already calculated points (or replaces existing). |
848fa7e3 |
93 | //! @param thePoint point to be added. |
94 | //! @param theParam parameter on the curve corresponding to the given point. |
95 | //! @param theIsReplace if TRUE replaces existing point lying within |
fc9b36d6 |
96 | //! parameteric tolerance of the given point. |
848fa7e3 |
97 | //! @return index of new added point or found with parametric tolerance |
fc9b36d6 |
98 | inline Standard_Integer AddPoint(const gp_Pnt& thePoint, |
99 | const Standard_Real theParam, |
100 | const Standard_Boolean theIsReplace = Standard_True) |
101 | { |
102 | return myDiscretTool.AddPoint(thePoint, theParam, theIsReplace); |
103 | } |
104 | |
105 | //! Returns number of discretization points. |
106 | inline Standard_Integer NbPoints() const |
107 | { |
108 | return myDiscretTool.NbPoints(); |
109 | } |
110 | |
111 | //! Gets parameters of discretization point with the given index. |
848fa7e3 |
112 | //! @param theIndex index of discretization point. |
113 | //! @param theIsoParam parameter on surface to be used as second coordinate |
fc9b36d6 |
114 | //! of resulting 2d point. |
848fa7e3 |
115 | //! @param theParam[out] parameter of the point on the iso curve. |
116 | //! @param thePoint[out] discretization point. |
117 | //! @param theUV[out] discretization point in parametric space of the surface. |
118 | //! @return TRUE on success, FALSE elsewhere. |
fc9b36d6 |
119 | Standard_EXPORT Standard_Boolean Value(const Standard_Integer theIndex, |
120 | const Standard_Real theIsoParam, |
121 | Standard_Real& theParam, |
122 | gp_Pnt& thePoint, |
123 | gp_Pnt2d& theUV) const; |
124 | |
125 | //! Gets parameters of discretization point with the given index. |
848fa7e3 |
126 | //! @param theIndex index of discretization point. |
848fa7e3 |
127 | //! @param theParam[out] parameter of the point on the curve. |
128 | //! @param thePoint[out] discretization point. |
848fa7e3 |
129 | //! @return TRUE on success, FALSE elsewhere. |
fc9b36d6 |
130 | Standard_EXPORT Standard_Boolean Value(const Standard_Integer theIndex, |
fc9b36d6 |
131 | Standard_Real& theParam, |
81093856 |
132 | gp_Pnt& thePoint) const; |
fc9b36d6 |
133 | |
848fa7e3 |
134 | public: //! @name static API |
135 | |
d315303d |
136 | //! Computes normal to the given surface at the specified |
137 | //! position in parametric space. |
138 | //! @param theSurface surface the normal should be found for. |
848fa7e3 |
139 | //! @param theParamU U parameter in parametric space of the surface. |
140 | //! @param theParamV V parameter in parametric space of the surface. |
141 | //! @param[out] thePoint 3d point corresponding to the given parameters. |
142 | //! @param[out] theNormal normal vector at the point specified by the parameters. |
143 | //! @return FALSE if the normal can not be computed, TRUE elsewhere. |
d315303d |
144 | Standard_EXPORT static Standard_Boolean Normal( |
145 | const Handle(BRepAdaptor_HSurface)& theSurface, |
146 | const Standard_Real theParamU, |
147 | const Standard_Real theParamV, |
148 | gp_Pnt& thePoint, |
149 | gp_Dir& theNormal); |
fc9b36d6 |
150 | |
151 | //! Checks intersection between two lines defined by two points. |
848fa7e3 |
152 | //! @param theStartPnt1 start point of first line. |
153 | //! @param theEndPnt1 end point of first line. |
154 | //! @param theStartPnt2 start point of second line. |
155 | //! @param theEndPnt2 end point of second line. |
156 | //! @param[out] theIntPnt point of intersection. |
157 | //! @param[out] theParamOnSegment parameters of intersection point |
fc9b36d6 |
158 | //! corresponding to first and second segment. |
848fa7e3 |
159 | //! @return status of intersection check. |
d315303d |
160 | Standard_EXPORT static IntFlag IntLinLin( |
161 | const gp_XY& theStartPnt1, |
162 | const gp_XY& theEndPnt1, |
163 | const gp_XY& theStartPnt2, |
164 | const gp_XY& theEndPnt2, |
165 | gp_XY& theIntPnt, |
166 | Standard_Real (&theParamOnSegment)[2]); |
fc9b36d6 |
167 | |
168 | //! Checks intersection between the two segments. |
169 | //! Checks that intersection point lies within ranges of both segments. |
848fa7e3 |
170 | //! @param theStartPnt1 start point of first segment. |
171 | //! @param theEndPnt1 end point of first segment. |
172 | //! @param theStartPnt2 start point of second segment. |
173 | //! @param theEndPnt2 end point of second segment. |
174 | //! @param isConsiderEndPointTouch if TRUE EndPointTouch status will be |
fc9b36d6 |
175 | //! returned in case if segments are touching by end points, if FALSE |
176 | //! returns NoIntersection flag. |
848fa7e3 |
177 | //! @param isConsiderPointOnSegment if TRUE PointOnSegment status will be |
fc9b36d6 |
178 | //! returned in case if end point of one segment lies onto another one, |
179 | //! if FALSE returns NoIntersection flag. |
848fa7e3 |
180 | //! @param[out] theIntPnt point of intersection. |
181 | //! @return status of intersection check. |
d315303d |
182 | Standard_EXPORT static IntFlag IntSegSeg( |
183 | const gp_XY& theStartPnt1, |
184 | const gp_XY& theEndPnt1, |
185 | const gp_XY& theStartPnt2, |
186 | const gp_XY& theEndPnt2, |
187 | const Standard_Boolean isConsiderEndPointTouch, |
188 | const Standard_Boolean isConsiderPointOnSegment, |
189 | gp_Pnt2d& theIntPnt); |
fc9b36d6 |
190 | |
191 | private: |
192 | |
193 | //! Classifies the point in case of coincidence of two vectors. |
848fa7e3 |
194 | //! @param thePoint1 the start point of a segment (base point). |
195 | //! @param thePoint2 the end point of a segment. |
196 | //! @param thePointToCheck the point to classify. |
197 | //! @return zero value if point is out of segment and non zero value |
fc9b36d6 |
198 | //! if point is between the first and the second point of segment. |
199 | static Standard_Integer classifyPoint (const gp_XY& thePoint1, |
200 | const gp_XY& thePoint2, |
201 | const gp_XY& thePointToCheck); |
202 | |
203 | private: |
204 | |
205 | const TopoDS_Edge* myEdge; |
206 | GCPnts_TangentialDeflection myDiscretTool; |
207 | GeomAbs_IsoType myIsoType; |
208 | }; |
209 | |
210 | #endif |