53 if ( !averagingMethod )
60 block = averagingMethod->
calculate( block3d );
64 QVector<double> QgsMeshLayerUtils::calculateMagnitudes(
const QgsMeshDataBlock &block )
67 int count = block.
count();
68 QVector<double> ret( count );
70 for (
int i = 0; i < count; ++i )
78 void QgsMeshLayerUtils::boundingBoxToScreenRectangle(
const QgsMapToPixel &mtp,
79 const QSize &outputSize,
88 topLim = std::max(
int( ur.
y() ), 0 );
89 bottomLim = std::min(
int( ll.
y() ), outputSize.height() - 1 );
90 leftLim = std::max(
int( ll.
x() ), 0 );
91 rightLim = std::min(
int( ur.
x() ), outputSize.width() - 1 );
94 static void lamTol(
double &lam )
96 const static double eps = 1e-6;
97 if ( ( lam < 0.0 ) && ( lam > -eps ) )
104 double &lam1,
double &lam2,
double &lam3 )
106 if ( pA == pB || pA == pC || pB == pC )
115 double dot00 = v0 * v0;
116 double dot01 = v0 * v1;
117 double dot02 = v0 * v2;
118 double dot11 = v1 * v1;
119 double dot12 = v1 * v2;
122 double invDenom = 1.0 / ( dot00 * dot11 - dot01 * dot01 );
123 lam1 = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
124 lam2 = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
125 lam3 = 1.0 - lam1 - lam2;
133 if ( ( lam1 < 0 ) || ( lam2 < 0 ) || ( lam3 < 0 ) )
142 double val1,
double val2,
double val3,
const QgsPointXY &pt )
144 double lam1, lam2, lam3;
145 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
146 return std::numeric_limits<double>::quiet_NaN();
148 return lam1 * val3 + lam2 * val2 + lam3 * val1;
153 double lam1, lam2, lam3;
154 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
155 return QgsVector( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
157 return vect3 * lam1 + vect2 * lam2 + vect1 * lam3;
163 double lam1, lam2, lam3;
164 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
165 return std::numeric_limits<double>::quiet_NaN();
173 double lam1, lam2, lam3;
174 if ( !E3T_physicalToBarycentric( p1, p2, p3, pt, lam1, lam2, lam3 ) )
175 return QgsVector( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
181 QVector<double> QgsMeshLayerUtils::interpolateFromFacesData(
182 QVector<double> valuesOnFaces,
188 Q_UNUSED( triangularMesh )
191 assert( nativeMesh );
196 int vertexCount = triangularMesh->
vertices().size();
198 QVector<double> res( vertexCount, 0.0 );
200 QVector<int> count( vertexCount, 0 );
202 for (
int i = 0; i < nativeMesh->
faces.size(); ++i )
204 if ( !active || active->
active( i ) )
206 double val = valuesOnFaces[ i ];
207 if ( !std::isnan( val ) )
211 for (
int j = 0; j < face.size(); ++j )
213 int vertexIndex = face[j];
214 res[vertexIndex] += val;
215 count[vertexIndex] += 1;
221 for (
int i = 0; i < vertexCount; ++i )
223 if ( count.at( i ) > 0 )
225 res[i] = res[i] / double( count.at( i ) );
229 res[i] = std::numeric_limits<double>::quiet_NaN();
239 double xMin = p1.
x();
240 double xMax = p1.
x();
241 double yMin = p1.
y();
242 double yMax = p1.
y();
245 xMin = ( ( xMin < p2.
x() ) ? xMin : p2.
x() );
246 xMax = ( ( xMax > p2.
x() ) ? xMax : p2.
x() );
247 yMin = ( ( yMin < p2.
y() ) ? yMin : p2.
y() );
248 yMax = ( ( yMax > p2.
y() ) ? yMax : p2.
y() );
251 xMin = ( ( xMin < p3.
x() ) ? xMin : p3.
x() );
252 xMax = ( ( xMax > p3.
x() ) ? xMax : p3.
x() );
253 yMin = ( ( yMin < p3.
y() ) ? yMin : p3.
y() );
254 yMax = ( ( yMax > p3.
y() ) ? yMax : p3.
y() );
267 hours = hours / 3600.0;
270 hours = hours / 60.0;
275 hours = hours * 24.0;
283 qint64 seconds =
static_cast<qint64
>( hours * 3600.0 );
284 dateTime = dateTime.addSecs( seconds );
285 ret = dateTime.toString( format );
287 ret = dateTime.toString();
292 format = format.trimmed();
294 int totalHours =
static_cast<int>( hours );
296 if ( format == QStringLiteral(
"hh:mm:ss.zzz" ) )
298 int ms =
static_cast<int>( hours * 3600.0 * 1000 );
299 int seconds = ms / 1000;
301 int m = seconds / 60;
302 int s = seconds % 60;
305 ret = QStringLiteral(
"%1:%2:%3.%4" ).
306 arg( h, 2, 10, QLatin1Char(
'0' ) ).
307 arg( m, 2, 10, QLatin1Char(
'0' ) ).
308 arg( s, 2, 10, QLatin1Char(
'0' ) ).
309 arg( z, 3, 10, QLatin1Char(
'0' ) );
311 else if ( format == QStringLiteral(
"hh:mm:ss" ) )
313 int seconds =
static_cast<int>( hours * 3600.0 );
314 int m = seconds / 60;
315 int s = seconds % 60;
318 ret = QStringLiteral(
"%1:%2:%3" ).
319 arg( h, 2, 10, QLatin1Char(
'0' ) ).
320 arg( m, 2, 10, QLatin1Char(
'0' ) ).
321 arg( s, 2, 10, QLatin1Char(
'0' ) );
324 else if ( format == QStringLiteral(
"d hh:mm:ss" ) )
326 int seconds =
static_cast<int>( hours * 3600.0 );
327 int m = seconds / 60;
328 int s = seconds % 60;
331 int d = totalHours / 24;
333 ret = QStringLiteral(
"%1 d %2:%3:%4" ).
335 arg( h, 2, 10, QLatin1Char(
'0' ) ).
336 arg( m, 2, 10, QLatin1Char(
'0' ) ).
337 arg( s, 2, 10, QLatin1Char(
'0' ) );
339 else if ( format == QStringLiteral(
"d hh" ) )
341 int d = totalHours / 24;
342 int h = totalHours % 24;
343 ret = QStringLiteral(
"%1 d %2" ).
347 else if ( format == QStringLiteral(
"d" ) )
349 int d = totalHours / 24;
350 ret = QStringLiteral(
"%1" ).arg( d );
352 else if ( format == QStringLiteral(
"ss" ) )
354 int seconds =
static_cast<int>( hours * 3600.0 );
355 ret = QStringLiteral(
"%1" ).arg( seconds );
359 ret = QStringLiteral(
"%1" ).arg( hours );
365 QDateTime QgsMeshLayerUtils::firstReferenceTime(
QgsMeshLayer *meshLayer )
A rectangle specified with double values.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
A class to represent a 2D point.
int count() const
Number of items stored in the block.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame...
TimeUnit providerTimeUnit() const
Returns the provider time unit.
DataType type() const
Type of data stored in the block.
bool isValid() const
Whether the block is valid.
For each vertex does a simple average of values defined for all faces that contains given vertex...
QVector< QgsMeshVertex > vertices
vertices
double relativeTimeOffsetHours() const
Returns number of offset hours for relative time formatting.
bool active(int index) const
Returns a value for active flag by the index For scalar and vector 2d the behavior is undefined...
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
DataInterpolationMethod
Interpolation of value defined on vertices from datasets with data defined on faces.
QgsMeshRendererSettings rendererSettings() const
Returns renderer settings.
QgsMeshDataBlock calculate(const QgsMesh3dDataBlock &block3d, QgsFeedback *feedback=nullptr) const
Calculated 2d block values from 3d stacked mesh values.
QString absoluteTimeFormat() const
Returns format used for absolute time.
Integer boolean flag whether face is active.
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
bool useAbsoluteTime() const
Returns whether to use absolute time format.
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
Represents a mesh time settings for mesh datasets.
A class to represent a vector.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsMesh3dAveragingMethod * averagingMethod() const
Returns averaging method for conversion of 3d stacked mesh data to 2d data.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Base class for providing data for QgsMeshLayer.
QDateTime absoluteTimeReferenceTime() const
Returns reference time used for absolute time format.
Mesh - vertices and faces.
bool isValid() const
Whether the block is valid.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Abstract class to interpolate 3d stacked mesh data to 2d data.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
virtual QgsMesh3dDataBlock dataset3dValues(QgsMeshDatasetIndex index, int faceIndex, int count) const =0
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes...
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QVector< QgsMeshFace > faces
faces
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
QString relativeTimeFormat() const
Returns format used for relative time.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.