Salome HOME
Update copyrights
[modules/homard.git] / src / FrontTrack / FrontTrack_Projector.cxx
old mode 100755 (executable)
new mode 100644 (file)
index ce24d4b..c51c06c
@@ -1,3 +1,21 @@
+// Copyright (C) 2017-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 // File      : FrontTrack_Projector.cxx
 // Created   : Wed Apr 26 20:33:55 2017
 // Author    : Edward AGAPOV (eap)
@@ -104,9 +122,12 @@ namespace // actual projection algorithms
                             double*       newSolution,
                             const double* prevSolution = 0)
     {
+#ifdef _DEBUG_
+    std::cout << ".. project a point to the curve prevSolution = " << prevSolution << std::endl;
+#endif
       gp_Pnt         proj;
       Standard_Real param;
-      
+
       if ( prevSolution )
       {
         _dist = _projector.NextProject( prevSolution[0], _curve, P, _tol, proj, param );
@@ -114,8 +135,11 @@ namespace // actual projection algorithms
       else
       {
         _dist = _projector.Project( _curve, P, _tol, proj, param, false );
-        proj  = _curve.Value( param );
       }
+#ifdef _DEBUG_
+    std::cout << "..    _dist : " << _dist << std::endl;
+#endif
+      proj = _curve.Value( param );
 
       newSolution[0] = param;
 
@@ -130,6 +154,9 @@ namespace // actual projection algorithms
                                      double*       newSolution,
                                      const double* prevSolution = 0)
     {
+#ifdef _DEBUG_
+    std::cout << ".. project a point to a curve and check " << std::endl;
+#endif
       projection = project( point, newSolution, prevSolution );
       return ( _uRange[0] < newSolution[0] && newSolution[0] < _uRange[1] &&
                _dist * _dist < maxDist2 );
@@ -611,7 +638,7 @@ namespace // actual projection algorithms
   bool isStraight( const GeomAdaptor_Curve& curve, const double tol )
   {
     // rough check: evaluate how far from a straight line connecting the curve ends
-    // stand several internal points of the curve 
+    // stand several internal points of the curve
 
     const double  f = curve.FirstParameter();
     const double  l = curve.LastParameter();
@@ -649,6 +676,7 @@ FT_Projector::FT_Projector(const TopoDS_Shape& shape)
 {
   _realProjector = 0;
   setBoundaryShape( shape );
+  _tryWOPrevSolution = false;
 }
 
 //================================================================================
@@ -662,6 +690,7 @@ FT_Projector::FT_Projector(const FT_Projector& other)
   _realProjector = 0;
   _shape = other._shape;
   _bndBox = other._bndBox;
+  _tryWOPrevSolution = false;
 }
 
 //================================================================================
@@ -786,6 +815,9 @@ void FT_Projector::prepareForProjection()
       }
       break;
     }
+
+    if ( !_realProjector )
+      delete classifier;
   }
 }
 
@@ -859,7 +891,13 @@ bool FT_Projector::project( const gp_Pnt& point,
   _realProjector->_dist = 1e100;
   projection = _realProjector->project( point, newSolution, prevSolution );
 
-  return ( _realProjector->_dist * _realProjector->_dist < maxDist2 );
+  bool ok = ( _realProjector->_dist * _realProjector->_dist < maxDist2 );
+  if ( !ok && _tryWOPrevSolution && prevSolution )
+  {
+    projection = _realProjector->project( point, newSolution );
+    ok = ( _realProjector->_dist * _realProjector->_dist < maxDist2 );
+  }
+  return ok;
 }
 
 //================================================================================
@@ -889,8 +927,12 @@ bool FT_Projector::projectAndClassify( const gp_Pnt& point,
   if ( _bndBox.IsOut( point ) || !_realProjector )
     return false;
 
-  return _realProjector->projectAndClassify( point, maxDist2, projection,
-                                             newSolution, prevSolution );
+  bool ok = _realProjector->projectAndClassify( point, maxDist2, projection,
+                                                newSolution, prevSolution );
+  if ( !ok && _tryWOPrevSolution && prevSolution )
+    ok = _realProjector->projectAndClassify( point, maxDist2, projection, newSolution );
+
+  return ok;
 }
 
 //================================================================================