0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / BRepMesh / BRepMesh_EdgeParameterProvider.hxx
CommitLineData
ceb418e1 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#ifndef _BRepMesh_EdgeParameterProvider_HeaderFile
17#define _BRepMesh_EdgeParameterProvider_HeaderFile
18
7bd071ed 19#include <IMeshData_Types.hxx>
20#include <IMeshData_Edge.hxx>
21#include <IMeshData_Face.hxx>
22#include <TopoDS.hxx>
ceb418e1 23#include <Standard.hxx>
24#include <Standard_DefineAlloc.hxx>
25#include <Extrema_LocateExtPC.hxx>
b7c077b9 26#include <TColStd_HArray1OfReal.hxx>
51aed730 27#include <BRepAdaptor_Curve.hxx>
7bd071ed 28#include <Adaptor3d_CurveOnSurface.hxx>
29#include <TColStd_HArray1OfReal.hxx>
c22b52d6 30#include <Geom2dAdaptor_Curve.hxx>
31#include <GeomAdaptor_Surface.hxx>
ceb418e1 32
33class gp_Pnt;
34class TopoDS_Edge;
35class TopoDS_Face;
ceb418e1 36
37//! Auxiliary class provides correct parameters
38//! on curve regarding SameParameter flag.
7bd071ed 39template<class ParametersCollection>
40class BRepMesh_EdgeParameterProvider : public Standard_Transient
ceb418e1 41{
42public:
43
44 DEFINE_STANDARD_ALLOC
45
7bd071ed 46 //! Constructor. Initializes empty provider.
47 BRepMesh_EdgeParameterProvider()
d533dafb 48 : myIsSameParam(Standard_False),
49 myFirstParam(0.0),
50 myOldFirstParam(0.0),
51 myScale(0.0),
52 myCurParam(0.0),
53 myFoundParam(0.0)
7bd071ed 54 {
55 }
56
ceb418e1 57 //! Constructor.
58 //! @param theEdge edge which parameters should be processed.
59 //! @param theFace face the parametric values are defined for.
60 //! @param theParameters parameters corresponded to discretization points.
61 BRepMesh_EdgeParameterProvider(
7bd071ed 62 const IMeshData::IEdgeHandle& theEdge,
63 const TopAbs_Orientation theOrientation,
64 const IMeshData::IFaceHandle& theFace,
65 const ParametersCollection& theParameters)
66 {
67 Init(theEdge, theOrientation, theFace, theParameters);
68 }
69
70 //! Initialized provider by the given data.
71 void Init (
72 const IMeshData::IEdgeHandle& theEdge,
73 const TopAbs_Orientation theOrientation,
74 const IMeshData::IFaceHandle& theFace,
75 const ParametersCollection& theParameters)
76 {
77 myParameters = theParameters;
78 myIsSameParam = theEdge->GetSameParam();
79 myScale = 1.;
80
81 // Extract actual parametric values
82 const TopoDS_Edge aEdge = TopoDS::Edge(theEdge->GetEdge().Oriented(theOrientation));
83
84 myCurveAdaptor.Initialize(aEdge, theFace->GetFace());
85 if (myIsSameParam)
86 {
87 return;
88 }
89
90 myFirstParam = myCurveAdaptor.FirstParameter();
91 const Standard_Real aLastParam = myCurveAdaptor.LastParameter();
92
93 myFoundParam = myCurParam = myFirstParam;
94
95 // Extract parameters stored in polygon
96 myOldFirstParam = myParameters->Value(myParameters->Lower());
97 const Standard_Real aOldLastParam = myParameters->Value(myParameters->Upper());
98
99 // Calculate scale factor between actual and stored parameters
100 if ((myOldFirstParam != myFirstParam || aOldLastParam != aLastParam) &&
101 myOldFirstParam != aOldLastParam)
102 {
103 myScale = (aLastParam - myFirstParam) / (aOldLastParam - myOldFirstParam);
104 }
105
106 myProjector.Initialize(myCurveAdaptor, myCurveAdaptor.FirstParameter(),
107 myCurveAdaptor.LastParameter(),Precision::PConfusion());
108 }
ceb418e1 109
110 //! Returns parameter according to SameParameter flag of the edge.
111 //! If SameParameter is TRUE returns value from parameters w/o changes,
112 //! elsewhere scales initial parameter and tries to determine resulting
113 //! value using projection of the corresponded 3D point on PCurve.
114 Standard_Real Parameter(const Standard_Integer theIndex,
7bd071ed 115 const gp_Pnt& thePoint3d) const
116 {
117 if (myIsSameParam)
118 {
119 return myParameters->Value(theIndex);
120 }
121
122 // Use scaled
123 const Standard_Real aParam = myParameters->Value(theIndex);
124
125 const Standard_Real aPrevParam = myCurParam;
126 myCurParam = myFirstParam + myScale * (aParam - myOldFirstParam);
127
128 const Standard_Real aPrevFoundParam = myFoundParam;
129 myFoundParam += (myCurParam - aPrevParam);
130
131 myProjector.Perform(thePoint3d, myFoundParam);
132 if (myProjector.IsDone())
133 {
134 const Standard_Real aFoundParam = myProjector.Point().Parameter();
135 if ((aPrevFoundParam < myFoundParam && aPrevFoundParam < aFoundParam) ||
136 (aPrevFoundParam > myFoundParam && aPrevFoundParam > aFoundParam))
137 {
138 // Rude protection against case when amplified parameter goes before
139 // previous one due to period or other reason occurred in projector.
140 // Using parameter returned by projector as is can produce self-intersections.
141 myFoundParam = aFoundParam;
142 }
143 }
144
145 return myFoundParam;
146 }
147
148 //! Returns pcurve used to compute parameters.
c22b52d6 149 const Handle(Adaptor2d_Curve2d)& GetPCurve() const
7bd071ed 150 {
151 return myCurveAdaptor.CurveOnSurface().GetCurve();
152 }
ceb418e1 153
154private:
155
7bd071ed 156 ParametersCollection myParameters;
ceb418e1 157
158 Standard_Boolean myIsSameParam;
159 Standard_Real myFirstParam;
160
161 Standard_Real myOldFirstParam;
162 Standard_Real myScale;
163
7bd071ed 164 mutable Standard_Real myCurParam;
165 mutable Standard_Real myFoundParam;
ceb418e1 166
51aed730 167 BRepAdaptor_Curve myCurveAdaptor;
7bd071ed 168
169 mutable Extrema_LocateExtPC myProjector;
ceb418e1 170};
171
172#endif