File indexing completed on 2025-01-18 10:03:14
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 <Adaptor3d_CurveOnSurface.hxx>
0028 #include <Geom2dAdaptor_Curve.hxx>
0029
0030 class gp_Pnt;
0031 class TopoDS_Edge;
0032 class TopoDS_Face;
0033
0034
0035
0036 template<class ParametersCollection>
0037 class BRepMesh_EdgeParameterProvider : public Standard_Transient
0038 {
0039 public:
0040
0041 DEFINE_STANDARD_ALLOC
0042
0043
0044 BRepMesh_EdgeParameterProvider()
0045 : myIsSameParam(Standard_False),
0046 myFirstParam(0.0),
0047 myOldFirstParam(0.0),
0048 myScale(0.0),
0049 myCurParam(0.0),
0050 myFoundParam(0.0)
0051 {
0052 }
0053
0054
0055
0056
0057
0058 BRepMesh_EdgeParameterProvider(
0059 const IMeshData::IEdgeHandle& theEdge,
0060 const TopAbs_Orientation theOrientation,
0061 const IMeshData::IFaceHandle& theFace,
0062 const ParametersCollection& theParameters)
0063 {
0064 Init(theEdge, theOrientation, theFace, theParameters);
0065 }
0066
0067
0068 void Init (
0069 const IMeshData::IEdgeHandle& theEdge,
0070 const TopAbs_Orientation theOrientation,
0071 const IMeshData::IFaceHandle& theFace,
0072 const ParametersCollection& theParameters)
0073 {
0074 myParameters = theParameters;
0075 myIsSameParam = theEdge->GetSameParam();
0076 myScale = 1.;
0077
0078
0079 const TopoDS_Edge aEdge = TopoDS::Edge(theEdge->GetEdge().Oriented(theOrientation));
0080
0081 myCurveAdaptor.Initialize(aEdge, theFace->GetFace());
0082 if (myIsSameParam)
0083 {
0084 return;
0085 }
0086
0087 myFirstParam = myCurveAdaptor.FirstParameter();
0088 const Standard_Real aLastParam = myCurveAdaptor.LastParameter();
0089
0090 myFoundParam = myCurParam = myFirstParam;
0091
0092
0093 myOldFirstParam = myParameters->Value(myParameters->Lower());
0094 const Standard_Real aOldLastParam = myParameters->Value(myParameters->Upper());
0095
0096
0097 if ((myOldFirstParam != myFirstParam || aOldLastParam != aLastParam) &&
0098 myOldFirstParam != aOldLastParam)
0099 {
0100 myScale = (aLastParam - myFirstParam) / (aOldLastParam - myOldFirstParam);
0101 }
0102
0103 myProjector.Initialize(myCurveAdaptor, myCurveAdaptor.FirstParameter(),
0104 myCurveAdaptor.LastParameter(),Precision::PConfusion());
0105 }
0106
0107
0108
0109
0110
0111 Standard_Real Parameter(const Standard_Integer theIndex,
0112 const gp_Pnt& thePoint3d) const
0113 {
0114 if (myIsSameParam)
0115 {
0116 return myParameters->Value(theIndex);
0117 }
0118
0119
0120 const Standard_Real aParam = myParameters->Value(theIndex);
0121
0122 const Standard_Real aPrevParam = myCurParam;
0123 myCurParam = myFirstParam + myScale * (aParam - myOldFirstParam);
0124
0125 const Standard_Real aPrevFoundParam = myFoundParam;
0126 myFoundParam += (myCurParam - aPrevParam);
0127
0128 myProjector.Perform(thePoint3d, myFoundParam);
0129 if (myProjector.IsDone())
0130 {
0131 const Standard_Real aFoundParam = myProjector.Point().Parameter();
0132 if ((aPrevFoundParam < myFoundParam && aPrevFoundParam < aFoundParam) ||
0133 (aPrevFoundParam > myFoundParam && aPrevFoundParam > aFoundParam))
0134 {
0135
0136
0137
0138 myFoundParam = aFoundParam;
0139 }
0140 }
0141
0142 return myFoundParam;
0143 }
0144
0145
0146 const Handle(Adaptor2d_Curve2d)& GetPCurve() const
0147 {
0148 return myCurveAdaptor.CurveOnSurface().GetCurve();
0149 }
0150
0151 private:
0152
0153 ParametersCollection myParameters;
0154
0155 Standard_Boolean myIsSameParam;
0156 Standard_Real myFirstParam;
0157
0158 Standard_Real myOldFirstParam;
0159 Standard_Real myScale;
0160
0161 mutable Standard_Real myCurParam;
0162 mutable Standard_Real myFoundParam;
0163
0164 BRepAdaptor_Curve myCurveAdaptor;
0165
0166 mutable Extrema_LocateExtPC myProjector;
0167 };
0168
0169 #endif