2016-11-23 15:48:22 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-11-23 15:48:22 +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/Color.h>
|
|
|
|
#include <vtkm/rendering/TextAnnotation.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/rendering/View1D.h>
|
2016-11-23 15:48:22 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-11-23 15:48:22 +00:00
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
View1D::View1D(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-11-23 15:48:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
View1D::View1D(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-11-23 15:48:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:18:24 +00:00
|
|
|
View1D::~View1D() {}
|
2016-11-23 15:48:22 +00:00
|
|
|
|
|
|
|
void View1D::Paint()
|
|
|
|
{
|
|
|
|
this->GetCanvas().Clear();
|
2017-08-07 14:45:03 +00:00
|
|
|
this->UpdateCameraProperties();
|
2021-03-03 18:52:15 +00:00
|
|
|
this->AddAdditionalAnnotation([&]() { this->RenderColorLegendAnnotations(); });
|
2017-07-28 17:31:19 +00:00
|
|
|
this->RenderAnnotations();
|
2021-03-03 18:52:15 +00:00
|
|
|
this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
2016-11-23 15:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void View1D::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);
|
2016-11-23 15:48:22 +00:00
|
|
|
|
2021-10-19 21:12:18 +00:00
|
|
|
this->GetCanvas().BeginTextRenderingBatch();
|
|
|
|
this->GetWorldAnnotator().BeginLineRenderingBatch();
|
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-12-02 15:26:36 +00:00
|
|
|
vtkm::Bounds viewRange = this->GetCamera().GetViewRange2D();
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-08-07 14:45:03 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetLogarithmic(LogX);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetRangeForAutoTicks(viewRange.X.Min, viewRange.X.Max);
|
2016-11-23 15:48:22 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetMajorTickSize(0, .05, 1.0);
|
|
|
|
this->HorizontalAxisAnnotation.SetMinorTickSize(0, .02, 1.0);
|
|
|
|
this->HorizontalAxisAnnotation.SetLabelAlignment(vtkm::rendering::TextAnnotation::HCenter,
|
|
|
|
vtkm::rendering::TextAnnotation::Top);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->HorizontalAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-11-23 15:48:22 +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-08-07 14:45:03 +00:00
|
|
|
this->VerticalAxisAnnotation.SetLogarithmic(LogY);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->VerticalAxisAnnotation.SetRangeForAutoTicks(viewRange.Y.Min, viewRange.Y.Max);
|
2016-11-23 15:48:22 +00:00
|
|
|
this->VerticalAxisAnnotation.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
|
|
|
this->VerticalAxisAnnotation.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
|
|
|
this->VerticalAxisAnnotation.SetLabelAlignment(vtkm::rendering::TextAnnotation::Right,
|
|
|
|
vtkm::rendering::TextAnnotation::VCenter);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->VerticalAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2021-10-19 21:12:18 +00:00
|
|
|
|
|
|
|
this->GetWorldAnnotator().EndLineRenderingBatch();
|
|
|
|
this->GetCanvas().EndTextRenderingBatch();
|
2016-11-23 15:48:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 17:31:19 +00:00
|
|
|
void View1D::RenderColorLegendAnnotations()
|
|
|
|
{
|
|
|
|
if (LegendEnabled)
|
|
|
|
{
|
|
|
|
this->Legend.Clear();
|
2021-10-19 21:12:18 +00:00
|
|
|
this->GetWorldAnnotator().BeginLineRenderingBatch();
|
|
|
|
this->GetCanvas().BeginTextRenderingBatch();
|
2017-07-28 17:31:19 +00:00
|
|
|
for (int i = 0; i < this->GetScene().GetNumberOfActors(); ++i)
|
|
|
|
{
|
|
|
|
vtkm::rendering::Actor act = this->GetScene().GetActor(i);
|
2018-01-18 18:55:15 +00:00
|
|
|
|
|
|
|
vtkm::Vec<double, 4> colorData;
|
|
|
|
act.GetColorTable().GetPoint(0, colorData);
|
|
|
|
|
|
|
|
//colorData[0] is the transfer function x position
|
|
|
|
vtkm::rendering::Color color{ static_cast<vtkm::Float32>(colorData[1]),
|
|
|
|
static_cast<vtkm::Float32>(colorData[2]),
|
|
|
|
static_cast<vtkm::Float32>(colorData[3]) };
|
|
|
|
this->Legend.AddItem(act.GetScalarField().GetName(), color);
|
2017-07-28 17:31:19 +00:00
|
|
|
}
|
2017-12-05 04:46:38 +00:00
|
|
|
this->Legend.SetLabelColor(this->GetCanvas().GetForegroundColor());
|
2017-07-28 17:31:19 +00:00
|
|
|
this->Legend.Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2021-10-19 21:12:18 +00:00
|
|
|
this->GetWorldAnnotator().EndLineRenderingBatch();
|
|
|
|
this->GetCanvas().EndTextRenderingBatch();
|
2017-07-28 17:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 15:48:22 +00:00
|
|
|
void View1D::RenderWorldAnnotations()
|
|
|
|
{
|
|
|
|
// 1D views don't have world annotations.
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2017-07-28 17:31:19 +00:00
|
|
|
|
|
|
|
void View1D::EnableLegend()
|
|
|
|
{
|
|
|
|
LegendEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View1D::DisableLegend()
|
|
|
|
{
|
|
|
|
LegendEnabled = false;
|
|
|
|
}
|
2017-08-07 14:45:03 +00:00
|
|
|
|
|
|
|
void View1D::UpdateCameraProperties()
|
|
|
|
{
|
|
|
|
// Modify the camera if we are going log scaling or if our bounds are equal
|
|
|
|
vtkm::Bounds origCamBounds = this->GetCamera().GetViewRange2D();
|
|
|
|
vtkm::Float64 vmin = origCamBounds.Y.Min;
|
|
|
|
vtkm::Float64 vmax = origCamBounds.Y.Max;
|
|
|
|
if (LogY)
|
|
|
|
{
|
|
|
|
if (vmin <= 0 || vmax <= 0)
|
|
|
|
{
|
|
|
|
origCamBounds.Y.Min = 0;
|
|
|
|
origCamBounds.Y.Max = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
origCamBounds.Y.Min = log10(vmin);
|
|
|
|
origCamBounds.Y.Max = log10(vmax);
|
|
|
|
if (origCamBounds.Y.Min == origCamBounds.Y.Max)
|
|
|
|
{
|
|
|
|
origCamBounds.Y.Min /= 10;
|
|
|
|
origCamBounds.Y.Max *= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
origCamBounds.Y.Min = vmin;
|
|
|
|
origCamBounds.Y.Max = vmax;
|
|
|
|
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);
|
|
|
|
|
2017-08-10 13:26:16 +00:00
|
|
|
// if unchanged by user we always want to start with a curve being full-frame
|
2022-03-17 20:22:41 +00:00
|
|
|
if (this->GetCamera().GetMode() == Camera::Mode::TwoD && this->GetCamera().GetXScale() == 1.0f)
|
2017-08-07 14:45:03 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 15:48:22 +00:00
|
|
|
}
|
2016-11-23 18:45:03 +00:00
|
|
|
} // namespace vtkm::rendering
|