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 
163  QList<RSpline> getBezierSegments() const;
164 
165  bool isValid() const;
166  double getTDelta() const;
167  double getTMin() const;
168  double getTMax() const;
169  double getTAtPoint(const RVector& point) const;
170  QList<RSpline> getSegments(const QList<RVector>& points) const;
171  //bool getIntersectionPointsProxy(QList<RVector>& res, const RShape& other, bool limited, bool same) const;
172 
173  void updateFromControlPoints() const;
174  void updateFromFitPoints(bool useTangents = false) const;
175  void update() const;
176 
177  static bool hasProxy() {
178  return splineProxy!=NULL;
179  }
180 
184  static void setSplineProxy(RSplineProxy* p) {
185  splineProxy = p;
186  }
187 
192  return splineProxy;
193  }
194 
195 protected:
196  void invalidate() const;
197  void updateInternal() const;
198  void updateBoundingBox() const;
199 
200 public:
201  // members are mutable, so the spline can update itself from fit points
202 
207  mutable QList<RVector> controlPoints;
208 
212  mutable QList<double> knotVector;
213 
217  mutable QList<double> weights;
218 
223  QList<RVector> fitPoints;
224 
229  mutable int degree;
230 
235 
240 
244  mutable bool periodic;
245 
246  mutable bool dirty;
247  mutable bool updateInProgress;
248 
249 protected:
250  virtual void print(QDebug dbg) const;
251 
252 private:
253 #ifndef R_NO_OPENNURBS
254  mutable ON_NurbsCurve curve;
255 #endif
256  mutable RBox boundingBox;
257  mutable QList<QSharedPointer<RShape> > exploded;
258 
260 };
261 
266 Q_DECLARE_METATYPE(QSharedPointer<RSpline>)
267 Q_DECLARE_METATYPE(QSharedPointer<RSpline>*)
268 
269 #endif