Renamed and restructured files and classes

This commit is contained in:
Magne Sjaastad 2014-08-13 11:00:47 +02:00
parent 7e5c46cf59
commit 2a55b47e9a
6 changed files with 426 additions and 366 deletions

View File

@ -29,6 +29,7 @@ ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.h
${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.h
${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.h
${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.h
${CEE_CURRENT_LIST_DIR}RivCellEdgeGeometryUtils.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -54,6 +55,7 @@ ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.cpp
${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.cpp
${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.cpp
${CEE_CURRENT_LIST_DIR}RivCellEdgeGeometryUtils.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
// Copyright (C) Statoil ASA, Ceetron Solutions 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
@ -16,330 +16,23 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaStdInclude.h"
#include "RivCellEdgeEffectGenerator.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigCellEdgeResultAccessor.h"
#include "RigGridBase.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCase.h"
#include "RimCellEdgeResultSlot.h"
#include "RimReservoirView.h"
#include "RimResultSlot.h"
#include "RimTernaryLegendConfig.h"
#include "RimWellCollection.h"
#include "RivTernaryScalarMapper.h"
#include "RivTernaryTextureCoordsCreator.h"
#include "cvfStructGridGeometryGenerator.h"
#include "cvfRenderStateBlending.h"
#include "cvfRenderStateCullFace.h"
#include "cvfRenderStateTextureBindings.h"
#include "cvfSampler.h"
#include "cvfShaderProgram.h"
#include "cvfShaderProgramGenerator.h"
#include "cvfShaderSourceProvider.h"
#include "cvfTexture.h"
#include "cvfqtUtils.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel)
{
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
CVF_ASSERT(eclipseCase != NULL);
// Create result access objects
cvf::ref<RigResultAccessor> cellCenterDataAccessObject = createCellCenterResultAccessor(cellResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeCenterResultAccessor(cellResultSlot, cellEdgeResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
size_t vertexCount = geo->vertexArray()->size();
size_t quadCount = vertexCount / 4;
cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
localCoords->resize(vertexCount);
cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
faceIndexArray->resize(vertexCount);
cvf::ref<cvf::FloatArray> cellColorTextureCoordArray = new cvf::FloatArray;
cellColorTextureCoordArray->resize(vertexCount);
// Build six cell face color arrays
cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
size_t idx;
for (idx = 0; idx < 6; idx++)
{
cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
colorArray->resize(vertexCount);
cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
}
cvf::ScalarMapper* cellResultScalarMapper = cellResultSlot->legendConfig()->scalarMapper();
cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultSlot->legendConfig()->scalarMapper();
double ignoredScalarValue = cellEdgeResultSlot->ignoredScalarValue();
const std::vector<cvf::ubyte>* isWellPipeVisible = NULL;
cvf::ref<cvf::UIntArray> gridCellToWellindexMap;
if (opacityLevel < 1.0f)
{
isWellPipeVisible = &(cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex));
gridCellToWellindexMap = eclipseCase->gridCellToWellIndex( gridIndex );
}
#pragma omp parallel for
for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
{
localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));
faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx) );
faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx) );
faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx) );
faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx) );
size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);
{
cvf::StructGridInterface::FaceType cellFace = quadToCellFaceMapper->cellFace(quadIdx);
double scalarValue = cellCenterDataAccessObject->cellFaceScalar(cellIndex, cellFace);
{
float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color
if (scalarValue != HUGE_VAL)
{
cellColorTextureCoord = cellResultScalarMapper->mapToTextureCoord(scalarValue)[0];
// If we are dealing with wellcells, the default is transparent.
// we need to make cells opaque if there are no wellpipe through them.
if (opacityLevel < 1.0f)
{
cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex);
if (wellIndex != cvf::UNDEFINED_UINT)
{
if (!(*isWellPipeVisible)[wellIndex])
{
cellColorTextureCoord += 2.0f; // The shader must interpret values in the range 2-3 as "opaque"
}
}
}
}
else
{
cellColorTextureCoord = -1.0f; // Undefined texture coord. Shader handles this.
}
cellColorTextureCoordArray->set(quadIdx * 4 + 0, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 1, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 2, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 3, cellColorTextureCoord);
}
}
float edgeColor;
for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
edgeColor = -1.0f; // Undefined texture coord. Shader handles this.
double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));
if (scalarValue != HUGE_VAL && scalarValue != ignoredScalarValue)
{
edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
}
cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);
colArr->set(quadIdx * 4 + 0, edgeColor);
colArr->set(quadIdx * 4 + 1, edgeColor);
colArr->set(quadIdx * 4 + 2, edgeColor);
colArr->set(quadIdx * 4 + 3, edgeColor);
}
}
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorCell", cellColorTextureCoordArray.p()));
cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
geo->setVertexAttribute(faceIntAttribute.p());
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryGenerator::addTernaryCellEdgeResultsToDrawableGeo(size_t timeStepIndex, RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo, size_t gridIndex, float opacityLevel)
{
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
CVF_ASSERT(eclipseCase != NULL);
cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeCenterResultAccessor(cellResultSlot, cellEdgeResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
size_t vertexCount = geo->vertexArray()->size();
size_t quadCount = vertexCount / 4;
cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
localCoords->resize(vertexCount);
cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
faceIndexArray->resize(vertexCount);
cvf::ref<cvf::Vec2fArray> vCellColorTextureCoordArray = new cvf::Vec2fArray;
vCellColorTextureCoordArray->resize(vertexCount);
// Build six cell face color arrays
cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
size_t idx;
for (idx = 0; idx < 6; idx++)
{
cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
colorArray->resize(vertexCount);
cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
}
RivTernaryScalarMapper* ternaryCellResultScalarMapper = cellResultSlot->ternaryLegendConfig()->scalarMapper();
cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultSlot->legendConfig()->scalarMapper();
double ignoredScalarValue = cellEdgeResultSlot->ignoredScalarValue();
RivTernaryTextureCoordsCreator texturer(cellResultSlot, cellResultSlot->ternaryLegendConfig(),
timeStepIndex,
gridIndex,
quadToCellFaceMapper);
texturer.createTextureCoords(vCellColorTextureCoordArray.p());
#pragma omp parallel for
for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
{
localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));
faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx));
size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);
float edgeColor;
for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
edgeColor = -1.0f; // Undefined texture coord. Shader handles this.
double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));
if (scalarValue != HUGE_VAL && scalarValue != ignoredScalarValue)
{
edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
}
cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);
colArr->set(quadIdx * 4 + 0, edgeColor);
colArr->set(quadIdx * 4 + 1, edgeColor);
colArr->set(quadIdx * 4 + 2, edgeColor);
colArr->set(quadIdx * 4 + 3, edgeColor);
}
}
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_cellTextureCoord", vCellColorTextureCoordArray.p()));
cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
geo->setVertexAttribute(faceIntAttribute.p());
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigResultAccessor> RivCellEdgeGeometryGenerator::createCellEdgeCenterResultAccessor(
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid)
{
cvf::ref<RigCellEdgeResultAccessor> cellEdgeResultAccessor = new RigCellEdgeResultAccessor();
{
size_t resultIndices[6];
cellEdgeResultSlot->gridScalarIndices(resultIndices);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
size_t cubeFaceIdx;
for (cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
// Assuming static values to be mapped onto cell edge, always using time step zero
cvf::ref<RigResultAccessor> daObj = RigResultAccessorFactory::createResultAccessor(eclipseCase, grid->gridIndex(), porosityModel, 0, resultIndices[cubeFaceIdx]);
cellEdgeResultAccessor->setDataAccessObjectForFace(static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx), daObj.p());
}
}
return cellEdgeResultAccessor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigResultAccessor> RivCellEdgeGeometryGenerator::createCellCenterResultAccessor(RimResultSlot* cellResultSlot, size_t timeStepIndex, RigCaseData* eclipseCase, const RigGridBase* grid)
{
cvf::ref<RigResultAccessor> resultAccessor = NULL;
if (cellResultSlot->hasResult())
{
if (!cellResultSlot->hasDynamicResult())
{
// Static result values are located at time step 0
timeStepIndex = 0;
}
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, grid->gridIndex(), porosityModel, timeStepIndex, cellResultSlot->resultVariable());
}
if (resultAccessor.isNull())
{
resultAccessor = new RigHugeValResultAccessor;
}
return resultAccessor;
}
#include <QFile>
#include <QTextStream>
//--------------------------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
// Copyright (C) Statoil ASA, Ceetron Solutions 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
@ -20,54 +20,9 @@
#include "cafEffectGenerator.h"
namespace cvf
{
class DrawableGeo;
class StructGridQuadToCellFaceMapper;
}
class RimCellEdgeResultSlot;
class RimResultSlot;
class RigGridBase;
class RigResultAccessor;
class RigCaseData;
class RivTernaryScalarMapper;
class RivCellEdgeGeometryGenerator
{
public:
static void addCellEdgeResultsToDrawableGeo(size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel);
static void addTernaryCellEdgeResultsToDrawableGeo(size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel);
private:
static cvf::ref<RigResultAccessor> createCellCenterResultAccessor(
RimResultSlot* cellResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid);
static cvf::ref<RigResultAccessor> createCellEdgeCenterResultAccessor(
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid);
};
/*
Thoughts on organizing the texture coords generation a bit.

View File

@ -0,0 +1,339 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA, Ceetron Solutions 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 "RivCellEdgeGeometryUtils.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigCellEdgeResultAccessor.h"
#include "RigGridBase.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimCase.h"
#include "RimCellEdgeResultSlot.h"
#include "RimReservoirView.h"
#include "RimResultSlot.h"
#include "RimTernaryLegendConfig.h"
#include "RimWellCollection.h"
#include "RivTernaryTextureCoordsCreator.h"
#include "cvfDrawableGeo.h"
#include "cvfVertexAttribute.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryUtils::addCellEdgeResultsToDrawableGeo(
size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel)
{
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
CVF_ASSERT(eclipseCase != NULL);
// Create result access objects
cvf::ref<RigResultAccessor> cellCenterDataAccessObject = createCellCenterResultAccessor(cellResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeCenterResultAccessor(cellResultSlot, cellEdgeResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
size_t vertexCount = geo->vertexArray()->size();
size_t quadCount = vertexCount / 4;
cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
localCoords->resize(vertexCount);
cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
faceIndexArray->resize(vertexCount);
cvf::ref<cvf::FloatArray> cellColorTextureCoordArray = new cvf::FloatArray;
cellColorTextureCoordArray->resize(vertexCount);
// Build six cell face color arrays
cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
size_t idx;
for (idx = 0; idx < 6; idx++)
{
cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
colorArray->resize(vertexCount);
cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
}
cvf::ScalarMapper* cellResultScalarMapper = cellResultSlot->legendConfig()->scalarMapper();
cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultSlot->legendConfig()->scalarMapper();
double ignoredScalarValue = cellEdgeResultSlot->ignoredScalarValue();
const std::vector<cvf::ubyte>* isWellPipeVisible = NULL;
cvf::ref<cvf::UIntArray> gridCellToWellindexMap;
if (opacityLevel < 1.0f)
{
isWellPipeVisible = &(cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex));
gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(gridIndex);
}
#pragma omp parallel for
for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
{
localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));
faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx));
size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);
{
cvf::StructGridInterface::FaceType cellFace = quadToCellFaceMapper->cellFace(quadIdx);
double scalarValue = cellCenterDataAccessObject->cellFaceScalar(cellIndex, cellFace);
{
float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color
if (scalarValue != HUGE_VAL)
{
cellColorTextureCoord = cellResultScalarMapper->mapToTextureCoord(scalarValue)[0];
// If we are dealing with wellcells, the default is transparent.
// we need to make cells opaque if there are no wellpipe through them.
if (opacityLevel < 1.0f)
{
cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex);
if (wellIndex != cvf::UNDEFINED_UINT)
{
if (!(*isWellPipeVisible)[wellIndex])
{
cellColorTextureCoord += 2.0f; // The shader must interpret values in the range 2-3 as "opaque"
}
}
}
}
else
{
cellColorTextureCoord = -1.0f; // Undefined texture coord. Shader handles this.
}
cellColorTextureCoordArray->set(quadIdx * 4 + 0, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 1, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 2, cellColorTextureCoord);
cellColorTextureCoordArray->set(quadIdx * 4 + 3, cellColorTextureCoord);
}
}
float edgeColor;
for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
edgeColor = -1.0f; // Undefined texture coord. Shader handles this.
double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));
if (scalarValue != HUGE_VAL && scalarValue != ignoredScalarValue)
{
edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
}
cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);
colArr->set(quadIdx * 4 + 0, edgeColor);
colArr->set(quadIdx * 4 + 1, edgeColor);
colArr->set(quadIdx * 4 + 2, edgeColor);
colArr->set(quadIdx * 4 + 3, edgeColor);
}
}
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorCell", cellColorTextureCoordArray.p()));
cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
geo->setVertexAttribute(faceIntAttribute.p());
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCellEdgeGeometryUtils::addTernaryCellEdgeResultsToDrawableGeo(size_t timeStepIndex, RimResultSlot* cellResultSlot, RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo, size_t gridIndex, float opacityLevel)
{
RigCaseData* eclipseCase = cellResultSlot->reservoirView()->eclipseCase()->reservoirData();
CVF_ASSERT(eclipseCase != NULL);
cvf::ref<RigResultAccessor> cellEdgeResultAccessor = createCellEdgeCenterResultAccessor(cellResultSlot, cellEdgeResultSlot, timeStepIndex, eclipseCase, eclipseCase->grid(gridIndex));
size_t vertexCount = geo->vertexArray()->size();
size_t quadCount = vertexCount / 4;
cvf::ref<cvf::Vec2fArray> localCoords = new cvf::Vec2fArray;
localCoords->resize(vertexCount);
cvf::ref<cvf::IntArray> faceIndexArray = new cvf::IntArray;
faceIndexArray->resize(vertexCount);
cvf::ref<cvf::Vec2fArray> vCellColorTextureCoordArray = new cvf::Vec2fArray;
vCellColorTextureCoordArray->resize(vertexCount);
// Build six cell face color arrays
cvf::Collection<cvf::FloatArray> cellEdgeColorTextureCoordsArrays;
size_t idx;
for (idx = 0; idx < 6; idx++)
{
cvf::ref<cvf::FloatArray> colorArray = new cvf::FloatArray;
colorArray->resize(vertexCount);
cellEdgeColorTextureCoordsArrays.push_back(colorArray.p());
}
RivTernaryScalarMapper* ternaryCellResultScalarMapper = cellResultSlot->ternaryLegendConfig()->scalarMapper();
cvf::ScalarMapper* edgeResultScalarMapper = cellEdgeResultSlot->legendConfig()->scalarMapper();
double ignoredScalarValue = cellEdgeResultSlot->ignoredScalarValue();
RivTernaryTextureCoordsCreator texturer(cellResultSlot, cellResultSlot->ternaryLegendConfig(),
timeStepIndex,
gridIndex,
quadToCellFaceMapper);
texturer.createTextureCoords(vCellColorTextureCoordArray.p());
#pragma omp parallel for
for (int quadIdx = 0; quadIdx < static_cast<int>(quadCount); quadIdx++)
{
localCoords->set(quadIdx * 4 + 0, cvf::Vec2f(0, 0));
localCoords->set(quadIdx * 4 + 1, cvf::Vec2f(1, 0));
localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1));
localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1));
faceIndexArray->set(quadIdx * 4 + 0, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 1, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 2, quadToCellFaceMapper->cellFace(quadIdx));
faceIndexArray->set(quadIdx * 4 + 3, quadToCellFaceMapper->cellFace(quadIdx));
size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx);
float edgeColor;
for (size_t cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
edgeColor = -1.0f; // Undefined texture coord. Shader handles this.
double scalarValue = cellEdgeResultAccessor->cellFaceScalar(cellIndex, static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx));
if (scalarValue != HUGE_VAL && scalarValue != ignoredScalarValue)
{
edgeColor = edgeResultScalarMapper->mapToTextureCoord(scalarValue)[0];
}
cvf::FloatArray* colArr = cellEdgeColorTextureCoordsArrays.at(cubeFaceIdx);
colArr->set(quadIdx * 4 + 0, edgeColor);
colArr->set(quadIdx * 4 + 1, edgeColor);
colArr->set(quadIdx * 4 + 2, edgeColor);
colArr->set(quadIdx * 4 + 3, edgeColor);
}
}
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_localCoord", localCoords.p()));
geo->setVertexAttribute(new cvf::Vec2fVertexAttribute("a_cellTextureCoord", vCellColorTextureCoordArray.p()));
cvf::ref<cvf::IntVertexAttributeDirect> faceIntAttribute = new cvf::IntVertexAttributeDirect("a_face", faceIndexArray.p());
geo->setVertexAttribute(faceIntAttribute.p());
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosI", cellEdgeColorTextureCoordsArrays.at(0)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegI", cellEdgeColorTextureCoordsArrays.at(1)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosJ", cellEdgeColorTextureCoordsArrays.at(2)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegJ", cellEdgeColorTextureCoordsArrays.at(3)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorPosK", cellEdgeColorTextureCoordsArrays.at(4)));
geo->setVertexAttribute(new cvf::FloatVertexAttribute("a_colorNegK", cellEdgeColorTextureCoordsArrays.at(5)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigResultAccessor> RivCellEdgeGeometryUtils::createCellEdgeCenterResultAccessor(
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid)
{
cvf::ref<RigCellEdgeResultAccessor> cellEdgeResultAccessor = new RigCellEdgeResultAccessor();
{
size_t resultIndices[6];
cellEdgeResultSlot->gridScalarIndices(resultIndices);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
size_t cubeFaceIdx;
for (cubeFaceIdx = 0; cubeFaceIdx < 6; cubeFaceIdx++)
{
// Assuming static values to be mapped onto cell edge, always using time step zero
cvf::ref<RigResultAccessor> daObj = RigResultAccessorFactory::createResultAccessor(eclipseCase, grid->gridIndex(), porosityModel, 0, resultIndices[cubeFaceIdx]);
cellEdgeResultAccessor->setDataAccessObjectForFace(static_cast<cvf::StructGridInterface::FaceType>(cubeFaceIdx), daObj.p());
}
}
return cellEdgeResultAccessor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigResultAccessor> RivCellEdgeGeometryUtils::createCellCenterResultAccessor(RimResultSlot* cellResultSlot, size_t timeStepIndex, RigCaseData* eclipseCase, const RigGridBase* grid)
{
cvf::ref<RigResultAccessor> resultAccessor = NULL;
if (cellResultSlot->hasResult())
{
if (!cellResultSlot->hasDynamicResult())
{
// Static result values are located at time step 0
timeStepIndex = 0;
}
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel());
resultAccessor = RigResultAccessorFactory::createResultAccessor(eclipseCase, grid->gridIndex(), porosityModel, timeStepIndex, cellResultSlot->resultVariable());
}
if (resultAccessor.isNull())
{
resultAccessor = new RigHugeValResultAccessor;
}
return resultAccessor;
}

View File

@ -0,0 +1,70 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA, Ceetron Solutions 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
namespace cvf
{
class DrawableGeo;
class StructGridQuadToCellFaceMapper;
}
class RimCellEdgeResultSlot;
class RimResultSlot;
class RigGridBase;
class RigResultAccessor;
class RigCaseData;
class RivCellEdgeGeometryUtils
{
public:
static void addCellEdgeResultsToDrawableGeo(size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel);
static void addTernaryCellEdgeResultsToDrawableGeo(size_t timeStepIndex,
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper,
cvf::DrawableGeo* geo,
size_t gridIndex,
float opacityLevel);
private:
static cvf::ref<RigResultAccessor> createCellCenterResultAccessor(
RimResultSlot* cellResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid);
static cvf::ref<RigResultAccessor> createCellEdgeCenterResultAccessor(
RimResultSlot* cellResultSlot,
RimCellEdgeResultSlot* cellEdgeResultSlot,
size_t timeStepIndex,
RigCaseData* eclipseCase,
const RigGridBase* grid);
};

View File

@ -25,6 +25,7 @@
#include "RimTernaryLegendConfig.h"
#include "RivCellEdgeEffectGenerator.h"
#include "RivCellEdgeGeometryUtils.h"
#include "RivTernaryScalarMapper.h"
#include "RivTernaryScalarMapperEffectGenerator.h"
@ -78,7 +79,7 @@ cvf::ref<cvf::Effect> RivScalarMapperUtils::createCellEdgeEffect(cvf::DrawableGe
if (cellResultSlot->isTernarySaturationSelected())
{
RivCellEdgeGeometryGenerator::addTernaryCellEdgeResultsToDrawableGeo(timeStepIndex, cellResultSlot, cellEdgeResultSlot,
RivCellEdgeGeometryUtils::addTernaryCellEdgeResultsToDrawableGeo(timeStepIndex, cellResultSlot, cellEdgeResultSlot,
quadToCellFaceMapper, dg, gridIndex, opacityLevel);
RivTernaryScalarMapper* ternaryCellScalarMapper = cellResultSlot->ternaryLegendConfig()->scalarMapper();
@ -88,7 +89,7 @@ cvf::ref<cvf::Effect> RivScalarMapperUtils::createCellEdgeEffect(cvf::DrawableGe
{
if (cellResultSlot->hasResult())
{
RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(timeStepIndex, cellResultSlot, cellEdgeResultSlot,
RivCellEdgeGeometryUtils::addCellEdgeResultsToDrawableGeo(timeStepIndex, cellResultSlot, cellEdgeResultSlot,
quadToCellFaceMapper, dg, gridIndex, opacityLevel);
cvf::ScalarMapper* cellScalarMapper = cellResultSlot->legendConfig()->scalarMapper();