2016-08-27 02:32:15 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-08-27 02:32:15 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/rendering/ColorBarAnnotation.h>
|
2018-01-18 21:21:39 +00:00
|
|
|
#include <vtkm/rendering/TextAnnotationScreen.h>
|
2016-08-27 02:32:15 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-08-27 02:32:15 +00:00
|
|
|
|
2016-09-08 23:08:17 +00:00
|
|
|
ColorBarAnnotation::ColorBarAnnotation()
|
2020-09-14 19:26:16 +00:00
|
|
|
: ColorTable(vtkm::ColorSpace::Lab)
|
2018-04-02 17:21:44 +00:00
|
|
|
, Position(vtkm::Range(-0.88, +0.88), vtkm::Range(+0.87, +0.92), vtkm::Range(0, 0))
|
|
|
|
, Horizontal(true)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2016-09-08 23:08:17 +00:00
|
|
|
|
2018-01-18 21:21:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void ColorBarAnnotation::SetRange(const vtkm::Range& range, vtkm::IdComponent numTicks)
|
2016-08-27 02:32:15 +00:00
|
|
|
{
|
|
|
|
std::vector<vtkm::Float64> positions, proportions;
|
|
|
|
this->Axis.SetMinorTicks(positions, proportions); // clear any minor ticks
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < numTicks; ++i)
|
2016-08-27 02:32:15 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Float64 prop = static_cast<vtkm::Float64>(i) / static_cast<vtkm::Float64>(numTicks - 1);
|
|
|
|
vtkm::Float64 pos = range.Min + prop * range.Length();
|
2016-08-27 02:32:15 +00:00
|
|
|
positions.push_back(pos);
|
|
|
|
proportions.push_back(prop);
|
|
|
|
}
|
|
|
|
this->Axis.SetMajorTicks(positions, proportions);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void ColorBarAnnotation::Render(const vtkm::rendering::Camera& camera,
|
|
|
|
const vtkm::rendering::WorldAnnotator& worldAnnotator,
|
|
|
|
vtkm::rendering::Canvas& canvas)
|
2016-08-27 02:32:15 +00:00
|
|
|
{
|
|
|
|
|
2018-01-18 21:21:39 +00:00
|
|
|
canvas.AddColorBar(Position, this->ColorTable, Horizontal);
|
2016-08-27 02:32:15 +00:00
|
|
|
|
2017-12-05 04:46:38 +00:00
|
|
|
this->Axis.SetColor(canvas.GetForegroundColor());
|
2016-08-27 02:32:15 +00:00
|
|
|
this->Axis.SetLineWidth(1);
|
2018-01-18 21:21:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
this->Axis.SetMinorTickSize(0, 0, 0); // no minor ticks
|
2016-08-27 02:32:15 +00:00
|
|
|
this->Axis.Render(camera, worldAnnotator, canvas);
|
2018-01-18 21:21:39 +00:00
|
|
|
|
2023-06-05 15:02:27 +00:00
|
|
|
if (!FieldName.empty())
|
2018-01-18 21:21:39 +00:00
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec2f_32 labelPos;
|
2018-01-18 21:21:39 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-08-27 02:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|