Commit dd390109 authored by Matt Larsen's avatar Matt Larsen Committed by Kitware Robot

Merge topic 'colorbar_enhancement'

b420a4b3 fixing typo
2bb64e65 fixing opacity for veritical bar
80081f2a adding finer grain control over color bar and scalar field label
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1063
parents 31a9cc52 b420a4b3
......@@ -207,10 +207,12 @@ struct DrawColorBar : public vtkm::worklet::WorkletMapField
{
// local bar coord
vtkm::Id x = index % BarWidth;
vtkm::Id y = index / BarWidth, yLocal = y;
vtkm::Id y = index / BarWidth;
vtkm::Id sample = Horizontal ? x : y;
vtkm::Vec<vtkm::Float32, 4> color = colorMap.Get(sample);
vtkm::Float32 normalizedHeight =
Horizontal ? vtkm::Float32(y) / BarHeight : vtkm::Float32(x) / BarWidth;
// offset to global image coord
x += BarBottomLeft[0];
y += BarBottomLeft[1];
......@@ -218,7 +220,6 @@ struct DrawColorBar : public vtkm::worklet::WorkletMapField
vtkm::Id offset = y * ImageWidth + x;
// If the colortable has alpha values, we blend each color sample with translucent white.
// The height of the resultant translucent bar indicates the opacity.
vtkm::Float32 normalizedHeight = static_cast<vtkm::Float32>(yLocal) / BarHeight;
if (color[3] < 1.0f && normalizedHeight <= color[3])
{
vtkm::Float32 intensity = 0.4f;
......@@ -234,6 +235,8 @@ struct DrawColorBar : public vtkm::worklet::WorkletMapField
}
else
{
// make sure this is opaque
color[3] = 1.f;
frameBuffer.Set(offset, color);
}
}
......
......@@ -19,6 +19,7 @@
//============================================================================
#include <vtkm/rendering/ColorBarAnnotation.h>
#include <vtkm/rendering/TextAnnotationScreen.h>
namespace vtkm
{
......@@ -27,12 +28,32 @@ namespace rendering
ColorBarAnnotation::ColorBarAnnotation()
{
vtkm::Bounds bounds(vtkm::Range(-0.88, +0.88), vtkm::Range(+0.87, +0.92), vtkm::Range(0, 0));
Position = bounds;
Horizontal = true;
FieldName = "";
}
ColorBarAnnotation::~ColorBarAnnotation()
{
}
void ColorBarAnnotation::SetFieldName(const std::string& fieldName)
{
FieldName = fieldName;
}
void ColorBarAnnotation::SetPosition(const vtkm::Bounds& position)
{
Position = position;
vtkm::Float64 x = Position.X.Length();
vtkm::Float64 y = Position.Y.Length();
if (x > y)
Horizontal = true;
else
Horizontal = false;
}
void ColorBarAnnotation::SetRange(const vtkm::Range& range, vtkm::IdComponent numTicks)
{
std::vector<vtkm::Float64> positions, proportions;
......@@ -52,17 +73,50 @@ void ColorBarAnnotation::Render(const vtkm::rendering::Camera& camera,
const vtkm::rendering::WorldAnnotator& worldAnnotator,
vtkm::rendering::Canvas& canvas)
{
vtkm::Bounds bounds(vtkm::Range(-0.88, +0.88), vtkm::Range(+0.87, +0.92), vtkm::Range(0, 0));
canvas.AddColorBar(bounds, this->ColorTable, true);
canvas.AddColorBar(Position, this->ColorTable, Horizontal);
this->Axis.SetColor(canvas.GetForegroundColor());
this->Axis.SetLineWidth(1);
this->Axis.SetScreenPosition(bounds.X.Min, bounds.Y.Min, bounds.X.Max, bounds.Y.Min);
this->Axis.SetMajorTickSize(0, .02, 1.0);
if (Horizontal)
{
this->Axis.SetScreenPosition(Position.X.Min, Position.Y.Min, Position.X.Max, Position.Y.Min);
this->Axis.SetLabelAlignment(TextAnnotation::HCenter, TextAnnotation::Top);
this->Axis.SetMajorTickSize(0, .02, 1.0);
}
else
{
this->Axis.SetScreenPosition(Position.X.Min, Position.Y.Min, Position.X.Min, Position.Y.Max);
this->Axis.SetLabelAlignment(TextAnnotation::Right, TextAnnotation::VCenter);
this->Axis.SetMajorTickSize(.02, 0.0, 1.0);
}
this->Axis.SetMinorTickSize(0, 0, 0); // no minor ticks
this->Axis.SetLabelAlignment(TextAnnotation::HCenter, TextAnnotation::Top);
this->Axis.Render(camera, worldAnnotator, canvas);
if (FieldName != "")
{
vtkm::Vec<vtkm::Float32, 2> labelPos;
if (Horizontal)
{
labelPos[0] = vtkm::Float32(Position.X.Min);
labelPos[1] = vtkm::Float32(Position.Y.Max);
}
else
{
labelPos[0] = vtkm::Float32(Position.X.Min - 0.07);
labelPos[1] = vtkm::Float32(Position.Y.Max + 0.03);
}
vtkm::rendering::TextAnnotationScreen var(FieldName,
canvas.GetForegroundColor(),
.045f, // font scale
labelPos,
0.f); // rotation
var.Render(camera, worldAnnotator, canvas);
}
}
}
} // namespace vtkm::rendering
......@@ -38,6 +38,9 @@ class VTKM_RENDERING_EXPORT ColorBarAnnotation
protected:
vtkm::rendering::ColorTable ColorTable;
vtkm::rendering::AxisAnnotation2D Axis;
vtkm::Bounds Position;
bool Horizontal;
std::string FieldName;
public:
ColorBarAnnotation();
......@@ -50,14 +53,22 @@ public:
this->ColorTable = colorTable;
}
VTKM_CONT
void SetRange(const vtkm::Range& range, vtkm::IdComponent numTicks);
VTKM_CONT
void SetFieldName(const std::string& fieldName);
VTKM_CONT
void SetRange(vtkm::Float64 l, vtkm::Float64 h, vtkm::IdComponent numTicks)
{
this->SetRange(vtkm::Range(l, h), numTicks);
}
VTKM_CONT
void SetPosition(const vtkm::Bounds& position);
virtual void Render(const vtkm::rendering::Camera& camera,
const vtkm::rendering::WorldAnnotator& worldAnnotator,
vtkm::rendering::Canvas& canvas);
......
......@@ -102,6 +102,7 @@ void View2D::RenderScreenAnnotations()
if (scene.GetNumberOfActors() > 0)
{
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
this->ColorBarAnnotation.SetFieldName(scene.GetActor(0).GetScalarField().GetName());
this->ColorBarAnnotation.SetRange(
scene.GetActor(0).GetScalarRange().Min, scene.GetActor(0).GetScalarRange().Max, 5);
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
......
......@@ -69,6 +69,7 @@ void View3D::RenderScreenAnnotations()
if (this->GetScene().GetNumberOfActors() > 0)
{
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
this->ColorBarAnnotation.SetFieldName(this->GetScene().GetActor(0).GetScalarField().GetName());
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).GetColorTable());
this->ColorBarAnnotation.Render(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment