2016-09-01 18:33:28 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-09-01 18:33:28 +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/View3D.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
|
|
|
View3D::View3D(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
|
|
|
View3D::View3D(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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:18:24 +00:00
|
|
|
View3D::~View3D() {}
|
2016-09-08 23:08:17 +00:00
|
|
|
|
2016-09-01 18:33:28 +00:00
|
|
|
void View3D::Paint()
|
|
|
|
{
|
|
|
|
this->GetCanvas().Clear();
|
2017-08-10 13:26:16 +00:00
|
|
|
this->RenderAnnotations();
|
2021-03-03 18:52:15 +00:00
|
|
|
this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
2016-09-01 18:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void View3D::RenderScreenAnnotations()
|
|
|
|
{
|
|
|
|
if (this->GetScene().GetNumberOfActors() > 0)
|
|
|
|
{
|
|
|
|
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
2018-01-18 21:21:39 +00:00
|
|
|
this->ColorBarAnnotation.SetFieldName(this->GetScene().GetActor(0).GetScalarField().GetName());
|
2017-05-18 14:29:41 +00:00
|
|
|
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
|
|
|
|
this->ColorBarAnnotation.SetColorTable(this->GetScene().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 View3D::RenderWorldAnnotations()
|
|
|
|
{
|
|
|
|
vtkm::Bounds bounds = this->GetScene().GetSpatialBounds();
|
|
|
|
vtkm::Float64 xmin = bounds.X.Min, xmax = bounds.X.Max;
|
|
|
|
vtkm::Float64 ymin = bounds.Y.Min, ymax = bounds.Y.Max;
|
|
|
|
vtkm::Float64 zmin = bounds.Z.Min, zmax = bounds.Z.Max;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Float64 dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin;
|
|
|
|
vtkm::Float64 size = vtkm::Sqrt(dx * dx + dy * dy + dz * dz);
|
2016-09-01 18:33:28 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
this->BoxAnnotation.SetColor(Color(.5f, .5f, .5f));
|
2016-09-01 18:33:28 +00:00
|
|
|
this->BoxAnnotation.SetExtents(this->GetScene().GetSpatialBounds());
|
|
|
|
this->BoxAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator());
|
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f_32 lookAt = this->GetCamera().GetLookAt();
|
|
|
|
vtkm::Vec3f_32 position = this->GetCamera().GetPosition();
|
2016-09-01 18:33:28 +00:00
|
|
|
bool xtest = lookAt[0] > position[0];
|
|
|
|
bool ytest = lookAt[1] > position[1];
|
|
|
|
bool ztest = lookAt[2] > position[2];
|
|
|
|
|
|
|
|
const bool outsideedges = true; // if false, do closesttriad
|
|
|
|
if (outsideedges)
|
|
|
|
{
|
|
|
|
xtest = !xtest;
|
|
|
|
//ytest = !ytest;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::Float64 xrel = vtkm::Abs(dx) / size;
|
|
|
|
vtkm::Float64 yrel = vtkm::Abs(dy) / size;
|
|
|
|
vtkm::Float64 zrel = vtkm::Abs(dz) / size;
|
|
|
|
|
|
|
|
this->XAxisAnnotation.SetAxis(0);
|
2017-08-02 16:32:19 +00:00
|
|
|
this->XAxisAnnotation.SetColor(AxisColor);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->XAxisAnnotation.SetTickInvert(xtest, ytest, ztest);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->XAxisAnnotation.SetWorldPosition(
|
|
|
|
xmin, ytest ? ymin : ymax, ztest ? zmin : zmax, xmax, ytest ? ymin : ymax, ztest ? zmin : zmax);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->XAxisAnnotation.SetRange(xmin, xmax);
|
|
|
|
this->XAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->XAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
|
|
|
this->XAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
|
|
|
this->XAxisAnnotation.SetMoreOrLessTickAdjustment(xrel < .3 ? -1 : 0);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->XAxisAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
|
|
|
|
this->YAxisAnnotation.SetAxis(1);
|
2017-08-02 16:32:19 +00:00
|
|
|
this->YAxisAnnotation.SetColor(AxisColor);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->YAxisAnnotation.SetTickInvert(xtest, ytest, ztest);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->YAxisAnnotation.SetWorldPosition(
|
|
|
|
xtest ? xmin : xmax, ymin, ztest ? zmin : zmax, xtest ? xmin : xmax, ymax, ztest ? zmin : zmax);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->YAxisAnnotation.SetRange(ymin, ymax);
|
|
|
|
this->YAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->YAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
|
|
|
this->YAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
|
|
|
this->YAxisAnnotation.SetMoreOrLessTickAdjustment(yrel < .3 ? -1 : 0);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->YAxisAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
|
|
|
|
this->ZAxisAnnotation.SetAxis(2);
|
2017-08-02 16:32:19 +00:00
|
|
|
this->ZAxisAnnotation.SetColor(AxisColor);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->ZAxisAnnotation.SetTickInvert(xtest, ytest, ztest);
|
2017-05-26 17:53:28 +00:00
|
|
|
this->ZAxisAnnotation.SetWorldPosition(
|
|
|
|
xtest ? xmin : xmax, ytest ? ymin : ymax, zmin, xtest ? xmin : xmax, ytest ? ymin : ymax, zmax);
|
2016-09-01 18:33:28 +00:00
|
|
|
this->ZAxisAnnotation.SetRange(zmin, zmax);
|
|
|
|
this->ZAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->ZAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
|
|
|
this->ZAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
|
|
|
this->ZAxisAnnotation.SetMoreOrLessTickAdjustment(zrel < .3 ? -1 : 0);
|
2017-05-18 14:29:41 +00:00
|
|
|
this->ZAxisAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-09-01 18:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|