2016-02-09 13:59:26 +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 2015 Sandia Corporation.
|
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 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.
|
|
|
|
//============================================================================
|
2016-06-02 21:43:30 +00:00
|
|
|
#ifndef vtk_m_rendering_View_h
|
|
|
|
#define vtk_m_rendering_View_h
|
2016-02-09 13:59:26 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
2016-04-15 19:24:23 +00:00
|
|
|
#include <vtkm/rendering/BoundingBoxAnnotation.h>
|
2016-04-19 21:04:00 +00:00
|
|
|
#include <vtkm/rendering/AxisAnnotation3D.h>
|
2016-05-09 20:32:27 +00:00
|
|
|
#include <vtkm/rendering/AxisAnnotation2D.h>
|
2016-06-02 19:04:01 +00:00
|
|
|
#include <vtkm/rendering/Camera.h>
|
2016-05-24 20:34:47 +00:00
|
|
|
#include <vtkm/rendering/Color.h>
|
2016-05-18 19:29:50 +00:00
|
|
|
#include <vtkm/rendering/ColorBarAnnotation.h>
|
2016-05-20 21:57:56 +00:00
|
|
|
#include <vtkm/rendering/TextAnnotation.h>
|
2016-05-24 20:34:47 +00:00
|
|
|
#include <vtkm/rendering/Scene.h>
|
2016-02-09 13:59:26 +00:00
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace rendering {
|
|
|
|
|
2016-06-02 21:43:30 +00:00
|
|
|
class View
|
2016-04-18 20:42:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-08 23:20:25 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
View(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: Scene(scene),
|
|
|
|
MapperPointer(new MapperType(mapper)),
|
2016-06-13 15:57:19 +00:00
|
|
|
CanvasPointer(new CanvasType(canvas))
|
2016-06-08 23:20:25 +00:00
|
|
|
{
|
2016-06-13 15:57:19 +00:00
|
|
|
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
2016-06-08 23:20:25 +00:00
|
|
|
this->WorldAnnotatorPointer = this->CanvasPointer->CreateWorldAnnotator();
|
|
|
|
|
|
|
|
vtkm::Bounds spatialBounds = this->Scene.GetSpatialBounds();
|
|
|
|
this->Camera.ResetToBounds(spatialBounds);
|
|
|
|
if (spatialBounds.Z.Length() > 0.0)
|
|
|
|
{
|
|
|
|
this->Camera.SetModeTo3D();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Camera.SetModeTo2D();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
View(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: Scene(scene),
|
|
|
|
MapperPointer(new MapperType(mapper)),
|
|
|
|
CanvasPointer(new CanvasType(canvas)),
|
2016-06-11 18:09:51 +00:00
|
|
|
Camera(camera)
|
2016-06-08 20:53:32 +00:00
|
|
|
{
|
2016-06-11 18:09:51 +00:00
|
|
|
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
2016-06-08 20:53:32 +00:00
|
|
|
this->WorldAnnotatorPointer = this->CanvasPointer->CreateWorldAnnotator();
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType,
|
|
|
|
typename WorldAnnotatorType>
|
|
|
|
View(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const WorldAnnotatorType &annotator,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: Scene(scene),
|
|
|
|
MapperPointer(new MapperType(mapper)),
|
|
|
|
CanvasPointer(new CanvasType(canvas)),
|
|
|
|
WorldAnnotatorPointer(new WorldAnnotatorType(annotator)),
|
2016-06-11 18:09:51 +00:00
|
|
|
Camera(camera)
|
2016-05-24 20:34:47 +00:00
|
|
|
{
|
2016-06-11 18:09:51 +00:00
|
|
|
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
2016-06-06 14:29:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
virtual ~View()
|
|
|
|
{
|
|
|
|
delete this->MapperPointer;
|
|
|
|
delete this->CanvasPointer;
|
|
|
|
delete this->WorldAnnotatorPointer;
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::Scene &GetScene() const { return this->Scene; }
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::rendering::Scene &GetScene() { return this->Scene; }
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetScene(const vtkm::rendering::Scene &scene) { this->Scene = scene; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::Mapper &GetMapper() const
|
|
|
|
{
|
|
|
|
return *this->MapperPointer;
|
|
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::rendering::Mapper &GetMapper()
|
|
|
|
{
|
|
|
|
return *this->MapperPointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::Canvas &GetCanvas() const
|
|
|
|
{
|
|
|
|
return *this->CanvasPointer;
|
|
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::rendering::Canvas &GetCanvas()
|
|
|
|
{
|
|
|
|
return *this->CanvasPointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::WorldAnnotator &GetWorldAnnotator() const
|
|
|
|
{
|
|
|
|
return *this->WorldAnnotatorPointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::Camera &GetCamera() const
|
|
|
|
{
|
|
|
|
return this->Camera;
|
|
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::rendering::Camera &GetCamera()
|
|
|
|
{
|
|
|
|
return this->Camera;
|
|
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetCamera(const vtkm::rendering::Camera &camera)
|
|
|
|
{
|
|
|
|
this->Camera = camera;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const vtkm::rendering::Color &GetBackgroundColor() const
|
|
|
|
{
|
2016-06-11 18:09:51 +00:00
|
|
|
return this->CanvasPointer->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetBackgroundColor(const vtkm::rendering::Color &color)
|
|
|
|
{
|
|
|
|
this->CanvasPointer->SetBackgroundColor(color);
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2016-06-06 14:29:17 +00:00
|
|
|
virtual void Initialize() {this->GetCanvas().Initialize();}
|
2016-05-24 20:34:47 +00:00
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void Paint() = 0;
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderScreenAnnotations() {}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderWorldAnnotations() {}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SaveAs(const std::string &fileName)
|
|
|
|
{
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().SaveAs(fileName);
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
2016-04-18 20:42:59 +00:00
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
protected:
|
2016-05-24 20:34:47 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetupForWorldSpace(bool viewportClip=true)
|
|
|
|
{
|
2016-06-02 19:04:01 +00:00
|
|
|
//this->Camera.SetupMatrices();
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().SetViewToWorldSpace(this->Camera,viewportClip);
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetupForScreenSpace(bool viewportClip=false)
|
|
|
|
{
|
2016-06-02 19:04:01 +00:00
|
|
|
//this->Camera.SetupMatrices();
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().SetViewToScreenSpace(this->Camera,viewportClip);
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
2016-06-06 14:29:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::rendering::Scene Scene;
|
|
|
|
vtkm::rendering::Mapper *MapperPointer;
|
|
|
|
vtkm::rendering::Canvas *CanvasPointer;
|
|
|
|
vtkm::rendering::WorldAnnotator *WorldAnnotatorPointer;
|
|
|
|
vtkm::rendering::Camera Camera;
|
2016-04-18 20:42:59 +00:00
|
|
|
};
|
2016-05-19 22:37:37 +00:00
|
|
|
|
2016-06-02 21:43:30 +00:00
|
|
|
// View2D View3D
|
2016-06-06 14:29:17 +00:00
|
|
|
class View3D : public vtkm::rendering::View
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-08 23:20:25 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
View3D(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, backgroundColor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
View3D(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, camera, backgroundColor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType,
|
|
|
|
typename WorldAnnotatorType>
|
2016-05-24 20:34:47 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-02 21:43:30 +00:00
|
|
|
View3D(const vtkm::rendering::Scene &scene,
|
2016-06-06 14:29:17 +00:00
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const WorldAnnotatorType &annotator,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, annotator, camera, backgroundColor)
|
2016-05-24 20:34:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void Paint()
|
|
|
|
{
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().Activate();
|
|
|
|
this->GetCanvas().Clear();
|
2016-05-24 20:34:47 +00:00
|
|
|
this->SetupForWorldSpace();
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetScene().Render(
|
|
|
|
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
2016-05-24 20:34:47 +00:00
|
|
|
this->RenderWorldAnnotations();
|
|
|
|
|
|
|
|
this->SetupForScreenSpace();
|
|
|
|
this->RenderScreenAnnotations();
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().Finish();
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderScreenAnnotations()
|
|
|
|
{
|
2016-06-06 14:29:17 +00:00
|
|
|
if (this->GetScene().GetNumberOfActors() > 0)
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
2016-05-31 19:32:56 +00:00
|
|
|
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
2016-08-31 23:28:41 +00:00
|
|
|
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
|
|
|
|
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).GetColorTable());
|
2016-06-06 14:29:17 +00:00
|
|
|
this->ColorBarAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-02-09 13:59:26 +00:00
|
|
|
}
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderWorldAnnotations()
|
|
|
|
{
|
2016-06-06 14:29:17 +00:00
|
|
|
vtkm::Bounds bounds = this->GetScene().GetSpatialBounds();
|
2016-05-26 23:04:35 +00:00
|
|
|
vtkm::Float64 xmin = bounds.X.Min, xmax = bounds.X.Max;
|
|
|
|
vtkm::Float64 ymin = bounds.Y.Min, ymax = bounds.Y.Max;
|
2016-05-31 19:32:56 +00:00
|
|
|
vtkm::Float64 zmin = bounds.Z.Min, zmax = bounds.Z.Max;
|
2016-05-24 20:34:47 +00:00
|
|
|
vtkm::Float64 dx = xmax-xmin, dy = ymax-ymin, dz = zmax-zmin;
|
|
|
|
vtkm::Float64 size = vtkm::Sqrt(dx*dx + dy*dy + dz*dz);
|
|
|
|
|
|
|
|
this->BoxAnnotation.SetColor(Color(.5f,.5f,.5f));
|
2016-06-06 14:29:17 +00:00
|
|
|
this->BoxAnnotation.SetExtents(this->GetScene().GetSpatialBounds());
|
|
|
|
this->BoxAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
vtkm::Vec<vtkm::Float32,3> lookAt = this->GetCamera().GetLookAt();
|
|
|
|
vtkm::Vec<vtkm::Float32,3> position = this->GetCamera().GetPosition();
|
2016-06-03 23:27:03 +00:00
|
|
|
bool xtest = lookAt[0] > position[0];
|
|
|
|
bool ytest = lookAt[1] > position[1];
|
|
|
|
bool ztest = lookAt[2] > position[2];
|
2016-05-31 19:32:56 +00:00
|
|
|
|
|
|
|
const bool outsideedges = true; // if false, do closesttriad
|
|
|
|
if (outsideedges)
|
2016-05-09 20:32:27 +00:00
|
|
|
{
|
2016-05-31 19:32:56 +00:00
|
|
|
xtest = !xtest;
|
|
|
|
//ytest = !ytest;
|
2016-05-09 20:32:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 20:34:47 +00:00
|
|
|
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);
|
|
|
|
this->XAxisAnnotation.SetColor(Color(1,1,1));
|
|
|
|
this->XAxisAnnotation.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
this->XAxisAnnotation.SetWorldPosition(xmin,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
ztest ? zmin : zmax,
|
|
|
|
xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
ztest ? zmin : zmax);
|
|
|
|
this->XAxisAnnotation.SetRange(xmin, xmax);
|
|
|
|
this->XAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->XAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
2016-05-31 19:32:56 +00:00
|
|
|
this->XAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
2016-05-24 20:34:47 +00:00
|
|
|
this->XAxisAnnotation.SetMoreOrLessTickAdjustment(xrel < .3 ? -1 : 0);
|
2016-06-06 14:29:17 +00:00
|
|
|
this->XAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
2016-05-31 19:32:56 +00:00
|
|
|
this->YAxisAnnotation.SetAxis(1);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->YAxisAnnotation.SetColor(Color(1,1,1));
|
|
|
|
this->YAxisAnnotation.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
this->YAxisAnnotation.SetWorldPosition(xtest ? xmin : xmax,
|
|
|
|
ymin,
|
|
|
|
ztest ? zmin : zmax,
|
|
|
|
xtest ? xmin : xmax,
|
|
|
|
ymax,
|
|
|
|
ztest ? zmin : zmax);
|
|
|
|
this->YAxisAnnotation.SetRange(ymin, ymax);
|
|
|
|
this->YAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->YAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
2016-05-31 19:32:56 +00:00
|
|
|
this->YAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
2016-05-24 20:34:47 +00:00
|
|
|
this->YAxisAnnotation.SetMoreOrLessTickAdjustment(yrel < .3 ? -1 : 0);
|
2016-06-06 14:29:17 +00:00
|
|
|
this->YAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
2016-05-31 19:32:56 +00:00
|
|
|
this->ZAxisAnnotation.SetAxis(2);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->ZAxisAnnotation.SetColor(Color(1,1,1));
|
|
|
|
this->ZAxisAnnotation.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
this->ZAxisAnnotation.SetWorldPosition(xtest ? xmin : xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
zmin,
|
|
|
|
xtest ? xmin : xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
zmax);
|
|
|
|
this->ZAxisAnnotation.SetRange(zmin, zmax);
|
|
|
|
this->ZAxisAnnotation.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
this->ZAxisAnnotation.SetMinorTickSize(size / 80.f, 0);
|
2016-05-31 19:32:56 +00:00
|
|
|
this->ZAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
2016-05-24 20:34:47 +00:00
|
|
|
this->ZAxisAnnotation.SetMoreOrLessTickAdjustment(zrel < .3 ? -1 : 0);
|
2016-06-06 14:29:17 +00:00
|
|
|
this->ZAxisAnnotation.Render(
|
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
2016-06-06 14:29:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// 3D-specific annotations
|
|
|
|
vtkm::rendering::BoundingBoxAnnotation BoxAnnotation;
|
|
|
|
vtkm::rendering::AxisAnnotation3D XAxisAnnotation;
|
|
|
|
vtkm::rendering::AxisAnnotation3D YAxisAnnotation;
|
|
|
|
vtkm::rendering::AxisAnnotation3D ZAxisAnnotation;
|
|
|
|
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
2016-02-09 13:59:26 +00:00
|
|
|
};
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
class View2D : public vtkm::rendering::View
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-08 23:20:25 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
View2D(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, backgroundColor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
View2D(const vtkm::rendering::Scene &scene,
|
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, camera, backgroundColor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
template<typename MapperType,
|
|
|
|
typename CanvasType,
|
|
|
|
typename WorldAnnotatorType>
|
2016-05-24 20:34:47 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-02 21:43:30 +00:00
|
|
|
View2D(const vtkm::rendering::Scene &scene,
|
2016-06-06 14:29:17 +00:00
|
|
|
const MapperType &mapper,
|
|
|
|
const CanvasType &canvas,
|
|
|
|
const WorldAnnotatorType annotator,
|
|
|
|
const vtkm::rendering::Camera &camera,
|
|
|
|
const vtkm::rendering::Color &backgroundColor =
|
|
|
|
vtkm::rendering::Color(0,0,0,1))
|
|
|
|
: View(scene, mapper, canvas, annotator, camera, backgroundColor)
|
2016-05-24 20:34:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void Paint()
|
|
|
|
{
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().Activate();
|
|
|
|
this->GetCanvas().Clear();
|
2016-05-24 20:34:47 +00:00
|
|
|
this->SetupForWorldSpace();
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetScene().Render(
|
|
|
|
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
2016-05-24 20:34:47 +00:00
|
|
|
this->RenderWorldAnnotations();
|
|
|
|
|
|
|
|
this->SetupForScreenSpace();
|
|
|
|
this->RenderScreenAnnotations();
|
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCanvas().Finish();
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void RenderScreenAnnotations()
|
|
|
|
{
|
|
|
|
vtkm::Float32 viewportLeft;
|
|
|
|
vtkm::Float32 viewportRight;
|
|
|
|
vtkm::Float32 viewportTop;
|
|
|
|
vtkm::Float32 viewportBottom;
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCamera().GetRealViewport(
|
|
|
|
this->GetCanvas().GetWidth(), this->GetCanvas().GetHeight(),
|
2016-05-24 20:34:47 +00:00
|
|
|
viewportLeft, viewportRight, viewportBottom, viewportTop);
|
|
|
|
|
|
|
|
this->HorizontalAxisAnnotation.SetColor(vtkm::rendering::Color(1,1,1));
|
|
|
|
this->HorizontalAxisAnnotation.SetScreenPosition(
|
|
|
|
viewportLeft, viewportBottom, viewportRight, viewportBottom);
|
2016-06-06 14:29:17 +00:00
|
|
|
vtkm::Bounds viewRange = this->GetCamera().GetViewRange2D();
|
|
|
|
this->HorizontalAxisAnnotation.SetRangeForAutoTicks(viewRange.X.Min,
|
|
|
|
viewRange.X.Max);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetMajorTickSize(0, .05, 1.0);
|
|
|
|
this->HorizontalAxisAnnotation.SetMinorTickSize(0, .02, 1.0);
|
2016-05-31 19:32:56 +00:00
|
|
|
this->HorizontalAxisAnnotation.SetLabelAlignment(TextAnnotation::HCenter,
|
|
|
|
TextAnnotation::Top);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->HorizontalAxisAnnotation.Render(
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
|
|
|
vtkm::Float32 windowaspect =
|
2016-06-06 14:29:17 +00:00
|
|
|
vtkm::Float32(this->GetCanvas().GetWidth()) /
|
|
|
|
vtkm::Float32(this->GetCanvas().GetHeight());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
|
|
|
this->VerticalAxisAnnotation.SetColor(Color(1,1,1));
|
|
|
|
this->VerticalAxisAnnotation.SetScreenPosition(
|
|
|
|
viewportLeft, viewportBottom, viewportLeft, viewportTop);
|
2016-06-06 14:29:17 +00:00
|
|
|
this->VerticalAxisAnnotation.SetRangeForAutoTicks(viewRange.Y.Min,
|
|
|
|
viewRange.Y.Max);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->VerticalAxisAnnotation.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
|
|
|
this->VerticalAxisAnnotation.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
2016-05-31 19:32:56 +00:00
|
|
|
this->VerticalAxisAnnotation.SetLabelAlignment(TextAnnotation::Right,
|
|
|
|
TextAnnotation::VCenter);
|
2016-05-24 20:34:47 +00:00
|
|
|
this->VerticalAxisAnnotation.Render(
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-24 20:34:47 +00:00
|
|
|
|
2016-06-06 14:29:17 +00:00
|
|
|
const vtkm::rendering::Scene &scene = this->GetScene();
|
|
|
|
if (scene.GetNumberOfActors() > 0)
|
2016-05-09 20:32:27 +00:00
|
|
|
{
|
2016-05-31 19:32:56 +00:00
|
|
|
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
2016-08-31 23:28:41 +00:00
|
|
|
this->ColorBarAnnotation.SetRange(scene.GetActor(0).GetScalarRange().Min,
|
|
|
|
scene.GetActor(0).GetScalarRange().Max,
|
2016-05-24 20:34:47 +00:00
|
|
|
5);
|
2016-08-31 23:28:41 +00:00
|
|
|
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
|
2016-05-24 20:34:47 +00:00
|
|
|
this->ColorBarAnnotation.Render(
|
2016-06-06 14:29:17 +00:00
|
|
|
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
2016-05-09 20:32:27 +00:00
|
|
|
}
|
2016-05-24 20:34:47 +00:00
|
|
|
}
|
2016-06-06 14:29:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// 2D-specific annotations
|
|
|
|
vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation;
|
|
|
|
vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation;
|
|
|
|
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
2016-02-09 13:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}} //namespace vtkm::rendering
|
|
|
|
|
2016-06-02 21:43:30 +00:00
|
|
|
#endif //vtk_m_rendering_View_h
|