From 22f054c6b9936b6ab96a11c5a17e5e21ed00cc92 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 21 Dec 2018 09:06:01 +0100 Subject: [PATCH] #3919 Apply contrast colours to contour lines as well. --- .../RivContourMapProjectionPartMgr.cpp | 63 ++++++++++++------- .../RivContourMapProjectionPartMgr.h | 8 +-- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp index 2ecf80b497..f316d4e66d 100644 --- a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.cpp @@ -35,6 +35,8 @@ RivContourMapProjectionPartMgr::RivContourMapProjectionPartMgr(RimContourMapProj //-------------------------------------------------------------------------------------------------- void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList* model, const caf::DisplayCoordTransform* displayCoordTransform) const { + cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); + cvf::ref drawable = createProjectionMapDrawable(displayCoordTransform); if (drawable.notNull() && drawable->boundingBox().isValid()) { @@ -42,7 +44,6 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList part->setDrawable(drawable.p()); cvf::ref textureCoords = createTextureCoords(); - cvf::ScalarMapper* mapper = m_contourMapProjection->legendConfig()->scalarMapper(); RivScalarMapperUtils::applyTextureResultsToPart(part.p(), textureCoords.p(), mapper, 1.0f, caf::FC_NONE, true, m_parentContourMap->backgroundColor()); part->setSourceInfo(new RivObjectSourceInfo(m_contourMapProjection.p())); @@ -52,22 +53,34 @@ void RivContourMapProjectionPartMgr::appendProjectionToModel(cvf::ModelBasicList if (m_contourMapProjection->showContourLines()) { - std::vector> contourDrawables = createContourPolygons(displayCoordTransform); - for (cvf::ref contourDrawable : contourDrawables) + std::vector tickValues; + mapper->majorTickValues(&tickValues); + + std::vector>> contourDrawablesForAllLevels = createContourPolygons(displayCoordTransform); + for (size_t i = 0; i < contourDrawablesForAllLevels.size(); ++i) { - if (contourDrawable.notNull() && contourDrawable->boundingBox().isValid()) + std::vector> contourDrawables = contourDrawablesForAllLevels[i]; + + cvf::Color3f backgroundColor(mapper->mapToColor(tickValues[i])); + cvf::Color3f lineColor = RiaColorTools::constrastColor(backgroundColor); + + for (cvf::ref contourDrawable : contourDrawables) { - caf::MeshEffectGenerator meshEffectGen(cvf::Color3::BLACK); - meshEffectGen.setLineWidth(1.0f); - meshEffectGen.createAndConfigurePolygonOffsetRenderState(caf::PO_1); - cvf::ref effect = meshEffectGen.generateCachedEffect(); + if (contourDrawable.notNull() && contourDrawable->boundingBox().isValid()) + { + caf::MeshEffectGenerator meshEffectGen(lineColor); + meshEffectGen.setLineWidth(1.0f); + meshEffectGen.createAndConfigurePolygonOffsetRenderState(caf::PO_1); - cvf::ref part = new cvf::Part; - part->setDrawable(contourDrawable.p()); - part->setEffect(effect.p()); - part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p())); + cvf::ref effect = meshEffectGen.generateCachedEffect(); - model->addPart(part.p()); + cvf::ref part = new cvf::Part; + part->setDrawable(contourDrawable.p()); + part->setEffect(effect.p()); + part->setSourceInfo(new RivMeshLinesSourceInfo(m_contourMapProjection.p())); + + model->addPart(part.p()); + } } } } @@ -155,7 +168,7 @@ cvf::ref RivContourMapProjectionPartMgr::createTextureCoords() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RivContourMapProjectionPartMgr::createTextLabel(const cvf::Color3f& backgroundColor) +cvf::ref RivContourMapProjectionPartMgr::createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor) { auto font = RiaFontCache::getFont(RiaFontCache::FONT_SIZE_8); @@ -167,7 +180,6 @@ cvf::ref RivContourMapProjectionPartMgr::createTextLabel(cons labelDrawable->setDrawBackground(true); labelDrawable->setBackgroundColor(backgroundColor); labelDrawable->setVerticalAlignment(cvf::TextDrawer::BASELINE); - cvf::Color3f textColor = RiaColorTools::constrastColor(backgroundColor); labelDrawable->setTextColor(textColor); return labelDrawable; @@ -206,7 +218,7 @@ cvf::ref RivContourMapProjectionPartMgr::createProjectionMapDr //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const +std::vector>> RivContourMapProjectionPartMgr::createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const { m_contourMapProjection->generateContourPolygons(); const std::vector& contourPolygons = m_contourMapProjection->contourPolygons(); @@ -215,11 +227,14 @@ std::vector> RivContourMapProjectionPartMgr::createConto std::vector tickValues; mapper->majorTickValues(&tickValues); - std::vector> contourDrawables; + std::vector>> contourDrawablesForAllLevels; std::vector> labelDrawables; for (int64_t i = (int64_t) contourPolygons.size() - 1; i > 0; --i) { + std::vector> contourDrawables; + cvf::Color3f backgroundColor(mapper->mapToColor(tickValues[i])); + cvf::Color3f textColor = RiaColorTools::constrastColor(backgroundColor); for (size_t j = 0; j < contourPolygons[i].size(); ++j) { @@ -229,7 +244,7 @@ std::vector> RivContourMapProjectionPartMgr::createConto size_t nLabels = m_contourMapProjection->showContourLabels() ? std::max((size_t)1, nVertices / 150u) : 0u; for (size_t l = 0; l < nLabels; ++l) { - cvf::ref label = createTextLabel(backgroundColor); + cvf::ref label = createTextLabel(textColor, backgroundColor); cvf::Vec3f labelVertex(displayCoordTransform->transformToDisplayCoord(contourPolygons[i][j].vertices[(nVertices * l) / nLabels])); labelVertex.z() += 3.0f; label->addText(contourPolygons[i][j].label, labelVertex); @@ -274,13 +289,15 @@ std::vector> RivContourMapProjectionPartMgr::createConto geo->setVertexArray(vertexArray.p()); contourDrawables.push_back(geo); } - } - for (cvf::ref labelDrawable : labelDrawables) - { - contourDrawables.push_back(labelDrawable); + for (cvf::ref labelDrawable : labelDrawables) + { + contourDrawables.push_back(labelDrawable); + } + + contourDrawablesForAllLevels.push_back(contourDrawables); } - return contourDrawables; + return contourDrawablesForAllLevels; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.h b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.h index 2fe43cd5be..8d72a3ac27 100644 --- a/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivContourMapProjectionPartMgr.h @@ -43,10 +43,10 @@ public: cvf::ref createTextureCoords() const; private: - static cvf::ref createTextLabel(const cvf::Color3f& backgroundColor); - cvf::ref createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const; - std::vector> createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const; - cvf::ref createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const; + static cvf::ref createTextLabel(const cvf::Color3f& textColor, const cvf::Color3f& backgroundColor); + cvf::ref createProjectionMapDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const; + std::vector>> createContourPolygons(const caf::DisplayCoordTransform* displayCoordTransform) const; + cvf::ref createPickPointVisDrawable(const caf::DisplayCoordTransform* displayCoordTransform) const; private: caf::PdmPointer m_contourMapProjection; caf::PdmPointer m_parentContourMap;