opennurbs_linecurve.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(ON_GEOMETRY_CURVE_LINE_INC_)
18 #define ON_GEOMETRY_CURVE_LINE_INC_
19 
20 class ON_LineCurve;
21 class ON_CLASS ON_LineCurve : public ON_Curve
22 {
23  ON_OBJECT_DECLARE(ON_LineCurve);
24 
25 public:
26  ON_LineCurve() ON_NOEXCEPT;
27  virtual ~ON_LineCurve();
28  ON_LineCurve(const ON_LineCurve&);
30 
31 #if defined(ON_HAS_RVALUEREF)
32  // rvalue copy constructor
33  ON_LineCurve( ON_LineCurve&& ) ON_NOEXCEPT;
34 
35  // The rvalue assignment operator calls ON_Object::operator=(ON_Object&&)
36  // which could throw exceptions. See the implementation of
37  // ON_Object::operator=(ON_Object&&) for details.
39 #endif
40 
41  ON_LineCurve(const ON_2dPoint&,const ON_2dPoint&); // creates a 2d line curve
42  ON_LineCurve(const ON_3dPoint&,const ON_3dPoint&); // creates a 3d line curve
43  ON_LineCurve(const ON_Line&);
44  ON_LineCurve(const ON_Line&,
45  double,double // domain
46  );
47 
48 
49 
51 
52  /////////////////////////////////////////////////////////////////
53  // ON_Object overrides
54 
55  // virtual ON_Object::SizeOf override
56  unsigned int SizeOf() const override;
57 
58  // virtual ON_Object::DataCRC override
59  ON__UINT32 DataCRC(ON__UINT32 current_remainder) const override;
60 
61  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
62 
63  void Dump( ON_TextLog& ) const override; // for debugging
64 
65  bool Write(
66  ON_BinaryArchive& // open binary file
67  ) const override;
68 
69  bool Read(
70  ON_BinaryArchive& // open binary file
71  ) override;
72 
73  /////////////////////////////////////////////////////////////////
74  // ON_Geometry overrides
75 
76  int Dimension() const override;
77 
78  // virtual ON_Geometry GetBBox override
79  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
80 
81  // virtual ON_Geometry GetTightBoundingBox override
82  bool GetTightBoundingBox( class ON_BoundingBox& tight_bbox, bool bGrowBox = false, const class ON_Xform* xform = nullptr ) const override;
83 
84  bool Transform(
85  const ON_Xform&
86  ) override;
87 
88  // virtual ON_Geometry::IsDeformable() override
89  bool IsDeformable() const override;
90 
91  // virtual ON_Geometry::MakeDeformable() override
92  bool MakeDeformable() override;
93 
94  bool SwapCoordinates(
95  int, int // indices of coords to swap
96  ) override;
97 
98 
99  /////////////////////////////////////////////////////////////////
100  // ON_Curve overrides
101 
102  ON_Interval Domain() const override;
103 
104  // Description:
105  // Set the domain of the curve
106  // Parameters:
107  // t0 - [in]
108  // t1 - [in] new domain will be [t0,t1]
109  // Returns:
110  // true if successful.
111  bool SetDomain(
112  double t0,
113  double t1
114  ) override;
115 
116  bool ChangeDimension(
117  int desired_dimension
118  ) override;
119 
120  int SpanCount() const override; // number of smooth spans in curve
121 
122  bool GetSpanVector( // span "knots"
123  double* // array of length SpanCount() + 1
124  ) const override; //
125 
126  int Degree( // returns maximum algebraic degree of any span
127  // ( or a good estimate if curve spans are not algebraic )
128  ) const override;
129 
130  bool IsLinear( // true if curve locus is a line segment between
131  // between specified points
132  double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity
133  ) const override;
134 
135  /*
136  Description:
137  Several types of ON_Curve can have the form of a polyline including
138  a degree 1 ON_NurbsCurve, an ON_PolylineCurve, and an ON_PolyCurve
139  all of whose segments are some form of polyline. IsPolyline tests
140  a curve to see if it can be represented as a polyline.
141  Parameters:
142  pline_points - [out] if not nullptr and true is returned, then the
143  points of the polyline form are returned here.
144  t - [out] if not nullptr and true is returned, then the parameters of
145  the polyline points are returned here.
146  Returns:
147  @untitled table
148  0 curve is not some form of a polyline
149  >=2 number of points in polyline form
150  */
151  //virtual
152  int IsPolyline(
153  ON_SimpleArray<ON_3dPoint>* pline_points = nullptr,
154  ON_SimpleArray<double>* pline_t = nullptr
155  ) const override;
156 
157  bool IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between
158  // specified points
159  const ON_Plane* = nullptr, // if not nullptr, test is performed in this plane
160  ON_Arc* = nullptr, // if not nullptr and true is returned, then arc parameters
161  // are filled in
162  double = ON_ZERO_TOLERANCE // tolerance to use when checking
163  ) const override;
164 
165  bool IsPlanar(
166  ON_Plane* = nullptr, // if not nullptr and true is returned, then plane parameters
167  // are filled in
168  double = ON_ZERO_TOLERANCE // tolerance to use when checking
169  ) const override;
170 
171  bool IsInPlane(
172  const ON_Plane&, // plane to test
173  double = ON_ZERO_TOLERANCE // tolerance to use when checking
174  ) const override;
175 
176  bool IsClosed( // true if curve is closed (either curve has
177  void // clamped end knots and euclidean location of start
178  ) const override; // CV = euclidean location of end CV, or curve is
179  // periodic.)
180 
181  bool IsPeriodic( // true if curve is a single periodic segment
182  void
183  ) const override;
184 
185  /*
186  Description:
187  Force the curve to start at a specified point.
188  Parameters:
189  start_point - [in]
190  Returns:
191  true if successful.
192  Remarks:
193  Some end points cannot be moved. Be sure to check return
194  code.
195  See Also:
196  ON_Curve::SetEndPoint
197  ON_Curve::PointAtStart
198  ON_Curve::PointAtEnd
199  */
200  bool SetStartPoint(
201  ON_3dPoint start_point
202  ) override;
203 
204  /*
205  Description:
206  Force the curve to end at a specified point.
207  Parameters:
208  end_point - [in]
209  Returns:
210  true if successful.
211  Remarks:
212  Some end points cannot be moved. Be sure to check return
213  code.
214  See Also:
215  ON_Curve::SetStartPoint
216  ON_Curve::PointAtStart
217  ON_Curve::PointAtEnd
218  */
219  bool SetEndPoint(
220  ON_3dPoint end_point
221  ) override;
222 
223  bool Reverse() override; // reverse parameterizatrion
224  // Domain changes from [a,b] to [-b,-a]
225 
226  bool Evaluate( // returns false if unable to evaluate
227  double, // evaluation parameter
228  int, // number of derivatives (>=0)
229  int, // array stride (>=Dimension())
230  double*, // array of length stride*(ndir+1)
231  int = 0, // optional - determines which side to evaluate from
232  // 0 = default
233  // < 0 to evaluate from below,
234  // > 0 to evaluate from above
235  int* = 0 // optional - evaluation hint (int) used to speed
236  // repeated evaluations
237  ) const override;
238 
239 
240  // Description:
241  // virtual ON_Curve::Trim override.
242  // Removes portions of the curve outside the specified interval.
243  // Parameters:
244  // domain - [in] interval of the curve to keep. Portions of the
245  // curve before curve(domain[0]) and after curve(domain[1]) are
246  // removed.
247  // Returns:
248  // true if successful.
249  bool Trim(
250  const ON_Interval& domain
251  ) override;
252 
253  // Description:
254  // Where possible, analytically extends curve to include domain.
255  // Parameters:
256  // domain - [in] if domain is not included in curve domain,
257  // curve will be extended so that its domain includes domain.
258  // Original curve is identical
259  // to the restriction of the resulting curve to the original curve domain,
260  // Returns:
261  // true if successful.
262  bool Extend(
263  const ON_Interval& domain
264  ) override;
265 
266  // Description:
267  // virtual ON_Curve::Split override.
268  // Divide the curve at the specified parameter. The parameter
269  // must be in the interior of the curve's domain. The pointers
270  // passed to Split must either be nullptr or point to an ON_Curve
271  // object of the same of the same type. If the pointer is nullptr,
272  // then a curve will be created in Split(). You may pass "this"
273  // as one of the pointers to Split().
274  // Parameters:
275  // t - [in] parameter in interval Domain().
276  // left_side - [out] left portion of curve
277  // right_side - [out] right portion of curve
278  // Example:
279  // For example, if crv were an ON_NurbsCurve, then
280  //
281  // ON_NurbsCurve right_side;
282  // crv.Split( crv.Domain().Mid() &crv, &right_side );
283  //
284  // would split crv at the parametric midpoint, put the left side
285  // in crv, and return the right side in right_side.
286  bool Split(
287  double t, // t = curve parameter to split curve at
288  ON_Curve*& left_side, // left portion returned here
289  ON_Curve*& right_side // right portion returned here
290  ) const override;
291 
292  // Description:
293  // virtual ON_Curve::GetNurbForm override.
294  // Get a NURBS curve representation of this curve.
295  // Parameters:
296  // nurbs_curve - [out] NURBS representation returned here
297  // tolerance - [in] tolerance to use when creating NURBS
298  // representation.
299  // subdomain - [in] if not nullptr, then the NURBS representation
300  // for this portion of the curve is returned.
301  // Returns:
302  // 0 unable to create NURBS representation
303  // with desired accuracy.
304  // 1 success - returned NURBS parameterization
305  // matches the curve's to wthe desired accuracy
306  // 2 success - returned NURBS point locus matches
307  // the curve's to the desired accuracy but, on
308  // the interior of the curve's domain, the
309  // curve's parameterization and the NURBS
310  // parameterization may not match to the
311  // desired accuracy.
312  int GetNurbForm(
313  ON_NurbsCurve&,
314  double = 0.0,
315  const ON_Interval* = nullptr
316  ) const override;
317 
318  // Description:
319  // virtual ON_Curve::HasNurbForm override.
320  // Does a NURBS curve representation of this curve exist.
321  // Parameters:
322  // Returns:
323  // 0 unable to create NURBS representation
324  // with desired accuracy.
325  // 1 success - returned NURBS parameterization
326  // matches the curve's to wthe desired accuracy
327  // 2 success - returned NURBS point locus matches
328  // the curve's to the desired accuracy but, on
329  // the interior of the curve's domain, the
330  // curve's parameterization and the NURBS
331  // parameterization may not match to the
332  // desired accuracy.
333  int HasNurbForm(
334  ) const override;
335 
336  // Description:
337  // virtual ON_Curve::GetCurveParameterFromNurbFormParameter override.
338  // Convert a NURBS curve parameter to a curve parameter
339  //
340  // Parameters:
341  // nurbs_t - [in] nurbs form parameter
342  // curve_t - [out] curve parameter
343  //
344  // Remarks:
345  // If GetNurbForm returns 2, this function converts the curve
346  // parameter to the NURBS curve parameter.
347  //
348  // See Also:
349  // ON_Curve::GetNurbForm, ON_Curve::GetNurbFormParameterFromCurveParameter
350  //virtual
352  double nurbs_t,
353  double* curve_t
354  ) const override;
355 
356  // Description:
357  // virtual ON_Curve::GetNurbFormParameterFromCurveParameter override.
358  // Convert a curve parameter to a NURBS curve parameter.
359  //
360  // Parameters:
361  // curve_t - [in] curve parameter
362  // nurbs_t - [out] nurbs form parameter
363  //
364  // Remarks:
365  // If GetNurbForm returns 2, this function converts the curve
366  // parameter to the NURBS curve parameter.
367  //
368  // See Also:
369  // ON_Curve::GetNurbForm, ON_Curve::GetCurveParameterFromNurbFormParameter
370  //virtual
372  double curve_t,
373  double* nurbs_t
374  ) const override;
375 
376  /////////////////////////////////////////////////////////////////
377  // Interface
378 
379  ON_Line m_line;
380  ON_Interval m_t; // domain
381  int m_dim; // 2 or 3 (2 so ON_LineCurve can be uses as a trimming curve)
382 };
383 
385 #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 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 bool SetStartPoint(ON_3dPoint start_point)
Force the curve to start at a specified point.
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 MakeDeformable()
If possible, converts the object into a form that can be accuratly modified with "squishy" transforma...
virtual bool Reverse()=0
Reverse the direction of the curve.
virtual bool Extend(const ON_Interval &domain)
Pure virtual function. Default returns false. Where possible, analytically extends curve to include d...
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.
Definition: opennurbs_linecurve.h:21
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 SwapCoordinates(int i, int j)
Swaps object coordinate values with indices i and j.
virtual bool GetNurbFormParameterFromCurveParameter(double curve_t, double *nurbs_t) const
Convert a curve parameter to a NURBS curve parameter.
virtual bool ChangeDimension(int desired_dimension)
Change the dimension of a 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)...
Definition: opennurbs_point.h:277
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_bounding_box.h:25
Definition: opennurbs_xform.h:28
bool GetTightBoundingBox(class ON_BoundingBox &tight_bbox, bool bGrowBox=false, const class ON_Xform *xform=nullptr) const override
virtual ON_Geometry GetTightBoundingBox override
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
virtual bool IsDeformable() const
ON_Curve & operator=(const ON_Curve &)
virtual bool IsPeriodic() const
Test a curve to see if it is periodic.
Definition: opennurbs_line.h:20
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 SetEndPoint(ON_3dPoint end_point)
Force the curve to end at a specified point.
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().
Definition: opennurbs_point.h:460
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
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...