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 "RVector.h"
31 
32 #ifndef R_NO_OPENNURBS
33 #include "opennurbs/opennurbs.h"
34 #endif
35 
36 class RSplineProxy;
37 
38 #ifndef RDEFAULT_MIN1
39 #define RDEFAULT_MIN1 -1
40 #endif
41 
54 class QCADCORE_EXPORT RSpline: public RShape, public RExplodable, public RDirected {
55 public:
56  RSpline();
57  RSpline(const QList<RVector>& controlPoints, int degree);
58  virtual ~RSpline();
59 
60  virtual RSpline* clone() const {
61  return new RSpline(*this);
62  }
63 
64  void copySpline(const RSpline& other);
65 
66  static QList<RSpline> createSplinesFromArc(const RArc& arc);
67  static RSpline createBezierFromSmallArc(double r, double a1, double a2);
68 
69  virtual void to2D();
70 
71  virtual bool isInterpolated() const {
72  return true;
73  }
74 
75  //virtual RVector getClosestPointOnShape(const RVector& p, bool limited) const;
76 
77  void appendControlPoint(const RVector& point);
78  void removeLastControlPoint();
79  void setControlPoints(const QList<RVector>& points);
80  QList<RVector> getControlPoints() const;
81  QList<RVector> getControlPointsWrapped() const;
82  int countControlPoints() const;
83 
84  void appendFitPoint(const RVector& point);
85  void removeLastFitPoint();
86  void setFitPoints(const QList<RVector>& points);
87  QList<RVector> getFitPoints() const;
88  int countFitPoints() const;
89  bool hasFitPoints() const;
90 
91  QList<double> getKnotVector() const;
92  QList<double> getActualKnotVector() const;
93  void setKnotVector(const QList<double>& knots);
94  void appendKnot(double k);
95  QList<double> getWeights() const;
96 
97  void setDegree(int d);
98  int getDegree() const;
99 
100  int getOrder() const;
101 
102  void setPeriodic(bool on);
103  //bool isClosedPeriodic() const;
104 
105  bool isClosed() const;
106  bool isGeometricallyClosed(double tolerance=RS::PointTolerance) const;
107  bool isPeriodic() const;
108 
109  virtual double getDirection1() const;
110  virtual double getDirection2() const;
111 
112  virtual RVector getStartPoint() const;
113  virtual RVector getEndPoint() const;
114 
115  void setStartPoint(const RVector& v);
116  void setEndPoint(const RVector& v);
117 
118  void setTangents(const RVector& start, const RVector& end);
119  void unsetTangents();
120 
121  void setTangentAtStart(const RVector& t);
122  RVector getTangentAtStart() const;
123  void unsetTangentAtStart();
124  void setTangentAtEnd(const RVector& t);
125  RVector getTangentAtEnd() const;
126  void unsetTangentAtEnd();
127 
128  void updateTangentsPeriodic();
129 
130  virtual RBox getBoundingBox() const;
131 
132  virtual double getLength() const;
133  RVector getPointAt(double t) const;
134  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
135 
136  virtual QList<RVector> getEndPoints() const;
137  RVector getMiddlePoint() const;
138  virtual QList<RVector> getMiddlePoints() const;
139  virtual QList<RVector> getCenterPoints() const;
140  virtual QList<RVector> getPointsWithDistanceToEnd(
141  double distance, RS::From from = RS::FromAny) const;
142 
143  virtual RVector getVectorTo(const RVector& point,
144  bool limited = true, double strictRange = RMAXDOUBLE) const;
145 
146  virtual bool move(const RVector& offset);
147  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
148  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
149  virtual bool mirror(const RLine& axis);
150  virtual bool flipHorizontal();
151  virtual bool flipVertical();
152  virtual bool reverse();
153 
154  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
155 
156  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
157  virtual void trimStartPoint(const RVector& p);
158  virtual void trimEndPoint(const RVector& p);
159 
160  RPolyline toPolyline(int segments) const;
161 
162  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
163  QList<QSharedPointer<RShape> > getExplodedBezier(int segments) const;
164  QList<QSharedPointer<RShape> > getExplodedWithSegmentLength(double segmentLength) const;
165 
166  QList<RSpline> getBezierSegments() const;
167 
168  bool isValid() const;
169  double getTDelta() const;
170  double getTMin() const;
171  double getTMax() const;
172  double getTAtPoint(const RVector& point) const;
173  QList<RSpline> getSegments(const QList<RVector>& points) const;
174  //bool getIntersectionPointsProxy(QList<RVector>& res, const RShape& other, bool limited, bool same) const;
175 
176  void updateFromControlPoints() const;
177  void updateFromFitPoints(bool useTangents = false) const;
178  void update() const;
179 
180  static bool hasProxy() {
181  return splineProxy!=NULL;
182  }
183 
187  static void setSplineProxy(RSplineProxy* p) {
188  splineProxy = p;
189  }
190 
195  return splineProxy;
196  }
197 
198 protected:
199  void appendToExploded(const RLine& line) const;
200  //void appendToExploded(QList<QSharedPointer<RShape> >& list) const;
201  void invalidate() const;
202  void updateInternal() const;
203  void updateBoundingBox() const;
204 
205 public:
206  // members are mutable, so the spline can update itself from fit points
207 
212  mutable QList<RVector> controlPoints;
213 
217  mutable QList<double> knotVector;
218 
222  mutable QList<double> weights;
223 
228  QList<RVector> fitPoints;
229 
234  mutable int degree;
235 
240 
245 
249  mutable bool periodic;
250 
251  mutable bool dirty;
252  mutable bool updateInProgress;
253 
254 protected:
255  virtual void print(QDebug dbg) const;
256 
257 private:
258 #ifndef R_NO_OPENNURBS
259  mutable ON_NurbsCurve curve;
260 #endif
261  mutable RBox boundingBox;
262  mutable QList<QSharedPointer<RShape> > exploded;
263 
265 };
266 
271 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
272 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
273 
274 #endif
bool periodic
Closed periodic flag.
Definition: RSpline.h:249
Represents a box e.g.
Definition: RBox.h:43
int degree
Getter function for this property: getDegree.
Definition: RSpline.h:234
Ending
Entity ending.
Definition: RS.h:136
ON_NurbsCurve curve
Definition: RSpline.h:259
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:251
Low-level mathematical representation of a spline.
Definition: RSpline.h:54
RBox boundingBox
Definition: RSpline.h:261
static RSplineProxy * getSplineProxy()
Definition: RSpline.h:194
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:180
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:212
virtual void trimStartPoint(const RVector &p)=0
QList< double > knotVector
Getter function for this property: getKnotVector.
Definition: RSpline.h:217
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RSplineProxy.h:34
virtual RS::Ending getTrimEnd(const RVector &coord, const RVector &trimPoint)=0
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
virtual RSpline * clone() const
Definition: RSpline.h:60
Start or end.
Definition: RS.h:187
QList< RVector > fitPoints
Getter function for this property: getFitPoints.
Definition: RSpline.h:228
virtual bool move(const RVector &offset)=0
virtual bool flipHorizontal()
Definition: RShape.cpp:1600
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:135
static const double PointTolerance
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RS.h:524
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:187
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
virtual void trimEndPoint(const RVector &p)=0
virtual QList< RVector > getMiddlePoints() const =0
#define RMAXDOUBLE
Definition: RMath.h:50
Definition: RS.h:185
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:71
Low-level mathematical representation of a line.
Definition: RLine.h:42
#define RDEFAULT_MIN1
Copyright (c) 2011-2015 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-2015 by Andrew Mustun.
Definition: RSpline.h:264
virtual bool reverse()=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
Copyright (c) 2011-2015 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:184
virtual double getDirection2() const =0
RVector tangentStart
Unit vector start tangent.
Definition: RSpline.h:239
virtual bool flipVertical()
Definition: RShape.cpp:1604
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1619
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:244
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1623
QList< QSharedPointer< RShape > > exploded
Definition: RSpline.h:262
QList< double > weights
Getter function for this property: getWeights.
Definition: RSpline.h:222
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
bool updateInProgress
Definition: RSpline.h:252