From 6ab59dd740a5fb1e04967e982c5c6d4c7507f4cb Mon Sep 17 00:00:00 2001 From: Matt Larsen Date: Tue, 28 Sep 2021 14:22:15 -0700 Subject: [PATCH] allow the renderer to set the number of color bars (#84) --- src/dray/rendering/annotator.cpp | 21 ++++++++++++++++++++- src/dray/rendering/annotator.hpp | 2 ++ src/dray/rendering/renderer.cpp | 10 +++++++++- src/dray/rendering/renderer.hpp | 2 ++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/dray/rendering/annotator.cpp b/src/dray/rendering/annotator.cpp index 5742c944..e7c26d08 100644 --- a/src/dray/rendering/annotator.cpp +++ b/src/dray/rendering/annotator.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -72,6 +73,7 @@ void simple_ticks(Framebuffer &fb, Array> &ticks, const float32 l } // namespace detail Annotator::Annotator() + : m_max_color_bars(2) { // ranges are (-1,1) AABB<2> p0; @@ -103,6 +105,23 @@ Annotator::Annotator() m_color_bar_pos.push_back(p0); m_color_bar_pos.push_back(p1); } + +void +Annotator::max_color_bars(const int32 max_bars) +{ + // Technically we can do more that this, but we need to get text + // alignment working before we enable the other positions + if(max_bars > 2) + { + DRAY_ERROR("Max bars cannot exceed 2"); + } + if(max_bars < 0) + { + DRAY_ERROR("Max bars cannot be less than 0"); + } + m_max_color_bars = max_bars; +} + void Annotator::screen_annotations(Framebuffer &fb, const std::vector &field_names, @@ -111,7 +130,7 @@ Annotator::screen_annotations(Framebuffer &fb, // TODO: capping at 2 // we need to justify text to the left of right // oriented color bars - const int32 size = std::min(int32(field_names.size()),2); + const int32 size = std::min(int32(field_names.size()), m_max_color_bars); const int32 height = fb.height(); const int32 width = fb.width(); diff --git a/src/dray/rendering/annotator.hpp b/src/dray/rendering/annotator.hpp index b724dcaf..602e9114 100644 --- a/src/dray/rendering/annotator.hpp +++ b/src/dray/rendering/annotator.hpp @@ -19,9 +19,11 @@ class Annotator { protected: std::vector> m_color_bar_pos; + int32 m_max_color_bars; public: Annotator(); + void max_color_bars(int max_bars); void screen_annotations(Framebuffer &fb, const std::vector &field_names, std::vector &color_maps); diff --git a/src/dray/rendering/renderer.cpp b/src/dray/rendering/renderer.cpp index 29fc6075..d2123a61 100644 --- a/src/dray/rendering/renderer.cpp +++ b/src/dray/rendering/renderer.cpp @@ -162,7 +162,8 @@ PointLight default_light(Camera &camera) Renderer::Renderer() : m_volume(nullptr), m_use_lighting(true), - m_screen_annotations(true) + m_screen_annotations(true), + m_max_color_bars(2) { } @@ -307,6 +308,7 @@ Framebuffer Renderer::render(Camera &camera) if(m_screen_annotations && dray::mpi_rank() == 0) { Annotator annot; + annot.max_color_bars(m_max_color_bars); annot.screen_annotations(framebuffer, field_names, color_maps); } DRAY_LOG_CLOSE(); @@ -379,4 +381,10 @@ void Renderer::composite(Array &rays, #endif } +void Renderer::max_color_bars(const int32 max_bars) +{ + // limits will be enforced in the annotator + m_max_color_bars = max_bars; +} + } // namespace dray diff --git a/src/dray/rendering/renderer.hpp b/src/dray/rendering/renderer.hpp index 9d7617dd..f803d7ab 100644 --- a/src/dray/rendering/renderer.hpp +++ b/src/dray/rendering/renderer.hpp @@ -26,6 +26,7 @@ class Renderer std::vector m_lights; bool m_use_lighting; bool m_screen_annotations; + int32 m_max_color_bars; public: Renderer(); void clear(); @@ -41,6 +42,7 @@ class Renderer bool synch_deptsh) const; void screen_annotations(bool on); + void max_color_bars(const int32 max_bars); };