opennurbs_sumsurface.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_SUM_SURFACE_INC_)
18 #define OPENNURBS_SUM_SURFACE_INC_
19 
20 class ON_SumSurface;
21 
22 // surface of revolution
23 class ON_CLASS ON_SumSurface : public ON_Surface
24 {
25  ON_OBJECT_DECLARE(ON_SumSurface);
26 
27 public:
28  // virtual ON_Object::DestroyRuntimeCache override
29  void DestroyRuntimeCache( bool bDelete = true ) override;
30 
31 public:
32 
33  // for expert users
34  // surface-PointAt(s,t)
35  // = m_curve[0]->PointAt(s) + m_curve[1]->PointAt(t) + m_basepoint;
36  ON_Curve* m_curve[2]; // m_curve[0] and m_curve[1] are deleted by ~ON_SumSuface.
37  // Use a ON_ProxyCurve if this is problem.
39  ON_BoundingBox m_bbox; // lazy evaluation used in ON_SumSurface::BoundingBox()
40 
41 public:
42 
43  /*
44  Description:
45  Use ON_SumSurface::New(...) instead of new ON_SumSurface(...)
46  Returns:
47  Pointer to an ON_SumSurface. Destroy by calling delete.
48  Remarks:
49  See static ON_Brep* ON_Brep::New() for details.
50  */
51  static ON_SumSurface* New();
52  static ON_SumSurface* New( const ON_SumSurface& rev_surface );
53 
54  ON_SumSurface();
55  virtual ~ON_SumSurface();
56  ON_SumSurface( const ON_SumSurface& );
58 
59  /*
60  Description:
61  Extrude a curve to create a surface.
62  Parameters:
63  curve - [in] curve is copied.
64  extrusion_vector - [in] extrusion vector (must be nonzero)
65  Returns:
66  true if a valid surface is created.
67  */
68  bool Create( const ON_Curve& curve, ON_3dVector extrusion_vector );
69 
70  /*
71  Description:
72  Extrude a curve to create a surface.
73  Parameters:
74  pCurve - [in] pointer to a curve. This pointer will
75  be assigned to m_curve[0] and will be deleted
76  by ~ON_SumSurface.
77  extrusion_vector - [in] extrusion vector (must be nonzero)
78  Returns:
79  true if a valid surface is created.
80  */
81  bool Create( ON_Curve* pCurve, ON_3dVector extrusion_vector );
82 
83  /*
84  Description:
85  Extrude a curve along a path to create a surface.
86  Parameters:
87  curve - [in] curve is copied.
88  path_curve - [in] path_curve is copied.
89  Returns:
90  true if a valid surface is created.
91  */
92  bool Create( const ON_Curve& curve,
93  const ON_Curve& path_curve
94  );
95 
96  /*
97  Description:
98  Extrude a curve to create a surface.
99  Parameters:
100  pCurve - [in] pointer to a curve. This pointer will
101  be assigned to m_curve[0] and will be deleted
102  by ~ON_SumSurface.
103  pPathCurve - [in] pointer to a path curve. This pointer will
104  be assigned to m_curve[1] and will be deleted
105  by ~ON_SumSurface.
106  Returns:
107  true if a valid surface is created.
108  */
109  bool Create(
110  ON_Curve* pCurve,
111  ON_Curve* pPathCurve
112  );
113 
114  void Destroy();
115 
116  void EmergencyDestroy();
117 
118 
119  ////////////////////////////////////////////////////////////
120  //
121  // overrides of virtual ON_Object functions
122  //
123 
124  // virtual ON_Object::SizeOf override
125  unsigned int SizeOf() const override;
126 
127  // virtual ON_Object::DataCRC override
128  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
129 
130  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
131 
132  void Dump( ON_TextLog& ) const override; // for debugging
133 
134  // Use ON_BinaryArchive::WriteObject() and ON_BinaryArchive::ReadObject()
135  // for top level serialization. These Read()/Write() members should just
136  // write/read specific definitions. In particular, they should not write/
137  // read any chunk typecode or length information. The default
138  // implementations return false and do nothing.
139  bool Write(
140  ON_BinaryArchive& // serialize definition to binary archive
141  ) const override;
142 
143  bool Read(
144  ON_BinaryArchive& // restore definition from binary archive
145  ) override;
146 
147  ////////////////////////////////////////////////////////////
148  //
149  // overrides of virtual ON_Geometry functions
150  //
151  int Dimension() const override;
152 
153  // virtual ON_Geometry GetBBox override
154  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
155 
156  void ClearBoundingBox() override;
157 
158  bool Transform(
159  const ON_Xform&
160  ) override;
161 
162  // virtual ON_Geometry::IsDeformable() override
163  bool IsDeformable() const override;
164 
165  // virtual ON_Geometry::MakeDeformable() override
166  bool MakeDeformable() override;
167 
168  ////////////////////////////////////////////////////////////
169  //
170  // overrides of virtual ON_Surface functions
171  //
172 
173  bool SetDomain(
174  int dir, // 0 sets first parameter's domain, 1 gets second parameter's domain
175  double t0,
176  double t1
177  ) override;
178 
180  int // 0 gets first parameter's domain, 1 gets second parameter's domain
181  ) const override;
182 
183  /*
184  Description:
185  Get an estimate of the size of the rectangle that would
186  be created if the 3d surface where flattened into a rectangle.
187  Parameters:
188  width - [out] (corresponds to the first surface parameter)
189  height - [out] (corresponds to the first surface parameter)
190  Remarks:
191  overrides virtual ON_Surface::GetSurfaceSize
192  Returns:
193  true if successful.
194  */
195  bool GetSurfaceSize(
196  double* width,
197  double* height
198  ) const override;
199 
200  int SpanCount(
201  int // 0 gets first parameter's domain, 1 gets second parameter's domain
202  ) const override; // number of smooth spans in curve
203 
204  bool GetSpanVector( // span "knots"
205  int, // 0 gets first parameter's domain, 1 gets second parameter's domain
206  double* // array of length SpanCount() + 1
207  ) const override; //
208 
209  int Degree( // returns maximum algebraic degree of any span
210  // ( or a good estimate if curve spans are not algebraic )
211  int // 0 gets first parameter's domain, 1 gets second parameter's domain
212  ) const override;
213 
214  bool GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
215  int, // 0 gets first parameter, 1 gets second parameter
216  double, // t = parameter in domain
217  double*, // tminus
218  double* // tplus
219  ) const override;
220 
221  /*
222  Description:
223  Test a surface to see if it is planar.
224  Parameters:
225  plane - [out] if not nullptr and true is returned,
226  the plane parameters are filled in.
227  tolerance - [in] tolerance to use when checking
228  Returns:
229  true if there is a plane such that the maximum distance from
230  the surface to the plane is <= tolerance.
231  Remarks:
232  Overrides virtual ON_Surface::IsPlanar.
233  */
234  bool IsPlanar(
235  ON_Plane* plane = nullptr,
236  double tolerance = ON_ZERO_TOLERANCE
237  ) const override;
238 
239  bool IsClosed( // true if surface is closed in direction
240  int // dir 0 = "s", 1 = "t"
241  ) const override;
242 
243  bool IsPeriodic( // true if surface is periodic in direction
244  int // dir 0 = "s", 1 = "t"
245  ) const override;
246 
247  bool IsSingular( // true if surface side is collapsed to a point
248  int // side of parameter space to test
249  // 0 = south, 1 = east, 2 = north, 3 = west
250  ) const override;
251 
252  /*
253  Description:
254  Search for a derivatitive, tangent, or curvature
255  discontinuity.
256  Parameters:
257  dir - [in] If 0, then "u" parameter is checked. If 1, then
258  the "v" parameter is checked.
259  c - [in] type of continity to test for.
260  t0 - [in] Search begins at t0. If there is a discontinuity
261  at t0, it will be ignored. This makes it
262  possible to repeatedly call GetNextDiscontinuity
263  and step through the discontinuities.
264  t1 - [in] (t0 != t1) If there is a discontinuity at t1 is
265  will be ingored unless c is a locus discontinuity
266  type and t1 is at the start or end of the curve.
267  t - [out] if a discontinuity is found, then *t reports the
268  parameter at the discontinuity.
269  hint - [in/out] if GetNextDiscontinuity will be called
270  repeatedly, passing a "hint" with initial value *hint=0
271  will increase the speed of the search.
272  dtype - [out] if not nullptr, *dtype reports the kind of
273  discontinuity found at *t. A value of 1 means the first
274  derivative or unit tangent was discontinuous. A value
275  of 2 means the second derivative or curvature was
276  discontinuous. A value of 0 means teh curve is not
277  closed, a locus discontinuity test was applied, and
278  t1 is at the start of end of the curve.
279  cos_angle_tolerance - [in] default = cos(1 degree) Used only
280  when c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the
281  cosine of the angle between two tangent vectors is
282  <= cos_angle_tolerance, then a G1 discontinuity is reported.
283  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used
284  only when c is ON::continuity::G2_continuous. If K0 and K1 are
285  curvatures evaluated from above and below and
286  |K0 - K1| > curvature_tolerance, then a curvature
287  discontinuity is reported.
288  Returns:
289  Parametric continuity tests c = (C0_continuous, ..., G2_continuous):
290 
291  true if a parametric discontinuity was found strictly
292  between t0 and t1. Note well that all curves are
293  parametrically continuous at the ends of their domains.
294 
295  Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous):
296 
297  true if a locus discontinuity was found strictly between
298  t0 and t1 or at t1 is the at the end of a curve.
299  Note well that all open curves (IsClosed()=false) are locus
300  discontinuous at the ends of their domains. All closed
301  curves (IsClosed()=true) are at least C0_locus_continuous at
302  the ends of their domains.
303  */
304  bool GetNextDiscontinuity(
305  int dir,
306  ON::continuity c,
307  double t0,
308  double t1,
309  double* t,
310  int* hint=nullptr,
311  int* dtype=nullptr,
312  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
313  double curvature_tolerance=ON_SQRT_EPSILON
314  ) const override;
315 
316  /*
317  Description:
318  Test continuity at a surface parameter value.
319  Parameters:
320  c - [in] continuity to test for
321  s - [in] surface parameter to test
322  t - [in] surface parameter to test
323  hint - [in] evaluation hint
324  point_tolerance - [in] if the distance between two points is
325  greater than point_tolerance, then the surface is not C0.
326  d1_tolerance - [in] if the difference between two first derivatives is
327  greater than d1_tolerance, then the surface is not C1.
328  d2_tolerance - [in] if the difference between two second derivatives is
329  greater than d2_tolerance, then the surface is not C2.
330  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
331  c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the cosine
332  of the angle between two normal vectors
333  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
334  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
335  c is ON::continuity::G2_continuous. If K0 and K1 are curvatures evaluated
336  from above and below and |K0 - K1| > curvature_tolerance,
337  then a curvature discontinuity is reported.
338  Returns:
339  true if the surface has at least the c type continuity at the parameter t.
340  Remarks:
341  Overrides virtual ON_Surface::IsContinuous
342  */
343  bool IsContinuous(
344  ON::continuity c,
345  double s,
346  double t,
347  int* hint = nullptr,
348  double point_tolerance=ON_ZERO_TOLERANCE,
349  double d1_tolerance=ON_ZERO_TOLERANCE,
350  double d2_tolerance=ON_ZERO_TOLERANCE,
351  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
352  double curvature_tolerance=ON_SQRT_EPSILON
353  ) const override;
354 
355  bool Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a]
356  int // dir 0 = "s", 1 = "t"
357  ) override;
358 
359  bool Transpose() override; // transpose surface parameterization (swap "s" and "t")
360 
361  bool Evaluate( // returns false if unable to evaluate
362  double, double, // evaluation parameters
363  int, // number of derivatives (>=0)
364  int, // array stride (>=Dimension())
365  double*, // array of length stride*(ndir+1)*(ndir+2)/2
366  int = 0, // optional - determines which quadrant to evaluate from
367  // 0 = default
368  // 1 from NE quadrant
369  // 2 from NW quadrant
370  // 3 from SW quadrant
371  // 4 from SE quadrant
372  int* = 0 // optional - evaluation hint (int[2]) used to speed
373  // repeated evaluations
374  ) const override;
375 
377  int, // 0 first parameter varies and second parameter is constant
378  // e.g., point on IsoCurve(0,c) at t is srf(t,c)
379  // 1 first parameter is constant and second parameter varies
380  // e.g., point on IsoCurve(1,c) at t is srf(c,t)
381  double // value of constant parameter
382  ) const override;
383 
384  int GetNurbForm( // returns 0: unable to create NURBS representation
385  // with desired accuracy.
386  // 1: success - returned NURBS parameterization
387  // matches the surface's to wthe desired accuracy
388  // 2: success - returned NURBS point locus matches
389  // the surfaces's to the desired accuracy but, on
390  // the interior of the surface's domain, the
391  // surface's parameterization and the NURBS
392  // parameterization may not match to the
393  // desired accuracy.
395  double = 0.0
396  ) const override;
397 
398  int HasNurbForm( // returns 0: unable to create NURBS representation
399  // with desired accuracy.
400  // 1: success - returned NURBS parameterization
401  // matches the surface's to wthe desired accuracy
402  // 2: success - returned NURBS point locus matches
403  // the surfaces's to the desired accuracy but, on
404  // the interior of the surface's domain, the
405  // surface's parameterization and the NURBS
406  // parameterization may not match to the
407  // desired accuracy.
408  ) const override;
409 
411  double nurbs_s, double nurbs_t,
412  double* surface_s, double* surface_t
413  ) const override;
414 
416  double surface_s, double surface_t,
417  double* nurbs_s, double* nurbs_t
418  ) const override;
419 
420 
421  /*
422  Description:
423  Removes the portions of the surface outside of the specified interval.
424 
425  Parameters:
426  dir - [in] 0 The domain specifies an sub-interval of Domain(0)
427  (the first surface parameter).
428  1 The domain specifies an sub-interval of Domain(1)
429  (the second surface parameter).
430  domain - [in] interval of the surface to keep. If dir is 0, then
431  the portions of the surface with parameters (s,t) satisfying
432  s < Domain(0).Min() or s > Domain(0).Max() are trimmed away.
433  If dir is 1, then the portions of the surface with parameters
434  (s,t) satisfying t < Domain(1).Min() or t > Domain(1).Max()
435  are trimmed away.
436  */
437  bool Trim(
438  int dir,
439  const ON_Interval& domain
440  ) override;
441 
442  /*
443  Description:
444  Where possible, analytically extends surface to include domain.
445  Parameters:
446  dir - [in] 0 new Domain(0) will include domain.
447  (the first surface parameter).
448  1 new Domain(1) will include domain.
449  (the second surface parameter).
450  domain - [in] if domain is not included in surface domain,
451  surface will be extended so that its domain includes domain.
452  Will not work if surface is closed in direction dir.
453  Original surface is identical to the restriction of the
454  resulting surface to the original surface domain,
455  Returns:
456  true if successful.
457  */
458  bool Extend(
459  int dir,
460  const ON_Interval& domain
461  ) override;
462 
463  /*
464  Description:
465  Splits (divides) the surface into two parts at the
466  specified parameter.
467 
468  Parameters:
469  dir - [in] 0 The surface is split vertically. The "west" side
470  is returned in "west_or_south_side" and the "east"
471  side is returned in "east_or_north_side".
472  1 The surface is split horizontally. The "south" side
473  is returned in "west_or_south_side" and the "north"
474  side is returned in "east_or_north_side".
475  c - [in] value of constant parameter in interval returned
476  by Domain(dir)
477  west_or_south_side - [out] west/south portion of surface returned here
478  east_or_north_side - [out] east/north portion of surface returned here
479 
480  Example:
481 
482  ON_SumSurface srf = ...;
483  int dir = 1;
484  ON_SumSurface* south_side = 0;
485  ON_SumSurface* north_side = 0;
486  srf.Split( dir, srf.Domain(dir).Mid() south_side, north_side );
487 
488  */
489  bool Split(
490  int dir,
491  double c,
492  ON_Surface*& west_or_south_side,
493  ON_Surface*& east_or_north_side
494  ) const override;
495 };
496 
497 #endif
ON_BoundingBox m_bbox
Definition: opennurbs_sumsurface.h:39
virtual bool Transpose()=0
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
virtual bool IsClosed(int) const
ON_3dVector m_basepoint
Definition: opennurbs_sumsurface.h:38
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
virtual bool GetBBox(double *boxmin, double *boxmax, bool bGrowBox=false) const
This is the virtual function that actually calculates axis aligned bounding boxes.
virtual bool MakeDeformable()
If possible, converts the object into a form that can be accuratly modified with "squishy" transforma...
virtual bool GetSpanVector(int dir, double *span_vector) const =0
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
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
Definition: opennurbs_bounding_box.h:25
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.
void EmergencyDestroy()
Sets m_user_data_list = 0.
virtual bool IsDeformable() const
unsigned int SizeOf() const override
virtual ON_Object::SizeOf override
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...
surface of revolution
Definition: opennurbs_sumsurface.h:23
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
Definition: opennurbs_surface.h:57
virtual bool Reverse(int)=0
virtual bool IsSingular(int) const
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:1152
Definition: opennurbs_point.h:46
virtual int HasNurbForm() const
Is there a NURBS surface representation of this surface.
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.