Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
allow the renderer to set the number of color bars (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
mclarsen authored Sep 28, 2021
1 parent 53b94cc commit 6ab59dd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/dray/rendering/annotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dray/rendering/device_framebuffer.hpp>
#include <dray/policies.hpp>
#include <dray/error_check.hpp>
#include <dray/error.hpp>
#include <dray/math.hpp>

#include <cmath>
Expand Down Expand Up @@ -72,6 +73,7 @@ void simple_ticks(Framebuffer &fb, Array<Vec<float32,2>> &ticks, const float32 l
} // namespace detail

Annotator::Annotator()
: m_max_color_bars(2)
{
// ranges are (-1,1)
AABB<2> p0;
Expand Down Expand Up @@ -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<std::string> &field_names,
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/dray/rendering/annotator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class Annotator
{
protected:
std::vector<AABB<2>> 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<std::string> &field_names,
std::vector<ColorMap> &color_maps);
Expand Down
10 changes: 9 additions & 1 deletion src/dray/rendering/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -379,4 +381,10 @@ void Renderer::composite(Array<Ray> &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
2 changes: 2 additions & 0 deletions src/dray/rendering/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Renderer
std::vector<PointLight> m_lights;
bool m_use_lighting;
bool m_screen_annotations;
int32 m_max_color_bars;
public:
Renderer();
void clear();
Expand All @@ -41,6 +42,7 @@ class Renderer
bool synch_deptsh) const;

void screen_annotations(bool on);
void max_color_bars(const int32 max_bars);
};


Expand Down

0 comments on commit 6ab59dd

Please sign in to comment.