QCAD
Open Source 2D CAD
RSpline.h
Go to the documentation of this file.
1 
20 #ifndef RSPLINE_H
21 #define RSPLINE_H
22 
23 #include "../core_global.h"
24 
25 #include "RArc.h"
26 #include "RBox.h"
27 #include "RExplodable.h"
28 #include "RShape.h"
29 #include "RSplineProxy.h"
30 #include "RVector.h"
31 
32 #include "RPolyline.h"
33 
34 #ifndef R_NO_OPENNURBS
35 #include "opennurbs/opennurbs.h"
36 #endif
37 
38 #ifndef RDEFAULT_MIN1
39 #define RDEFAULT_MIN1 -1
40 #endif
41 
54 class QCADCORE_EXPORT RSpline: public RShape, public RExplodable {
55 public:
56  RSpline();
57  RSpline(const RSpline& other);
58  RSpline(const QList<RVector>& controlPoints, int degree);
59  //virtual ~RSpline();
60 
61  RSpline& operator =(const RSpline& other);
62 
63  virtual RShape::Type getShapeType() const {
64  return Spline;
65  }
66 
67  virtual RSpline* clone() const {
68  return new RSpline(*this);
69  }
70 
71  virtual bool isDirected() const {
72  return true;
73  }
74 
75  void copySpline(const RSpline& other);
76 
77  static QList<RSpline> createSplinesFromArc(const RArc& arc);
78  static RSpline createBezierFromSmallArc(double r, double a1, double a2);
79 
80  virtual void setZ(double z);
81 
82  virtual QList<RVector> getVectorProperties() const;
83  virtual QList<int> getIntProperties() const;
84  virtual QList<double> getDoubleProperties() const;
85  virtual QList<bool> getBoolProperties() const;
86 
87  virtual bool isInterpolated() const {
88  return true;
89  }
90 
91  //virtual RVector getClosestPointOnShape(const RVector& p, bool limited) const;
92 
93  void appendControlPoint(const RVector& point);
94  void appendControlPoints(const QList<RVector>& points);
95  void removeLastControlPoint();
96  void setControlPoints(const QList<RVector>& points);
97  QList<RVector> getControlPoints() const;
98  QList<RVector> getControlPointsWrapped() const;
99  int countControlPoints() const;
100  RVector getControlPointAt(int i) const;
101 
102  void appendFitPoint(const RVector& point);
103  void prependFitPoint(const RVector& point);
104  void insertFitPointAt(const RVector& point);
105  void insertFitPointAt(double t, const RVector& point);
106  void removeFitPointAt(const RVector& point);
107  void removeFirstFitPoint();
108  void removeLastFitPoint();
109  void setFitPoints(const QList<RVector>& points);
110  QList<RVector> getFitPoints() const;
111  int countFitPoints() const;
112  bool hasFitPoints() const;
113  RVector getFitPointAt(int i) const;
114 
115  QList<double> getKnotVector() const;
116  QList<double> getActualKnotVector() const;
117  void setKnotVector(const QList<double>& knots);
118  void appendKnot(double k);
119  QList<double> getWeights() const;
120  void setWeights(QList<double>& w);
121 
122  void setDegree(int d);
123  int getDegree() const;
124 
125  int getOrder() const;
126 
127  void setPeriodic(bool on);
128  //bool isClosedPeriodic() const;
129 
130  bool isClosed() const;
131  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
132  bool isPeriodic() const;
133 
134  virtual double getDirection1() const;
135  virtual double getDirection2() const;
136 
137  virtual RS::Side getSideOfPoint(const RVector& point) const;
138 
139  virtual RVector getStartPoint() const;
140  virtual RVector getEndPoint() const;
141 
142  void setStartPoint(const RVector& v);
143  void setEndPoint(const RVector& v);
144 
145  void setTangents(const RVector& start, const RVector& end);
146  void unsetTangents();
147 
148  void setTangentAtStart(const RVector& t);
149  RVector getTangentAtStart() const;
150  void unsetTangentAtStart();
151  void setTangentAtEnd(const RVector& t);
152  RVector getTangentAtEnd() const;
153  void unsetTangentAtEnd();
154 
155  void updateTangentsPeriodic();
156 
157  virtual RBox getBoundingBox() const;
158 
159  virtual double getLength() const;
160  RVector getPointAt(double t) const;
161  RVector getPointAtDistance(double distance) const;
162  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
163 
164  virtual QList<RVector> getEndPoints() const;
165  virtual RVector getMiddlePoint() const;
166  virtual QList<RVector> getMiddlePoints() const;
167  virtual QList<RVector> getCenterPoints() const;
168  virtual QList<RVector> getPointsWithDistanceToEnd(
169  double distance, int from = RS::FromAny) const;
170  virtual QList<RVector> getPointCloud(double segmentLength) const;
171 
172  virtual RVector getVectorTo(const RVector& point,
173  bool limited = true, double strictRange = RMAXDOUBLE) const;
174  virtual bool isOnShape(const RVector& point,
175  bool limited = true,
176  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
177 
178  virtual bool move(const RVector& offset);
179  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
180  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
181  virtual bool mirror(const RLine& axis);
182  virtual bool flipHorizontal();
183  virtual bool flipVertical();
184  virtual bool reverse();
185  virtual bool stretch(const RPolyline& area, const RVector& offset);
186 
187  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
188 
189  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
190  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
191  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
192  virtual bool trimStartPoint(double trimDist) {
193  return RShape::trimStartPoint(trimDist);
194  }
195  virtual bool trimEndPoint(double trimDist) {
196  return RShape::trimEndPoint(trimDist);
197  }
198  virtual double getDistanceFromStart(const RVector& p) const;
199 
200  QList<RSpline> splitAtPoints(const QList<RVector>& points) const;
201  QList<RSpline> splitAtParams(const QList<double>& params) const;
202 
203  RPolyline toPolyline(int segments) const;
204  RPolyline approximateWithArcs(double tolerance, double radiusLimit=RDEFAULT_MIN1) const;
205 
206  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
207  QList<QSharedPointer<RShape> > getExplodedBezier(int segments) const;
208  QList<QSharedPointer<RShape> > getExplodedWithSegmentLength(double segmentLength) const;
209 
210  QList<RSpline> getBezierSegments(const RBox& queryBox = RDEFAULT_RBOX) const;
211 
212  bool isValid() const;
213  double getTDelta() const;
214  double getTMin() const;
215  double getTMax() const;
216  double getTAtPoint(const RVector& point) const;
217  double getTAtDistance(double distance) const;
218  double getDistanceAtT(double t) const;
219  QList<RSpline> getSegments(const QList<RVector>& points) const;
220 
221  QList<RVector> getDiscontinuities() const;
222  RSpline simplify(double tolerance);
223 
224  void updateFromControlPoints() const;
225  void updateFromFitPoints() const;
226  void update() const;
227 
228  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
229 
230  bool isDirty() const {
231  return dirty;
232  }
233 
234  QList<RVector> getSelfIntersectionPoints() const;
235 
236  static bool hasProxy() {
237  return splineProxy!=NULL;
238  }
239 
243  static void setSplineProxy(RSplineProxy* p) {
244  if (splineProxy!=NULL) {
245  delete splineProxy;
246  }
247  splineProxy = p;
248  }
249 
254  return splineProxy;
255  }
256 
257 protected:
258  void appendToExploded(const RLine& line) const;
259  //void appendToExploded(QList<QSharedPointer<RShape> >& list) const;
260  void invalidate() const;
261  void updateInternal() const;
262  void updateBoundingBox() const;
263 
264  virtual void print(QDebug dbg) const;
265 
266 public:
267  // members are mutable, so the spline can update itself from fit points
268 
273  mutable QList<RVector> controlPoints;
274 
278  mutable QList<double> knotVector;
279 
284  mutable QList<double> weights;
285 
290  QList<RVector> fitPoints;
291 
296  mutable int degree;
297 
302 
307 
311  mutable bool periodic;
312 
313  mutable bool dirty;
314  mutable bool updateInProgress;
315 
316 private:
317 #ifndef R_NO_OPENNURBS
318  mutable ON_NurbsCurve curve;
319 #endif
320  mutable RBox boundingBox;
321  mutable QList<QSharedPointer<RShape> > exploded;
322  // cached length:
323  mutable double length;
324 
326 };
327 
331 Q_DECLARE_METATYPE(QList<RSpline>)
332 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
333 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
334 
335 #endif
RSpline::fitPoints
QList< RVector > fitPoints
Getter function for this property: getFitPoints Setter function for this property: setFitPoints
Definition: RSpline.h:290
RSpline::tangentStart
RVector tangentStart
Unit vector start tangent.
Definition: RSpline.h:301
RSpline::length
double length
Definition: RSpline.h:323
RShape::splitAt
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2114
RShape::getIntProperties
virtual QList< int > getIntProperties() const
Definition: RShape.h:166
RShape::getSelfIntersectionPoints
virtual QList< RVector > getSelfIntersectionPoints() const
Definition: RShape.h:263
RSpline::updateInProgress
bool updateInProgress
Definition: RSpline.h:314
RSpline::hasProxy
static bool hasProxy()
Definition: RSpline.h:236
RSpline::trimEndPoint
virtual bool trimEndPoint(double trimDist)
Definition: RSpline.h:195
RShape::getTransformed
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
RShape::trimEndPoint
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:322
RSpline::setSplineProxy
static void setSplineProxy(RSplineProxy *p)
Definition: RSpline.h:243
RShape::getLength
virtual double getLength() const =0
RSpline
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RSpline.h:54
RBox.h
RSpline::tangentEnd
RVector tangentEnd
Unit vector end tangent.
Definition: RSpline.h:306
RShape::stretch
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1740
RSpline::dirty
bool dirty
Definition: RSpline.h:313
RSpline::isDirty
bool isDirty() const
Definition: RSpline.h:230
rotate
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:109
RShape::getMiddlePoints
virtual QList< RVector > getMiddlePoints() const =0
RShape::Spline
@ Spline
Definition: RShape.h:82
RS::Side
Side
Side used for side of a point relative to an entity (right hand or left hand side)
Definition: RS.h:205
RS::PointTolerance
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RS.h:699
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RSplineProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RSplineProxy.h:34
RS::Ending
Ending
Entity ending.
Definition: RS.h:215
RS::FromStart
@ FromStart
Definition: RS.h:264
RShape::getVectorProperties
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:165
RSpline::clone
virtual RSpline * clone() const
Definition: RSpline.h:67
i
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: autostart.js:49
RShape::getCenterPoints
virtual QList< RVector > getCenterPoints() const =0
RArc
Low-level mathematical representation of an arc.
Definition: RArc.h:40
RSpline::curve
ON_NurbsCurve curve
Definition: RSpline.h:318
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RSpline::getSplineProxy
static RSplineProxy * getSplineProxy()
Definition: RSpline.h:253
RShape::getTrimEnd
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition: RShape.h:339
RShape::Type
Type
Definition: RShape.h:74
RSpline::trimStartPoint
virtual bool trimStartPoint(double trimDist)
Definition: RSpline.h:192
RShape
Interface for geometrical shape classes.
Definition: RShape.h:72
RSpline::degree
int degree
Getter function for this property: getDegree Setter function for this property: setDegree
Definition: RSpline.h:296
RShape::trimStartPoint
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:303
RShape.h
RDEFAULT_RVECTOR
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
RShape::getVectorTo
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
RSpline::splineProxy
static RSplineProxy * splineProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RSpline.h:325
RVector.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RDEFAULT_TOLERANCE_1E_MIN4
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:43
update
void update()
Keeps the user interface up to date during long operations.
Definition: simple.js:26
RShape::flipHorizontal
virtual bool flipHorizontal()
Definition: RShape.cpp:1732
RShape::getDirection1
virtual double getDirection1() const
Definition: RShape.h:271
RShape::getDistanceFromStart
virtual double getDistanceFromStart(const RVector &p) const
Definition: RShape.h:350
RShape::getDoubleProperties
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:167
RSpline::exploded
QList< QSharedPointer< RShape > > exploded
Definition: RSpline.h:321
RSpline::knotVector
QList< double > knotVector
Getter function for this property: getKnotVector
Definition: RSpline.h:278
RShape::getBoolProperties
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:168
RDEFAULT_MIN1
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RExplodable.h:30
mirror
void mirror(void e, void axis)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:42
RShape::getPointCloud
virtual QList< RVector > getPointCloud(double segmentLength) const =0
RShape::getBoundingBox
virtual RBox getBoundingBox() const =0
RShape::getSideOfPoint
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition: RShape.h:278
RExplodable::getExploded
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
RShape::getEndPoints
virtual QList< RVector > getEndPoints() const =0
RMAXDOUBLE
#define RMAXDOUBLE
Definition: RMath.h:63
trimEndPoint
void trimEndPoint(void shape, void trimPoint, void clickPoint)
Definition: library.js:690
RSpline::periodic
bool periodic
Closed periodic flag.
Definition: RSpline.h:311
RSpline::isDirected
virtual bool isDirected() const
Definition: RSpline.h:71
RShape::getStartPoint
virtual RVector getStartPoint() const
Definition: RShape.h:283
RShape::getPointsWithDistanceToEnd
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
RShape::isOnShape
virtual bool isOnShape(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: RShape.cpp:71
RPolyline.h
RArc.h
RSplineProxy.h
RShape::setZ
virtual void setZ(double z)=0
RSpline::weights
QList< double > weights
Getter function for this property: getWeights Setter function for this property: setWeights
Definition: RSpline.h:284
RS::FromAny
@ FromAny
Start or end.
Definition: RS.h:266
RShape::getDirection2
virtual double getDirection2() const
Definition: RShape.h:274
RShape::print
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1759
RShape::getMiddlePoint
virtual RVector getMiddlePoint() const
Definition: RShape.h:289
RDEFAULT_RBOX
#define RDEFAULT_RBOX
Definition: RBox.h:32
RSpline::isInterpolated
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RSpline.h:87
RSpline::boundingBox
RBox boundingBox
Definition: RSpline.h:320
RShape::reverse
virtual bool reverse()
Definition: RShape.h:293
RSpline::controlPoints
QList< RVector > controlPoints
Getter function for this property: getControlPoints Setter function for this property: setControlP...
Definition: RSpline.h:273
RBox
Represents a box e.g.
Definition: RBox.h:43
move
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:25
RVector::invalid
static const RVector invalid
invalid vector
Definition: RVector.h:322
RExplodable.h
RS::From
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:263
RExplodable
Interface for explodable shape classes.
Definition: RExplodable.h:40
RShape::getAngleAt
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:244
RShape::getEndPoint
virtual RVector getEndPoint() const
Definition: RShape.h:286
trimStartPoint
void trimStartPoint(void shape, void trimPoint, void clickPoint)
Definition: library.js:206
RPolyline
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
RShape::flipVertical
virtual bool flipVertical()
Definition: RShape.cpp:1736
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
scale
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:76
RSpline::getShapeType
virtual RShape::Type getShapeType() const
Definition: RSpline.h:63