2012-05-18 02:45:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011-2012 Statoil ASA, 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"
|
2013-05-06 03:55:00 -05:00
|
|
|
|
2014-08-11 06:59:12 -05:00
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaPreferences.h"
|
|
|
|
|
|
|
|
#include "RigCaseCellResultsData.h"
|
|
|
|
#include "RigCaseData.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
|
|
|
#include "RimCase.h"
|
|
|
|
#include "RimCellEdgeResultSlot.h"
|
|
|
|
#include "RimReservoirCellResultsStorage.h"
|
|
|
|
#include "RimReservoirView.h"
|
|
|
|
#include "RimResultSlot.h"
|
|
|
|
#include "RimTernaryLegendConfig.h"
|
|
|
|
#include "RimWellCollection.h"
|
|
|
|
|
|
|
|
#include "RivCellEdgeEffectGenerator.h"
|
|
|
|
#include "RivResultToTextureMapper.h"
|
|
|
|
#include "RivScalarMapperUtils.h"
|
|
|
|
#include "RivSourceInfo.h"
|
|
|
|
#include "RivTernaryScalarMapperEffectGenerator.h"
|
|
|
|
#include "RivTernaryTextureCoordsCreator.h"
|
|
|
|
#include "RivTextureCoordsCreator.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cafEffectGenerator.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
#include "cafPdmFieldCvfColor.h"
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cafPdmFieldCvfMat4d.h"
|
2014-04-04 03:59:21 -05:00
|
|
|
#include "cafProgressInfo.h"
|
2014-08-11 06:59:12 -05:00
|
|
|
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfMath.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
2014-04-08 01:37:22 -05:00
|
|
|
#include "cvfRenderStateBlending.h"
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cvfRenderStatePolygonOffset.h"
|
|
|
|
#include "cvfRenderState_FF.h"
|
|
|
|
#include "cvfShaderProgram.h"
|
2014-04-11 06:08:05 -05:00
|
|
|
#include "cvfShaderProgramGenerator.h"
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cvfShaderSourceProvider.h"
|
2014-04-11 06:08:05 -05:00
|
|
|
#include "cvfShaderSourceRepository.h"
|
2014-05-06 15:51:17 -05:00
|
|
|
#include "cvfStructGrid.h"
|
2014-08-11 06:59:12 -05:00
|
|
|
#include "cvfUniform.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2014-07-30 07:52:32 -05:00
|
|
|
RivGridPartMgr::RivGridPartMgr(const RigGridBase* grid, size_t gridIdx)
|
2012-05-18 02:45:23 -05:00
|
|
|
: m_surfaceGenerator(grid),
|
2013-02-01 05:25:34 -06:00
|
|
|
m_gridIdx(gridIdx),
|
|
|
|
m_grid(grid),
|
2012-05-18 02:45:23 -05:00
|
|
|
m_surfaceFaceFilter(grid),
|
|
|
|
m_opacityLevel(1.0f),
|
2014-07-30 07:52:32 -05:00
|
|
|
m_defaultColor(cvf::Color3::WHITE)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
CVF_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)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(m_scaleTransform.notNull());
|
|
|
|
CVF_ASSERT(cellVisibilities);
|
|
|
|
|
|
|
|
m_cellVisibility = cellVisibilities;
|
|
|
|
|
|
|
|
m_surfaceGenerator.setCellVisibility(cellVisibilities);
|
|
|
|
m_surfaceGenerator.addFaceVisibilityFilter(&m_surfaceFaceFilter);
|
|
|
|
|
2014-07-30 07:52:32 -05:00
|
|
|
generatePartGeometry(m_surfaceGenerator);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
2014-07-30 07:52:32 -05:00
|
|
|
void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoBuilder)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
bool useBufferObjects = true;
|
|
|
|
// Surface geometry
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::DrawableGeo> geo = geoBuilder.generateSurface();
|
|
|
|
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->setId(m_gridIdx); // !! For now, use grid index as part ID (needed for pick info)
|
|
|
|
part->setDrawable(geo.p());
|
|
|
|
part->setTransform(m_scaleTransform.p());
|
|
|
|
|
|
|
|
// Set mapping from triangle face index to cell index
|
2013-12-20 03:57:53 -06:00
|
|
|
cvf::ref<RivSourceInfo> si = new RivSourceInfo;
|
2014-06-24 10:19:30 -05:00
|
|
|
si->m_cellFaceFromTriangleMapper = geoBuilder.triangleToCellFaceMapper();
|
|
|
|
|
2013-12-20 03:57:53 -06:00
|
|
|
part->setSourceInfo(si.p());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
part->updateBoundingBox();
|
|
|
|
|
|
|
|
// Set default effect
|
2013-12-17 06:11:46 -06:00
|
|
|
caf::SurfaceEffectGenerator geometryEffgen(cvf::Color4f(cvf::Color3f::WHITE), caf::PO_1);
|
2012-05-18 02:45:23 -05:00
|
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateEffect();
|
|
|
|
part->setEffect(geometryOnlyEffect.p());
|
2014-07-30 07:52:32 -05:00
|
|
|
part->setEnableMask(surfaceBit);
|
|
|
|
m_surfaceFaces = part;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mesh geometry
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::DrawableGeo> 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();
|
|
|
|
|
2013-04-12 06:15:41 -05:00
|
|
|
RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
cvf::ref<cvf::Effect> eff;
|
2014-07-30 07:52:32 -05:00
|
|
|
caf::MeshEffectGenerator effGen(prefs->defaultGridLineColors());
|
|
|
|
eff = effGen.generateEffect();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2014-07-30 07:52:32 -05:00
|
|
|
// Set priority to make sure fault lines are rendered first
|
|
|
|
part->setPriority(10);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2014-07-30 07:52:32 -05:00
|
|
|
part->setEnableMask(meshSurfaceBit);
|
|
|
|
part->setEffect(eff.p());
|
|
|
|
m_surfaceGridLines = part;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 07:52:32 -05:00
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivGridPartMgr::appendPartsToModel(cvf::ModelBasicList* model)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(model != NULL);
|
|
|
|
|
|
|
|
if(m_surfaceFaces.notNull() ) model->addPart(m_surfaceFaces.p() );
|
|
|
|
if(m_surfaceGridLines.notNull()) model->addPart(m_surfaceGridLines.p());
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivGridPartMgr::updateCellColor(cvf::Color4f color)
|
|
|
|
{
|
2014-07-30 07:52:32 -05:00
|
|
|
if (m_surfaceFaces.isNull()) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
// Set default effect
|
2013-12-17 06:11:46 -06:00
|
|
|
caf::SurfaceEffectGenerator geometryEffgen(color, caf::PO_1);
|
2012-05-18 02:45:23 -05:00
|
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateEffect();
|
|
|
|
|
|
|
|
if (m_surfaceFaces.notNull()) m_surfaceFaces->setEffect(geometryOnlyEffect.p());
|
|
|
|
|
|
|
|
if (color.a() < 1.0f)
|
|
|
|
{
|
|
|
|
// Set priority to make sure this transparent geometry are rendered last
|
|
|
|
if (m_surfaceFaces.notNull()) m_surfaceFaces->setPriority(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_opacityLevel = color.a();
|
|
|
|
m_defaultColor = color.toColor3f();
|
2013-04-12 06:15:41 -05:00
|
|
|
|
|
|
|
// Update mesh colors as well, in case of change
|
|
|
|
RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
|
|
if (m_surfaceFaces.notNull())
|
|
|
|
{
|
|
|
|
caf::MeshEffectGenerator effGen(prefs->defaultGridLineColors());
|
|
|
|
eff = effGen.generateEffect();
|
|
|
|
m_surfaceGridLines->setEffect(eff.p());
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
2014-08-08 09:08:11 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* cellResultSlot)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(cellResultSlot);
|
|
|
|
|
|
|
|
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
|
|
|
|
|
|
|
|
cvf::ref<cvf::Color3ubArray> surfaceFacesColorArray;
|
|
|
|
|
|
|
|
// Outer surface
|
2014-08-11 06:59:12 -05:00
|
|
|
if (m_surfaceFaces.notNull())
|
|
|
|
{
|
|
|
|
if (cellResultSlot->isTernarySaturationSelected())
|
|
|
|
{
|
2014-08-11 03:50:31 -05:00
|
|
|
RivTernaryTextureCoordsCreator texturer(cellResultSlot, cellResultSlot->ternaryLegendConfig(),
|
|
|
|
timeStepIndex,
|
|
|
|
m_grid->gridIndex(),
|
|
|
|
m_surfaceGenerator.quadToCellFaceMapper());
|
|
|
|
|
|
|
|
texturer.createTextureCoords(m_surfaceFacesTextureCoords.p());
|
|
|
|
|
2014-08-11 06:59:12 -05:00
|
|
|
const RivTernaryScalarMapper* mapper = cellResultSlot->ternaryLegendConfig()->scalarMapper();
|
2014-08-21 07:41:03 -05:00
|
|
|
RivScalarMapperUtils::applyTernaryTextureResultsToPart(m_surfaceFaces.p(), m_surfaceFacesTextureCoords.p(), mapper, m_opacityLevel, caf::FC_NONE);
|
2014-08-11 06:59:12 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RivTextureCoordsCreator texturer(cellResultSlot,
|
|
|
|
timeStepIndex,
|
|
|
|
m_grid->gridIndex(),
|
|
|
|
m_surfaceGenerator.quadToCellFaceMapper());
|
2014-08-11 04:02:16 -05:00
|
|
|
if (!texturer.isValid())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-08-08 09:08:11 -05:00
|
|
|
|
2014-08-11 06:59:12 -05:00
|
|
|
texturer.createTextureCoords(m_surfaceFacesTextureCoords.p());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2014-08-11 06:59:12 -05:00
|
|
|
const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper();
|
2014-08-21 07:41:03 -05:00
|
|
|
RivScalarMapperUtils::applyTextureResultsToPart(m_surfaceFaces.p(), m_surfaceFacesTextureCoords.p(), mapper, m_opacityLevel, caf::FC_NONE);
|
2014-08-11 06:59:12 -05:00
|
|
|
}
|
|
|
|
}
|
2014-06-24 15:49:56 -05:00
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivGridPartMgr::updateCellEdgeResultColor(size_t timeStepIndex, RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot)
|
|
|
|
{
|
2014-08-13 03:45:09 -05:00
|
|
|
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(),
|
2014-08-21 07:41:03 -05:00
|
|
|
timeStepIndex, cellResultSlot, cellEdgeResultSlot, m_opacityLevel, m_defaultColor, caf::FC_NONE);
|
2014-07-04 02:12:42 -05:00
|
|
|
|
2014-08-13 03:45:09 -05:00
|
|
|
m_surfaceFaces->setEffect(eff.p());
|
|
|
|
}
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
}
|
2013-12-16 13:52:49 -06:00
|
|
|
|
2013-12-17 00:58:29 -06:00
|
|
|
|