24#include <QApplication>
31 for (
int i = 0; i <
mNormVec->count(); i++ )
33 delete ( *mNormVec )[i];
47 pointno =
mTIN->addPoint( p );
49 if ( pointno == -100 )
60 const QList<int> list =
mTIN->surroundingTriangles( pointno );
61 auto it = list.constBegin();
62 while ( it != list.constEnd() )
112 int numberofbreaks = 0;
113 int ffirstbp = -1000;
114 int lfirstbp = -1000;
115 bool pointfound =
false;
116 int numberofruns = 0;
117 const int limit = 100000;
129 if ( ( ( vlist.count() ) % 4 ) != 0 )
131 QgsDebugError( QStringLiteral(
"warning, wrong number of items in vlist" ) );
135 auto it = vlist.constBegin();
142 if ( numberofruns > limit )
144 QgsDebugError( QStringLiteral(
"warning, a probable endless loop is detected" ) );
148 int p1, p2, p3, line;
159 if ( numberofbreaks > 0 )
161 if ( p1 != -1 && p2 != -1 && p3 != -1 )
178 if ( numberofbreaks == 0 )
185 if ( p2 == ffirstbp && p3 == lfirstbp && !firstrun )
189 QgsDebugError( QStringLiteral(
"warning: point (x,y) was in no triangle" ) );
196 if ( numberofbreaks > 0 && pointfound )
210 if ( it == vlist.constEnd() )
212 it = vlist.constBegin();
246 if ( v1 && v2 && v3 )
296 QgsDebugError( QStringLiteral(
"warning, number below 0" ) );
302bool 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 )
304 if ( v1 && v2 && v3 && state1 && state2 && state3 )
312 ( *state1 ) = ( *mPointState )[( ptn1 )];
318 ( *state2 ) = ( *mPointState )[( ptn2 )];
324 ( *state3 ) = ( *mPointState )[( ptn3 )];
352 int numberofbreaks = 0;
354 double currentweight = 0;
377 ( *mNormVec )[pointno]->setX( 0 );
378 ( *mNormVec )[pointno]->setY( 0 );
379 ( *mNormVec )[pointno]->setZ( 0 );
384 if ( ( vlist.count() % 4 ) != 0 )
386 QgsDebugError( QStringLiteral(
"warning, wrong number of items in vlist" ) );
390 auto it = vlist.constBegin();
391 while ( it != vlist.constEnd() )
393 int p1, p2, p3, flag;
413 if ( p1 != -1 && p2 != -1 && p3 != -1 )
421 currentweight = 1 / ( dist1 * dist1 * dist2 * dist2 );
422 total.
setX( total.
getX() + part.
getX() * currentweight );
423 total.
setY( total.
getY() + part.
getY() * currentweight );
424 total.
setZ( total.
getZ() + part.
getZ() * currentweight );
425 weights += currentweight;
431 if ( total.
getX() == 0 && total.
getY() == 0 && total.
getZ() == 0 )
437 total.
setX( total.
getX() / weights );
438 total.
setY( total.
getY() / weights );
439 total.
setZ( total.
getZ() / weights );
444 if ( numberofbreaks == 0 )
448 else if ( numberofbreaks == 1 )
470 ( *mNormVec )[pointno]->setX( total.
getX() );
471 ( *mNormVec )[pointno]->setY( total.
getY() );
472 ( *mNormVec )[pointno]->setZ( total.
getZ() );
482 ( *mPointState )[pointno] = status;
491 for (
int i = 0; i < numberPoints; i++ )
495 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / numberPoints );
509 mTIN->eliminateHorizontalTriangles();
514 mTIN->eliminateHorizontalTriangles();
527 ( *mPointState )[pointno] = s;
545 b =
mTIN->swapEdge( x, y );
546 for (
const int i : list )
554 b =
mTIN->swapEdge( x, y );
571 return mTIN->saveTriangulation( sink, feedback );
580 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.