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+

‎src/analysis/interpolation/CloughTocherInterpolator.cc

Lines changed: 735 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/***************************************************************************
2+
CloughTocherInterpolator.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 CLOUGHTOCHERINTERPOLATOR_H
18+
#define CLOUGHTOCHERINTERPOLATOR_H
19+
20+
#include "NormVecDecorator.h"
21+
#include "TriangleInterpolator.h"
22+
#include "Point3D.h"
23+
#include "Vector3D.h"
24+
#include "MathUtils.h"
25+
#include "Bezier3D.h"
26+
27+
/**This is an implementation of a Clough-Tocher interpolator based on a triangular tessellation. The derivatives orthogonal to the boundary curves are interpolated linearly along a triangle edge.*/
28+
class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
29+
{
30+
protected:
31+
/**association with a triangulation object*/
32+
NormVecDecorator* mTIN;
33+
/**Tolerance of the barycentric coordinates at the borders of the triangles (to prevent errors because of very small negativ baricentric coordinates)*/
34+
double mEdgeTolerance;
35+
/**first point of the triangle in x-,y-,z-coordinates*/
36+
Point3D point1;
37+
/**second point of the triangle in x-,y-,z-coordinates*/
38+
Point3D point2;
39+
/**third point of the triangle in x-,y-,z-coordinates*/
40+
Point3D point3;
41+
Point3D cp1;
42+
Point3D cp2;
43+
Point3D cp3;
44+
Point3D cp4;
45+
Point3D cp5;
46+
Point3D cp6;
47+
Point3D cp7;
48+
Point3D cp8;
49+
Point3D cp9;
50+
Point3D cp10;
51+
Point3D cp11;
52+
Point3D cp12;
53+
Point3D cp13;
54+
Point3D cp14;
55+
Point3D cp15;
56+
Point3D cp16;
57+
/**derivative in x-direction at point1*/
58+
double der1X;
59+
/**derivative in y-direction at point1*/
60+
double der1Y;
61+
/**derivative in x-direction at point2*/
62+
double der2X;
63+
/**derivative in y-direction at point2*/
64+
double der2Y;
65+
/**derivative in x-direction at point3*/
66+
double der3X;
67+
/**derivative in y-direction at point3*/
68+
double der3Y;
69+
/**stores point1 of the last run*/
70+
Point3D lpoint1;
71+
/**stores point2 of the last run*/
72+
Point3D lpoint2;
73+
/**stores point3 of the last run*/
74+
Point3D lpoint3;
75+
/**Finds out, in which triangle the point with the coordinates x and y is*/
76+
void init( double x, double y );
77+
/**Calculates the Bernsteinpolynomials to calculate the Beziertriangle. 'n' is three in the cubical case, 'i', 'j', 'k' are the indices of the controllpoint and 'u', 'v', 'w' are the barycentric coordinates of the point*/
78+
double calcBernsteinPoly( int n, int i, int j, int k, double u, double v, double w );
79+
80+
public:
81+
/**standard constructor*/
82+
CloughTocherInterpolator();
83+
/**constructor with a pointer to the triangulation as argument*/
84+
CloughTocherInterpolator( NormVecDecorator* tin );
85+
/**destructor*/
86+
virtual ~CloughTocherInterpolator();
87+
/**Calculates the normal vector and assigns it to vec (not implemented at the moment)*/
88+
virtual bool calcNormVec( double x, double y, Vector3D* result );
89+
/**Performs a linear interpolation in a triangle and assigns the x-,y- and z-coordinates to point*/
90+
virtual bool calcPoint( double x, double y, Point3D* result );
91+
virtual void setTriangulation( NormVecDecorator* tin );
92+
};
93+
94+
95+
inline CloughTocherInterpolator::CloughTocherInterpolator() : mTIN( 0 ), mEdgeTolerance( 0.00001 )
96+
{
97+
98+
}
99+
100+
inline CloughTocherInterpolator::CloughTocherInterpolator( NormVecDecorator* tin ) : mTIN( tin ), mEdgeTolerance( 0.00001 )
101+
{
102+
103+
}
104+
105+
inline CloughTocherInterpolator::~CloughTocherInterpolator()
106+
{
107+
//nothing to do
108+
}
109+
110+
inline void CloughTocherInterpolator::setTriangulation( NormVecDecorator* tin )
111+
{
112+
mTIN = tin;
113+
}
114+
115+
#endif
116+
117+
118+

