23 #include "qgsmeshmemorydataprovider.h" 29 const double D_TRUE = 1.0;
30 const double D_FALSE = 0.0;
31 const double D_NODATA = std::numeric_limits<double>::quiet_NaN();
33 std::shared_ptr<QgsMeshMemoryDatasetGroup> QgsMeshCalcUtils::create(
const QString &datasetGroupName )
const 35 const auto dp = mMeshLayer->dataProvider();
36 std::shared_ptr<QgsMeshMemoryDatasetGroup> grp;
37 for (
int groupIndex = 0; groupIndex < dp->datasetGroupCount(); ++groupIndex )
39 const auto meta = dp->datasetGroupMetadata( groupIndex );
40 const QString name = meta.name();
41 if ( name == datasetGroupName )
48 grp = std::make_shared<QgsMeshMemoryDatasetGroup>();
49 grp->isScalar = meta.isScalar();
50 grp->type = mOutputType;
51 grp->maximum = meta.maximum();
52 grp->minimum = meta.minimum();
53 grp->name = meta.name();
58 for (
int datasetIndex = 0; datasetIndex < dp->datasetCount( groupIndex ); ++datasetIndex )
61 const auto dsMeta = dp->datasetMetadata( index );
62 std::shared_ptr<QgsMeshMemoryDataset> ds = create( grp->type );
63 ds->maximum = dsMeta.maximum();
64 ds->minimum = dsMeta.minimum();
65 ds->time = dsMeta.time();
66 ds->valid = dsMeta.isValid();
69 QgsMeshDataBlock block = QgsMeshLayerUtils::datasetValues( mMeshLayer, index, 0, nativeCount );
72 Q_ASSERT( block.
count() == nativeCount );
80 QVector<double> data =
81 QgsMeshLayerUtils::interpolateFromFacesData(
88 Q_ASSERT( data.size() == resultCount );
89 for (
int valueIndex = 0; valueIndex < resultCount; ++valueIndex )
94 QVector<double> buf = block.
values();
95 QVector<double> x( nativeCount );
96 QVector<double> y( nativeCount );
97 for (
int value_i = 0; value_i < nativeCount; ++value_i )
99 x[value_i] = buf[2 * value_i];
100 y[value_i] = buf[2 * value_i + 1];
103 QVector<double> dataX =
104 QgsMeshLayerUtils::interpolateFromFacesData(
106 mMeshLayer->nativeMesh(),
107 mMeshLayer->triangularMesh(),
109 mMeshLayer->rendererSettings().scalarSettings( groupIndex ).dataInterpolationMethod()
111 Q_ASSERT( dataX.size() == resultCount );
112 QVector<double> dataY =
113 QgsMeshLayerUtils::interpolateFromFacesData(
115 mMeshLayer->nativeMesh(),
116 mMeshLayer->triangularMesh(),
118 mMeshLayer->rendererSettings().scalarSettings( groupIndex ).dataInterpolationMethod()
121 Q_ASSERT( dataY.size() == resultCount );
123 for (
int value_i = 0; value_i < resultCount; ++value_i )
131 for (
int value_i = 0; value_i < resultCount; ++value_i )
132 ds->values[value_i] = block.
value( value_i );
137 const QgsMeshDataBlock active = dp->areFacesActive( index, 0, dp->faceCount() );
138 Q_ASSERT( active.
count() == dp->faceCount() );
139 for (
int value_i = 0; value_i < dp->faceCount(); ++value_i )
142 grp->addDataset( ds );
151 std::shared_ptr<QgsMeshMemoryDataset> QgsMeshCalcUtils::create(
const QgsMeshMemoryDatasetGroup &grp )
const 153 return create( grp.type );
160 std::shared_ptr<QgsMeshMemoryDataset> ds = std::make_shared<QgsMeshMemoryDataset>();
163 ds->values.resize( mMeshLayer->dataProvider()->vertexCount() );
164 ds->active.resize( mMeshLayer->dataProvider()->faceCount() );
165 memset( ds->active.data(), 1,
static_cast<size_t>( ds->active.size() ) *
sizeof(
int ) );
169 ds->values.resize( mMeshLayer->dataProvider()->faceCount() );
175 QgsMeshCalcUtils:: QgsMeshCalcUtils(
QgsMeshLayer *layer,
176 const QStringList &usedGroupNames,
179 : mMeshLayer( layer )
183 mOutputType = determineResultDataType( layer, usedGroupNames );
187 for (
const QString &groupName : usedGroupNames )
189 std::shared_ptr<QgsMeshMemoryDatasetGroup> ds = create( groupName );
193 mDatasetGroupMap.insert( groupName, ds );
198 bool timesPopulated =
false;
199 const auto vals = mDatasetGroupMap.values();
200 for (
const auto &ds : vals )
202 if ( ds->datasetCount() == 0 )
208 if ( ds->datasetCount() > 1 )
210 if ( timesPopulated )
212 if ( ds->datasetCount() != mTimes.size() )
219 for (
int datasetIndex = 0; datasetIndex < ds->datasetCount(); ++datasetIndex )
221 std::shared_ptr<const QgsMeshMemoryDataset> o = ds->constDataset( datasetIndex );
222 if ( timesPopulated )
232 mTimes.append( o->time );
236 timesPopulated =
true;
241 if ( mTimes.isEmpty() )
243 mTimes.push_back( 0.0 );
248 for ( QVector<double>::iterator it = mTimes.begin(); it != mTimes.end(); )
252 ( ( *it >= startTime ) && ( *it <= endTime ) ) )
255 it = mTimes.erase( it );
260 for (
const auto &ds : vals )
262 if ( ds->type != mOutputType )
270 bool QgsMeshCalcUtils::isValid()
const 280 std::shared_ptr<const QgsMeshMemoryDatasetGroup> QgsMeshCalcUtils::group(
const QString &datasetName )
const 282 return mDatasetGroupMap[datasetName];
285 void QgsMeshCalcUtils::populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter,
const QgsRectangle &extent )
const 289 filter.clearDatasets();
291 std::shared_ptr<QgsMeshMemoryDataset> output = create( filter );
292 output->time = mTimes[0];
294 const QList<int> faceIndexesForRectangle = triangularMesh()->faceIndexesForRectangle( extent );
295 const QVector<int> trianglesToNativeFaces = triangularMesh()->trianglesToNativeFaces();
299 for (
const int faceIndex : faceIndexesForRectangle )
301 const int nativeIndex = trianglesToNativeFaces[faceIndex];
302 const QgsMeshFace face = nativeMesh()->face( nativeIndex );
303 for (
const int vertexIndex : face )
305 output->values[vertexIndex].set( D_TRUE );
311 for (
const int faceIndex : faceIndexesForRectangle )
313 const int nativeIndex = trianglesToNativeFaces[faceIndex];
314 output->values[nativeIndex].set( D_TRUE );
317 filter.addDataset( output );
321 void QgsMeshCalcUtils::populateMaskFilter( QgsMeshMemoryDatasetGroup &filter,
const QgsGeometry &mask )
const 325 filter.clearDatasets();
326 std::shared_ptr<QgsMeshMemoryDataset> output = create( filter );
327 output->time = mTimes[0];
329 const QVector<QgsMeshVertex> &vertices = triangularMesh()->vertices();
335 for (
int i = 0; i < nativeVertexCount; ++i )
340 output->values[i].set( D_TRUE );
344 output->values[i].set( D_FALSE );
350 const QVector<QgsMeshFace> &triangles = triangularMesh()->triangles();
351 for (
int i = 0; i < triangles.size(); ++i )
358 output->values[i].
set( D_TRUE );
362 output->values[i].set( D_FALSE );
366 filter.addDataset( output );
369 std::shared_ptr<QgsMeshMemoryDataset> QgsMeshCalcUtils::number(
double val,
double time )
const 371 Q_ASSERT( isValid() );
373 std::shared_ptr<QgsMeshMemoryDataset> output = create( mOutputType );
377 if ( std::isnan( val ) )
380 memset( output->active.data(), 0,
static_cast<size_t>( output->active.size() ) *
sizeof(
int ) );
384 for (
int i = 0; i < output->values.size(); ++i )
386 output->values[i].set( val );
393 void QgsMeshCalcUtils::number( QgsMeshMemoryDatasetGroup &group1,
double val )
const 395 Q_ASSERT( isValid() );
397 group1.datasets.clear();
398 std::shared_ptr<QgsMeshMemoryDataset> output = number( val, mTimes[0] );
399 group1.datasets.push_back( output );
403 void QgsMeshCalcUtils::ones( QgsMeshMemoryDatasetGroup &group1 )
const 405 Q_ASSERT( isValid() );
406 number( group1, 1.0 );
409 void QgsMeshCalcUtils::nodata( QgsMeshMemoryDatasetGroup &group1 )
const 411 Q_ASSERT( isValid() );
412 number( group1, D_NODATA );
416 std::shared_ptr<QgsMeshMemoryDataset> QgsMeshCalcUtils::copy(
417 std::shared_ptr<const QgsMeshMemoryDataset> dataset0
420 Q_ASSERT( isValid() );
421 Q_ASSERT( dataset0 );
423 std::shared_ptr<QgsMeshMemoryDataset> output = std::make_shared<QgsMeshMemoryDataset>();
424 output->values = dataset0->values;
425 output->active = dataset0->active;
426 output->time = dataset0->time;
427 output->valid = dataset0->valid;
431 void QgsMeshCalcUtils::copy( QgsMeshMemoryDatasetGroup &group1,
const QString &groupName )
const 433 Q_ASSERT( isValid() );
435 std::shared_ptr<const QgsMeshMemoryDatasetGroup> group2 = group( groupName );
438 if ( group2->datasetCount() == 1 )
441 std::shared_ptr<const QgsMeshMemoryDataset> o0 = group2->constDataset( 0 );
442 std::shared_ptr<QgsMeshMemoryDataset> output = copy( o0 );
443 group1.addDataset( output );
447 for (
int output_index = 0; output_index < group2->datasetCount(); ++output_index )
449 std::shared_ptr<const QgsMeshMemoryDataset> o0 = group2->constDataset( output_index );
452 ( ( o0->time >= mTimes.first() ) && ( o0->time <= mTimes.last() ) )
455 std::shared_ptr<QgsMeshMemoryDataset> output = copy( o0 );
456 group1.addDataset( output );
462 void QgsMeshCalcUtils::transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 )
const 464 Q_ASSERT( isValid() );
466 group1.clearDatasets();
467 for (
int i = 0; i < group2.datasetCount(); ++i )
469 std::shared_ptr<QgsMeshMemoryDataset> o = group2.datasets[i];
471 group1.addDataset( o );
473 group2.clearDatasets();
476 void QgsMeshCalcUtils::expand( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 478 Q_ASSERT( isValid() );
480 if ( group2.datasetCount() > 1 )
482 if ( group1.datasetCount() == 1 )
484 const std::shared_ptr<QgsMeshMemoryDataset> o0 = group1.datasets[0];
486 for (
int i = 1; i < group2.datasetCount(); ++i )
488 std::shared_ptr<QgsMeshMemoryDataset> o = copy( o0 );
490 group1.addDataset( o );
497 std::shared_ptr<QgsMeshMemoryDataset> QgsMeshCalcUtils::canditateDataset(
498 QgsMeshMemoryDatasetGroup &group,
499 int datasetIndex )
const 501 Q_ASSERT( isValid() );
503 if ( group.datasetCount() > 1 )
505 Q_ASSERT( group.datasetCount() > datasetIndex );
506 return group.datasets[datasetIndex];
510 Q_ASSERT( group.datasetCount() == 1 );
511 return group.datasets[0];
515 std::shared_ptr<const QgsMeshMemoryDataset> QgsMeshCalcUtils::constCandidateDataset(
516 const QgsMeshMemoryDatasetGroup &group,
517 int datasetIndex )
const 519 Q_ASSERT( isValid() );
521 if ( group.datasetCount() > 1 )
523 Q_ASSERT( group.datasetCount() > datasetIndex );
524 return group.constDataset( datasetIndex );
528 Q_ASSERT( group.datasetCount() == 1 );
529 return group.constDataset( 0 );
533 int QgsMeshCalcUtils::datasetCount(
534 const QgsMeshMemoryDatasetGroup &group1,
535 const QgsMeshMemoryDatasetGroup &group2 )
const 537 Q_ASSERT( isValid() );
539 if ( ( group1.datasetCount() > 1 ) || ( group2.datasetCount() > 1 ) )
541 return mTimes.size();
549 void QgsMeshCalcUtils::func1( QgsMeshMemoryDatasetGroup &group,
550 std::function<
double(
double )> func )
const 552 Q_ASSERT( isValid() );
554 for (
int time_index = 0; time_index < group.datasetCount(); ++time_index )
556 std::shared_ptr<QgsMeshMemoryDataset> output = canditateDataset( group, time_index );
558 for (
int n = 0; n < output->values.size(); ++n )
560 double val1 = output->values[n].scalar();
561 double res_val = D_NODATA;
562 if ( !std::isnan( val1 ) )
563 res_val = func( val1 );
564 output->values[n] = res_val;
573 void QgsMeshCalcUtils::func2( QgsMeshMemoryDatasetGroup &group1,
574 const QgsMeshMemoryDatasetGroup &group2,
575 std::function<
double(
double,
double )> func )
const 577 Q_ASSERT( isValid() );
578 Q_ASSERT( group1.type == group2.type );
580 expand( group1, group2 );
582 for (
int time_index = 0; time_index < datasetCount( group1, group2 ); ++time_index )
584 std::shared_ptr<QgsMeshMemoryDataset> o1 = canditateDataset( group1, time_index );
585 std::shared_ptr<const QgsMeshMemoryDataset> o2 = constCandidateDataset( group2, time_index );
587 for (
int n = 0; n < o2->values.size(); ++n )
589 double val1 = o1->values[n].scalar();
590 double val2 = o2->values[n].scalar();
591 double res_val = D_NODATA;
592 if ( !std::isnan( val1 ) && !std::isnan( val2 ) )
593 res_val = func( val1, val2 );
594 o1->values[n] = res_val;
605 void QgsMeshCalcUtils::funcAggr(
606 QgsMeshMemoryDatasetGroup &group1,
607 std::function<
double( QVector<double>& )> func
610 Q_ASSERT( isValid() );
615 output->time = mTimes[0];
618 QVector < double > vals;
619 for (
int datasetIndex = 0; datasetIndex < group1.datasetCount(); ++datasetIndex )
621 const std::shared_ptr<QgsMeshMemoryDataset> o1 = canditateDataset( group1, datasetIndex );
623 double val1 = o1->values[n].scalar();
627 if ( !std::isnan( val1 ) )
629 vals.push_back( val1 );
633 double res_val = D_NODATA;
634 if ( !vals.isEmpty() )
636 res_val = func( vals );
639 output->values[n] = res_val;
645 group1.datasets.clear();
646 group1.datasets.push_back( output );
652 output->time = mTimes[0];
655 output->values.resize( facesCount );
659 QVector < double > vals;
660 for (
int datasetIndex = 0; datasetIndex < group1.datasetCount(); ++datasetIndex )
662 const std::shared_ptr<QgsMeshMemoryDataset> o1 = canditateDataset( group1, datasetIndex );
663 double val1 = o1->values[n].scalar();
664 if ( !std::isnan( val1 ) )
666 vals.push_back( val1 );
670 double res_val = D_NODATA;
671 if ( !vals.isEmpty() )
673 res_val = func( vals );
676 output->values[n] = res_val;
679 group1.datasets.clear();
680 group1.datasets.push_back( output );
691 const QgsMesh *QgsMeshCalcUtils::nativeMesh()
const 698 void QgsMeshCalcUtils::updateMesh()
const 724 void QgsMeshCalcUtils::addIf( QgsMeshMemoryDatasetGroup &trueGroup,
725 const QgsMeshMemoryDatasetGroup &falseGroup,
726 const QgsMeshMemoryDatasetGroup &condition )
const 728 Q_ASSERT( isValid() );
731 expand( trueGroup, condition );
732 expand( trueGroup, falseGroup );
734 Q_ASSERT( trueGroup.type == falseGroup.type );
735 Q_ASSERT( trueGroup.type == condition.type );
737 for (
int time_index = 0; time_index < trueGroup.datasetCount(); ++time_index )
739 std::shared_ptr<QgsMeshMemoryDataset> true_o = canditateDataset( trueGroup, time_index );
740 std::shared_ptr<const QgsMeshMemoryDataset> false_o = constCandidateDataset( falseGroup, time_index );
741 std::shared_ptr<const QgsMeshMemoryDataset> condition_o = constCandidateDataset( condition, time_index );
742 for (
int n = 0; n < true_o->values.size(); ++n )
744 double conditionValue = condition_o->values[n].scalar();
745 double resultValue = D_NODATA;
746 if ( !std::isnan( conditionValue ) )
749 resultValue = true_o->values[n].scalar();
751 resultValue = false_o->values[n].scalar();
753 true_o->values[n] = resultValue;
760 activate( true_o, condition_o );
766 void QgsMeshCalcUtils::activate( QgsMeshMemoryDatasetGroup &group )
const 768 Q_ASSERT( isValid() );
772 for (
int datasetIndex = 0; datasetIndex < group.datasetCount(); ++datasetIndex )
774 std::shared_ptr<QgsMeshMemoryDataset> o1 = canditateDataset( group, datasetIndex );
782 void QgsMeshCalcUtils::activate(
783 std::shared_ptr<QgsMeshMemoryDataset> dataset,
784 std::shared_ptr<const QgsMeshMemoryDataset> refDataset
788 Q_ASSERT( isValid() );
794 if ( refDataset && !refDataset->active.isEmpty() && ( !refDataset->active[idx] ) )
796 dataset->active[idx] =
false;
800 if ( !dataset->active[idx] )
807 bool isActive =
true;
808 for (
int j = 0; j < face.size(); ++j )
810 if ( std::isnan( dataset->values[face[j]].scalar() ) )
816 dataset->active[idx] = isActive;
820 double QgsMeshCalcUtils::ffilter(
double val1,
double filter )
const 822 Q_ASSERT( !std::isnan( val1 ) );
830 double QgsMeshCalcUtils::fadd(
double val1,
double val2 )
const 832 Q_ASSERT( !std::isnan( val1 ) );
833 Q_ASSERT( !std::isnan( val2 ) );
838 double QgsMeshCalcUtils::fsubtract(
double val1,
double val2 )
const 840 Q_ASSERT( !std::isnan( val1 ) );
841 Q_ASSERT( !std::isnan( val2 ) );
846 double QgsMeshCalcUtils::fmultiply(
double val1,
double val2 )
const 848 Q_ASSERT( !std::isnan( val1 ) );
849 Q_ASSERT( !std::isnan( val2 ) );
854 double QgsMeshCalcUtils::fdivide(
double val1,
double val2 )
const 856 Q_ASSERT( !std::isnan( val1 ) );
857 Q_ASSERT( !std::isnan( val2 ) );
865 double QgsMeshCalcUtils::fpower(
double val1,
double val2 )
const 867 Q_ASSERT( !std::isnan( val1 ) );
868 Q_ASSERT( !std::isnan( val2 ) );
869 return pow( val1, val2 );
873 double QgsMeshCalcUtils::fequal(
double val1,
double val2 )
const 875 Q_ASSERT( !std::isnan( val1 ) );
876 Q_ASSERT( !std::isnan( val2 ) );
888 double QgsMeshCalcUtils::fnotEqual(
double val1,
double val2 )
const 890 Q_ASSERT( !std::isnan( val1 ) );
891 Q_ASSERT( !std::isnan( val2 ) );
903 double QgsMeshCalcUtils::fgreaterThan(
double val1,
double val2 )
const 905 Q_ASSERT( !std::isnan( val1 ) );
906 Q_ASSERT( !std::isnan( val2 ) );
918 double QgsMeshCalcUtils::flesserThan(
double val1,
double val2 )
const 920 Q_ASSERT( !std::isnan( val1 ) );
921 Q_ASSERT( !std::isnan( val2 ) );
933 double QgsMeshCalcUtils::flesserEqual(
double val1,
double val2 )
const 935 Q_ASSERT( !std::isnan( val1 ) );
936 Q_ASSERT( !std::isnan( val2 ) );
948 double QgsMeshCalcUtils::fgreaterEqual(
double val1,
double val2 )
const 950 Q_ASSERT( !std::isnan( val1 ) );
951 Q_ASSERT( !std::isnan( val2 ) );
964 double QgsMeshCalcUtils::flogicalAnd(
double val1,
double val2 )
const 966 Q_ASSERT( !std::isnan( val1 ) );
967 Q_ASSERT( !std::isnan( val2 ) );
970 if ( bval1 && bval2 )
977 double QgsMeshCalcUtils::flogicalOr(
double val1,
double val2 )
const 979 Q_ASSERT( !std::isnan( val1 ) );
980 Q_ASSERT( !std::isnan( val2 ) );
983 if ( bval1 || bval2 )
990 double QgsMeshCalcUtils::flogicalNot(
double val1 )
const 992 Q_ASSERT( !std::isnan( val1 ) );
1001 double QgsMeshCalcUtils::fchangeSign(
double val1 )
const 1003 Q_ASSERT( !std::isnan( val1 ) );
1007 double QgsMeshCalcUtils::fmin(
double val1,
double val2 )
const 1009 Q_ASSERT( !std::isnan( val1 ) );
1021 double QgsMeshCalcUtils::fmax(
double val1,
double val2 )
const 1023 Q_ASSERT( !std::isnan( val1 ) );
1024 Q_ASSERT( !std::isnan( val2 ) );
1036 double QgsMeshCalcUtils::fabs(
double val1 )
const 1038 Q_ASSERT( !std::isnan( val1 ) );
1050 double QgsMeshCalcUtils::fsumAggregated( QVector<double> &vals )
const 1052 Q_ASSERT( !vals.contains( D_NODATA ) );
1053 Q_ASSERT( !vals.isEmpty() );
1054 return std::accumulate( vals.begin(), vals.end(), 0.0 );
1057 double QgsMeshCalcUtils::fminimumAggregated( QVector<double> &vals )
const 1059 Q_ASSERT( !vals.contains( D_NODATA ) );
1060 Q_ASSERT( !vals.isEmpty() );
1061 return *std::min_element( vals.begin(), vals.end() );
1064 double QgsMeshCalcUtils::fmaximumAggregated( QVector<double> &vals )
const 1066 Q_ASSERT( !vals.contains( D_NODATA ) );
1067 Q_ASSERT( !vals.isEmpty() );
1068 return *std::max_element( vals.begin(), vals.end() );
1071 double QgsMeshCalcUtils::faverageAggregated( QVector<double> &vals )
const 1073 Q_ASSERT( !vals.contains( D_NODATA ) );
1074 Q_ASSERT( !vals.isEmpty() );
1075 return fsumAggregated( vals ) / vals.size();
1078 void QgsMeshCalcUtils::logicalNot( QgsMeshMemoryDatasetGroup &group1 )
const 1080 return func1( group1, std::bind( & QgsMeshCalcUtils::flogicalNot,
this, std::placeholders::_1 ) );
1083 void QgsMeshCalcUtils::changeSign( QgsMeshMemoryDatasetGroup &group1 )
const 1085 return func1( group1, std::bind( & QgsMeshCalcUtils::fchangeSign,
this, std::placeholders::_1 ) );
1088 void QgsMeshCalcUtils::abs( QgsMeshMemoryDatasetGroup &group1 )
const 1090 return func1( group1, std::bind( & QgsMeshCalcUtils::fabs,
this, std::placeholders::_1 ) );
1093 void QgsMeshCalcUtils::add( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1095 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fadd,
this, std::placeholders::_1, std::placeholders::_2 ) );
1098 void QgsMeshCalcUtils::subtract( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1100 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fsubtract,
this, std::placeholders::_1, std::placeholders::_2 ) );
1103 void QgsMeshCalcUtils::multiply( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1105 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fmultiply,
this, std::placeholders::_1, std::placeholders::_2 ) );
1108 void QgsMeshCalcUtils::divide( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1110 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fdivide,
this, std::placeholders::_1, std::placeholders::_2 ) );
1113 void QgsMeshCalcUtils::power( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1115 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fpower,
this, std::placeholders::_1, std::placeholders::_2 ) );
1118 void QgsMeshCalcUtils::equal( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1120 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fequal,
this, std::placeholders::_1, std::placeholders::_2 ) );
1123 void QgsMeshCalcUtils::notEqual( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1125 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fnotEqual,
this, std::placeholders::_1, std::placeholders::_2 ) );
1128 void QgsMeshCalcUtils::greaterThan( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1130 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fgreaterThan,
this, std::placeholders::_1, std::placeholders::_2 ) );
1133 void QgsMeshCalcUtils::lesserThan( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1135 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::flesserThan,
this, std::placeholders::_1, std::placeholders::_2 ) );
1138 void QgsMeshCalcUtils::lesserEqual( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1140 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::flesserEqual,
this, std::placeholders::_1, std::placeholders::_2 ) );
1143 void QgsMeshCalcUtils::greaterEqual( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1145 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fgreaterEqual,
this, std::placeholders::_1, std::placeholders::_2 ) );
1148 void QgsMeshCalcUtils::logicalAnd( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1150 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::flogicalAnd,
this, std::placeholders::_1, std::placeholders::_2 ) );
1153 void QgsMeshCalcUtils::logicalOr( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1155 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::flogicalOr,
this, std::placeholders::_1, std::placeholders::_2 ) );
1158 void QgsMeshCalcUtils::minimum( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1160 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fmin,
this, std::placeholders::_1, std::placeholders::_2 ) );
1163 void QgsMeshCalcUtils::maximum( QgsMeshMemoryDatasetGroup &group1,
const QgsMeshMemoryDatasetGroup &group2 )
const 1165 return func2( group1, group2, std::bind( & QgsMeshCalcUtils::fmax,
this, std::placeholders::_1, std::placeholders::_2 ) );
1170 QHash<QString, int> names;
1175 const QString name = meta.
name();
1176 names[ name ] = groupId;
1178 for (
const auto &datasetGroupName : usedGroupNames )
1180 if ( names.contains( datasetGroupName ) )
1182 int groupId = names.value( datasetGroupName );
1193 void QgsMeshCalcUtils::filter( QgsMeshMemoryDatasetGroup &group1,
const QgsRectangle &extent )
const 1195 QgsMeshMemoryDatasetGroup filter(
"filter", outputType() );
1196 populateSpatialFilter( filter, extent );
1197 return func2( group1, filter, std::bind( & QgsMeshCalcUtils::ffilter,
this, std::placeholders::_1, std::placeholders::_2 ) );
1200 void QgsMeshCalcUtils::filter( QgsMeshMemoryDatasetGroup &group1,
const QgsGeometry &mask )
const 1202 QgsMeshMemoryDatasetGroup filter(
"filter", outputType() );
1203 populateMaskFilter( filter, mask );
1204 return func2( group1, filter, std::bind( & QgsMeshCalcUtils::ffilter,
this, std::placeholders::_1, std::placeholders::_2 ) );
1207 void QgsMeshCalcUtils::sumAggregated( QgsMeshMemoryDatasetGroup &group1 )
const 1209 return funcAggr( group1, std::bind( & QgsMeshCalcUtils::fsumAggregated,
this, std::placeholders::_1 ) );
1212 void QgsMeshCalcUtils::minimumAggregated( QgsMeshMemoryDatasetGroup &group1 )
const 1214 return funcAggr( group1, std::bind( & QgsMeshCalcUtils::fminimumAggregated,
this, std::placeholders::_1 ) );
1217 void QgsMeshCalcUtils::maximumAggregated( QgsMeshMemoryDatasetGroup &group1 )
const 1219 return funcAggr( group1, std::bind( & QgsMeshCalcUtils::fmaximumAggregated,
this, std::placeholders::_1 ) );
1222 void QgsMeshCalcUtils::averageAggregated( QgsMeshMemoryDatasetGroup &group1 )
const 1224 return funcAggr( group1, std::bind( & QgsMeshCalcUtils::faverageAggregated,
this, std::placeholders::_1 ) );
CORE_EXPORT QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
virtual int faceCount() const =0
Returns number of faces in the native mesh.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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...
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
A geometry is the spatial representation of a feature.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
For each vertex does a simple average of values defined for all faces that contains given vertex...
The QgsMapSettings class contains configuration for rendering of the map.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
bool active(int index) const
Returns a value for active flag by the index For scalar and vector 2d the behavior is undefined...
QgsRectangle extent() const override
Returns the extent of the layer.
QVector< double > values() const
Returns buffer to the array with values For vector it is pairs (x1, y1, x2, y2, ...
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Base class for providing data for QgsMeshLayer.
Contains information about the context of a rendering operation.
Mesh - vertices and faces.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool isValid() const
Whether the block is valid.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetValue value(int index) const
Returns a value represented by the index For active flag the behavior is undefined.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshDatasetValue represents single dataset value.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QgsCoordinateReferenceSystem crs
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.