2015-11-17 02:23:33 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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 "RigCaseCellResultsData.h"
|
|
|
|
#include "RigCaseData.h"
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
2015-11-19 04:41:16 -06:00
|
|
|
#include "RimCrossSection.h"
|
2015-11-17 02:23:33 -06:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCellColors.h"
|
2015-11-19 04:41:16 -06:00
|
|
|
#include "RimEclipseView.h"
|
2015-11-17 02:23:33 -06:00
|
|
|
#include "RimTernaryLegendConfig.h"
|
|
|
|
|
|
|
|
#include "RivResultToTextureMapper.h"
|
|
|
|
#include "RivScalarMapperUtils.h"
|
|
|
|
#include "RivTernaryScalarMapper.h"
|
|
|
|
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cvfPrimitiveSetDirect.h"
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-19 04:41:16 -06:00
|
|
|
RivCrossSectionPartMgr::RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection)
|
|
|
|
: m_rimCrossSection(rimCrossSection),
|
|
|
|
m_grid(NULL),
|
|
|
|
m_defaultColor(cvf::Color3::WHITE)
|
2015-11-17 02:23:33 -06:00
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
CVF_ASSERT(m_rimCrossSection);
|
2015-11-17 02:23:33 -06:00
|
|
|
|
|
|
|
m_nativeCrossSectionFacesTextureCoords = new cvf::Vec2fArray;
|
2015-11-19 04:41:16 -06:00
|
|
|
|
|
|
|
computeData();
|
2015-11-17 02:23:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivCrossSectionPartMgr::applySingleColorEffect()
|
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
if (m_nativeCrossSectionGenerator.isNull()) return;
|
|
|
|
|
2015-11-17 02:23:33 -06:00
|
|
|
m_defaultColor = cvf::Color3f::OLIVE;//m_rimCrossSection->CrossSectionColor();
|
|
|
|
this->updatePartEffect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEclipseCellColors* cellResultColors)
|
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
if (m_nativeCrossSectionGenerator.isNull()) return;
|
|
|
|
|
2015-11-17 02:23:33 -06:00
|
|
|
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
|
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
CVF_ASSERT(m_nativeCrossSectionGenerator.notNull());
|
|
|
|
|
2015-11-17 02:23:33 -06:00
|
|
|
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()
|
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
if (m_nativeCrossSectionGenerator.isNull()) return;
|
2015-11-17 02:23:33 -06:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2015-11-19 04:41:16 -06:00
|
|
|
if (m_nativeCrossSectionGenerator.isNull()) return;
|
|
|
|
|
2015-11-17 02:23:33 -06:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-17 10:21:53 -06:00
|
|
|
void RivCrossSectionPartMgr::appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
|
2015-11-17 02:23:33 -06:00
|
|
|
{
|
|
|
|
if (m_nativeCrossSectionFaces.isNull())
|
|
|
|
{
|
|
|
|
generatePartGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_nativeCrossSectionFaces.notNull())
|
|
|
|
{
|
2015-11-17 10:21:53 -06:00
|
|
|
m_nativeCrossSectionFaces->setTransform(scaleTransform);
|
2015-11-17 02:23:33 -06:00
|
|
|
model->addPart(m_nativeCrossSectionFaces.p());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-17 10:21:53 -06:00
|
|
|
void RivCrossSectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
|
2015-11-17 02:23:33 -06:00
|
|
|
{
|
2015-11-17 10:21:53 -06:00
|
|
|
if (m_nativeCrossSectionGridLines.isNull())
|
|
|
|
{
|
|
|
|
generatePartGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_nativeCrossSectionGridLines.notNull())
|
|
|
|
{
|
|
|
|
m_nativeCrossSectionGridLines->setTransform(scaleTransform);
|
|
|
|
model->addPart(m_nativeCrossSectionGridLines.p());
|
|
|
|
}
|
2015-11-17 02:23:33 -06:00
|
|
|
}
|
|
|
|
|
2015-11-19 04:41:16 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivCrossSectionPartMgr::computeData()
|
|
|
|
{
|
|
|
|
m_grid = mainGrid();
|
|
|
|
CVF_ASSERT(m_grid.notNull());
|
|
|
|
|
|
|
|
std::vector< std::vector <cvf::Vec3d> > polyLine = m_rimCrossSection->polyLines();
|
|
|
|
if (polyLine.size() > 0)
|
|
|
|
{
|
|
|
|
cvf::Vec3d direction = extrusionDirection(polyLine[0]);
|
|
|
|
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine[0], direction, m_grid.p());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RigMainGrid* RivCrossSectionPartMgr::mainGrid()
|
|
|
|
{
|
|
|
|
RigMainGrid* grid = NULL;
|
|
|
|
|
|
|
|
RimEclipseView* eclipseView = NULL;
|
|
|
|
m_rimCrossSection->firstAnchestorOrThisOfType(eclipseView);
|
|
|
|
if (eclipseView)
|
|
|
|
{
|
|
|
|
grid = eclipseView->eclipseCase()->reservoirData()->mainGrid();
|
|
|
|
}
|
|
|
|
|
|
|
|
return grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec3d RivCrossSectionPartMgr::extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const
|
|
|
|
{
|
|
|
|
CVF_ASSERT(m_rimCrossSection);
|
|
|
|
|
|
|
|
cvf::Vec3d dir = cvf::Vec3d::Z_AXIS;
|
|
|
|
|
|
|
|
if (m_rimCrossSection->direction == RimCrossSection::CS_VERTICAL &&
|
|
|
|
polyline.size() > 1)
|
|
|
|
{
|
|
|
|
// Use first and last point of polyline to approximate orientation of polyline
|
|
|
|
// Then cross with Z axis to find extrusion direction
|
|
|
|
|
|
|
|
cvf::Vec3d polyLineDir = polyline[polyline.size() - 1] - polyline[0];
|
|
|
|
cvf::Vec3d up = cvf::Vec3d::Z_AXIS;
|
|
|
|
dir = polyLineDir ^ up;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|