‎src/analysis/interpolation/NormVecDecorator.cc

Lines changed: 595 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/***************************************************************************
2+
NormVecDecorator.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 NORMVECDECORATOR_H
18+
#define NORMVECDECORATOR_H
19+
20+
using namespace std;
21+
22+
#include "TriDecorator.h"
23+
#include <TriangleInterpolator.h>
24+
#include <MathUtils.h>
25+
26+
/**Decorator class which adds the functionality of estimating normals at the data points*/
27+
class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
28+
{
29+
public:
30+
/**Enumeration for the state of a point. NORMAL means, that the point is not on a breakline, BREAKLINE means that the point is on a breakline (but not an endpoint of it) and ENDPOINT means, that it is an endpoint of a breakline*/
31+
enum pointState {NORMAL, BREAKLINE, ENDPOINT};
32+
NormVecDecorator();
33+
NormVecDecorator( Triangulation* tin );
34+
virtual ~NormVecDecorator();
35+
/**Adds a point to the triangulation*/
36+
int addPoint( Point3D* p );
37+
/**Calculates the normal at a point on the surface and assigns it to 'result'. Returns true in case of success and false in case of failure*/
38+
bool calcNormal( double x, double y, Vector3D* result );
39+
/**Calculates the normal of a triangle-point for the point with coordinates x and y. This is needed, if a point is on a break line and there is no unique normal stored in 'mNormVec'. Returns false, it something went wrong and true otherwise*/
40+
bool calcNormalForPoint( double x, double y, int point, Vector3D* result );
41+
/**Calculates x-, y and z-value of the point on the surface and assigns it to 'result'. Returns true in case of success and flase in case of failure*/
42+
bool calcPoint( double x, double y, Point3D* result );
43+
/**Eliminates the horizontal triangles by swapping or by insertion of new points. If alreadyestimated is true, a re-estimation of the normals will be done*/
44+
virtual void eliminateHorizontalTriangles();
45+
/**Estimates the first derivative a point. Return true in case of succes and false otherwise*/
46+
bool estimateFirstDerivative( int pointno );
47+
/**This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise*/
48+
bool estimateFirstDerivatives();
49+
/**Returns a pointer to the normal vector for the point with the number n*/
50+
Vector3D* getNormal( int n ) const;
51+
/**Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p1, p2, p3 and the estimated normals to v1, v2, v3. The vectors are normaly taken from 'mNormVec', exept if p1, p2 or p3 is a point on a breakline. In this case, the normal is calculated on-the-fly. Returns false, if something went wrong and true otherwise*/
52+
bool getTriangle( double x, double y, Point3D* p1, Vector3D* v1, Point3D* p2, Vector3D* v2, Point3D* p3, Vector3D* v3 );
53+
/**This function behaves similar to the one above. Additionally, the numbers of the points are returned (ptn1, ptn2, ptn3) as well as the pointStates of the triangle points (state1, state2, state3)*/
54+
bool getTriangle( double x, double y, Point3D* p1, int* ptn1, Vector3D* v1, pointState* state1, Point3D* p2, int* ptn2, Vector3D* v2, pointState* state2, Point3D* p3, int* ptn3, Vector3D* v3, pointState* state3 );
55+
/**Returns the state of the point with the number 'pointno'*/
56+
pointState getState( int pointno ) const;
57+
/**Sets an interpolator*/
58+
void setTriangleInterpolator( TriangleInterpolator* inter );
59+
/**Swaps the edge which is closest to the point with x and y coordinates (if this is possible) and forces recalculation of the concerned normals (if alreadyestimated is true)*/
60+
virtual bool swapEdge( double x, double y );
61+
/**Saves the triangulation as a (line) shapefile
62+
@return true in case of success*/
63+
virtual bool saveAsShapefile( const QString& fileName ) const;
64+
65+
protected:
66+
/**Is true, if the normals already have been estimated*/
67+
bool alreadyestimated;
68+
const static unsigned int mDefaultStorageForNormals = 50000;
69+
/**Association with an interpolator object*/
70+
TriangleInterpolator* mInterpolator;
71+
/**Vector that stores the normals for the points. If 'estimateFirstDerivatives()' was called and there is a null pointer, this means, that the triangle point is on a breakline*/
72+
QVector<Vector3D*>* mNormVec;
73+
/**Vector who stores, it a point is not on a breakline, if it is a normal point of the breakline or if it is an endpoint of a breakline*/
74+
QVector<pointState>* mPointState;
75+
/**Sets the state (BREAKLINE, NORMAL, ENDPOINT) of a point*/
76+
void setState( int pointno, pointState s );
77+
};
78+
79+
inline NormVecDecorator::NormVecDecorator(): TriDecorator(), mInterpolator( 0 ), mNormVec( new QVector<Vector3D*>( mDefaultStorageForNormals ) ), mPointState( new QVector<pointState>( mDefaultStorageForNormals ) )
80+
{
81+
alreadyestimated = false;
82+
}
83+
84+
inline NormVecDecorator::NormVecDecorator( Triangulation* tin ): TriDecorator( tin ), mInterpolator( 0 ), mNormVec( new QVector<Vector3D*>( mDefaultStorageForNormals ) ), mPointState( new QVector<pointState>( mDefaultStorageForNormals ) )
85+
{
86+
alreadyestimated = false;
87+
}
88+
89+
inline void NormVecDecorator::setTriangleInterpolator( TriangleInterpolator* inter )
90+
{
91+
mInterpolator = inter;
92+
}
93+
94+
inline Vector3D* NormVecDecorator::getNormal( int n ) const
95+
{
96+
if ( mNormVec )
97+
{
98+
return mNormVec->at( n );
99+
}
100+
else
101+
{
102+
cout << "warning, null pointer in NormVecDecorator::getNormal" << endl << flush;
103+
return 0;
104+
}
105+
}
106+
107+
#endif
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/***************************************************************************
2+
ParametricLine.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 "ParametricLine.h"
18+
#include <iostream>
19+
20+
21+
void ParametricLine::add( ParametricLine* pl )
22+
{
23+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
24+
}
25+
26+
void ParametricLine::calcFirstDer( float t, Vector3D* v )
27+
{
28+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
29+
}
30+
31+
void ParametricLine::calcSecDer( float t, Vector3D* v )
32+
{
33+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
34+
}
35+
36+
void ParametricLine::calcPoint( float t, Point3D* )
37+
{
38+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
39+
}
40+
41+
ParametricLine* ParametricLine::getParent() const
42+
{
43+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
44+
return 0;
45+
}
46+
47+
void ParametricLine::remove( int i )
48+
{
49+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
50+
}
51+
52+
void ParametricLine::setControlPoly( QVector<Point3D*>* cp )
53+
{
54+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
55+
}
56+
57+
void ParametricLine::setParent( ParametricLine* paral )
58+
{
59+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
60+
}
61+
62+
int ParametricLine::getDegree() const
63+
{
64+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
65+
return mDegree;
66+
}
67+
68+
const Point3D* ParametricLine::getControlPoint( int number ) const
69+
{
70+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
71+
return 0;
72+
}
73+
74+
const QVector<Point3D*>* ParametricLine::getControlPoly() const
75+
{
76+
std::cout << "warning, derive a class from ParametricLine" << std::endl;
77+
return 0;
78+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************
2+
ParametricLine.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 PARAMETRICLINE_H
18+
#define PARAMETRICLINE_H
19+
20+
#include "Point3D.h"
21+
#include "Vector3D.h"
22+
#include <QVector>
23+
24+
class ANALYSIS_EXPORT ParametricLine
25+
/**ParametricLine is an Interface for parametric lines. It is possible, that a parametric line is composed of several parametric lines (see the composite pattern in Gamma et al. 'Design Patterns'). Do not build instances of it since it is an abstract class.*/
26+
{
27+
protected:
28+
/**Degree of the parametric Line*/
29+
int mDegree;
30+
/**Pointer to the parent object. If there isn't one, mParent is 0*/
31+
ParametricLine* mParent;
32+
/**mControlPoly stores the points of the control polygon*/
33+
QVector<Point3D*>* mControlPoly;
34+
public:
35+
/**Default constructor*/
36+
ParametricLine();
37+
/**Constructor, par is a pointer to the parent object, controlpoly the controlpolygon*/
38+
ParametricLine( ParametricLine* par, QVector<Point3D*>* controlpoly );
39+
/**Destructor*/
40+
virtual ~ParametricLine();
41+
virtual void add( ParametricLine* pl ) = 0;
42+
virtual void calcFirstDer( float t, Vector3D* v ) = 0;
43+
virtual void calcSecDer( float t, Vector3D* v ) = 0;
44+
//virtual Point3D calcPoint(float t);
45+
virtual void calcPoint( float t, Point3D* ) = 0;
46+
virtual void changeDirection() = 0;
47+
//virtual void draw(QPainter* p);
48+
virtual const Point3D* getControlPoint( int number ) const = 0;
49+
virtual const QVector<Point3D*>* getControlPoly() const = 0;
50+
virtual int getDegree() const = 0;
51+
virtual ParametricLine* getParent() const = 0;
52+
//virtual bool intersects(ParametricLine* pal);
53+
virtual void remove( int i ) = 0;
54+
virtual void setControlPoly( QVector<Point3D*>* cp ) = 0;
55+
virtual void setParent( ParametricLine* paral ) = 0;
56+
};
57+
58+
//-----------------------------------------constructors and destructor----------------------
59+
60+
inline ParametricLine::ParametricLine() : mParent( 0 ), mControlPoly( 0 )
61+
{
62+
63+
}
64+
65+
inline ParametricLine::ParametricLine( ParametricLine* par, QVector<Point3D*>* controlpoly ) : mParent( par ), mControlPoly( controlpoly )
66+
{
67+
68+
}
69+
70+
inline ParametricLine::~ParametricLine()
71+
{
72+
//delete mParent;
73+
}
74+
75+
#endif
76+
77+
78+
79+
80+
81+
82+
83+
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
/***************************************************************************
2+
TriDecorator.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 "TriDecorator.h"
18+
19+
void TriDecorator::addLine( Line3D* line, bool breakline )
20+
{
21+
if ( mTIN )
22+
{
23+
mTIN->addLine( line, breakline );
24+
}
25+
else
26+
{
27+
cout << "warning, null pointer in TriDecorator::addLine" << endl << flush;
28+
}
29+
}
30+
31+
int TriDecorator::addPoint( Point3D* p )
32+
{
33+
if ( mTIN )
34+
{
35+
unsigned int number = mTIN->addPoint( p );
36+
return number;
37+
}
38+
else
39+
{
40+
cout << "warning, null pointer in TriDecorator::addPoint" << endl << flush;
41+
return 0;
42+
}
43+
}
44+
45+
void TriDecorator::performConsistencyTest()
46+
{
47+
if ( mTIN )
48+
{
49+
mTIN->performConsistencyTest();
50+
}
51+
else
52+
{
53+
cout << "warning, null pointer in TriDecorator::performConsistencyTest" << endl << flush;
54+
}
55+
}
56+
57+
bool TriDecorator::calcNormal( double x, double y, Vector3D* result )
58+
{
59+
if ( mTIN )
60+
{
61+
bool b = mTIN->calcNormal( x, y, result );
62+
return b;
63+
}
64+
else
65+
{
66+
cout << "warning, null pointer in TriDecorator::calcNormal" << endl << flush;
67+
return false;
68+
}
69+
}
70+
71+
bool TriDecorator::calcPoint( double x, double y, Point3D* result )
72+
{
73+
if ( mTIN )
74+
{
75+
bool b = mTIN->calcPoint( x, y, result );
76+
return b;
77+
}
78+
else
79+
{
80+
cout << "warning, null pointer in TriDecorator::calcPoint" << endl << flush;
81+
return false;
82+
}
83+
}
84+
85+
Point3D* TriDecorator::getPoint( unsigned int i ) const
86+
{
87+
if ( mTIN )
88+
{
89+
Point3D* p = mTIN->getPoint( i );
90+
return p;
91+
}
92+
else
93+
{
94+
cout << "warning, null pointer in TriDecorator::getPoint" << endl << flush;
95+
return 0;
96+
}
97+
}
98+
99+
bool TriDecorator::getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 )
100+
{
101+
if ( mTIN )
102+
{
103+
bool b = mTIN->getTriangle( x, y, p1, n1, p2, n2, p3, n3 );
104+
return b;
105+
}
106+
else
107+
{
108+
cout << "warning, null pointer in TriDecorator::getTriangle" << endl << flush;
109+
return false;
110+
}
111+
}
112+
113+
bool TriDecorator::getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 )
114+
{
115+
if ( mTIN )
116+
{
117+
bool b = mTIN->getTriangle( x, y, p1, p2, p3 );
118+
return b;
119+
}
120+
else
121+
{
122+
cout << "warning, null pointer in TriDecorator::getTriangle" << endl << flush;
123+
return false;
124+
}
125+
}
126+
127+
int TriDecorator::getNumberOfPoints() const
128+
{
129+
if ( mTIN )
130+
{
131+
return ( mTIN->getNumberOfPoints() );
132+
}
133+
else
134+
{
135+
cout << "warning, null pointer in TriDecorator::getNumberOfPoints" << endl << flush;
136+
return false;
137+
}
138+
}
139+
140+
int TriDecorator::getOppositePoint( int p1, int p2 )
141+
{
142+
if ( mTIN )
143+
{
144+
int i = mTIN->getOppositePoint( p1, p2 );
145+
return i;
146+
}
147+
else
148+
{
149+
cout << "warning, null pointer in TriDecorator::getOppositePoint" << endl << flush;
150+
return 0;
151+
}
152+
}
153+
154+
QList<int>* TriDecorator::getSurroundingTriangles( int pointno )
155+
{
156+
if ( mTIN )
157+
{
158+
QList<int>* vl = mTIN->getSurroundingTriangles( pointno );
159+
return vl;
160+
}
161+
else
162+
{
163+
cout << "warning, null pointer in TriDecorator::getSurroundingTriangles" << endl << flush;
164+
return 0;
165+
}
166+
}
167+
168+
double TriDecorator::getXMax() const
169+
{
170+
if ( mTIN )
171+
{
172+
double d = mTIN->getXMax();
173+
return d;
174+
}
175+
else
176+
{
177+
cout << "warning, null pointer in TriDecorator::getXMax" << endl << flush;
178+
return 0;
179+
}
180+
}
181+
182+
double TriDecorator::getXMin() const
183+
{
184+
if ( mTIN )
185+
{
186+
double d = mTIN->getXMin();
187+
return d;
188+
}
189+
else
190+
{
191+
cout << "warning, null pointer in TriDecorator::getXMin" << endl << flush;
192+
return 0;
193+
}
194+
}
195+
double TriDecorator::getYMax() const
196+
{
197+
if ( mTIN )
198+
{
199+
double d = mTIN->getYMax();
200+
return d;
201+
}
202+
else
203+
{
204+
cout << "warning, null pointer in TriDecorator::getYMax" << endl << flush;
205+
return 0;
206+
}
207+
}
208+
209+
double TriDecorator::getYMin() const
210+
{
211+
if ( mTIN )
212+
{
213+
double d = mTIN->getYMin();
214+
return d;
215+
}
216+
else
217+
{
218+
cout << "warning, null pointer in TriDecorator::getYMin" << endl << flush;
219+
return 0;
220+
}
221+
}
222+
223+
void TriDecorator::setForcedCrossBehaviour( Triangulation::forcedCrossBehaviour b )
224+
{
225+
if ( mTIN )
226+
{
227+
mTIN->setForcedCrossBehaviour( b );
228+
}
229+
else
230+
{
231+
cout << "warning, null pointer in TriDecorator::setForcedCrossBehaviour" << endl << flush;
232+
}
233+
}
234+
235+
void TriDecorator::setEdgeColor( int r, int g, int b )
236+
{
237+
if ( mTIN )
238+
{
239+
mTIN->setEdgeColor( r, g, b );
240+
}
241+
else
242+
{
243+
cout << "warning, null pointer in TriDecorator::setEdgeColor" << endl << flush;
244+
}
245+
}
246+
247+
void TriDecorator::setForcedEdgeColor( int r, int g, int b )
248+
{
249+
if ( mTIN )
250+
{
251+
mTIN->setForcedEdgeColor( r, g, b );
252+
}
253+
else
254+
{
255+
cout << "warning, null pointer in TriDecorator::setForcedEdgeColor" << endl << flush;
256+
}
257+
}
258+
259+
void TriDecorator::setBreakEdgeColor( int r, int g, int b )
260+
{
261+
if ( mTIN )
262+
{
263+
mTIN->setBreakEdgeColor( r, g, b );
264+
}
265+
else
266+
{
267+
cout << "warning, null pointer in TriDecorator::setBreakEdgeColor" << endl << flush;
268+
}
269+
}
270+
271+
void TriDecorator::setTriangleInterpolator( TriangleInterpolator* interpolator )
272+
{
273+
if ( mTIN )
274+
{
275+
mTIN->setTriangleInterpolator( interpolator );
276+
}
277+
else
278+
{
279+
cout << "warning, null pointer in TriDecorator::setTriangleInterpolator" << endl << flush;
280+
}
281+
}
282+
283+
void TriDecorator::eliminateHorizontalTriangles()
284+
{
285+
if ( mTIN )
286+
{
287+
mTIN->eliminateHorizontalTriangles();
288+
}
289+
else
290+
{
291+
cout << "warning, null pointer in TriDecorator::swapHorizontalTriangles" << endl << flush;
292+
}
293+
}
294+
295+
void TriDecorator::ruppertRefinement()
296+
{
297+
if ( mTIN )
298+
{
299+
mTIN->ruppertRefinement();
300+
}
301+
else
302+
{
303+
cout << "warning, null pointer in TriDecorator::ruppertRefinement" << endl << flush;
304+
}
305+
}
306+
307+
bool TriDecorator::pointInside( double x, double y )
308+
{
309+
if ( mTIN )
310+
{
311+
bool b = mTIN->pointInside( x, y );
312+
return b;
313+
}
314+
else
315+
{
316+
cout << "warning, null pointer in TriDecorator::pointInside" << endl << flush;
317+
return false;
318+
}
319+
}
320+
321+
bool TriDecorator::swapEdge( double x, double y )
322+
{
323+
if ( mTIN )
324+
{
325+
bool b = mTIN->swapEdge( x, y );
326+
return b;
327+
}
328+
else
329+
{
330+
cout << "warning, null pointer in TriDecorator::swapEdge" << endl << flush;
331+
return false;
332+
}
333+
}
334+
335+
QList<int>* TriDecorator::getPointsAroundEdge( double x, double y )
336+
{
337+
if ( mTIN )
338+
{
339+
return mTIN->getPointsAroundEdge( x, y );
340+
}
341+
else
342+
{
343+
cout << "warning, null pointer in TriDecorator::getPointsAroundEdge" << endl << flush;
344+
return 0;
345+
}
346+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/***************************************************************************
2+
TriDecorator.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 TRIDECORATOR_H
18+
#define TRIDECORATOR_H
19+
20+
using namespace std;
21+
22+
#include "Triangulation.h"
23+
24+
/**Decorator class for Triangulations (s. Decorator pattern in Gamma et al.)*/
25+
class TriDecorator: public Triangulation
26+
{
27+
public:
28+
TriDecorator();
29+
TriDecorator( Triangulation* t );
30+
virtual ~TriDecorator();
31+
virtual void addLine( Line3D* line, bool breakline );
32+
virtual int addPoint( Point3D* p );
33+
/**Adds an association to a triangulation*/
34+
virtual void addTriangulation( Triangulation* t );
35+
/**Performs a consistency check, remove this later*/
36+
virtual void performConsistencyTest();
37+
virtual bool calcNormal( double x, double y, Vector3D* result );
38+
virtual bool calcPoint( double x, double y, Point3D* result );
39+
virtual Point3D* getPoint( unsigned int i ) const;
40+
virtual int getNumberOfPoints() const;
41+
virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 );
42+
virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 );
43+
virtual int getOppositePoint( int p1, int p2 );
44+
virtual QList<int>* getSurroundingTriangles( int pointno );
45+
virtual double getXMax() const;
46+
virtual double getXMin() const;
47+
virtual double getYMax() const;
48+
virtual double getYMin() const;
49+
virtual void setForcedCrossBehaviour( Triangulation::forcedCrossBehaviour b );
50+
virtual void setEdgeColor( int r, int g, int b );
51+
virtual void setForcedEdgeColor( int r, int g, int b );
52+
virtual void setBreakEdgeColor( int r, int g, int b );
53+
virtual void setTriangleInterpolator( TriangleInterpolator* interpolator );
54+
virtual void eliminateHorizontalTriangles();
55+
virtual void ruppertRefinement();
56+
virtual bool pointInside( double x, double y );
57+
virtual bool swapEdge( double x, double y );
58+
virtual QList<int>* getPointsAroundEdge( double x, double y );
59+
protected:
60+
/**Association with a Triangulation object*/
61+
Triangulation* mTIN;
62+
};
63+
64+
inline TriDecorator::TriDecorator(): mTIN( 0 )
65+
{
66+
67+
}
68+
69+
inline TriDecorator::TriDecorator( Triangulation* t ): mTIN( t )
70+
{
71+
72+
}
73+
74+
inline TriDecorator::~TriDecorator()
75+
{
76+
77+
}
78+
79+
inline void TriDecorator::addTriangulation( Triangulation* t )
80+
{
81+
mTIN = t;
82+
}
83+
84+
#endif
85+
86+

