Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:15:56

0001 // Created on: 2014-08-13
0002 // Created by: Oleg AGASHIN
0003 // Copyright (c) 2011-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
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 //! Auxiliary class provides correct parameters
0034 //! on curve regarding SameParameter flag.
0035 template <class ParametersCollection>
0036 class BRepMesh_EdgeParameterProvider : public Standard_Transient
0037 {
0038 public:
0039   DEFINE_STANDARD_ALLOC
0040 
0041   //! Constructor. Initializes empty provider.
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   //! Constructor.
0053   //! @param theEdge edge which parameters should be processed.
0054   //! @param theFace face the parametric values are defined for.
0055   //! @param theParameters parameters corresponded to discretization points.
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   //! Initialized provider by the given data.
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     // Extract actual parametric values
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     // Extract parameters stored in polygon
0089     myOldFirstParam            = myParameters->Value(myParameters->Lower());
0090     const double aOldLastParam = myParameters->Value(myParameters->Upper());
0091 
0092     // Calculate scale factor between actual and stored parameters
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   //! Returns parameter according to SameParameter flag of the edge.
0106   //! If SameParameter is TRUE returns value from parameters w/o changes,
0107   //! elsewhere scales initial parameter and tries to determine resulting
0108   //! value using projection of the corresponded 3D point on PCurve.
0109   double Parameter(const int theIndex, const gp_Pnt& thePoint3d) const
0110   {
0111     if (myIsSameParam)
0112     {
0113       return myParameters->Value(theIndex);
0114     }
0115 
0116     // Use scaled
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         // Rude protection against case when amplified parameter goes before
0133         // previous one due to period or other reason occurred in projector.
0134         // Using parameter returned by projector as is can produce self-intersections.
0135         myFoundParam = aFoundParam;
0136       }
0137     }
0138 
0139     return myFoundParam;
0140   }
0141 
0142   //! Returns pcurve used to compute parameters.
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