#7742 Contour map : Fix mix of global grid and result index

Always use globalGridCellIndex for grid cells
Always use resultGridIndex for result property vectors
This commit is contained in:
Magne Sjaastad 2021-06-03 14:33:04 +02:00
parent 33a1bbb6d6
commit e1e7201b9b
2 changed files with 19 additions and 23 deletions

View File

@ -460,10 +460,9 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
{ {
case RESULTS_TOP_VALUE: case RESULTS_TOP_VALUE:
{ {
for ( auto cellIdxAndWeight : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
double cellValue = gridCellValues[cellIdx];
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
return cellValue; return cellValue;
@ -476,7 +475,7 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
RiaWeightedMeanCalculator<double> calculator; RiaWeightedMeanCalculator<double> calculator;
for ( auto [cellIdx, weight] : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
double cellValue = gridCellValues[cellIdx]; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
calculator.addValueAndWeight( cellValue, weight ); calculator.addValueAndWeight( cellValue, weight );
@ -493,7 +492,7 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
RiaWeightedGeometricMeanCalculator calculator; RiaWeightedGeometricMeanCalculator calculator;
for ( auto [cellIdx, weight] : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
double cellValue = gridCellValues[cellIdx]; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
if ( cellValue < 1.0e-8 ) if ( cellValue < 1.0e-8 )
@ -512,17 +511,16 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
case RESULTS_HARM_VALUE: case RESULTS_HARM_VALUE:
{ {
RiaWeightedHarmonicMeanCalculator calculator; RiaWeightedHarmonicMeanCalculator calculator;
for ( auto cellIdxAndWeight : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
double cellValue = gridCellValues[cellIdx];
if ( std::fabs( cellValue ) < 1.0e-8 ) if ( std::fabs( cellValue ) < 1.0e-8 )
{ {
return 0.0; return 0.0;
} }
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
calculator.addValueAndWeight( cellValue, cellIdxAndWeight.second ); calculator.addValueAndWeight( cellValue, weight );
} }
} }
if ( calculator.validAggregatedWeight() ) if ( calculator.validAggregatedWeight() )
@ -534,10 +532,9 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
case RESULTS_MAX_VALUE: case RESULTS_MAX_VALUE:
{ {
double maxValue = -std::numeric_limits<double>::infinity(); double maxValue = -std::numeric_limits<double>::infinity();
for ( auto cellIdxAndWeight : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
double cellValue = gridCellValues[cellIdx];
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
maxValue = std::max( maxValue, cellValue ); maxValue = std::max( maxValue, cellValue );
@ -552,10 +549,9 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
case RESULTS_MIN_VALUE: case RESULTS_MIN_VALUE:
{ {
double minValue = std::numeric_limits<double>::infinity(); double minValue = std::numeric_limits<double>::infinity();
for ( auto cellIdxAndWeight : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
double cellValue = gridCellValues[cellIdx];
minValue = std::min( minValue, cellValue ); minValue = std::min( minValue, cellValue );
} }
return minValue; return minValue;
@ -567,13 +563,12 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
case RESULTS_HC_COLUMN: case RESULTS_HC_COLUMN:
{ {
double sum = 0.0; double sum = 0.0;
for ( auto cellIdxAndWeight : matchingCells ) for ( auto [cellIdx, weight] : matchingCells )
{ {
size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[gridResultIndex( cellIdx )];
double cellValue = gridCellValues[cellIdx];
if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() ) if ( std::abs( cellValue ) != std::numeric_limits<double>::infinity() )
{ {
sum += cellValue * cellIdxAndWeight.second; sum += cellValue * weight;
} }
} }
return sum; return sum;
@ -1364,11 +1359,11 @@ std::vector<RimContourMapProjection::CellIndexAndResult>
double overlapVolume = calculateOverlapVolume( globalCellIdx, bbox2dElement ); double overlapVolume = calculateOverlapVolume( globalCellIdx, bbox2dElement );
if ( overlapVolume > 0.0 ) if ( overlapVolume > 0.0 )
{ {
size_t resultIndex = gridResultIndex( globalCellIdx ); double weight = overlapVolume *
double weight = overlapVolume * getParameterWeightForCell( resultIndex, weightingResultValues ); getParameterWeightForCell( gridResultIndex( globalCellIdx ), weightingResultValues );
if ( weight > 0.0 ) if ( weight > 0.0 )
{ {
matchingVisibleCellsAndWeight.push_back( std::make_pair( resultIndex, weight ) ); matchingVisibleCellsAndWeight.push_back( std::make_pair( globalCellIdx, weight ) );
} }
} }
} }
@ -1420,7 +1415,7 @@ std::vector<RimContourMapProjection::CellIndexAndResult>
double lengthInCell = calculateRayLengthInCell( globalCellIdx, highestPoint, lowestPoint ); double lengthInCell = calculateRayLengthInCell( globalCellIdx, highestPoint, lowestPoint );
if ( lengthInCell > 0.0 ) if ( lengthInCell > 0.0 )
{ {
cellsAndWeightsThisLayer.push_back( std::make_pair( gridResultIndex( globalCellIdx ), lengthInCell ) ); cellsAndWeightsThisLayer.push_back( std::make_pair( globalCellIdx, lengthInCell ) );
weightSumThisKLayer += lengthInCell; weightSumThisKLayer += lengthInCell;
} }
} }

View File

@ -142,6 +142,7 @@ protected:
const cvf::Vec3d& lowestPoint ) const = 0; const cvf::Vec3d& lowestPoint ) const = 0;
virtual double getParameterWeightForCell( size_t globalCellIdx, const std::vector<double>& parameterWeights ) const = 0; virtual double getParameterWeightForCell( size_t globalCellIdx, const std::vector<double>& parameterWeights ) const = 0;
// Use this function to get the result index into grid cell results. The index will differ if we have active cells
virtual size_t gridResultIndex( size_t globalCellIdx ) const; virtual size_t gridResultIndex( size_t globalCellIdx ) const;
double calculateValueInMapCell( uint i, uint j, const std::vector<double>& gridCellValues ) const; double calculateValueInMapCell( uint i, uint j, const std::vector<double>& gridCellValues ) const;