QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RSpline Class Reference

Low-level mathematical representation of a 2nd or 3rd degree spline. More...

#include <RSpline.h>

Inheritance diagram for RSpline:
RShape RExplodable RDirected RSplineData

List of all members.

Public Member Functions

void appendControlPoint (const RVector &point)
 Disabled for splines (bad performance).
void appendFitPoint (const RVector &point)
 Appends a fit point.
void appendKnot (double k)
virtual RSplineclone () const
void copySpline (const RSpline &other)
int countControlPoints () const
int countFitPoints () const
virtual bool flipHorizontal ()
virtual bool flipVertical ()
QList< double > getActualKnotVector () const
QList< RSplinegetBezierSegments () const
virtual RBox getBoundingBox () const
virtual QList< RVectorgetCenterPoints () const
QList< RVectorgetControlPoints () const
QList< RVectorgetControlPointsWrapped () const
int getDegree () const
virtual double getDirection1 () const
virtual double getDirection2 () const
virtual RVector getEndPoint () const
virtual QList< RVectorgetEndPoints () const
virtual QList< QSharedPointer
< RShape > > 
getExploded (int segments=RDEFAULT_MIN1) const
QList< RVectorgetFitPoints () const
QList< double > getKnotVector () const
virtual double getLength () const
RVector getMiddlePoint () const
virtual QList< RVectorgetMiddlePoints () const
int getOrder () const
RVector getPointAt (double t) const
virtual QList< RVectorgetPointsWithDistanceToEnd (double distance, RS::From from=RS::FromAny) const
QList< RSplinegetSegments (const QList< RVector > &points) const
virtual RVector getStartPoint () const
RVector getTangentAtEnd () const
RVector getTangentAtStart () const
double getTAtPoint (const RVector &point) const
double getTDelta () const
double getTMax () const
double getTMin () const
QSharedPointer< RShapegetTransformed (const QTransform &transform) const
virtual RS::Ending getTrimEnd (const RVector &coord, const RVector &trimPoint)
virtual RVector getVectorTo (const RVector &point, bool limited=true) const
QList< double > getWeights () const
bool hasFitPoints () const
bool isClosed () const
virtual bool isInterpolated () const
 Reimplement and return true if this shape relies on interpolation for geometrical operations such as finding intersection points.
bool isPeriodic () const
bool isValid () const
virtual bool mirror (const RLine &axis)
virtual bool move (const RVector &offset)
void removeLastControlPoint ()
 Removes the last control point.
void removeLastFitPoint ()
 Removes the last fit point.
virtual bool reverse ()
virtual bool rotate (double rotation, const RVector &center=RDEFAULT_RVECTOR)
 RSpline ()
 Creates a spline object without controlPoints.
 RSpline (const QList< RVector > &controlPoints, int degree)
 Creates a spline object with the given control points and degree.
