17#include <QApplication>
32 for (
int i = 0; i <
mNormVec->count(); i++ )
34 delete ( *mNormVec )[i];
50 if ( pointno == -100 )
62 auto it = list.constBegin();
63 while ( it != list.constEnd() )
113 int numberofbreaks = 0;
114 int ffirstbp = -1000;
115 int lfirstbp = -1000;
116 bool pointfound =
false;
117 int numberofruns = 0;
118 const int limit = 100000;
130 if ( ( ( vlist.count() ) % 4 ) != 0 )
132 QgsDebugError( QStringLiteral(
"warning, wrong number of items in vlist" ) );
136 auto it = vlist.constBegin();
143 if ( numberofruns > limit )
145 QgsDebugError( QStringLiteral(
"warning, a probable endless loop is detected" ) );
149 int p1, p2, p3, line;
160 if ( numberofbreaks > 0 )
163 if ( p1 != -1 && p2 != -1 && p3 != -1 )
181 if ( numberofbreaks == 0 )
188 if ( p2 == ffirstbp && p3 == lfirstbp && !firstrun )
192 QgsDebugError( QStringLiteral(
"warning: point (x,y) was in no triangle" ) );
199 if ( numberofbreaks > 0 && pointfound )
213 if ( it == vlist.constEnd() )
215 it = vlist.constBegin();
251 if ( v1 && v2 && v3 )
301 QgsDebugError( QStringLiteral(
"warning, number below 0" ) );
307bool NormVecDecorator::getTriangle(
double x,
double y,
QgsPoint &p1,
int &ptn1,
Vector3D *v1,
PointState *state1,
QgsPoint &p2,
int &ptn2,
Vector3D *v2,
PointState *state2,
QgsPoint &p3,
int &ptn3,
Vector3D *v3,
PointState *state3 )
309 if ( v1 && v2 && v3 && state1 && state2 && state3 )
317 ( *state1 ) = ( *mPointState )[( ptn1 )];
323 ( *state2 ) = ( *mPointState )[( ptn2 )];
329 ( *state3 ) = ( *mPointState )[( ptn3 )];
358 int numberofbreaks = 0;
360 double currentweight = 0;
383 ( *mNormVec )[pointno]->setX( 0 );
384 ( *mNormVec )[pointno]->setY( 0 );
385 ( *mNormVec )[pointno]->setZ( 0 );
390 if ( ( vlist.count() % 4 ) != 0 )
392 QgsDebugError( QStringLiteral(
"warning, wrong number of items in vlist" ) );
396 auto it = vlist.constBegin();
397 while ( it != vlist.constEnd() )
399 int p1, p2, p3, flag;
419 if ( p1 != -1 && p2 != -1 && p3 != -1 )
427 currentweight = 1 / ( dist1 * dist1 * dist2 * dist2 );
431 weights += currentweight;
437 if ( total.
getX() == 0 && total.
getY() == 0 && total.
getZ() == 0 )
443 total.
setX( total.
getX() / weights );
444 total.
setY( total.
getY() / weights );
445 total.
setZ( total.
getZ() / weights );
450 if ( numberofbreaks == 0 )
454 else if ( numberofbreaks == 1 )
476 ( *mNormVec )[pointno]->setX( total.
getX() );
477 ( *mNormVec )[pointno]->setY( total.
getY() );
478 ( *mNormVec )[pointno]->setZ( total.
getZ() );
488 ( *mPointState )[pointno] = status;
497 for (
int i = 0; i < numberPoints; i++ )
501 feedback->
setProgress( 100.0 *
static_cast< double >( i ) / numberPoints );
533 ( *mPointState )[pointno] = s;
552 for (
const int i : list )
bool getTriangle(double x, double y, QgsPoint &p1, Vector3D *v1, QgsPoint &p2, Vector3D *v2, QgsPoint &p3, Vector3D *v3)
Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p...
QVector< PointState > * mPointState
Vector who stores, it a point is not on a breakline, if it is a normal point of the breakline or if i...
bool alreadyestimated
Is true, if the normals already have been estimated.
bool calcNormal(double x, double y, QgsPoint &result) override
Calculates the normal at a point on the surface and assigns it to 'result'. Returns true in case of s...
bool saveTriangulation(QgsFeatureSink *sink, QgsFeedback *feedback=nullptr) const override
Saves the triangulation features to a feature sink.
~NormVecDecorator() override
QgsMesh triangulationToMesh(QgsFeedback *feedback=nullptr) const override
Returns a QgsMesh corresponding to the triangulation.
void eliminateHorizontalTriangles() override
Eliminates the horizontal triangles by swapping or by insertion of new points. If alreadyestimated is...
bool calcPoint(double x, double y, QgsPoint &result) override
Calculates x-, y and z-value of the point on the surface and assigns it to 'result'.
TriangleInterpolator * mInterpolator
Association with an interpolator object.
void setState(int pointno, PointState s)
Sets the state (BreakLine, Normal, EndPoint) of a point.
QVector< Vector3D * > * mNormVec
Vector that stores the normals for the points. If 'estimateFirstDerivatives()' was called and there i...
bool swapEdge(double x, double y) override
Swaps the edge which is closest to the point with x and y coordinates (if this is possible) and force...
PointState getState(int pointno) const
Returns the state of the point with the number 'pointno'.
bool calcNormalForPoint(double x, double y, int pointIndex, Vector3D *result)
Calculates the normal of a triangle-point for the point with coordinates x and y. This is needed,...
bool estimateFirstDerivatives(QgsFeedback *feedback=nullptr)
This method adds the functionality of estimating normals at the data points. Return true in the case ...
bool estimateFirstDerivative(int pointno)
Estimates the first derivative a point. Return true in case of success and false otherwise.
PointState
Enumeration for the state of a point. Normal means, that the point is not on a BreakLine,...
int addPoint(const QgsPoint &p) override
Adds a point to the triangulation.
An interface for objects which accept features via addFeature(s) methods.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void setProgress(double progress)
Sets the current progress for the feedback object.
Point geometry type, with support for z-dimension and m-values.
double distance3D(double x, double y, double z) const
Returns the Cartesian 3D distance between this point and a specified x, y, z coordinate.
virtual QgsMesh triangulationToMesh(QgsFeedback *feedback=nullptr) const =0
Returns a QgsMesh corresponding to the triangulation.
virtual void eliminateHorizontalTriangles()=0
Eliminates the horizontal triangles by swapping.
virtual bool saveTriangulation(QgsFeatureSink *sink, QgsFeedback *feedback=nullptr) const =0
Saves the triangulation features to a feature sink.
virtual int addPoint(const QgsPoint &point)=0
Adds a point to the triangulation.
virtual bool swapEdge(double x, double y)=0
Reads the content of a taff-file.
virtual QList< int > surroundingTriangles(int pointno)=0
Returns a value list with the information of the triangles surrounding (counterclockwise) a point.
QgsPoint * point(int i) const override
Returns a pointer to the point with number i.
QgsTriangulation * mTIN
Association with a Triangulation object.
QList< int > pointsAroundEdge(double x, double y) override
Returns a value list with the numbers of the four points, which would be affected by an edge swap.
QList< int > surroundingTriangles(int pointno) override
Returns a value list with the information of the triangles surrounding (counterclockwise) a point.
int pointsCount() const override
Returns the number of points.
bool triangleVertices(double x, double y, QgsPoint &p1, int &n1, QgsPoint &p2, int &n2, QgsPoint &p3, int &n3) override
Finds out in which triangle the point with coordinates x and y is and assigns the numbers of the vert...
virtual bool calcNormVec(double x, double y, QgsPoint &result)=0
Calculates the normal vector and assigns it to vec.
virtual bool calcPoint(double x, double y, QgsPoint &result)=0
Performs a linear interpolation in a triangle and assigns the x-,y- and z-coordinates to point.
Class Vector3D represents a 3D-Vector, capable to store x-,y- and z-coordinates in double values.
void standardise()
Standardises the vector.
void setX(double x)
Sets the x-component of the vector.
double getY() const
Returns the y-component of the vector.
double getX() const
Returns the x-component of the vector.
void setY(double y)
Sets the y-component of the vector.
double getZ() const
Returns the z-component of the vector.
void setZ(double z)
Sets the z-component of the vector.
bool ANALYSIS_EXPORT pointInsideTriangle(double x, double y, QgsPoint *p1, QgsPoint *p2, QgsPoint *p3)
Returns true, if the point with coordinates x and y is inside (or at the edge) of the triangle p1,...
void ANALYSIS_EXPORT normalFromPoints(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, Vector3D *vec)
Calculates the normal vector of the plane through the points p1, p2 and p3 and assigns the result to ...
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
Mesh - vertices, edges and faces.