|
||||
File indexing completed on 2025-01-18 10:03:20
0001 // Created on: 2013-05-20 0002 // Created by: Mikhail PONIKAROV 0003 // Copyright (c) 2003-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 ChFi2d_FilletAlgo_HeaderFile 0017 #define ChFi2d_FilletAlgo_HeaderFile 0018 0019 #include <TopoDS_Edge.hxx> 0020 #include <TopoDS_Wire.hxx> 0021 #include <Geom2d_Curve.hxx> 0022 #include <Geom_Plane.hxx> 0023 #include <TColStd_ListOfReal.hxx> 0024 #include <TColStd_SequenceOfReal.hxx> 0025 #include <TColStd_SequenceOfBoolean.hxx> 0026 #include <TColStd_SequenceOfInteger.hxx> 0027 0028 class FilletPoint; 0029 0030 //! Algorithm that creates fillet edge: arc tangent to two edges in the start 0031 //! and in the end vertices. Initial edges must be located on the plane and 0032 //! must be connected by the end or start points (shared vertices are not 0033 //! obligatory). Created fillet arc is created with the given radius, that is 0034 //! useful in sketcher applications. 0035 //! 0036 //! The algorithm is iterative that allows to create fillet on any curves 0037 //! of initial edges, that supports projection of point and C2 continuous. 0038 //! Principles of algorithm can de reduced to the Newton method: 0039 //! 1. Splitting initial edge into N segments where probably only 1 root can be 0040 //! found. N depends on the complexity of the underlying curve. 0041 //! 2. On each segment compute value and derivative of the function: 0042 //! - argument of the function is the parameter on the curve 0043 //! - take point on the curve by the parameter: point of tangency 0044 //! - make center of fillet: perpendicular vector from the point of tagency 0045 //! - make projection from the center to the second curve 0046 //! - length of the projection minus radius of the fillet is result of the 0047 //! function 0048 //! - derivative of this function in the point is computed by value in 0049 //! point with small shift 0050 //! 3. Using Newton search method take the point on the segment where function 0051 //! value is most close to zero. If it is not enough close, step 2 and 3 are 0052 //! repeated taking as start or end point the found point. 0053 //! 4. If solution is found, result is created on point on root of the function (as a start point), 0054 //! point of the projection onto second curve (as an end point) and center of arc in found center. 0055 //! Initial edges are cut by the start and end point of tangency. 0056 class ChFi2d_FilletAlgo 0057 { 0058 public: 0059 0060 //! An empty constructor of the fillet algorithm. 0061 //! Call a method Init() to initialize the algorithm 0062 //! before calling of a Perform() method. 0063 Standard_EXPORT ChFi2d_FilletAlgo(); 0064 0065 //! A constructor of a fillet algorithm: accepts a wire consisting of two edges in a plane. 0066 Standard_EXPORT ChFi2d_FilletAlgo(const TopoDS_Wire& theWire, 0067 const gp_Pln& thePlane); 0068 0069 //! A constructor of a fillet algorithm: accepts two edges in a plane. 0070 Standard_EXPORT ChFi2d_FilletAlgo(const TopoDS_Edge& theEdge1, 0071 const TopoDS_Edge& theEdge2, 0072 const gp_Pln& thePlane); 0073 0074 //! Initializes a fillet algorithm: accepts a wire consisting of two edges in a plane. 0075 Standard_EXPORT void Init(const TopoDS_Wire& theWire, 0076 const gp_Pln& thePlane); 0077 0078 //! Initializes a fillet algorithm: accepts two edges in a plane. 0079 Standard_EXPORT void Init(const TopoDS_Edge& theEdge1, 0080 const TopoDS_Edge& theEdge2, 0081 const gp_Pln& thePlane); 0082 0083 //! Constructs a fillet edge. 0084 //! Returns true, if at least one result was found 0085 Standard_EXPORT Standard_Boolean Perform(const Standard_Real theRadius); 0086 0087 //! Returns number of possible solutions. 0088 //! <thePoint> chooses a particular fillet in case of several fillets 0089 //! may be constructed (for example, a circle intersecting a segment in 2 points). 0090 //! Put the intersecting (or common) point of the edges. 0091 Standard_EXPORT Standard_Integer NbResults(const gp_Pnt& thePoint); 0092 0093 //! Returns result (fillet edge, modified edge1, modified edge2), 0094 //! nearest to the given point <thePoint> if iSolution == -1. 0095 //! <thePoint> chooses a particular fillet in case of several fillets 0096 //! may be constructed (for example, a circle intersecting a segment in 2 points). 0097 //! Put the intersecting (or common) point of the edges. 0098 Standard_EXPORT TopoDS_Edge Result(const gp_Pnt& thePoint, 0099 TopoDS_Edge& theEdge1, TopoDS_Edge& theEdge2, 0100 const Standard_Integer iSolution = -1); 0101 0102 private: 0103 //! Computes the value the function in the current point. 0104 //! <theLimit> is end parameter of the segment 0105 void FillPoint(FilletPoint*, const Standard_Real theLimit); 0106 //! Computes the derivative value of the function in the current point. 0107 //! <theDiffStep> is small step for approximate derivative computation 0108 //! <theFront> is direction of the step: from or reversed 0109 void FillDiff(FilletPoint*, Standard_Real theDiffStep, Standard_Boolean theFront); 0110 //! Using Newton methods computes optimal point, that can be root of the 0111 //! function taking into account two input points, functions value and derivatives. 0112 //! Performs iteration until root is found or failed to find root. 0113 //! Stores roots in myResultParams. 0114 void PerformNewton(FilletPoint*, FilletPoint*); 0115 //! Splits segment by the parameter and calls Newton method for both segments. 0116 //! It supplies recursive iterations of the Newton methods calls 0117 //! (PerformNewton calls this function and this calls Netwton two times). 0118 Standard_Boolean ProcessPoint(FilletPoint*, FilletPoint*, Standard_Real); 0119 0120 //! Initial edges where the fillet must be computed. 0121 TopoDS_Edge myEdge1, myEdge2; 0122 //! Plane where fillet arc must be created. 0123 Handle(Geom_Plane) myPlane; 0124 //! Underlying curves of the initial edges 0125 Handle(Geom2d_Curve) myCurve1, myCurve2; 0126 //! Start and end parameters of curves of initial edges. 0127 Standard_Real myStart1, myEnd1, myStart2, myEnd2, myRadius; 0128 //! List of params where roots were found. 0129 TColStd_ListOfReal myResultParams; 0130 //! sequence of 0 or 1: position of the fillet relatively to the first curve 0131 TColStd_SequenceOfInteger myResultOrientation; 0132 //! position of the fillet relatively to the first curve 0133 Standard_Boolean myStartSide; 0134 //! are initial edges where exchanged in the beginning: to make first edge 0135 //! more simple and minimize number of iterations 0136 Standard_Boolean myEdgesExchnged; 0137 //! Number to avoid infinity recursion: indicates how deep the recursion is performed. 0138 Standard_Integer myDegreeOfRecursion; 0139 }; 0140 0141 //! Private class. Corresponds to the point on the first curve, computed 0142 //! fillet function and derivative on it. 0143 class FilletPoint 0144 { 0145 public: 0146 //! Creates a point on a first curve by parameter on this curve. 0147 FilletPoint(const Standard_Real theParam); 0148 0149 //! Changes the point position by changing point parameter on the first curve. 0150 void setParam(Standard_Real theParam) {myParam = theParam;} 0151 0152 //! Returns the point parameter on the first curve. 0153 Standard_Real getParam() const {return myParam;} 0154 0155 //! Returns number of found values of function in this point. 0156 Standard_Integer getNBValues() {return myV.Length();} 0157 0158 //! Returns value of function in this point. 0159 Standard_Real getValue(int theIndex) {return myV.Value(theIndex);} 0160 0161 //! Returns derivatives of function in this point. 0162 Standard_Real getDiff(int theIndex) {return myD.Value(theIndex);} 0163 0164 //! Returns true if function is valid (rediuses vectors of fillet do not intersect any curve). 0165 Standard_Boolean isValid(int theIndex) {return myValid.Value(theIndex);} 0166 0167 //! Returns the index of the nearest value 0168 int getNear(int theIndex) {return myNear.Value(theIndex);} 0169 0170 //! Defines the parameter of the projected point on the second curve. 0171 void setParam2(const Standard_Real theParam2) {myParam2 = theParam2;} 0172 0173 //! Returns the parameter of the projected point on the second curve. 0174 Standard_Real getParam2() { return myParam2 ; } 0175 0176 //! Center of the fillet. 0177 void setCenter(const gp_Pnt2d thePoint) {myCenter = thePoint;} 0178 //! Center of the fillet. 0179 const gp_Pnt2d getCenter() {return myCenter;} 0180 0181 //! Appends value of the function. 0182 void appendValue(Standard_Real theValue, Standard_Boolean theValid); 0183 0184 //! Computes difference between this point and the given. Stores difference in myD. 0185 Standard_Boolean calculateDiff(FilletPoint*); 0186 0187 //! Filters out the values and leaves the most optimal one. 0188 void FilterPoints(FilletPoint*); 0189 0190 //! Returns a pointer to created copy of the point 0191 //! warning: this is not the full copy! Copies only: myParam, myV, myD, myValid 0192 FilletPoint* Copy(); 0193 0194 //! Returns the index of the solution or zero if there is no solution 0195 Standard_Integer hasSolution(Standard_Real theRadius); 0196 0197 //! For debug only 0198 Standard_Real LowerValue() 0199 { 0200 Standard_Integer a, aResultIndex = 0; 0201 Standard_Real aValue; 0202 for(a = myV.Length(); a > 0; a--) 0203 { 0204 if (aResultIndex == 0 || Abs(aValue) > Abs(myV.Value(a))) 0205 { 0206 aResultIndex = a; 0207 aValue = myV.Value(a); 0208 } 0209 } 0210 return aValue; 0211 } 0212 //! Removes the found value by the given index. 0213 void remove(Standard_Integer theIndex); 0214 0215 private: 0216 //! Parameter on the first curve (start fillet point). 0217 Standard_Real myParam; 0218 //! Parameter on the second curve (end fillet point). 0219 Standard_Real myParam2; 0220 //! Values and derivative values of the fillet function. 0221 //! May be several if there are many projections on the second curve. 0222 TColStd_SequenceOfReal myV, myD; 0223 //! Center of the fillet arc. 0224 gp_Pnt2d myCenter; 0225 //! Flags for storage the validity of solutions. Indexes corresponds to indexes 0226 //! in sequences myV, myD. 0227 TColStd_SequenceOfBoolean myValid; 0228 TColStd_SequenceOfInteger myNear; 0229 }; 0230 0231 #endif // _FILLETALGO_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |