Skip to content

Commit

Permalink
Tighten API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 3, 2017
1 parent 5a8e351 commit 7d015ef
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
69 changes: 35 additions & 34 deletions src/analysis/interpolation/DualEdgeTriangulation.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsvectorfilewriter.h"
#include "qgsinterpolator.h"

double leftOfTresh = 0.00000001;

Expand Down Expand Up @@ -66,7 +67,7 @@ void DualEdgeTriangulation::performConsistencyTest()
QgsDebugMsg( "consistency test finished" );
}

void DualEdgeTriangulation::addLine( Line3D *line, bool breakline )
void DualEdgeTriangulation::addLine( Line3D *line, QgsInterpolator::SourceType lineType )
{
int actpoint = -10;//number of the last point, which has been inserted from the line
int currentpoint = -10;//number of the point, which is currently inserted from the line
Expand Down Expand Up @@ -101,7 +102,7 @@ void DualEdgeTriangulation::addLine( Line3D *line, bool breakline )
currentpoint = mDecorator->addPoint( QgsPoint( *line->getPoint() ) );
if ( currentpoint != -100 && actpoint != -100 && currentpoint != actpoint )//-100 is the return value if the point could not be not inserted
{
insertForcedSegment( actpoint, currentpoint, breakline );
insertForcedSegment( actpoint, currentpoint, lineType );
}
actpoint = currentpoint;
}
Expand Down Expand Up @@ -1166,7 +1167,7 @@ unsigned int DualEdgeTriangulation::insertEdge( int dual, int next, int point, b

}