‎src/analysis/interpolation/qgstininterpolator.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
***************************************************************************/
1717

1818
#include "qgstininterpolator.h"
19+
#include "CloughTocherInterpolator.h"
1920
#include "DualEdgeTriangulation.h"
21+
#include "NormVecDecorator.h"
2022
#include "LinTriangleInterpolator.h"
2123
#include "Point3D.h"
2224
#include "qgsfeature.h"
@@ -35,8 +37,8 @@
3537
#define isnan(f) _isnan(f)
3638
#endif
3739

38-
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData>& inputData, bool showProgressDialog ): QgsInterpolator( inputData ), mTriangulation( 0 ), \
39-
mTriangleInterpolator( 0 ), mIsInitialized( false ), mShowProgressDialog( showProgressDialog ), mExportTriangulationToFile( false )
40+
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData>& inputData, TIN_INTERPOLATION interpolation, bool showProgressDialog ): QgsInterpolator( inputData ), mTriangulation( 0 ), \
41+
mTriangleInterpolator( 0 ), mIsInitialized( false ), mShowProgressDialog( showProgressDialog ), mExportTriangulationToFile( false ), mInterpolation( interpolation )
4042
{
4143
}
4244

@@ -70,7 +72,16 @@ int QgsTINInterpolator::interpolatePoint( double x, double y, double& result )
7072
void QgsTINInterpolator::initialize()
7173
{
7274
DualEdgeTriangulation* theDualEdgeTriangulation = new DualEdgeTriangulation( 100000, 0 );
73-
mTriangulation = theDualEdgeTriangulation;
75+
if ( mInterpolation == CloughTocher )
76+
{
77+
NormVecDecorator* dec = new NormVecDecorator();
78+
dec->addTriangulation( theDualEdgeTriangulation );
79+
mTriangulation = dec;
80+
}
81+
else
82+
{
83+
mTriangulation = theDualEdgeTriangulation;
84+
}
7485

7586
//get number of features if we use a progress bar
7687
int nFeatures = 0;
@@ -124,7 +135,23 @@ void QgsTINInterpolator::initialize()
124135
}
125136

