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