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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_rendering_Window_h
|
|
|
|
#define vtk_m_rendering_Window_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/rendering/SceneRenderer.h>
|
|
|
|
#include <vtkm/rendering/Color.h>
|
|
|
|
#include <vtkm/rendering/View.h>
|
|
|
|
#include <vtkm/rendering/Scene.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-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-02-09 13:59:26 +00:00
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace rendering {
|
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
template<typename SceneRendererType,
|
|
|
|
typename SurfaceType,
|
|
|
|
typename WorldAnnotatorType>
|
2016-04-18 20:42:59 +00:00
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SceneRendererType sceneRenderer;
|
|
|
|
SurfaceType surface;
|
2016-05-19 14:13:04 +00:00
|
|
|
Color bgColor;
|
2016-04-18 20:42:59 +00:00
|
|
|
vtkm::rendering::View view;
|
2016-05-19 14:13:04 +00:00
|
|
|
WorldAnnotatorType worldAnnotator;
|
2016-04-19 21:04:00 +00:00
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
Window(const SceneRendererType &sr,
|
2016-04-18 20:42:59 +00:00
|
|
|
const SurfaceType &surf,
|
|
|
|
const vtkm::rendering::View &v,
|
|
|
|
const vtkm::rendering::Color &bg=vtkm::rendering::Color(0,0,0,1)) :
|
2016-05-19 14:13:04 +00:00
|
|
|
bgColor(bg), view(v), sceneRenderer(sr), surface(surf)
|
2016-04-18 20:42:59 +00:00
|
|
|
{
|
|
|
|
sceneRenderer.SetBackgroundColor(bgColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void Initialize() {surface.Initialize();}
|
2016-04-18 20:42:59 +00:00
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void Paint() = 0;
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderScreenAnnotations() {}
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RenderWorldAnnotations() {}
|
2016-04-18 20:42:59 +00:00
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SaveAs(const std::string &fileName)
|
|
|
|
{
|
|
|
|
surface.SaveAs(fileName);
|
|
|
|
}
|
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
protected:
|
2016-04-18 20:42:59 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetupForWorldSpace(bool viewportClip=true)
|
|
|
|
{
|
|
|
|
//view.SetupMatrices();
|
2016-05-19 14:13:04 +00:00
|
|
|
surface.SetViewToWorldSpace(view,viewportClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetupForScreenSpace(bool viewportClip=false)
|
|
|
|
{
|
|
|
|
//view.SetupMatrices();
|
|
|
|
surface.SetViewToScreenSpace(view,viewportClip);
|
2016-04-18 20:42:59 +00:00
|
|
|
}
|
|
|
|
};
|
2016-05-19 22:37:37 +00:00
|
|
|
|
2016-02-09 13:59:26 +00:00
|
|
|
// Window2D Window3D
|
2016-04-15 19:24:23 +00:00
|
|
|
template<typename SceneRendererType,
|
|
|
|
typename SurfaceType,
|
|
|
|
typename WorldAnnotatorType>
|
2016-05-19 14:13:04 +00:00
|
|
|
class Window3D : public Window<SceneRendererType, SurfaceType,WorldAnnotatorType>
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
vtkm::rendering::Scene3D scene;
|
2016-04-15 19:24:23 +00:00
|
|
|
// 3D-specific annotations
|
|
|
|
BoundingBoxAnnotation bbox;
|
2016-04-19 21:04:00 +00:00
|
|
|
AxisAnnotation3D xaxis, yaxis, zaxis;
|
2016-05-18 19:29:50 +00:00
|
|
|
ColorBarAnnotation colorbar;
|
2016-04-15 19:24:23 +00:00
|
|
|
|
2016-02-09 13:59:26 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Window3D(const vtkm::rendering::Scene3D &s,
|
|
|
|
const SceneRendererType &sr,
|
|
|
|
const SurfaceType &surf,
|
2016-04-19 13:16:10 +00:00
|
|
|
const vtkm::rendering::View &v,
|
2016-02-09 13:59:26 +00:00
|
|
|
const vtkm::rendering::Color &bg=vtkm::rendering::Color(0,0,0,1)) :
|
2016-05-19 14:13:04 +00:00
|
|
|
Window<SceneRendererType,SurfaceType,WorldAnnotatorType>(sr,surf,v,bg), scene(s)
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void Paint()
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
2016-05-19 14:13:04 +00:00
|
|
|
this->surface.Activate();
|
|
|
|
this->surface.Clear();
|
|
|
|
this->SetupForWorldSpace();
|
|
|
|
scene.Render(this->sceneRenderer, this->surface, this->view);
|
2016-04-15 19:24:23 +00:00
|
|
|
RenderWorldAnnotations();
|
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
this->SetupForScreenSpace();
|
2016-05-09 20:32:27 +00:00
|
|
|
RenderScreenAnnotations();
|
2016-05-19 14:13:04 +00:00
|
|
|
|
|
|
|
this->surface.Finish();
|
2016-02-09 13:59:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:32:27 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void RenderScreenAnnotations()
|
2016-05-09 20:32:27 +00:00
|
|
|
{
|
2016-05-18 19:29:50 +00:00
|
|
|
if (scene.plots.size() > 0)
|
|
|
|
{
|
|
|
|
//colorbar.SetAxisColor(eavlColor::white);
|
2016-05-19 16:49:45 +00:00
|
|
|
colorbar.SetRange(scene.plots[0].scalarBounds[0], scene.plots[0].scalarBounds[1], 5);
|
2016-05-18 19:29:50 +00:00
|
|
|
colorbar.SetColorTable(scene.plots[0].colorTable);
|
2016-05-19 14:13:04 +00:00
|
|
|
colorbar.Render(this->view, this->worldAnnotator, this->surface);
|
2016-05-18 19:29:50 +00:00
|
|
|
}
|
2016-05-09 20:32:27 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 19:24:23 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void RenderWorldAnnotations()
|
2016-04-15 19:24:23 +00:00
|
|
|
{
|
2016-05-19 16:49:45 +00:00
|
|
|
vtkm::Float64 *bnd = scene.GetSpatialBounds();
|
|
|
|
vtkm::Float64 xmin = bnd[0], xmax = bnd[1];
|
|
|
|
vtkm::Float64 ymin = bnd[2], ymax = bnd[3];
|
|
|
|
vtkm::Float64 zmin = bnd[4], zmax = bnd[5];
|
|
|
|
vtkm::Float64 dx = xmax-xmin, dy = ymax-ymin, dz = zmax-zmin;
|
|
|
|
vtkm::Float64 size = vtkm::Sqrt(dx*dx + dy*dy + dz*dz);
|
|
|
|
|
|
|
|
bbox.SetColor(Color(.5f,.5f,.5f));
|
2016-04-15 19:24:23 +00:00
|
|
|
bbox.SetExtents(scene.GetSpatialBounds());
|
2016-05-19 14:13:04 +00:00
|
|
|
bbox.Render(this->view, this->worldAnnotator);
|
2016-04-19 21:04:00 +00:00
|
|
|
|
|
|
|
///\todo: set x/y/ztest based on view
|
|
|
|
bool xtest=true, ytest=false, ztest=false;
|
|
|
|
|
2016-05-19 16:49:45 +00:00
|
|
|
vtkm::Float64 xrel = vtkm::Abs(dx) / size;
|
|
|
|
vtkm::Float64 yrel = vtkm::Abs(dy) / size;
|
|
|
|
vtkm::Float64 zrel = vtkm::Abs(dz) / size;
|
2016-04-19 21:04:00 +00:00
|
|
|
|
|
|
|
xaxis.SetAxis(0);
|
|
|
|
xaxis.SetColor(Color(1,1,1));
|
|
|
|
xaxis.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
xaxis.SetWorldPosition(xmin,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
ztest ? zmin : zmax,
|
|
|
|
xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
ztest ? zmin : zmax);
|
|
|
|
xaxis.SetRange(xmin, xmax);
|
2016-05-05 17:26:39 +00:00
|
|
|
xaxis.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
xaxis.SetMinorTickSize(size / 80.f, 0);
|
2016-04-19 21:04:00 +00:00
|
|
|
xaxis.SetLabelFontScale(size / 30.);
|
|
|
|
xaxis.SetMoreOrLessTickAdjustment(xrel < .3 ? -1 : 0);
|
2016-05-19 14:13:04 +00:00
|
|
|
xaxis.Render(this->view, this->worldAnnotator);
|
2016-04-19 21:04:00 +00:00
|
|
|
|
|
|
|
yaxis.SetAxis(0);
|
|
|
|
yaxis.SetColor(Color(1,1,1));
|
|
|
|
yaxis.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
yaxis.SetWorldPosition(xtest ? xmin : xmax,
|
|
|
|
ymin,
|
|
|
|
ztest ? zmin : zmax,
|
|
|
|
xtest ? xmin : xmax,
|
|
|
|
ymax,
|
|
|
|
ztest ? zmin : zmax);
|
|
|
|
yaxis.SetRange(ymin, ymax);
|
2016-05-05 17:26:39 +00:00
|
|
|
yaxis.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
yaxis.SetMinorTickSize(size / 80.f, 0);
|
2016-04-19 21:04:00 +00:00
|
|
|
yaxis.SetLabelFontScale(size / 30.);
|
|
|
|
yaxis.SetMoreOrLessTickAdjustment(yrel < .3 ? -1 : 0);
|
2016-05-19 14:13:04 +00:00
|
|
|
yaxis.Render(this->view, this->worldAnnotator);
|
2016-04-19 21:04:00 +00:00
|
|
|
|
|
|
|
zaxis.SetAxis(0);
|
|
|
|
zaxis.SetColor(Color(1,1,1));
|
|
|
|
zaxis.SetTickInvert(xtest,ytest,ztest);
|
|
|
|
zaxis.SetWorldPosition(xtest ? xmin : xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
zmin,
|
|
|
|
xtest ? xmin : xmax,
|
|
|
|
ytest ? ymin : ymax,
|
|
|
|
zmax);
|
|
|
|
zaxis.SetRange(zmin, zmax);
|
2016-05-05 17:26:39 +00:00
|
|
|
zaxis.SetMajorTickSize(size / 40.f, 0);
|
|
|
|
zaxis.SetMinorTickSize(size / 80.f, 0);
|
2016-04-19 21:04:00 +00:00
|
|
|
zaxis.SetLabelFontScale(size / 30.);
|
|
|
|
zaxis.SetMoreOrLessTickAdjustment(zrel < .3 ? -1 : 0);
|
2016-05-19 14:13:04 +00:00
|
|
|
zaxis.Render(this->view, this->worldAnnotator);
|
2016-05-09 20:32:27 +00:00
|
|
|
}
|
2016-02-09 13:59:26 +00:00
|
|
|
};
|
|
|
|
|
2016-04-19 13:16:10 +00:00
|
|
|
template<typename SceneRendererType,
|
2016-05-09 20:32:27 +00:00
|
|
|
typename SurfaceType,
|
|
|
|
typename WorldAnnotatorType>
|
2016-05-19 14:13:04 +00:00
|
|
|
class Window2D : public Window<SceneRendererType, SurfaceType,WorldAnnotatorType>
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
vtkm::rendering::Scene2D scene;
|
2016-05-09 20:32:27 +00:00
|
|
|
// 2D-specific annotations
|
|
|
|
AxisAnnotation2D haxis, vaxis;
|
2016-05-18 19:29:50 +00:00
|
|
|
ColorBarAnnotation colorbar;
|
2016-05-09 20:32:27 +00:00
|
|
|
|
2016-02-09 13:59:26 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
Window2D(const vtkm::rendering::Scene2D &s,
|
|
|
|
const SceneRendererType &sr,
|
2016-04-19 13:16:10 +00:00
|
|
|
const SurfaceType &surf,
|
|
|
|
const vtkm::rendering::View &v,
|
2016-02-09 13:59:26 +00:00
|
|
|
const vtkm::rendering::Color &bg=vtkm::rendering::Color(0,0,0,1)) :
|
2016-05-19 14:13:04 +00:00
|
|
|
Window<SceneRendererType,SurfaceType,WorldAnnotatorType>(sr,surf,v,bg), scene(s)
|
2016-04-19 13:16:10 +00:00
|
|
|
{
|
|
|
|
}
|
2016-05-19 14:13:04 +00:00
|
|
|
|
2016-04-19 13:16:10 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-05-19 14:13:04 +00:00
|
|
|
virtual void Paint()
|
2016-04-19 13:16:10 +00:00
|
|
|
{
|
2016-05-19 14:13:04 +00:00
|
|
|
this->surface.Activate();
|
|
|
|
this->surface.Clear();
|
|
|
|
this->SetupForWorldSpace();
|
2016-04-19 13:16:10 +00:00
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
scene.Render(this->sceneRenderer, this->surface, this->view);
|
|
|
|
this->RenderWorldAnnotations();
|
2016-05-09 20:32:27 +00:00
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
this->SetupForScreenSpace();
|
|
|
|
this->RenderScreenAnnotations();
|
2016-04-19 13:16:10 +00:00
|
|
|
|
2016-05-19 14:13:04 +00:00
|
|
|
this->surface.Finish();
|
2016-04-19 13:16:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:32:27 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void RenderScreenAnnotations()
|
|
|
|
{
|
|
|
|
vtkm::Float32 vl, vr, vt, vb;
|
2016-05-19 14:13:04 +00:00
|
|
|
this->view.GetRealViewport(vl,vr,vb,vt);
|
2016-05-09 20:32:27 +00:00
|
|
|
|
|
|
|
haxis.SetColor(Color(1,1,1));
|
|
|
|
haxis.SetScreenPosition(vl,vb, vr,vb);
|
2016-05-20 14:04:37 +00:00
|
|
|
haxis.SetRangeForAutoTicks(this->view.View2d.Left, this->view.View2d.Right);
|
2016-05-09 20:32:27 +00:00
|
|
|
haxis.SetMajorTickSize(0, .05, 1.0);
|
|
|
|
haxis.SetMinorTickSize(0, .02, 1.0);
|
2016-05-20 21:57:56 +00:00
|
|
|
haxis.SetLabelAlignment(TextAnnotation::HCenter,
|
|
|
|
TextAnnotation::Top);
|
2016-05-19 14:13:04 +00:00
|
|
|
haxis.Render(this->view, this->worldAnnotator, this->surface);
|
2016-05-09 20:32:27 +00:00
|
|
|
|
2016-05-20 14:04:37 +00:00
|
|
|
vtkm::Float32 windowaspect = vtkm::Float32(this->view.Width) / vtkm::Float32(this->view.Height);
|
2016-05-09 20:32:27 +00:00
|
|
|
|
|
|
|
vaxis.SetColor(Color(1,1,1));
|
|
|
|
vaxis.SetScreenPosition(vl,vb, vl,vt);
|
2016-05-20 14:04:37 +00:00
|
|
|
vaxis.SetRangeForAutoTicks(this->view.View2d.Bottom, this->view.View2d.Top);
|
2016-05-09 20:32:27 +00:00
|
|
|
vaxis.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
|
|
|
vaxis.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
2016-05-20 21:57:56 +00:00
|
|
|
vaxis.SetLabelAlignment(TextAnnotation::Right,
|
|
|
|
TextAnnotation::VCenter);
|
2016-05-19 14:13:04 +00:00
|
|
|
vaxis.Render(this->view, this->worldAnnotator, this->surface);
|
2016-05-18 19:29:50 +00:00
|
|
|
|
|
|
|
if (scene.plots.size() > 0)
|
|
|
|
{
|
|
|
|
//colorbar.SetAxisColor(eavlColor::white);
|
2016-05-19 16:49:45 +00:00
|
|
|
colorbar.SetRange(scene.plots[0].scalarBounds[0], scene.plots[0].scalarBounds[1], 5);
|
2016-05-18 19:29:50 +00:00
|
|
|
colorbar.SetColorTable(scene.plots[0].colorTable);
|
2016-05-19 14:13:04 +00:00
|
|
|
colorbar.Render(this->view, this->worldAnnotator, this->surface);
|
2016-05-18 19:29:50 +00:00
|
|
|
}
|
2016-05-09 20:32:27 +00:00
|
|
|
}
|
2016-02-09 13:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}} //namespace vtkm::rendering
|
|
|
|
|
|
|
|
#endif //vtk_m_rendering_Window_h
|