opennurbs_planesurface.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(ON_GEOMETRY_SURFACE_PLANE_INC_)
18 #define ON_GEOMETRY_SURFACE_PLANE_INC_
19 
20 class ON_PlaneSurface;
21 
22 class ON_CLASS ON_PlaneSurface : public ON_Surface
23 {
24  ON_OBJECT_DECLARE(ON_PlaneSurface);
25 
26 public:
30 
31  ON_PlaneSurface(const ON_Plane&);
33 
34  virtual ~ON_PlaneSurface();
35 
36  // An ON_PlaneSurface is really a finite rectangle.
37  // m_plane defines the plane and m_extents[] stores
38  // the x and y intervals of the plane that define the
39  // rectangle. The m_domain[] intervals specify the
40  // evaluation domain. Changing the extents are domain
41  // are INDEPENDENT of each other. Use Domain() and
42  // SetDomain() to control the evluation domain. Use
43  // Extents() and SetExtents() to control the rectangle
44  // extents.
46 
47  /////////////////////////////////////////////////////////////////
48  // ON_Object overrides
49 
50  // virtual ON_Object::SizeOf override
51  unsigned int SizeOf() const override;
52 
53  // virtual ON_Object::DataCRC override
54  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
55 
56  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
57 
58  void Dump( ON_TextLog& ) const override; // for debugging
59 
60  bool Write(
61  ON_BinaryArchive& // open binary file
62  ) const override;
63 
64  bool Read(
65  ON_BinaryArchive& // open binary file
66  ) override;
67 
68  /////////////////////////////////////////////////////////////////
69  // ON_Geometry overrides
70 
71  int Dimension() const override;
72 
73  // virtual ON_Geometry GetBBox override
74  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
75 
76  bool Transform(
77  const ON_Xform&
78  ) override;
79 
80  /////////////////////////////////////////////////////////////////
81  // ON_Surface overrides
82 
83 
84  /*
85  Description:
86  Sets the evaluation domains. Does not change the geometry.
87  Parameters:
88  dir - [in] 0 sets first parameter's domain
89  1 sets second parameter's domain
90  t0 - [in]
91  t1 - [in] (t0 < t1) the interval (t0,t1) will be the new domain
92  Returns:
93  True if successful.
94  See Also:
95  ON_PlaneSurface::SetExtents
96  */
97  bool SetDomain(
98  int dir,
99  double t0,
100  double t1
101  ) override;
102 
104  int // 0 gets first parameter's domain, 1 gets second parameter's domain
105  ) const override;
106 
107  /*
108  Description:
109  Get an estimate of the size of the rectangle that would
110  be created if the 3d surface where flattened into a rectangle.
111  Parameters:
112  width - [out] (corresponds to the first surface parameter)
113  height - [out] (corresponds to the first surface parameter)
114  Remarks:
115  overrides virtual ON_Surface::GetSurfaceSize
116  Returns:
117  true if successful.
118  */
119  bool GetSurfaceSize(
120  double* width,
121  double* height
122  ) const override;
123 
124  int SpanCount(
125  int // 0 gets first parameter's domain, 1 gets second parameter's domain
126  ) const override; // number of smooth spans in curve
127 
128  bool GetSpanVector( // span "knots"
129  int, // 0 gets first parameter's domain, 1 gets second parameter's domain
130  double* // array of length SpanCount() + 1
131  ) const override; //
132 
133  int Degree( // returns maximum algebraic degree of any span
134  // ( or a good estimate if curve spans are not algebraic )
135  int // 0 gets first parameter's domain, 1 gets second parameter's domain
136  ) const override;
137 
138  bool GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
139  int, // 0 gets first parameter, 1 gets second parameter
140  double, // t = parameter in domain
141  double*, // tminus
142  double* // tplus
143  ) const override;
144 
145  /*
146  Description:
147  Test a surface to see if it is planar.
148  Parameters:
149  plane - [out] if not nullptr and true is returned,
150  the plane parameters are filled in.
151  tolerance - [in] tolerance to use when checking
152  Returns:
153  true if there is a plane such that the maximum distance from
154  the surface to the plane is <= tolerance.
155  Remarks:
156  Overrides virtual ON_Surface::IsPlanar.
157  */
158  bool IsPlanar(
159  ON_Plane* plane = nullptr,
160  double tolerance = ON_ZERO_TOLERANCE
161  ) const override;
162 
163  bool IsClosed( // true if surface is closed in direction
164  int // dir 0 = "s", 1 = "t"
165  ) const override;
166 
167  bool IsPeriodic( // true if surface is periodic in direction
168  int // dir 0 = "s", 1 = "t"
169  ) const override;
170 
171  bool IsSingular( // true if surface side is collapsed to a point
172  int // side of parameter space to test
173  // 0 = south, 1 = east, 2 = north, 3 = west
174  ) const override;
175 
176  /*
177  Description:
178  Search for a derivatitive, tangent, or curvature
179  discontinuity.
180  Parameters:
181  dir - [in] If 0, then "u" parameter is checked. If 1, then
182  the "v" parameter is checked.
183  c - [in] type of continity to test for.
184  t0 - [in] Search begins at t0. If there is a discontinuity
185  at t0, it will be ignored. This makes it
186  possible to repeatedly call GetNextDiscontinuity
187  and step through the discontinuities.
188  t1 - [in] (t0 != t1) If there is a discontinuity at t1 is
189  will be ingored unless c is a locus discontinuity
190  type and t1 is at the start or end of the curve.
191  t - [out] if a discontinuity is found, then *t reports the
192  parameter at the discontinuity.
193  hint - [in/out] if GetNextDiscontinuity will be called
194  repeatedly, passing a "hint" with initial value *hint=0
195  will increase the speed of the search.
196  dtype - [out] if not nullptr, *dtype reports the kind of
197  discontinuity found at *t. A value of 1 means the first
198  derivative or unit tangent was discontinuous. A value
199  of 2 means the second derivative or curvature was
200  discontinuous. A value of 0 means teh curve is not
201  closed, a locus discontinuity test was applied, and
202  t1 is at the start of end of the curve.
203  cos_angle_tolerance - [in] default = cos(1 degree) Used only
204  when c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the
205  cosine of the angle between two tangent vectors is
206  <= cos_angle_tolerance, then a G1 discontinuity is reported.
207  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used
208  only when c is ON::continuity::G2_continuous. If K0 and K1 are
209  curvatures evaluated from above and below and
210  |K0 - K1| > curvature_tolerance, then a curvature
211  discontinuity is reported.
212  Returns:
213  Parametric continuity tests c = (C0_continuous, ..., G2_continuous):
214 
215  true if a parametric discontinuity was found strictly
216  between t0 and t1. Note well that all curves are
217  parametrically continuous at the ends of their domains.
218 
219  Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous):
220 
221  true if a locus discontinuity was found strictly between
222  t0 and t1 or at t1 is the at the end of a curve.
223  Note well that all open curves (IsClosed()=false) are locus
224  discontinuous at the ends of their domains. All closed
225  curves (IsClosed()=true) are at least C0_locus_continuous at
226  the ends of their domains.
227  */
228  bool GetNextDiscontinuity(
229  int dir,
230  ON::continuity c,
231  double t0,
232  double t1,
233  double* t,
234  int* hint=nullptr,
235  int* dtype=nullptr,
236  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
237  double curvature_tolerance=ON_SQRT_EPSILON
238  ) const override;
239 
240  /*
241  Description:
242  Test continuity at a surface parameter value.
243  Parameters:
244  c - [in] continuity to test for
245  s - [in] surface parameter to test
246  t - [in] surface parameter to test
247  hint - [in] evaluation hint
248  point_tolerance - [in] if the distance between two points is
249  greater than point_tolerance, then the surface is not C0.
250  d1_tolerance - [in] if the difference between two first derivatives is
251  greater than d1_tolerance, then the surface is not C1.
252  d2_tolerance - [in] if the difference between two second derivatives is
253  greater than d2_tolerance, then the surface is not C2.
254  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
255  c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the cosine
256  of the angle between two normal vectors
257  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
258  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
259  c is ON::continuity::G2_continuous. If K0 and K1 are curvatures evaluated
260  from above and below and |K0 - K1| > curvature_tolerance,
261  then a curvature discontinuity is reported.
262  Returns:
263  true if the surface has at least the c type continuity at the parameter t.
264  Remarks:
265  Overrides virtual ON_Surface::IsContinuous
266  */
267  bool IsContinuous(
268  ON::continuity c,
269  double s,
270  double t,
271  int* hint = nullptr,
272  double point_tolerance=ON_ZERO_TOLERANCE,
273  double d1_tolerance=ON_ZERO_TOLERANCE,
274  double d2_tolerance=ON_ZERO_TOLERANCE,
275  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
276  double curvature_tolerance=ON_SQRT_EPSILON
277  ) const override;
278 
279  bool Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a]
280  int // dir 0 = "s", 1 = "t"
281  ) override;
282 
283  bool Transpose() override; // transpose surface parameterization (swap "s" and "t")
284 
285 
286  bool Evaluate( // returns false if unable to evaluate
287  double, double, // evaluation parameters
288  int, // number of derivatives (>=0)
289  int, // array stride (>=Dimension())
290  double*, // array of length stride*(ndir+1)*(ndir+2)/2
291  int = 0, // optional - determines which quadrant to evaluate from
292  // 0 = default
293  // 1 from NE quadrant
294  // 2 from NW quadrant
295  // 3 from SW quadrant
296  // 4 from SE quadrant
297  int* = 0 // optional - evaluation hint (int[2]) used to speed
298  // repeated evaluations
299  ) const override;
300 
301  /*
302  Description:
303  Get isoparametric curve.
304  Overrides virtual ON_Surface::IsoCurve.
305  Parameters:
306  dir - [in] 0 first parameter varies and second parameter is constant
307  e.g., point on IsoCurve(0,c) at t is srf(t,c)
308  1 first parameter is constant and second parameter varies
309  e.g., point on IsoCurve(1,c) at t is srf(c,t)
310 
311  c - [in] value of constant parameter
312  Returns:
313  Isoparametric curve.
314  */
316  int dir,
317  double c
318  ) const override;
319 
320 
321  /*
322  Description:
323  Removes the portions of the surface outside of the specified interval.
324  Overrides virtual ON_Surface::Trim.
325 
326  Parameters:
327  dir - [in] 0 The domain specifies an sub-interval of Domain(0)
328  (the first surface parameter).
329  1 The domain specifies an sub-interval of Domain(1)
330  (the second surface parameter).
331  domain - [in] interval of the surface to keep. If dir is 0, then
332  the portions of the surface with parameters (s,t) satisfying
333  s < Domain(0).Min() or s > Domain(0).Max() are trimmed away.
334  If dir is 1, then the portions of the surface with parameters
335  (s,t) satisfying t < Domain(1).Min() or t > Domain(1).Max()
336  are trimmed away.
337  */
338  bool Trim(
339  int dir,
340  const ON_Interval& domain
341  ) override;
342 
343  /*
344  Description:
345  Where possible, analytically extends surface to include domain.
346  Parameters:
347  dir - [in] 0 new Domain(0) will include domain.
348  (the first surface parameter).
349  1 new Domain(1) will include domain.
350  (the second surface parameter).
351  domain - [in] if domain is not included in surface domain,
352  surface will be extended so that its domain includes domain.
353  Will not work if surface is closed in direction dir.
354  Original surface is identical to the restriction of the
355  resulting surface to the original surface domain,
356  Returns:
357  true if successful.
358  */
359  bool Extend(
360  int dir,
361  const ON_Interval& domain
362  ) override;
363 
364  /*
365  Description:
366  Splits (divides) the surface into two parts at the
367  specified parameter.
368  Overrides virtual ON_Surface::Split.
369 
370  Parameters:
371  dir - [in] 0 The surface is split vertically. The "west" side
372  is returned in "west_or_south_side" and the "east"
373  side is returned in "east_or_north_side".
374  1 The surface is split horizontally. The "south" side
375  is returned in "west_or_south_side" and the "north"
376  side is returned in "east_or_north_side".
377  c - [in] value of constant parameter in interval returned
378  by Domain(dir)
379  west_or_south_side - [out] west/south portion of surface returned here
380  east_or_north_side - [out] east/north portion of surface returned here
381 
382  Example:
383 
384  ON_PlaneSurface srf = ...;
385  int dir = 1;
386  ON_PlaneSurface* south_side = 0;
387  ON_PlaneSurface* north_side = 0;
388  srf.Split( dir, srf.Domain(dir).Mid() south_side, north_side );
389 
390  */
391  bool Split(
392  int dir,
393  double c,
394  ON_Surface*& west_or_south_side,
395  ON_Surface*& east_or_north_side
396  ) const override;
397 
398 
399  int GetNurbForm( // returns 0: unable to create NURBS representation
400  // with desired accuracy.
401  // 1: success - returned NURBS parameterization
402  // matches the surface's to wthe desired accuracy
403  // 2: success - returned NURBS point locus matches
404  // the surfaces's to the desired accuracy but, on
405  // the interior of the surface's domain, the
406  // surface's parameterization and the NURBS
407  // parameterization may not match to the
408  // desired accuracy.
410  double = 0.0
411  ) const override;
412 
413  int HasNurbForm( // returns 0: unable to create NURBS representation
414  // with desired accuracy.
415  // 1: success - returned NURBS parameterization
416  // matches the surface's to wthe desired accuracy
417  // 2: success - returned NURBS point locus matches
418  // the surfaces's to the desired accuracy but, on
419  // the interior of the surface's domain, the
420  // surface's parameterization and the NURBS
421  // parameterization may not match to the
422  // desired accuracy.
423  ) const override;
424 
425  /*
426  Description:
427  Sets the extents of then rectangle. Does not change the evaluation
428  domain.
429  Parameters:
430  dir - [in] 0 sets plane's x coordinate extents
431  0 sets plane's y coordinate extents
432  extents - [in] increasing interval
433  bSynchDomain - [in] if true, the corresponding evaluation interval
434  domain is set so that it matches the extents interval
435  Returns:
436  True if successful.
437  See Also:
438  ON_PlaneSurface::SetDomain
439  */
440  bool SetExtents(
441  int dir,
442  ON_Interval extents,
443  bool bSynchDomain = false
444  );
445 
446  /*
447  Description:
448  Gets the extents of the rectangle.
449  Parameters:
450  dir - [in] 0 gets plane's x coordinate extents
451  0 gets plane's y coordinate extents
452  Returns:
453  Increasing interval
454  See Also:
455  ON_PlaneSurface::Domain
456  */
457  ON_Interval Extents(
458  int dir
459  ) const;
460 
461  /*
462  Description:
463  Create a plane that contains the projection of a bounding box.
464  Parameters:
465  plane_equation - [in]
466  bbox - [in]
467  padding - [in]
468  amount of extra padding to add around the edges of the
469  plane. Default is 0.0625
470  Returns:
471  true if successful
472  */
473  bool CreatePseudoInfinitePlane(
474  ON_PlaneEquation plane_equation,
475  const ON_BoundingBox& bbox,
476  double padding = 0.0625
477  );
478 
479  /*
480  Description:
481  Create a plane that contains the projection of a bounding box.
482  Parameters:
483  plane - [in]
484  bbox - [in]
485  padding - [in]
486  amount of extra padding to add around the edges of the
487  plane. Default is 0.0625
488  Returns:
489  true if successful
490  */
491  bool CreatePseudoInfinitePlane(
492  const ON_Plane& plane,
493  const ON_BoundingBox& bbox,
494  double padding = 0.0625
495  );
496 
497  /*
498  Description:
499  Create a plane that contains the projection of a list of points.
500  Parameters:
501  plane - [in]
502  point_count - [in]
503  point_list - [in]
504  padding - [in]
505  amount of extra padding to add around the edges of the
506  plane. Default is 0.0625
507  Returns:
508  true if successful
509  */
510  bool CreatePseudoInfinitePlane(
511  const ON_Plane& plane,
512  int point_count,
513  const ON_3dPoint* point_list,
514  double padding = 0.0625
515  );
516 
517 protected:
518  // evaluation domain (always increasing)
519  ON_Interval m_domain[2]; // always increasing
520 
521  // rectangle extents (in m_plane x,y coordinates)
522  ON_Interval m_extents[2];
523 };
524 
525 
526 class ON_CLASS ON_ClippingPlaneSurface : public ON_PlaneSurface
527 {
528  ON_OBJECT_DECLARE(ON_ClippingPlaneSurface);
529 public:
531  ON_ClippingPlaneSurface(const ON_Plane& src);
534 
537 
538  void Default();
539 
540  // override ON_Object::ObjectType() - returns ON::clipplane_object
541  ON::object_type ObjectType() const override;
542 
543  // virtual ON_Object::SizeOf override
544  unsigned int SizeOf() const override;
545 
546  // virtual ON_Object::DataCRC override
547  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
548 
549  // virtual ON_Object::Dump override
550  void Dump( ON_TextLog& ) const override; // for debugging
552  // virtual ON_Object::Write override
553  bool Write(
554  ON_BinaryArchive& // open binary file
555  ) const override;
556 
557  // virtual ON_Object::Read override
558  bool Read(
559  ON_BinaryArchive& // open binary file
560  ) override;
561 
562  ON_ClippingPlane m_clipping_plane;
563 };
564 
565 
566 #endif
virtual bool Transpose()=0
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
virtual bool IsClosed(int) const
unsigned int SizeOf() const override
ON_Object overrides.
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 GetSpanVector(int dir, double *span_vector) const =0
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
Definition: opennurbs_planesurface.h:22
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
Definition: opennurbs_plane.h:524
virtual int Degree(int dir) const =0
bool Write(ON_BinaryArchive &) const override
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
bool Read(ON_BinaryArchive &) override
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_bounding_box.h:25
virtual int SpanCount(int dir) const =0
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override
virtual ON_Object::DataCRC override
Definition: opennurbs_xform.h:28
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
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.
Definition: opennurbs_planesurface.h:515
virtual bool GetParameterTolerance(int dir, double t, double *tminus, double *tplus) const
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
ON_Plane m_plane
Definition: opennurbs_planesurface.h:45
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
void Dump(ON_TextLog &) const override
Creates a text dump of the object.
Definition: opennurbs_point.h:460
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
Typically the vector portion is a unit vector and m_d = -(x*P.x + y*P.y + z*P.z) for a point P on the...
Definition: opennurbs_point.h:1433
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 ...
ON_PlaneSurface & operator=(const ON_PlaneSurface &)
Definition: opennurbs_point.h:46
virtual int HasNurbForm() const
Is there a NURBS surface representation of this surface.
ON::object_type ObjectType() const override
override ON_Object::ObjectType() - returns ON::surface_object
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.