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