30 static void bbox2rect(
32 const QSize &outputSize,
34 int &leftLim,
int &rightLim,
int &topLim,
int &bottomLim )
38 topLim = std::max(
int( ur.
y() ), 0 );
39 bottomLim = std::min(
int( ll.
y() ), outputSize.height() - 1 );
40 leftLim = std::max(
int( ll.
x() ), 0 );
41 rightLim = std::min(
int( ur.
x() ), outputSize.width() - 1 );
44 static void lamTol(
double &lam )
46 const static double eps = 1e-6;
47 if ( ( lam < 0.0 ) && ( lam > -eps ) )
54 double &lam1,
double &lam2,
double &lam3 )
56 if ( pA == pB || pA == pC || pB == pC )
65 double dot00 = v0 * v0;
66 double dot01 = v0 * v1;
67 double dot02 = v0 * v2;
68 double dot11 = v1 * v1;
69 double dot12 = v1 * v2;
72 double invDenom = 1.0 / ( dot00 * dot11 - dot01 * dot01 );
73 lam1 = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
74 lam2 = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
75 lam3 = 1.0 - lam1 - lam2;
83 if ( ( lam1 < 0 ) || ( lam2 < 0 ) || ( lam3 < 0 ) )
93 double val1,
double val2,
double val3,
const QgsPointXY &pt )
95 double lam1, lam2, lam3;
96 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
97 return std::numeric_limits<double>::quiet_NaN();
99 return lam1 * val3 + lam2 * val2 + lam3 * val1;
104 double lam1, lam2, lam3;
105 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
106 return std::numeric_limits<double>::quiet_NaN();
111 QgsMeshLayerInterpolator::QgsMeshLayerInterpolator(
113 const QVector<double> &datasetValues,
114 bool dataIsOnVertices,
117 : mTriangularMesh( m ),
118 mDatasetValues( datasetValues ),
120 mDataOnVertices( dataIsOnVertices ),
125 QgsMeshLayerInterpolator::~QgsMeshLayerInterpolator() =
default;
138 int QgsMeshLayerInterpolator::bandCount()
const 146 outputBlock->setIsNoData();
147 double *data =
reinterpret_cast<double *
>( outputBlock->bits() );
149 const QVector<QgsMeshFace> &triangles = mTriangularMesh.triangles();
150 const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices();
153 if ( mDataOnVertices )
154 Q_ASSERT( mDatasetValues.count() == mTriangularMesh.vertices().count() );
156 for (
int i = 0; i < triangles.size(); ++i )
163 const int v1 = face[0], v2 = face[1], v3 = face[2];
164 const QgsPoint p1 = vertices[v1], p2 = vertices[v2], p3 = vertices[v3];
174 int topLim, bottomLim, leftLim, rightLim;
175 bbox2rect( mContext.mapToPixel(), mOutputSize, bbox, leftLim, rightLim, topLim, bottomLim );
178 for (
int j = topLim; j <= bottomLim; j++ )
180 double *line = data + ( j * width );
181 for (
int k = leftLim; k <= rightLim; k++ )
184 const QgsPointXY p = mContext.mapToPixel().toMapCoordinates( k, j );
185 if ( mDataOnVertices )
186 val = interpolateFromVerticesData(
196 int face = mTriangularMesh.trianglesToNativeFaces()[i];
197 val = interpolateFromFacesData(
201 mDatasetValues[face],
206 if ( !std::isnan( val ) )
209 outputBlock->setIsData( j, k );
216 return outputBlock.release();;
A rectangle specified with double values.
A class to represent a 2D point.
DataType
Raster data types.
Sixty four bit floating point (double)
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
QgsRectangle extent() const override
Returns the extent of the layer.
Base class for processing filters like renderers, reprojector, resampler etc.
Point geometry type, with support for z-dimension and m-values.
A class to represent a vector.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
Contains information about the context of a rendering operation.
bool isCanceled() const
Tells whether the operation has been canceled already.
QVector< int > QgsMeshFace
List of vertex indexes.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
Feedback object tailored for raster block reading.