Skip to content
Permalink
Browse files

Cubic tin interpolation in interpolation plugin

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11958 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 7, 2009
1 parent 0bf1126 commit f6bb0ea0bc8e489bd7def572e6360f9a470cec5e
@@ -8,15 +8,20 @@ SET(QGIS_ANALYSIS_SRCS
interpolation/qgsidwinterpolator.cpp
interpolation/qgsinterpolator.cpp
interpolation/qgstininterpolator.cpp
interpolation/Bezier3D.cc
interpolation/CloughTocherInterpolator.cc
interpolation/DualEdgeTriangulation.cc
interpolation/HalfEdge.cc
interpolation/Line3D.cc
interpolation/LinTriangleInterpolator.cc
interpolation/MathUtils.cc
interpolation/NormVecDecorator.cc
interpolation/Node.cc
interpolation/ParametricLine.cc
interpolation/Point3D.cc
interpolation/TriangleInterpolator.cc
interpolation/Triangulation.cc
interpolation/TriDecorator.cc
interpolation/Vector3D.cc
raster/qgsninecellfilter.cpp
raster/qgsruggednessfilter.cpp
@@ -0,0 +1,160 @@
/***************************************************************************
Bezier3D.cc - description
-------------------
copyright : (C) 2004 by Marco Hugentobler
email : mhugent@geo.unizh.ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "Bezier3D.h"
#include <iostream>


void Bezier3D::calcFirstDer( float t, Vector3D* v )
{
if ( v && mControlPoly )
{
v->setX( 0 );
v->setY( 0 );
v->setZ( 0 );

if ( mControlPoly->count() < 2 )
{
return;
}

for ( int n = 1;n <= int( mControlPoly->count() - 1 );n++ )
{
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 2, n - 1, t );
v->setX( v->getX() + (( *mControlPoly )[n]->getX() - ( *mControlPoly )[n-1]->getX() )*bernst );
v->setY( v->getY() + (( *mControlPoly )[n]->getY() - ( *mControlPoly )[n-1]->getY() )*bernst );
v->setZ( v->getZ() + (( *mControlPoly )[n]->getZ() - ( *mControlPoly )[n-1]->getZ() )*bernst );
}
v->setX( v->getX()*( mControlPoly->count() - 1 ) );
v->setY( v->getY()*( mControlPoly->count() - 1 ) );
v->setZ( v->getZ()*( mControlPoly->count() - 1 ) );
}

else
{
std::cout << "warning: null pointer in Bezier3D::calcFirstDer" << std::endl << std::flush;
}
}

void Bezier3D::calcPoint( float t, Point3D* p )
{

if ( p && mControlPoly )
{
p->setX( 0 );
p->setY( 0 );
p->setZ( 0 );

for ( int n = 1;n <= int( mControlPoly->count() );n++ )
{
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 1, n - 1, t );
p->setX( p->getX() + ( *mControlPoly )[n-1]->getX()*bernst );
p->setY( p->getY() + ( *mControlPoly )[n-1]->getY()*bernst );
p->setZ( p->getZ() + ( *mControlPoly )[n-1]->getZ()*bernst );
}
}

else
{
std::cout << "warning: null pointer in Bezier3D::calcPoint" << std::endl << std::flush;
}
}

void Bezier3D::calcSecDer( float t, Vector3D* v )
{
if ( v && mControlPoly )
{
v->setX( 0 );
v->setY( 0 );
v->setZ( 0 );

if ( mControlPoly->count() < 3 )
{
return;
}

for ( int n = 1;n <= int( mControlPoly->count() - 2 );n++ )
{
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 3, n - 1, t );
v->setX( v->getX() + (( *mControlPoly )[n+1]->getX() - 2*( *mControlPoly )[n]->getX() + ( *mControlPoly )[n-1]->getX() )*bernst );
v->setY( v->getY() + (( *mControlPoly )[n+1]->getY() - 2*( *mControlPoly )[n]->getY() + ( *mControlPoly )[n-1]->getY() )*bernst );
v->setZ( v->getZ() + (( *mControlPoly )[n+1]->getZ() - 2*( *mControlPoly )[n]->getZ() + ( *mControlPoly )[n-1]->getZ() )*bernst );
}
v->setX( v->getX()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setY( v->getY()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setZ( v->getZ()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
}

else
{
std::cout << "warning: null pointer in Bezier3D::calcSecDer" << std::endl << std::flush;
}
}


void Bezier3D::changeDirection()//does this work correctli? more testing is needed.
{
if ( mControlPoly )
{
Point3D** pointer = new Point3D*[mControlPoly->count()];//create an array to temporarily store pointer to the control points
for ( uint i = 0;i < mControlPoly->count();i++ )//store the points
{
pointer[i] = ( *mControlPoly )[i];
}

for ( uint i = 0;i < mControlPoly->count();i++ )
{
mControlPoly->insert( i, pointer[( mControlPoly->count()-1 )-i] );
}
}

else
{
std::cout << "warning: null pointer in Bezier3D::changeDirection" << std::endl << std::flush;
}
}
































@@ -0,0 +1,136 @@
/***************************************************************************
Bezier3D.h - description
-------------------
copyright : (C) 2004 by Marco Hugentobler
email : mhugent@geo.unizh.ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef BEZIER3D_H
#define BEZIER3D_H

using namespace std;

#include "ParametricLine.h"
#include "Vector3D.h"
#include "MathUtils.h"

/**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.*/
class ANALYSIS_EXPORT Bezier3D: public ParametricLine
{
protected:

public:
/**Default constructor*/
Bezier3D();
/**Constructor, par is a pointer to the parent, controlpoly a controlpolygon*/
Bezier3D( ParametricLine* par, QVector<Point3D*>* controlpoly );
/**Destructor*/
virtual ~Bezier3D();
/**Do not use this method, since a Bezier curve does not consist of other curves*/
virtual void add( ParametricLine* pl );
/**Calculates the first derivative and assigns it to v*/
virtual void calcFirstDer( float t, Vector3D* v );
/**Calculates the second derivative and assigns it to v*/
virtual void calcSecDer( float t, Vector3D* v );
//virtual Point3D calcPoint(float t);
/**Calculates the point on the curve and assigns it to p*/
virtual void calcPoint( float t, Point3D* p );
/**changes the order of control points*/
virtual void changeDirection();
//virtual void draw(QPainter* p);
//virtual bool intersects(ParametricLine* pal);
/**Do not use this method, since a Bezier curve does not consist of other curves*/
virtual void remove( int i );
/**Returns a control point*/
virtual const Point3D* getControlPoint( int number ) const;
/**Returns a pointer to the control polygon*/
virtual const QVector<Point3D*>* getControlPoly() const;
/**Returns the degree of the curve*/
virtual int getDegree() const;
/**Returns the parent*/
virtual ParametricLine* getParent() const;
/** Sets the parent*/
virtual void setParent( ParametricLine* par );
/**Sets the control polygon*/
virtual void setControlPoly( QVector<Point3D*>* cp );

};

//-----------------------------------------------constructors, destructor and assignment operator------------------------------

inline Bezier3D::Bezier3D() : ParametricLine()//default constructor
{

}

inline Bezier3D::Bezier3D( ParametricLine* parent, QVector<Point3D*>* controlpoly ) : ParametricLine( parent, controlpoly )
{
mDegree = mControlPoly->count() - 1;
}

inline Bezier3D::~Bezier3D()
{

}

//----------------------------------------------invalid methods add and remove (because of inheritance from ParametricLine)

inline void Bezier3D::add( ParametricLine* pl )
{
cout << "Error!!!!! A Bezier-curve can not be parent of a ParametricLine." << endl;
}

inline void Bezier3D::remove( int i )
{
cout << "Error!!!!! A Bezier-curve has no Childs to remove." << endl;
}

//-----------------------------------------------setters and getters---------------------------------------------------------------

inline const Point3D* Bezier3D::getControlPoint( int number ) const
{
return ( *mControlPoly )[number-1];
}

inline const QVector<Point3D*>* Bezier3D::getControlPoly() const
{
return mControlPoly;
}

inline int Bezier3D::getDegree() const
{
return mDegree;
}

inline ParametricLine* Bezier3D::getParent() const
{
return mParent;
}

inline void Bezier3D::setParent( ParametricLine* par )
{
mParent = par;
}

inline void Bezier3D::setControlPoly( QVector<Point3D*>* cp )
{
mControlPoly = cp;
mDegree = mControlPoly->count() - 1;
}

#endif






0 comments on commit f6bb0ea

Please sign in to comment.
You can’t perform that action at this time.