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  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
134 
135  virtual QList<RVector> getEndPoints() const;
136  RVector getMiddlePoint() const;
137  virtual QList<RVector> getMiddlePoints() const;
138  virtual QList<RVector> getCenterPoints() const;
139  virtual QList<RVector> getPointsWithDistanceToEnd(
140  double distance, RS::From from = RS::FromAny) const;
141 
142  virtual RVector getVectorTo(const RVector& point,
143  bool limited = true, double strictRange = RMAXDOUBLE) const;
144 
145  virtual bool move(const RVector& offset);
146  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
147  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
148  virtual bool mirror(const RLine& axis);
149  virtual bool flipHorizontal();
150  virtual bool flipVertical();
151  virtual bool reverse();
152 
153  QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
154 
155  virtual RS::Ending getTrimEnd(const RVector& coord, const RVector& trimPoint);
156  virtual void trimStartPoint(const RVector& p);
157  virtual void trimEndPoint(const RVector& p);
158 
159  RPolyline toPolyline(int segments) const;
160 
161  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
162  QList<QSharedPointer<RShape> > getExplodedWithSegmentLength(double segmentLength) const;
163 
164  QList<RSpline> getBezierSegments() const;
165 
166  bool isValid() const;
167  double getTDelta() const;
168  double getTMin() const;
169  double getTMax() const;
170  double getTAtPoint(const RVector& point) const;
171  QList<RSpline> getSegments(const QList<RVector>& points) const;
172  //bool getIntersectionPointsProxy(QList<RVector>& res, const RShape& other, bool limited, bool same) const;
173 
174  void updateFromControlPoints() const;
175  void updateFromFitPoints(bool useTangents = false) const;
176  void update() const;
177 
178  static bool hasProxy() {
179  return splineProxy!=NULL;
180  }
181 
185  static void setSplineProxy(RSplineProxy* p) {
186  splineProxy = p;
187  }
188 
193  return splineProxy;
194  }
195 
196 protected:
197  void appendToExploded(const RLine& line) const;
198  void invalidate() const;
199  void updateInternal() const;
200  void updateBoundingBox() const;
201 
202 public:
203  // members are mutable, so the spline can update itself from fit points
204 
209  mutable QList<RVector> controlPoints;
210 
214  mutable QList<double> knotVector;
215 
219  mutable QList<double> weights;
220 
225  QList<RVector> fitPoints;
226 
231  mutable int degree;
232 
237 
242 
246  mutable bool periodic;
247 
248  mutable bool dirty;
249  mutable bool updateInProgress;
250 
251 protected:
252  virtual void print(QDebug dbg) const;
253 
254 private:
255 #ifndef R_NO_OPENNURBS
256  mutable ON_NurbsCurve curve;
257 #endif
258  mutable RBox boundingBox;
259  mutable QList<QSharedPointer<RShape> > exploded;
260 
262 };
263 
268 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
269 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
270 
271 #endif