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