Point Cloud Library (PCL)  1.14.1-dev
opennurbs_curveproxy.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 curve proxy object
20 //
21 ////////////////////////////////////////////////////////////////
22 
23 #if !defined(OPENNURBS_CURVEPROXY_INC_)
24 #define OPENNURBS_CURVEPROXY_INC_
25 
26 /*
27 Description:
28  An ON_CurveProxy is a reference to an ON_Curve.
29  One may specify a subdomain of the referenced curve
30  and apply a affine reparameterization, possibly reversing
31  the orientation. The underlying curve cannot be modified through
32  the curve proxy.
33 Details:
34  The reference to the "real_curve" is const, so most functions
35  which modify an ON_Curve will fail when passed an ON_CurveProxy.
36 */
37 class ON_CurveProxy;
38 class ON_CLASS ON_CurveProxy : public ON_Curve
39 {
40  ON_OBJECT_DECLARE(ON_CurveProxy);
41 
42 public:
43  // virtual ON_Object::DestroyRuntimeCache override
44  void DestroyRuntimeCache( bool bDelete = true );
45 
46 public:
51 
53 
54  virtual ~ON_CurveProxy();
55 
56  // virtual ON_Object::SizeOf override
57  unsigned int SizeOf() const;
58 
59  // virtual ON_Object::DataCRC override
60  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
61 
62  /*
63  Description:
64  Sets the curve geometry that "this" is a proxy for.
65  Sets proxy domain to proxy_curve->Domain().
66  Parameters:
67  real_curve - [in]
68  */
69  void SetProxyCurve( const ON_Curve* real_curve );
70 
71  /*
72  Description:
73  Sets the curve geometry that "this" is a proxy for.
74  Sets proxy domain to proxy_curve->Domain().
75  Parameters:
76  real_curve - [in]
77  real_curve_subdomain - [in] increasing sub interval of
78  real_curve->Domain(). This interval defines the
79  portion the "real" curve geometry that "this" proxy
80  uses.
81  bReversed - [in] true if the parameterization of "this" proxy
82  as a curve is reversed from the underlying "real" curve
83  geometry.
84  */
85  void SetProxyCurve( const ON_Curve* real_curve,
86  ON_Interval real_curve_subdomain
87  );
88 
89  /*
90  Returns:
91  "Real" curve geometry that "this" is a proxy for.
92  */
93  const ON_Curve* ProxyCurve() const;
94 
95  /*
96  Description:
97  Sets portion of the "real" curve that this proxy represents.
98  Does NOT change the domain of "this" curve.
99  Parameters:
100  proxy_curve_subdomain - [in] increasing sub interval of
101  ProxyCurve()->Domain(). This interval defines the
102  portion the curve geometry that "this" proxy uses.
103  Remarks:
104  This function is poorly named. It does NOT set the proxy
105  curve's domain. It does set the interval of the "real"
106  curve for which "this" is a proxy.
107  */
108  bool SetProxyCurveDomain( ON_Interval proxy_curve_subdomain );
109 
110 
111  /*
112  Returns:
113  Sub interval of the "real" curve's domain that "this" uses.
114  This interval is not necessarily the same as "this" curve's
115  domain.
116  Remarks:
117  This function is poorly named. It does NOT get the proxy
118  curve's domain. It does get the evaluation interval
119  of the "real" curve for which "this" is a proxy.
120  */
122 
123  /*
124  Returns:
125  True if "this" as a curve is reversed from the "real" curve
126  geometry.
127  */
128  bool ProxyCurveIsReversed() const;
129 
130  /*
131  Parameters:
132  t - [in] parameter for "this" curve
133  Returns:
134  Corresponding parameter in m_real_curve's domain.
135  */
136  double RealCurveParameter( double t ) const;
137 
138  /*
139  Parameters:
140  real_curve_parameter - [in] m_real_curve parameter
141  Returns:
142  Corresponding parameter for "this" curve
143  */
144  double ThisCurveParameter( double real_curve_parameter ) const;
145 
146 private:
147  // "real" curve geometry that "this" is a proxy for.
148  const ON_Curve* m_real_curve;
149 
150  // If true, the parameterization of "this" proxy is
151  // the reverse of the m_curve parameterization.
152  bool m_bReversed;
153 
154  // The m_domain interval is always increasing and included in
155  // m_curve->Domain(). The m_domain interval defines the portion
156  // of m_curve that "this" proxy uses and it can be a proper
157  // sub-interval of m_curve->Domain().
158  ON_Interval m_real_curve_domain;
159 
160  // The evaluation domain of this curve. If "t" is a parameter for
161  // "this" and "r" is a parameter for m_curve, then when m_bReversed==false
162  // we have
163  // t = m_this_domain.ParameterAt(m_real_curve_domain.NormalizedParameterAt(r))
164  // r = m_real_curve_domain.ParameterAt(m_this_domain.NormalizedParameterAt(t))
165  // and when m_bReversed==true we have
166  // t = m_this_domain.ParameterAt(1 - m_real_curve_domain.NormalizedParameterAt(r))
167  // r = m_real_curve_domain.ParameterAt(1 - m_this_domain.NormalizedParameterAt(t))
168  ON_Interval m_this_domain;
169 
170  ON_Interval RealCurveInterval( const ON_Interval* sub_domain ) const;
171 
172 
173 public:
174  /*
175  Description:
176  Get a duplicate of the curve.
177  Returns:
178  A duplicate of the curve.
179  Remarks:
180  The caller must delete the returned curve.
181  For non-ON_CurveProxy objects, this simply duplicates the curve using
182  ON_Object::Duplicate.
183  For ON_CurveProxy objects, this duplicates the actual proxy curve
184  geometry and, if necessary, trims and reverse the result to that
185  the returned curve's parameterization and locus match the proxy curve's.
186  */
188 
189  /////////////////////////////////////////////////////////////////
190  // ON_Object overrides
191 
192  /*
193  Description:
194  Tests an object to see if its data members are correctly
195  initialized.
196  Parameters:
197  text_log - [in] if the object is not valid and text_log
198  is not NULL, then a brief englis description of the
199  reason the object is not valid is appened to the log.
200  The information appended to text_log is suitable for
201  low-level debugging purposes by programmers and is
202  not intended to be useful as a high level user
203  interface tool.
204  Returns:
205  @untitled table
206  true object is valid
207  false object is invalid, uninitialized, etc.
208  Remarks:
209  Overrides virtual ON_Object::IsValid
210  */
211  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
212 
213  void Dump( ON_TextLog& ) const; // for debugging
214 
215  ON_BOOL32 Write( // returns false - nothing serialized
216  ON_BinaryArchive& // open binary file
217  ) const;
218 
219  ON_BOOL32 Read( // returns false - nothing serialized
220  ON_BinaryArchive& // open binary file
221  );
222 
223  /////////////////////////////////////////////////////////////////
224  // ON_Geometry overrides
225 
226  int Dimension() const;
227 
228  ON_BOOL32 GetBBox( // returns true if successful
229  double*, // minimum
230  double*, // maximum
231  ON_BOOL32 = false // true means grow box
232  ) const;
233 
234  ON_BOOL32 Transform(
235  const ON_Xform&
236  );
237 
238  /////////////////////////////////////////////////////////////////
239  // ON_Curve overrides
240 
241  // Returns:
242  // domain of the curve.
243  // Remarks:
244  // If m_bReverse is true, this returns the reverse
245  // of m_domain.
247 
248  /* virtual ON_Curve::SetDomain() override */
249  ON_BOOL32 SetDomain(
250  double t0,
251  double t1
252  );
253 
254  bool SetDomain( ON_Interval domain );
255 
256  int SpanCount() const; // number of smooth spans in curve
257 
258  ON_BOOL32 GetSpanVector(
259  double*
260  ) const;
261 
262  int Degree( // returns maximum algebraic degree of any span
263  // ( or a good estimate if curve spans are not algebraic )
264  ) const;
265 
266  // (optional - override if curve is piecewise smooth)
267  ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
268  double, // t = parameter in domain
269  double*, // tminus
270  double* // tplus
271  ) const;
272 
273  ON_BOOL32 IsLinear( // true if curve locus is a line segment between
274  // between specified points
275  double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity
276  ) const;
277 
278  // virtual override of ON_Curve::IsPolyline
280  ON_SimpleArray<ON_3dPoint>* pline_points = NULL,
281  ON_SimpleArray<double>* pline_t = NULL
282  ) const;
283 
284  ON_BOOL32 IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between
285  // specified points
286  const ON_Plane* = NULL, // if not NULL, test is performed in this plane
287  ON_Arc* = NULL, // if not NULL and true is returned, then arc parameters
288  // are filled in
289  double = ON_ZERO_TOLERANCE // tolerance to use when checking
290  ) const;
291 
292  ON_BOOL32 IsPlanar(
293  ON_Plane* = NULL, // if not NULL and true is returned, then plane parameters
294  // are filled in
295  double = ON_ZERO_TOLERANCE // tolerance to use when checking
296  ) const;
297 
298  ON_BOOL32 IsInPlane(
299  const ON_Plane&, // plane to test
300  double = ON_ZERO_TOLERANCE // tolerance to use when checking
301  ) const;
302 
303  ON_BOOL32 IsClosed( // true if curve is closed (either curve has
304  void // clamped end knots and euclidean location of start
305  ) const; // CV = euclidean location of end CV, or curve is
306  // periodic.)
307 
308  ON_BOOL32 IsPeriodic( // true if curve is a single periodic segment
309  void
310  ) const;
311 
312  /*
313  Description:
314  Search for a derivatitive, tangent, or curvature discontinuity.
315  Parameters:
316  c - [in] type of continity to test for. If ON::C1_continuous
317  t0 - [in] search begins at t0
318  t1 - [in] (t0 < t1) search ends at t1
319  t - [out] if a discontinuity is found, the *t reports the
320  parameter at the discontinuity.
321  hint - [in/out] if GetNextDiscontinuity will be called repeatedly,
322  passing a "hint" with initial value *hint=0 will increase the speed
323  of the search.
324  dtype - [out] if not NULL, *dtype reports the kind of discontinuity
325  found at *t. A value of 1 means the first derivative or unit tangent
326  was discontinuous. A value of 2 means the second derivative or
327  curvature was discontinuous.
328  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
329  c is ON::G1_continuous or ON::G2_continuous. If the cosine
330  of the angle between two tangent vectors
331  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
332  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
333  c is ON::G2_continuous or ON::Gsmooth_continuous.
334  ON::G2_continuous:
335  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  ON::Gsmooth_continuous:
339  If K0 and K1 are curvatures evaluated from above and below
340  and the angle between K0 and K1 is at least twice angle tolerance
341  or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance,
342  then a curvature discontinuity is reported.
343  Returns:
344  true if a discontinuity was found on the interior of the interval (t0,t1).
345  Remarks:
346  Overrides ON_Curve::GetNextDiscontinuity.
347  */
349  ON::continuity c,
350  double t0,
351  double t1,
352  double* t,
353  int* hint=NULL,
354  int* dtype=NULL,
355  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
356  double curvature_tolerance=ON_SQRT_EPSILON
357  ) const;
358 
359  /*
360  Description:
361  Test continuity at a curve parameter value.
362  Parameters:
363  c - [in] continuity to test for
364  t - [in] parameter to test
365  hint - [in] evaluation hint
366  point_tolerance - [in] if the distance between two points is
367  greater than point_tolerance, then the curve is not C0.
368  d1_tolerance - [in] if the difference between two first derivatives is
369  greater than d1_tolerance, then the curve is not C1.
370  d2_tolerance - [in] if the difference between two second derivatives is
371  greater than d2_tolerance, then the curve is not C2.
372  cos_angle_tolerance - [in] default = cos(1 degree) Used only when
373  c is ON::G1_continuous or ON::G2_continuous. If the cosine
374  of the angle between two tangent vectors
375  is <= cos_angle_tolerance, then a G1 discontinuity is reported.
376  curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
377  c is ON::G2_continuous or ON::Gsmooth_continuous.
378  ON::G2_continuous:
379  If K0 and K1 are curvatures evaluated
380  from above and below and |K0 - K1| > curvature_tolerance,
381  then a curvature discontinuity is reported.
382  ON::Gsmooth_continuous:
383  If K0 and K1 are curvatures evaluated from above and below
384  and the angle between K0 and K1 is at least twice angle tolerance
385  or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance,
386  then a curvature discontinuity is reported.
387  Returns:
388  true if the curve has at least the c type continuity at the parameter t.
389  Remarks:
390  Overrides ON_Curve::IsContinuous.
391  */
393  ON::continuity c,
394  double t,
395  int* hint = NULL,
396  double point_tolerance=ON_ZERO_TOLERANCE,
397  double d1_tolerance=ON_ZERO_TOLERANCE,
398  double d2_tolerance=ON_ZERO_TOLERANCE,
399  double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
400  double curvature_tolerance=ON_SQRT_EPSILON
401  ) const;
402 
403  ON_BOOL32 Reverse(); // reverse parameterizatrion
404  // Domain changes from [a,b] to [-b,-a]
405 
406  ON_BOOL32 Evaluate( // returns false if unable to evaluate
407  double, // evaluation parameter
408  int, // number of derivatives (>=0)
409  int, // array stride (>=Dimension())
410  double*, // array of length stride*(ndir+1)
411  int = 0, // optional - determines which side to evaluate from
412  // 0 = default
413  // < 0 to evaluate from below,
414  // > 0 to evaluate from above
415  int* = 0 // optional - evaluation hint (int) used to speed
416  // repeated evaluations
417  ) const;
418 
419  // override of virtual ON_Curve::Trim
420  ON_BOOL32 Trim(
421  const ON_Interval& domain
422  );
423 
424  // override of virtual ON_Curve::Split
425  ON_BOOL32 Split(
426  double t,
427  ON_Curve*& left_side,
428  ON_Curve*& right_side
429  ) const;
430 
431  int GetNurbForm( // returns 0: unable to create NURBS representation
432  // with desired accuracy.
433  // 1: success - returned NURBS parameterization
434  // matches the curve's to wthe desired accuracy
435  // 2: success - returned NURBS point locus matches
436  // the curve's to the desired accuracy but, on
437  // the interior of the curve's domain, the
438  // curve's parameterization and the NURBS
439  // parameterization may not match to the
440  // desired accuracy.
441  ON_NurbsCurve&,
442  double = 0.0,
443  const ON_Interval* = NULL // OPTIONAL subdomain of ON_CurveProxy::Domain()
444  ) const;
445 
446  int HasNurbForm( // returns 0: unable to create NURBS representation
447  // with desired accuracy.
448  // 1: success - returned NURBS parameterization
449  // matches the curve's to wthe desired accuracy
450  // 2: success - returned NURBS point locus matches
451  // the curve's to the desired accuracy but, on
452  // the interior of the curve's domain, the
453  // curve's parameterization and the NURBS
454  // parameterization may not match to the
455  // desired accuracy.
456  ) const;
457 
458  // virtual ON_Curve::GetCurveParameterFromNurbFormParameter override
460  double, // nurbs_t
461  double* // curve_t
462  ) const;
463 
464  // virtual ON_Curve::GetNurbFormParameterFromCurveParameter override
466  double, // curve_t
467  double* // nurbs_t
468  ) const;
469 };
470 
471 
472 #endif
ON_BOOL32 GetSpanVector(double *) const
bool ProxyCurveIsReversed() const
bool GetNextDiscontinuity(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
ON_BOOL32 Transform(const ON_Xform &)
double RealCurveParameter(double t) const
ON_BOOL32 Evaluate(double, int, int, double *, int=0, int *=0) const
ON_BOOL32 Trim(const ON_Interval &domain)
ON_CurveProxy(const ON_Curve *, ON_Interval)
int SpanCount() const
ON_BOOL32 Split(double t, ON_Curve *&left_side, ON_Curve *&right_side) const
ON_CurveProxy & operator=(const ON_CurveProxy &)
ON_BOOL32 Reverse()
void SetProxyCurve(const ON_Curve *real_curve)
ON_BOOL32 IsPeriodic(void) const
ON_CurveProxy(const ON_Curve *)
ON_BOOL32 Write(ON_BinaryArchive &) const
int IsPolyline(ON_SimpleArray< ON_3dPoint > *pline_points=NULL, ON_SimpleArray< double > *pline_t=NULL) const
ON_Curve * DuplicateCurve() const
bool SetDomain(ON_Interval domain)
bool SetProxyCurveDomain(ON_Interval proxy_curve_subdomain)
void SetProxyCurve(const ON_Curve *real_curve, ON_Interval real_curve_subdomain)
bool IsContinuous(ON::continuity c, 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
ON_BOOL32 IsPlanar(ON_Plane *=NULL, double=ON_ZERO_TOLERANCE) const
unsigned int SizeOf() const
int Dimension() const
ON_BOOL32 IsLinear(double=ON_ZERO_TOLERANCE) const
ON_BOOL32 GetParameterTolerance(double, double *, double *) const
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
int Degree() const
ON_CurveProxy(const ON_CurveProxy &)
ON_BOOL32 IsInPlane(const ON_Plane &, double=ON_ZERO_TOLERANCE) const
int HasNurbForm() const
ON_BOOL32 Read(ON_BinaryArchive &)
double ThisCurveParameter(double real_curve_parameter) const
ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const
ON_BOOL32 SetDomain(double t0, double t1)
void Dump(ON_TextLog &) const
ON_BOOL32 GetBBox(double *, double *, ON_BOOL32=false) const
ON_BOOL32 GetCurveParameterFromNurbFormParameter(double, double *) const
virtual ~ON_CurveProxy()
const ON_Curve * ProxyCurve() const
void DestroyRuntimeCache(bool bDelete=true)
ON_BOOL32 GetNurbFormParameterFromCurveParameter(double, double *) const
ON_Interval Domain() const
int GetNurbForm(ON_NurbsCurve &, double=0.0, const ON_Interval *=NULL) const
ON_Interval ProxyCurveDomain() const
ON_BOOL32 IsClosed(void) const
ON_BOOL32 IsArc(const ON_Plane *=NULL, ON_Arc *=NULL, double=ON_ZERO_TOLERANCE) const