virtual bool scale (const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
void setControlPoints (const QList< RVector > &points)
 Sets the control points of this spline.
void setDegree (int d)
 Sets the degree of this spline (2 or 3 for control point defined spline, 3 for fit point defined spline).
void setEndPoint (const RVector &v)
void setFitPoints (const QList< RVector > &points)
 Sets the fit points.
void setKnotVector (const QList< double > &knots)
 Sets the knot vector manually.
void setPeriodic (bool on)
void setStartPoint (const RVector &v)
void setTangentAtEnd (const RVector &t)
 Sets the end tangent.
void setTangentAtStart (const RVector &t)
 Sets the start tangent.
void setTangents (const RVector &start, const RVector &end)
 Sets the start and end tangents.
virtual void to2D ()
 Flattens this shape to the X/Y plane.
RPolyline toPolyline (int segments) const
virtual void trimEndPoint (const RVector &p)
virtual void trimStartPoint (const RVector &p)
void unsetTangentAtEnd ()
 Clears the valud of the end tangent.
void unsetTangentAtStart ()
 Clears the valud of the start tangent.
void unsetTangents ()
 Clears the valud of the start and end tangents.
void update () const
void updateFromControlPoints () const
void updateFromFitPoints (bool useTangents=false) const
 Closes this spline and makes it periodic if it isn't already.
void updateTangentsPeriodic ()
 Updates the tangents at the start and end to make the spline periodic.
virtual ~RSpline ()
- Public Member Functions inherited from RShape
void dump ()
virtual QList< RVectorfilterOnShape (const QList< RVector > &pointList, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
virtual RVector getClosestPointOnShape (const RVector &p, bool limited=true) const
virtual double getDistanceTo (const RVector &point, bool limited=true) const
QList< RVectorgetIntersectionPoints (const RShape &other, bool limited=true, bool same=false, bool force=false) const
virtual RVector getPointAtPercent (double p) const
virtual RVector getVectorFromEndpointTo (const RVector &point) const
virtual bool intersectsWith (const RShape &other, bool limited=true) const
virtual bool isOnShape (const RVector &point, bool limited=true, double tolerance=RDEFAULT_TOLERANCE_1E_MIN4) const
 RShape ()
virtual bool scale (double scaleFactor, const RVector &center=RVector())
virtual bool stretch (const RBox &area, const RVector &offset)
virtual bool stretch (const RPolyline &area, const RVector &offset)
virtual ~RShape ()
- Public Member Functions inherited from RExplodable
virtual ~RExplodable ()
- Public Member Functions inherited from RDirected
virtual double getDistanceFromStart (const RVector &p) const
virtual ~RDirected ()

Static Public Member Functions

static RSpline createBezierFromSmallArc (double r, double a1, double a2)
 Cubic bezier approximation of a circular arc centered at the origin, from (radians) a1 to a2, where a2-a1 < pi/2.
static QList< RSplinecreateSplinesFromArc (const RArc &arc)
static bool hasProxy ()
static void setSplineProxy (RSplineProxy *p)
- Static Public Member Functions inherited from RShape
static const RExplodablecastToExplodable (const RShape *shape)
static QList< RVectorgetIntersectionPoints (const RShape &shape1, const RShape &shape2, bool limited=true, bool same=false, bool force=false)
static QList< RVectorgetIntersectionPointsAA (const RArc &arc1, const RArc &arc2, bool limited=true)
static QList< RVectorgetIntersectionPointsAC (const RArc &arc1, const RCircle &circle2, bool limited=true)
static QList< RVectorgetIntersectionPointsAE (const RArc &arc1, const REllipse &ellipse2, bool limited=true)
static QList< RVectorgetIntersectionPointsAS (const RArc &arc1, const RSpline &spline2, bool limited=true)
static QList< RVectorgetIntersectionPointsAT (const RArc &arc1, const RTriangle &triangle2, bool limited=true)
static QList< RVectorgetIntersectionPointsAX (const RArc &arc1, const RExplodable &explodable2, bool limited=true)
static QList< RVectorgetIntersectionPointsCC (const RCircle &circle1, const RCircle &circle2)
static QList< RVectorgetIntersectionPointsCE (const RCircle &circle1, const REllipse &ellipse2)
static QList< RVectorgetIntersectionPointsCS (const RCircle &circle1, const RSpline &spline2, bool limited=true)
static QList< RVectorgetIntersectionPointsCX (const RCircle &circle1, const RExplodable &explodable2, bool limited=true)
static QList< RVectorgetIntersectionPointsEE (const REllipse &ellipse1, const REllipse &ellipse2)
static QList< RVectorgetIntersectionPointsEE (const REllipse &ellipse1, const REllipse &ellipse2, bool limited)
static QList< RVectorgetIntersectionPointsES (const REllipse &ellipse1, const RSpline &spline2, bool limited=true)
static QList< RVectorgetIntersectionPointsEX (const REllipse &ellipse1, const RExplodable &explodable2, bool limited=true)
static QList< RVectorgetIntersectionPointsLA (const RLine &line1, const RArc &arc2, bool limited=true)
static QList< RVectorgetIntersectionPointsLA (const RLine &line1, const RArc &arc2, bool limited1, bool limited2)
static QList< RVectorgetIntersectionPointsLC (const RLine &line1, const RCircle &circle2, bool limited=true)
static QList< RVectorgetIntersectionPointsLE (const RLine &line1, const REllipse &ellipse2, bool limited=true)
static QList< RVectorgetIntersectionPointsLE (const RLine &line1, const REllipse &ellipse2, bool limited1, bool limited2)
static QList< RVectorgetIntersectionPointsLL (const RLine &line1, const RLine &line2, bool limited=true)
static QList< RVectorgetIntersectionPointsLL (const RLine &line1, const RLine &line2, bool limited1, bool limited2)
static QList< RVectorgetIntersectionPointsLS (const RLine &line1, const RSpline &spline2, bool limited=true)
static QList< RVectorgetIntersectionPointsLT (const RLine &line1, const RTriangle &triangle2, bool limited=true)
static QList< RVectorgetIntersectionPointsLT (const RLine &line1, const RTriangle &triangle2, bool limited1, bool limited2)
static QList< RVectorgetIntersectionPointsLX (const RLine &line1, const RExplodable &explodable2, bool limited=true)
static QList< RVectorgetIntersectionPointsXX (const RExplodable &explodable1, const RExplodable &explodable2, bool limited=true, bool same=false)
static bool order (QList< QList< QSharedPointer< RShape > > > &boundary)
 Orders the given list of loops into a list of closed loops in which all shapes are connected end to start point.

Public Attributes

QList< RVectorcontrolPoints
 Getter function for this property: getControlPoints.
int degree
 Getter function for this property: getDegree.
bool dirty
QList< RVectorfitPoints
 Getter function for this property: getFitPoints.
QList< double > knotVector
 Getter function for this property: getKnotVector.
bool periodic
 Closed periodic flag.
RVector tangentEnd
 Unit vector end tangent.
RVector tangentStart
 Unit vector start tangent.
bool updateInProgress
QList< double > weights
 Getter function for this property: getWeights.

Protected Member Functions

void invalidate () const
virtual void print (QDebug dbg) const
void updateBoundingBox () const
 Updates the internal bounding box.
void updateInternal () const

Private Attributes

RBox boundingBox
ON_NurbsCurve curve
QList< QSharedPointer< RShape > > exploded

Static Private Attributes

static RSplineProxysplineProxy = NULL
 Copyright (c) 2011-2013 by Andrew Mustun.

Detailed Description

Low-level mathematical representation of a 2nd or 3rd degree spline.

The spline may be defined by its control points or by its fit points but not both.

Scriptable:
This class is wrapped for script environments.
Shared Pointer Support:
Script wrappers of this class support wrapping in QSharedPointer.
Copyable:
Script wrappers of this class should pass objects by reference.
Stream Operator:
Script wrappers of this class use the stream operator for the output of toString().

Constructor & Destructor Documentation

RSpline::RSpline ( )

Creates a spline object without controlPoints.

RSpline::RSpline ( const QList< RVector > &  controlPoints,
int  degree 
)

Creates a spline object with the given control points and degree.

RSpline::~RSpline ( )
virtual

Member Function Documentation

void RSpline::appendControlPoint ( const RVector point)

Disabled for splines (bad performance).

20120223: Re-enabled, seems to perform OK, needed by some users. Appends a control point.

Reimplemented in RSplineData.

void RSpline::appendFitPoint ( const RVector point)

Appends a fit point.

void RSpline::appendKnot ( double  k)
virtual RSpline* RSpline::clone ( ) const
inlinevirtual

Implements RShape.

void RSpline::copySpline ( const RSpline other)
int RSpline::countControlPoints ( ) const
Returns:
Number of control points.
int RSpline::countFitPoints ( ) const
Returns:
Number of fit points.
RSpline RSpline::createBezierFromSmallArc ( double  r,
double  a1,
double  a2 
)
static

Cubic bezier approximation of a circular arc centered at the origin, from (radians) a1 to a2, where a2-a1 < pi/2.

The arc's radius is r.

Returns an spline approximation.

This algorithm is based on the approach described in: A. Riškus, "Approximation of a Cubic Bezier Curve by Circular Arcs and Vice Versa," Information Technology and Control, 35(4), 2006 pp. 371-378.

QList< RSpline > RSpline::createSplinesFromArc ( const RArc arc)
static
Returns:
List of splines which approximate the given arc.
bool RSpline::flipHorizontal ( )
virtual

Reimplemented from RShape.

bool RSpline::flipVertical ( )
virtual

Reimplemented from RShape.

QList< double > RSpline::getActualKnotVector ( ) const

Reimplemented in RSplineData.

QList< RSpline > RSpline::getBezierSegments ( ) const
Returns:
List of bezier spline segments which together represent this curve.
RBox RSpline::getBoundingBox ( ) const
virtual
Returns:
The bounding box of this shape.

Implements RShape.

Reimplemented in RSplineData.

QList< RVector > RSpline::getCenterPoints ( ) const
virtual
Returns:
The center point(s) of this shape.

Implements RShape.

QList< RVector > RSpline::getControlPoints ( ) const
Returns:
Control points.

Reimplemented in RSplineData.

QList< RVector > RSpline::getControlPointsWrapped ( ) const
Returns:
Control points of internal spline representation (may be closed).

Reimplemented in RSplineData.

int RSpline::getDegree ( ) const
Returns:
Degree of this spline.

Reimplemented in RSplineData.

double RSpline::getDirection1 ( ) const
virtual
Returns:
Tangent angle of spline at start point.

Implements RDirected.

Reimplemented in RSplineData.

double RSpline::getDirection2 ( ) const
virtual
Returns:
Tangent angle of spline at end point.

Implements RDirected.

Reimplemented in RSplineData.

RVector RSpline::getEndPoint ( ) const
virtual

Implements RDirected.

Reimplemented in RSplineData.

QList< RVector > RSpline::getEndPoints ( ) const
virtual
Returns:
The end point(s) of this shape.

Implements RShape.

QList< QSharedPointer< RShape > > RSpline::getExploded ( int  segments = RDEFAULT_MIN1) const
virtual
Returns:
List of RLines describing this spline.

Implements RExplodable.

QList< RVector > RSpline::getFitPoints ( ) const
Returns:
Fit points.

Reimplemented in RSplineData.

QList< double > RSpline::getKnotVector ( ) const
Returns:
Knot vector, internally calculated and updated.

Reimplemented in RSplineData.

double RSpline::getLength ( ) const
virtual
Returns:
The total length of this shape if applicable or NaN if not.

Implements RShape.

RVector RSpline::getMiddlePoint ( ) const
QList< RVector > RSpline::getMiddlePoints ( ) const
virtual
Returns:
The middle point(s) of this shape.

Implements RShape.

int RSpline::getOrder ( ) const
Returns:
Order of this spline (=degree+1).
RVector RSpline::getPointAt ( double  t) const
Returns:
Point on spline at given position t (0..1).
QList< RVector > RSpline::getPointsWithDistanceToEnd ( double  distance,
RS::From  from = RS::FromAny 
) const
virtual
Returns:
All points on this shape with the given distance to an endpoint.

Implements RShape.

QList< RSpline > RSpline::getSegments ( const QList< RVector > &  points) const
RVector RSpline::getStartPoint ( ) const
virtual

Implements RDirected.

Reimplemented in RSplineData.

RVector RSpline::getTangentAtEnd ( ) const
Returns:
The end tangent.

Reimplemented in RSplineData.

RVector RSpline::getTangentAtStart ( ) const
Returns:
The start tangent.

Reimplemented in RSplineData.

double RSpline::getTAtPoint ( const RVector point) const
double RSpline::getTDelta ( ) const
double RSpline::getTMax ( ) const
double RSpline::getTMin ( ) const
QSharedPointer< RShape > RSpline::getTransformed ( const QTransform &  transform) const
virtual

Implements RShape.

RS::Ending RSpline::getTrimEnd ( const RVector coord,
const RVector trimPoint 
)
virtual
Parameters:
coordClicked coordiante
trimPointTrim start point or end point to this coordiante.

Implements RDirected.

Reimplemented in RSplineData.

RVector RSpline::getVectorTo ( const RVector point,
bool  limited = true 
) const
virtual
Returns:
Shortest vector from this shape to the given point.
Parameters:
pointthe given point
limitedIf false, the shape is treaded as an unlimited shape that extends in a logical way. For example an unlimited line for a line, full circle for an arc or a plane for a triangle.

Implements RShape.

QList< double > RSpline::getWeights ( ) const
Returns:
Knot weights, internally calculated and updated.

Reimplemented in RSplineData.

bool RSpline::hasFitPoints ( ) const
Returns:
True if this spline has fit points and is therefore defined by its fit points, false otherwise.
static bool RSpline::hasProxy ( )
inlinestatic
void RSpline::invalidate ( ) const
protected
bool RSpline::isClosed ( ) const
Returns:
True if this spline is closed, i.e. start point and end point are very close to each other.

Reimplemented in RSplineData.

virtual bool RSpline::isInterpolated ( ) const
inlinevirtual

Reimplement and return true if this shape relies on interpolation for geometrical operations such as finding intersection points.

E.g. splines.

Reimplemented from RShape.

bool RSpline::isPeriodic ( ) const
Returns:
True if this spline is periodic, i.e. closed and 'smooth' where start and end connect. The tangents at the start point and end point are nearly identical.

Reimplemented in RSplineData.

bool RSpline::isValid ( ) const

Reimplemented in RSplineData.

bool RSpline::mirror ( const RLine axis)
virtual

Implements RShape.

bool RSpline::move ( const RVector offset)
virtual

Implements RShape.

void RSpline::print ( QDebug  dbg) const
protectedvirtual
Returns:
New spline that covers this spline from d1 to d2, where d1 and d2 are distances from the start point of this spline.

Reimplemented from RShape.

void RSpline::removeLastControlPoint ( )

Removes the last control point.

Parameters:
updUpdate internal spline representation.
void RSpline::removeLastFitPoint ( )

Removes the last fit point.

bool RSpline::reverse ( )
virtual

Implements RDirected.

Reimplemented in RSplineData.

bool RSpline::rotate ( double  rotation,
const RVector center = RDEFAULT_RVECTOR 
)
virtual

Implements RShape.

bool RSpline::scale ( const RVector scaleFactors,
const RVector center = RDEFAULT_RVECTOR 
)
virtual

Implements RShape.

void RSpline::setControlPoints ( const QList< RVector > &  points)

Sets the control points of this spline.

void RSpline::setDegree ( int  d)

Sets the degree of this spline (2 or 3 for control point defined spline, 3 for fit point defined spline).

void RSpline::setEndPoint ( const RVector v)
void RSpline::setFitPoints ( const QList< RVector > &  points)

Sets the fit points.

void RSpline::setKnotVector ( const QList< double > &  knots)

Sets the knot vector manually.

Mainly for importing ready data.

void RSpline::setPeriodic ( bool  on)

Reimplemented in RSplineData.

static void RSpline::setSplineProxy ( RSplineProxy p)
inlinestatic
   \par Non-Scriptable:

This function is not available in script environments.

void RSpline::setStartPoint ( const RVector v)
void RSpline::setTangentAtEnd ( const RVector t)

Sets the end tangent.

void RSpline::setTangentAtStart ( const RVector t)

Sets the start tangent.

void RSpline::setTangents ( const RVector start,
const RVector end 
)

Sets the start and end tangents.

void RSpline::to2D ( )
virtual

Flattens this shape to the X/Y plane.

Implements RShape.

RPolyline RSpline::toPolyline ( int  segments) const

Reimplemented in RSplineData.

void RSpline::trimEndPoint ( const RVector p)
virtual

Implements RDirected.

Reimplemented in RSplineData.

void RSpline::trimStartPoint ( const RVector p)
virtual

Implements RDirected.

Reimplemented in RSplineData.

void RSpline::unsetTangentAtEnd ( )

Clears the valud of the end tangent.

The end tangent is calculated and updated internally if not set manually.

void RSpline::unsetTangentAtStart ( )

Clears the valud of the start tangent.

The start tangent is calculated and updated internally if not set manually.

void RSpline::unsetTangents ( )

Clears the valud of the start and end tangents.

The tangents are calculated and updated internally if not set manually.

void RSpline::update ( ) const

Reimplemented in RSplineData.

void RSpline::updateBoundingBox ( ) const
protected

Updates the internal bounding box.

void RSpline::updateFromControlPoints ( ) const
void RSpline::updateFromFitPoints ( bool  useTangents = false) const

Closes this spline and makes it periodic if it isn't already.

Updates the internal spline data from fitPoints. Degree is always corrected to 3rd degree.

void RSpline::updateInternal ( ) const
protected
void RSpline::updateTangentsPeriodic ( )

Updates the tangents at the start and end to make the spline periodic.


Member Data Documentation

RBox RSpline::boundingBox
mutableprivate
QList<RVector> RSpline::controlPoints
mutable

Getter function for this property: getControlPoints.

Setter function for this property: setControlPoints

ON_NurbsCurve RSpline::curve
mutableprivate
int RSpline::degree
mutable

Getter function for this property: getDegree.

Setter function for this property: setDegree

bool RSpline::dirty
mutable
QList<QSharedPointer<RShape> > RSpline::exploded
mutableprivate
QList<RVector> RSpline::fitPoints

Getter function for this property: getFitPoints.

Setter function for this property: setFitPoints

QList<double> RSpline::knotVector
mutable

Getter function for this property: getKnotVector.

bool RSpline::periodic
mutable

Closed periodic flag.

RSplineProxy * RSpline::splineProxy = NULL
staticprivate

Copyright (c) 2011-2013 by Andrew Mustun.

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD.

RVector RSpline::tangentEnd
mutable

Unit vector end tangent.

RVector RSpline::tangentStart
mutable

Unit vector start tangent.

bool RSpline::updateInProgress
mutable
QList<double> RSpline::weights
mutable

Getter function for this property: getWeights.


The documentation for this class was generated from the following files: