File indexing completed on 2026-09-13 09:15:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _BRepMesh_EdgeParameterProvider_HeaderFile
0017 #define _BRepMesh_EdgeParameterProvider_HeaderFile
0018
0019 #include <IMeshData_Types.hxx>
0020 #include <IMeshData_Edge.hxx>
0021 #include <IMeshData_Face.hxx>
0022 #include <TopoDS.hxx>
0023 #include <Standard.hxx>
0024 #include <Standard_DefineAlloc.hxx>
0025 #include <Extrema_LocateExtPC.hxx>
0026 #include <BRepAdaptor_Curve.hxx>
0027 #include <Geom2dAdaptor_Curve.hxx>
0028
0029 class gp_Pnt;
0030 class TopoDS_Edge;
0031 class TopoDS_Face;
0032
0033
0034
0035 template <class ParametersCollection>
0036 class BRepMesh_EdgeParameterProvider : public Standard_Transient
0037 {
0038 public:
0039 DEFINE_STANDARD_ALLOC
0040
0041
0042 BRepMesh_EdgeParameterProvider()
0043 : myIsSameParam(false),
0044 myFirstParam(0.0),
0045 myOldFirstParam(0.0),
0046 myScale(0.0),
0047 myCurParam(0.0),
0048 myFoundParam(0.0)
0049 {
0050 }
0051
0052
0053
0054
0055
0056 BRepMesh_EdgeParameterProvider(const IMeshData::IEdgeHandle& theEdge,
0057 const TopAbs_Orientation theOrientation,
0058 const IMeshData::IFaceHandle& theFace,
0059 const ParametersCollection& theParameters)
0060 {
0061 Init(theEdge, theOrientation, theFace, theParameters);
0062 }
0063
0064
0065 void Init(const IMeshData::IEdgeHandle& theEdge,
0066 const TopAbs_Orientation theOrientation,
0067 const IMeshData::IFaceHandle& theFace,
0068 const ParametersCollection& theParameters)
0069 {
0070 myParameters = theParameters;
0071 myIsSameParam = theEdge->GetSameParam();
0072 myScale = 1.;
0073
0074
0075 const TopoDS_Edge aEdge = TopoDS::Edge(theEdge->GetEdge().Oriented(theOrientation));
0076
0077 myCurveAdaptor.Initialize(aEdge, theFace->GetFace());
0078 if (myIsSameParam)
0079 {
0080 return;
0081 }
0082
0083 myFirstParam = myCurveAdaptor.FirstParameter();
0084 const double aLastParam = myCurveAdaptor.LastParameter();
0085
0086 myFoundParam = myCurParam = myFirstParam;
0087
0088
0089 myOldFirstParam = myParameters->Value(myParameters->Lower());
0090 const double aOldLastParam = myParameters->Value(myParameters->Upper());
0091
0092
0093 if ((myOldFirstParam != myFirstParam || aOldLastParam != aLastParam)
0094 && myOldFirstParam != aOldLastParam)
0095 {
0096 myScale = (aLastParam - myFirstParam) / (aOldLastParam - myOldFirstParam);
0097 }
0098
0099 myProjector.Initialize(myCurveAdaptor,
0100 myCurveAdaptor.FirstParameter(),
0101 myCurveAdaptor.LastParameter(),
0102 Precision::PConfusion());
0103 }
0104
0105
0106
0107
0108
0109 double Parameter(const int theIndex, const gp_Pnt& thePoint3d) const
0110 {
0111 if (myIsSameParam)
0112 {
0113 return myParameters->Value(theIndex);
0114 }
0115
0116
0117 const double aParam = myParameters->Value(theIndex);
0118
0119 const double aPrevParam = myCurParam;
0120 myCurParam = myFirstParam + myScale * (aParam - myOldFirstParam);
0121
0122 const double aPrevFoundParam = myFoundParam;
0123 myFoundParam += (myCurParam - aPrevParam);
0124
0125 myProjector.Perform(thePoint3d, myFoundParam);
0126 if (myProjector.IsDone())
0127 {
0128 const double aFoundParam = myProjector.Point().Parameter();
0129 if ((aPrevFoundParam < myFoundParam && aPrevFoundParam < aFoundParam)
0130 || (aPrevFoundParam > myFoundParam && aPrevFoundParam > aFoundParam))
0131 {
0132
0133
0134
0135 myFoundParam = aFoundParam;
0136 }
0137 }
0138
0139 return myFoundParam;
0140 }
0141
0142
0143 const occ::handle<Adaptor2d_Curve2d>& GetPCurve() const
0144 {
0145 return myCurveAdaptor.CurveOnSurface().GetCurve();
0146 }
0147
0148 private:
0149 ParametersCollection myParameters;
0150
0151 bool myIsSameParam;
0152 double myFirstParam;
0153
0154 double myOldFirstParam;
0155 double myScale;
0156
0157 mutable double myCurParam;
0158 mutable double myFoundParam;
0159
0160 BRepAdaptor_Curve myCurveAdaptor;
0161
0162 mutable Extrema_LocateExtPC myProjector;
0163 };
0164
0165 #endif