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 "RDirected.h"
28 #include "RExplodable.h"
29 #include "RShape.h"
30 #include "RSplineProxy.h"
31 #include "RVector.h"
32 
33 #include "RPolyline.h"
34 
35 #ifndef R_NO_OPENNURBS
36 #include "opennurbs/opennurbs.h"
37 #endif
38 
39 
40 #ifndef RDEFAULT_MIN1
41 #define RDEFAULT_MIN1 -1
42 #endif
43 
56 class QCADCORE_EXPORT RSpline: public RShape, public RExplodable, public RDirected {
57 public:
58  RSpline();
59  RSpline(const QList<RVector>& controlPoints, int degree);
60  virtual ~RSpline();
61 
62  virtual RSpline* clone() const {
63  return new RSpline(*this);
64  }
65 
66  void copySpline(const RSpline& other);
67 
68  static QList<RSpline> createSplinesFromArc(const RArc& arc);
69  static RSpline createBezierFromSmallArc(double r, double a1, double a2);
70 
71  virtual void to2D();
72 
73  virtual bool isInterpolated() const {
74  return true;
75  }
76 
77  //virtual RVector getClosestPointOnShape(const RVector& p, bool limited) const;
78 
79  void appendControlPoint(const RVector& point);
80  void appendControlPoints(const QList<RVector>& points);
81  void removeLastControlPoint();
82  void setControlPoints(const QList<RVector>& points);
83  QList<RVector> getControlPoints() const;
84  QList<RVector> getControlPointsWrapped() const;
85  int countControlPoints() const;
86  RVector getControlPointAt(int i) const;
87 
88  void appendFitPoint(const RVector& point);
89  void prependFitPoint(const RVector& point);
90  void insertFitPointAt(const RVector& point);
91  void removeFitPointAt(const RVector& point);
92  void removeLastFitPoint();
93  void setFitPoints(const QList<RVector>& points);
94  QList<RVector> getFitPoints() const;
95  int countFitPoints() const;
96  bool hasFitPoints() const;
97 
98  QList<double> getKnotVector() const;
99  QList<double> getActualKnotVector() const;
100  void setKnotVector(const QList<double>& knots);
101  void appendKnot(double k);
102  QList<double> getWeights() const;
103 
104  void setDegree(int d);
105  int getDegree() const;
106 
107  int getOrder() const;
108 
109  void setPeriodic(bool on);
110  //bool isClosedPeriodic() const;
111 
112  bool isClosed() const;
113  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
114  bool isPeriodic() const;
115 
116  virtual double getDirection1() const;
117  virtual double getDirection2() const;
118 
119  virtual RS::Side getSideOfPoint(const RVector& point) const;
120 
121  virtual RVector getStartPoint() const;
122  virtual RVector getEndPoint() const;
123 
124  void setStartPoint(const RVector& v);
125  void setEndPoint(const RVector& v);
126 
127  void setTangents(const RVector& start, const RVector& end);
128  void unsetTangents();
129 
130  void setTangentAtStart(const RVector& t);
131  RVector getTangentAtStart() const;
132  void unsetTangentAtStart();
133  void setTangentAtEnd(const RVector& t);
134  RVector getTangentAtEnd() const;
135  void unsetTangentAtEnd();
136 
137  void updateTangentsPeriodic();
138 
139  virtual RBox getBoundingBox() const;
140 
141  virtual double getLength() const;
142  RVector getPointAt(double t) const;
143  RVector getPointAtDistance(double distance) const;
144  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
145 
146  virtual QList<RVector> getEndPoints() const;
147  RVector getMiddlePoint() const;
148  virtual QList<RVector> getMiddlePoints() const;
149  virtual QList<RVector> getCenterPoints() const;
150  virtual QList<RVector> getPointsWithDistanceToEnd(
151  double distance, RS::From from = RS::FromAny) const;
152 
153  virtual RVector getVectorTo(const RVector& point,
154  bool limited = true, double strictRange = RMAXDOUBLE) const;
155  virtual bool isOnShape(const RVector& point,
156  bool limited = true,
157  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
158 
159  virtual bool move(const RVector& offset);
160  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
161  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
162  virtual bool mirror(const RLine& axis);
163  virtual bool flipHorizontal();
164  virtual bool flipVertical();
165  virtual bool reverse();
166 
167  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
168 
169  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
170  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid);
171  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid);
172 
173  QList<RSpline> splitAtPoints(const QList<RVector>& points) const;
174  QList<RSpline> splitAtParams(const QList<double>& params) const;
175 
176  RPolyline toPolyline(int segments) const;
177 
178  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
179  QList<QSharedPointer<RShape> > getExplodedBezier(int segments) const;
180  QList<QSharedPointer<RShape> > getExplodedWithSegmentLength(double segmentLength) const;
181 
182  QList<RSpline> getBezierSegments() const;
183 
184  bool isValid() const;
185  double getTDelta() const;
186  double getTMin() const;
187  double getTMax() const;
188  double getTAtPoint(const RVector& point) const;
189  double getTAtDistance(double distance) const;
190  QList<RSpline> getSegments(const QList<RVector>& points) const;
191 
192  QList<RVector> getDiscontinuities() const;
193  RSpline simplify(double tolerance);
194 
195  void updateFromControlPoints() const;
196  void updateFromFitPoints(bool useTangents = false) const;
197  void update() const;
198 
199  bool isDirty() const {
200  return dirty;
201  }
202 
203  static bool hasProxy() {
204  return splineProxy!=NULL;
205  }
206 
210  static void setSplineProxy(RSplineProxy* p) {
211  if (splineProxy!=NULL) {
212  delete splineProxy;
213  }
214  splineProxy = p;
215  }
216 
221  return splineProxy;
222  }
223 
224 protected:
225  void appendToExploded(const RLine& line) const;
226  //void appendToExploded(QList<QSharedPointer<RShape> >& list) const;
227  void invalidate() const;
228  void updateInternal() const;
229  void updateBoundingBox() const;
230 
231 public:
232  // members are mutable, so the spline can update itself from fit points
233 
238  mutable QList<RVector> controlPoints;
239 
243  mutable QList<double> knotVector;
244 
248  mutable QList<double> weights;
249 
254  QList<RVector> fitPoints;
255 
260  mutable int degree;
261 
266 
271 
275  mutable bool periodic;
276 
277  mutable bool dirty;
278  mutable bool updateInProgress;
279 
280 protected:
281  virtual void print(QDebug dbg) const;
282 
283 private:
284 #ifndef R_NO_OPENNURBS
285  mutable ON_NurbsCurve curve;
286 #endif
287  mutable RBox boundingBox;
288  mutable QList<QSharedPointer<RShape> > exploded;
289 
291 };
292 
297 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
298 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
299 
300 #endif
bool periodic
Closed periodic flag.
Definition: RSpline.h:275
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid)=0
Represents a box e.g.
Definition: RBox.h:43
int degree
Getter function for this property: getDegree.
Definition: RSpline.h:260
Ending
Entity ending.
Definition: RS.h:149
ON_NurbsCurve curve
Definition: RSpline.h:285
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.
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
bool dirty
Definition: RSpline.h:277
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:56
RBox boundingBox
Definition: RSpline.h:287
static RSplineProxy * getSplineProxy()
Definition: RSpline.h:220
virtual QList< RVector > getEndPoints() const =0
Low-level mathematical representation of an arc.
Definition: RArc.h:41
virtual double getDirection1() const =0
static bool hasProxy()
Definition: RSpline.h:203
virtual RVector getEndPoint() const =0
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
#define QCADCORE_EXPORT
Definition: core_global.h:10
QList< RVector > controlPoints
Getter function for this property: getControlPoints.
Definition: RSpline.h:238
QList< double > knotVector
Getter function for this property: getKnotVector.
Definition: RSpline.h:243
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:62
Start or end.
Definition: RS.h:200
QList< RVector > fitPoints
Getter function for this property: getFitPoints.
Definition: RSpline.h:254
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:139
virtual bool move(const RVector &offset)=0
virtual bool flipHorizontal()
Definition: RShape.cpp:1656
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:151
static const double PointTolerance
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RS.h:549
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny) const =0
Q_DECLARE_METATYPE(RMath *)
static void setSplineProxy(RSplineProxy *p)
Definition: RSpline.h:210
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
virtual QList< RVector > getMiddlePoints() const =0
#define RMAXDOUBLE
Definition: RMath.h:63
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:42
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid)=0
Definition: RS.h:198
virtual bool mirror(const RLine &axis)=0
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RSpline.h:73
Low-level mathematical representation of a line.
Definition: RLine.h:42
virtual RS::Side getSideOfPoint(const RVector &point) const =0
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual RVector getStartPoint() const =0
static RSplineProxy * splineProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:290
virtual bool reverse()=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
virtual bool isOnShape(const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
Definition: RShape.cpp:53
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDirected.h:36
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:197
virtual double getDirection2() const =0
RVector tangentStart
Unit vector start tangent.
Definition: RSpline.h:265
virtual bool flipVertical()
Definition: RShape.cpp:1660
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1675
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
RVector tangentEnd
Unit vector end tangent.
Definition: RSpline.h:270
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1679
static const RVector invalid
invalid vector
Definition: RVector.h:307
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)=0
QList< QSharedPointer< RShape > > exploded
Definition: RSpline.h:288
QList< double > weights
Getter function for this property: getWeights.
Definition: RSpline.h:248
bool isDirty() const
Definition: RSpline.h:199
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
bool updateInProgress
Definition: RSpline.h:278