Skip to content

Commit 4bba95f

Browse files
committed
Fix broken TIN interpolation (loss of point z coordinates)
1 parent 356588a commit 4bba95f

File tree

5 files changed

+48
-39
lines changed

5 files changed

+48
-39
lines changed

src/analysis/interpolation/CloughTocherInterpolator.cc

-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ bool CloughTocherInterpolator::calcNormVec( double x, double y, Vector3D *result
164164
return true;
165165
}
166166

167-
QgsDebugMsg( "warning, point outside the triangle" );
168167
result->setX( 0 );//return a vertical normal if failed
169168
result->setY( 0 );
170169
result->setZ( 1 );
@@ -240,7 +239,6 @@ bool CloughTocherInterpolator::calcPoint( double x, double y, QgsPoint *result )
240239
}
241240
else
242241
{
243-
QgsDebugMsg( "warning, point outside the triangle" );
244242
result->setX( x );
245243
result->setY( y );
246244
result->setZ( 0 );

src/analysis/interpolation/CloughTocherInterpolator.h

+38-22
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,43 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
3333
//! Tolerance of the barycentric coordinates at the borders of the triangles (to prevent errors because of very small negativ baricentric coordinates)
3434
double mEdgeTolerance;
3535
//! First point of the triangle in x-,y-,z-coordinates
36-
QgsPoint point1;
36+
QgsPoint point1 = QgsPoint( 0, 0, 0 );
3737
//! Second point of the triangle in x-,y-,z-coordinates
38-
QgsPoint point2;
38+
QgsPoint point2 = QgsPoint( 0, 0, 0 );
3939
//! Third point of the triangle in x-,y-,z-coordinates
40-
QgsPoint point3;
41-
QgsPoint cp1;
42-
QgsPoint cp2;
43-
QgsPoint cp3;
44-
QgsPoint cp4;
45-
QgsPoint cp5;
46-
QgsPoint cp6;
47-
QgsPoint cp7;
48-
QgsPoint cp8;
49-
QgsPoint cp9;
50-
QgsPoint cp10;
51-
QgsPoint cp11;
52-
QgsPoint cp12;
53-
QgsPoint cp13;
54-
QgsPoint cp14;
55-
QgsPoint cp15;
56-
QgsPoint cp16;
40+
QgsPoint point3 = QgsPoint( 0, 0, 0 );
41+
//! Control point 1
42+
QgsPoint cp1 = QgsPoint( 0, 0, 0 );
43+
//! Control point 2
44+
QgsPoint cp2 = QgsPoint( 0, 0, 0 );
45+
//! Control point 3
46+
QgsPoint cp3 = QgsPoint( 0, 0, 0 );
47+
//! Control point 4
48+
QgsPoint cp4 = QgsPoint( 0, 0, 0 );
49+
//! Control point 5
50+
QgsPoint cp5 = QgsPoint( 0, 0, 0 );
51+
//! Control point 6
52+
QgsPoint cp6 = QgsPoint( 0, 0, 0 );
53+
//! Control point 7
54+
QgsPoint cp7 = QgsPoint( 0, 0, 0 );
55+
//! Control point 8
56+
QgsPoint cp8 = QgsPoint( 0, 0, 0 );
57+
//! Control point 9
58+
QgsPoint cp9 = QgsPoint( 0, 0, 0 );
59+
//! Control point 10
60+
QgsPoint cp10 = QgsPoint( 0, 0, 0 );
61+
//! Control point 11
62+
QgsPoint cp11 = QgsPoint( 0, 0, 0 );
63+
//! Control point 12
64+
QgsPoint cp12 = QgsPoint( 0, 0, 0 );
65+
//! Control point 13
66+
QgsPoint cp13 = QgsPoint( 0, 0, 0 );
67+
//! Control point 14
68+
QgsPoint cp14 = QgsPoint( 0, 0, 0 );
69+
//! Control point 15
70+
QgsPoint cp15 = QgsPoint( 0, 0, 0 );
71+
//! Control point 16
72+
QgsPoint cp16 = QgsPoint( 0, 0, 0 );
5773
//! Derivative in x-direction at point1
5874
double der1X;
5975
//! Derivative in y-direction at point1
@@ -67,11 +83,11 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
6783
//! Derivative in y-direction at point3
6884
double der3Y;
6985
//! Stores point1 of the last run
70-
QgsPoint lpoint1;
86+
QgsPoint lpoint1 = QgsPoint( 0, 0, 0 );
7187
//! Stores point2 of the last run
72-
QgsPoint lpoint2;
88+
QgsPoint lpoint2 = QgsPoint( 0, 0, 0 );
7389
//! Stores point3 of the last run
74-
QgsPoint lpoint3;
90+
QgsPoint lpoint3 = QgsPoint( 0, 0, 0 );
7591
//! Finds out, in which triangle the point with the coordinates x and y is
7692
void init( double x, double y );
7793
//! 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

src/analysis/interpolation/DualEdgeTriangulation.cc

+9-13
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,6 @@ bool DualEdgeTriangulation::getTriangle( double x, double y, QgsPoint *p1, int *
976976
int edge = baseEdgeOfTriangle( &point );
977977
if ( edge == -10 )//the point is outside the convex hull
978978
{
979-
QgsDebugMsg( "edge outside the convex hull" );
980979
return false;
981980
}
982981

@@ -1094,7 +1093,6 @@ bool DualEdgeTriangulation::getTriangle( double x, double y, QgsPoint *p1, QgsPo
10941093
int edge = baseEdgeOfTriangle( &point );
10951094
if ( edge == -10 )//the point is outside the convex hull
10961095
{
1097-
QgsDebugMsg( "edge outside the convex hull" );
10981096
return false;
10991097
}
11001098
else if ( edge >= 0 )//the point is inside the convex hull
@@ -1178,14 +1176,12 @@ bool DualEdgeTriangulation::getTriangle( double x, double y, QgsPoint *p1, QgsPo
11781176
}
11791177
else//problems
11801178
{
1181-
QgsDebugMsg( QString( "problems: the edge is: %1" ).arg( edge ) );
11821179
return false;
11831180
}
11841181
}
11851182

11861183
else
11871184
{
1188-
QgsDebugMsg( "warning, null pointer" );
11891185
return false;
11901186
}
11911187
}
@@ -1270,7 +1266,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
12701266
{
12711267
if ( mHalfEdge[mHalfEdge[actedge]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::SnappingTypeVertex )//if the crossed edge is a forced edge, we have to snap the forced line to the next node
12721268
{
1273-
QgsPoint crosspoint;
1269+
QgsPoint crosspoint( 0, 0, 0 );
12741270
int p3, p4;
12751271
p3 = mHalfEdge[mHalfEdge[actedge]->getNext()]->getPoint();
12761272
p4 = mHalfEdge[mHalfEdge[mHalfEdge[actedge]->getNext()]->getDual()]->getPoint();
@@ -1292,7 +1288,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
12921288
}
12931289
else if ( mHalfEdge[mHalfEdge[actedge]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::InsertVertex )//if the crossed edge is a forced edge, we have to insert a new vertice on this edge
12941290
{
1295-
QgsPoint crosspoint;
1291+
QgsPoint crosspoint( 0, 0, 0 );
12961292
int p3, p4;
12971293
p3 = mHalfEdge[mHalfEdge[actedge]->getNext()]->getPoint();
12981294
p4 = mHalfEdge[mHalfEdge[mHalfEdge[actedge]->getNext()]->getDual()]->getPoint();
@@ -1358,7 +1354,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
13581354
{
13591355
if ( mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::SnappingTypeVertex )//if the crossed edge is a forced edge and mForcedCrossBehavior is SnappingType_VERTICE, we have to snap the forced line to the next node
13601356
{
1361-
QgsPoint crosspoint;
1357+
QgsPoint crosspoint( 0, 0, 0 );
13621358
int p3, p4;
13631359
p3 = mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getPoint();
13641360
p4 = mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getPoint();
@@ -1380,7 +1376,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
13801376
}
13811377
else if ( mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::InsertVertex )//if the crossed edge is a forced edge, we have to insert a new vertice on this edge
13821378
{
1383-
QgsPoint crosspoint;
1379+
QgsPoint crosspoint( 0, 0, 0 );
13841380
int p3, p4;
13851381
p3 = mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getPoint();
13861382
p4 = mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getPoint();
@@ -1405,7 +1401,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
14051401
{
14061402
if ( mHalfEdge[mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::SnappingTypeVertex )//if the crossed edge is a forced edge and mForcedCrossBehavior is SnappingType_VERTICE, we have to snap the forced line to the next node
14071403
{
1408-
QgsPoint crosspoint;
1404+
QgsPoint crosspoint( 0, 0, 0 );
14091405
int p3, p4;
14101406
p3 = mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getPoint();
14111407
p4 = mHalfEdge[mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getNext()]->getPoint();
@@ -1427,7 +1423,7 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
14271423
}
14281424
else if ( mHalfEdge[mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getNext()]->getForced() && mForcedCrossBehavior == Triangulation::InsertVertex )//if the crossed edge is a forced edge, we have to insert a new vertice on this edge
14291425
{
1430-
QgsPoint crosspoint;
1426+
QgsPoint crosspoint( 0, 0, 0 );
14311427
int p3, p4;
14321428
p3 = mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getPoint();
14331429
p4 = mHalfEdge[mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getNext()]->getPoint();
@@ -1769,7 +1765,7 @@ void DualEdgeTriangulation::ruppertRefinement()
17691765
int minedgenext;
17701766
int minedgenextnext;
17711767

1772-
QgsPoint circumcenter;
1768+
QgsPoint circumcenter( 0, 0, 0 );
17731769

17741770
while ( !edge_angle.empty() )
17751771
{
@@ -2205,7 +2201,7 @@ void DualEdgeTriangulation::ruppertRefinement()
22052201

22062202
/*******otherwise, try to add the circumcenter to the triangulation************************************************************************************************/
22072203

2208-
QgsPoint *p = new QgsPoint();
2204+
QgsPoint *p = new QgsPoint( 0, 0, 0 );
22092205
mDecorator->calcPoint( circumcenter.x(), circumcenter.y(), p );
22102206
int pointno = mDecorator->addPoint( p );
22112207

@@ -3218,7 +3214,7 @@ int DualEdgeTriangulation::splitHalfEdge( int edge, float position )
32183214
QgsPoint *p = new QgsPoint( mPointVector[mHalfEdge[edge]->getPoint()]->x()*position + mPointVector[mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint()]->x() * ( 1 - position ), mPointVector[mHalfEdge[edge]->getPoint()]->y()*position + mPointVector[mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint()]->y() * ( 1 - position ), 0 );
32193215

32203216
//calculate the z-value of the point to insert
3221-
QgsPoint zvaluepoint;
3217+
QgsPoint zvaluepoint( 0, 0, 0 );
32223218
mDecorator->calcPoint( p->x(), p->y(), &zvaluepoint );
32233219
p->setZ( zvaluepoint.z() );
32243220

src/analysis/interpolation/NormVecDecorator.cc

-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ bool NormVecDecorator::getTriangle( double x, double y, QgsPoint *p1, int *ptn1,
350350
}
351351
else
352352
{
353-
QgsDebugMsg( "warning, getTriangle returned false" );
354353
return false;
355354
}
356355

src/analysis/interpolation/qgstininterpolator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int QgsTINInterpolator::interpolatePoint( double x, double y, double &result )
5858
return 1;
5959
}
6060

61-
QgsPoint r;
61+
QgsPoint r( 0, 0, 0 );
6262
if ( !mTriangleInterpolator->calcPoint( x, y, &r ) )
6363
{
6464
return 2;

0 commit comments

Comments
 (0)