126137
delete theProgressDialog;
127-
mTriangleInterpolator = new LinTriangleInterpolator( theDualEdgeTriangulation );
138+
139+
if ( mInterpolation == CloughTocher )
140+
{
141+
CloughTocherInterpolator* ctInterpolator = new CloughTocherInterpolator();
142+
NormVecDecorator* dec = dynamic_cast<NormVecDecorator*>( mTriangulation );
143+
if ( dec )
144+
{
145+
dec->estimateFirstDerivatives();
146+
ctInterpolator->setTriangulation( dec );
147+
dec->setTriangleInterpolator( ctInterpolator );
148+
mTriangleInterpolator = ctInterpolator;
149+
}
150+
}
151+
else //linear
152+
{
153+
mTriangleInterpolator = new LinTriangleInterpolator( theDualEdgeTriangulation );
154+
}
128155
mIsInitialized = true;
129156

130157
//debug

‎src/analysis/interpolation/qgstininterpolator.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ class QgsFeature;
2929
class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
3030
{
3131
public:
32-
QgsTINInterpolator( const QList<LayerData>& inputData, bool showProgressDialog = false );
32+
//describes the type of interpolation
33+
enum TIN_INTERPOLATION
34+
{
35+
Linear,
36+
CloughTocher
37+
};
38+
QgsTINInterpolator( const QList<LayerData>& inputData, TIN_INTERPOLATION interpolation = Linear, bool showProgressDialog = false );
3339
~QgsTINInterpolator();
3440

3541
/**Calculates interpolation value for map coordinates x, y
@@ -51,6 +57,8 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
5157
bool mExportTriangulationToFile;
5258
/**File path to export the triangulation*/
5359
QString mTriangulationFilePath;
60+
/**Type of interpolation*/
61+
TIN_INTERPOLATION mInterpolation;
5462

5563
/**Create dual edge triangulation*/
5664
void initialize();

‎src/plugins/interpolation/qgstininterpolatordialog.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ QgsTINInterpolatorDialog::QgsTINInterpolatorDialog( QWidget* parent, QgisInterfa
3030
mTriangulationFileButton->setEnabled( false );
3131

3232
//enter available interpolation methods
33-
mInterpolationComboBox->insertItem( 0, tr( "Linear interpolation" ) );
34-
//mInterpolationComboBox->insertItem(1, tr("Clough-Toucher interpolation")); //to come...
33+
mInterpolationComboBox->insertItem( 0, tr( "Linear" ) );
34+
mInterpolationComboBox->insertItem( 1, tr( "Clough-Toucher (cubic)" ) );
3535
}
3636

3737
QgsTINInterpolatorDialog::~QgsTINInterpolatorDialog()
@@ -41,7 +41,17 @@ QgsTINInterpolatorDialog::~QgsTINInterpolatorDialog()
4141

4242
QgsInterpolator* QgsTINInterpolatorDialog::createInterpolator() const
4343
{
44-
QgsTINInterpolator* theInterpolator = new QgsTINInterpolator( mInputData, true );
44+
QgsTINInterpolator* theInterpolator = 0;
45+
46+
if ( mInterpolationComboBox->currentText() == tr( "Clough-Toucher (cubic)" ) )
47+
{
48+
theInterpolator = new QgsTINInterpolator( mInputData, QgsTINInterpolator::CloughTocher, true );
49+
}
50+
else //linear is the default
51+
{
52+
theInterpolator = new QgsTINInterpolator( mInputData, QgsTINInterpolator::Linear, true );
53+
}
54+
4555
if ( mExportTriangulationCheckBox->checkState() == Qt::Checked )
4656
{
4757
theInterpolator->setExportTriangulationToFile( true );

0 commit comments

Comments
 (0)
Please sign in to comment.