(#166) WIP: First visible section with hacks

This commit is contained in:
Jacob Støren
2015-11-17 09:23:33 +01:00
parent 7845d9bd3c
commit 57f7c1229a
7 changed files with 358 additions and 6 deletions

View File

@@ -9,6 +9,8 @@ ${CEE_CURRENT_LIST_DIR}RivCellEdgeEffectGenerator.h
${CEE_CURRENT_LIST_DIR}RivColorTableArray.h
${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.h
${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.h
${CEE_CURRENT_LIST_DIR}RivCrossSectionGeometryGenerator.h
${CEE_CURRENT_LIST_DIR}RivCrossSectionPartMgr.h
${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.h
${CEE_CURRENT_LIST_DIR}RivGridPartMgr.h
${CEE_CURRENT_LIST_DIR}RivTernarySaturationOverlayItem.h
@@ -40,6 +42,8 @@ ${CEE_CURRENT_LIST_DIR}RivCellEdgeEffectGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivColorTableArray.cpp
${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivCrossSectionGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivCrossSectionPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.cpp
${CEE_CURRENT_LIST_DIR}RivGridPartMgr.cpp
${CEE_CURRENT_LIST_DIR}RivTernarySaturationOverlayItem.cpp

View File

@@ -704,7 +704,7 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
if (m_triangleVxes->size()) return;
std::vector<cvf::Vec3f> triangleVertices;
cvf::Vec3d displayOffset = m_mainGrid->displayModelOffset();
cvf::BoundingBox gridBBox = m_mainGrid->boundingBox();
m_extrusionDirection.normalize();
@@ -741,9 +741,11 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
for (size_t cccIdx = 0; cccIdx < columnCellCandidates.size(); ++cccIdx)
{
triangleVxes.clear();
size_t globalCellIdx = columnCellCandidates[cccIdx];
if (m_mainGrid->cells()[globalCellIdx].isInvalid()) continue;
triangleVxes.clear();
cvf::Vec3d cellCorners[8];
m_mainGrid->cellCornerVertices(globalCellIdx, cellCorners);
@@ -770,9 +772,9 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
{
// Accumulate to geometry
int triVxIdx = tIdx*3;
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+0].vx));
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+1].vx));
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+2].vx));
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+0].vx - displayOffset));
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+1].vx - displayOffset));
triangleVertices.push_back(cvf::Vec3f(triangleVxes[triVxIdx+2].vx - displayOffset));
m_triangleToCellIdxMap.push_back(globalCellIdx);
}
@@ -867,6 +869,15 @@ cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::generateSurface()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::createMeshDrawable()
{
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
return geo;
}
//--------------------------------------------------------------------------------------------------
/// Calculates the texture coordinates in a "nearly" one dimentional texture.

View File

@@ -53,7 +53,7 @@ public:
// Generated geometry
cvf::ref<cvf::DrawableGeo> generateSurface();
//cvf::ref<cvf::DrawableGeo> createMeshDrawable();
cvf::ref<cvf::DrawableGeo> createMeshDrawable();
private:
void calculateArrays();

View File

