Skip to content
Permalink
Browse files

renaming and cleaning of Triangulation class and export to QgsMesh

  • Loading branch information
vcloarec authored and nyalldawson committed Jul 30, 2020
1 parent a4372d2 commit eb24446f84f60013e95f2df74b727bbbec62895b
@@ -10,14 +10,14 @@ SET(QGIS_ANALYSIS_SRCS
interpolation/qgstininterpolator.cpp
interpolation/Bezier3D.cpp
interpolation/CloughTocherInterpolator.cpp
interpolation/DualEdgeTriangulation.cpp
interpolation/qgsdualedgetriangulation.cpp
interpolation/HalfEdge.cpp
interpolation/LinTriangleInterpolator.cpp
interpolation/MathUtils.cpp
interpolation/NormVecDecorator.cpp
interpolation/ParametricLine.cpp
interpolation/TriangleInterpolator.cpp
interpolation/Triangulation.cpp
interpolation/qgstriangulation.cpp
interpolation/TriDecorator.cpp
interpolation/Vector3D.cpp

@@ -273,15 +273,15 @@ SET(QGIS_ANALYSIS_HDRS

interpolation/Bezier3D.h
interpolation/CloughTocherInterpolator.h
interpolation/DualEdgeTriangulation.h
interpolation/qgsdualedgetriangulation.h
interpolation/HalfEdge.h
interpolation/LinTriangleInterpolator.h
interpolation/MathUtils.h
interpolation/NormVecDecorator.h
interpolation/ParametricLine.h
interpolation/TriDecorator.h
interpolation/TriangleInterpolator.h
interpolation/Triangulation.h
interpolation/qgstriangulation.h
interpolation/Vector3D.h
interpolation/qgsgridfilewriter.h
interpolation/qgsidwinterpolator.h
@@ -42,9 +42,20 @@ double CloughTocherInterpolator::calcBernsteinPoly( int n, int i, int j, int k,
return result;
}

bool CloughTocherInterpolator::calcNormVec( double x, double y, Vector3D *result )
static void normalize( QgsPoint &point )
{
if ( result )
double length = sqrt( pow( point.x(), 2 ) + pow( point.y(), 2 ) + pow( point.z(), 2 ) );
if ( length > 0 )
{
point.setX( point.x() / length );
point.setY( point.y() / length );
point.setZ( point.z() / length );
}
}

bool CloughTocherInterpolator::calcNormVec( double x, double y, QgsPoint &result )
{
if ( !result.isEmpty() )
{
init( x, y );
QgsPoint barycoord( 0, 0, 0 );//barycentric coordinates of (x,y) with respect to the triangle
@@ -66,10 +77,10 @@ bool CloughTocherInterpolator::calcNormVec( double x, double y, Vector3D *result
endpointVXY.setZ( 3 * ( zv - zw ) );
Vector3D v1( endpointUXY.x() - x, endpointUXY.y() - y, endpointUXY.z() );
Vector3D v2( endpointVXY.x() - x, endpointVXY.y() - y, endpointVXY.z() );
result->setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result->setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result->setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
result->standardise();
result.setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result.setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result.setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
normalize( result );
return true;
}
//is the point in the second subtriangle (point2,point3,cp10)?
@@ -85,10 +96,10 @@ bool CloughTocherInterpolator::calcNormVec( double x, double y, Vector3D *result
endpointVXY.setZ( 3 * ( zv - zw ) );
Vector3D v1( endpointUXY.x() - x, endpointUXY.y() - y, endpointUXY.z() );
Vector3D v2( endpointVXY.x() - x, endpointVXY.y() - y, endpointVXY.z() );
result->setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result->setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result->setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
result->standardise();
result.setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result.setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result.setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
normalize( result );
return true;

}
@@ -105,42 +116,39 @@ bool CloughTocherInterpolator::calcNormVec( double x, double y, Vector3D *result
endpointVXY.setZ( 3 * ( zv - zw ) );
Vector3D v1( endpointUXY.x() - x, endpointUXY.y() - y, endpointUXY.z() );
Vector3D v2( endpointVXY.x() - x, endpointVXY.y() - y, endpointVXY.z() );
result->setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result->setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result->setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
result->standardise();
result.setX( v1.getY()*v2.getZ() - v1.getZ()*v2.getY() );
result.setY( v1.getZ()*v2.getX() - v1.getX()*v2.getZ() );
result.setZ( v1.getX()*v2.getY() - v1.getY()*v2.getX() );
normalize( result );
return true;
}

//the point is in none of the subtriangles, test if point has the same position as one of the vertices
if ( x == point1.x() && y == point1.y() )
{
result->setX( -der1X );
result->setY( -der1Y );
result->setZ( 1 );
result->standardise();
result.setX( -der1X );
result.setY( -der1Y );
result.setZ( 1 ); normalize( result );
return true;
}
else if ( x == point2.x() && y == point2.y() )
{
result->setX( -der2X );
result->setY( -der2Y );
result->setZ( 1 );
result->standardise();
result.setX( -der2X );
result.setY( -der2Y );
result.setZ( 1 ); normalize( result );
return true;
}
else if ( x == point3.x() && y == point3.y() )
{
result->setX( -der3X );
result->setY( -der3Y );
result->setZ( 1 );
result->standardise();
result.setX( -der3X );
result.setY( -der3Y );
result.setZ( 1 ); normalize( result );
return true;
}

result->setX( 0 );//return a vertical normal if failed
result->setY( 0 );
result->setZ( 1 );
result.setX( 0 );//return a vertical normal if failed
result.setY( 0 );
result.setZ( 1 );
return false;

}
@@ -106,7 +106,7 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
CloughTocherInterpolator( NormVecDecorator *tin );

//! Calculates the normal vector and assigns it to vec (not implemented at the moment)
bool calcNormVec( double x, double y, Vector3D *result SIP_OUT ) override;
bool calcNormVec( double x, double y, QgsPoint &result SIP_OUT ) override;
bool calcPoint( double x, double y, QgsPoint &result SIP_OUT ) override;
virtual void setTriangulation( NormVecDecorator *tin );
};
@@ -26,7 +26,7 @@ bool LinTriangleInterpolator::calcFirstDerX( double x, double y, Vector3D *vec )
QgsPoint pt2( 0, 0, 0 );
QgsPoint pt3( 0, 0, 0 );

if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
if ( !mTIN->triangleVertices( x, y, pt1, pt2, pt3 ) )
{
return false;//point outside the convex hull or numerical problems
}
@@ -52,7 +52,7 @@ bool LinTriangleInterpolator::calcFirstDerY( double x, double y, Vector3D *vec )
QgsPoint pt2( 0, 0, 0 );
QgsPoint pt3( 0, 0, 0 );

if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
if ( !mTIN->triangleVertices( x, y, pt1, pt2, pt3 ) )
{
return false;
}
@@ -70,10 +70,10 @@ bool LinTriangleInterpolator::calcFirstDerY( double x, double y, Vector3D *vec )
}
}

