vtk-m/vtkm/rendering/ColorBarAnnotation.h
Kenneth Moreland 2be7a8e032 Remove templating from View
The template parameters on vtkm::rendering::View are unnecessary. All
three of the templated classes are polymorphic (with virtual functions).
Thus, you just have to specify them at the constructor. Removing the
template parameters makes the syntax a bit cleaner and removes some
unnecessary duplication in the executable.

Removing the template does mean we cannot optimize in the future.
However, I expect us to start using more virtual methods rather than
less, so I think this is a move in the right direction.
2016-06-09 12:08:01 -06:00

89 lines
2.7 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_rendering_ColorBarAnnotation_h
#define vtk_m_rendering_ColorBarAnnotation_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/rendering/AxisAnnotation2D.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/Canvas.h>
#include <vtkm/rendering/ColorTable.h>
namespace vtkm {
namespace rendering {
class ColorBarAnnotation
{
protected:
vtkm::rendering::ColorTable colortable;
vtkm::rendering::AxisAnnotation2D axis;
public:
ColorBarAnnotation()
{
}
void SetColorTable(const vtkm::rendering::ColorTable &ct)
{
colortable = ct;
}
void SetRange(vtkm::Float64 l, vtkm::Float64 h, int nticks)
{
std::vector<vtkm::Float64> pos, prop;
axis.SetMinorTicks(pos, prop); // clear any minor ticks
for (int i=0; i<nticks; ++i)
{
vtkm::Float64 p = static_cast<vtkm::Float64>(i) / static_cast<vtkm::Float64>(nticks-1);
vtkm::Float64 v = l + p*(h-l);
pos.push_back(v);
prop.push_back(p);
}
axis.SetMajorTicks(pos, prop);
}
void SetRange(const vtkm::Range &range, int nticks)
{
this->SetRange(range.Min, range.Max, nticks);
}
virtual void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas)
{
vtkm::Float32 l = -0.88f, r = +0.88f;
vtkm::Float32 b = +0.87f, t = +0.92f;
canvas.AddColorBar(l, t, r-l, b-t,
colortable, true);
axis.SetColor(Color(1,1,1));
axis.SetLineWidth(1);
axis.SetScreenPosition(l,b, r,b);
axis.SetMajorTickSize(0, .02, 1.0);
axis.SetMinorTickSize(0,0,0); // no minor ticks
axis.SetLabelAlignment(TextAnnotation::HCenter,
TextAnnotation::Top);
axis.Render(camera, worldAnnotator, canvas);
}
};
}} //namespace vtkm::rendering
#endif // vtk_m_rendering_ColorBarAnnotation_h