@@ -0,0 +1,252 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA
// Copyright (C) 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 "RivCrossSectionPartMgr.h"
//#include "RiaApplication.h"
//#include "RiaPreferences.h"
#include "RigCaseCellResultsData.h"
#include "RigCaseData.h"
#include "RigResultAccessor.h"
#include "RigResultAccessorFactory.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimEclipseCellColors.h"
#include "RimTernaryLegendConfig.h"
//#include "RimCrossSectionCollection.h"
#include "RivResultToTextureMapper.h"
#include "RivScalarMapperUtils.h"
#include "RivTernaryScalarMapper.h"
#include "cvfDrawableGeo.h"
#include "cvfModelBasicList.h"
#include "cvfPart.h"
#include "cvfPrimitiveSetDirect.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivCrossSectionPartMgr::RivCrossSectionPartMgr( const RigMainGrid* grid,
const RimCrossSectionCollection* rimCrossSectionCollection,
const RimCrossSection* rimCrossSection)
: m_grid(grid),
m_rimCrossSectionCollection(rimCrossSectionCollection),
m_rimCrossSection(rimCrossSection),
m_defaultColor(cvf::Color3::WHITE)
{
std::vector<cvf::Vec3d> polyLine;
polyLine.push_back(grid->boundingBox().max());
polyLine.push_back(grid->boundingBox().min());
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine, cvf::Vec3d(0,0,1.0), grid );
m_nativeCrossSectionFacesTextureCoords = new cvf::Vec2fArray;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::applySingleColorEffect()
{
m_defaultColor = cvf::Color3f::OLIVE;//m_rimCrossSection->CrossSectionColor();
this->updatePartEffect();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors)
{
CVF_ASSERT(cellResultColors);
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultColors->porosityModel());
RimEclipseView* eclipseView = cellResultColors->reservoirView();
RigCaseData* eclipseCase = eclipseView->eclipseCase()->reservoirData();
// CrossSections
if (m_nativeCrossSectionFaces.notNull())
{
if (cellResultColors->isTernarySaturationSelected())
{
//RivTernaryTextureCoordsCreator texturer(cellResultColors, cellResultColors->ternaryLegendConfig(),
// timeStepIndex,
// m_grid->gridIndex(),
// m_nativeCrossSectionGenerator->quadToCellFaceMapper());
//
//texturer.createTextureCoords(m_nativeCrossSectionFacesTextureCoords.p());
CVF_ASSERT(false); // Todo
const RivTernaryScalarMapper* mapper = cellResultColors->ternaryLegendConfig()->scalarMapper();
RivScalarMapperUtils::applyTernaryTextureResultsToPart(m_nativeCrossSectionFaces.p(),
m_nativeCrossSectionFacesTextureCoords.p(),
mapper,
1.0,
caf::FC_NONE,
eclipseView->isLightingDisabled());
}
else
{
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createResultAccessor(cellResultColors->reservoirView()->eclipseCase()->reservoirData(),
0,
RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultColors->porosityModel()),
timeStepIndex,
cellResultColors->resultVariable());
m_nativeCrossSectionGenerator->textureCoordinates(m_nativeCrossSectionFacesTextureCoords.p(), resultAccessor.p() ,mapper);
RivScalarMapperUtils::applyTextureResultsToPart(m_nativeCrossSectionFaces.p(),
m_nativeCrossSectionFacesTextureCoords.p(),
mapper,
1.0,
caf::FC_NONE,
eclipseView->isLightingDisabled());
}
}
}
const int priCrossSectionGeo = 1;
const int priNncGeo = 2;
const int priMesh = 3;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::generatePartGeometry()
{
bool useBufferObjects = true;
// Surface geometry
{
cvf::ref<cvf::DrawableGeo> geo = m_nativeCrossSectionGenerator->generateSurface();
if (geo.notNull())
{
geo->computeNormals();
if (useBufferObjects)
{
geo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
}
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("Cross Section ");
part->setDrawable(geo.p());
// Set mapping from triangle face index to cell index
//cvf::ref<RivSourceInfo> si = new RivSourceInfo(m_grid->gridIndex());
//si->m_cellFaceFromTriangleMapper = m_nativeCrossSectionGenerator->triangleToCellFaceMapper();
//part->setSourceInfo(si.p());
part->updateBoundingBox();
part->setEnableMask(surfaceBit);
part->setPriority(priCrossSectionGeo);
m_nativeCrossSectionFaces = part;
}
}
// Mesh geometry
{
cvf::ref<cvf::DrawableGeo> geoMesh = m_nativeCrossSectionGenerator->createMeshDrawable();
if (geoMesh.notNull())
{
if (useBufferObjects)
{
geoMesh->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
}
cvf::ref<cvf::Part> part = new cvf::Part;
part->setName("Cross Section mesh" );
part->setDrawable(geoMesh.p());
part->updateBoundingBox();
part->setEnableMask(meshSurfaceBit);
part->setPriority(priMesh);
m_nativeCrossSectionGridLines = part;
}
}
updatePartEffect();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::updatePartEffect()
{
// Set deCrossSection effect
caf::SurfaceEffectGenerator geometryEffgen(m_defaultColor, caf::PO_1);
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
if (m_nativeCrossSectionFaces.notNull())
{
m_nativeCrossSectionFaces->setEffect(geometryOnlyEffect.p());
}
// Update mesh colors as well, in case of change
//RiaPreferences* prefs = RiaApplication::instance()->preferences();
cvf::ref<cvf::Effect> eff;
caf::MeshEffectGenerator CrossSectionEffGen(cvf::Color3::WHITE);//prefs->defaultCrossSectionGridLineColors());
eff = CrossSectionEffGen.generateCachedEffect();
if (m_nativeCrossSectionGridLines.notNull())
{
m_nativeCrossSectionGridLines->setEffect(eff.p());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model)
{
if (m_nativeCrossSectionFaces.isNull())
{
generatePartGeometry();
}
if (m_nativeCrossSectionFaces.notNull())
{
model->addPart(m_nativeCrossSectionFaces.p());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivCrossSectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* model)
{
if (m_nativeCrossSectionGridLines.notNull()) model->addPart(m_nativeCrossSectionGridLines.p());
}

View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) Statoil ASA
// Copyright (C) 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"
//#include "RimCrossSection.h"
#include "RivCrossSectionGeometryGenerator.h"
#include "cvfColor4.h"
namespace cvf
{
class ModelBasicList;
class Transform;
class Part;
}
class RimEclipseCellColors;
class RimCellEdgeColors;
class RimCrossSectionCollection;
class RimCrossSection;
//==================================================================================================
///
///
//==================================================================================================
class RivCrossSectionPartMgr : public cvf::Object
{
public:
RivCrossSectionPartMgr(const RigMainGrid* grid,
const RimCrossSectionCollection* rimCrossSectionCollection,
const RimCrossSection* rimCrossSection);
void applySingleColorEffect();
void updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors);
void appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model);
void appendMeshLinePartsToModel(cvf::ModelBasicList* model);
private:
void updatePartEffect();
void generatePartGeometry();
cvf::cref<RigMainGrid> m_grid;
const RimCrossSection* m_rimCrossSection;
const RimCrossSectionCollection* m_rimCrossSectionCollection;
cvf::Color3f m_defaultColor;
cvf::ref<RivCrossSectionGeometryGenerator> m_nativeCrossSectionGenerator;
cvf::ref<cvf::Part> m_nativeCrossSectionFaces;
cvf::ref<cvf::Part> m_nativeCrossSectionGridLines;
cvf::ref<cvf::Vec2fArray> m_nativeCrossSectionFacesTextureCoords;
};

