Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:14

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 <Adaptor3d_CurveOnSurface.hxx>
0028 #include <Geom2dAdaptor_Curve.hxx>
0029 
0030 class gp_Pnt;
0031 class TopoDS_Edge;
0032 class TopoDS_Face;
0033 
0034 //! Auxiliary class provides correct parameters 
0035 //! on curve regarding SameParameter flag.
0036 template<class ParametersCollection>
0037 class BRepMesh_EdgeParameterProvider : public Standard_Transient
0038 {
0039 public:
0040 
0041   DEFINE_STANDARD_ALLOC
0042 
0043   //! Constructor. Initializes empty provider.
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   //! Constructor.
0055   //! @param theEdge edge which parameters should be processed.
0056   //! @param theFace face the parametric values are defined for.
0057   //! @param theParameters parameters corresponded to discretization points.
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   //! Initialized provider by the given data.
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     // Extract actual parametric values
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     // Extract parameters stored in polygon
0093     myOldFirstParam                   = myParameters->Value(myParameters->Lower());
0094     const Standard_Real aOldLastParam = myParameters->Value(myParameters->Upper());
0095 
0096     // Calculate scale factor between actual and stored parameters
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   //! Returns parameter according to SameParameter flag of the edge.
0108   //! If SameParameter is TRUE returns value from parameters w/o changes,
0109   //! elsewhere scales initial parameter and tries to determine resulting
0110   //! value using projection of the corresponded 3D point on PCurve.
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     // Use scaled
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         // Rude protection against case when amplified parameter goes before 
0136         // previous one due to period or other reason occurred in projector.
0137         // Using parameter returned by projector as is can produce self-intersections.
0138         myFoundParam = aFoundParam;
0139       }
0140     }
0141 
0142     return myFoundParam;
0143   }
0144 
0145   //! Returns pcurve used to compute parameters.
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