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