Skip to content

Commit

Permalink
Move calculateExpandedPorBarBBox
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Nov 1, 2024
1 parent b0eb78e commit d52ff27
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
#include "cvfStructGridGeometryGenerator.h"
#include "cvfVector3.h"

#include <algorithm>
#include <array>

CAF_PDM_SOURCE_INIT( RimGeoMechContourMapProjection, "RimGeoMechContourMapProjection" );

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -172,52 +169,6 @@ cvf::ref<cvf::UByteArray> RimGeoMechContourMapProjection::getCellVisibility() co
return cellGridIdxVisibility;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RimGeoMechContourMapProjection::calculateExpandedPorBarBBox( int timeStep, int frameIndex ) const
{
RigFemResultAddress porBarAddr( RigFemResultPosEnum::RIG_ELEMENT_NODAL,
RigFemAddressDefines::porBar(),
view()->cellResult()->resultComponentName().toStdString() );
RigGeoMechCaseData* caseData = geoMechCase()->geoMechData();
RigFemPartResultsCollection* resultCollection = caseData->femPartResults();

const std::vector<float>& resultValues = resultCollection->resultValues( porBarAddr, 0, timeStep, frameIndex );
cvf::BoundingBox boundingBox;

if ( resultValues.empty() )
{
return boundingBox;
}

for ( int i = 0; i < m_femPart->elementCount(); ++i )
{
size_t resValueIdx = m_femPart->elementNodeResultIdx( (int)i, 0 );
CVF_ASSERT( resValueIdx < resultValues.size() );
double scalarValue = resultValues[resValueIdx];
bool validPorValue = scalarValue != std::numeric_limits<double>::infinity();

if ( validPorValue )
{
std::array<cvf::Vec3d, 8> hexCorners;
m_femPartGrid->cellCornerVertices( i, hexCorners.data() );
for ( size_t c = 0; c < 8; ++c )
{
boundingBox.add( hexCorners[c] );
}
}
}
cvf::Vec3d boxMin = boundingBox.min();
cvf::Vec3d boxMax = boundingBox.max();
cvf::Vec3d boxExtent = boundingBox.extent();
boxMin.x() -= boxExtent.x() * 0.5 * m_paddingAroundPorePressureRegion();
boxMin.y() -= boxExtent.y() * 0.5 * m_paddingAroundPorePressureRegion();
boxMax.x() += boxExtent.x() * 0.5 * m_paddingAroundPorePressureRegion();
boxMax.y() += boxExtent.y() * 0.5 * m_paddingAroundPorePressureRegion();
return cvf::BoundingBox( boxMin, boxMax );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -235,7 +186,12 @@ void RimGeoMechContourMapProjection::updateGridInformation()
{
auto [stepIdx, frameIdx] = view()->currentStepAndDataFrame();

expandedBoundingBox = calculateExpandedPorBarBBox( stepIdx, frameIdx );
expandedBoundingBox =
RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( *geoMechCase->geoMechData(),
view()->cellResult()->resultComponentName().toStdString(),
stepIdx,
frameIdx,
m_paddingAroundPorePressureRegion() );
if ( !expandedBoundingBox.isValid() )
{
m_limitToPorePressureRegions = false;
Expand All @@ -257,7 +213,10 @@ void RimGeoMechContourMapProjection::updateGridInformation()
expandedBoundingBox = cvf::BoundingBox( minExpandedPoint, maxExpandedPoint );

m_contourMapGrid = std::make_unique<RigContourMapGrid>( gridBoundingBox, expandedBoundingBox, sampleSpacing() );
m_contourMapProjection = std::make_unique<RigGeoMechContourMapProjection>( *geoMechCase->geoMechData(), *m_contourMapGrid );
m_contourMapProjection = std::make_unique<RigGeoMechContourMapProjection>( *geoMechCase->geoMechData(),
*m_contourMapGrid,
m_limitToPorePressureRegions,
m_paddingAroundPorePressureRegion );
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
#include "RigFemPart.h"
#include "RigFemResultAddress.h"

#include "RimCheckableNamedObject.h"
#include "RimContourMapProjection.h"

#include "cafDisplayCoordTransform.h"
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"

#include "cvfArray.h"
#include "cvfBoundingBox.h"
#include "cvfGeometryBuilderFaceList.h"
#include "cvfString.h"
#include "cvfVector2.h"

class RimGeoMechContourMapView;
class RimGeoMechCase;
Expand Down Expand Up @@ -61,24 +55,18 @@ class RimGeoMechContourMapProjection : public RimContourMapProjection
using CellIndexAndResult = RimContourMapProjection::CellIndexAndResult;

// GeoMech implementation specific data generation methods
std::vector<bool> getMapCellVisibility() override;
cvf::ref<cvf::UByteArray> getCellVisibility() const override;
cvf::BoundingBox calculateExpandedPorBarBBox( int timeStep, int frameIndex ) const;
void updateGridInformation() override;
std::vector<bool> getMapCellVisibility() override;
std::vector<double> retrieveParameterWeights() override;
std::vector<double> generateResults( int viewerStepIndex ) override;

std::vector<double> retrieveParameterWeights() override;
std::vector<double> generateResults( int viewerStepIndex ) override;
std::vector<double>
generateResultsFromAddress( RigFemResultAddress resultAddress, const std::vector<bool>& mapCellVisibility, int viewerStepIndex );
bool resultVariableChanged() const override;
void clearResultVariable() override;
RimGridView* baseView() const override;
// std::vector<size_t> findIntersectingCells( const cvf::BoundingBox& bbox ) const;
// size_t kLayer( size_t globalCellIdx ) const;
// size_t kLayers() const;
// double calculateOverlapVolume( size_t globalCellIdx, const cvf::BoundingBox& bbox ) const;
// double calculateRayLengthInCell( size_t globalCellIdx, const cvf::Vec3d& highestPoint, const cvf::Vec3d& lowestPoint ) const;
// double getParameterWeightForCell( size_t globalCellIdx, const std::vector<double>& parameterWeights ) const;
// std::vector<double> gridCellValues( RigFemResultAddress resAddr, std::vector<float>& resultValues ) const;
RimGridView* baseView() const override;
RimGeoMechCase* geoMechCase() const;
RimGeoMechContourMapView* view() const;

Expand All @@ -100,5 +88,4 @@ class RimGeoMechContourMapProjection : public RimContourMapProjection
cvf::ref<RigFemPart> m_femPart;
cvf::cref<RigFemPartGrid> m_femPartGrid;
RigFemResultAddress m_currentResultAddr;
// size_t m_kLayers;
};
166 changes: 22 additions & 144 deletions ApplicationLibCode/ReservoirDataModel/RigGeoMechContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseData& caseData, const RigContourMapGrid& contourMapGrid )
RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseData& caseData,
const RigContourMapGrid& contourMapGrid,
bool limitToPorePressureRegions,
double paddingAroundPorePressureRegion )
: RigContourMapProjection( contourMapGrid )
, m_caseData( caseData )
, m_limitToPorePressureRegions( limitToPorePressureRegions )
, m_paddingAroundPorePressureRegion( paddingAroundPorePressureRegion )
, m_kLayers( 0u )
{
m_femPart = m_caseData.femParts()->part( 0 );
Expand All @@ -56,90 +61,14 @@ RigGeoMechContourMapProjection::RigGeoMechContourMapProjection( RigGeoMechCaseDa
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// void RigGeoMechContourMapProjection::updateLegend()
// {
// RimGeoMechCellColors* cellColors = view()->cellResult();

// double minVal = minValue( m_aggregatedResults );
// double maxVal = maxValue( m_aggregatedResults );

// std::pair<double, double> minmaxValAllTimeSteps = minmaxValuesAllTimeSteps();

// legendConfig()->setAutomaticRanges( minmaxValAllTimeSteps.first, minmaxValAllTimeSteps.second, minVal, maxVal );

// QString projectionLegendText = QString( "Map Projection\n%1" ).arg( m_resultAggregation().uiText() );
// if ( cellColors->resultAddress().isValid() )
// {
// projectionLegendText += QString( "\nResult: %1" ).arg( cellColors->resultFieldUiName() );
// if ( !cellColors->resultComponentUiName().isEmpty() )
// {
// projectionLegendText += QString( ", %1" ).arg( cellColors->resultComponentUiName() );
// }
// }
// else
// {
// projectionLegendText += QString( "\nNo Result Selected" );
// }

// legendConfig()->setTitle( projectionLegendText );
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// double RigGeoMechContourMapProjection::sampleSpacing() const
// {
// return m_relativeSampleSpacing * m_caseData.femParts()->characteristicElementSize();
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// cvf::ref<cvf::UByteArray> RigGeoMechContourMapProjection::getCellVisibility() const
// {
// cvf::ref<cvf::UByteArray> cellGridIdxVisibility = new cvf::UByteArray( m_femPart->elementCount() );
// RivFemElmVisibilityCalculator::computeAllVisible( cellGridIdxVisibility.p(), m_femPart.p() );

// if ( view()->cellFilterCollection()->isActive() )
// {
// cvf::CellRangeFilter cellRangeFilter;
// view()->cellFilterCollection()->compoundCellRangeFilter( &cellRangeFilter, 0 );

// cvf::UByteArray indexIncludeVis = ( *cellGridIdxVisibility.p() );
// cvf::UByteArray indexExcludeVis = ( *cellGridIdxVisibility.p() );
// view()->cellFilterCollection()->updateCellVisibilityByIndex( &indexIncludeVis, &indexExcludeVis, 0 );

// RivFemElmVisibilityCalculator::computeRangeVisibility( cellGridIdxVisibility.p(),
// m_femPart.p(),
// cellRangeFilter,
// &indexIncludeVis,
// &indexExcludeVis,
// view()->cellFilterCollection()->hasActiveIncludeIndexFilters(),
// view()->cellFilterCollection()->useAndOperation() );
// }
// if ( view()->propertyFilterCollection()->isActive() )
// {
// auto [stepIdx, frameIdx] = view()->currentStepAndDataFrame();

// RivFemElmVisibilityCalculator::computePropertyVisibility( cellGridIdxVisibility.p(),
// m_femPart.p(),
// stepIdx,
// frameIdx,
// cellGridIdxVisibility.p(),
// view()->geoMechPropertyFilterCollection() );
// }

// return cellGridIdxVisibility;
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox
RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( const std::string& resultComponentName, int timeStep, int frameIndex ) const
cvf::BoundingBox RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( RigGeoMechCaseData& caseData,
const std::string& resultComponentName,
int timeStep,
int frameIndex,
double paddingAroundPorePressureRegion )
{
RigFemResultAddress porBarAddr( RigFemResultPosEnum::RIG_ELEMENT_NODAL, RigFemAddressDefines::porBar(), resultComponentName );
RigFemPartResultsCollection* resultCollection = m_caseData.femPartResults();
RigFemPartResultsCollection* resultCollection = caseData.femPartResults();

const std::vector<float>& resultValues = resultCollection->resultValues( porBarAddr, 0, timeStep, frameIndex );
cvf::BoundingBox boundingBox;
Expand All @@ -149,75 +78,36 @@ cvf::BoundingBox
return boundingBox;
}

for ( int i = 0; i < m_femPart->elementCount(); ++i )
auto femPart = caseData.femParts()->part( 0 );
auto femPartGrid = femPart->getOrCreateStructGrid();
for ( int i = 0; i < femPart->elementCount(); ++i )
{
size_t resValueIdx = m_femPart->elementNodeResultIdx( (int)i, 0 );
size_t resValueIdx = femPart->elementNodeResultIdx( (int)i, 0 );
CVF_ASSERT( resValueIdx < resultValues.size() );
double scalarValue = resultValues[resValueIdx];
bool validPorValue = scalarValue != std::numeric_limits<double>::infinity();

if ( validPorValue )
{
std::array<cvf::Vec3d, 8> hexCorners;
m_femPartGrid->cellCornerVertices( i, hexCorners.data() );
femPartGrid->cellCornerVertices( i, hexCorners.data() );
for ( size_t c = 0; c < 8; ++c )
{
boundingBox.add( hexCorners[c] );
}
}
}

cvf::Vec3d boxMin = boundingBox.min();
cvf::Vec3d boxMax = boundingBox.max();
cvf::Vec3d boxExtent = boundingBox.extent();
boxMin.x() -= boxExtent.x() * 0.5 * m_paddingAroundPorePressureRegion;
boxMin.y() -= boxExtent.y() * 0.5 * m_paddingAroundPorePressureRegion;
boxMax.x() += boxExtent.x() * 0.5 * m_paddingAroundPorePressureRegion;
boxMax.y() += boxExtent.y() * 0.5 * m_paddingAroundPorePressureRegion;
boxMin.x() -= boxExtent.x() * 0.5 * paddingAroundPorePressureRegion;
boxMin.y() -= boxExtent.y() * 0.5 * paddingAroundPorePressureRegion;
boxMax.x() += boxExtent.x() * 0.5 * paddingAroundPorePressureRegion;
boxMax.y() += boxExtent.y() * 0.5 * paddingAroundPorePressureRegion;
return cvf::BoundingBox( boxMin, boxMax );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// void RigGeoMechContourMapProjection::updateGridInformation()
// {
// RimGeoMechCase* geoMechCase = this->geoMechCase();
// m_femPart = geoMechCase->geoMechData()->femParts()->part( 0 );
// m_femPartGrid = m_femPart->getOrCreateStructGrid();
// m_kLayers = m_femPartGrid->cellCountK();
// m_femPart->ensureIntersectionSearchTreeIsBuilt();

// cvf::BoundingBox gridBoundingBox = geoMechCase->activeCellsBoundingBox();
// cvf::BoundingBox expandedBoundingBox;

// if ( m_limitToPorePressureRegions )
// {
// auto [stepIdx, frameIdx] = view()->currentStepAndDataFrame();

// expandedBoundingBox = calculateExpandedPorBarBBox( stepIdx, frameIdx );
// if ( !expandedBoundingBox.isValid() )
// {
// m_limitToPorePressureRegions = false;
// }
// }

// if ( !m_limitToPorePressureRegions )
// {
// expandedBoundingBox = gridBoundingBox;
// }

// cvf::Vec3d minExpandedPoint = expandedBoundingBox.min() - cvf::Vec3d( gridEdgeOffset(), gridEdgeOffset(), 0.0 );
// cvf::Vec3d maxExpandedPoint = expandedBoundingBox.max() + cvf::Vec3d( gridEdgeOffset(), gridEdgeOffset(), 0.0 );
// if ( m_limitToPorePressureRegions && !m_applyPPRegionLimitVertically )
// {
// minExpandedPoint.z() = gridBoundingBox.min().z();
// maxExpandedPoint.z() = gridBoundingBox.max().z();
// }
// expandedBoundingBox = cvf::BoundingBox( minExpandedPoint, maxExpandedPoint );

// m_contourMapGrid = std::make_unique<RigContourMapGrid>( gridBoundingBox, expandedBoundingBox, sampleSpacing() );
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -497,18 +387,6 @@ std::vector<double> RigGeoMechContourMapProjection::gridCellValues( RigFemResult
return gridCellValues;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// void RigGeoMechContourMapProjection::updateAfterResultGeneration( int timeStep )
// {
// m_currentResultTimestep = timeStep;

// RimGeoMechCellColors* cellColors = view()->cellResult();
// RigFemResultAddress resAddr = cellColors->resultAddress();
// m_currentResultAddr = resAddr;
// }

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit d52ff27

Please sign in to comment.