int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, QgsInterpolator::SourceType segmentType )
{
if ( p1 == p2 )
{
Expand Down Expand Up @@ -1210,9 +1211,9 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
if ( mHalfEdge[actedge]->getPoint() == p2 )
{
mHalfEdge[actedge]->setForced( true );
mHalfEdge[actedge]->setBreak( breakline );
mHalfEdge[actedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setForced( true );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( breakline );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
return actedge;
}

Expand All @@ -1221,10 +1222,10 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
{
//mark actedge and Dual(actedge) as forced, reset p1 and start the method from the beginning
mHalfEdge[actedge]->setForced( true );
mHalfEdge[actedge]->setBreak( breakline );
mHalfEdge[actedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setForced( true );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( breakline );
int a = insertForcedSegment( mHalfEdge[actedge]->getPoint(), p2, breakline );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
int a = insertForcedSegment( mHalfEdge[actedge]->getPoint(), p2, segmentType );
return a;
}

Expand All @@ -1247,14 +1248,14 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
double distb = std::sqrt( ( crosspoint.x() - mPointVector[p4]->x() ) * ( crosspoint.x() - mPointVector[p4]->x() ) + ( crosspoint.y() - mPointVector[p4]->y() ) * ( crosspoint.y() - mPointVector[p4]->y() ) );
if ( dista <= distb )
{
insertForcedSegment( p1, p3, breakline );
int e = insertForcedSegment( p3, p2, breakline );
insertForcedSegment( p1, p3, segmentType );
int e = insertForcedSegment( p3, p2, segmentType );
return e;
}
else if ( distb <= dista )
{
insertForcedSegment( p1, p4, breakline );
int e = insertForcedSegment( p4, p2, breakline );
insertForcedSegment( p1, p4, segmentType );
int e = insertForcedSegment( p4, p2, segmentType );
return e;
}
}
Expand All @@ -1275,22 +1276,22 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
{
//mark actedge and Dual(actedge) as forced, reset p1 and start the method from the beginning
mHalfEdge[actedge]->setForced( true );
mHalfEdge[actedge]->setBreak( breakline );
mHalfEdge[actedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setForced( true );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( breakline );
int a = insertForcedSegment( p4, p2, breakline );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
int a = insertForcedSegment( p4, p2, segmentType );
return a;
}
else if ( frac == 1 )
{
//mark actedge and Dual(actedge) as forced, reset p1 and start the method from the beginning
mHalfEdge[actedge]->setForced( true );
mHalfEdge[actedge]->setBreak( breakline );
mHalfEdge[actedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setForced( true );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( breakline );
mHalfEdge[mHalfEdge[actedge]->getDual()]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
if ( p3 != p2 )
{
int a = insertForcedSegment( p3, p2, breakline );
int a = insertForcedSegment( p3, p2, segmentType );
return a;
}
else
Expand All @@ -1305,8 +1306,8 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
else
{
int newpoint = splitHalfEdge( mHalfEdge[actedge]->getNext(), frac );
insertForcedSegment( p1, newpoint, breakline );
int e = insertForcedSegment( newpoint, p2, breakline );
insertForcedSegment( p1, newpoint, segmentType );
int e = insertForcedSegment( newpoint, p2, segmentType );
return e;
}
}
Expand Down Expand Up @@ -1335,14 +1336,14 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
double distb = std::sqrt( ( crosspoint.x() - mPointVector[p4]->x() ) * ( crosspoint.x() - mPointVector[p4]->x() ) + ( crosspoint.y() - mPointVector[p4]->y() ) * ( crosspoint.y() - mPointVector[p4]->y() ) );
if ( dista <= distb )
{
insertForcedSegment( p1, p3, breakline );
int e = insertForcedSegment( p3, p2, breakline );
insertForcedSegment( p1, p3, segmentType );
int e = insertForcedSegment( p3, p2, segmentType );
return e;
}
else if ( distb <= dista )
{
insertForcedSegment( p1, p4, breakline );
int e = insertForcedSegment( p4, p2, breakline );
insertForcedSegment( p1, p4, segmentType );
int e = insertForcedSegment( p4, p2, segmentType );
return e;
}
}
Expand All @@ -1361,8 +1362,8 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
break;//seems that a roundoff error occurred. We found the endpoint
}
int newpoint = splitHalfEdge( mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext(), frac );
insertForcedSegment( p1, newpoint, breakline );
int e = insertForcedSegment( newpoint, p2, breakline );
insertForcedSegment( p1, newpoint, segmentType );
int e = insertForcedSegment( newpoint, p2, segmentType );
return e;
}

Expand All @@ -1382,14 +1383,14 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
double distb = std::sqrt( ( crosspoint.x() - mPointVector[p4]->x() ) * ( crosspoint.x() - mPointVector[p4]->x() ) + ( crosspoint.y() - mPointVector[p4]->y() ) * ( crosspoint.y() - mPointVector[p4]->y() ) );
if ( dista <= distb )
{
insertForcedSegment( p1, p3, breakline );
int e = insertForcedSegment( p3, p2, breakline );
insertForcedSegment( p1, p3, segmentType );
int e = insertForcedSegment( p3, p2, segmentType );
return e;
}
else if ( distb <= dista )
{
insertForcedSegment( p1, p4, breakline );
int e = insertForcedSegment( p4, p2, breakline );
insertForcedSegment( p1, p4, segmentType );
int e = insertForcedSegment( p4, p2, segmentType );
return e;
}
}
Expand All @@ -1408,8 +1409,8 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
break;//seems that a roundoff error occurred. We found the endpoint
}
int newpoint = splitHalfEdge( mHalfEdge[mHalfEdge[mHalfEdge[crossedEdges.last()]->getDual()]->getNext()]->getNext(), frac );
insertForcedSegment( p1, newpoint, breakline );
int e = insertForcedSegment( newpoint, p2, breakline );
insertForcedSegment( p1, newpoint, segmentType );
int e = insertForcedSegment( newpoint, p2, segmentType );
return e;
}

