#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,47 +81,132 @@ 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 else
{ {
CVF_ASSERT( m_intersectionBoxGenerator.notNull() ); geomResultDef = sepResDef->geoMechResultDefinition();
}
scalarColorMapper = sepResDef->regularLegendConfig()->scalarMapper();
ternaryColorMapper = sepResDef->ternaryLegendConfig()->scalarMapper();
timeStepIndex = sepResDef->timeStep();
}
// 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; cvf::ref<RigResultAccessor> resultAccessor;
@ -136,46 +222,74 @@ void RivIntersectionBoxPartMgr::updateCellResultColor( size_t
eclipseResDef ); eclipseResDef );
} }
RivIntersectionPartMgr::calculateEclipseTextureCoordinates( m_intersectionBoxFacesTextureCoords.p(), RivIntersectionPartMgr::calculateEclipseTextureCoordinates( intersectionFacesTextureCoords,
m_intersectionBoxGenerator->triangleToCellIndex(), triangleToCellIndexMapping,
resultAccessor.p(), resultAccessor.p(),
scalarColorMapper ); scalarColorMapper );
RivScalarMapperUtils::applyTextureResultsToPart( m_intersectionBoxFaces.p(), RivScalarMapperUtils::applyTextureResultsToPart( intersectionFacesPart,
m_intersectionBoxFacesTextureCoords.p(), intersectionFacesTextureCoords,
scalarColorMapper, scalarColorMapper,
1.0, 1.0,
caf::FC_NONE, caf::FC_NONE,
isLightingDisabled ); isLightingDisabled );
} }
}
}
RimGeoMechView* geoView; //--------------------------------------------------------------------------------------------------
m_rimIntersectionBox->firstAncestorOrThisOfType( geoView ); ///
//--------------------------------------------------------------------------------------------------
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 );
if ( geoView ) texturer.createTextureCoords( intersectionFacesTextureCoords, triangleToCellIndexMapping );
{
bool isLightingDisabled = geoView->isLightingDisabled();
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; RigGeoMechCaseData* caseData = nullptr;
RigFemResultAddress resVarAddress; RigFemResultAddress resVarAddress;
{ {
RimGeoMechResultDefinition* geomResultDef = geoView->cellResult();
caseData = geomResultDef->ownerCaseData(); caseData = geomResultDef->ownerCaseData();
resVarAddress = geomResultDef->resultAddress(); resVarAddress = geomResultDef->resultAddress();
} }
if ( !caseData ) return; 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 ) if ( resVarAddress.resultPosType == RIG_ELEMENT )
{ {
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress, const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0, 0,
(int)timeStepIndex ); (int)timeStepIndex );
const std::vector<size_t>& triangleToCellIdx = m_intersectionBoxGenerator->triangleToCellIndex();
RivIntersectionPartMgr::calculateElementBasedGeoMechTextureCoords( m_intersectionBoxFacesTextureCoords.p(), RivIntersectionPartMgr::calculateElementBasedGeoMechTextureCoords( intersectionFacesTextureCoords,
resultValues, resultValues,
triangleToCellIdx, triangleToCellIdx,
scalarColorMapper ); scalarColorMapper );
@ -183,21 +297,17 @@ void RivIntersectionBoxPartMgr::updateCellResultColor( size_t
else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE ) else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE )
{ {
// Special direction sensitive result calculation // Special direction sensitive result calculation
const cvf::Vec3fArray* triangelVxes = m_intersectionBoxGenerator->triangleVxes();
if ( resVarAddress.componentName == "Pazi" || resVarAddress.componentName == "Pinc" ) if ( resVarAddress.componentName == "Pazi" || resVarAddress.componentName == "Pinc" )
{ {
RivIntersectionPartMgr::calculatePlaneAngleTextureCoords( m_intersectionBoxFacesTextureCoords.p(), RivIntersectionPartMgr::calculatePlaneAngleTextureCoords( intersectionFacesTextureCoords,
triangelVxes, triangelVxes,
resVarAddress, resVarAddress,
scalarColorMapper ); scalarColorMapper );
} }
else else
{ {
const std::vector<RivIntersectionVertexWeights>& vertexWeights = RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords( intersectionFacesTextureCoords,
m_intersectionBoxGenerator->triangleVxToCellCornerInterpolationWeights();
RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords( m_intersectionBoxFacesTextureCoords.p(),
triangelVxes, triangelVxes,
vertexWeights, vertexWeights,
caseData, caseData,
@ -209,19 +319,20 @@ void RivIntersectionBoxPartMgr::updateCellResultColor( size_t
else else
{ {
// Do a "Hack" to show elm nodal and not nodal POR results // Do a "Hack" to show elm nodal and not nodal POR results
if ( resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar" ) if ( resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar" )
{
resVarAddress.resultPosType = RIG_ELEMENT_NODAL; resVarAddress.resultPosType = RIG_ELEMENT_NODAL;
}
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress, const std::vector<float>& resultValues = caseData->femPartResults()->resultValues( resVarAddress,
0, 0,
(int)timeStepIndex ); (int)timeStepIndex );
RigFemPart* femPart = caseData->femParts()->part( 0 ); RigFemPart* femPart = caseData->femParts()->part( 0 );
bool isElementNodalResult = !( resVarAddress.resultPosType == RIG_NODAL ); bool isElementNodalResult = !( resVarAddress.resultPosType == RIG_NODAL );
const std::vector<RivIntersectionVertexWeights>& vertexWeights =
m_intersectionBoxGenerator->triangleVxToCellCornerInterpolationWeights();
RivIntersectionPartMgr::calculateNodeOrElementNodeBasedGeoMechTextureCoords( m_intersectionBoxFacesTextureCoords RivIntersectionPartMgr::calculateNodeOrElementNodeBasedGeoMechTextureCoords( intersectionFacesTextureCoords,
.p(),
vertexWeights, vertexWeights,
resultValues, resultValues,
isElementNodalResult, isElementNodalResult,
@ -229,13 +340,12 @@ void RivIntersectionBoxPartMgr::updateCellResultColor( size_t
scalarColorMapper ); scalarColorMapper );
} }
RivScalarMapperUtils::applyTextureResultsToPart( m_intersectionBoxFaces.p(), RivScalarMapperUtils::applyTextureResultsToPart( intersectionFacesPart,
m_intersectionBoxFacesTextureCoords.p(), intersectionFacesTextureCoords,
scalarColorMapper, scalarColorMapper,
1.0, 1.0,
caf::FC_NONE, caf::FC_NONE,
isLightingDisabled ); 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;
//================================================================================================== //==================================================================================================
/// ///
@ -48,9 +56,7 @@ 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 );
} }
} }
} }