vtk-m2/vtkm/rendering/ColorBarAnnotation.h

89 lines
2.7 KiB
C
Raw Normal View History

2016-05-18 19:29:50 +00:00
//============================================================================
// 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>
2016-06-02 19:04:01 +00:00
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/Canvas.h>
2016-05-18 19:29:50 +00:00
#include <vtkm/rendering/ColorTable.h>
namespace vtkm {
namespace rendering {
class ColorBarAnnotation
{
protected:
vtkm::rendering::ColorTable colortable;
2016-05-20 14:04:37 +00:00
vtkm::rendering::AxisAnnotation2D axis;
2016-05-18 19:29:50 +00:00
public:
ColorBarAnnotation()
{
}
void SetColorTable(const vtkm::rendering::ColorTable &ct)
2016-05-18 19:29:50 +00:00
{
colortable = ct;
}
void SetRange(vtkm::Float64 l, vtkm::Float64 h, int nticks)
2016-05-18 19:29:50 +00:00
{
std::vector<vtkm::Float64> pos, prop;
2016-05-18 19:29:50 +00:00
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);
2016-05-18 19:29:50 +00:00
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);
}
2016-05-18 19:29:50 +00:00
virtual void Render(const vtkm::rendering::Camera &camera,
const vtkm::rendering::WorldAnnotator &worldAnnotator,
vtkm::rendering::Canvas &canvas)
2016-05-18 19:29:50 +00:00
{
vtkm::Float32 l = -0.88f, r = +0.88f;
vtkm::Float32 b = +0.87f, t = +0.92f;
2016-05-18 19:29:50 +00:00
canvas.AddColorBar(l, t, r-l, b-t,
2016-05-18 19:29:50 +00:00
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);
2016-05-18 19:29:50 +00:00
}
};
}} //namespace vtkm::rendering
#endif // vtk_m_rendering_ColorBarAnnotation_h