2015-04-24 08:53:50 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-05-08 06:33:18 -05:00
|
|
|
#include <stdlib.h>
|
2016-10-18 00:31:02 -05:00
|
|
|
|
2015-04-24 08:53:50 -05:00
|
|
|
#include "RivGeoMechPartMgr.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaPreferences.h"
|
|
|
|
|
2016-10-18 00:31:02 -05:00
|
|
|
#include "RifGeoMechReaderInterface.h"
|
|
|
|
|
|
|
|
#include "RigFemPartResultsCollection.h"
|
|
|
|
#include "RigFemScalarResultFrames.h"
|
|
|
|
#include "RigGeoMechCaseData.h"
|
|
|
|
|
2015-05-21 03:34:38 -05:00
|
|
|
#include "RimEclipseView.h"
|
2015-06-25 06:32:00 -05:00
|
|
|
#include "RimGeoMechCellColors.h"
|
2015-06-17 08:07:20 -05:00
|
|
|
#include "RimGeoMechView.h"
|
2016-08-01 15:27:03 -05:00
|
|
|
#include "RimLegendConfig.h"
|
2015-04-24 08:53:50 -05:00
|
|
|
|
2016-10-18 00:31:02 -05:00
|
|
|
#include "RivFemPickSourceInfo.h"
|
2017-02-17 07:52:56 -06:00
|
|
|
#include "RivPartPriority.h"
|
2015-04-24 08:53:50 -05:00
|
|
|
#include "RivResultToTextureMapper.h"
|
|
|
|
#include "RivScalarMapperUtils.h"
|
|
|
|
#include "RivSourceInfo.h"
|
|
|
|
#include "RivTextureCoordsCreator.h"
|
|
|
|
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfMath.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
2016-10-18 00:31:02 -05:00
|
|
|
#include "cvfRenderState_FF.h"
|
2015-04-24 08:53:50 -05:00
|
|
|
#include "cvfRenderStateBlending.h"
|
|
|
|
#include "cvfRenderStatePolygonOffset.h"
|
|
|
|
#include "cvfShaderProgram.h"
|
|
|
|
#include "cvfShaderProgramGenerator.h"
|
|
|
|
#include "cvfShaderSourceProvider.h"
|
|
|
|
#include "cvfShaderSourceRepository.h"
|
|
|
|
#include "cvfStructGrid.h"
|
2017-02-24 04:07:15 -06:00
|
|
|
#include "cvfTransform.h"
|
2015-04-24 08:53:50 -05:00
|
|
|
#include "cvfUniform.h"
|
|
|
|
|
|
|
|
|
2017-02-24 04:07:15 -06:00
|
|
|
|
2015-04-24 08:53:50 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
RivFemPartPartMgr::RivFemPartPartMgr(const RigFemPart* grid)
|
2015-04-24 08:53:50 -05:00
|
|
|
: m_surfaceGenerator(grid),
|
|
|
|
m_grid(grid),
|
|
|
|
m_opacityLevel(1.0f),
|
|
|
|
m_defaultColor(cvf::Color3::WHITE)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(grid);
|
|
|
|
m_gridIdx = grid->elementPartId();
|
|
|
|
m_cellVisibility = new cvf::UByteArray;
|
|
|
|
m_surfaceFacesTextureCoords = new cvf::Vec2fArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
void RivFemPartPartMgr::setTransform(cvf::Transform* scaleTransform)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
|
|
|
m_scaleTransform = scaleTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
void RivFemPartPartMgr::setCellVisibility(cvf::UByteArray* cellVisibilities)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(m_scaleTransform.notNull());
|
|
|
|
CVF_ASSERT(cellVisibilities);
|
|
|
|
|
|
|
|
m_cellVisibility = cellVisibilities;
|
|
|
|
|
|
|
|
m_surfaceGenerator.setElementVisibility(cellVisibilities);
|
|
|
|
|
|
|
|
generatePartGeometry(m_surfaceGenerator);
|
|
|
|
}
|
|
|
|
|
2015-04-27 03:52:48 -05:00
|
|
|
void RivFemPartPartMgr::generatePartGeometry(RivFemPartGeometryGenerator& geoBuilder)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
|
|
|
bool useBufferObjects = true;
|
|
|
|
// Surface geometry
|
2015-05-13 07:27:39 -05:00
|
|
|
{
|
2018-02-18 11:56:43 -06:00
|
|
|
m_surfaceFaces = nullptr; // To possibly free memory before adding the new stuff
|
2015-05-13 07:27:39 -05:00
|
|
|
|
2015-04-24 08:53:50 -05:00
|
|
|
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("FemPart " + cvf::String(m_gridIdx));
|
2015-06-05 08:17:02 -05:00
|
|
|
part->setId(m_gridIdx); // Use grid index as part ID
|
2015-04-24 08:53:50 -05:00
|
|
|
part->setDrawable(geo.p());
|
|
|
|
part->setTransform(m_scaleTransform.p());
|
|
|
|
|
2015-06-05 08:17:02 -05:00
|
|
|
// Set mapping from triangle face index to element index
|
|
|
|
cvf::ref<RivFemPickSourceInfo> si = new RivFemPickSourceInfo(m_gridIdx, geoBuilder.triangleToElementMapper());
|
|
|
|
part->setSourceInfo(si.p());
|
2015-04-24 08:53:50 -05:00
|
|
|
|
|
|
|
part->updateBoundingBox();
|
|
|
|
|
|
|
|
// Set default effect
|
|
|
|
caf::SurfaceEffectGenerator geometryEffgen(cvf::Color4f(cvf::Color3f::WHITE), caf::PO_1);
|
2015-08-13 07:35:30 -05:00
|
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
|
2015-04-24 08:53:50 -05:00
|
|
|
part->setEffect(geometryOnlyEffect.p());
|
|
|
|
part->setEnableMask(surfaceBit);
|
|
|
|
m_surfaceFaces = part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mesh geometry
|
|
|
|
{
|
2018-02-18 11:56:43 -06:00
|
|
|
m_surfaceGridLines = nullptr; // To possibly free memory before adding the new stuff
|
2015-05-13 07:27:39 -05:00
|
|
|
|
2015-04-24 08:53:50 -05:00
|
|
|
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;
|
2015-12-09 04:20:33 -06:00
|
|
|
part->setName("Grid mesh " + cvf::String(m_gridIdx));
|
2015-04-24 08:53:50 -05:00
|
|
|
part->setDrawable(geoMesh.p());
|
|
|
|
|
|
|
|
part->setTransform(m_scaleTransform.p());
|
|
|
|
part->updateBoundingBox();
|
|
|
|
|
|
|
|
RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
|
|
caf::MeshEffectGenerator effGen(prefs->defaultGridLineColors());
|
2015-08-13 07:35:30 -05:00
|
|
|
eff = effGen.generateCachedEffect();
|
2015-04-24 08:53:50 -05:00
|
|
|
|
2017-02-17 07:52:56 -06:00
|
|
|
part->setPriority(RivPartPriority::PartType::MeshLines);
|
2015-04-24 08:53:50 -05:00
|
|
|
|
|
|
|
part->setEnableMask(meshSurfaceBit);
|
|
|
|
part->setEffect(eff.p());
|
|
|
|
m_surfaceGridLines = part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
void RivFemPartPartMgr::appendPartsToModel(cvf::ModelBasicList* model)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
2018-02-18 11:56:43 -06:00
|
|
|
CVF_ASSERT(model != nullptr);
|
2015-04-24 08:53:50 -05:00
|
|
|
|
|
|
|
if(m_surfaceFaces.notNull() ) model->addPart(m_surfaceFaces.p() );
|
|
|
|
if(m_surfaceGridLines.notNull()) model->addPart(m_surfaceGridLines.p());
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:43:12 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const RivFemPartGeometryGenerator* RivFemPartPartMgr::surfaceGenerator() const
|
|
|
|
{
|
|
|
|
return &m_surfaceGenerator;
|
|
|
|
}
|
|
|
|
|
2015-04-24 08:53:50 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
void RivFemPartPartMgr::updateCellColor(cvf::Color4f color)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
|
|
|
if (m_surfaceFaces.isNull()) return;
|
|
|
|
|
|
|
|
// Set default effect
|
|
|
|
caf::SurfaceEffectGenerator geometryEffgen(color, caf::PO_1);
|
2015-08-13 07:35:30 -05:00
|
|
|
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
|
2015-04-24 08:53:50 -05:00
|
|
|
|
|
|
|
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
|
2017-02-17 07:52:56 -06:00
|
|
|
if (m_surfaceFaces.notNull()) m_surfaceFaces->setPriority(RivPartPriority::PartType::Transparent);
|
2015-04-24 08:53:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_opacityLevel = color.a();
|
|
|
|
m_defaultColor = color.toColor3f();
|
|
|
|
|
|
|
|
// 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());
|
2015-08-13 07:35:30 -05:00
|
|
|
eff = effGen.generateCachedEffect();
|
2015-04-24 08:53:50 -05:00
|
|
|
m_surfaceGridLines->setEffect(eff.p());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-06-25 07:34:20 -05:00
|
|
|
void RivFemPartPartMgr::updateCellResultColor(size_t timeStepIndex, RimGeoMechCellColors* cellResultColors)
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
2015-06-25 07:34:20 -05:00
|
|
|
CVF_ASSERT(cellResultColors);
|
2015-04-24 08:53:50 -05:00
|
|
|
|
|
|
|
cvf::ref<cvf::Color3ubArray> surfaceFacesColorArray;
|
|
|
|
|
|
|
|
// Outer surface
|
2015-05-04 11:16:57 -05:00
|
|
|
if (m_surfaceFaces.notNull())
|
|
|
|
{
|
|
|
|
|
2015-06-25 07:34:20 -05:00
|
|
|
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
|
2015-05-06 09:07:30 -05:00
|
|
|
|
2015-06-25 07:34:20 -05:00
|
|
|
RigGeoMechCaseData* caseData = cellResultColors->ownerCaseData();
|
2015-05-06 09:07:30 -05:00
|
|
|
|
|
|
|
if (!caseData) return;
|
|
|
|
|
2015-06-25 07:34:20 -05:00
|
|
|
RigFemResultAddress resVarAddress = cellResultColors->resultAddress();
|
2015-05-08 03:34:57 -05:00
|
|
|
|
2015-09-28 00:39:57 -05:00
|
|
|
// Do a "Hack" to show elm nodal and not nodal POR results
|
|
|
|
if (resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar") resVarAddress.resultPosType = RIG_ELEMENT_NODAL;
|
|
|
|
|
2015-06-04 09:10:02 -05:00
|
|
|
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues(resVarAddress, m_gridIdx, (int)timeStepIndex);
|
2015-05-06 09:07:30 -05:00
|
|
|
|
2018-02-18 11:56:43 -06:00
|
|
|
const std::vector<size_t>* vxToResultMapping = nullptr;
|
2016-10-19 05:22:13 -05:00
|
|
|
int vxCount = 0;
|
2015-05-06 09:07:30 -05:00
|
|
|
|
2015-09-28 00:39:57 -05:00
|
|
|
if (resVarAddress.resultPosType == RIG_NODAL)
|
2015-05-06 09:07:30 -05:00
|
|
|
{
|
|
|
|
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToNodeIdxMapping());
|
|
|
|
}
|
2015-09-28 00:39:57 -05:00
|
|
|
else if ( resVarAddress.resultPosType == RIG_ELEMENT_NODAL
|
2016-09-06 03:27:30 -05:00
|
|
|
|| resVarAddress.resultPosType == RIG_INTEGRATION_POINT
|
|
|
|
|| resVarAddress.resultPosType == RIG_FORMATION_NAMES)
|
2015-05-06 09:07:30 -05:00
|
|
|
{
|
2015-05-11 16:22:55 -05:00
|
|
|
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToGlobalElmNodeIdx());
|
2015-05-06 09:07:30 -05:00
|
|
|
}
|
2016-10-19 05:22:13 -05:00
|
|
|
else if(resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE)
|
|
|
|
{
|
|
|
|
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToGlobalElmFaceNodeIdx());
|
|
|
|
}
|
2018-01-10 07:14:36 -06:00
|
|
|
else if (resVarAddress.resultPosType == RIG_ELEMENT)
|
|
|
|
{
|
|
|
|
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToGlobalElmIdx());
|
|
|
|
}
|
2018-01-10 03:43:33 -06:00
|
|
|
|
|
|
|
if (!vxToResultMapping) return;
|
|
|
|
|
2016-10-19 05:22:13 -05:00
|
|
|
vxCount = static_cast<int>(vxToResultMapping->size());
|
|
|
|
m_surfaceFacesTextureCoords->resize(vxCount);
|
2015-05-04 11:16:57 -05:00
|
|
|
|
2015-06-09 04:09:11 -05:00
|
|
|
if (resultValues.size() == 0)
|
2015-05-04 11:16:57 -05:00
|
|
|
{
|
2015-06-09 04:09:11 -05:00
|
|
|
m_surfaceFacesTextureCoords->setAll(cvf::Vec2f(0.0, 1.0f));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cvf::Vec2f* rawPtr = m_surfaceFacesTextureCoords->ptr();
|
2015-05-04 11:16:57 -05:00
|
|
|
|
2015-06-09 04:09:11 -05:00
|
|
|
#pragma omp parallel for schedule(dynamic)
|
2015-06-26 05:12:40 -05:00
|
|
|
for (int quadStartIdx = 0; quadStartIdx < vxCount; quadStartIdx += 4)
|
2015-05-04 11:16:57 -05:00
|
|
|
{
|
2016-10-19 05:22:13 -05:00
|
|
|
float resultValue1 = resultValues[(*vxToResultMapping)[quadStartIdx + 0]];
|
2015-06-26 05:12:40 -05:00
|
|
|
float resultValue2 = resultValues[(*vxToResultMapping)[quadStartIdx + 1]];
|
|
|
|
float resultValue3 = resultValues[(*vxToResultMapping)[quadStartIdx + 2]];
|
|
|
|
float resultValue4 = resultValues[(*vxToResultMapping)[quadStartIdx + 3]];
|
|
|
|
|
|
|
|
if ( resultValue1 == HUGE_VAL || resultValue1 != resultValue1 // a != a is true for NAN's
|
|
|
|
|| resultValue2 == HUGE_VAL || resultValue2 != resultValue2
|
|
|
|
|| resultValue3 == HUGE_VAL || resultValue3 != resultValue3
|
|
|
|
|| resultValue4 == HUGE_VAL || resultValue4 != resultValue4)
|
2015-06-09 04:09:11 -05:00
|
|
|
{
|
2015-06-26 05:12:40 -05:00
|
|
|
rawPtr[quadStartIdx][1] = 1.0f;
|
|
|
|
rawPtr[quadStartIdx + 1][1] = 1.0f;
|
|
|
|
rawPtr[quadStartIdx + 2][1] = 1.0f;
|
|
|
|
rawPtr[quadStartIdx + 3][1] = 1.0f;
|
2015-06-09 04:09:11 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-26 05:12:40 -05:00
|
|
|
rawPtr[quadStartIdx] = mapper->mapToTextureCoord(resultValue1);
|
|
|
|
rawPtr[quadStartIdx + 1] = mapper->mapToTextureCoord(resultValue2);
|
|
|
|
rawPtr[quadStartIdx + 2] = mapper->mapToTextureCoord(resultValue3);
|
|
|
|
rawPtr[quadStartIdx + 3] = mapper->mapToTextureCoord(resultValue4);
|
2015-06-09 04:09:11 -05:00
|
|
|
}
|
2015-05-04 11:16:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 11:56:43 -06:00
|
|
|
Rim3dView* view = nullptr;
|
2016-09-21 06:59:41 -05:00
|
|
|
cellResultColors->firstAncestorOrThisOfType(view);
|
2015-10-26 04:14:45 -05:00
|
|
|
CVF_ASSERT(view);
|
2015-09-01 10:11:23 -05:00
|
|
|
|
2015-11-20 08:54:22 -06:00
|
|
|
RivScalarMapperUtils::applyTextureResultsToPart(m_surfaceFaces.p(),
|
|
|
|
m_surfaceFacesTextureCoords.p(),
|
|
|
|
mapper,
|
|
|
|
m_opacityLevel,
|
|
|
|
caf::FC_NONE,
|
|
|
|
view->isLightingDisabled());
|
2015-05-04 11:16:57 -05:00
|
|
|
}
|
2015-04-24 08:53:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:52:48 -05:00
|
|
|
RivFemPartPartMgr::~RivFemPartPartMgr()
|
2015-04-24 08:53:50 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|