|
||||
File indexing completed on 2025-01-18 10:04:39
0001 // Created on: 1993-02-17 0002 // Created by: Remi LEQUETTE 0003 // Copyright (c) 1993-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Precision_HeaderFile 0018 #define _Precision_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Real.hxx> 0023 0024 //! The Precision package offers a set of functions defining precision criteria 0025 //! for use in conventional situations when comparing two numbers. 0026 //! Generalities 0027 //! It is not advisable to use floating number equality. Instead, the difference 0028 //! between numbers must be compared with a given precision, i.e. : 0029 //! Standard_Real x1, x2 ; 0030 //! x1 = ... 0031 //! x2 = ... 0032 //! If ( x1 == x2 ) ... 0033 //! should not be used and must be written as indicated below: 0034 //! Standard_Real x1, x2 ; 0035 //! Standard_Real Precision = ... 0036 //! x1 = ... 0037 //! x2 = ... 0038 //! If ( Abs ( x1 - x2 ) < Precision ) ... 0039 //! Likewise, when ordering floating numbers, you must take the following into account : 0040 //! Standard_Real x1, x2 ; 0041 //! Standard_Real Precision = ... 0042 //! x1 = ... ! a large number 0043 //! x2 = ... ! another large number 0044 //! If ( x1 < x2 - Precision ) ... 0045 //! is incorrect when x1 and x2 are large numbers ; it is better to write : 0046 //! Standard_Real x1, x2 ; 0047 //! Standard_Real Precision = ... 0048 //! x1 = ... ! a large number 0049 //! x2 = ... ! another large number 0050 //! If ( x2 - x1 > Precision ) ... 0051 //! Precision in Cas.Cade 0052 //! Generally speaking, the precision criterion is not implicit in Cas.Cade. Low-level geometric algorithms accept 0053 //! precision criteria as arguments. As a rule, they should not refer directly to the precision criteria provided by the 0054 //! Precision package. 0055 //! On the other hand, high-level modeling algorithms have to provide the low-level geometric algorithms that they 0056 //! call, with a precision criteria. One way of doing this is to use the above precision criteria. 0057 //! Alternatively, the high-level algorithms can have their own system for precision management. For example, the 0058 //! Topology Data Structure stores precision criteria for each elementary shape (as a vertex, an edge or a face). When 0059 //! a new topological object is constructed, the precision criteria are taken from those provided by the Precision 0060 //! package, and stored in the related data structure. Later, a topological algorithm which analyses these objects will 0061 //! work with the values stored in the data structure. Also, if this algorithm is to build a new topological object, from 0062 //! these precision criteria, it will compute a new precision criterion for the new topological object, and write it into the 0063 //! data structure of the new topological object. 0064 //! The different precision criteria offered by the Precision package, cover the most common requirements of 0065 //! geometric algorithms, such as intersections, approximations, and so on. 0066 //! The choice of precision depends on the algorithm and on the geometric space. The geometric space may be : 0067 //! - a "real" 2D or 3D space, where the lengths are measured in meters, millimeters, microns, inches, etc ..., or 0068 //! - a "parametric" space, 1D on a curve or 2D on a surface, where lengths have no dimension. 0069 //! The choice of precision criteria for real space depends on the choice of the product, as it is based on the accuracy 0070 //! of the machine and the unit of measurement. 0071 //! The choice of precision criteria for parametric space depends on both the accuracy of the machine and the 0072 //! dimensions of the curve or the surface, since the parametric precision criterion and the real precision criterion are 0073 //! linked : if the curve is defined by the equation P(t), the inequation : 0074 //! Abs ( t2 - t1 ) < ParametricPrecision 0075 //! means that the parameters t1 and t2 are considered to be equal, and the inequation : 0076 //! Distance ( P(t2) , P(t1) ) < RealPrecision 0077 //! means that the points P(t1) and P(t2) are considered to be coincident. It seems to be the same idea, and it 0078 //! would be wonderful if these two inequations were equivalent. Note that this is rarely the case ! 0079 //! What is provided in this package? 0080 //! The Precision package provides : 0081 //! - a set of real space precision criteria for the algorithms, in view of checking distances and angles, 0082 //! - a set of parametric space precision criteria for the algorithms, in view of checking both : 0083 //! - the equality of parameters in a parametric space, 0084 //! - or the coincidence of points in the real space, by using parameter values, 0085 //! - the notion of infinite value, composed of a value assumed to be infinite, and checking tests designed to verify 0086 //! if any value could be considered as infinite. 0087 //! All the provided functions are very simple. The returned values result from the adaptation of the applications 0088 //! developed by the Open CASCADE company to Open CASCADE algorithms. The main interest of these functions 0089 //! lies in that it incites engineers developing applications to ask questions on precision factors. Which one is to be 0090 //! used in such or such case ? Tolerance criteria are context dependent. They must first choose : 0091 //! - either to work in real space, 0092 //! - or to work in parametric space, 0093 //! - or to work in a combined real and parametric space. 0094 //! They must next decide which precision factor will give the best answer to the current problem. Within an application 0095 //! environment, it is crucial to master precision even though this process may take a great deal of time. 0096 class Precision 0097 { 0098 public: 0099 0100 DEFINE_STANDARD_ALLOC 0101 0102 //! Returns the recommended precision value 0103 //! when checking the equality of two angles (given in radians). 0104 //! Standard_Real Angle1 = ... , Angle2 = ... ; 0105 //! If ( Abs( Angle2 - Angle1 ) < Precision::Angular() ) ... 0106 //! The tolerance of angular equality may be used to check the parallelism of two vectors : 0107 //! gp_Vec V1, V2 ; 0108 //! V1 = ... 0109 //! V2 = ... 0110 //! If ( V1.IsParallel (V2, Precision::Angular() ) ) ... 0111 //! The tolerance of angular equality is equal to 1.e-12. 0112 //! Note : The tolerance of angular equality can be used when working with scalar products or 0113 //! cross products since sines and angles are equivalent for small angles. Therefore, in order to 0114 //! check whether two unit vectors are perpendicular : 0115 //! gp_Dir D1, D2 ; 0116 //! D1 = ... 0117 //! D2 = ... 0118 //! you can use : 0119 //! If ( Abs( D1.D2 ) < Precision::Angular() ) ... 0120 //! (although the function IsNormal does exist). 0121 static Standard_Real Angular() { return 1.e-12; } 0122 0123 //! Returns the recommended precision value when 0124 //! checking coincidence of two points in real space. 0125 //! The tolerance of confusion is used for testing a 3D 0126 //! distance : 0127 //! - Two points are considered to be coincident if their 0128 //! distance is smaller than the tolerance of confusion. 0129 //! gp_Pnt P1, P2 ; 0130 //! P1 = ... 0131 //! P2 = ... 0132 //! if ( P1.IsEqual ( P2 , Precision::Confusion() ) ) 0133 //! then ... 0134 //! - A vector is considered to be null if it has a null length : 0135 //! gp_Vec V ; 0136 //! V = ... 0137 //! if ( V.Magnitude() < Precision::Confusion() ) then ... 0138 //! The tolerance of confusion is equal to 1.e-7. 0139 //! The value of the tolerance of confusion is also used to 0140 //! define : 0141 //! - the tolerance of intersection, and 0142 //! - the tolerance of approximation. 0143 //! Note : As a rule, coordinate values in Cas.Cade are not 0144 //! dimensioned, so 1. represents one user unit, whatever 0145 //! value the unit may have : the millimeter, the meter, the 0146 //! inch, or any other unit. Let's say that Cas.Cade 0147 //! algorithms are written to be tuned essentially with 0148 //! mechanical design applications, on the basis of the 0149 //! millimeter. However, these algorithms may be used with 0150 //! any other unit but the tolerance criterion does no longer 0151 //! have the same signification. 0152 //! So pay particular attention to the type of your application, 0153 //! in relation with the impact of your unit on the precision criterion. 0154 //! - For example in mechanical design, if the unit is the 0155 //! millimeter, the tolerance of confusion corresponds to a 0156 //! distance of 1 / 10000 micron, which is rather difficult to measure. 0157 //! - However in other types of applications, such as 0158 //! cartography, where the kilometer is frequently used, 0159 //! the tolerance of confusion corresponds to a greater 0160 //! distance (1 / 10 millimeter). This distance 0161 //! becomes easily measurable, but only within a restricted 0162 //! space which contains some small objects of the complete scene. 0163 static Standard_Real Confusion() { return 1.e-7; } 0164 0165 //! Returns square of Confusion. 0166 //! Created for speed and convenience. 0167 static Standard_Real SquareConfusion() { return Confusion() * Confusion(); } 0168 0169 //! Returns the precision value in real space, frequently 0170 //! used by intersection algorithms to decide that a solution is reached. 0171 //! This function provides an acceptable level of precision 0172 //! for an intersection process to define the adjustment limits. 0173 //! The tolerance of intersection is designed to ensure 0174 //! that a point computed by an iterative algorithm as the 0175 //! intersection between two curves is indeed on the 0176 //! intersection. It is obvious that two tangent curves are 0177 //! close to each other, on a large distance. An iterative 0178 //! algorithm of intersection may find points on these 0179 //! curves within the scope of the confusion tolerance, but 0180 //! still far from the true intersection point. In order to force 0181 //! the intersection algorithm to continue the iteration 0182 //! process until a correct point is found on the tangent 0183 //! objects, the tolerance of intersection must be smaller 0184 //! than the tolerance of confusion. 0185 //! On the other hand, the tolerance of intersection must 0186 //! be large enough to minimize the time required by the 0187 //! process to converge to a solution. 0188 //! The tolerance of intersection is equal to : 0189 //! Precision::Confusion() / 100. 0190 //! (that is, 1.e-9). 0191 static Standard_Real Intersection() { return Confusion() * 0.01; } 0192 0193 //! Returns the precision value in real space, frequently used 0194 //! by approximation algorithms. 0195 //! This function provides an acceptable level of precision for 0196 //! an approximation process to define adjustment limits. 0197 //! The tolerance of approximation is designed to ensure 0198 //! an acceptable computation time when performing an 0199 //! approximation process. That is why the tolerance of 0200 //! approximation is greater than the tolerance of confusion. 0201 //! The tolerance of approximation is equal to : 0202 //! Precision::Confusion() * 10. 0203 //! (that is, 1.e-6). 0204 //! You may use a smaller tolerance in an approximation 0205 //! algorithm, but this option might be costly. 0206 static Standard_Real Approximation() { return Confusion() * 10.0; } 0207 0208 //! Convert a real space precision to a parametric 0209 //! space precision. <T> is the mean value of the 0210 //! length of the tangent of the curve or the surface. 0211 //! 0212 //! Value is P / T 0213 static Standard_Real Parametric (const Standard_Real P, const Standard_Real T) { return P / T; } 0214 0215 //! Returns a precision value in parametric space, which may be used : 0216 //! - to test the coincidence of two points in the real space, 0217 //! by using parameter values, or 0218 //! - to test the equality of two parameter values in a parametric space. 0219 //! The parametric tolerance of confusion is designed to 0220 //! give a mean value in relation with the dimension of 0221 //! the curve or the surface. It considers that a variation of 0222 //! parameter equal to 1. along a curve (or an 0223 //! isoparametric curve of a surface) generates a segment 0224 //! whose length is equal to 100. (default value), or T. 0225 //! The parametric tolerance of confusion is equal to : 0226 //! - Precision::Confusion() / 100., or Precision::Confusion() / T. 0227 //! The value of the parametric tolerance of confusion is also used to define : 0228 //! - the parametric tolerance of intersection, and 0229 //! - the parametric tolerance of approximation. 0230 //! Warning 0231 //! It is rather difficult to define a unique precision value in parametric space. 0232 //! - First consider a curve (c) ; if M is the point of 0233 //! parameter u and M' the point of parameter u+du on 0234 //! the curve, call 'parametric tangent' at point M, for the 0235 //! variation du of the parameter, the quantity : 0236 //! T(u,du)=MM'/du (where MM' represents the 0237 //! distance between the two points M and M', in the real space). 0238 //! - Consider the other curve resulting from a scaling 0239 //! transformation of (c) with a scale factor equal to 0240 //! 10. The 'parametric tangent' at the point of 0241 //! parameter u of this curve is ten times greater than the 0242 //! previous one. This shows that for two different curves, 0243 //! the distance between two points on the curve, resulting 0244 //! from the same variation of parameter du, may vary considerably. 0245 //! - Moreover, the variation of the parameter along the 0246 //! curve is generally not proportional to the curvilinear 0247 //! abscissa along the curve. So the distance between two 0248 //! points resulting from the same variation of parameter 0249 //! du, at two different points of a curve, may completely differ. 0250 //! - Moreover, the parameterization of a surface may 0251 //! generate two quite different 'parametric tangent' values 0252 //! in the u or in the v parametric direction. 0253 //! - Last, close to the poles of a sphere (the points which 0254 //! correspond to the values -Pi/2. and Pi/2. of the 0255 //! v parameter) the u parameter may change from 0 to 0256 //! 2.Pi without impacting on the resulting point. 0257 //! Therefore, take great care when adjusting a parametric 0258 //! tolerance to your own algorithm. 0259 static Standard_Real PConfusion (const Standard_Real T) { return Parametric (Confusion(), T); } 0260 0261 //! Returns square of PConfusion. 0262 //! Created for speed and convenience. 0263 static Standard_Real SquarePConfusion() { return PConfusion() * PConfusion(); } 0264 0265 //! Returns a precision value in parametric space, which 0266 //! may be used by intersection algorithms, to decide that 0267 //! a solution is reached. The purpose of this function is to 0268 //! provide an acceptable level of precision in parametric 0269 //! space, for an intersection process to define the adjustment limits. 0270 //! The parametric tolerance of intersection is 0271 //! designed to give a mean value in relation with the 0272 //! dimension of the curve or the surface. It considers 0273 //! that a variation of parameter equal to 1. along a curve 0274 //! (or an isoparametric curve of a surface) generates a 0275 //! segment whose length is equal to 100. (default value), or T. 0276 //! The parametric tolerance of intersection is equal to : 0277 //! - Precision::Intersection() / 100., or Precision::Intersection() / T. 0278 static Standard_Real PIntersection (const Standard_Real T) { return Parametric(Intersection(),T); } 0279 0280 //! Returns a precision value in parametric space, which may 0281 //! be used by approximation algorithms. The purpose of this 0282 //! function is to provide an acceptable level of precision in 0283 //! parametric space, for an approximation process to define 0284 //! the adjustment limits. 0285 //! The parametric tolerance of approximation is 0286 //! designed to give a mean value in relation with the 0287 //! dimension of the curve or the surface. It considers 0288 //! that a variation of parameter equal to 1. along a curve 0289 //! (or an isoparametric curve of a surface) generates a 0290 //! segment whose length is equal to 100. (default value), or T. 0291 //! The parametric tolerance of intersection is equal to : 0292 //! - Precision::Approximation() / 100., or Precision::Approximation() / T. 0293 static Standard_Real PApproximation (const Standard_Real T) { return Parametric(Approximation(),T); } 0294 0295 //! Convert a real space precision to a parametric 0296 //! space precision on a default curve. 0297 //! 0298 //! Value is Parametric(P,1.e+2) 0299 static Standard_Real Parametric (const Standard_Real P) { return Parametric (P, 100.0); } 0300 0301 //! Used to test distances in parametric space on a 0302 //! default curve. 0303 //! 0304 //! This is Precision::Parametric(Precision::Confusion()) 0305 static Standard_Real PConfusion() { return Parametric (Confusion()); } 0306 0307 //! Used for Intersections in parametric space on a 0308 //! default curve. 0309 //! 0310 //! This is Precision::Parametric(Precision::Intersection()) 0311 static Standard_Real PIntersection() { return Parametric (Intersection()); } 0312 0313 //! Used for Approximations in parametric space on a 0314 //! default curve. 0315 //! 0316 //! This is Precision::Parametric(Precision::Approximation()) 0317 static Standard_Real PApproximation() { return Parametric (Approximation()); } 0318 0319 //! Returns True if R may be considered as an infinite 0320 //! number. Currently Abs(R) > 1e100 0321 static Standard_Boolean IsInfinite (const Standard_Real R) { return Abs (R) >= (0.5 * Precision::Infinite()); } 0322 0323 //! Returns True if R may be considered as a positive 0324 //! infinite number. Currently R > 1e100 0325 static Standard_Boolean IsPositiveInfinite (const Standard_Real R) { return R >= (0.5 * Precision::Infinite()); } 0326 0327 //! Returns True if R may be considered as a negative 0328 //! infinite number. Currently R < -1e100 0329 static Standard_Boolean IsNegativeInfinite (const Standard_Real R) { return R <= -(0.5 * Precision::Infinite()); } 0330 0331 //! Returns a big number that can be considered as 0332 //! infinite. Use -Infinite() for a negative big number. 0333 static Standard_Real Infinite() { return 2.e+100; } 0334 0335 }; 0336 0337 #endif // _Precision_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |