#5019 Refactor the color generation in the boxintersection into static methods

These methods are to be used from the normal intersections as well.
This commit is contained in:
Jacob Støren 2019-11-20 12:00:43 +01:00
parent c8053284d1
commit 46f335ad0b
4 changed files with 310 additions and 156 deletions

View File

@ -37,7 +37,16 @@ class ScalarMapper;
class DrawableGeo; class DrawableGeo;
} // namespace cvf } // namespace cvf
class RivIntersectionBoxGeometryGenerator : public cvf::Object class RivIntersectionGeometryGeneratorIF
{
public:
virtual bool isAnyGeometryPresent() const = 0;
virtual const std::vector<size_t>& triangleToCellIndex() const = 0;
virtual const std::vector<RivIntersectionVertexWeights>& triangleVxToCellCornerInterpolationWeights() const = 0;
virtual const cvf::Vec3fArray* triangleVxes() const = 0;
};
class RivIntersectionBoxGeometryGenerator : public cvf::Object, public RivIntersectionGeometryGeneratorIF
{ {
public: public:
RivIntersectionBoxGeometryGenerator( RimIntersectionBox* intersectionBox, RivIntersectionBoxGeometryGenerator( RimIntersectionBox* intersectionBox,
@ -45,16 +54,16 @@ public:
~RivIntersectionBoxGeometryGenerator() override; ~RivIntersectionBoxGeometryGenerator() override;
bool isAnyGeometryPresent() const; bool isAnyGeometryPresent() const override;
// Mapping between cells and geometry
const std::vector<size_t>& triangleToCellIndex() const override;
const std::vector<RivIntersectionVertexWeights>& triangleVxToCellCornerInterpolationWeights() const override;
const cvf::Vec3fArray* triangleVxes() const override;
// Generate geometry // Generate geometry
cvf::ref<cvf::DrawableGeo> generateSurface(); cvf::ref<cvf::DrawableGeo> generateSurface();
cvf::ref<cvf::DrawableGeo> createMeshDrawable(); cvf::ref<cvf::DrawableGeo> createMeshDrawable();
// Mapping between cells and geometry
const std::vector<size_t>& triangleToCellIndex() const;
const std::vector<RivIntersectionVertexWeights>& triangleVxToCellCornerInterpolationWeights() const;
const cvf::Vec3fArray* triangleVxes() const;
RimIntersectionBox* intersectionBox() const; RimIntersectionBox* intersectionBox() const;

View File

@ -32,6 +32,7 @@
#include "RimGeoMechCellColors.h" #include "RimGeoMechCellColors.h"
#include "RimGeoMechView.h" #include "RimGeoMechView.h"
#include "RimIntersectionBox.h" #include "RimIntersectionBox.h"
#include "RimIntersectionResultDefinition.h"
#include "RimRegularLegendConfig.h" #include "RimRegularLegendConfig.h"
#include "RimTernaryLegendConfig.h" #include "RimTernaryLegendConfig.h"
@ -80,162 +81,271 @@ void RivIntersectionBoxPartMgr::applySingleColorEffect()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RivIntersectionBoxPartMgr::updateCellResultColor( size_t timeStepIndex, void RivIntersectionBoxPartMgr::updateCellResultColor( size_t timeStepIndex )
const cvf::ScalarMapper* scalarColorMapper,
const RivTernaryScalarMapper* ternaryColorMapper )
{ {
if ( !m_intersectionBoxGenerator->isAnyGeometryPresent() ) return; RivIntersectionBoxPartMgr::updateCellResultColorStatic( timeStepIndex,
m_rimIntersectionBox,
m_intersectionBoxGenerator.p(),
m_intersectionBoxFaces.p(),
m_intersectionBoxFacesTextureCoords.p() );
}
CVF_ASSERT( scalarColorMapper ); //--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivIntersectionBoxPartMgr::updateCellResultColorStatic(
size_t timeStepIndex,
RimIntersectionHandle* rimIntersectionHandle,
const RivIntersectionGeometryGeneratorIF* intersectionGeomGenIF,
cvf::Part* intersectionFacesPart,
cvf::Vec2fArray* intersectionFacesTextureCoords )
{
if ( !intersectionGeomGenIF->isAnyGeometryPresent() ) return;
RimEclipseView* eclipseView = nullptr; RimGridView* gridView = nullptr;
m_rimIntersectionBox->firstAncestorOrThisOfType( eclipseView ); rimIntersectionHandle->firstAncestorOrThisOfType( gridView );
if ( eclipseView ) if ( !gridView ) return;
bool isLightingDisabled = gridView->isLightingDisabled();
RimEclipseResultDefinition* eclipseResDef = nullptr;
RimGeoMechResultDefinition* geomResultDef = nullptr;
const cvf::ScalarMapper* scalarColorMapper = nullptr;
const RivTernaryScalarMapper* ternaryColorMapper = nullptr;
// Separate intersection result
RimIntersectionResultDefinition* sepResDef = rimIntersectionHandle->activeSeparateResultDefinition();
if ( sepResDef && sepResDef->activeCase() )
{ {
bool isLightingDisabled = eclipseView->isLightingDisabled(); if ( sepResDef->isEclipseResultDefinition() )
RimEclipseResultDefinition* eclipseResDef = eclipseView->cellResult();
bool isTernaryResult = eclipseResDef->isTernarySaturationSelected();
RigEclipseCaseData* eclipseCaseData = eclipseResDef->eclipseCase()->eclipseCaseData();
CVF_ASSERT( eclipseResDef );
// CrossSections
if ( m_intersectionBoxFaces.notNull() )
{ {
if ( isTernaryResult ) eclipseResDef = sepResDef->eclipseResultDefinition();
{
RivTernaryTextureCoordsCreator texturer( eclipseResDef, ternaryColorMapper, timeStepIndex );
texturer.createTextureCoords( m_intersectionBoxFacesTextureCoords.p(),
m_intersectionBoxGenerator->triangleToCellIndex() );
RivScalarMapperUtils::applyTernaryTextureResultsToPart( m_intersectionBoxFaces.p(),
m_intersectionBoxFacesTextureCoords.p(),
ternaryColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
else
{
CVF_ASSERT( m_intersectionBoxGenerator.notNull() );
cvf::ref<RigResultAccessor> resultAccessor;
if ( RiaDefines::isPerCellFaceResult( eclipseResDef->resultVariable() ) )
{
resultAccessor = new RigHugeValResultAccessor;
}
else
{
resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCaseData,
0,
timeStepIndex,
eclipseResDef );
}
RivIntersectionPartMgr::calculateEclipseTextureCoordinates( m_intersectionBoxFacesTextureCoords.p(),
m_intersectionBoxGenerator->triangleToCellIndex(),
resultAccessor.p(),
scalarColorMapper );
RivScalarMapperUtils::applyTextureResultsToPart( m_intersectionBoxFaces.p(),
m_intersectionBoxFacesTextureCoords.p(),
scalarColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
}
}
RimGeoMechView* geoView;
m_rimIntersectionBox->firstAncestorOrThisOfType( geoView );
if ( geoView )
{
bool isLightingDisabled = geoView->isLightingDisabled();
RigGeoMechCaseData* caseData = nullptr;
RigFemResultAddress resVarAddress;
{
RimGeoMechResultDefinition* geomResultDef = geoView->cellResult();
caseData = geomResultDef->ownerCaseData();
resVarAddress = geomResultDef->resultAddress();
}
if ( !caseData ) return;
if ( resVarAddress.resultPosType == RIG_ELEMENT )
{
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0,
(int)timeStepIndex );
const std::vector<size_t>& triangleToCellIdx = m_intersectionBoxGenerator->triangleToCellIndex();
RivIntersectionPartMgr::calculateElementBasedGeoMechTextureCoords( m_intersectionBoxFacesTextureCoords.p(),
resultValues,
triangleToCellIdx,
scalarColorMapper );
}
else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE )
{
// Special direction sensitive result calculation
const cvf::Vec3fArray* triangelVxes = m_intersectionBoxGenerator->triangleVxes();
if ( resVarAddress.componentName == "Pazi" || resVarAddress.componentName == "Pinc" )
{
RivIntersectionPartMgr::calculatePlaneAngleTextureCoords( m_intersectionBoxFacesTextureCoords.p(),
triangelVxes,
resVarAddress,
scalarColorMapper );
}
else
{
const std::vector<RivIntersectionVertexWeights>& vertexWeights =
m_intersectionBoxGenerator->triangleVxToCellCornerInterpolationWeights();
RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords( m_intersectionBoxFacesTextureCoords.p(),
triangelVxes,
vertexWeights,
caseData,
resVarAddress,
(int)timeStepIndex,
scalarColorMapper );
}
} }
else else
{ {
// Do a "Hack" to show elm nodal and not nodal POR results geomResultDef = sepResDef->geoMechResultDefinition();
if ( resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar" )
resVarAddress.resultPosType = RIG_ELEMENT_NODAL;
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0,
(int)timeStepIndex );
RigFemPart* femPart = caseData->femParts()->part( 0 );
bool isElementNodalResult = !( resVarAddress.resultPosType == RIG_NODAL );
const std::vector<RivIntersectionVertexWeights>& vertexWeights =
m_intersectionBoxGenerator->triangleVxToCellCornerInterpolationWeights();
RivIntersectionPartMgr::calculateNodeOrElementNodeBasedGeoMechTextureCoords( m_intersectionBoxFacesTextureCoords
.p(),
vertexWeights,
resultValues,
isElementNodalResult,
femPart,
scalarColorMapper );
} }
RivScalarMapperUtils::applyTextureResultsToPart( m_intersectionBoxFaces.p(), scalarColorMapper = sepResDef->regularLegendConfig()->scalarMapper();
m_intersectionBoxFacesTextureCoords.p(), ternaryColorMapper = sepResDef->ternaryLegendConfig()->scalarMapper();
scalarColorMapper, timeStepIndex = sepResDef->timeStep();
1.0,
caf::FC_NONE,
isLightingDisabled );
} }
// Ordinary result
if ( !eclipseResDef && !geomResultDef )
{
RimEclipseView* eclipseView = nullptr;
rimIntersectionHandle->firstAncestorOrThisOfType( eclipseView );
if ( eclipseView )
{
eclipseResDef = eclipseView->cellResult();
scalarColorMapper = eclipseView->cellResult()->legendConfig()->scalarMapper();
ternaryColorMapper = eclipseView->cellResult()->ternaryLegendConfig()->scalarMapper();
timeStepIndex = eclipseView->currentTimeStep();
}
RimGeoMechView* geoView;
rimIntersectionHandle->firstAncestorOrThisOfType( geoView );
if ( geoView )
{
geomResultDef = geoView->cellResult();
scalarColorMapper = geoView->cellResult()->legendConfig()->scalarMapper();
timeStepIndex = geoView->currentTimeStep();
}
}
if ( eclipseResDef )
{
if ( eclipseResDef->isTernarySaturationSelected() )
{
updateEclipseTernaryCellResultColors( eclipseResDef,
ternaryColorMapper,
timeStepIndex,
isLightingDisabled,
intersectionGeomGenIF->triangleToCellIndex(),
intersectionFacesPart,
intersectionFacesTextureCoords );
}
else
{
updateEclipseCellResultColors( eclipseResDef,
scalarColorMapper,
timeStepIndex,
isLightingDisabled,
intersectionGeomGenIF->triangleToCellIndex(),
intersectionFacesPart,
intersectionFacesTextureCoords );
}
}
else if ( geomResultDef )
{
updateGeoMechCellResultColors( geomResultDef,
timeStepIndex,
scalarColorMapper,
isLightingDisabled,
intersectionGeomGenIF,
intersectionFacesPart,
intersectionFacesTextureCoords );
return;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivIntersectionBoxPartMgr::updateEclipseCellResultColors( const RimEclipseResultDefinition* eclipseResDef,
const cvf::ScalarMapper* scalarColorMapper,
size_t timeStepIndex,
bool isLightingDisabled,
const std::vector<size_t>& triangleToCellIndexMapping,
cvf::Part* intersectionFacesPart,
cvf::Vec2fArray* intersectionFacesTextureCoords )
{
RigEclipseCaseData* eclipseCaseData = eclipseResDef->eclipseCase()->eclipseCaseData();
cvf::ref<RigResultAccessor> resultAccessor;
if ( RiaDefines::isPerCellFaceResult( eclipseResDef->resultVariable() ) )
{
resultAccessor = new RigHugeValResultAccessor;
}
else
{
resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCaseData,
0,
timeStepIndex,
eclipseResDef );
}
RivIntersectionPartMgr::calculateEclipseTextureCoordinates( intersectionFacesTextureCoords,
triangleToCellIndexMapping,
resultAccessor.p(),
scalarColorMapper );
RivScalarMapperUtils::applyTextureResultsToPart( intersectionFacesPart,
intersectionFacesTextureCoords,
scalarColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivIntersectionBoxPartMgr::updateEclipseTernaryCellResultColors( const RimEclipseResultDefinition* eclipseResDef,
const RivTernaryScalarMapper* ternaryColorMapper,
size_t timeStepIndex,
bool isLightingDisabled,
const std::vector<size_t>& triangleToCellIndexMapping,
cvf::Part* intersectionFacesPart,
cvf::Vec2fArray* intersectionFacesTextureCoords )
{
RivTernaryTextureCoordsCreator texturer( eclipseResDef, ternaryColorMapper, timeStepIndex );
texturer.createTextureCoords( intersectionFacesTextureCoords, triangleToCellIndexMapping );
RivScalarMapperUtils::applyTernaryTextureResultsToPart( intersectionFacesPart,
intersectionFacesTextureCoords,
ternaryColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivIntersectionBoxPartMgr::updateGeoMechCellResultColors( const RimGeoMechResultDefinition* geomResultDef,
size_t timeStepIndex,
const cvf::ScalarMapper* scalarColorMapper,
bool isLightingDisabled,
const RivIntersectionGeometryGeneratorIF* geomGenerator,
cvf::Part* intersectionFacesPart,
cvf::Vec2fArray* intersectionFacesTextureCoords )
{
RigGeoMechCaseData* caseData = nullptr;
RigFemResultAddress resVarAddress;
{
caseData = geomResultDef->ownerCaseData();
resVarAddress = geomResultDef->resultAddress();
}
if ( !caseData ) return;
const std::vector<size_t>& triangleToCellIdx = geomGenerator->triangleToCellIndex();
const cvf::Vec3fArray* triangelVxes = geomGenerator->triangleVxes();
const std::vector<RivIntersectionVertexWeights>& vertexWeights =
geomGenerator->triangleVxToCellCornerInterpolationWeights();
if ( resVarAddress.resultPosType == RIG_ELEMENT )
{
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0,
(int)timeStepIndex );
RivIntersectionPartMgr::calculateElementBasedGeoMechTextureCoords( intersectionFacesTextureCoords,
resultValues,
triangleToCellIdx,
scalarColorMapper );
}
else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE )
{
// Special direction sensitive result calculation
if ( resVarAddress.componentName == "Pazi" || resVarAddress.componentName == "Pinc" )
{
RivIntersectionPartMgr::calculatePlaneAngleTextureCoords( intersectionFacesTextureCoords,
triangelVxes,
resVarAddress,
scalarColorMapper );
}
else
{
RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords( intersectionFacesTextureCoords,
triangelVxes,
vertexWeights,
caseData,
resVarAddress,
(int)timeStepIndex,
scalarColorMapper );
}
}
else
{
// Do a "Hack" to show elm nodal and not nodal POR results
if ( resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar" )
{
resVarAddress.resultPosType = RIG_ELEMENT_NODAL;
}
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0,
(int)timeStepIndex );
RigFemPart* femPart = caseData->femParts()->part( 0 );
bool isElementNodalResult = !( resVarAddress.resultPosType == RIG_NODAL );
RivIntersectionPartMgr::calculateNodeOrElementNodeBasedGeoMechTextureCoords( intersectionFacesTextureCoords,
vertexWeights,
resultValues,
isElementNodalResult,
femPart,
scalarColorMapper );
}
RivScalarMapperUtils::applyTextureResultsToPart( intersectionFacesPart,
intersectionFacesTextureCoords,
scalarColorMapper,
1.0,
caf::FC_NONE,
isLightingDisabled );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -32,10 +32,18 @@ class ScalarMapper;
class RigMainGrid; class RigMainGrid;
class RigResultAccessor; class RigResultAccessor;
class RivTernaryScalarMapper;
class RimCellEdgeColors; class RimCellEdgeColors;
class RimEclipseCellColors; class RimEclipseCellColors;
class RimIntersectionBox; class RimIntersectionBox;
class RivTernaryScalarMapper; class RimIntersectionHandle;
class RimEclipseView;
class RimGeoMechView;
class RimEclipseResultDefinition;
class RimGeoMechResultDefinition;
//================================================================================================== //==================================================================================================
/// ///
@ -47,10 +55,8 @@ class RivIntersectionBoxPartMgr : public cvf::Object
public: public:
explicit RivIntersectionBoxPartMgr( RimIntersectionBox* intersectionBox ); explicit RivIntersectionBoxPartMgr( RimIntersectionBox* intersectionBox );
void applySingleColorEffect(); void applySingleColorEffect();
void updateCellResultColor( size_t timeStepIndex, void updateCellResultColor( size_t timeStepIndex );
const cvf::ScalarMapper* scalarColorMapper,
const RivTernaryScalarMapper* ternaryColorMapper );
void appendNativeCrossSectionFacesToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform ); void appendNativeCrossSectionFacesToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform );
void appendMeshLinePartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform ); void appendMeshLinePartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform );
@ -59,6 +65,35 @@ private:
void updatePartEffect(); void updatePartEffect();
void generatePartGeometry(); void generatePartGeometry();
static void updateCellResultColorStatic( size_t timeStepIndex,
RimIntersectionHandle* m_rimIntersectionBox,
const RivIntersectionGeometryGeneratorIF* m_intersectionBoxGenerator,
cvf::Part* m_intersectionBoxFaces,
cvf::Vec2fArray* m_intersectionBoxFacesTextureCoords );
static void updateEclipseCellResultColors( const RimEclipseResultDefinition* eclipseResDef,
const cvf::ScalarMapper* scalarColorMapper,
size_t timeStepIndex,
bool isLightingDisabled,
const std::vector<size_t>& triangleToCellIndexMapping,
cvf::Part* m_intersectionBoxFaces,
cvf::Vec2fArray* m_intersectionBoxFacesTextureCoords );
static void updateEclipseTernaryCellResultColors( const RimEclipseResultDefinition* eclipseResDef,
const RivTernaryScalarMapper* ternaryColorMapper,
size_t timeStepIndex,
bool isLightingDisabled,
const std::vector<size_t>& triangleToCellIndexMapping,
cvf::Part* m_intersectionBoxFaces,
cvf::Vec2fArray* m_intersectionBoxFacesTextureCoords );
static void updateGeoMechCellResultColors( const RimGeoMechResultDefinition* geomResultDef,
size_t timeStepIndex,
const cvf::ScalarMapper* scalarColorMapper,
bool isLightingDisabled,
const RivIntersectionGeometryGeneratorIF* geomGenerator,
cvf::Part* m_intersectionBoxFaces,
cvf::Vec2fArray* m_intersectionBoxFacesTextureCoords );
private: private:
RimIntersectionBox* m_rimIntersectionBox; RimIntersectionBox* m_rimIntersectionBox;

View File

@ -115,7 +115,7 @@ void RimIntersectionCollection::updateCellResultColor( size_t
{ {
if ( cs->isActive() ) if ( cs->isActive() )
{ {
cs->intersectionBoxPartMgr()->updateCellResultColor( timeStepIndex, scalarColorMapper, ternaryColorMapper ); cs->intersectionBoxPartMgr()->updateCellResultColor( timeStepIndex );
} }
} }
} }