QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 isPeriodic() const;
107 
108  virtual double getDirection1() const;
109  virtual double getDirection2() const;
110 
111  virtual RVector getStartPoint() const;
112  virtual RVector getEndPoint() const;
113 
114  void setStartPoint(const RVector& v);
115  void setEndPoint(const RVector& v);
116 
117  void setTangents(const RVector& start, const RVector& end);
118  void unsetTangents();
119 
120  void setTangentAtStart(const RVector& t);
121  RVector getTangentAtStart() const;
122  void unsetTangentAtStart();
123  void setTangentAtEnd(const RVector& t);
124  RVector getTangentAtEnd() const;
125  void unsetTangentAtEnd();
126 
127  void updateTangentsPeriodic();
128 
129  virtual RBox getBoundingBox() const;
130 
131  virtual double getLength() const;
132  RVector getPointAt(double t) const;
133 
134  virtual QList<RVector> getEndPoints() const;
135  RVector getMiddlePoint() const;
136  virtual QList<RVector> getMiddlePoints() const;
137  virtual QList<RVector> getCenterPoints() const;
138  virtual QList<RVector> getPointsWithDistanceToEnd(
139  double distance, RS::From from = RS::FromAny) const;
140 
141  virtual RVector getVectorTo(const RVector& point,
142  bool limited = true, double strictRange = RMAXDOUBLE) const;
143 
144  virtual bool move(const RVector& offset);
145  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
146  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
147  virtual bool mirror(const RLine& axis);
148  virtual bool flipHorizontal();
149  virtual bool flipVertical();
150  virtual bool reverse();
151 
152  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
153 
154  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
155  virtual void trimStartPoint(const RVector& p);
156  virtual void trimEndPoint(const RVector& p);
157 
158  RPolyline toPolyline(int segments) const;
159 
160  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
161 
162  QList<RSpline> getBezierSegments() const;
163 
164  bool isValid() const;
165  double getTDelta() const;
166  double getTMin() const;
167  double getTMax() const;
168  double getTAtPoint(const RVector& point) const;
169  QList<RSpline> getSegments(const QList<RVector>& points) const;
170  //bool getIntersectionPointsProxy(QList<RVector>& res, const RShape& other, bool limited, bool same) const;
171 
172  void updateFromControlPoints() const;
173  void updateFromFitPoints(bool useTangents = false) const;
174  void update() const;
175 
176  static bool hasProxy() {
177  return splineProxy!=NULL;
178  }
179 
183  static void setSplineProxy(RSplineProxy* p) {
184  splineProxy = p;
185  }
186 
187 protected:
188  void invalidate() const;
189  void updateInternal() const;
190  void updateBoundingBox() const;
191 
192 public:
193  // members are mutable, so the spline can update itself from fit points
194 
199  mutable QList<RVector> controlPoints;
200 
204  mutable QList<double> knotVector;
205 
209  mutable QList<double> weights;
210 
215  QList<RVector> fitPoints;
216 
221  mutable int degree;
222 
227 
232 
236  mutable bool periodic;
237 
238  mutable bool dirty;
239  mutable bool updateInProgress;
240 
241 protected:
242  virtual void print(QDebug dbg) const;
243 
244 private:
245 #ifndef R_NO_OPENNURBS
246  mutable ON_NurbsCurve curve;
247 #endif
248  mutable RBox boundingBox;
249  mutable QList<QSharedPointer<RShape> > exploded;
250 
252 };
253 
258 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
259 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
260 
261 #endif