Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 2013 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepMesh_GeomTool_HeaderFile
0015 #define _BRepMesh_GeomTool_HeaderFile
0016 
0017 #include <BRepAdaptor_Surface.hxx>
0018 #include <GCPnts_TangentialDeflection.hxx>
0019 #include <GeomAbs_IsoType.hxx>
0020 #include <TopoDS_Edge.hxx>
0021 #include <Precision.hxx>
0022 
0023 class BRepAdaptor_Curve;
0024 class gp_Pnt2d;
0025 class BRepMesh_DefaultRangeSplitter;
0026 
0027 //! Tool class accumulating common geometrical functions as well as 
0028 //! functionality using shape geometry to produce data necessary for 
0029 //! tessellation.
0030 //! General aim is to calculate discretization points for the given
0031 //! curve or iso curve of surface according to the specified parameters.
0032 class BRepMesh_GeomTool
0033 {
0034 public:
0035 
0036   //! Enumerates states of segments intersection check.
0037   enum IntFlag
0038   {
0039     NoIntersection,
0040     Cross,
0041     EndPointTouch,
0042     PointOnSegment,
0043     Glued,
0044     Same
0045   };
0046 
0047 public:
0048 
0049   DEFINE_STANDARD_ALLOC
0050   
0051   //! Constructor.
0052   //! Initiates discretization of the given geometric curve.
0053   //! @param theCurve curve to be discretized.
0054   //! @param theFirstParam first parameter of the curve.
0055   //! @param theLastParam last parameter of the curve.
0056   //! @param theLinDeflection linear deflection.
0057   //! @param theAngDeflection angular deflection.
0058   //! @param theMinPointsNb minimum number of points to be produced.
0059   Standard_EXPORT BRepMesh_GeomTool(
0060     const BRepAdaptor_Curve& theCurve,
0061     const Standard_Real      theFirstParam,
0062     const Standard_Real      theLastParam,
0063     const Standard_Real      theLinDeflection,
0064     const Standard_Real      theAngDeflection,
0065     const Standard_Integer   theMinPointsNb = 2,
0066     const Standard_Real      theMinSize = Precision::Confusion());
0067   
0068   //! Constructor.
0069   //! Initiates discretization of geometric curve corresponding 
0070   //! to iso curve of the given surface.
0071   //! @param theSurface surface the iso curve to be taken from.
0072   //! @param theIsoType type of iso curve to be used, U or V.
0073   //! @param theParamIso parameter on the surface specifying the iso curve.
0074   //! @param theFirstParam first parameter of the curve.
0075   //! @param theLastParam last parameter of the curve.
0076   //! @param theLinDeflection linear deflection.
0077   //! @param theAngDeflection angular deflection.
0078   //! @param theMinPointsNb minimum number of points to be produced.
0079   Standard_EXPORT BRepMesh_GeomTool(
0080     const Handle(BRepAdaptor_Surface)& theSurface,
0081     const GeomAbs_IsoType               theIsoType,
0082     const Standard_Real                 theParamIso,
0083     const Standard_Real                 theFirstParam,
0084     const Standard_Real                 theLastParam,
0085     const Standard_Real                 theLinDeflection,
0086     const Standard_Real                 theAngDeflection,
0087     const Standard_Integer              theMinPointsNb = 2,
0088     const Standard_Real                 theMinSize = Precision::Confusion());
0089 
0090   //! Adds point to already calculated points (or replaces existing).
0091   //! @param thePoint point to be added.
0092   //! @param theParam parameter on the curve corresponding to the given point.
0093   //! @param theIsReplace if TRUE replaces existing point lying within 
0094   //! parameteric tolerance of the given point.
0095   //! @return index of new added point or found with parametric tolerance
0096   Standard_Integer AddPoint(const gp_Pnt&           thePoint,
0097                             const Standard_Real     theParam,
0098                             const Standard_Boolean  theIsReplace = Standard_True)
0099   {
0100     return myDiscretTool.AddPoint(thePoint, theParam, theIsReplace);
0101   }
0102   
0103   //! Returns number of discretization points.
0104   Standard_Integer NbPoints() const
0105   {
0106     return myDiscretTool.NbPoints();
0107   }
0108   
0109   //! Gets parameters of discretization point with the given index.
0110   //! @param theIndex index of discretization point.
0111   //! @param theIsoParam parameter on surface to be used as second coordinate 
0112   //! of resulting 2d point.
0113   //! @param theParam[out] parameter of the point on the iso curve.
0114   //! @param thePoint[out] discretization point.
0115   //! @param theUV[out] discretization point in parametric space of the surface.
0116   //! @return TRUE on success, FALSE elsewhere.
0117   Standard_EXPORT Standard_Boolean Value(const Standard_Integer theIndex,
0118                                          const Standard_Real    theIsoParam,
0119                                          Standard_Real&         theParam,
0120                                          gp_Pnt&                thePoint,
0121                                          gp_Pnt2d&              theUV) const;
0122   
0123   //! Gets parameters of discretization point with the given index.
0124   //! @param theIndex index of discretization point.
0125   //! @param theSurface surface the curve is lying onto.
0126   //! @param theParam[out] parameter of the point on the curve.
0127   //! @param thePoint[out] discretization point.
0128   //! @param theUV[out] discretization point in parametric space of the surface.
0129   //! @return TRUE on success, FALSE elsewhere.
0130   Standard_EXPORT Standard_Boolean Value(const Standard_Integer              theIndex,
0131                                          const Handle(BRepAdaptor_Surface)& theSurface,
0132                                          Standard_Real&                      theParam,
0133                                          gp_Pnt&                             thePoint,
0134                                          gp_Pnt2d&                           theUV) const;
0135   
0136 public: //! @name static API
0137 
0138   //! Computes normal to the given surface at the specified
0139   //! position in parametric space.
0140   //! @param theSurface surface the normal should be found for.
0141   //! @param theParamU U parameter in parametric space of the surface.
0142   //! @param theParamV V parameter in parametric space of the surface.
0143   //! @param[out] thePoint 3d point corresponding to the given parameters.
0144   //! @param[out] theNormal normal vector at the point specified by the parameters.
0145   //! @return FALSE if the normal can not be computed, TRUE elsewhere.
0146   Standard_EXPORT static Standard_Boolean Normal(
0147     const Handle(BRepAdaptor_Surface)& theSurface,
0148     const Standard_Real                 theParamU,
0149     const Standard_Real                 theParamV,
0150     gp_Pnt&                             thePoint,
0151     gp_Dir&                             theNormal);
0152 
0153   //! Checks intersection between two lines defined by two points.
0154   //! @param theStartPnt1 start point of first line.
0155   //! @param theEndPnt1 end point of first line.
0156   //! @param theStartPnt2 start point of second line.
0157   //! @param theEndPnt2 end point of second line.
0158   //! @param[out] theIntPnt point of intersection.
0159   //! @param[out] theParamOnSegment parameters of intersection point 
0160   //! corresponding to first and second segment.
0161   //! @return status of intersection check.
0162   Standard_EXPORT static IntFlag IntLinLin(
0163     const gp_XY&  theStartPnt1,
0164     const gp_XY&  theEndPnt1,
0165     const gp_XY&  theStartPnt2,
0166     const gp_XY&  theEndPnt2,
0167     gp_XY&        theIntPnt,
0168     Standard_Real (&theParamOnSegment)[2]);
0169 
0170   //! Checks intersection between the two segments. 
0171   //! Checks that intersection point lies within ranges of both segments.
0172   //! @param theStartPnt1 start point of first segment.
0173   //! @param theEndPnt1 end point of first segment.
0174   //! @param theStartPnt2 start point of second segment.
0175   //! @param theEndPnt2 end point of second segment.
0176   //! @param isConsiderEndPointTouch if TRUE EndPointTouch status will be
0177   //! returned in case if segments are touching by end points, if FALSE
0178   //! returns NoIntersection flag.
0179   //! @param isConsiderPointOnSegment if TRUE PointOnSegment status will be
0180   //! returned in case if end point of one segment lies onto another one, 
0181   //! if FALSE returns NoIntersection flag.
0182   //! @param[out] theIntPnt point of intersection.
0183   //! @return status of intersection check.
0184   Standard_EXPORT static IntFlag IntSegSeg(
0185     const gp_XY&           theStartPnt1,
0186     const gp_XY&           theEndPnt1,
0187     const gp_XY&           theStartPnt2,
0188     const gp_XY&           theEndPnt2,
0189     const Standard_Boolean isConsiderEndPointTouch,
0190     const Standard_Boolean isConsiderPointOnSegment,
0191     gp_Pnt2d&              theIntPnt);
0192 
0193   //! Compute deflection of the given segment.
0194   static Standard_Real SquareDeflectionOfSegment(
0195     const gp_Pnt& theFirstPoint,
0196     const gp_Pnt& theLastPoint,
0197     const gp_Pnt& theMidPoint)
0198   {
0199     // 23.03.2010 skl for OCC21645 - change precision for comparison
0200     if (theFirstPoint.SquareDistance(theLastPoint) > Precision::SquareConfusion())
0201     {
0202       gp_Lin aLin(theFirstPoint, gp_Dir(gp_Vec(theFirstPoint, theLastPoint)));
0203       return aLin.SquareDistance(theMidPoint);
0204     }
0205 
0206     return theFirstPoint.SquareDistance(theMidPoint);
0207   }
0208 
0209   // For better meshing performance we try to estimate the acceleration circles grid structure sizes:
0210   // For each parametric direction (U, V) we estimate firstly an approximate distance between the future points -
0211   // this estimation takes into account the required face deflection and the complexity of the face.
0212   // Particularly, the complexity of the faces based on BSpline curves and surfaces requires much more points.
0213   // At the same time, for planar faces and linear parts of the arbitrary surfaces usually no intermediate points
0214   // are necessary.
0215   // The general idea for each parametric direction:
0216   // cells_count = 2 ^ log10 ( estimated_points_count )
0217   // For linear parametric direction we fall back to the initial vertex count:
0218   // cells_count = 2 ^ log10 ( initial_vertex_count )
0219   Standard_EXPORT static std::pair<Standard_Integer, Standard_Integer> CellsCount (
0220     const Handle (Adaptor3d_Surface)&   theSurface,
0221     const Standard_Integer               theVerticesNb,
0222     const Standard_Real                  theDeflection,
0223     const BRepMesh_DefaultRangeSplitter* theRangeSplitter);
0224 
0225 private:
0226 
0227   //! Classifies the point in case of coincidence of two vectors.
0228   //! @param thePoint1 the start point of a segment (base point).
0229   //! @param thePoint2 the end point of a segment.
0230   //! @param thePointToCheck the point to classify.
0231   //! @return zero value if point is out of segment and non zero value 
0232   //! if point is between the first and the second point of segment.
0233   static Standard_Integer classifyPoint (const gp_XY& thePoint1,
0234                                          const gp_XY& thePoint2,
0235                                          const gp_XY& thePointToCheck);
0236 
0237 private:
0238 
0239   const TopoDS_Edge*                  myEdge;
0240   GCPnts_TangentialDeflection         myDiscretTool;
0241   GeomAbs_IsoType                     myIsoType;
0242 };
0243 
0244 #endif