diff --git a/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.cpp b/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.cpp index c7e218a58c..3742dc14c0 100644 --- a/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.cpp @@ -129,7 +129,8 @@ void RivTensorResultPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicLi cvf::Vec3f center = nodes.coordinates.at(quadVerticesToNodeIdxMapping[quadVertex]) + nodes.coordinates.at(quadVerticesToNodeIdxMapping[quadVertex + 2]); - cvf::Vec3d displayCoord = m_rimReservoirView->displayCoordTransform()->transformToDisplayCoord(cvf::Vec3d(center/2)); + cvf::Vec3d displayCoord = + m_rimReservoirView->displayCoordTransform()->transformToDisplayCoord(cvf::Vec3d(center / 2)); cvf::Vec3f faceNormal = calculateFaceNormal(nodes, quadVerticesToNodeIdxMapping, quadVertex); @@ -293,9 +294,6 @@ cvf::ref RivTensorResultPartMgr::createPart(const std::vector vertices; vertices.reserve(tensorVisualizations.size() * 5); - cvf::ref colors = new cvf::Color3ubArray(); - colors->reserve(tensorVisualizations.size() * 5); - uint counter = 0; for (TensorVisualization tensor : tensorVisualizations) { @@ -321,41 +319,38 @@ cvf::ref RivTensorResultPartMgr::createPart(const std::vector drawable = new cvf::DrawableGeo(); - drawable->setColorArray(colors.p()); - indexedUInt->setIndices(indexArray.p()); drawable->addPrimitiveSet(indexedUInt.p()); cvf::ref vertexArray = new cvf::Vec3fArray(vertices); drawable->setVertexArray(vertexArray.p()); - // Setup a scalar mapper - cvf::ref scalarMapper = new cvf::ScalarMapperDiscreteLinear; - { - cvf::Color3ubArray legendColors; - legendColors.resize(3); - if (m_rimReservoirView->tensorResults()->vectorColors() == RimTensorResults::MAGENTA_BROWN_BLACK) - { - legendColors[0] = cvf::Color3::MAGENTA; - legendColors[1] = cvf::Color3::BROWN; - legendColors[2] = cvf::Color3::BLACK; - } - else if (m_rimReservoirView->tensorResults()->vectorColors() == RimTensorResults::WHITE_GRAY_BLACK) - { - legendColors[0] = cvf::Color3::WHITE; - legendColors[1] = cvf::Color3::GRAY; - legendColors[2] = cvf::Color3::BLACK; - } - else - { - legendColors[0] = cvf::Color3::BLACK; - legendColors[1] = cvf::Color3::BLACK; - legendColors[2] = cvf::Color3::BLACK; - } + cvf::ref lineTexCoords = const_cast(drawable->textureCoordArray()); - scalarMapper->setColors(legendColors); + if (lineTexCoords.isNull()) + { + lineTexCoords = new cvf::Vec2fArray; + } + cvf::ref scalarMapper = new cvf::ScalarMapperDiscreteLinear; + + auto vectorColors = m_rimReservoirView->tensorResults()->vectorColors(); + if (vectorColors == RimTensorResults::MAGENTA_BROWN_BLACK || vectorColors == RimTensorResults::WHITE_GRAY_BLACK) + { + createOneColorPerPrincipalScalarMapper(m_rimReservoirView->tensorResults()->vectorColors(), scalarMapper.p()); + createOneColorPerPrincipalTextureCoords(lineTexCoords.p(), tensorVisualizations, scalarMapper.p()); + } + else + { + // THIS WILL BE REPLACED BY REAL RESULT COLOR MAPPER + cvf::Color3ubArray arrowColors; + arrowColors.resize(3); + arrowColors[0] = cvf::Color3::BLACK; + arrowColors[1] = cvf::Color3::BLACK; + arrowColors[2] = cvf::Color3::BLACK; + scalarMapper->setColors(arrowColors); scalarMapper->setRange(0.5, 3.5); scalarMapper->setLevelCount(3, true); + createOneColorPerPrincipalTextureCoords(lineTexCoords.p(), tensorVisualizations, scalarMapper.p()); } caf::ScalarMapperEffectGenerator surfEffGen(scalarMapper.p(), caf::PO_1); @@ -368,16 +363,6 @@ cvf::ref RivTensorResultPartMgr::createPart(const std::vector scalarMapperMeshEffect = meshEffGen.generateUnCachedEffect(); - cvf::ref lineTexCoords = const_cast(drawable->textureCoordArray()); - - if (lineTexCoords.isNull()) - { - lineTexCoords = new cvf::Vec2fArray; - } - - // Calculate new texture coordinates - createTextureCoords(lineTexCoords.p(), tensorVisualizations, scalarMapper.p()); - drawable->setTextureCoordArray(lineTexCoords.p()); cvf::ref part = new cvf::Part; @@ -387,6 +372,57 @@ cvf::ref RivTensorResultPartMgr::createPart(const std::vectorsetColors(arrowColors); + scalarMapper->setRange(0.5, 3.5); + scalarMapper->setLevelCount(3, true); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivTensorResultPartMgr::createOneColorPerPrincipalTextureCoords(cvf::Vec2fArray* textureCoords, + const std::vector& tensorVisualizations, + const cvf::ScalarMapper* mapper) +{ + CVF_ASSERT(textureCoords); + CVF_ASSERT(mapper); + + size_t vertexCount = tensorVisualizations.size() * 5; + if (textureCoords->size() != vertexCount) textureCoords->reserve(vertexCount); + + for (auto tensor : tensorVisualizations) + { + for (size_t vxIdx = 0; vxIdx < 5; ++vxIdx) + { + cvf::Vec2f texCoord = mapper->mapToTextureCoord(tensor.princial); + textureCoords->add(texCoord); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -469,7 +505,7 @@ bool RivTensorResultPartMgr::isDrawable(cvf::Vec3f resultVector, bool showPrinci //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::array RivTensorResultPartMgr::createArrowVertices(const TensorVisualization &tensorVisualization) const +std::array RivTensorResultPartMgr::createArrowVertices(const TensorVisualization& tensorVisualization) const { std::array vertices; @@ -502,26 +538,3 @@ std::array RivTensorResultPartMgr::createArrowVertices(const Tens return vertices; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivTensorResultPartMgr::createTextureCoords(cvf::Vec2fArray* textureCoords, - const std::vector& tensorVisualizations, - const cvf::ScalarMapper* mapper) const -{ - CVF_ASSERT(textureCoords); - CVF_ASSERT(mapper); - - size_t vertexCount = tensorVisualizations.size() * 5; - if (textureCoords->size() != vertexCount) textureCoords->reserve(vertexCount); - - for (auto tensor : tensorVisualizations) - { - for (size_t vxIdx = 0; vxIdx < 5; ++vxIdx) - { - cvf::Vec2f texCoord = mapper->mapToTextureCoord(tensor.princial); - textureCoords->add(texCoord); - } - } -} diff --git a/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.h b/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.h index 999dd79777..f1ab24d75e 100644 --- a/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivTensorResultPartMgr.h @@ -27,14 +27,17 @@ #include "cafPdmPointer.h" #include "cafTensor3.h" +#include "RimTensorResults.h" + #include #include namespace cvf { -class Part; class ModelBasicList; +class Part; class ScalarMapper; +class ScalarMapperDiscreteLinear; } // namespace cvf class RigFemResultAddress; @@ -82,15 +85,17 @@ private: cvf::ref createPart(const std::vector& tensorVisualizations) const; + static void createOneColorPerPrincipalScalarMapper(const RimTensorResults::TensorColors& colorSet, cvf::ScalarMapperDiscreteLinear* scalarMapper); + static void createOneColorPerPrincipalTextureCoords(cvf::Vec2fArray* textureCoords, + const std::vector& tensorVisualization, + const cvf::ScalarMapper* mapper); + static bool isTensorAddress(RigFemResultAddress address); static bool isValid(cvf::Vec3f resultVector); static bool isPressure(float principalValue); bool isDrawable(cvf::Vec3f resultVector, bool showPrincipal) const; std::array createArrowVertices(const TensorVisualization &tensorVisualization) const; - void createTextureCoords(cvf::Vec2fArray* textureCoords, - const std::vector& tensorVisualization, - const cvf::ScalarMapper* mapper) const; private: caf::PdmPointer m_rimReservoirView;