mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
Migrate all assert macros in ApplicationLibCode to CAF_ASSERT and remove every use of cvfAssert.h. CVF_ASSERT is replaced one to one. CVF_TIGHT_ASSERT is also replaced by CAF_ASSERT, which is semantically exact: CVF_ENABLE_TIGHT_ASSERTS is 1 only under _DEBUG, and that is what CAF_ASSERT now does. The two CVF_FAIL_MSG sites become CAF_ASSERT( false && "message" ), preserving the message with the idiom already used elsewhere in the code base. Counts before and after: CVF_ASSERT 1044 to 0, CVF_TIGHT_ASSERT 66 to 0, CVF_FAIL_MSG 2 to 0, cvfAssert.h references 154 to 0. Include handling: files that included cvfAssert.h directly now include cafAssert.h instead, includes left dead by the migration are removed, and files that were relying on cvfAssert.h transitively get an explicit cafAssert.h. Files that reach cafAssert.h through another caf header are left unchanged; a missing include here is a compile error, not a silently disabled assert. ResultStatisticsCache links only LibCore and therefore had no path to cafAssert.h. Add the cafPdmCore directory as a private include path rather than linking the library, since cafAssert.h is header only. Note that this stops these asserts from firing in Release and RelWithDebInfo, where CVF_ASSERT was previously active.
388 lines
16 KiB
C++
388 lines
16 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2011- Statoil ASA
|
|
// Copyright (C) 2013- Ceetron Solutions AS
|
|
// Copyright (C) 2011-2012 Ceetron AS
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RivGridPartMgr.h"
|
|
|
|
#include "RiaLogging.h"
|
|
#include "RiaPreferences.h"
|
|
#include "RiaPreferencesGrid.h"
|
|
#include "RiaRegressionTestRunner.h"
|
|
|
|
#include "RimCellEdgeColors.h"
|
|
#include "RimEclipseCase.h"
|
|
#include "RimEclipseCellColors.h"
|
|
#include "RimEclipseView.h"
|
|
#include "RimRegularLegendConfig.h"
|
|
#include "RimTernaryLegendConfig.h"
|
|
|
|
#include "RivCompletionTypeResultToTextureMapper.h"
|
|
#include "RivMeshLinesSourceInfo.h"
|
|
#include "RivPartPriority.h"
|
|
#include "RivScalarMapperUtils.h"
|
|
#include "RivSingleCellPartGenerator.h"
|
|
#include "RivSourceInfo.h"
|
|
#include "RivTernaryTextureCoordsCreator.h"
|
|
#include "RivTextureCoordsCreator.h"
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
#include "cvfModelBasicList.h"
|
|
#include "cvfPart.h"
|
|
#include "cvfTransform.h"
|
|
|
|
namespace caf
|
|
{
|
|
template <>
|
|
void caf::AppEnum<RivCellSetEnum>::setUp()
|
|
{
|
|
addItem( RivCellSetEnum::OVERRIDDEN_CELL_VISIBILITY, "OVERRIDDEN_CELL_VISIBILITY", "OVERRIDDEN_CELL_VISIBILITY" );
|
|
addItem( RivCellSetEnum::ALL_CELLS, "ALL_CELLS", "ALL_CELLS" );
|
|
addItem( RivCellSetEnum::ACTIVE, "ACTIVE", "ACTIVE" );
|
|
addItem( RivCellSetEnum::ALL_WELL_CELLS, "ALL_WELL_CELLS", "ALL_WELL_CELLS" );
|
|
addItem( RivCellSetEnum::VISIBLE_WELL_CELLS, "VISIBLE_WELL_CELLS", "VISIBLE_WELL_CELLS" );
|
|
addItem( RivCellSetEnum::VISIBLE_WELL_FENCE_CELLS, "VISIBLE_WELL_FENCE_CELLS", "VISIBLE_WELL_FENCE_CELLS" );
|
|
addItem( RivCellSetEnum::INACTIVE, "INACTIVE", "INACTIVE" );
|
|
addItem( RivCellSetEnum::RANGE_FILTERED, "RANGE_FILTERED", "RANGE_FILTERED" );
|
|
addItem( RivCellSetEnum::RANGE_FILTERED_INACTIVE, "RANGE_FILTERED_INACTIVE", "RANGE_FILTERED_INACTIVE" );
|
|
addItem( RivCellSetEnum::RANGE_FILTERED_WELL_CELLS, "RANGE_FILTERED_WELL_CELLS", "RANGE_FILTERED_WELL_CELLS" );
|
|
addItem( RivCellSetEnum::VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER,
|
|
"VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER",
|
|
"VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER" );
|
|
addItem( RivCellSetEnum::VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER,
|
|
"VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER",
|
|
"VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER" );
|
|
addItem( RivCellSetEnum::PROPERTY_FILTERED, "PROPERTY_FILTERED", "PROPERTY_FILTERED" );
|
|
addItem( RivCellSetEnum::PROPERTY_FILTERED_WELL_CELLS, "PROPERTY_FILTERED_WELL_CELLS", "PROPERTY_FILTERED_WELL_CELLS" );
|
|
}
|
|
} // namespace caf
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RivGridPartMgr::RivGridPartMgr( RivCellSetEnum cellSetType, RimEclipseCase* eclipseCase, const RigGridBase* grid, size_t gridIdx )
|
|
: m_surfaceGenerator( grid, RiaRegressionTestRunner::instance()->useOpenMPForGeometryCreation() )
|
|
, m_gridIdx( gridIdx )
|
|
, m_grid( grid )
|
|
, m_surfaceFaceFilter( grid )
|
|
, m_opacityLevel( 1.0f )
|
|
, m_defaultColor( cvf::Color3::WHITE )
|
|
, m_eclipseCase( eclipseCase )
|
|
, m_cellSetType( cellSetType )
|
|
{
|
|
CAF_ASSERT( grid );
|
|
m_cellVisibility = new cvf::UByteArray;
|
|
m_surfaceFacesTextureCoords = new cvf::Vec2fArray;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::setTransform( cvf::Transform* scaleTransform )
|
|
{
|
|
m_scaleTransform = scaleTransform;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::setCellVisibility( cvf::UByteArray* cellVisibilities )
|
|
{
|
|
CAF_ASSERT( m_scaleTransform.notNull() );
|
|
CAF_ASSERT( cellVisibilities );
|
|
|
|
m_cellVisibility = cellVisibilities;
|
|
|
|
m_surfaceGenerator.setCellVisibility( cellVisibilities );
|
|
m_surfaceGenerator.addFaceVisibilityFilter( &m_surfaceFaceFilter );
|
|
|
|
generatePartGeometry( m_surfaceGenerator );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::generatePartGeometry( cvf::StructGridGeometryGenerator& geoBuilder )
|
|
{
|
|
bool useBufferObjects = true;
|
|
|
|
// Surface geometry
|
|
{
|
|
auto startTime = RiaLogging::currentTime();
|
|
|
|
cvf::ref<cvf::DrawableGeo> geo = geoBuilder.generateSurface();
|
|
|
|
bool showDebugTiming = false;
|
|
if ( showDebugTiming )
|
|
{
|
|
auto text = caf::AppEnum<RivCellSetEnum>::text( m_cellSetType );
|
|
RiaLogging::logElapsedTime( text.toStdString(), startTime );
|
|
}
|
|
|
|
if ( geo.notNull() )
|
|
{
|
|
geo->computeNormals();
|
|
|
|
if ( useBufferObjects )
|
|
{
|
|
geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
|
|
}
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
part->setName( "Grid " + cvf::String( static_cast<int>( m_gridIdx ) ) );
|
|
part->setDrawable( geo.p() );
|
|
part->setTransform( m_scaleTransform.p() );
|
|
|
|
// Set mapping from triangle face index to cell index
|
|
cvf::ref<RivSourceInfo> si = new RivSourceInfo( m_eclipseCase, m_gridIdx );
|
|
si->setCellSetType( m_cellSetType );
|
|
|
|
si->m_cellFaceFromTriangleMapper = geoBuilder.triangleToCellFaceMapper();
|
|
|
|
part->setSourceInfo( si.p() );
|
|
|
|
part->updateBoundingBox();
|
|
|
|
// Set default effect
|
|
caf::SurfaceEffectGenerator geometryEffgen( cvf::Color4f( cvf::Color3f::WHITE ), caf::PO_1 );
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
|
|
part->setEffect( geometryOnlyEffect.p() );
|
|
part->setEnableMask( surfaceBit );
|
|
|
|
if ( m_opacityLevel < 1.0f )
|
|
{
|
|
part->setPriority( RivPartPriority::PartType::Transparent );
|
|
}
|
|
|
|
m_surfaceFaces = part;
|
|
}
|
|
}
|
|
|
|
// Mesh geometry
|
|
{
|
|
cvf::ref<cvf::DrawableGeo> geoMesh;
|
|
|
|
if ( RiaPreferencesGrid::current()->radialGridMode() == RiaGridDefines::RadialGridMode::CYLINDRICAL && m_grid->isRadial() &&
|
|
m_grid->isTempGrid() )
|
|
{
|
|
std::vector<size_t> localGridCellIndices;
|
|
for ( size_t i = 0; i < m_grid->cellCount(); i++ )
|
|
{
|
|
if ( ( *m_cellVisibility )[i] )
|
|
{
|
|
localGridCellIndices.push_back( i );
|
|
}
|
|
}
|
|
|
|
geoMesh = RivSingleCellPartGenerator::createMeshLinesOfParentGridCells( m_grid.p(),
|
|
localGridCellIndices,
|
|
m_eclipseCase->displayModelOffset() );
|
|
}
|
|
else
|
|
{
|
|
geoMesh = geoBuilder.createMeshDrawable();
|
|
}
|
|
|
|
if ( geoMesh.notNull() )
|
|
{
|
|
if ( useBufferObjects )
|
|
{
|
|
geoMesh->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
|
|
}
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
part->setName( "Grid mesh " + cvf::String( static_cast<int>( m_gridIdx ) ) );
|
|
part->setDrawable( geoMesh.p() );
|
|
|
|
part->setTransform( m_scaleTransform.p() );
|
|
part->updateBoundingBox();
|
|
|
|
RiaPreferences* prefs = RiaPreferences::current();
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
caf::MeshEffectGenerator effGen( prefs->defaultGridLineColors() );
|
|
eff = effGen.generateCachedEffect();
|
|
|
|
part->setPriority( RivPartPriority::PartType::MeshLines );
|
|
|
|
part->setEnableMask( meshSurfaceBit );
|
|
part->setEffect( eff.p() );
|
|
|
|
part->setSourceInfo( new RivMeshLinesSourceInfo( m_eclipseCase ) );
|
|
|
|
m_surfaceGridLines = part;
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::appendPartsToModel( cvf::ModelBasicList* model )
|
|
{
|
|
CAF_ASSERT( model != nullptr );
|
|
|
|
if ( m_surfaceFaces.notNull() ) model->addPart( m_surfaceFaces.p() );
|
|
if ( m_surfaceGridLines.notNull() ) model->addPart( m_surfaceGridLines.p() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::updateCellColor( cvf::Color4f color )
|
|
{
|
|
m_opacityLevel = color.a();
|
|
m_defaultColor = color.toColor3f();
|
|
|
|
if ( m_surfaceFaces.isNull() ) return;
|
|
|
|
// Set default effect
|
|
caf::SurfaceEffectGenerator geometryEffgen( color, caf::PO_1 );
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
|
|
m_surfaceFaces->setEffect( geometryOnlyEffect.p() );
|
|
|
|
if ( m_opacityLevel < 1.0f )
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::Transparent );
|
|
else
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::BaseLevel );
|
|
|
|
// Update mesh colors as well, in case of change
|
|
if ( m_surfaceGridLines.notNull() )
|
|
{
|
|
RiaPreferences* prefs = RiaPreferences::current();
|
|
caf::MeshEffectGenerator effGen( prefs->defaultGridLineColors() );
|
|
cvf::ref<cvf::Effect> eff = effGen.generateCachedEffect();
|
|
m_surfaceGridLines->setEffect( eff.p() );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::updateCellResultColor( size_t timeStepIndex, RimEclipseCellColors* cellResultColors )
|
|
{
|
|
CAF_ASSERT( cellResultColors );
|
|
|
|
// Outer surface
|
|
if ( m_surfaceFaces.notNull() )
|
|
{
|
|
float effectiveOpacityLevel = m_opacityLevel;
|
|
|
|
if ( cellResultColors->isTernarySaturationSelected() )
|
|
{
|
|
RivTernaryTextureCoordsCreator texturer( cellResultColors,
|
|
cellResultColors->ternaryLegendConfig(),
|
|
cellResultColors->reservoirView()->wellCollection(),
|
|
timeStepIndex,
|
|
m_grid->gridIndex(),
|
|
m_surfaceGenerator.quadToCellFaceMapper() );
|
|
|
|
texturer.createTextureCoords( m_surfaceFacesTextureCoords.p() );
|
|
|
|
const RivTernaryScalarMapper* mapper = cellResultColors->ternaryLegendConfig()->scalarMapper();
|
|
RivScalarMapperUtils::applyTernaryTextureResultsToPart( m_surfaceFaces.p(),
|
|
m_surfaceFacesTextureCoords.p(),
|
|
mapper,
|
|
effectiveOpacityLevel,
|
|
caf::FC_NONE,
|
|
cellResultColors->reservoirView()->isLightingDisabled() );
|
|
}
|
|
else
|
|
{
|
|
RivTextureCoordsCreator texturer( cellResultColors, timeStepIndex, m_grid->gridIndex(), m_surfaceGenerator.quadToCellFaceMapper() );
|
|
if ( !texturer.isValid() )
|
|
{
|
|
return;
|
|
}
|
|
|
|
if ( cellResultColors->isCompletionTypeSelected() )
|
|
{
|
|
cvf::ref<RigPipeInCellEvaluator> pipeInCellEval =
|
|
RivTextureCoordsCreator::createPipeInCellEvaluator( cellResultColors, timeStepIndex, m_grid->gridIndex() );
|
|
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
|
|
|
|
texturer.setResultToTextureMapper( new RivCompletionTypeResultToTextureMapper( mapper, pipeInCellEval.p() ) );
|
|
effectiveOpacityLevel = 0.5;
|
|
}
|
|
|
|
texturer.createTextureCoords( m_surfaceFacesTextureCoords.p() );
|
|
|
|
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
|
|
RivScalarMapperUtils::applyTextureResultsToPart( m_surfaceFaces.p(),
|
|
m_surfaceFacesTextureCoords.p(),
|
|
mapper,
|
|
effectiveOpacityLevel,
|
|
caf::FC_NONE,
|
|
cellResultColors->reservoirView()->isLightingDisabled() );
|
|
}
|
|
|
|
if ( effectiveOpacityLevel < 1.0f )
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::Transparent );
|
|
else
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::BaseLevel );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RivGridPartMgr::updateCellEdgeResultColor( size_t timeStepIndex,
|
|
RimEclipseCellColors* cellResultColors,
|
|
RimCellEdgeColors* cellEdgeResultColors )
|
|
{
|
|
if ( m_surfaceFaces.notNull() )
|
|
{
|
|
cvf::DrawableGeo* dg = dynamic_cast<cvf::DrawableGeo*>( m_surfaceFaces->drawable() );
|
|
if ( dg )
|
|
{
|
|
cvf::ref<cvf::Effect> eff = RivScalarMapperUtils::createCellEdgeEffect( dg,
|
|
m_surfaceGenerator.quadToCellFaceMapper(),
|
|
m_grid->gridIndex(),
|
|
timeStepIndex,
|
|
cellResultColors,
|
|
cellEdgeResultColors,
|
|
m_opacityLevel,
|
|
m_defaultColor,
|
|
caf::FC_NONE,
|
|
cellResultColors->reservoirView()->isLightingDisabled() );
|
|
|
|
m_surfaceFaces->setEffect( eff.p() );
|
|
|
|
if ( m_opacityLevel < 1.0f )
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::Transparent );
|
|
else
|
|
m_surfaceFaces->setPriority( RivPartPriority::PartType::BaseLevel );
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RivGridPartMgr::~RivGridPartMgr()
|
|
{
|
|
#if 0
|
|
if (m_faultFaces.notNull()) m_faultFaces->deleteOrReleaseOpenGLResources();
|
|
if (m_faultGridLines.notNull()) m_faultGridLines->deleteOrReleaseOpenGLResources();
|
|
if (m_surfaceGridLines.notNull()) m_surfaceGridLines->deleteOrReleaseOpenGLResources();
|
|
if (m_surfaceFaces.notNull()) m_surfaceFaces->deleteOrReleaseOpenGLResources();
|
|
#endif
|
|
}
|