mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
2344 Tensor vectors: Code cleanup
This commit is contained in:
@@ -56,6 +56,8 @@
|
|||||||
#include "cvfShaderProgram.h"
|
#include "cvfShaderProgram.h"
|
||||||
#include "cvfStructGridGeometryGenerator.h"
|
#include "cvfStructGridGeometryGenerator.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -85,36 +87,17 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicLi
|
|||||||
|
|
||||||
std::vector<TensorVisualization> tensorVisualizations;
|
std::vector<TensorVisualization> tensorVisualizations;
|
||||||
|
|
||||||
|
RimTensorResults::TensorColors tensorColor = m_rimReservoirView->tensorResults()->vectorColors();
|
||||||
|
cvf::Color3f color1, color2, color3;
|
||||||
|
|
||||||
|
assignColorVectors(tensorColor, color1, color2, color3);
|
||||||
|
|
||||||
RigFemResultAddress address = m_rimReservoirView->tensorResults()->selectedTensorResult();
|
RigFemResultAddress address = m_rimReservoirView->tensorResults()->selectedTensorResult();
|
||||||
if (!isTensorAddress(address)) return;
|
if (!isTensorAddress(address)) return;
|
||||||
|
|
||||||
RigFemPartResultsCollection* resultCollection = m_rimReservoirView->geoMechCase()->geoMechData()->femPartResults();
|
RigFemPartResultsCollection* resultCollection = m_rimReservoirView->geoMechCase()->geoMechData()->femPartResults();
|
||||||
if (!resultCollection) return;
|
if (!resultCollection) return;
|
||||||
|
|
||||||
RimTensorResults::TensorColors tensorColor = m_rimReservoirView->tensorResults()->vectorColors();
|
|
||||||
cvf::Color3f color1;
|
|
||||||
cvf::Color3f color2;
|
|
||||||
cvf::Color3f color3;
|
|
||||||
|
|
||||||
if (tensorColor == RimTensorResults::WHITE_GRAY_BLACK)
|
|
||||||
{
|
|
||||||
color1 = cvf::Color3f(cvf::Color3::WHITE);
|
|
||||||
color2 = cvf::Color3f(cvf::Color3::GRAY);
|
|
||||||
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
|
||||||
}
|
|
||||||
else if (tensorColor == RimTensorResults::MAGENTA_BROWN_BLACK)
|
|
||||||
{
|
|
||||||
color1 = cvf::Color3f(cvf::Color3::MAGENTA);
|
|
||||||
color2 = cvf::Color3f(cvf::Color3::BROWN);
|
|
||||||
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
color1 = cvf::Color3f(cvf::Color3::BLACK);
|
|
||||||
color2 = cvf::Color3f(cvf::Color3::BLACK);
|
|
||||||
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int partIdx = 0; partIdx < femParts->partCount(); partIdx++)
|
for (int partIdx = 0; partIdx < femParts->partCount(); partIdx++)
|
||||||
{
|
{
|
||||||
std::vector<caf::Ten3f> tensors = resultCollection->tensors(address, partIdx, (int)frameIndex);
|
std::vector<caf::Ten3f> tensors = resultCollection->tensors(address, partIdx, (int)frameIndex);
|
||||||
@@ -161,18 +144,17 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicLi
|
|||||||
elmPrincipalDirections[nIdx][2] = principalDirs[2];
|
elmPrincipalDirections[nIdx][2] = principalDirs[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<RivGeoMechPartMgrCache::Key> partKeys =
|
||||||
|
m_rimReservoirView->vizLogic()->keysToVisiblePartMgrs((int)frameIndex);
|
||||||
|
|
||||||
RigFemPartNodes nodes = part->nodes();
|
RigFemPartNodes nodes = part->nodes();
|
||||||
|
|
||||||
double min;
|
double min, max;
|
||||||
double max;
|
|
||||||
resultCollection->minMaxScalarValuesOverAllTensorComponents(address, (int)frameIndex, &min, &max);
|
resultCollection->minMaxScalarValuesOverAllTensorComponents(address, (int)frameIndex, &min, &max);
|
||||||
|
|
||||||
if (max == 0) max = 1;
|
if (max == 0) max = 1;
|
||||||
float arrowResultScaling = 0.5 * m_rimReservoirView->tensorResults()->sizeScale() * part->characteristicElementSize() / cvf::Math::abs(max);
|
|
||||||
float arrowConstantScaling = 0.5 * m_rimReservoirView->tensorResults()->sizeScale() * part->characteristicElementSize();
|
float arrowConstantScaling = 0.5 * m_rimReservoirView->tensorResults()->sizeScale() * part->characteristicElementSize();
|
||||||
|
float arrowResultScaling = arrowConstantScaling / cvf::Math::abs(max);
|
||||||
std::vector<RivGeoMechPartMgrCache::Key> partKeys =
|
|
||||||
m_rimReservoirView->vizLogic()->keysToVisiblePartMgrs((int)frameIndex);
|
|
||||||
|
|
||||||
cvf::ref<RivGeoMechPartMgrCache> partMgrCache = m_rimReservoirView->vizLogic()->partMgrCache();
|
cvf::ref<RivGeoMechPartMgrCache> partMgrCache = m_rimReservoirView->vizLogic()->partMgrCache();
|
||||||
|
|
||||||
@@ -197,9 +179,7 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicLi
|
|||||||
|
|
||||||
size_t elmIdx = quadVerticesToElmIdx[quadIdx];
|
size_t elmIdx = quadVerticesToElmIdx[quadIdx];
|
||||||
|
|
||||||
cvf::Vec3f result1;
|
cvf::Vec3f result1, result2, result3;
|
||||||
cvf::Vec3f result2;
|
|
||||||
cvf::Vec3f result3;
|
|
||||||
|
|
||||||
if (m_rimReservoirView->tensorResults()->scaleMethod() == RimTensorResults::RESULT)
|
if (m_rimReservoirView->tensorResults()->scaleMethod() == RimTensorResults::RESULT)
|
||||||
{
|
{
|
||||||
@@ -214,47 +194,21 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicLi
|
|||||||
result3.set(elmPrincipalDirections[elmIdx][2] * arrowConstantScaling);
|
result3.set(elmPrincipalDirections[elmIdx][2] * arrowConstantScaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValid(result1) && m_rimReservoirView->tensorResults()->showPrincipal1())
|
if (isDrawable(result1, m_rimReservoirView->tensorResults()->showPrincipal1()))
|
||||||
{
|
{
|
||||||
if (result1.length() > m_rimReservoirView->tensorResults()->threshold())
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result1, color1, isPressure(elmPrincipals[0][elmIdx])));
|
||||||
{
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result1, color1, isPressure(elmPrincipals[0][elmIdx])));
|
||||||
bool isPressure = true;
|
|
||||||
if (elmPrincipals[0][elmIdx] < 0)
|
|
||||||
{
|
|
||||||
isPressure = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result1, color1, isPressure));
|
if (isDrawable(result2, m_rimReservoirView->tensorResults()->showPrincipal2()))
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result1, color1, isPressure));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isValid(result2) && m_rimReservoirView->tensorResults()->showPrincipal2())
|
|
||||||
{
|
{
|
||||||
if (result2.length() > m_rimReservoirView->tensorResults()->threshold())
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result2, color2, isPressure(elmPrincipals[1][elmIdx])));
|
||||||
{
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result2, color2, isPressure(elmPrincipals[1][elmIdx])));
|
||||||
bool isPressure = true;
|
|
||||||
if (elmPrincipals[1][elmIdx] < 0)
|
|
||||||
{
|
|
||||||
isPressure = false;
|
|
||||||
}
|
}
|
||||||
|
if (isDrawable(result3, m_rimReservoirView->tensorResults()->showPrincipal3()))
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result2, color2, isPressure));
|
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result2, color2, isPressure));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isValid(result3) && m_rimReservoirView->tensorResults()->showPrincipal3())
|
|
||||||
{
|
{
|
||||||
if (result3.length() > m_rimReservoirView->tensorResults()->threshold())
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result3, color3, isPressure(elmPrincipals[2][elmIdx])));
|
||||||
{
|
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result3, color3, isPressure(elmPrincipals[2][elmIdx])));
|
||||||
bool isPressure = true;
|
|
||||||
if (elmPrincipals[2][elmIdx] < 0)
|
|
||||||
{
|
|
||||||
isPressure = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), result3, color3, isPressure));
|
|
||||||
tensorVisualizations.push_back(TensorVisualization(cvf::Vec3f(displayCoord), -result3, color3, isPressure));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,6 +296,31 @@ cvf::ref<cvf::Part> RivTensorResultPartMgr::createPart(std::vector<TensorVisuali
|
|||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RivTensorResultPartMgr::assignColorVectors(RimTensorResults::TensorColors tensorColor, cvf::Color3f color1, cvf::Color3f color2, cvf::Color3f color3)
|
||||||
|
{
|
||||||
|
if (tensorColor == RimTensorResults::WHITE_GRAY_BLACK)
|
||||||
|
{
|
||||||
|
color1 = cvf::Color3f(cvf::Color3::WHITE);
|
||||||
|
color2 = cvf::Color3f(cvf::Color3::GRAY);
|
||||||
|
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
||||||
|
}
|
||||||
|
else if (tensorColor == RimTensorResults::MAGENTA_BROWN_BLACK)
|
||||||
|
{
|
||||||
|
color1 = cvf::Color3f(cvf::Color3::MAGENTA);
|
||||||
|
color2 = cvf::Color3f(cvf::Color3::BROWN);
|
||||||
|
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color1 = cvf::Color3f(cvf::Color3::BLACK);
|
||||||
|
color2 = cvf::Color3f(cvf::Color3::BLACK);
|
||||||
|
color3 = cvf::Color3f(cvf::Color3::BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -366,6 +345,15 @@ bool RivTensorResultPartMgr::isTensorAddress(RigFemResultAddress address)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RivTensorResultPartMgr::isValid(cvf::Vec3f resultVector)
|
bool RivTensorResultPartMgr::isValid(cvf::Vec3f resultVector)
|
||||||
{
|
{
|
||||||
|
//nan
|
||||||
|
if ( resultVector.x() != resultVector.x()
|
||||||
|
|| resultVector.y() != resultVector.y()
|
||||||
|
|| resultVector.z() != resultVector.z())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//inf
|
||||||
if ( resultVector.x() == HUGE_VAL
|
if ( resultVector.x() == HUGE_VAL
|
||||||
|| resultVector.y() == HUGE_VAL
|
|| resultVector.y() == HUGE_VAL
|
||||||
|| resultVector.z() == HUGE_VAL
|
|| resultVector.z() == HUGE_VAL
|
||||||
@@ -376,7 +364,43 @@ bool RivTensorResultPartMgr::isValid(cvf::Vec3f resultVector)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultVector.length() == 0)
|
//zero
|
||||||
|
if (resultVector == cvf::Vec3f::ZERO)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RivTensorResultPartMgr::isPressure(float principalValue)
|
||||||
|
{
|
||||||
|
if (principalValue < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RivTensorResultPartMgr::isDrawable(cvf::Vec3f resultVector, bool showPrincipal) const
|
||||||
|
{
|
||||||
|
if (!showPrincipal)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValid(resultVector))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultVector.length() <= m_rimReservoirView->tensorResults()->threshold())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "cafPdmPointer.h"
|
#include "cafPdmPointer.h"
|
||||||
|
|
||||||
|
#include "RimTensorResults.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -60,8 +62,11 @@ private:
|
|||||||
private:
|
private:
|
||||||
cvf::ref<cvf::Part> createPart(std::vector<TensorVisualization>& tensorVisualizations) const;
|
cvf::ref<cvf::Part> createPart(std::vector<TensorVisualization>& tensorVisualizations) const;
|
||||||
|
|
||||||
|
static void assignColorVectors(RimTensorResults::TensorColors tensorColor, cvf::Color3f color1, cvf::Color3f color2, cvf::Color3f color3);
|
||||||
static bool isTensorAddress(RigFemResultAddress address);
|
static bool isTensorAddress(RigFemResultAddress address);
|
||||||
static bool isValid(cvf::Vec3f resultVector);
|
static bool isValid(cvf::Vec3f resultVector);
|
||||||
|
static bool isPressure(float principalValue);
|
||||||
|
bool isDrawable(cvf::Vec3f resultVector, bool showPrincipal) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmPointer<RimGeoMechView> m_rimReservoirView;
|
caf::PdmPointer<RimGeoMechView> m_rimReservoirView;
|
||||||
|
|||||||
Reference in New Issue
Block a user