Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPTFrontTrack / FrontTrack_Projector.hxx
1 // Copyright (C) 2017-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : FrontTrack_Projector.hxx
20 // Created   : Wed Apr 26 20:12:13 2017
21 // Author    : Edward AGAPOV (eap)
22
23 #ifndef __FrontTrack_Projector_HXX__
24 #define __FrontTrack_Projector_HXX__
25
26 #include <TopoDS_Shape.hxx>
27 #include <Bnd_Box.hxx>
28
29 struct FT_RealProjector;
30
31 /*!
32  * \brief Projector of a point to a boundary shape. Wrapper of a real projection algo
33  */
34 class FT_Projector
35 {
36 public:
37
38   FT_Projector(const TopoDS_Shape& shape = TopoDS_Shape());
39   FT_Projector(const FT_Projector& other);
40   ~FT_Projector();
41
42   // initialize with a boundary shape, compute the bounding box
43   void setBoundaryShape(const TopoDS_Shape& shape);
44
45   // return the boundary shape
46   const TopoDS_Shape& getShape() const { return _shape; }
47
48   // return the bounding box
49   const Bnd_Box getBoundingBox() const { return _bndBox; }
50
51
52   // create a real projector
53   void prepareForProjection();
54
55   // return true if a previously found solution can be used to speed up the projection
56   bool canUsePrevSolution() const;
57
58   // return true if projection is not needed
59   bool isPlanarBoundary() const;
60
61
62   // switch a mode of usage of prevSolution.
63   // If projection fails, to try to project without usage of prevSolution.
64   // By default this mode is off
65   void tryWithoutPrevSolution( bool toTry ) { _tryWOPrevSolution = toTry; }
66
67   // project a point to the boundary shape
68   bool project( const gp_Pnt& point,
69                 const double  maxDist2,
70                 gp_Pnt&       projection,
71                 double*       newSolution,
72                 const double* prevSolution = 0);
73
74   // project a point to the boundary shape and check if the projection is within the shape boundary
75   bool projectAndClassify( const gp_Pnt& point,
76                            const double  maxDist2,
77                            gp_Pnt&       projection,
78                            double*       newSolution,
79                            const double* prevSolution = 0);
80
81   // check if a point lies on the boundary shape
82   bool isOnShape( const gp_Pnt& point,
83                   const double  tol2,
84                   double*       newSolution,
85                   const double* prevSolution = 0);
86
87 private:
88
89   FT_RealProjector* _realProjector;
90   Bnd_Box           _bndBox;
91   TopoDS_Shape      _shape;
92   bool              _tryWOPrevSolution;
93 };
94
95 #endif