diff --git a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake index fc4c22bbe0..5079ead6ff 100644 --- a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake +++ b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake @@ -28,6 +28,7 @@ ${CEE_CURRENT_LIST_DIR}RivTextureCoordsCreator.h ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.h ${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.h ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.h +${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -52,6 +53,7 @@ ${CEE_CURRENT_LIST_DIR}RivTextureCoordsCreator.cpp ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapper.cpp ${CEE_CURRENT_LIST_DIR}RivTernaryTextureCoordsCreator.cpp ${CEE_CURRENT_LIST_DIR}RivTernaryScalarMapperEffectGenerator.cpp +${CEE_CURRENT_LIST_DIR}RivScalarMapperUtils.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ModelVisualization/RivScalarMapperUtils.cpp b/ApplicationCode/ModelVisualization/RivScalarMapperUtils.cpp new file mode 100644 index 0000000000..e9620f6536 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivScalarMapperUtils.cpp @@ -0,0 +1,86 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RivScalarMapperUtils.h" + +#include "RivTernaryScalarMapperEffectGenerator.h" +#include "RivTernaryScalarMapper.h" + +#include "cafEffectGenerator.h" + +#include "cvfDrawableGeo.h" +#include "cvfPart.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivScalarMapperUtils::applyTextureResultsToPart(cvf::Part* part, cvf::Vec2fArray* textureCoords, const cvf::ScalarMapper* mapper, float opacityLevel) +{ + CVF_ASSERT(part && textureCoords && mapper); + + cvf::DrawableGeo* dg = dynamic_cast(part->drawable()); + if (dg) dg->setTextureCoordArray(textureCoords); + + cvf::ref scalarEffect = RivScalarMapperUtils::createScalarMapperEffect(mapper, opacityLevel); + part->setEffect(scalarEffect.p()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivScalarMapperUtils::applyTernaryTextureResultsToPart(cvf::Part* part, cvf::Vec2fArray* textureCoords, const RivTernaryScalarMapper* mapper, float opacityLevel) +{ + CVF_ASSERT(part && textureCoords && mapper); + + cvf::DrawableGeo* dg = dynamic_cast(part->drawable()); + if (dg) dg->setTextureCoordArray(textureCoords); + + cvf::ref scalarEffect = RivScalarMapperUtils::createTernaryScalarMapperEffect(mapper, opacityLevel); + part->setEffect(scalarEffect.p()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RivScalarMapperUtils::createScalarMapperEffect(const cvf::ScalarMapper* mapper, float opacityLevel) +{ + CVF_ASSERT(mapper); + + caf::PolygonOffset polygonOffset = caf::PO_1; + caf::ScalarMapperEffectGenerator scalarEffgen(mapper, polygonOffset); + scalarEffgen.setOpacityLevel(opacityLevel); + cvf::ref scalarEffect = scalarEffgen.generateEffect(); + + return scalarEffect; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RivScalarMapperUtils::createTernaryScalarMapperEffect(const RivTernaryScalarMapper* mapper, float opacityLevel) +{ + CVF_ASSERT(mapper); + + caf::PolygonOffset polygonOffset = caf::PO_1; + RivTernaryScalarMapperEffectGenerator scalarEffgen(mapper, polygonOffset); + scalarEffgen.setOpacityLevel(opacityLevel); + cvf::ref scalarEffect = scalarEffgen.generateEffect(); + + return scalarEffect; +} diff --git a/ApplicationCode/ModelVisualization/RivScalarMapperUtils.h b/ApplicationCode/ModelVisualization/RivScalarMapperUtils.h new file mode 100644 index 0000000000..de92c033b0 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivScalarMapperUtils.h @@ -0,0 +1,45 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfArray.h" + +namespace cvf +{ + class ScalarMapper; + class Part; + class Effect; +} + +class RivTernaryScalarMapper; + +//================================================================================================== +/// +//================================================================================================== +class RivScalarMapperUtils +{ +public: + static void applyTextureResultsToPart(cvf::Part* part, cvf::Vec2fArray* textureCoords, const cvf::ScalarMapper* mapper, float opacityLevel); + static void applyTernaryTextureResultsToPart(cvf::Part* part, cvf::Vec2fArray* textureCoords, const RivTernaryScalarMapper* mapper, float opacityLevel); + +private: + static cvf::ref createScalarMapperEffect(const cvf::ScalarMapper* mapper, float opacityLevel); + static cvf::ref createTernaryScalarMapperEffect(const RivTernaryScalarMapper* mapper, float opacityLevel); +}; +