0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / BRepMesh / BRepMesh_EdgeParameterProvider.cxx
1 // Created on: 2014-08-13
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BRepMesh_EdgeParameterProvider.hxx>
17 #include <gp_Pnt.hxx>
18 #include <TopoDS_Edge.hxx>
19 #include <TopoDS_Face.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepAdaptor_Curve.hxx>
23 #include <Precision.hxx>
24
25 //=======================================================================
26 //function : Constructor
27 //purpose  : 
28 //=======================================================================
29 BRepMesh_EdgeParameterProvider::BRepMesh_EdgeParameterProvider(
30   const TopoDS_Edge&                   theEdge,
31   const TopoDS_Face&                   theFace,
32   const Handle(TColStd_HArray1OfReal)& theParameters)
33   : myParameters(theParameters),
34     myIsSameParam(BRep_Tool::SameParameter(theEdge)),
35     myScale(1.),
36     myCurveAdaptor(theEdge, theFace)
37 {
38   if (myIsSameParam)
39     return;
40
41   // Extract actual parametric values
42   Standard_Real aLastParam;
43   BRep_Tool::Range(theEdge, theFace, myFirstParam, aLastParam);
44
45   myFoundParam = myCurParam = myFirstParam;
46
47   // Extract parameters stored in polygon
48   myOldFirstParam =
49     myParameters->Value(myParameters->Lower());
50
51   const Standard_Real aOldLastParam =
52     myParameters->Value(myParameters->Upper());
53
54   // Calculate scale factor between actual and stored parameters
55   if ((myOldFirstParam != myFirstParam || aOldLastParam != aLastParam) &&
56     myOldFirstParam != aOldLastParam)
57   {
58     myScale = (aLastParam - myFirstParam) /
59       (aOldLastParam - myOldFirstParam);
60   }
61
62   myProjector.Initialize(myCurveAdaptor, myCurveAdaptor.FirstParameter(),
63     myCurveAdaptor.LastParameter(), Precision::PConfusion());
64 }
65
66 //=======================================================================
67 //function : Parameter
68 //purpose  : 
69 //=======================================================================
70 Standard_Real BRepMesh_EdgeParameterProvider::Parameter(
71   const Standard_Integer theIndex,
72   const gp_Pnt&          thePoint3d)
73 {
74   if (myIsSameParam)
75     return myParameters->Value(theIndex);
76
77   // Use scaled
78   Standard_Real aPrevParam = myCurParam;
79   myCurParam = myFirstParam + myScale * 
80     (myParameters->Value(theIndex) - myOldFirstParam);
81
82   myFoundParam += (myCurParam - aPrevParam);
83
84   myProjector.Perform(thePoint3d, myFoundParam);
85   if (myProjector.IsDone())
86     myFoundParam = myProjector.Point().Parameter();
87
88   return myFoundParam;
89 }