Point Cloud Library (PCL)  1.14.1-dev
opennurbs_polylinecurve.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(OPENNURBS_CURVE_POLYLINE_INC_)
18 #define OPENNURBS_CURVE_POLYLINE_INC_
19 
20 class ON_PolylineCurve;
21 class ON_CLASS ON_PolylineCurve : public ON_Curve
22 {
23  ON_OBJECT_DECLARE(ON_PolylineCurve);
24 
25 public:
31 
32  virtual ~ON_PolylineCurve();
33 
34  // Description:
35  // Call if memory used by ON_PolylineCurve becomes invalid.
37 
38 
39  /////////////////////////////////////////////////////////////////
40  // ON_Object overrides
41 
42  // virtual ON_Object::SizeOf override
43  unsigned int SizeOf() const;
44 
45  // virtual ON_Object::DataCRC override
46  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
47 
48  /*
49  Description:
50  Tests an object to see if its data members are correctly
51  initialized.
52  Parameters:
53  text_log - [in] if the object is not valid and text_log
54  is not NULL, then a brief englis description of the
55  reason the object is not valid is appened to the log.
56  The information appended to text_log is suitable for
57  low-level debugging purposes by programmers and is
58  not intended to be useful as a high level user
59  interface tool.
60  Returns:
61  @untitled table
62  true object is valid
63  false object is invalid, uninitialized, etc.
64  Remarks:
65  Overrides virtual ON_Object::IsValid
66  */
67  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
68 
69  // Description:
70  // virtual ON_Object::Dump override
71  void Dump(
72  ON_TextLog& dump
73  ) const;
74 
75  // Description:
76  // virtual ON_Object::Write override
77  ON_BOOL32 Write(
78  ON_BinaryArchive& binary_archive
79  ) const;
80 
81  // Description:
82  // virtual ON_Object::Read override
83  ON_BOOL32 Read(
84  ON_BinaryArchive& binary_archive
85  );
86 
87  /////////////////////////////////////////////////////////////////
88  // ON_Geometry overrides
89 
90  // Description:
91  // virtual ON_Geometry::Dimension override
92  // Returns:
93  // value of m_dim
94  int Dimension() const;
95 
96  // Description:
97  // virtual ON_Geometry::GetBBox override
98  // Calculates axis aligned bounding box.
99  // Parameters:
100  // boxmin - [in/out] array of Dimension() doubles
101  // boxmax - [in/out] array of Dimension() doubles
102  // bGrowBox - [in] (default=false)
103  // If true, then the union of the input bbox and the
104  // object's bounding box is returned in bbox.
105  // If false, the object's bounding box is returned in bbox.
106  // Returns:
107  // true if object has bounding box and calculation was successful
108  ON_BOOL32 GetBBox( // returns true if successful
109  double* boxmin,
110  double* boxmax,
111  int bGrowBox = false
112  ) const;
113 
114  /*
115  Description:
116  Get tight bounding box.
117  Parameters:
118  tight_bbox - [in/out] tight bounding box
119  bGrowBox -[in] (default=false)
120  If true and the input tight_bbox is valid, then returned
121  tight_bbox is the union of the input tight_bbox and the
122  polyline's tight bounding box.
123  xform -[in] (default=NULL)
124  If not NULL, the tight bounding box of the transformed
125  polyline is calculated. The polyline is not modified.
126  Returns:
127  True if a valid tight_bbox is returned.
128  */
130  ON_BoundingBox& tight_bbox,
131  int bGrowBox = false,
132  const ON_Xform* xform = 0
133  ) const;
134 
135  // Description:
136  // virtual ON_Geometry::Transform override.
137  // Transforms the NURBS curve.
138  //
139  // Parameters:
140  // xform - [in] transformation to apply to object.
141  //
142  // Remarks:
143  // When overriding this function, be sure to include a call
144  // to ON_Object::TransformUserData() which takes care of
145  // transforming any ON_UserData that may be attached to
146  // the object.
147  ON_BOOL32 Transform(
148  const ON_Xform& xform
149  );
150 
151  // virtual ON_Geometry::IsDeformable() override
152  bool IsDeformable() const;
153 
154  // virtual ON_Geometry::MakeDeformable() override
156 
157  // Description:
158  // virtual ON_Geometry::SwapCoordinates override.
159  // Swaps control point coordinate values with indices i and j.
160  // Parameters:
161  // i - [in] coordinate index
162  // j - [in] coordinate index
163  ON_BOOL32 SwapCoordinates(
164  int i,
165  int j
166  );
167 
168  /////////////////////////////////////////////////////////////////
169  // ON_Curve overrides
170 
171  // Description:
172  // virtual ON_Curve::Domain override.
173  // Returns:
174  // domain of the polyline curve.
176 
177  // Description:
178  // virtual ON_Curve::SetDomain override.
179  // Set the domain of the curve
180  // Parameters:
181  // t0 - [in]
182  // t1 - [in] new domain will be [t0,t1]
183  // Returns:
184  // true if successful.
185  ON_BOOL32 SetDomain(
186  double t0,
187  double t1
188  );
189 
191  int desired_dimension
192  );
193 
194  /*
195  Description:
196  If this curve is closed, then modify it so that
197  the start/end point is at curve parameter t.
198  Parameters:
199  t - [in] curve parameter of new start/end point. The
200  returned curves domain will start at t.
201  Returns:
202  true if successful.
203  Remarks:
204  Overrides virtual ON_Curve::ChangeClosedCurveSeam
205  */
207  double t
208  );
209 
210  // Description:
211  // virtual ON_Curve::SpanCount override.
212  // Get number of segments in polyline.
213  // Returns:
214  // Number of segments in polyline.
215  int SpanCount() const;
216 
217  // Description:
218  // virtual ON_Curve::GetSpanVector override.
219  // Get list of parameters at polyline points.
220  // Parameters:
221  // knot_values - [out] an array of length SpanCount()+1 is
222  // filled in with the parameter values. knot_values[i]
223  // is the parameter for the point m_pline[i].
224  // Returns:
225  // true if successful
226  ON_BOOL32 GetSpanVector(
227  double* knot_values
228  ) const;
229 
230  // Description:
231  // virtual ON_Curve::Degree override.
232  // Returns:
233  // 1
234  int Degree() const;
235 
236  // Description:
237  // virtual ON_Curve::IsLinear override.
238  // Returns:
239  // true if all the polyline points are within tolerance
240  // of the line segment connecting the ends of the polyline.
241  ON_BOOL32 IsLinear(
242  double tolerance = ON_ZERO_TOLERANCE
243  ) const;
244 
245  /*
246  Description:
247  Several types of ON_Curve can have the form of a polyline including
248  a degree 1 ON_NurbsCurve, an ON_PolylineCurve, and an ON_PolyCurve
249  all of whose segments are some form of polyline. IsPolyline tests
250  a curve to see if it can be represented as a polyline.
251  Parameters:
252  pline_points - [out] if not NULL and true is returned, then the
253  points of the polyline form are returned here.
254  t - [out] if not NULL and true is returned, then the parameters of
255  the polyline points are returned here.
256  Returns:
257  @untitled table
258  0 curve is not some form of a polyline
259  >=2 number of points in polyline form
260  */
262  ON_SimpleArray<ON_3dPoint>* pline_points = NULL,
263  ON_SimpleArray<double>* pline_t = NULL
264  ) const;
265 
266  // Description:
267  // virtual ON_Curve::IsArc override.
268  // Returns:
269  // false for all polylines.
270  ON_BOOL32 IsArc(
271  const ON_Plane* plane = NULL,
272  ON_Arc* arc = NULL,
273  double tolerance = ON_ZERO_TOLERANCE
274  ) const;
275 
276  // Description:
277  // virtual ON_Curve::IsPlanar override.
278  // Returns:
279  // true if the polyline is planar.
280  ON_BOOL32 IsPlanar(
281  ON_Plane* plane = NULL,
282  double tolerance = ON_ZERO_TOLERANCE
283  ) const;
284 
285  // Description:
286  // virtual ON_Curve::IsInPlane override.
287  // Returns:
288  // true if every point in the polyline is within
289  // tolerance of the test_plane.
290  ON_BOOL32 IsInPlane(
291  const ON_Plane& test_plane,
292  double tolerance = ON_ZERO_TOLERANCE
293  ) const;
294 
295  // Description:
296  // virtual ON_Curve::IsClosed override.
297  // Returns:
298  // true if the polyline has 4 or more point, the
299  // first point and the last point are equal, and
300  // some other point is distinct from the first and
301  // last point.
302  ON_BOOL32 IsClosed() const;
303 
304  // Description:
305  // virtual ON_Curve::IsPeriodic override.
306  // Returns:
307  // false for all polylines.
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  // Description:
404  // virtual ON_Curve::Reverse override.
405  // Reverse parameterizatrion by negating all m_t values
406  // and reversing the order of the m_pline points.
407  // Remarks:
408  // Domain changes from [a,b] to [-b,-a]
409  ON_BOOL32 Reverse();
410 
411  /*
412  Description:
413  Force the curve to start at a specified point.
414  Parameters:
415  start_point - [in]
416  Returns:
417  true if successful.
418  Remarks:
419  Some start points cannot be moved. Be sure to check return
420  code.
421  See Also:
422  ON_Curve::SetEndPoint
423  ON_Curve::PointAtStart
424  ON_Curve::PointAtEnd
425  */
426  // virtual
427  ON_BOOL32 SetStartPoint(
428  ON_3dPoint start_point
429  );
430 
431  /*
432  Description:
433  Force the curve to end at a specified point.
434  Parameters:
435  end_point - [in]
436  Returns:
437  true if successful.
438  Remarks:
439  Some end points cannot be moved. Be sure to check return
440  code.
441  See Also:
442  ON_Curve::SetStartPoint
443  ON_Curve::PointAtStart
444  ON_Curve::PointAtEnd
445  */
446  //virtual
447  ON_BOOL32 SetEndPoint(
448  ON_3dPoint end_point
449  );
450 
451  ON_BOOL32 Evaluate( // returns false if unable to evaluate
452  double, // evaluation parameter
453  int, // number of derivatives (>=0)
454  int, // array stride (>=Dimension())
455  double*, // array of length stride*(ndir+1)
456  int = 0, // optional - determines which side to evaluate from
457  // 0 = default
458  // < 0 to evaluate from below,
459  // > 0 to evaluate from above
460  int* = 0 // optional - evaluation hint (int) used to speed
461  // repeated evaluations
462  ) const;
463 
464  // Description:
465  // virtual ON_Curve::Trim override.
466  ON_BOOL32 Trim( const ON_Interval& );
467 
468  // Description:
469  // Where possible, analytically extends curve to include domain.
470  // Parameters:
471  // domain - [in] if domain is not included in curve domain,
472  // curve will be extended so that its domain includes domain.
473  // Will not work if curve is closed. Original curve is identical
474  // to the restriction of the resulting curve to the original curve domain,
475  // Returns:
476  // true if successful.
477  bool Extend(
478  const ON_Interval& domain
479  );
480 
481  // Description:
482  // virtual ON_Curve::Split override.
483  //
484  // Split() divides the polyline at the specified parameter. The parameter
485  // must be in the interior of the curve's domain. The pointers passed
486  // to ON_NurbsCurve::Split must either be NULL or point to an ON_NurbsCurve.
487  // If the pointer is NULL, then a curve will be created
488  // in Split(). You may pass "this" as one of the pointers to Split().
489  // For example,
490  //
491  // ON_NurbsCurve right_side;
492  // crv.Split( crv.Domain().Mid() &crv, &right_side );
493  //
494  // would split crv at the parametric midpoint, put the left side in crv,
495  // and return the right side in right_side.
496  ON_BOOL32 Split(
497  double, // t = curve parameter to split curve at
498  ON_Curve*&, // left portion returned here (must be an ON_NurbsCurve)
499  ON_Curve*& // right portion returned here (must be an ON_NurbsCurve)
500  ) const;
501 
502  int GetNurbForm( // returns 0: unable to create NURBS representation
503  // with desired accuracy.
504  // 1: success - returned NURBS parameterization
505  // matches the curve's to wthe desired accuracy
506  // 2: success - returned NURBS point locus matches
507  // the curve's to the desired accuracy but, on
508  // the interior of the curve's domain, the
509  // curve's parameterization and the NURBS
510  // parameterization may not match to the
511  // desired accuracy.
512  ON_NurbsCurve&,
513  double = 0.0,
514  const ON_Interval* = NULL // OPTIONAL subdomain of polyline
515  ) const;
516 
517  int HasNurbForm( // returns 0: unable to create NURBS representation
518  // with desired accuracy.
519  // 1: success - returned NURBS parameterization
520  // matches the curve's to wthe desired accuracy
521  // 2: success - returned NURBS point locus matches
522  // the curve's to the desired accuracy but, on
523  // the interior of the curve's domain, the
524  // curve's parameterization and the NURBS
525  // parameterization may not match to the
526  // desired accuracy.
527  ) const;
528 
529  // virtual ON_Curve::GetCurveParameterFromNurbFormParameter override
531  double, // nurbs_t
532  double* // curve_t
533  ) const;
534 
535  // virtual ON_Curve::GetNurbFormParameterFromCurveParameter override
537  double, // curve_t
538  double* // nurbs_t
539  ) const;
540 /*
541  Description:
542  Lookup a parameter in the m_t array, optionally using a built in snap tolerance to
543  snap a parameter value to an element of m_t.
544  Parameters:
545  t - [in] parameter
546  index -[out] index into m_t such that
547  if function returns false then value of index is
548 
549  @table
550  value of index condition
551  -1 t<m_t[0] or m_t is empty
552  0<=i<=m_t.Count()-2 m_t[i] < t < m_t[i+1]
553  m_t.Count()-1 t>m_t[ m_t.Count()-1]
554 
555  if the function returns true then t is equal to, or is closest to and
556  within tolerance of m_t[index].
557 
558  bEnableSnap-[in] enable snapping
559  Returns:
560  true if the t is exactly equal to, or within tolerance of
561  (only if bEnableSnap==true) m_t[index].
562 */
563  bool ParameterSearch(double t, int& index, bool bEnableSnap) const;
564 
565  bool Append( const ON_PolylineCurve& );
566 
567  /////////////////////////////////////////////////////////////////
568  // Interface
569  public:
570  int PointCount() const; // number of points in polyline
571 
574  int m_dim; // 2 or 3 (2 so ON_PolylineCurve can be uses as a trimming curve)
575 };
576 
577 
578 #endif
ON_PolylineCurve & operator=(const ON_3dPointArray &)
ON_BOOL32 Trim(const ON_Interval &)
ON_BOOL32 SetEndPoint(ON_3dPoint end_point)
int SpanCount() 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
int HasNurbForm() const
ON_PolylineCurve & operator=(const ON_PolylineCurve &)
ON_Interval Domain() const
void Dump(ON_TextLog &dump) const
ON_BOOL32 Split(double, ON_Curve *&, ON_Curve *&) const
int PointCount() const
int Dimension() const
ON_BOOL32 GetBBox(double *boxmin, double *boxmax, int bGrowBox=false) const
ON_BOOL32 Reverse()
ON_BOOL32 SetStartPoint(ON_3dPoint start_point)
ON_BOOL32 GetSpanVector(double *knot_values) const
ON_BOOL32 SwapCoordinates(int i, int j)
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
ON_BOOL32 IsLinear(double tolerance=ON_ZERO_TOLERANCE) const
ON_PolylineCurve(const ON_3dPointArray &)
int IsPolyline(ON_SimpleArray< ON_3dPoint > *pline_points=NULL, ON_SimpleArray< double > *pline_t=NULL) const
ON_PolylineCurve(const ON_PolylineCurve &)
ON_BOOL32 IsClosed() const
ON_BOOL32 Transform(const ON_Xform &xform)
int GetNurbForm(ON_NurbsCurve &, double=0.0, const ON_Interval *=NULL) const
ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
int Degree() const
ON_BOOL32 ChangeClosedCurveSeam(double t)
bool IsDeformable() const
ON_SimpleArray< double > m_t
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 Read(ON_BinaryArchive &binary_archive)
bool ChangeDimension(int desired_dimension)
ON_BOOL32 GetNurbFormParameterFromCurveParameter(double, double *) const
ON_BOOL32 IsPlanar(ON_Plane *plane=NULL, double tolerance=ON_ZERO_TOLERANCE) const
ON_BOOL32 GetCurveParameterFromNurbFormParameter(double, double *) const
bool Append(const ON_PolylineCurve &)
ON_BOOL32 IsInPlane(const ON_Plane &test_plane, double tolerance=ON_ZERO_TOLERANCE) const
ON_BOOL32 IsArc(const ON_Plane *plane=NULL, ON_Arc *arc=NULL, double tolerance=ON_ZERO_TOLERANCE) const
bool Extend(const ON_Interval &domain)
bool GetTightBoundingBox(ON_BoundingBox &tight_bbox, int bGrowBox=false, const ON_Xform *xform=0) const
unsigned int SizeOf() const
bool ParameterSearch(double t, int &index, bool bEnableSnap) const
ON_BOOL32 SetDomain(double t0, double t1)
virtual ~ON_PolylineCurve()
ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const
ON_BOOL32 Evaluate(double, int, int, double *, int=0, int *=0) const
ON_BOOL32 IsPeriodic(void) const
void EmergencyDestroy()