Skip to content

Commit c778d1a

Browse files
author
mhugent
committedNov 7, 2009
Cubic tin interpolation in interpolation plugin
git-svn-id: http://svn.osgeo.org/qgis/trunk@11958 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent feb661c commit c778d1a

14 files changed

+2502
-8
lines changed
 

‎src/analysis/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ SET(QGIS_ANALYSIS_SRCS
88
interpolation/qgsidwinterpolator.cpp
99
interpolation/qgsinterpolator.cpp
1010
interpolation/qgstininterpolator.cpp
11+
interpolation/Bezier3D.cc
12+
interpolation/CloughTocherInterpolator.cc
1113
interpolation/DualEdgeTriangulation.cc
1214
interpolation/HalfEdge.cc
1315
interpolation/Line3D.cc
1416
interpolation/LinTriangleInterpolator.cc
1517
interpolation/MathUtils.cc
18+
interpolation/NormVecDecorator.cc
1619
interpolation/Node.cc
20+
interpolation/ParametricLine.cc
1721
interpolation/Point3D.cc
1822
interpolation/TriangleInterpolator.cc
1923
interpolation/Triangulation.cc
24+
interpolation/TriDecorator.cc
2025
interpolation/Vector3D.cc
2126
raster/qgsninecellfilter.cpp
2227
raster/qgsruggednessfilter.cpp
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/***************************************************************************
2+
Bezier3D.cc - 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+
#include "Bezier3D.h"
18+
#include <iostream>
19+
20+
21+
void Bezier3D::calcFirstDer( float t, Vector3D* v )
22+
{
23+
if ( v && mControlPoly )
24+
{
25+
v->setX( 0 );
26+
v->setY( 0 );
27+
v->setZ( 0 );
28+
29+
if ( mControlPoly->count() < 2 )
30+
{
31+
return;
32+
}
33+
34+
for ( int n = 1;n <= int( mControlPoly->count() - 1 );n++ )
35+
{
36+
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 2, n - 1, t );
37+
v->setX( v->getX() + (( *mControlPoly )[n]->getX() - ( *mControlPoly )[n-1]->getX() )*bernst );
38+
v->setY( v->getY() + (( *mControlPoly )[n]->getY() - ( *mControlPoly )[n-1]->getY() )*bernst );
39+
v->setZ( v->getZ() + (( *mControlPoly )[n]->getZ() - ( *mControlPoly )[n-1]->getZ() )*bernst );
40+
}
41+
v->setX( v->getX()*( mControlPoly->count() - 1 ) );
42+
v->setY( v->getY()*( mControlPoly->count() - 1 ) );
43+
v->setZ( v->getZ()*( mControlPoly->count() - 1 ) );
44+
}
45+
46+
else
47+
{
48+
std::cout << "warning: null pointer in Bezier3D::calcFirstDer" << std::endl << std::flush;
49+
}
50+
}
51+
52+
void Bezier3D::calcPoint( float t, Point3D* p )
53+
{
54+
55+
if ( p && mControlPoly )
56+
{
57+
p->setX( 0 );
58+
p->setY( 0 );
59+
p->setZ( 0 );
60+
61+
for ( int n = 1;n <= int( mControlPoly->count() );n++ )
62+
{
63+
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 1, n - 1, t );
64+
p->setX( p->getX() + ( *mControlPoly )[n-1]->getX()*bernst );
65+
p->setY( p->getY() + ( *mControlPoly )[n-1]->getY()*bernst );
66+
p->setZ( p->getZ() + ( *mControlPoly )[n-1]->getZ()*bernst );
67+
}
68+
}
69+
70+
else
71+
{
72+
std::cout << "warning: null pointer in Bezier3D::calcPoint" << std::endl << std::flush;
73+
}
74+
}
75+
76+
void Bezier3D::calcSecDer( float t, Vector3D* v )
77+
{
78+
if ( v && mControlPoly )
79+
{
80+
v->setX( 0 );
81+
v->setY( 0 );
82+
v->setZ( 0 );
83+
84+
if ( mControlPoly->count() < 3 )
85+
{
86+
return;
87+
}
88+
89+
for ( int n = 1;n <= int( mControlPoly->count() - 2 );n++ )
90+
{
91+
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 3, n - 1, t );
92+
v->setX( v->getX() + (( *mControlPoly )[n+1]->getX() - 2*( *mControlPoly )[n]->getX() + ( *mControlPoly )[n-1]->getX() )*bernst );
93+
v->setY( v->getY() + (( *mControlPoly )[n+1]->getY() - 2*( *mControlPoly )[n]->getY() + ( *mControlPoly )[n-1]->getY() )*bernst );
94+
v->setZ( v->getZ() + (( *mControlPoly )[n+1]->getZ() - 2*( *mControlPoly )[n]->getZ() + ( *mControlPoly )[n-1]->getZ() )*bernst );
95+
}
96+
v->setX( v->getX()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
97+
v->setY( v->getY()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
98+
v->setZ( v->getZ()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
99+
}
100+
101+
else
102+
{
103+
std::cout << "warning: null pointer in Bezier3D::calcSecDer" << std::endl << std::flush;
104+
}
105+
}
106+
107+
108+
void Bezier3D::changeDirection()//does this work correctli? more testing is needed.
109+
{
110+
if ( mControlPoly )
111+
{
112+
Point3D** pointer = new Point3D*[mControlPoly->count()];//create an array to temporarily store pointer to the control points
113+
for ( uint i = 0;i < mControlPoly->count();i++ )//store the points
114+
{
115+
pointer[i] = ( *mControlPoly )[i];
116+
}
117+
118+
for ( uint i = 0;i < mControlPoly->count();i++ )
119+
{
120+
mControlPoly->insert( i, pointer[( mControlPoly->count()-1 )-i] );
121+
}
122+
}
123+
124+
else
125+
{
126+
std::cout << "warning: null pointer in Bezier3D::changeDirection" << std::endl << std::flush;
127+
}
128+
}
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+

‎src/analysis/interpolation/Bezier3D.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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

Comments
 (0)
Please sign in to comment.