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 ) override;
28 
29 public:
30  // Revolute curve.
31  // If m_curve is not nullptr, 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.
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  bool SetAngleRadians(
81  double start_angle_radians,
82  double end_angle_radians
83  );
84 
85  bool 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 override;
97 
98  // virtual ON_Object::DataCRC override
99  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
100 
101  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
102 
103  void Dump( ON_TextLog& ) const override; // for debugging
104 
105  // Use ON_BinaryArchive::WriteObject() and ON_BinaryArchive::ReadObject()
106  // for top level serialization. These Read()/Write() members should just
107  // write/read specific definitions. In particular, they should not write/
108  // read any chunk typecode or length information. The default
109  // implementations return false and do nothing.
110  bool Write(
111  ON_BinaryArchive& // serialize definition to binary archive
112  ) const override;
113 
114  bool Read(
115  ON_BinaryArchive& // restore definition from binary archive
116  ) override;
117 
118  ////////////////////////////////////////////////////////////
119  //
120  // overrides of virtual ON_Geometry functions
121  //
122  int Dimension() const override;
123 
124  // virtual ON_Geometry GetBBox override
125  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
126 
127  void ClearBoundingBox() override;
128 
129  bool Transform(
130  const ON_Xform&
131  ) override;
132 
133  ////////////////////////////////////////////////////////////
134  //
135  // overrides of virtual ON_Surface functions
136  //
137 
138 
139  bool SetDomain(
140  int dir, // 0 sets first parameter's domain, 1 gets second parameter's domain
141  double t0,
142  double t1
143  ) override;
144 
146  int // 0 gets first parameter's domain, 1 gets second parameter's domain
147  ) const override;
148 
149  /*
150  Description:
151  Get an estimate of the size of the rectangle that would
152  be created if the 3d surface where flattened into a rectangle.
153  Parameters:
154  width - [out] (corresponds to the first surface parameter)
155  height - [out] (corresponds to the first surface parameter)
156  Remarks:
157  overrides virtual ON_Surface::GetSurfaceSize
158  Returns:
159  true if successful.
160  */
161  bool GetSurfaceSize(
162  double* width,
163  double* height
164  ) const override;
165 
166  int SpanCount(
167  int // 0 gets first parameter's domain, 1 gets second parameter's domain
168  ) const override; // number of smooth spans in curve
169 
170  bool GetSpanVector( // span "knots"
171  int, // 0 gets first parameter's domain, 1 gets second parameter's domain
172  double* // array of length SpanCount() + 1
173  ) const override; //
174 
175  int Degree( // returns maximum algebraic degree of any span
176  // ( or a good estimate if curve spans are not algebraic )
177  int // 0 gets first parameter's domain, 1 gets second parameter's domain
178  ) const override;
179 
180  bool GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
181  int, // 0 gets first parameter, 1 gets second parameter
182  double, // t = parameter in domain
183  double*, // tminus
184  double* // tplus
185  ) const override;
186 
187  /*
188  Description:
189  Test a surface of revolution to see if it is a portion
190  of a sphere.
191  Parameters:
192  sphere - [out] if not nullptr and true is returned,
193  the sphere parameters are filled in.
194  tolerance - [in] tolerance to use when checking
195  Returns:
196  true if the surface of revolution is a portion of a sphere.
197  */
198  bool IsSpherical(
199  ON_Sphere* sphere = nullptr,
200  double tolerance = ON_ZERO_TOLERANCE
201  ) const;
202 
203  /*
204  Description:
205  Test a surface of revolution to see if it is a portion
206  of a cylinder.
207  Parameters:
208  cylinder - [out] if not nullptr and true is returned,
209  the cylinder parameters are filled in.
210  tolerance - [in] tolerance to use when checking
211  Returns:
212  true if the surface of revolution is a portion of a cylinder.
213  */
214  bool IsCylindrical(
215  ON_Cylinder* cylinder = nullptr,
216  double tolerance = ON_ZERO_TOLERANCE
217  ) const;
218 
219  /*
220  Description:
221  Test a surface of revolution to see if it is a portion
222  of a cone.
223  Parameters:
224  cone - [out] if not nullptr and true is returned,
225  the cone parameters are filled in.
226  tolerance - [in] tolerance to use when checking
227  Returns:
228  true if the surface of revolution is a portion of a cone.
229  */
230  bool IsConical(
231  ON_Cone* cone = nullptr,
232  double tolerance = ON_ZERO_TOLERANCE
233  ) const;
234 
235  /*
236  Description:
237  Test a surface to see if it is planar.
238  Parameters:
239  plane - [out] if not nullptr and true is returned,
240  the plane parameters are filled in.
241  tolerance - [in] tolerance to use when checking
242  Returns:
243  true if there is a plane such that the maximum distance from
244  the surface to the plane is <= tolerance.
245  Remarks:
246  Overrides virtual ON_Surface::IsPlanar.
247  */
248  bool IsPlanar(
249  ON_Plane* plane = nullptr,
250  double tolerance = ON_ZERO_TOLERANCE
251  ) const override;
252 
253  bool IsClosed( // true if surface is closed in direction
254  int // dir 0 = "s", 1 = "t"
255  ) const override;
256 
257  bool IsPeriodic( // true if surface is periodic in direction
258  int // dir 0 = "s", 1 = "t"
259  ) const override;
260 
261  bool IsSingular( // true if surface side is collapsed to a point
262  int // side of parameter space to test
263  // 0 = south, 1 = east, 2 = north, 3 = west
264  ) const override;
265 
266  /*
267  Description:
268  Search for a derivatitive, tangent, or curvature
269  discontinuity.
270  Parameters:
271  dir - [in] If 0, then "u" parameter is checked. If 1, then
272  the "v" parameter is checked.
273  c - [in] type of continity to test for.
274  t0 - [in] Search begins at t0. If there is a discontinuity
275  at t0, it will be ignored. This makes it
276  possible to repeatedly call GetNextDiscontinuity
277  and step through the discontinuities.
278  t1 - [in] (t0 != t1) If there is a discontinuity at t1 is
279  will be ingored unless c is a locus discontinuity
280  type and t1 is at the start or end of the curve.
281  t - [out] if a discontinuity is found, then *t reports the
282  parameter at the discontinuity.
283  hint - [in/out] if GetNextDiscontinuity will be called
284  repeatedly, passing a "hint" with initial value *hint=0
285  will increase the speed of the search.
286  dtype - [out] if not nullptr, *dtype reports the kind of
287  discontinuity found at *t. A value of 1 means the first
288  derivative or unit tangent was discontinuous. A value
289  of 2 means the second derivative or curvature was
290  discontinuous. A value of 0 means teh curve is not
291  closed, a locus discontinuity test was applied, and
292  t1 is at the start of end of the curve.
293  cos_angle_tolerance - [in] default = cos(1 degree) Used only
294  when c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the
295  cosine of the angle between two tangent vectors is
296  <= cos_angle_tolerance, then a G1 discontinuity is reported.
297  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used
298  only when c is ON::continuity::G2_continuous. If K0 and K1 are
299  curvatures evaluated from above and below and
300  |K0 - K1| > curvature_tolerance, then a curvature
301  discontinuity is reported.
302  Returns:
303  Parametric continuity tests c = (C0_continuous, ..., G2_continuous):
304 
305  true if a parametric discontinuity was found strictly
306  between t0 and t1. Note well that all curves are
307  parametrically continuous at the ends of their domains.
308 
309  Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous):
310 
311  true if a locus discontinuity was found strictly between
312  t0 and t1 or at t1 is the at the end of a curve.
313  Note well that all open curves (IsClosed()=false) are locus
314  discontinuous at the ends of their domains. All closed
315  curves (IsClosed()=true) are at least C0_locus_continuous at
316  the ends of their domains.
317  */
318  bool GetNextDiscontinuity(
319  int dir,
320  ON::continuity c,
321  double t0,
322  double t1,
323  double* t,
324  int* hint=nullptr,
325  int* dtype=nullptr,
326  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
327  double curvature_tolerance=ON_SQRT_EPSILON
328  ) const override;
329 
330 /*
331  Description:
332  Test continuity at a surface parameter value.
333  Parameters:
334  c - [in] continuity to test for
335  s - [in] surface parameter to test
336  t - [in] surface parameter to test
337  hint - [in] evaluation hint
338  point_tolerance - [in] if the distance between two points is
339  greater than point_tolerance, then the surface is not C0.
340  d1_tolerance - [in] if the difference between two first derivatives is
341  greater than d1_tolerance, then the surface is not C1.
342  d2_tolerance - [in] if the difference between two second derivatives is
343  greater than d2_tolerance, then the surface is not C2.
344  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
345  c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the cosine
346  of the angle between two normal vectors
347  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
348  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
349  c is ON::continuity::G2_continuous. If K0 and K1 are curvatures evaluated
350  from above and below and |K0 - K1| > curvature_tolerance,
351  then a curvature discontinuity is reported.
352  Returns:
353  true if the surface has at least the c type continuity at the parameter t.
354  Remarks:
355  Overrides virtual ON_Surface::IsContinuous
356  */
357  bool IsContinuous(
358  ON::continuity c,
359  double s,
360  double t,
361  int* hint = nullptr,
362  double point_tolerance=ON_ZERO_TOLERANCE,
363  double d1_tolerance=ON_ZERO_TOLERANCE,
364  double d2_tolerance=ON_ZERO_TOLERANCE,
365  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
366  double curvature_tolerance=ON_SQRT_EPSILON
367  ) const override;
368 
369  bool Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a]
370  int // dir 0 = "s", 1 = "t"
371  ) override;
372 
373  bool Transpose() override; // transpose surface parameterization (swap "s" and "t")
374 
375  bool Evaluate( // returns false if unable to evaluate
376  double, double, // evaluation parameters (see m_bTransposed)
377  int, // number of derivatives (>=0)
378  int, // array stride (>=Dimension())
379  double*, // array of length stride*(ndir+1)*(ndir+2)/2
380  int = 0, // optional - determines which quadrant to evaluate from
381  // 0 = default
382  // 1 from NE quadrant
383  // 2 from NW quadrant
384  // 3 from SW quadrant
385  // 4 from SE quadrant
386  int* = 0 // optional - evaluation hint (int[2]) used to speed
387  // repeated evaluations
388  ) const override;
389 
390  /*
391  Description:
392  Get isoparametric curve.
393  Overrides virtual ON_Surface::IsoCurve.
394  Parameters:
395  dir - [in] 0 first parameter varies and second parameter is constant
396  e.g., point on IsoCurve(0,c) at t is srf(t,c)
397  1 first parameter is constant and second parameter varies
398  e.g., point on IsoCurve(1,c) at t is srf(c,t)
399 
400  c - [in] value of constant parameter
401  Returns:
402  Isoparametric curve.
403  */
405  int dir,
406  double c
407  ) const override;
408 
409  /*
410  Description:
411  Removes the portions of the surface outside of the specified interval.
412 
413  Parameters:
414  dir - [in] 0 The domain specifies an sub-interval of Domain(0)
415  (the first surface parameter).
416  1 The domain specifies an sub-interval of Domain(1)
417  (the second surface parameter).
418  domain - [in] interval of the surface to keep. If dir is 0, then
419  the portions of the surface with parameters (s,t) satisfying
420  s < Domain(0).Min() or s > Domain(0).Max() are trimmed away.
421  If dir is 1, then the portions of the surface with parameters
422  (s,t) satisfying t < Domain(1).Min() or t > Domain(1).Max()
423  are trimmed away.
424  */
425  bool Trim(
426  int dir,
427  const ON_Interval& domain
428  ) override;
429 
430  /*
431  Description:
432  Where possible, analytically extends surface to include domain.
433  Parameters:
434  dir - [in] 0 new Domain(0) will include domain.
435  (the first surface parameter).
436  1 new Domain(1) will include domain.
437  (the second surface parameter).
438  domain - [in] if domain is not included in surface domain,
439  surface will be extended so that its domain includes domain.
440  Will not work if surface is closed in direction dir.
441  Original surface is identical to the restriction of the
442  resulting surface to the original surface domain,
443  Returns:
444  true if successful.
445  */
446  bool Extend(
447  int dir,
448  const ON_Interval& domain
449  ) override;
450 
451  /*
452  Description:
453  Splits (divides) the surface into two parts at the
454  specified parameter.
455 
456  Parameters:
457  dir - [in] 0 The surface is split vertically. The "west" side
458  is returned in "west_or_south_side" and the "east"
459  side is returned in "east_or_north_side".
460  1 The surface is split horizontally. The "south" side
461  is returned in "west_or_south_side" and the "north"
462  side is returned in "east_or_north_side".
463  c - [in] value of constant parameter in interval returned
464  by Domain(dir)
465  west_or_south_side - [out] west/south portion of surface returned here
466  east_or_north_side - [out] east/north portion of surface returned here
467 
468  Example:
469 
470  ON_NurbsSurface srf = ...;
471  int dir = 1;
472  ON_RevSurface* south_side = 0;
473  ON_RevSurface* north_side = 0;
474  srf.Split( dir, srf.Domain(dir).Mid() south_side, north_side );
475 
476  */
477  bool Split(
478  int dir,
479  double c,
480  ON_Surface*& west_or_south_side,
481  ON_Surface*& east_or_north_side
482  ) const override;
483 
484 
485  int GetNurbForm( // returns 0: unable to create NURBS representation
486  // with desired accuracy.
487  // 1: success - returned NURBS parameterization
488  // matches the surface's to wthe desired accuracy
489  // 2: success - returned NURBS point locus matches
490  // the surfaces's to the desired accuracy but, on
491  // the interior of the surface's domain, the
492  // surface's parameterization and the NURBS
493  // parameterization may not match to the
494  // desired accuracy.
496  double = 0.0
497  ) const override;
498 
499  int HasNurbForm( // returns 0: unable to create NURBS representation
500  // with desired accuracy.
501  // 1: success - returned NURBS parameterization
502  // matches the surface's to wthe desired accuracy
503  // 2: success - returned NURBS point locus matches
504  // the surfaces's to the desired accuracy but, on
505  // the interior of the surface's domain, the
506  // surface's parameterization and the NURBS
507  // parameterization may not match to the
508  // desired accuracy.
509  ) const override;
510 
512  double nurbs_s, double nurbs_t,
513  double* surface_s, double* surface_t
514  ) const override;
515 
517  double surface_s, double surface_t,
518  double* nurbs_s, double* nurbs_t
519  ) const override;
520 };
521 
522 #endif
virtual bool Transpose()=0
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
virtual bool IsClosed(int) const
bool m_bTransposed
Definition: opennurbs_revsurface.h:56
bool SetDomain(int dir, ON_Interval domain)
ON_Surface & operator=(const ON_Surface &)
virtual bool IsPeriodic(int) const
virtual int Dimension() const
Dimension of the object.
virtual int GetNurbForm(ON_NurbsSurface &nurbs_surface, double tolerance=0.0) const
Get a NURBS surface representation of this surface.
Definition: opennurbs_nurbssurface.h:62
ON_Curve * m_curve
Definition: opennurbs_revsurface.h:32
virtual bool GetBBox(double *boxmin, double *boxmax, bool bGrowBox=false) const
This is the virtual function that actually calculates axis aligned bounding boxes.
Lightweight right circular cone. Use ON_ConeSurface if you need ON_Cone geometry as a virtual ON_Surf...
Definition: opennurbs_cone.h:27
virtual bool GetSpanVector(int dir, double *span_vector) const =0
ON_Interval m_t
Definition: opennurbs_revsurface.h:50
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
virtual bool GetSurfaceParameterFromNurbFormParameter(double nurbs_s, double nurbs_t, double *surface_s, double *surface_t) const
ON_Cylinder is a right circular cylinder.
Definition: opennurbs_cylinder.h:27
virtual bool IsPlanar(ON_Plane *plane=nullptr, double tolerance=ON_ZERO_TOLERANCE) const
Test a surface to see if it is planar.
virtual ON_Interval Domain(int dir) const =0
virtual int Degree(int dir) const =0
ON_Interval m_angle
Definition: opennurbs_revsurface.h:40
Definition: opennurbs_bounding_box.h:25
ON_Line m_axis
Axis of revolution.
Definition: opennurbs_revsurface.h:35
virtual int SpanCount(int dir) const =0
virtual bool GetNurbFormParameterFromSurfaceParameter(double surface_s, double surface_t, double *nurbs_s, double *nurbs_t) const
Definition: opennurbs_xform.h:28
virtual void ClearBoundingBox()
Some objects cache bounding box information. If you modify an object, then call ClearBoundingBox() to...
virtual bool Split(int dir, double c, ON_Surface *&west_or_south_side, ON_Surface *&east_or_north_side) const
Splits (divides) the surface into two parts at the specified parameter.
virtual bool Trim(int dir, const ON_Interval &domain)
Removes the portions of the surface outside of the specified interval.
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
unsigned int SizeOf() const override
virtual ON_Object::SizeOf override
Definition: opennurbs_line.h:20
void DestroyRuntimeCache(bool bDelete=true) override
virtual ON_Object::DestroyRuntimeCache override
virtual bool Extend(int dir, const ON_Interval &domain)
Pure virtual function. Default returns false. Where possible, analytically extends surface to include...
virtual ON_Curve * IsoCurve(int dir, double c) const
Get isoparametric curve.
virtual bool GetParameterTolerance(int dir, double t, double *tminus, double *tplus) const
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
bool IsValid(class ON_TextLog *text_log=nullptr) const override
Tests an object to see if its data members are correctly initialized.
virtual bool Write(ON_BinaryArchive &binary_archive) const
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
virtual ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Returns a CRC calculated from the information that defines the object. This CRC can be used as a quic...
Definition: opennurbs_plane.h:20
surface of revolution
Definition: opennurbs_revsurface.h:21
Definition: opennurbs_surface.h:57
virtual bool Reverse(int)=0
virtual bool IsSingular(int) const
ON_BoundingBox m_bbox
Bounding box of the surface of revolution.
Definition: opennurbs_revsurface.h:59
virtual bool GetSurfaceSize(double *width, double *height) const
Get an estimate of the size of the rectangle that would be created if the 3d surface where flattened ...
Definition: opennurbs_point.h:46
virtual int HasNurbForm() const
Is there a NURBS surface representation of this surface.
Definition: opennurbs_sphere.h:22
virtual bool Evaluate(double u, double v, int num_der, int array_stride, double *der_array, int quadrant=0, int *hint=0) const =0
work horse evaluator
virtual bool GetNextDiscontinuity(int dir, ON::continuity c, double t0, double t1, double *t, int *hint=nullptr, int *dtype=nullptr, double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE, double curvature_tolerance=ON_SQRT_EPSILON) const
Search for a derivatitive, tangent, or curvature discontinuity.
virtual bool IsContinuous(ON::continuity c, double s, double t, int *hint=nullptr, 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
Test continuity at a surface parameter value.