opennurbs_surfaceproxy.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 ////////////////////////////////////////////////////////////////
18 //
19 // Definition of surface proxy object
20 //
21 ////////////////////////////////////////////////////////////////
22 
23 #if !defined(OPENNURBS_SURFACEPROXY_INC_)
24 #define OPENNURBS_SURFACEPROXY_INC_
25 
26 class ON_CLASS ON_SurfaceProxy : public ON_Surface
27 {
28 public:
29  // virtual ON_Object::DestroyRuntimeCache override
30  void DestroyRuntimeCache( bool bDelete = true ) override;
31 
32 public:
37 
38  virtual ~ON_SurfaceProxy();
39 
40  void SetProxySurface( const ON_Surface* proxy_surface );
41  const ON_Surface* ProxySurface() const;
42  bool ProxySurfaceIsTransposed() const;
43 
44 private:
45  const ON_Surface* m_surface;
46  bool m_bTransposed; // proxy surface parameterization is transpose of m_surface
47 
48 public:
49  /*
50  Description:
51  Get a duplicate of the surface.
52  Returns:
53  A duplicate of the surface.
54  Remarks:
55  The caller must delete the returned surface.
56  For non-ON_SurfaceProxy objects, this simply duplicates the surface using
57  ON_Object::Duplicate.
58  For ON_SurfaceProxy objects, this duplicates the actual proxy surface
59  geometry and, if necessary, transposes the result to that
60  the returned surfaces's parameterization and locus match the proxy surface's.
61  */
62  ON_Surface* DuplicateSurface() const override;
63 
64  /////////////////////////////////////////////////////////////////
65  // ON_Object overrides
66 
67  // virtual ON_Object::SizeOf override
68  unsigned int SizeOf() const override;
69 
70  // virtual ON_Object::DataCRC override
71  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
72 
73  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
74 
75  void Dump( ON_TextLog& ) const override; // for debugging
76 
77  bool Write(
78  ON_BinaryArchive& // open binary file
79  ) const override;
80 
81  bool Read(
82  ON_BinaryArchive& // open binary file
83  ) override;
84 
85  /////////////////////////////////////////////////////////////////
86  // ON_Geometry overrides
87 
88  int Dimension() const override;
89 
90  // virtual ON_Geometry GetBBox override
91  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
92 
93  bool Transform(
94  const ON_Xform&
95  ) override;
96 
97  /////////////////////////////////////////////////////////////////
98  // ON_Surface overrides
99 
101  int // 0 gets first parameter's domain, 1 gets second parameter's domain
102  ) const override;
103 
104 
105  /*
106  Description:
107  Get an estimate of the size of the rectangle that would
108  be created if the 3d surface where flattened into a rectangle.
109  Parameters:
110  width - [out] (corresponds to the first surface parameter)
111  height - [out] (corresponds to the first surface parameter)
112  Remarks:
113  overrides virtual ON_Surface::GetSurfaceSize
114  Returns:
115  true if successful.
116  */
117  bool GetSurfaceSize(
118  double* width,
119  double* height
120  ) const override;
121 
122  int SpanCount(
123  int // 0 gets first parameter's domain, 1 gets second parameter's domain
124  ) const override; // number of smooth spans in curve
125 
126  bool GetSpanVector( // span "knots"
127  int, // 0 gets first parameter's domain, 1 gets second parameter's domain
128  double* // array of length SpanCount() + 1
129  ) const override; //
130 
131  int Degree( // returns maximum algebraic degree of any span
132  // ( or a good estimate if curve spans are not algebraic )
133  int // 0 gets first parameter's domain, 1 gets second parameter's domain
134  ) const override;
135 
136 
137  bool GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
138  int, // 0 gets first parameter, 1 gets second parameter
139  double, // t = parameter in domain
140  double*, // tminus
141  double* // tplus
142  ) const override;
143 
144  // override virtual ON_Surface::IsIsoparametric
146  const ON_Curve& curve,
147  const ON_Interval* curve_domain = nullptr
148  ) const override;
149 
150  // override virtual ON_Surface::IsIsoparametric
152  const ON_BoundingBox& bbox
153  ) const override;
154 
155  /*
156  Description:
157  Test a surface to see if it is planar.
158  Parameters:
159  plane - [out] if not nullptr and true is returned,
160  the plane parameters are filled in.
161  tolerance - [in] tolerance to use when checking
162  Returns:
163  true if there is a plane such that the maximum distance from
164  the surface to the plane is <= tolerance.
165  Remarks:
166  Overrides virtual ON_Surface::IsPlanar.
167  */
168  bool IsPlanar(
169  ON_Plane* plane = nullptr,
170  double tolerance = ON_ZERO_TOLERANCE
171  ) const override;
172 
173  bool IsClosed( // true if surface is closed in direction
174  int // dir 0 = "s", 1 = "t"
175  ) const override;
176 
177  bool IsPeriodic( // true if surface is periodic in direction
178  int // dir 0 = "s", 1 = "t"
179  ) const override;
180 
181  bool IsSingular( // true if surface side is collapsed to a point
182  int // side of parameter space to test
183  // 0 = south, 1 = east, 2 = north, 3 = west
184  ) const override;
185 
186  /*
187  Description:
188  Search for a derivatitive, tangent, or curvature
189  discontinuity.
190  Parameters:
191  dir - [in] If 0, then "u" parameter is checked. If 1, then
192  the "v" parameter is checked.
193  c - [in] type of continity to test for.
194  t0 - [in] Search begins at t0. If there is a discontinuity
195  at t0, it will be ignored. This makes it
196  possible to repeatedly call GetNextDiscontinuity
197  and step through the discontinuities.
198  t1 - [in] (t0 != t1) If there is a discontinuity at t1 is
199  will be ingored unless c is a locus discontinuity
200  type and t1 is at the start or end of the curve.
201  t - [out] if a discontinuity is found, then *t reports the
202  parameter at the discontinuity.
203  hint - [in/out] if GetNextDiscontinuity will be called
204  repeatedly, passing a "hint" with initial value *hint=0
205  will increase the speed of the search.
206  dtype - [out] if not nullptr, *dtype reports the kind of
207  discontinuity found at *t. A value of 1 means the first
208  derivative or unit tangent was discontinuous. A value
209  of 2 means the second derivative or curvature was
210  discontinuous. A value of 0 means teh curve is not
211  closed, a locus discontinuity test was applied, and
212  t1 is at the start of end of the curve.
213  cos_angle_tolerance - [in] default = cos(1 degree) Used only
214  when c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the
215  cosine of the angle between two tangent vectors is
216  <= cos_angle_tolerance, then a G1 discontinuity is reported.
217  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used
218  only when c is ON::continuity::G2_continuous. If K0 and K1 are
219  curvatures evaluated from above and below and
220  |K0 - K1| > curvature_tolerance, then a curvature
221  discontinuity is reported.
222  Returns:
223  Parametric continuity tests c = (C0_continuous, ..., G2_continuous):
224 
225  true if a parametric discontinuity was found strictly
226  between t0 and t1. Note well that all curves are
227  parametrically continuous at the ends of their domains.
228 
229  Locus continuity tests c = (C0_locus_continuous, ...,G2_locus_continuous):
230 
231  true if a locus discontinuity was found strictly between
232  t0 and t1 or at t1 is the at the end of a curve.
233  Note well that all open curves (IsClosed()=false) are locus
234  discontinuous at the ends of their domains. All closed
235  curves (IsClosed()=true) are at least C0_locus_continuous at
236  the ends of their domains.
237  */
238  bool GetNextDiscontinuity(
239  int dir,
240  ON::continuity c,
241  double t0,
242  double t1,
243  double* t,
244  int* hint=nullptr,
245  int* dtype=nullptr,
246  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
247  double curvature_tolerance=ON_SQRT_EPSILON
248  ) const override;
249 
250  /*
251  Description:
252  Test continuity at a surface parameter value.
253  Parameters:
254  c - [in] continuity to test for
255  s - [in] surface parameter to test
256  t - [in] surface parameter to test
257  hint - [in] evaluation hint
258  point_tolerance - [in] if the distance between two points is
259  greater than point_tolerance, then the surface is not C0.
260  d1_tolerance - [in] if the difference between two first derivatives is
261  greater than d1_tolerance, then the surface is not C1.
262  d2_tolerance - [in] if the difference between two second derivatives is
263  greater than d2_tolerance, then the surface is not C2.
264  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
265  c is ON::continuity::G1_continuous or ON::continuity::G2_continuous. If the cosine
266  of the angle between two normal vectors
267  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
268  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
269  c is ON::continuity::G2_continuous. If K0 and K1 are curvatures evaluated
270  from above and below and |K0 - K1| > curvature_tolerance,
271  then a curvature discontinuity is reported.
272  Returns:
273  true if the surface has at least the c type continuity at the parameter t.
274  Remarks:
275  Overrides virtual ON_Surface::IsContinuous
276  */
277  bool IsContinuous(
278  ON::continuity c,
279  double s,
280  double t,
281  int* hint = nullptr,
282  double point_tolerance=ON_ZERO_TOLERANCE,
283  double d1_tolerance=ON_ZERO_TOLERANCE,
284  double d2_tolerance=ON_ZERO_TOLERANCE,
285  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
286  double curvature_tolerance=ON_SQRT_EPSILON
287  ) const override;
288 
289  bool Reverse( // reverse parameterizatrion, Domain changes from [a,b] to [-b,-a]
290  int // dir 0 = "s", 1 = "t"
291  ) override;
292 
293  bool Transpose() override; // transpose surface parameterization (swap "s" and "t")
294 
295  // work horse evaluator
296  bool Evaluate( // returns false if unable to evaluate
297  double, double, // evaluation parameters
298  int, // number of derivatives (>=0)
299  int, // array stride (>=Dimension())
300  double*, // array of length stride*(ndir+1)*(ndir+2)/2
301  int = 0, // optional - determines which quadrant to evaluate from
302  // 0 = default
303  // 1 from NE quadrant
304  // 2 from NW quadrant
305  // 3 from SW quadrant
306  // 4 from SE quadrant
307  int* = 0 // optional - evaluation hint (int[2]) used to speed
308  // repeated evaluations
309  ) const override;
310 
311 
313  int dir,
314  double c
315  ) const override;
316 
317 
318  int GetNurbForm( // returns 0: unable to create NURBS representation
319  // with desired accuracy.
320  // 1: success - returned NURBS parameterization
321  // matches the surface's to wthe desired accuracy
322  // 2: success - returned NURBS point locus matches
323  // the surfaces's to the desired accuracy but, on
324  // the interior of the surface's domain, the
325  // surface's parameterization and the NURBS
326  // parameterization may not match to the
327  // desired accuracy.
329  double = 0.0
330  ) const override;
331 
332  int HasNurbForm( // returns 0: unable to create NURBS representation
333  // with desired accuracy.
334  // 1: success - returned NURBS parameterization
335  // matches the surface's to wthe desired accuracy
336  // 2: success - returned NURBS point locus matches
337  // the surfaces's to the desired accuracy but, on
338  // the interior of the surface's domain, the
339  // surface's parameterization and the NURBS
340  // parameterization may not match to the
341  // desired accuracy.
342  ) const override;
343 
345  double nurbs_s, double nurbs_t,
346  double* surface_s, double* surface_t
347  ) const override;
348 
350  double surface_s, double surface_t,
351  double* nurbs_s, double* nurbs_t
352  ) const override;
353 
354 private:
355 
356  ON_OBJECT_DECLARE(ON_SurfaceProxy);
357 };
358 
359 #endif
virtual bool Transpose()=0
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
virtual bool IsClosed(int) const
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
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
Definition: opennurbs_surfaceproxy.h:26
virtual int Degree(int dir) const =0
virtual ISO IsIsoparametric(const ON_Curve &curve, const ON_Interval *curve_domain=nullptr) const
Test a 2d curve to see if it is iso parameteric in the surface&#39;s parameter space. ...
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
ISO
pure virtual class for surface objects
Definition: opennurbs_surface.h:72
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
unsigned int SizeOf() const override
virtual ON_Object::SizeOf override
void DestroyRuntimeCache(bool bDelete=true) override
virtual ON_Object::DestroyRuntimeCache override
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 ON_Surface * DuplicateSurface() const
Get a duplicate of the surface.
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.
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.