From 41836a493007426f1d423071e5c1d262233dbb68 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 14 Feb 2017 10:29:25 +0100 Subject: [PATCH] #1138 Added test code for texture scalar mapping --- .../RivWellFracturePartMgr.cpp | 76 ++++++++++++++++++- .../RivWellFracturePartMgr.h | 1 + 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.cpp index 4077c56e24..9f06d24037 100644 --- a/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.cpp @@ -24,12 +24,13 @@ #include "cafEffectGenerator.h" +#include "cafDisplayCoordTransform.h" #include "cvfDrawableGeo.h" #include "cvfModelBasicList.h" #include "cvfPart.h" #include "cvfPrimitiveSet.h" #include "cvfPrimitiveSetIndexedUInt.h" -#include "cafDisplayCoordTransform.h" +#include "cvfScalarMapperContinuousLinear.h" //-------------------------------------------------------------------------------------------------- @@ -88,6 +89,74 @@ void RivWellFracturePartMgr::updatePartGeometry(caf::DisplayCoordTransform* disp } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivWellFracturePartMgr::updatePartGeometryTexture(caf::DisplayCoordTransform* displayCoordTransform) +{ + if (m_part.notNull()) return; + if (!displayCoordTransform) return; + + if (m_rimFracture) + { + if (!m_rimFracture->hasValidGeometry()) + { + m_rimFracture->computeGeometry(); + } + + if (!m_rimFracture->hasValidGeometry()) return; + + const std::vector& nodeCoords = m_rimFracture->nodeCoords(); + const std::vector& triangleIndices = m_rimFracture->triangleIndices(); + std::vector displayCoords; + + for (size_t i = 0; i < nodeCoords.size(); i++) + { + cvf::Vec3d nodeCoordsDouble = static_cast(nodeCoords[i]); + cvf::Vec3d displayCoordsDouble = displayCoordTransform->transformToDisplayCoord(nodeCoordsDouble); + displayCoords.push_back(static_cast(displayCoordsDouble)); + } + + cvf::ref geo = createGeo(triangleIndices, displayCoords); + + m_part = new cvf::Part; + m_part->setDrawable(geo.p()); + + + cvf::ref scalarMapper = new cvf::ScalarMapperContinuousLinear; + { + cvf::Color3ubArray legendColors; + legendColors.resize(4); + legendColors[0] = cvf::Color3::GRAY; + legendColors[1] = cvf::Color3::GREEN; + legendColors[2] = cvf::Color3::BLUE; + legendColors[3] = cvf::Color3::RED; + scalarMapper->setColors(legendColors); + scalarMapper->setRange(0.0, 4.0); + scalarMapper->setLevelCount(4, true); + } + + cvf::ref textureCoords = new cvf::Vec2fArray; + textureCoords->resize(nodeCoords.size()); + for (size_t i = 0; i < textureCoords->size(); i++) + { + //double scalarValue = i % 4; + double scalarValue = 0; + + cvf::Vec2f texCoord = scalarMapper->mapToTextureCoord(scalarValue); + + textureCoords->set(i, texCoord); + } + + geo->setTextureCoordArray(textureCoords.p()); + + caf::ScalarMapperEffectGenerator nncEffgen(scalarMapper.p(), caf::PO_NEG_LARGE); + cvf::ref eff = nncEffgen.generateUnCachedEffect(); + + m_part->setEffect(eff.p()); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -96,6 +165,7 @@ void RivWellFracturePartMgr::appendGeometryPartsToModel(cvf::ModelBasicList* mod if (m_part.isNull()) { updatePartGeometry(displayCoordTransform); + //updatePartGeometryTexture(displayCoordTransform); } if (m_part.notNull()) @@ -115,11 +185,11 @@ void RivWellFracturePartMgr::clearGeometryCache() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RivWellFracturePartMgr::createGeo(const std::vector& polygonIndices, const std::vector& nodeCoords) +cvf::ref RivWellFracturePartMgr::createGeo(const std::vector& triangleIndices, const std::vector& nodeCoords) { cvf::ref geo = new cvf::DrawableGeo; - cvf::ref indices = new cvf::UIntArray(polygonIndices); + cvf::ref indices = new cvf::UIntArray(triangleIndices); cvf::ref vertices = new cvf::Vec3fArray(nodeCoords); geo->setVertexArray(vertices.p()); diff --git a/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.h b/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.h index 9d86702a1a..34d29cc1ff 100644 --- a/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.h +++ b/ApplicationCode/ModelVisualization/RivWellFracturePartMgr.h @@ -56,6 +56,7 @@ public: private: void updatePartGeometry(caf::DisplayCoordTransform* displayCoordTransform); + void updatePartGeometryTexture(caf::DisplayCoordTransform* displayCoordTransform); static cvf::ref createGeo(const std::vector& triangleIndices, const std::vector& nodeCoords);