289 lines
8.6 KiB
Objective-C
Executable File
289 lines
8.6 KiB
Objective-C
Executable File
/**
|
|
**
|
|
** @RDE_HEADER@
|
|
** Implementation of Splines
|
|
** $Id$
|
|
** $HeadURL$
|
|
** $Author$
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Hardware-Environment: Intel-PC
|
|
** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5
|
|
**
|
|
** Language ........: C++ 11
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Author ...........: Jörg Turla, SPD G, Tel. 3132
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Notes .........:
|
|
**
|
|
** 12.08.2015, JT : First edition for use with Qt5
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QtCore/QPoint>
|
|
#include <QtCore/QVector>
|
|
|
|
#include <MathUtils/math_const.h>
|
|
#include <situation_map_export.h>
|
|
|
|
|
|
namespace SituationMap { namespace MathUtils
|
|
{
|
|
|
|
class PathRasterer;
|
|
|
|
/**
|
|
@class Curve curve.h
|
|
@brief Base class to calculate a polyline from curve functions like splines, circles, ellpises ...
|
|
|
|
Pure virtual base class to calculate a polyline from curve functions. The curve function is defined
|
|
in derived classes. The resolution of rasterization can be set in PathRasterer class.
|
|
|
|
@see PathRasterer, Ellipse, Spline, SmoothLine, HermiteSpline, BezierSpline
|
|
*/
|
|
|
|
class SITUATIONMAP_EXPORT Curve
|
|
{
|
|
public:
|
|
|
|
/**
|
|
Returns the maximum curve paramter t. The curve is defined in interval tmin ... tmax
|
|
*/
|
|
virtual qreal maximumCurveParameter() const = 0;
|
|
|
|
|
|
/**
|
|
Returns the minimum curve paramter t. The curve is defined in interval tmin ... tmax
|
|
*/
|
|
virtual qreal minimumCurveParameter() const = 0;
|
|
|
|
|
|
/**
|
|
Returns the position on curve at \c t
|
|
@param t curve parameter, should be in range of 0 ... tmax
|
|
*/
|
|
virtual QPointF positionOnCurve ( qreal t ) const = 0;
|
|
|
|
/**
|
|
Returns the tangent at position \c t
|
|
@param t curve parameter, should be in range of 0 ... tmax
|
|
*/
|
|
virtual QPointF directionOnCurve( qreal t ) const = 0;
|
|
|
|
/**
|
|
Returns the length of curve from start to position t
|
|
@param t curve parameter, should be in range of 0 ... tmax
|
|
*/
|
|
virtual qreal arcLength( qreal t ) const = 0;
|
|
|
|
/**
|
|
Returns the length of curve from position \c tmin to position \c tmax
|
|
@param tmin curve parameter, should be in range of 0 ... maximumCurveParameter()
|
|
@param tmax curve parameter, should be in range of tmin ... maximumCurveParameter()
|
|
*/
|
|
virtual qreal arcLength( qreal tmin, qreal tmax ) const { return arcLength(tmax)-arcLength(tmin); }
|
|
|
|
/**
|
|
Returns the length of complete curve
|
|
*/
|
|
inline qreal arcLength() const { return arcLength( maximumCurveParameter() ); }
|
|
|
|
/**
|
|
Create instance of class \c PathRasterer to rasterize the spline curve. After usage the
|
|
caller should use delete to free memory and avoid memory leaks. This methode is pure virtual
|
|
and has to be override by the derived class.
|
|
|
|
@see PathRasterer
|
|
*/
|
|
virtual PathRasterer * createPathRaster() const = 0;
|
|
|
|
}; /* Curve */
|
|
|
|
|
|
/**
|
|
@class SmoothLine curve.h
|
|
@brief Class to calculate a ellipse. A angle have to be defined in RAD in mathematical manner (counter clockwise and (1,0) is zero angle)
|
|
*/
|
|
class SITUATIONMAP_EXPORT Ellipse : public Curve
|
|
{
|
|
public:
|
|
|
|
Ellipse() = default;
|
|
|
|
Ellipse( QPointF center, qreal rx, qreal ry, qreal phi, qreal sectorStart = 0, qreal sectorEnd = MathConst::pi_two );
|
|
|
|
virtual ~Ellipse() = default;
|
|
|
|
qreal maximumCurveParameter() const override;
|
|
qreal minimumCurveParameter() const override;
|
|
|
|
QPointF positionOnCurve ( qreal t ) const override;
|
|
QPointF directionOnCurve( qreal t ) const override;
|
|
|
|
qreal arcLength( qreal t ) const override;
|
|
qreal arcLength( qreal tmin, qreal tmax ) const override;
|
|
|
|
PathRasterer * createPathRaster() const override;
|
|
|
|
protected:
|
|
|
|
QPointF _center;
|
|
qreal _radiusX;
|
|
qreal _radiusY;
|
|
qreal _eccentricity2;
|
|
qreal _sinPhi;
|
|
qreal _cosPhi;
|
|
qreal _phiSectorStart;
|
|
qreal _phiSectorEnd;
|
|
|
|
}; /* Ellipse */
|
|
|
|
|
|
/**
|
|
@class SmoothLine curve.h
|
|
@brief Class to calculate a line with rounded verticies based on spline functions
|
|
*/
|
|
|
|
class SITUATIONMAP_EXPORT SmoothLine : public Curve
|
|
{
|
|
public:
|
|
|
|
/**
|
|
@name Construction & Destruction
|
|
@{
|
|
*/
|
|
SmoothLine() = default;
|
|
|
|
explicit SmoothLine( const QVector<QPointF> & vertexVector, bool closedCurve = false );
|
|
|
|
virtual ~SmoothLine() = default;
|
|
/** @} */
|
|
|
|
/**
|
|
Defines the predicated polyline
|
|
@param vertexVector verticies of the polyline
|
|
@param closedCurve if \c closedCurve is true the polyline is closed to a polygon
|
|
*/
|
|
void vertexVector( const QVector<QPointF> & vertexVector, bool closedCurve = false );
|
|
|
|
|
|
qreal maximumCurveParameter() const override;
|
|
qreal minimumCurveParameter() const override { return 0.0; }
|
|
|
|
QPointF positionOnCurve ( qreal t ) const override;
|
|
QPointF directionOnCurve( qreal t ) const override;
|
|
|
|
qreal arcLength( qreal t ) const override;
|
|
|
|
PathRasterer * createPathRaster() const override;
|
|
|
|
protected:
|
|
|
|
bool _closedCurve;
|
|
QVector<QPointF> _vertexVector;
|
|
|
|
}; /* SmoothLine */
|
|
|
|
|
|
/**
|
|
@class HermitSpline curve.h
|
|
@brief Class to calculate 2D hermit spline curves
|
|
*/
|
|
class SITUATIONMAP_EXPORT HermiteSpline : public Curve
|
|
{
|
|
public:
|
|
|
|
/**
|
|
@name Construction & Destruction
|
|
@{
|
|
*/
|
|
HermiteSpline() = default;
|
|
|
|
HermiteSpline( const QVector<QPointF> & vertexVector
|
|
, const QVector<QPointF> & tangentVector
|
|
, bool closedCurve = false );
|
|
|
|
~HermiteSpline() = default;
|
|
/** @} */
|
|
|
|
/**
|
|
Defines the gemeotry of the hermite spline
|
|
@param vertexVector verticies to define the hermite spline
|
|
@param tangentVector tangents to define the hermite spline
|
|
@param closedCurve if \c closedCurve is true the spline curve is closed
|
|
*/
|
|
virtual void vertexVector( const QVector<QPointF> & vertexVector
|
|
, const QVector<QPointF> & tangentVector
|
|
, bool closedCurve = false );
|
|
|
|
|
|
qreal maximumCurveParameter() const override;
|
|
qreal minimumCurveParameter() const override { return 0.0; }
|
|
|
|
QPointF positionOnCurve ( qreal t ) const override;
|
|
QPointF directionOnCurve( qreal t ) const override;
|
|
|
|
qreal arcLength( qreal t ) const override;
|
|
|
|
PathRasterer * createPathRaster() const override;
|
|
|
|
private:
|
|
|
|
bool _closedCurve;
|
|
QVector<QPointF> _vertexVector;
|
|
QVector<QPointF> _tangentVector;
|
|
|
|
}; /* HermiteSpline */
|
|
|
|
|
|
/**
|
|
@class BezierSpline curve.h
|
|
@brief Class to calculate 2D bezier spline curves
|
|
*/
|
|
class SITUATIONMAP_EXPORT BezierSpline : public HermiteSpline
|
|
{
|
|
public:
|
|
|
|
/**
|
|
@name Construction & Destruction
|
|
@{
|
|
*/
|
|
BezierSpline() = default;
|
|
|
|
explicit BezierSpline( const QVector<QPointF> & ctrlPntVector, bool closedCurve = false );
|
|
|
|
~BezierSpline() = default;
|
|
/** @} */
|
|
|
|
|
|
/**
|
|
Defines the control points of the bezier curve
|
|
@param ctrlPntVector control points of bezier curve
|
|
@param closedCurve if \c closedCurve is true the spline curve is closed
|
|
*/
|
|
void controlPointVector( const QVector<QPointF> & ctrlPntVector, bool closedCurve = false );
|
|
|
|
|
|
/**
|
|
Don't call vertexVector methode from class HermiteSpline. It is not defined for bezier curves.
|
|
If you call it anyway, you will get an execption.
|
|
*/
|
|
void vertexVector( const QVector<QPointF> & vertexVector
|
|
, const QVector<QPointF> & tangentVector
|
|
, bool closedCurve = false ) override;
|
|
|
|
PathRasterer * createPathRaster() const override;
|
|
|
|
}; /* BezierSpline */
|
|
|
|
|
|
} } // namespace SituationMap::MathUtils
|