1 -- Created on: 1998-06-03
2 -- Created by: data exchange team
3 -- Copyright (c) 1998-1999 Matra Datavision
4 -- Copyright (c) 1999-2014 OPEN CASCADE SAS
6 -- This file is part of Open CASCADE Technology software library.
8 -- This library is free software; you can redistribute it and/or modify it under
9 -- the terms of the GNU Lesser General Public License version 2.1 as published
10 -- by the Free Software Foundation, with special exception defined in the file
11 -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 -- distribution for complete text of the license and disclaimer of any warranty.
14 -- Alternatively, this file may be used under the terms of Open CASCADE
15 -- commercial license or contractual agreement.
17 class Surface from ShapeAnalysis inherits TShared from MMgt
19 ---Purpose: Complements standard tool Geom_Surface by providing additional
20 -- functionality for detection surface singularities, checking
21 -- spatial surface closure and computing projections of 3D points
24 -- * The singularities
25 -- Each singularity stores the precision with which corresponding
26 -- surface iso-line is considered as degenerated.
27 -- The number of singularities is determined by specifying precision
28 -- and always not greater than 4.
30 -- * The spatial closure
31 -- The check for spatial closure is performed with given precision
32 -- (default value is Precision::Confusion).
33 -- If Geom_Surface says that the surface is closed, this class
34 -- also says this. Otherwise additional analysis is performed.
36 -- * The parameters of 3D point on the surface
37 -- The projection of the point is performed with given precision.
38 -- This class tries to find a solution taking into account possible
40 -- Additional method for searching the solution from already built
41 -- one is also provided.
43 -- This tool is optimised: computes most information only once
51 Surface from GeomAdaptor,
52 HSurface from GeomAdaptor,
54 Array1OfPnt from TColgp,
55 Array1OfPnt2d from TColgp
58 Create (S : Surface from Geom) returns Surface from ShapeAnalysis;
59 ---Purpose: Creates an analyzer object on the basis of existing surface
61 Init (me : mutable; S: Surface from Geom);
62 ---Purpose: Loads existing surface
64 Init (me : mutable; other: Surface from ShapeAnalysis);
65 ---Purpose: Reads all the data from another Surface, without recomputing
67 SetDomain(me : mutable; U1, U2, V1, V2 : Real);
69 Surface (me) returns Surface from Geom;
70 ---C++: return const &
72 ---Purpose: Returns a surface being analyzed
74 Adaptor3d (me : mutable) returns HSurface from GeomAdaptor;
75 ---C++: return const &
76 ---Purpose: Returns the Adaptor.
77 -- Creates it if not yet done.
79 TrueAdaptor3d (me) returns HSurface from GeomAdaptor;
80 ---C++: return const &
82 ---Purpose: Returns the Adaptor (may be Null if method Adaptor() was not called)
84 Gap (me) returns Real;
86 ---Purpose: Returns 3D distance found by one of the following methods.
87 -- IsDegenerated, DegeneratedValues, ProjectDegenerated
88 -- (distance between 3D point and found or last (if not found)
90 -- IsUClosed, IsVClosed (minimum value of precision to consider
91 -- the surface to be closed),
92 -- ValueOfUV (distance between 3D point and found solution).
94 Value (me : mutable; u,v : Real) returns Pnt from gp;
96 ---Purpose: Returns a 3D point specified by parameters in surface
99 Value (me : mutable; p2d : Pnt2d from gp) returns Pnt from gp;
101 ---Purpose: Returns a 3d point specified by a point in surface
102 -- parametrical space
104 ComputeSingularities (me: mutable) is private;
105 ---Purpose: Computes singularities on the surface.
106 -- Computes the sizes of boundaries or singular ares of the
107 -- surface. Then each boundary or area is considered as
108 -- degenerated with precision not less than its size.
110 -- The singularities and corresponding precisions are the
112 -- - ConicalSurface - one degenerated point (apex of the cone),
114 -- - ToroidalSurface - two degenerated points, precision is
115 -- Max (0, majorR-minorR),
116 -- - SphericalSurface - two degenerated points (poles),
118 -- - Bounded, Surface Of Revolution, Offset - four degenerated
119 -- points, precisions are maximum distance between corners
120 -- and middle point on the boundary
122 ---Remark: Considers only boundaries of the surface (i.e. does not detect
123 -- singularity if it is inside parametrical space)
125 HasSingularities (me: mutable; preci: Real) returns Boolean;
126 ---Purpose: Returns True if the surface has singularities for the given
127 -- precision (i.e. if there are surface singularities with sizes
128 -- not greater than precision).
130 NbSingularities (me: mutable; preci: Real) returns Integer;
131 ---Purpose: Returns the number of singularities for the given precision
132 -- (i.e. number of surface singularities with sizes not greater
135 Singularity (me: mutable; num : Integer;
137 P3d : out Pnt from gp;
138 firstP2d, lastP2d: out Pnt2d from gp;
139 firstpar, lastpar: out Real;
140 uisodeg : out Boolean)
142 ---Purpose: Returns the characteristics of the singularity specified by
143 -- its rank number <num>.
144 -- That means, that it is not neccessary for <num> to be in the
145 -- range [1, NbSingularities] but must be not greater than
146 -- possible (see ComputeSingularities).
147 -- The returned characteristics are:
148 -- preci: the smallest precision with which the iso-line is
149 -- considered as degenerated,
150 -- P3d: 3D point of singularity (middle point of the surface
152 -- firstP2d and lastP2d: first and last 2D points of the
153 -- iso-line in parametrical surface,
154 -- firstpar and lastpar: first and last parameters of the
155 -- iso-line in parametrical surface,
156 -- uisodeg: if the degenerated iso-line is U-iso (True) or
158 -- Returns False if <num> is out of range, else returns True.
159 ---Remarks - all the singularities are sorted in ascending order by
161 -- - firstP2d and lastP2d are such to define left-hand passing of
162 -- parametrical space
164 IsDegenerated (me: mutable; P3d : Pnt from gp;
167 ---Purpose: Returns True if there is at least one surface boundary which
168 -- is considered as degenerated with <preci> and distance
169 -- between P3d and corresponding singular point is less than
172 DegeneratedValues (me: mutable; P3d : Pnt from gp;
174 firstP2d, lastP2d: out Pnt2d from gp;
175 firstpar, lastpar: out Real;
176 forward : Boolean = Standard_True)
178 ---Purpose: Returns True if there is at least one surface iso-line which
179 -- is considered as degenerated with <preci> and distance
180 -- between P3d and corresponding singular point is less than
181 -- <preci> (like IsDegenerated).
182 -- Returns characteristics of the first found boundary matching
184 ---Remark : <forward> is not used
186 ProjectDegenerated (me: mutable; P3d : Pnt from gp;
188 neighbour: Pnt2d from gp;
189 result : in out Pnt2d from gp)
191 ---Purpose: Projects a point <P3d> on a singularity by computing
192 -- one of the coordinates of preliminary computed <result>.
194 -- Finds the iso-line which is considered as degenerated with
196 -- a. distance between P3d and corresponding singular point is
197 -- less than <preci> (like IsDegenerated) or
198 -- b. difference between already computed <result>'s coordinate
199 -- and iso-coordinate of the boundary is less than 2D
200 -- resolution (computed from <preci> by Geom_Adaptor).
201 -- Then sets not yet computed <result>'s coordinate taking it
202 -- from <neighbour> and returns True.
203 ---Example: U-iso at Ufirst=0 is degenerated with 1e-03,
204 -- <neighbour> = (0, 0.5),
205 -- <result> = (1e-06, ?); (1e-06 - already computed, ? - not yet)
206 -- After, <result> will be (1e-06, 0.5): 0.5 is taken from <neighbour>
208 ---Remark : This is only one method to compute the coordinate taking it
209 -- from neighbour point. Other methods are also possible (by
210 -- using tangent or C2, etc).
212 -- If the P3d is not on a singularity, no computation is done,
213 -- returns False and <result> remains unchanged
215 ProjectDegenerated (me: mutable; nbrPnt: Integer;
216 points: Array1OfPnt from TColgp;
217 pnt2d : in out Array1OfPnt2d from TColgp;
221 ---Purpose: Checks points at the beginning (direct is True) or end
222 -- (direct is False) of array <points> to lie in singularity of
223 -- surface, and if yes, adjusts the indeterminate 2d coordinate
224 -- of these points by nearest point which is not in singularity.
225 -- Returns True if some points were adjusted.
227 IsDegenerated (me: mutable; p2d1, p2d2: Pnt2d from gp; tol, ratio: Real)
229 ---Purpose: Returns True if straight pcurve going from point p2d1 to p2d2
230 -- is degenerate, i.e. lies in the singularity of the surface.
231 -- NOTE: it uses another method of detecting singularity than
232 -- used by ComputeSingularities() et al.!
233 -- For that, maximums of distances between points p2d1, p2d2
234 -- and 0.5*(p2d1+p2d2) and between corresponding 3d points are
236 -- The pcurve (p2d1, p2d2) is considered as degenerate if:
237 -- - max distance in 3d is less than <tol>
238 -- - max distance in 2d is at least <ratio> times greather than
239 -- the Resolution computed from max distance in 3d
240 -- (max3d < tol && max2d > ratio * Resolution(max3d))
241 -- NOTE: <ratio> should be >1 (e.g. 10)
243 Bounds (me; ufirst, ulast, vfirst, vlast: out Real);
245 ---Purpose: Returns the bounds of the surface
246 -- (from Bounds from Surface, but buffered)
248 ComputeBoundIsos(me : mutable);
249 ---Purpose: Computes bound isos (protected against exceptions)
251 UIso (me: mutable; U: Real) returns Curve from Geom;
252 ---Purpose: Returns a U-Iso. Null if not possible or failed
253 -- Remark : bound isos are buffered
255 VIso (me: mutable; V: Real) returns Curve from Geom;
256 ---Purpose: Returns a V-Iso. Null if not possible or failed
257 -- Remark : bound isos are buffered
259 IsUClosed (me: mutable; preci: Real = -1) returns Boolean;
260 ---Purpose: Tells if the Surface is spatially closed in U with given
261 -- precision. If <preci> < 0 then Precision::Confusion is used.
262 -- If Geom_Surface says that the surface is U-closed, this method
263 -- also says this. Otherwise additional analysis is performed,
264 -- comparing given precision with the following distances:
265 -- - periodic B-Splines are closed,
266 -- - polinomial B-Spline with boundary multiplicities degree+1
267 -- and Bezier - maximum distance between poles,
268 -- - rational B-Spline or one with boundary multiplicities not
269 -- degree+1 - maximum distance computed at knots and their
271 -- - surface of extrusion - distance between ends of basis
273 -- - other (RectangularTrimmed and Offset) - maximum distance
274 -- computed at 100 equi-distanted points.
276 IsVClosed (me: mutable; preci: Real = -1) returns Boolean;
277 ---Purpose: Tells if the Surface is spatially closed in V with given
278 -- precision. If <preci> < 0 then Precision::Confusion is used.
279 -- If Geom_Surface says that the surface is V-closed, this method
280 -- also says this. Otherwise additional analysis is performed,
281 -- comparing given precision with the following distances:
282 -- - periodic B-Splines are closed,
283 -- - polinomial B-Spline with boundary multiplicities degree+1
284 -- and Bezier - maximum distance between poles,
285 -- - rational B-Spline or one with boundary multiplicities not
286 -- degree+1 - maximum distance computed at knots and their
288 -- - surface of revolution - distance between ends of basis
290 -- - other (RectangularTrimmed and Offset) - maximum distance
291 -- computed at 100 equi-distanted points.
293 ValueOfUV (me: mutable; P3D: Pnt from gp;
295 returns Pnt2d from gp;
296 ---Purpose: Computes the parameters in the surface parametrical space of
298 -- The result is parameters of the point projected onto the
300 -- This method enhances functionality provided by the standard
301 -- tool GeomAPI_ProjectPointOnSurface by treatment of cases when
302 -- the projected point is near to the surface boundaries and
303 -- when this standard tool fails.
305 NextValueOfUV (me: mutable; p2dPrev: Pnt2d from gp;
308 maxpreci:Real = -1.0)
309 returns Pnt2d from gp;
310 ---Purpose: Projects a point P3D on the surface.
311 -- Does the same thing as ValueOfUV but tries to optimize
312 -- computations by taking into account previous point <p2dPrev>:
313 -- makes a step by UV and tries Newton algorithm.
314 -- If <maxpreci> >0. and distance between solution and
315 -- P3D is greater than <maxpreci>, that solution is considered
316 -- as bad, and ValueOfUV() is used.
317 -- If not succeded, calls ValueOfUV()
319 UVFromIso (me: mutable; P3D : Pnt from gp;
323 ---Purpose: Tries a refinement of an already computed couple (U,V) by
324 -- using projecting 3D point on iso-lines:
325 -- 1. boundaries of the surface,
326 -- 2. iso-lines passing through (U,V)
327 -- 3. iteratively received iso-lines passing through new U and
328 -- new V (number of iterations is limited by 5 in each
330 -- Returns the best resulting distance between P3D and Value(U,V)
331 -- in the case of success. Else, returns a very great value
333 UCloseVal (me) returns Real;
335 ---Purpose: Returns minimum value to consider the surface as U-closed
337 VCloseVal (me) returns Real;
339 ---Purpose: Returns minimum value to consider the surface as V-closed
341 GetBoxUF(me: mutable) returns Box from Bnd;
342 ---C++: return const&
344 GetBoxUL(me: mutable) returns Box from Bnd;
345 ---C++: return const&
347 GetBoxVF(me: mutable) returns Box from Bnd;
348 ---C++: return const&
350 GetBoxVL(me: mutable) returns Box from Bnd;
351 ---C++: return const&
353 ComputeBoxes(me: mutable) is private;
355 SurfaceNewton (me: mutable; p2dPrev: Pnt2d from gp;
358 sol :in out Pnt2d from gp)
359 returns Boolean is private;
361 SortSingularities (me: mutable) is private;
365 mySurf : Surface from Geom is protected;
366 myAdSur : HSurface from GeomAdaptor is protected;
368 myExtPS : ExtPS from Extrema is protected; -- speed optimization
369 myExtSrf : Surface from GeomAdaptor is protected; -- for extrema
370 myExtOK : Boolean is protected; -- is theExtPS initialized?
372 myNbDeg : Integer is protected; -- < 0 means not yet computed
373 myPreci : Real [4] is protected;
374 myP3d : Pnt from gp [4] is protected;
375 myFirstP2d : Pnt2d from gp [4] is protected;
376 myLastP2d : Pnt2d from gp [4] is protected;
377 myFirstPar : Real [4] is protected;
378 myLastPar : Real [4] is protected;
379 myUIsoDeg : Boolean [4] is protected; -- True if U-iso is degenerated, False if V-iso
381 myIsos : Boolean is protected; -- are bound isos computed
382 myUF : Real is protected;
383 myUL : Real is protected;
384 myVF : Real is protected;
385 myVL : Real is protected;
386 myIsoUF : Curve from Geom is protected;
387 myIsoUL : Curve from Geom is protected;
388 myIsoVF : Curve from Geom is protected;
389 myIsoVL : Curve from Geom is protected;
390 myIsoBoxes : Boolean is protected; -- are boxes for bound isos computed
391 myBndUF : Box from Bnd is protected;
392 myBndUL : Box from Bnd is protected;
393 myBndVF : Box from Bnd is protected;
394 myBndVL : Box from Bnd is protected;
396 myGap : Real is protected;
397 myUDelt : Real is protected; -- what overparametrisation to have good ValueOfUV
398 myVDelt : Real is protected;
400 myUCloseVal: Real is protected; -- minimum value to consider the surface as U-closed
401 myVCloseVal: Real is protected; -- minimum value to consider the surface as V-closed