Expand Down Expand Up @@ -1444,11 +1445,11 @@ int DualEdgeTriangulation::insertForcedSegment( int p1, int p2, bool breakline )
//insert the forced edge and enter the corresponding halfedges as the first edges in the left and right polygons. The nexts and points are set later because of the algorithm to build two polygons from 'crossedEdges'
int firstedge = freelist.first();//edge pointing from p1 to p2
mHalfEdge[firstedge]->setForced( true );
mHalfEdge[firstedge]->setBreak( breakline );
mHalfEdge[firstedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
leftPolygon.append( firstedge );
int dualfirstedge = mHalfEdge[freelist.first()]->getDual();//edge pointing from p2 to p1
mHalfEdge[dualfirstedge]->setForced( true );
mHalfEdge[dualfirstedge]->setBreak( breakline );
mHalfEdge[dualfirstedge]->setBreak( segmentType == QgsInterpolator::SourceBreakLines );
rightPolygon.append( dualfirstedge );
freelist.pop_front();//delete the first entry from the freelist

Expand Down
5 changes: 2 additions & 3 deletions src/analysis/interpolation/DualEdgeTriangulation.h
Expand Up @@ -47,8 +47,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
DualEdgeTriangulation( int nop, Triangulation *decorator );
virtual ~DualEdgeTriangulation();
void setDecorator( Triangulation *d ) {mDecorator = d;}
//! Adds a line (e.g. a break-, structure- or an isoline) to the triangulation. The class takes ownership of the line object and its points
void addLine( Line3D *line SIP_TRANSFER, bool breakline ) override;
void addLine( Line3D *line SIP_TRANSFER, QgsInterpolator::SourceType lineType ) override;
int addPoint( const QgsPoint &p ) override;
//! Performs a consistency check, remove this later
virtual void performConsistencyTest() override;
Expand Down Expand Up @@ -136,7 +135,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
//! Inserts an edge and makes sure, everything is OK with the storage of the edge. The number of the HalfEdge is returned
unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
//! Inserts a forced segment between the points with the numbers p1 and p2 into the triangulation and returns the number of a HalfEdge belonging to this forced edge or -100 in case of failure
int insertForcedSegment( int p1, int p2, bool breakline );
int insertForcedSegment( int p1, int p2, QgsInterpolator::SourceType segmentType );
//! Threshold for the leftOfTest to handle numerical instabilities
//const static double leftOfTresh=0.00001;
//! Security to prevent endless loops in 'baseEdgeOfTriangle'. It there are more iteration then this number, the point will not be inserted
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/interpolation/TriDecorator.cpp
Expand Up @@ -17,11 +17,11 @@
#include "TriDecorator.h"
#include "qgslogger.h"

void TriDecorator::addLine( Line3D *line, bool breakline )
void TriDecorator::addLine( Line3D *line, QgsInterpolator::SourceType lineType )
{
if ( mTIN )
{
mTIN->addLine( line, breakline );
mTIN->addLine( line, lineType );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/TriDecorator.h
Expand Up @@ -34,7 +34,7 @@ class ANALYSIS_EXPORT TriDecorator : public Triangulation
TriDecorator();
explicit TriDecorator( Triangulation *t );
virtual ~TriDecorator();
virtual void addLine( Line3D *line, bool breakline ) override;
void addLine( Line3D *line, QgsInterpolator::SourceType lineType ) override;
int addPoint( const QgsPoint &p ) override;
//! Adds an association to a triangulation
virtual void addTriangulation( Triangulation *t );
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/interpolation/Triangulation.h
Expand Up @@ -22,6 +22,7 @@
#include <QPainter>
#include "TriangleInterpolator.h"
#include "qgis_analysis.h"
#include "qgsinterpolator.h"

class QgsFeatureSink;
class Line3D;
Expand All @@ -48,10 +49,10 @@ class ANALYSIS_EXPORT Triangulation
virtual ~Triangulation();

/**
* Adds a line (e.g. a break-, structure- or an isoline) to the triangulation.
* Adds a \a line (e.g. a break-, structure- or an isoline) to the triangulation.
* The class takes ownership of the line object and its points
*/
virtual void addLine( Line3D *line SIP_TRANSFER, bool breakline ) = 0;
virtual void addLine( Line3D *line SIP_TRANSFER, QgsInterpolator::SourceType lineType ) = 0;

/**
* Adds a \a point to the triangulation.
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgstininterpolator.cpp
Expand Up @@ -308,7 +308,7 @@ int QgsTINInterpolator::insertData( const QgsFeature &f, QgsInterpolator::ValueS
line->insertPoint( new QgsPoint( p.x(), p.y(), z ) );
}

mTriangulation->addLine( line, type == SourceBreakLines );
mTriangulation->addLine( line, type );
}
break;
}
Expand Down

0 comments on commit 7d015ef

Please sign in to comment.