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 removeLastFitPoint();
108  void setFitPoints(const QList<RVector>& points);
109  QList<RVector> getFitPoints() const;
110  int countFitPoints() const;
111  bool hasFitPoints() const;
112  RVector getFitPointAt(int i) const;
113 
114  QList<double> getKnotVector() const;
115  QList<double> getActualKnotVector() const;
116  void setKnotVector(const QList<double>& knots);
117  void appendKnot(double k);
118  QList<double> getWeights() const;
119 
120  void setDegree(int d);
121  int getDegree() const;
122 
123  int getOrder() const;
124 
125  void setPeriodic(bool on);
126  //bool isClosedPeriodic() const;
127 
128  bool isClosed() const;
129  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
130  bool isPeriodic() const;
131 
132  virtual double getDirection1() const;
133  virtual double getDirection2() const;
134 
135  virtual RS::Side getSideOfPoint(const RVector& point) const;
136 
137  virtual RVector getStartPoint() const;
138  virtual RVector getEndPoint() const;
139 
140  void setStartPoint(const RVector& v);
141  void setEndPoint(const RVector& v);
142 
143  void setTangents(const RVector& start, const RVector& end);
144  void unsetTangents();
145 
146  void setTangentAtStart(const RVector& t);
147  RVector getTangentAtStart() const;
148  void unsetTangentAtStart();
149  void setTangentAtEnd(const RVector& t);
150  RVector getTangentAtEnd() const;
151  void unsetTangentAtEnd();
152 
153  void updateTangentsPeriodic();
154 
155  virtual RBox getBoundingBox() const;
156 
157  virtual double getLength() const;
158  RVector getPointAt(double t) const;
159  RVector getPointAtDistance(double distance) const;
160  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
161 
162  virtual QList<RVector> getEndPoints() const;
163  virtual RVector getMiddlePoint() const;
164  virtual QList<RVector> getMiddlePoints() const;
165  virtual QList<RVector> getCenterPoints() const;
166  virtual QList<RVector> getPointsWithDistanceToEnd(
167  double distance, int from = RS::FromAny) const;
168  virtual QList<RVector> getPointCloud(double segmentLength) const;
169 
170  virtual RVector getVectorTo(const RVector& point,
171  bool limited = true, double strictRange = RMAXDOUBLE) const;
172  virtual bool isOnShape(const RVector& point,
173  bool limited = true,
174  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
175 
176  virtual bool move(const RVector& offset);
177  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
178  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
179  virtual bool mirror(const RLine& axis);
180  virtual bool flipHorizontal();
181  virtual bool flipVertical();
182  virtual bool reverse();
183  virtual bool stretch(const RPolyline& area, const RVector& offset);
184 
185  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
186 
187  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
188  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
189  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
190  virtual bool trimStartPoint(double trimDist) {
191  return RShape::trimStartPoint(trimDist);
192  }
193  virtual bool trimEndPoint(double trimDist) {
194  return RShape::trimEndPoint(trimDist);
195  }
196  virtual double getDistanceFromStart(const RVector& p) const;
197 
198  QList<RSpline> splitAtPoints(const QList<RVector>& points) const;
199  QList<RSpline> splitAtParams(const QList<double>& params) const;
200 
201  RPolyline toPolyline(int segments) const;
202  RPolyline approximateWithArcs(double tolerance) const;
203 
204  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
205  QList<QSharedPointer<RShape> > getExplodedBezier(int segments) const;
206  QList<QSharedPointer<RShape> > getExplodedWithSegmentLength(double segmentLength) const;
207 
208  QList<RSpline> getBezierSegments(const RBox& queryBox = RDEFAULT_RBOX) const;
209 
210  bool isValid() const;
211  double getTDelta() const;
212  double getTMin() const;
213  double getTMax() const;
214  double getTAtPoint(const RVector& point) const;
215  double getTAtDistance(double distance) const;
216  double getDistanceAtT(double t) const;
217  QList<RSpline> getSegments(const QList<RVector>& points) const;
218 
219  QList<RVector> getDiscontinuities() const;
220  RSpline simplify(double tolerance);
221 
222  void updateFromControlPoints() const;
223  void updateFromFitPoints() const;
224  void update() const;
225 
226  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
227 
228  bool isDirty() const {
229  return dirty;
230  }
231 
232  QList<RVector> getSelfIntersectionPoints() const;
233 
234  static bool hasProxy() {
235  return splineProxy!=NULL;
236  }
237 
241  static void setSplineProxy(RSplineProxy* p) {
242  if (splineProxy!=NULL) {
243  delete splineProxy;
244  }
245  splineProxy = p;
246  }
247 
252  return splineProxy;
253  }
254 
255 protected:
256  void appendToExploded(const RLine& line) const;
257  //void appendToExploded(QList<QSharedPointer<RShape> >& list) const;
258  void invalidate() const;
259  void updateInternal() const;
260  void updateBoundingBox() const;
261 
262  virtual void print(QDebug dbg) const;
263 
264 public:
265  // members are mutable, so the spline can update itself from fit points
266 
271  mutable QList<RVector> controlPoints;
272 
276  mutable QList<double> knotVector;
277 
281  mutable QList<double> weights;
282 
287  QList<RVector> fitPoints;
288 
293  mutable int degree;
294 
299 
304 
308  mutable bool periodic;
309 
310  mutable bool dirty;
311  mutable bool updateInProgress;
312 
313 private:
314 #ifndef R_NO_OPENNURBS
315  mutable ON_NurbsCurve curve;
316 #endif
317  mutable RBox boundingBox;
318  mutable QList<QSharedPointer<RShape> > exploded;
319  // cached length:
320  mutable double length;
321 
323 };
324 
328 Q_DECLARE_METATYPE(QList<RSpline>)
329 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
330 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
331 
332 #endif
RSpline::fitPoints
QList< RVector > fitPoints
Getter function for this property: getFitPoints Setter function for this property: setFitPoints
Definition: RSpline.h:287
RSpline::tangentStart
RVector tangentStart
Unit vector start tangent.
Definition: RSpline.h:298
RSpline::length
double length
Definition: RSpline.h:320
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:311
RSpline::hasProxy
static bool hasProxy()
Definition: RSpline.h:234
RSpline::trimEndPoint
virtual bool trimEndPoint(double trimDist)
Definition: RSpline.h:193
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:241
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:303
RShape::stretch
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1740
RSpline::dirty
bool dirty
Definition: RSpline.h:310
RSpline::isDirty
bool isDirty() const
Definition: RSpline.h:228
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:32
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 relativ to an entity (right hand or left hand side)
Definition: RS.h:204
RS::PointTolerance
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RS.h:696
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:214
RS::FromStart
@ FromStart
Definition: RS.h:263
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:21
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:315
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RSpline::getSplineProxy
static RSplineProxy * getSplineProxy()
Definition: RSpline.h:251
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:190
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:293
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:322
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:38
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:318
RSpline::knotVector
QList< double > knotVector
Getter function for this property: getKnotVector
Definition: RSpline.h:276
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:18
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:280
RSpline::periodic
bool periodic
Closed periodic flag.
Definition: RSpline.h:308
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
Definition: RSpline.h:281
RS::FromAny
@ FromAny
Start or end.
Definition: RS.h:265
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:317
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:271
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:60
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:262
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:376
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:46
RSpline::getShapeType
virtual RShape::Type getShapeType() const
Definition: RSpline.h:63