2016-09-01 18:33:28 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-09-01 18:33:28 +00:00
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-09-01 18:33:28 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/rendering/View2D.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-09-01 18:33:28 +00:00
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
View2D::View2D(const vtkm::rendering::Scene& scene,
|
|
|
|
const vtkm::rendering::Mapper& mapper,
|
|
|
|
const vtkm::rendering::Canvas& canvas,
|
2017-12-05 04:46:38 +00:00
|
|
|
const vtkm::rendering::Color& backgroundColor,
|
|
|
|
const vtkm::rendering::Color& foregroundColor)
|
|
|
|
: View(scene, mapper, canvas, backgroundColor, foregroundColor)
|
2016-09-08 23:08:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
View2D::View2D(const vtkm::rendering::Scene& scene,
|
|
|
|
const vtkm::rendering::Mapper& mapper,
|
|
|
|
const vtkm::rendering::Canvas& canvas,
|
|
|
|
const vtkm::rendering::Camera& camera,
|
2017-12-05 04:46:38 +00:00
|
|
|
const vtkm::rendering::Color& backgroundColor,
|
|
|
|
const vtkm::rendering::Color& foregroundColor)
|
|
|
|
: View(scene, mapper, canvas, camera, backgroundColor, foregroundColor)
|
2016-09-08 23:08:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
View2D::~View2D()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:33:28 +00:00
|
|
|
void View2D::Paint()
|
|
|
|
{
|
|
|
|
this->GetCanvas().Activate();
|
|
|
|
this->GetCanvas().Clear();
|
2017-08-10 13:26:16 +00:00
|
|
|
this->UpdateCameraProperties();
|
2017-07-17 13:58:15 +00:00
|
|
|
this->SetupForWorldSpace();
|
2017-05-18 14:29:41 +00:00
|
|
|
this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
2016-09-01 18:33:28 +00:00
|
|
|
this->RenderWorldAnnotations();
|
|
|
|
this->SetupForScreenSpace();
|
|
|
|
this->RenderScreenAnnotations();
|
2017-08-10 13:26:16 +00:00
|
|
|
this->RenderAnnotations();
|
2016-09-01 18:33:28 +00:00
|
|
|
this->GetCanvas().Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void View2D::RenderScreenAnnotations()
|
|
|
|
{
|
|
|
|
vtkm::Float32 viewportLeft;
|
|
|
|
vtkm::Float32 viewportRight;
|
|
|
|
vtkm::Float32 viewportTop;
|
|
|
|
vtkm::Float32 viewportBottom;
|
2017-05-26 17:53:28 +00:00
|
|
|
this->GetCamera().GetRealViewport(this->GetCanvas().GetWidth(),
|
|
|
|
this->GetCanvas().GetHeight(),
|
|
|
|
viewportLeft,
|
|
|
|
viewportRight,
|
|
|
|
viewportBottom,
|
|
|
|
viewportTop);
|
2017-08-02 16:32:19 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetColor(AxisColor);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetScreenPosition(
|
|
|
|
viewportLeft, viewportBottom, viewportRight, viewportBottom);
|
2016-09-01 18:33:28 +00:00
|
|
|
vtkm::Bounds viewRange = this->GetCamera().GetViewRange2D();
|
2017-05-18 14:29:41 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetRangeForAutoTicks(viewRange.X.Min, viewRange.X.Max);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetMajorTickSize(0, .05, 1.0);
|
|
|
|
this->HorizontalAxisAnnotation.SetMinorTickSize(0, .02, 1.0);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetLabelAlignment(TextAnnotation::HCenter, TextAnnotation::Top);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->HorizontalAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
|
|
|
|
vtkm::Float32 windowaspect =
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Float32(this->GetCanvas().GetWidth()) / vtkm::Float32(this->GetCanvas().GetHeight());
|
|
|
|
|
2017-08-02 16:32:19 +00:00
|
|
|
this->VerticalAxisAnnotation.SetColor(AxisColor);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->VerticalAxisAnnotation.SetScreenPosition(
|
|
|
|
viewportLeft, viewportBottom, viewportLeft, viewportTop);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->VerticalAxisAnnotation.SetRangeForAutoTicks(viewRange.Y.Min, viewRange.Y.Max);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->VerticalAxisAnnotation.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
|
|
|
this->VerticalAxisAnnotation.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->VerticalAxisAnnotation.SetLabelAlignment(TextAnnotation::Right, TextAnnotation::VCenter);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->VerticalAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::rendering::Scene& scene = this->GetScene();
|
2016-09-01 18:33:28 +00:00
|
|
|
if (scene.GetNumberOfActors() > 0)
|
|
|
|
{
|
|
|
|
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
2018-01-18 21:21:39 +00:00
|
|
|
this->ColorBarAnnotation.SetFieldName(scene.GetActor(0).GetScalarField().GetName());
|
2017-05-26 17:53:28 +00:00
|
|
|
this->ColorBarAnnotation.SetRange(
|
|
|
|
scene.GetActor(0).GetScalarRange().Min, scene.GetActor(0).GetScalarRange().Max, 5);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
|
2017-05-26 17:53:28 +00:00
|
|
|
this->ColorBarAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void View2D::RenderWorldAnnotations()
|
|
|
|
{
|
|
|
|
// 2D views don't have world annotations.
|
|
|
|
}
|
2017-08-10 13:26:16 +00:00
|
|
|
|
|
|
|
void View2D::UpdateCameraProperties()
|
|
|
|
{
|
|
|
|
// Modify the camera if our bounds are equal to enable an image to show
|
|
|
|
vtkm::Bounds origCamBounds = this->GetCamera().GetViewRange2D();
|
|
|
|
if (origCamBounds.Y.Min == origCamBounds.Y.Max)
|
|
|
|
{
|
|
|
|
origCamBounds.Y.Min -= .5;
|
|
|
|
origCamBounds.Y.Max += .5;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set camera bounds with new top/bottom values
|
|
|
|
this->GetCamera().SetViewRange2D(
|
|
|
|
origCamBounds.X.Min, origCamBounds.X.Max, origCamBounds.Y.Min, origCamBounds.Y.Max);
|
|
|
|
|
|
|
|
// if unchanged by user we always want to start with a curve being full-frame
|
|
|
|
if (this->GetCamera().GetMode() == Camera::MODE_2D && this->GetCamera().GetXScale() == 1.0f)
|
|
|
|
{
|
|
|
|
vtkm::Float32 left, right, bottom, top;
|
|
|
|
this->GetCamera().GetViewRange2D(left, right, bottom, top);
|
|
|
|
this->GetCamera().SetXScale((static_cast<vtkm::Float32>(this->GetCanvas().GetWidth())) /
|
|
|
|
(static_cast<vtkm::Float32>(this->GetCanvas().GetHeight())) *
|
|
|
|
(top - bottom) / (right - left));
|
|
|
|
}
|
2017-10-26 14:58:02 +00:00
|
|
|
vtkm::Float32 left, right, bottom, top;
|
|
|
|
this->GetCamera().GetViewRange2D(left, right, bottom, top);
|
2017-08-10 13:26:16 +00:00
|
|
|
}
|
2016-09-01 18:33:28 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|