24#include <QApplication>
27using namespace Qt::StringLiterals;
34 for (
int i = 0; i <
mNormVec->count(); i++ )
36 delete ( *mNormVec )[i];
50 pointno =
mTIN->addPoint( p );
52 if ( pointno == -100 )
63 const QList<int> list =
mTIN->surroundingTriangles( pointno );
64 auto it = list.constBegin();
65 while ( it != list.constEnd() )
115 int numberofbreaks = 0;
116 int ffirstbp = -1000;
117 int lfirstbp = -1000;
118 bool pointfound =
false;
119 int numberofruns = 0;
120 const int limit = 100000;
132 if ( ( ( vlist.count() ) % 4 ) != 0 )
134 QgsDebugError( u
"warning, wrong number of items in vlist"_s );
138 auto it = vlist.constBegin();
145 if ( numberofruns > limit )
147 QgsDebugError( u
"warning, a probable endless loop is detected"_s );
151 int p1, p2, p3, line;
162 if ( numberofbreaks > 0 )
164 if ( p1 != -1 && p2 != -1 && p3 != -1 )
181 if ( numberofbreaks == 0 )
188 if ( p2 == ffirstbp && p3 == lfirstbp && !firstrun )
192 QgsDebugError( u
"warning: point (x,y) was in no triangle"_s );
199 if ( numberofbreaks > 0 && pointfound )
213 if ( it == vlist.constEnd() )
215 it = vlist.constBegin();
249 if ( v1 && v2 && v3 )
305bool 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 )
307 if ( v1 && v2 && v3 && state1 && state2 && state3 )
315 ( *state1 ) = ( *mPointState )[( ptn1 )];
321 ( *state2 ) = ( *mPointState )[( ptn2 )];
327 ( *state3 ) = ( *mPointState )[( ptn3 )];
355 int numberofbreaks = 0;
357 double currentweight = 0;
380 ( *mNormVec )[pointno]->setX( 0 );
381 ( *mNormVec )[pointno]->setY( 0 );
382 ( *mNormVec )[pointno]->setZ( 0 );
387 if ( ( vlist.count() % 4 ) != 0 )
389 QgsDebugError( u
"warning, wrong number of items in vlist"_s );
393 auto it = vlist.constBegin();
394 while ( it != vlist.constEnd() )
396 int p1, p2, p3, flag;
416 if ( p1 != -1 && p2 != -1 && p3 != -1 )
424 currentweight = 1 / ( dist1 * dist1 * dist2 * dist2 );
425 total.
setX( total.
getX() + part.
getX() * currentweight );
426 total.
setY( total.
getY() + part.
getY() * currentweight );
427 total.
setZ( total.
getZ() + part.
getZ() * currentweight );
428 weights += currentweight;
434 if ( total.
getX() == 0 && total.
getY() == 0 && total.
getZ() == 0 )
440 total.
setX( total.
getX() / weights );
441 total.
setY( total.
getY() / weights );
442 total.
setZ( total.
getZ() / weights );
447 if ( numberofbreaks == 0 )
451 else if ( numberofbreaks == 1 )
473 ( *mNormVec )[pointno]->setX( total.
getX() );
474 ( *mNormVec )[pointno]->setY( total.
getY() );
475 ( *mNormVec )[pointno]->setZ( total.
getZ() );
485 ( *mPointState )[pointno] = status;
494 for (
int i = 0; i < numberPoints; i++ )
498 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / numberPoints );
512 mTIN->eliminateHorizontalTriangles();
517 mTIN->eliminateHorizontalTriangles();
530 ( *mPointState )[pointno] = s;
548 b =
mTIN->swapEdge( x, y );
549 for (
const int i : list )
557 b =
mTIN->swapEdge( x, y );
574 return mTIN->saveTriangulation( sink, feedback );
583 return mTIN->triangulationToMesh( feedback );
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.
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...
Represents a 3D-Vector, capable of storing 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.