Point Cloud Library (PCL)  1.9.1-dev
opennurbs_revsurface.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_REVSURFACE_INC_)
18 #define OPENNURBS_REVSURFACE_INC_
19 
20 // surface of revolution
21 class ON_CLASS ON_RevSurface : public ON_Surface
22 {
23  ON_OBJECT_DECLARE(ON_RevSurface);
24 
25 public:
26  // virtual ON_Object::DestroyRuntimeCache override
27  void DestroyRuntimeCache( bool bDelete = true );
28 
29 public:
30  // Revolute curve.
31  // If m_curve is not NULL, then ~ON_RevSurface() deletes m_curve.
33 
34  // Axis of revolution.
36 
37  // Start and end angles of revolution in radians.
38  // The interval m_angle must be increasing and satisfiy
39  // ON_ZERO_TOLERANCE < m_angle.Length() <= 2.0*ON_PI
41 
42  // The interval m_t specifies the parameterization for the
43  // angular parameter; m_t must be an increasing interval.
44  // The parameter m_t[0] corresonds to angle m_angle[0] and
45  // the parameter m_t[1] corresponds to angle m_angle[1].
46  // Changing m_t and leaving m_angle unchanged will change the
47  // parameterization but not change the locus of the surface.
48  // Changing m_angle and leaving m_t unchanged, will change the
49  // locus of the surface but not change the evaluation domain.
51 
52  // If false, the "u" parameter is the angle parameter
53  // and the "v" parameter is the curve parameter.
54  // If true, the "u" parameter is the curve parameter
55  // and the "v" parameter is the angle parameter.
56  ON_BOOL32 m_bTransposed;
57 
58  // Bounding box of the surface of revolution.
60 
61  /*
62  Description:
63  Use ON_RevSurface::New(...) instead of new ON_RevSurface(...)
64  Returns:
65  Pointer to an ON_RevSurface. Destroy by calling delete.
66  Remarks:
67  See static ON_Brep* ON_Brep::New() for details.
68  */
69  static ON_RevSurface* New();
70  static ON_RevSurface* New( const ON_RevSurface& rev_surface );
71 
72 
73  ON_RevSurface();
74  ~ON_RevSurface();
75  ON_RevSurface( const ON_RevSurface& );
77 
78  void Destroy();
79 
80  ON_BOOL32 SetAngleRadians(
81  double start_angle_radians,
82  double end_angle_radians
83  );
84 
85  ON_BOOL32 SetAngleDegrees(
86  double start_angle_degrees,
87  double end_angle_degrees
88  );
89 
90  ////////////////////////////////////////////////////////////
91  //
92  // overrides of virtual ON_Object functions
93  //
94 
95  // virtual ON_Object::SizeOf override
96  unsigned int SizeOf() const;
97 
98  // virtual ON_Object::DataCRC override
99  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
100 
101  /*
102  Description:
103  Tests an object to see if its data members are correctly
104  initialized.
105  Parameters:
106  text_log - [in] if the object is not valid and text_log
107  is not NULL, then a brief englis description of the
108  reason the object is not valid is appened to the log.
109  The information appended to text_log is suitable for
110  low-level debugging purposes by programmers and is
111  not intended to be useful as a high level user
112  interface tool.
113  Returns:
114  @untitled table
115  true object is valid
116  false object is invalid, uninitialized, etc.
117  Remarks:
118  Overrides virtual ON_Object::IsValid
119  */
120  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
121 
122  void Dump( ON_TextLog& ) const; // for debugging
123 
124  // Use ON_BinaryArchive::WriteObject() and ON_BinaryArchive::ReadObject()
125  // for top level serialization. These Read()/Write() members should just
126  // write/read specific definitions. In particular, they should not write/
127  // read any chunk typecode or length information. The default
128  // implementations return false and do nothing.
129  ON_BOOL32 Write(
130  ON_BinaryArchive& // serialize definition to binary archive
131  ) const;
132 
133  ON_BOOL32 Read(
134  ON_BinaryArchive& // restore definition from binary archive
135  );
136 
137  ////////////////////////////////////////////////////////////
138  //
139  // overrides of virtual ON_Geometry functions
140  //
141  int Dimension() const;
142 
143  ON_BOOL32 GetBBox( // returns true if successful
144  double*, // boxmin[dim]
145  double*, // boxmax[dim]
146  ON_BOOL32 = false // true means grow box
147  ) const;
148 
149  void ClearBoundingBox();
150 
151  ON_BOOL32 Transform(
152  const ON_Xform&
153  );
154 
155  ////////////////////////////////////////////////////////////
156  //
157  // overrides of virtual ON_Surface functions
158  //
159 
160  ON_BOOL32 SetDomain(
161  int dir, // 0 sets first parameter's domain, 1 gets second parameter's domain
162  double t0,
163  double t1
164  );
165 
167  int // 0 gets first parameter's domain, 1 gets second parameter's domain
168  ) const;
169 
170  /*
171  Description:
172  Get an estimate of the size of the rectangle that would
173  be created if the 3d surface where flattened into a rectangle.
174  Parameters:
175  width - [out] (corresponds to the first surface parameter)
176  height - [out] (corresponds to the first surface parameter)
177  Remarks:
178  overrides virtual ON_Surface::GetSurfaceSize
179  Returns:
180  true if successful.
181  */
182  ON_BOOL32 GetSurfaceSize(
183  double* width,
184  double* height
185  ) const;
186 
187  int SpanCount(
188  int // 0 gets first parameter's domain, 1 gets second parameter's domain
189  ) const; // number of smooth spans in curve
190 
191  ON_BOOL32 GetSpanVector( // span "knots"
192  int, // 0 gets first parameter's domain, 1 gets second parameter's domain
193  double* // array of length SpanCount() + 1
194  ) const; //
195 
196  int Degree( // returns maximum algebraic degree of any span
197  // ( or a good estimate if curve spans are not algebraic )
198  int // 0 gets first parameter's domain, 1 gets second parameter's domain
199  ) const;
200 
201  ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
202  int, // 0 gets first parameter, 1 gets second parameter
203  double, // t = parameter in domain
204  double*, // tminus
205  double* // tplus
206  ) const;
207 
208  /*
209  Description:
210  Test a surface of revolution to see if it is a portion
211  of a sphere.
212  Parameters:
213  sphere - [out] if not NULL and true is returned,
214  the sphere parameters are filled in.
215  tolerance - [in] tolerance to use when checking
216  Returns:
217  true if the surface of revolution is a portion of a sphere.
218  */
219  ON_BOOL32 IsSpherical(
220  ON_Sphere* sphere = NULL,
221  double tolerance = ON_ZERO_TOLERANCE
222  ) const;
223 
224  /*
225  Description:
226  Test a surface of revolution to see if it is a portion
227  of a cylinder.
228  Parameters:
229  cylinder - [out] if not NULL and true is returned,
230  the cylinder parameters are filled in.
231  tolerance - [in] tolerance to use when checking
232  Returns:
233  true if the surface of revolution is a portion of a cylinder.
234  */
235  ON_BOOL32 IsCylindrical(
236  ON_Cylinder* cylinder = NULL,
237  double tolerance = ON_ZERO_TOLERANCE
238  ) const;
239 
240  /*
241  Description:
242  Test a surface of revolution to see if it is a portion
243  of a cone.
244  Parameters:
245  cone - [out] if not NULL and true is returned,
246  the cone parameters are filled in.
247  tolerance - [in] tolerance to use when checking
248  Returns:
249  true if the surface of revolution is a portion of a cone.
250  */
251  ON_BOOL32 IsConical(
252  ON_Cone* cone = NULL,
253  double tolerance = ON_ZERO_TOLERANCE
254  ) const;
255 
256  /*
257  Description:
258  Test a surface to see if it is planar.
259  Parameters:
260  plane - [out] if not NULL and true is returned,
261  the plane parameters are filled in.
262  tolerance - [in] tolerance to use when checking
263  Returns:
264  true if there is a plane such that the maximum distance from
265  the surface to the plane is <= tolerance.
266  Remarks:
267  Overrides virtual ON_Surface::IsPlanar.
268  */
269  ON_BOOL32 IsPlanar(
270  ON_Plane* plane = NULL,
271  double tolerance = ON_ZERO_TOLERANCE
272  ) const;
273 
274  ON_BOOL32 IsClosed( // true if surface is closed in direction
275  int // dir 0 = "s", 1 = "t"
276  ) const;
277 
278  ON_BOOL32 IsPeriodic( // true if surface is periodic in direction
279  int // dir 0 = "s", 1 = "t"
280  ) const;
281 
282  ON_BOOL32 IsSingular( // true if surface side is collapsed to a point
283  int // side of parameter space to test
284  // 0 = south, 1 = east, 2 = north, 3 = west
285  ) const;
286 
287  /*
288  Description:
289  Search for a derivatitive, tangent, or curvature
290  discontinuity.
291  Parameters:
292  dir - [in] If 0, then "u" parameter is checked. If 1, then
293  the "v" parameter is checked.
294  c - [in] type of continity to test for.
295  t0 - [in] Search begins at t0. If there is a discontinuity
296  at t0, it will be ignored. This makes it
297  possible to repeatedly call GetNextDiscontinuity
298  and step through the discontinuities.
299  t1 - [in] (t0 != t1) If there is a discontinuity at t1 is
300  will be ingored unless c is a locus discontinuity
301  type and t1 is at the start or end of the curve.
302  t - [out] if a discontinuity is found, then *t reports the
303  parameter at the discontinuity.
304  hint - [in/out] if GetNextDiscontinuity will be called
305  repeatedly, passing a "hint" with initial value *hint=0
306  will increase the speed of the search.
307  dtype - [out] if not NULL, *dtype reports the kind of
308  discontinuity found at *t. A value of 1 means the first
309  derivative or unit tangent was discontinuous. A value
310  of 2 means the second derivative or curvature was
311  discontinuous. A value of 0 means teh curve is not
312  closed, a locus discontinuity test was applied, and
313  t1 is at the start of end of the curve.
314  cos_angle_tolerance - [in] default = cos(1 degree) Used only
315  when c is ON::G1_continuous or ON::G2_continuous. If the
316  cosine of the angle between two tangent vectors is
317  <= cos_angle_tolerance, then a G1 discontinuity is reported.
318  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used
319  only when c is ON::G2_continuous. If K0 and K1 are
320  curvatures evaluated from above and below and
321  |K0 - K1| > curvature_tolerance, then a curvature
322  discontinuity is reported.
323  Returns:
324  Parametric continuity tests c = (C0_continuous, ..., G2_continuous):
325 
326  true if a parametric discontinuity was found strictly
327  between t0 and t1. Note well that all curves are
328  parametrically continuous at the ends of their domains.
329 
330  Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous):
331 
332  true if a locus discontinuity was found strictly between
333  t0 and t1 or at t1 is the at the end of a curve.
334  Note well that all open curves (IsClosed()=false) are locus
335  discontinuous at the ends of their domains. All closed
336  curves (IsClosed()=true) are at least C0_locus_continuous at
337  the ends of their domains.
338  */
339  bool GetNextDiscontinuity(
340  int dir,
341  ON::continuity c,
342  double t0,
343  double t1,
344  double* t,
345  int* hint=NULL,
346  int* dtype=NULL,
347  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
348  double curvature_tolerance=ON_SQRT_EPSILON
349  ) const;
350 
351 /*
352  Description:
353  Test continuity at a surface parameter value.
354  Parameters:
355  c - [in] continuity to test for
356  s - [in] surface parameter to test
357  t - [in] surface parameter to test
358  hint - [in] evaluation hint
359  point_tolerance - [in] if the distance between two points is
360  greater than point_tolerance, then the surface is not C0.
361  d1_tolerance - [in] if the difference between two first derivatives is
362  greater than d1_tolerance, then the surface is not C1.
363  d2_tolerance - [in] if the difference between two second derivatives is
364  greater than d2_tolerance, then the surface is not C2.
365  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
366  c is ON::G1_continuous or ON::G2_continuous. If the cosine
367  of the angle between two normal vectors
368  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
369  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
370  c is ON::G2_continuous. If K0 and K1 are curvatures evaluated
371  from above and below and |K0 - K1| > curvature_tolerance,
372  then a curvature discontinuity is reported.
373  Returns:
374  true if the surface has at least the c type continuity at the parameter t.
375  Remarks:
376  Overrides virtual ON_Surface::IsContinuous
377  */
378  bool IsContinuous(
379  ON::continuity c,
380  double s,
381  double t,
382  int* hint = NULL,
383  double point_tolerance=ON_ZERO_TOLERANCE,
384  double d1_tolerance=ON_ZERO_TOLERANCE,
385  double d2_tolerance=ON_ZERO_TOLERANCE,
386  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
387  double curvature_tolerance=ON_SQRT_EPSILON
388  ) const;
389 
390  ON_BOOL32 Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a]
391  int // dir 0 = "s", 1 = "t"
392  );
393 
394  ON_BOOL32 Transpose(); // transpose surface parameterization (swap "s" and "t")
395 
396  ON_BOOL32 Evaluate( // returns false if unable to evaluate
397  double, double, // evaluation parameters (see m_bTransposed)
398  int, // number of derivatives (>=0)
399  int, // array stride (>=Dimension())
400  double*, // array of length stride*(ndir+1)*(ndir+2)/2
401  int = 0, // optional - determines which quadrant to evaluate from
402  // 0 = default
403  // 1 from NE quadrant
404  // 2 from NW quadrant
405  // 3 from SW quadrant
406  // 4 from SE quadrant
407  int* = 0 // optional - evaluation hint (int[2]) used to speed
408  // repeated evaluations
409  ) const;
410 
411  /*
412  Description:
413  Get isoparametric curve.
414  Overrides virtual ON_Surface::IsoCurve.
415  Parameters:
416  dir - [in] 0 first parameter varies and second parameter is constant
417  e.g., point on IsoCurve(0,c) at t is srf(t,c)
418  1 first parameter is constant and second parameter varies
419  e.g., point on IsoCurve(1,c) at t is srf(c,t)
420 
421  c - [in] value of constant parameter
422  Returns:
423  Isoparametric curve.
424  */
426  int dir,
427  double c
428  ) const;
429 
430  /*
431  Description:
432  Removes the portions of the surface outside of the specified interval.
433 
434  Parameters:
435  dir - [in] 0 The domain specifies an sub-interval of Domain(0)
436  (the first surface parameter).
437  1 The domain specifies an sub-interval of Domain(1)
438  (the second surface parameter).
439  domain - [in] interval of the surface to keep. If dir is 0, then
440  the portions of the surface with parameters (s,t) satisfying
441  s < Domain(0).Min() or s > Domain(0).Max() are trimmed away.
442  If dir is 1, then the portions of the surface with parameters
443  (s,t) satisfying t < Domain(1).Min() or t > Domain(1).Max()
444  are trimmed away.
445  */
446  ON_BOOL32 Trim(
447  int dir,
448  const ON_Interval& domain
449  );
450 
451  /*
452  Description:
453  Where possible, analytically extends surface to include domain.
454  Parameters:
455  dir - [in] 0 new Domain(0) will include domain.
456  (the first surface parameter).
457  1 new Domain(1) will include domain.
458  (the second surface parameter).
459  domain - [in] if domain is not included in surface domain,
460  surface will be extended so that its domain includes domain.
461  Will not work if surface is closed in direction dir.
462  Original surface is identical to the restriction of the
463  resulting surface to the original surface domain,
464  Returns:
465  true if successful.
466  */
467  bool Extend(
468  int dir,
469  const ON_Interval& domain
470  );
471 
472  /*
473  Description:
474  Splits (divides) the surface into two parts at the
475  specified parameter.
476 
477  Parameters:
478  dir - [in] 0 The surface is split vertically. The "west" side
479  is returned in "west_or_south_side" and the "east"
480  side is returned in "east_or_north_side".
481  1 The surface is split horizontally. The "south" side
482  is returned in "west_or_south_side" and the "north"
483  side is returned in "east_or_north_side".
484  c - [in] value of constant parameter in interval returned
485  by Domain(dir)
486  west_or_south_side - [out] west/south portion of surface returned here
487  east_or_north_side - [out] east/north portion of surface returned here
488 
489  Example:
490 
491  ON_NurbsSurface srf = ...;
492  int dir = 1;
493  ON_RevSurface* south_side = 0;
494  ON_RevSurface* north_side = 0;
495  srf.Split( dir, srf.Domain(dir).Mid() south_side, north_side );
496 
497  */
498  ON_BOOL32 Split(
499  int dir,
500  double c,
501  ON_Surface*& west_or_south_side,
502  ON_Surface*& east_or_north_side
503  ) const;
504 
505  int GetNurbForm( // returns 0: unable to create NURBS representation
506  // with desired accuracy.
507  // 1: success - returned NURBS parameterization
508  // matches the surface's to wthe desired accuracy
509  // 2: success - returned NURBS point locus matches
510  // the surfaces's to the desired accuracy but, on
511  // the interior of the surface's domain, the
512  // surface's parameterization and the NURBS
513  // parameterization may not match to the
514  // desired accuracy.
516  double = 0.0
517  ) const;
518 
519  int HasNurbForm( // returns 0: unable to create NURBS representation
520  // with desired accuracy.
521  // 1: success - returned NURBS parameterization
522  // matches the surface's to wthe desired accuracy
523  // 2: success - returned NURBS point locus matches
524  // the surfaces's to the desired accuracy but, on
525  // the interior of the surface's domain, the
526  // surface's parameterization and the NURBS
527  // parameterization may not match to the
528  // desired accuracy.
529  ) const;
530 
532  double nurbs_s, double nurbs_t,
533  double* surface_s, double* surface_t
534  ) const;
535 
537  double surface_s, double surface_t,
538  double* nurbs_s, double* nurbs_t
539  ) const;
540 };
541 
542 #endif
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
bool SetDomain(int dir, ON_Interval domain)
ON_Surface & operator=(const ON_Surface &)
virtual int GetNurbForm(ON_NurbsSurface &nurbs_surface, double tolerance=0.0) const
virtual ON_BOOL32 IsClosed(int) const
virtual ON_BOOL32 Transform(const ON_Xform &xform)
virtual ON_BOOL32 GetParameterTolerance(int dir, double t, double *tminus, double *tplus) const
virtual bool GetSurfaceParameterFromNurbFormParameter(double nurbs_s, double nurbs_t, double *surface_s, double *surface_t) const
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
virtual ON_Interval Domain(int dir) const =0
virtual ON_BOOL32 Evaluate(double u, double v, int num_der, int array_stride, double *der_array, int quadrant=0, int *hint=0) const =0
virtual int Dimension() const =0
virtual ON_BOOL32 IsPlanar(ON_Plane *plane=NULL, double tolerance=ON_ZERO_TOLERANCE) const
virtual ON_BOOL32 GetSurfaceSize(double *width, double *height) const
virtual int Degree(int dir) const =0
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
virtual bool GetNextDiscontinuity(int dir, ON::continuity c, double t0, double t1, double *t, int *hint=NULL, int *dtype=NULL, double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, double curvature_tolerance=ON_SQRT_EPSILON) const
void DestroyRuntimeCache(bool bDelete=true)
virtual int SpanCount(int dir) const =0
virtual bool GetNurbFormParameterFromSurfaceParameter(double surface_s, double surface_t, double *nurbs_s, double *nurbs_t) const
virtual void ClearBoundingBox()
virtual void Dump(ON_TextLog &) const
virtual bool IsContinuous(ON::continuity c, double s, double t, int *hint=NULL, double point_tolerance=ON_ZERO_TOLERANCE, double d1_tolerance=ON_ZERO_TOLERANCE, double d2_tolerance=ON_ZERO_TOLERANCE, double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, double curvature_tolerance=ON_SQRT_EPSILON) const
virtual bool Extend(int dir, const ON_Interval &domain)
virtual ON_BOOL32 Reverse(int)=0
virtual ON_Curve * IsoCurve(int dir, double c) const
unsigned int SizeOf() const
virtual ON_BOOL32 Split(int dir, double c, ON_Surface *&west_or_south_side, ON_Surface *&east_or_north_side) const
virtual ON_BOOL32 Transpose()=0
virtual ON_BOOL32 IsSingular(int) const
virtual ON_BOOL32 IsPeriodic(int) const
virtual ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
virtual ON_BOOL32 Trim(int dir, const ON_Interval &domain)
virtual ON_BOOL32 GetBBox(double *boxmin, double *boxmax, int bGrowBox=false) const =0
virtual ON_BOOL32 GetSpanVector(int dir, double *span_vector) const =0
ON_BoundingBox m_bbox
virtual int HasNurbForm() const