|
| 1 | +/*************************************************************************** |
| 2 | + Bezier3D.h - description |
| 3 | + ------------------- |
| 4 | + copyright : (C) 2004 by Marco Hugentobler |
| 5 | + email : mhugent@geo.unizh.ch |
| 6 | + ***************************************************************************/ |
| 7 | + |
| 8 | +/*************************************************************************** |
| 9 | + * * |
| 10 | + * This program is free software; you can redistribute it and/or modify * |
| 11 | + * it under the terms of the GNU General Public License as published by * |
| 12 | + * the Free Software Foundation; either version 2 of the License, or * |
| 13 | + * (at your option) any later version. * |
| 14 | + * * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +#ifndef BEZIER3D_H |
| 18 | +#define BEZIER3D_H |
| 19 | + |
| 20 | +using namespace std; |
| 21 | + |
| 22 | +#include "ParametricLine.h" |
| 23 | +#include "Vector3D.h" |
| 24 | +#include "MathUtils.h" |
| 25 | + |
| 26 | +/**Class Bezier3D represents a bezier curve, represented by control points. Parameter t is running from 0 to 1. The class is capable to calculate the curve point and the first two derivatives belonging to t.*/ |
| 27 | +class ANALYSIS_EXPORT Bezier3D: public ParametricLine |
| 28 | +{ |
| 29 | + protected: |
| 30 | + |
| 31 | + public: |
| 32 | + /**Default constructor*/ |
| 33 | + Bezier3D(); |
| 34 | + /**Constructor, par is a pointer to the parent, controlpoly a controlpolygon*/ |
| 35 | + Bezier3D( ParametricLine* par, QVector<Point3D*>* controlpoly ); |
| 36 | + /**Destructor*/ |
| 37 | + virtual ~Bezier3D(); |
| 38 | + /**Do not use this method, since a Bezier curve does not consist of other curves*/ |
| 39 | + virtual void add( ParametricLine* pl ); |
| 40 | + /**Calculates the first derivative and assigns it to v*/ |
| 41 | + virtual void calcFirstDer( float t, Vector3D* v ); |
| 42 | + /**Calculates the second derivative and assigns it to v*/ |
| 43 | + virtual void calcSecDer( float t, Vector3D* v ); |
| 44 | + //virtual Point3D calcPoint(float t); |
| 45 | + /**Calculates the point on the curve and assigns it to p*/ |
| 46 | + virtual void calcPoint( float t, Point3D* p ); |
| 47 | + /**changes the order of control points*/ |
| 48 | + virtual void changeDirection(); |
| 49 | + //virtual void draw(QPainter* p); |
| 50 | + //virtual bool intersects(ParametricLine* pal); |
| 51 | + /**Do not use this method, since a Bezier curve does not consist of other curves*/ |
| 52 | + virtual void remove( int i ); |
| 53 | + /**Returns a control point*/ |
| 54 | + virtual const Point3D* getControlPoint( int number ) const; |
| 55 | + /**Returns a pointer to the control polygon*/ |
| 56 | + virtual const QVector<Point3D*>* getControlPoly() const; |
| 57 | + /**Returns the degree of the curve*/ |
| 58 | + virtual int getDegree() const; |
| 59 | + /**Returns the parent*/ |
| 60 | + virtual ParametricLine* getParent() const; |
| 61 | + /** Sets the parent*/ |
| 62 | + virtual void setParent( ParametricLine* par ); |
| 63 | + /**Sets the control polygon*/ |
| 64 | + virtual void setControlPoly( QVector<Point3D*>* cp ); |
| 65 | + |
| 66 | +}; |
| 67 | + |
| 68 | +//-----------------------------------------------constructors, destructor and assignment operator------------------------------ |
| 69 | + |
| 70 | +inline Bezier3D::Bezier3D() : ParametricLine()//default constructor |
| 71 | +{ |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +inline Bezier3D::Bezier3D( ParametricLine* parent, QVector<Point3D*>* controlpoly ) : ParametricLine( parent, controlpoly ) |
| 76 | +{ |
| 77 | + mDegree = mControlPoly->count() - 1; |
| 78 | +} |
| 79 | + |
| 80 | +inline Bezier3D::~Bezier3D() |
| 81 | +{ |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +//----------------------------------------------invalid methods add and remove (because of inheritance from ParametricLine) |
| 86 | + |
| 87 | +inline void Bezier3D::add( ParametricLine* pl ) |
| 88 | +{ |
| 89 | + cout << "Error!!!!! A Bezier-curve can not be parent of a ParametricLine." << endl; |
| 90 | +} |
| 91 | + |
| 92 | +inline void Bezier3D::remove( int i ) |
| 93 | +{ |
| 94 | + cout << "Error!!!!! A Bezier-curve has no Childs to remove." << endl; |
| 95 | +} |
| 96 | + |
| 97 | +//-----------------------------------------------setters and getters--------------------------------------------------------------- |
| 98 | + |
| 99 | +inline const Point3D* Bezier3D::getControlPoint( int number ) const |
| 100 | +{ |
| 101 | + return ( *mControlPoly )[number-1]; |
| 102 | +} |
| 103 | + |
| 104 | +inline const QVector<Point3D*>* Bezier3D::getControlPoly() const |
| 105 | +{ |
| 106 | + return mControlPoly; |
| 107 | +} |
| 108 | + |
| 109 | +inline int Bezier3D::getDegree() const |
| 110 | +{ |
| 111 | + return mDegree; |
| 112 | +} |
| 113 | + |
| 114 | +inline ParametricLine* Bezier3D::getParent() const |
| 115 | +{ |
| 116 | + return mParent; |
| 117 | +} |
| 118 | + |
| 119 | +inline void Bezier3D::setParent( ParametricLine* par ) |
| 120 | +{ |
| 121 | + mParent = par; |
| 122 | +} |
| 123 | + |
| 124 | +inline void Bezier3D::setControlPoly( QVector<Point3D*>* cp ) |
| 125 | +{ |
| 126 | + mControlPoly = cp; |
| 127 | + mDegree = mControlPoly->count() - 1; |
| 128 | +} |
| 129 | + |
| 130 | +#endif |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
0 commit comments