bool LinTriangleInterpolator::calcNormVec( double x, double y, Vector3D *vec )
bool LinTriangleInterpolator::calcNormVec( double x, double y, QgsPoint &vec )
{
//calculate vector product of the two derivative vectors in x- and y-direction and set the length to 1
if ( vec && mTIN )
if ( mTIN )
{
Vector3D vec1;
Vector3D vec2;
@@ -83,9 +83,9 @@ bool LinTriangleInterpolator::calcNormVec( double x, double y, Vector3D *vec )
{return false;}
Vector3D vec3( vec1.getY()*vec2.getZ() - vec1.getZ()*vec2.getY(), vec1.getZ()*vec2.getX() - vec1.getX()*vec2.getZ(), vec1.getX()*vec2.getY() - vec1.getY()*vec2.getX() );//calculate vector product
double absvec3 = std::sqrt( vec3.getX() * vec3.getX() + vec3.getY() * vec3.getY() + vec3.getZ() * vec3.getZ() );//length of vec3
vec->setX( vec3.getX() / absvec3 );//standardize vec3 and assign it to vec
vec->setY( vec3.getY() / absvec3 );
vec->setZ( vec3.getZ() / absvec3 );
vec.setX( vec3.getX() / absvec3 );//standardize vec3 and assign it to vec
vec.setY( vec3.getY() / absvec3 );
vec.setZ( vec3.getZ() / absvec3 );
return true;
}

@@ -105,7 +105,7 @@ bool LinTriangleInterpolator::calcPoint( double x, double y, QgsPoint &point )
QgsPoint pt2( 0, 0, 0 );
QgsPoint pt3( 0, 0, 0 );

if ( !mTIN->getTriangle( x, y, pt1, pt2, pt3 ) )
if ( !mTIN->triangleVertices( x, y, pt1, pt2, pt3 ) )
{
return false;//point is outside the convex hull or numerical problems
}
@@ -18,7 +18,7 @@
#define LINTRIANGLEINTERPOLATOR_H

#include "TriangleInterpolator.h"
#include "DualEdgeTriangulation.h"
#include "qgsdualedgetriangulation.h"
#include "qgis_analysis.h"

#define SIP_NO_FILE
@@ -34,18 +34,18 @@ class ANALYSIS_EXPORT LinTriangleInterpolator : public TriangleInterpolator
//! Default constructor
LinTriangleInterpolator() = default;
//! Constructor with reference to a DualEdgeTriangulation object
LinTriangleInterpolator( DualEdgeTriangulation *tin );
LinTriangleInterpolator( QgsDualEdgeTriangulation *tin );
//! Calculates the normal vector and assigns it to vec
bool calcNormVec( double x, double y, Vector3D *result SIP_OUT ) override;
bool calcNormVec( double x, double y, QgsPoint &result SIP_OUT ) override;
bool calcPoint( double x, double y, QgsPoint &result SIP_OUT ) override;
//! Returns a pointer to the current Triangulation object
virtual DualEdgeTriangulation *getTriangulation() const;
virtual QgsDualEdgeTriangulation *getTriangulation() const;
//! Sets a Triangulation
virtual void setTriangulation( DualEdgeTriangulation *tin );
virtual void setTriangulation( QgsDualEdgeTriangulation *tin );


protected:
DualEdgeTriangulation *mTIN = nullptr;
QgsDualEdgeTriangulation *mTIN = nullptr;
//! Calculates the first derivative with respect to x for a linear surface and assigns it to vec
virtual bool calcFirstDerX( double x, double y, Vector3D *result SIP_OUT );
//! Calculates the first derivative with respect to y for a linear surface and assigns it to vec
@@ -54,17 +54,17 @@ class ANALYSIS_EXPORT LinTriangleInterpolator : public TriangleInterpolator

#ifndef SIP_RUN

inline LinTriangleInterpolator::LinTriangleInterpolator( DualEdgeTriangulation *tin ): mTIN( tin )
inline LinTriangleInterpolator::LinTriangleInterpolator( QgsDualEdgeTriangulation *tin ): mTIN( tin )
{

}

inline DualEdgeTriangulation *LinTriangleInterpolator::getTriangulation() const
inline QgsDualEdgeTriangulation *LinTriangleInterpolator::getTriangulation() const
{
return mTIN;
}

inline void LinTriangleInterpolator::setTriangulation( DualEdgeTriangulation *tin )
inline void LinTriangleInterpolator::setTriangulation( QgsDualEdgeTriangulation *tin )
{
mTIN = tin;
}

0 comments on commit eb24446

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