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