1 // Created on: 2014-08-13
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BRepMesh_EdgeParameterProvider_HeaderFile
17 #define _BRepMesh_EdgeParameterProvider_HeaderFile
19 #include <IMeshData_Types.hxx>
20 #include <IMeshData_Edge.hxx>
21 #include <IMeshData_Face.hxx>
23 #include <Standard.hxx>
24 #include <Standard_DefineAlloc.hxx>
25 #include <Extrema_LocateExtPC.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <BRepAdaptor_Curve.hxx>
28 #include <Adaptor3d_CurveOnSurface.hxx>
29 #include <TColStd_HArray1OfReal.hxx>
30 #include <Geom2dAdaptor_HCurve.hxx>
31 #include <GeomAdaptor_HSurface.hxx>
37 //! Auxiliary class provides correct parameters
38 //! on curve regarding SameParameter flag.
39 template<class ParametersCollection>
40 class BRepMesh_EdgeParameterProvider : public Standard_Transient
46 //! Constructor. Initializes empty provider.
47 BRepMesh_EdgeParameterProvider()
52 //! @param theEdge edge which parameters should be processed.
53 //! @param theFace face the parametric values are defined for.
54 //! @param theParameters parameters corresponded to discretization points.
55 BRepMesh_EdgeParameterProvider(
56 const IMeshData::IEdgeHandle& theEdge,
57 const TopAbs_Orientation theOrientation,
58 const IMeshData::IFaceHandle& theFace,
59 const ParametersCollection& theParameters)
61 Init(theEdge, theOrientation, theFace, theParameters);
64 //! Initialized provider by the given data.
66 const IMeshData::IEdgeHandle& theEdge,
67 const TopAbs_Orientation theOrientation,
68 const IMeshData::IFaceHandle& theFace,
69 const ParametersCollection& theParameters)
71 myParameters = theParameters;
72 myIsSameParam = theEdge->GetSameParam();
75 // Extract actual parametric values
76 const TopoDS_Edge aEdge = TopoDS::Edge(theEdge->GetEdge().Oriented(theOrientation));
78 myCurveAdaptor.Initialize(aEdge, theFace->GetFace());
84 myFirstParam = myCurveAdaptor.FirstParameter();
85 const Standard_Real aLastParam = myCurveAdaptor.LastParameter();
87 myFoundParam = myCurParam = myFirstParam;
89 // Extract parameters stored in polygon
90 myOldFirstParam = myParameters->Value(myParameters->Lower());
91 const Standard_Real aOldLastParam = myParameters->Value(myParameters->Upper());
93 // Calculate scale factor between actual and stored parameters
94 if ((myOldFirstParam != myFirstParam || aOldLastParam != aLastParam) &&
95 myOldFirstParam != aOldLastParam)
97 myScale = (aLastParam - myFirstParam) / (aOldLastParam - myOldFirstParam);
100 myProjector.Initialize(myCurveAdaptor, myCurveAdaptor.FirstParameter(),
101 myCurveAdaptor.LastParameter(),Precision::PConfusion());
104 //! Returns parameter according to SameParameter flag of the edge.
105 //! If SameParameter is TRUE returns value from parameters w/o changes,
106 //! elsewhere scales initial parameter and tries to determine resulting
107 //! value using projection of the corresponded 3D point on PCurve.
108 Standard_Real Parameter(const Standard_Integer theIndex,
109 const gp_Pnt& thePoint3d) const
113 return myParameters->Value(theIndex);
117 const Standard_Real aParam = myParameters->Value(theIndex);
119 const Standard_Real aPrevParam = myCurParam;
120 myCurParam = myFirstParam + myScale * (aParam - myOldFirstParam);
122 const Standard_Real aPrevFoundParam = myFoundParam;
123 myFoundParam += (myCurParam - aPrevParam);
125 myProjector.Perform(thePoint3d, myFoundParam);
126 if (myProjector.IsDone())
128 const Standard_Real aFoundParam = myProjector.Point().Parameter();
129 if ((aPrevFoundParam < myFoundParam && aPrevFoundParam < aFoundParam) ||
130 (aPrevFoundParam > myFoundParam && aPrevFoundParam > aFoundParam))
132 // Rude protection against case when amplified parameter goes before
133 // previous one due to period or other reason occurred in projector.
134 // Using parameter returned by projector as is can produce self-intersections.
135 myFoundParam = aFoundParam;
142 //! Returns pcurve used to compute parameters.
143 const Handle(Adaptor2d_HCurve2d)& GetPCurve() const
145 return myCurveAdaptor.CurveOnSurface().GetCurve();
150 ParametersCollection myParameters;
152 Standard_Boolean myIsSameParam;
153 Standard_Real myFirstParam;
155 Standard_Real myOldFirstParam;
156 Standard_Real myScale;
158 mutable Standard_Real myCurParam;
159 mutable Standard_Real myFoundParam;
161 BRepAdaptor_Curve myCurveAdaptor;
163 mutable Extrema_LocateExtPC myProjector;