View File

@@ -70,6 +70,7 @@
#include <QMessageBox>
#include <limits.h>
#include "RivCrossSectionPartMgr.h"
@@ -416,6 +417,15 @@ void RimEclipseView::createDisplayModel()
}
{
if (m_csPartmgr.isNull()) m_csPartmgr = new RivCrossSectionPartMgr(m_reservoir->reservoirData()->mainGrid(), NULL, NULL);
for (size_t frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx)
{
m_csPartmgr->appendNativeCrossSectionFacesToModel(frameModels[frameIdx].p());
frameModels[frameIdx]->part(frameModels[frameIdx]->partCount()-1)->setTransform(m_reservoirGridPartManager->scaleTransform());
}
}
// Compute triangle count, Debug only
/*
if (false)

View File

@@ -55,6 +55,7 @@ class RimEclipseCellColors;
class RimEclipseWellCollection;
class RiuViewer;
class RivReservoirPipesPartMgr;
class RivCrossSectionPartMgr;
namespace cvf
{
@@ -181,6 +182,7 @@ private:
cvf::ref<RivReservoirViewPartMgr> m_reservoirGridPartManager;
cvf::ref<RivReservoirPipesPartMgr> m_pipesPartManager;
cvf::ref<RivCrossSectionPartMgr> m_csPartmgr;
std::vector<RivCellSetEnum> m_visibleGridParts;
};