mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add View to rendering library
To get rid of some templates, I added the ability to create new instances of mappers and canvases without knowing their type.
This commit is contained in:
parent
26671e9fd6
commit
22c6741152
@ -23,7 +23,7 @@
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
#include <vtkm/rendering/MapperRayTracer.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/ColorTable.h>
|
||||
|
||||
vtkm::rendering::View3D *view = nullptr;
|
||||
|
@ -43,6 +43,8 @@ set(headers
|
||||
TextAnnotationScreen.h
|
||||
Triangulator.h
|
||||
View.h
|
||||
View2D.h
|
||||
View3D.h
|
||||
WorldAnnotator.h
|
||||
)
|
||||
|
||||
@ -66,6 +68,9 @@ set(sources
|
||||
TextAnnotation.cxx
|
||||
TextAnnotationBillboard.cxx
|
||||
TextAnnotationScreen.cxx
|
||||
View.cxx
|
||||
View2D.cxx
|
||||
View3D.cxx
|
||||
WorldAnnotator.cxx
|
||||
|
||||
internal/RunTriangulator.cxx
|
||||
|
@ -35,7 +35,7 @@ Canvas::Canvas(vtkm::Id width, vtkm::Id height)
|
||||
Canvas::~Canvas()
|
||||
{ }
|
||||
|
||||
void Canvas::SaveAs(const std::string &fileName)
|
||||
void Canvas::SaveAs(const std::string &fileName) const
|
||||
{
|
||||
this->RefreshColorBuffer();
|
||||
std::ofstream of(fileName.c_str());
|
||||
|
@ -53,6 +53,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Finish() = 0;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual vtkm::rendering::Canvas *NewCopy() const = 0;
|
||||
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,4> > ColorBufferType;
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::Float32> DepthBufferType;
|
||||
|
||||
@ -109,9 +112,9 @@ public:
|
||||
// If a subclass uses a system that renderers to different buffers, then
|
||||
// these should be overridden to copy the data to the buffers.
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RefreshColorBuffer() { }
|
||||
virtual void RefreshColorBuffer() const { }
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RefreshDepthBuffer() { }
|
||||
virtual void RefreshDepthBuffer() const { }
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void SetViewToWorldSpace(const vtkm::rendering::Camera &, bool) {}
|
||||
@ -121,7 +124,7 @@ public:
|
||||
virtual void SetViewportClipping(const vtkm::rendering::Camera &, bool) {}
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void SaveAs(const std::string &fileName);
|
||||
virtual void SaveAs(const std::string &fileName) const;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void AddLine(const vtkm::Vec<vtkm::Float64,2> &point0,
|
||||
|
@ -121,5 +121,10 @@ void CanvasEGL::Activate()
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas *CanvasEGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasEGL(*this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -53,6 +53,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Activate() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Canvas *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
boost::shared_ptr<detail::CanvasEGLInternals> Internals;
|
||||
};
|
||||
|
@ -66,6 +66,11 @@ void CanvasGL::Finish()
|
||||
glFinish();
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas *CanvasGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasGL(*this);
|
||||
}
|
||||
|
||||
void CanvasGL::SetViewToWorldSpace(const vtkm::rendering::Camera &camera,
|
||||
bool clip)
|
||||
{
|
||||
@ -134,7 +139,7 @@ void CanvasGL::SetViewportClipping(const vtkm::rendering::Camera &camera,
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshColorBuffer()
|
||||
void CanvasGL::RefreshColorBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
@ -143,11 +148,11 @@ void CanvasGL::RefreshColorBuffer()
|
||||
|
||||
glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3],
|
||||
GL_RGBA, GL_FLOAT,
|
||||
&(*vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->GetColorBuffer().GetPortalControl())));
|
||||
const_cast<vtkm::Vec<float,4> *>(
|
||||
this->GetColorBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::RefreshDepthBuffer()
|
||||
void CanvasGL::RefreshDepthBuffer() const
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
@ -156,8 +161,8 @@ void CanvasGL::RefreshDepthBuffer()
|
||||
|
||||
glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3],
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT,
|
||||
&(*vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->GetDepthBuffer().GetPortalControl())));
|
||||
const_cast<vtkm::Float32 *>(
|
||||
this->GetDepthBuffer().GetStorage().GetArray()));
|
||||
}
|
||||
|
||||
void CanvasGL::AddLine(const vtkm::Vec<vtkm::Float64,2> &point0,
|
||||
|
@ -48,6 +48,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Finish() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Canvas *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetViewToWorldSpace(const vtkm::rendering::Camera &camera,
|
||||
bool clip) VTKM_OVERRIDE;
|
||||
@ -61,10 +64,10 @@ public:
|
||||
bool clip) VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void RefreshColorBuffer() VTKM_OVERRIDE;
|
||||
void RefreshColorBuffer() const VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RefreshDepthBuffer() VTKM_OVERRIDE;
|
||||
virtual void RefreshDepthBuffer() const VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void AddLine(const vtkm::Vec<vtkm::Float64,2> &point0,
|
||||
|
@ -71,7 +71,7 @@ void CanvasOSMesa::Initialize()
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasOSMesa::RefreshColorBuffer()
|
||||
void CanvasOSMesa::RefreshColorBuffer() const
|
||||
{
|
||||
// Override superclass because our OSMesa implementation renders right
|
||||
// to the color buffer.
|
||||
@ -110,5 +110,10 @@ void CanvasOSMesa::Finish()
|
||||
#endif
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas *CanvasOSMesa::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasOSMesa(*this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
virtual void Initialize() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RefreshColorBuffer() VTKM_OVERRIDE;
|
||||
virtual void RefreshColorBuffer() const VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Activate() VTKM_OVERRIDE;
|
||||
@ -59,6 +59,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Finish() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Canvas *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
boost::shared_ptr<detail::CanvasOSMesaInternals> Internals;
|
||||
};
|
||||
|
@ -113,6 +113,11 @@ void CanvasRayTracer::Clear()
|
||||
this->GetDepthBuffer()));
|
||||
}
|
||||
|
||||
vtkm::rendering::Canvas *CanvasRayTracer::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::CanvasRayTracer(*this);
|
||||
}
|
||||
|
||||
void CanvasRayTracer::AddLine(const vtkm::Vec<vtkm::Float64,2> &,
|
||||
const vtkm::Vec<vtkm::Float64,2> &,
|
||||
vtkm::Float32,
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Clear() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Canvas *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void AddLine(const vtkm::Vec<vtkm::Float64,2> &point0,
|
||||
const vtkm::Vec<vtkm::Float64,2> &point1,
|
||||
|
@ -56,6 +56,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void SetCanvas(vtkm::rendering::Canvas *canvas) = 0;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual vtkm::rendering::Mapper *NewCopy() const = 0;
|
||||
|
||||
protected:
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,4> > ColorMap;
|
||||
};
|
||||
|
@ -140,5 +140,10 @@ void MapperGL::SetCanvas(vtkm::rendering::Canvas *)
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
vtkm::rendering::Mapper *MapperGL::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::MapperGL(*this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
void EndScene() VTKM_OVERRIDE;
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetCanvas(vtkm::rendering::Canvas *canvas) VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Mapper *NewCopy() const VTKM_OVERRIDE;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -187,6 +187,11 @@ void MapperRayTracer::EndScene()
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
vtkm::rendering::Mapper *MapperRayTracer::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::MapperRayTracer(*this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // vtkm::rendering
|
||||
|
@ -53,6 +53,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void EndScene() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Mapper *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
boost::shared_ptr<InternalsType> Internals;
|
||||
|
@ -192,5 +192,10 @@ void MapperVolume::EndScene()
|
||||
// Nothing needs to be done.
|
||||
}
|
||||
|
||||
vtkm::rendering::Mapper *MapperVolume::NewCopy() const
|
||||
{
|
||||
return new vtkm::rendering::MapperVolume(*this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -51,6 +51,9 @@ public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void EndScene() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::rendering::Mapper *NewCopy() const VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
boost::shared_ptr<InternalsType> Internals;
|
||||
|
@ -39,6 +39,15 @@ struct TextureGL::InternalsType
|
||||
InternalsType()
|
||||
: Id(0), Dimension(0), MIPMap(false), Linear2D(true), LinearMIP(true)
|
||||
{ }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
~InternalsType()
|
||||
{
|
||||
if (this->Id != 0)
|
||||
{
|
||||
glDeleteTextures(1, &this->Id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TextureGL::TextureGL()
|
||||
@ -46,13 +55,7 @@ TextureGL::TextureGL()
|
||||
{ }
|
||||
|
||||
TextureGL::~TextureGL()
|
||||
{
|
||||
if (this->Internals->Id != 0)
|
||||
{
|
||||
glDeleteTextures(1, &this->Internals->Id);
|
||||
}
|
||||
delete this->Internals;
|
||||
}
|
||||
{ }
|
||||
|
||||
bool TextureGL::Valid() const
|
||||
{
|
||||
|
@ -28,13 +28,15 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/shared_ptr.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class TextureGL
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
VTKM_RENDERING_EXPORT
|
||||
TextureGL();
|
||||
@ -57,11 +59,8 @@ public:
|
||||
const std::vector<unsigned char> &rgba);
|
||||
|
||||
private:
|
||||
TextureGL(const TextureGL &); // Not implemented
|
||||
void operator=(const TextureGL &); // Not implemented
|
||||
|
||||
struct InternalsType;
|
||||
InternalsType *Internals;
|
||||
boost::shared_ptr<InternalsType> Internals;
|
||||
};
|
||||
|
||||
|
||||
|
89
vtkm/rendering/View.cxx
Normal file
89
vtkm/rendering/View.cxx
Normal file
@ -0,0 +1,89 @@
|
||||
//============================================================================
|
||||
// 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 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/View.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
View::View(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Color &backgroundColor)
|
||||
: Scene(scene),
|
||||
MapperPointer(mapper.NewCopy()),
|
||||
CanvasPointer(canvas.NewCopy()),
|
||||
WorldAnnotatorPointer(canvas.CreateWorldAnnotator())
|
||||
{
|
||||
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
||||
|
||||
vtkm::Bounds spatialBounds = this->Scene.GetSpatialBounds();
|
||||
this->Camera.ResetToBounds(spatialBounds);
|
||||
if (spatialBounds.Z.Length() > 0.0)
|
||||
{
|
||||
this->Camera.SetModeTo3D();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Camera.SetModeTo2D();
|
||||
}
|
||||
}
|
||||
|
||||
View::View(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::Color &backgroundColor)
|
||||
: Scene(scene),
|
||||
MapperPointer(mapper.NewCopy()),
|
||||
CanvasPointer(canvas.NewCopy()),
|
||||
WorldAnnotatorPointer(canvas.CreateWorldAnnotator()),
|
||||
Camera(camera)
|
||||
{
|
||||
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{ }
|
||||
|
||||
void View::Initialize()
|
||||
{
|
||||
this->GetCanvas().Initialize();
|
||||
}
|
||||
|
||||
void View::SaveAs(const std::string &fileName) const
|
||||
{
|
||||
this->GetCanvas().SaveAs(fileName);
|
||||
}
|
||||
|
||||
void View::SetupForWorldSpace(bool viewportClip)
|
||||
{
|
||||
//this->Camera.SetupMatrices();
|
||||
this->GetCanvas().SetViewToWorldSpace(this->Camera ,viewportClip);
|
||||
}
|
||||
|
||||
void View::SetupForScreenSpace(bool viewportClip)
|
||||
{
|
||||
//this->Camera.SetupMatrices();
|
||||
this->GetCanvas().SetViewToScreenSpace(this->Camera,viewportClip);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -20,14 +20,12 @@
|
||||
#ifndef vtk_m_rendering_View_h
|
||||
#define vtk_m_rendering_View_h
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/rendering/BoundingBoxAnnotation.h>
|
||||
#include <vtkm/rendering/AxisAnnotation3D.h>
|
||||
#include <vtkm/rendering/AxisAnnotation2D.h>
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/ColorBarAnnotation.h>
|
||||
#include <vtkm/rendering/TextAnnotation.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
|
||||
namespace vtkm {
|
||||
@ -36,74 +34,23 @@ namespace rendering {
|
||||
class View
|
||||
{
|
||||
public:
|
||||
template<typename MapperType,
|
||||
typename CanvasType>
|
||||
VTKM_RENDERING_EXPORT
|
||||
View(const vtkm::rendering::Scene &scene,
|
||||
const MapperType &mapper,
|
||||
const CanvasType &canvas,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Color &backgroundColor =
|
||||
vtkm::rendering::Color(0,0,0,1))
|
||||
: Scene(scene),
|
||||
MapperPointer(new MapperType(mapper)),
|
||||
CanvasPointer(new CanvasType(canvas))
|
||||
{
|
||||
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
||||
this->WorldAnnotatorPointer = this->CanvasPointer->CreateWorldAnnotator();
|
||||
vtkm::rendering::Color(0,0,0,1));
|
||||
|
||||
vtkm::Bounds spatialBounds = this->Scene.GetSpatialBounds();
|
||||
this->Camera.ResetToBounds(spatialBounds);
|
||||
if (spatialBounds.Z.Length() > 0.0)
|
||||
{
|
||||
this->Camera.SetModeTo3D();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Camera.SetModeTo2D();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MapperType,
|
||||
typename CanvasType>
|
||||
VTKM_RENDERING_EXPORT
|
||||
View(const vtkm::rendering::Scene &scene,
|
||||
const MapperType &mapper,
|
||||
const CanvasType &canvas,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &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)),
|
||||
Camera(camera)
|
||||
{
|
||||
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
||||
this->WorldAnnotatorPointer = this->CanvasPointer->CreateWorldAnnotator();
|
||||
}
|
||||
vtkm::rendering::Color(0,0,0,1));
|
||||
|
||||
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)),
|
||||
Camera(camera)
|
||||
{
|
||||
this->CanvasPointer->SetBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
virtual ~View()
|
||||
{
|
||||
delete this->MapperPointer;
|
||||
delete this->CanvasPointer;
|
||||
delete this->WorldAnnotatorPointer;
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual ~View();
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::rendering::Scene &GetScene() const { return this->Scene; }
|
||||
@ -168,330 +115,35 @@ public:
|
||||
this->CanvasPointer->SetBackgroundColor(color);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Initialize() {this->GetCanvas().Initialize();}
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Initialize();
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void Paint() = 0;
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void RenderScreenAnnotations() {}
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void RenderWorldAnnotations() {}
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RenderScreenAnnotations() = 0;
|
||||
VTKM_RENDERING_EXPORT
|
||||
virtual void RenderWorldAnnotations() = 0;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void SaveAs(const std::string &fileName)
|
||||
{
|
||||
this->GetCanvas().SaveAs(fileName);
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SaveAs(const std::string &fileName) const;
|
||||
|
||||
protected:
|
||||
VTKM_CONT_EXPORT
|
||||
void SetupForWorldSpace(bool viewportClip=true)
|
||||
{
|
||||
//this->Camera.SetupMatrices();
|
||||
this->GetCanvas().SetViewToWorldSpace(this->Camera,viewportClip);
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetupForWorldSpace(bool viewportClip=true);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void SetupForScreenSpace(bool viewportClip=false)
|
||||
{
|
||||
//this->Camera.SetupMatrices();
|
||||
this->GetCanvas().SetViewToScreenSpace(this->Camera,viewportClip);
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void SetupForScreenSpace(bool viewportClip=false);
|
||||
|
||||
private:
|
||||
vtkm::rendering::Scene Scene;
|
||||
vtkm::rendering::Mapper *MapperPointer;
|
||||
vtkm::rendering::Canvas *CanvasPointer;
|
||||
vtkm::rendering::WorldAnnotator *WorldAnnotatorPointer;
|
||||
boost::shared_ptr<vtkm::rendering::Mapper> MapperPointer;
|
||||
boost::shared_ptr<vtkm::rendering::Canvas> CanvasPointer;
|
||||
boost::shared_ptr<vtkm::rendering::WorldAnnotator> WorldAnnotatorPointer;
|
||||
vtkm::rendering::Camera Camera;
|
||||
};
|
||||
|
||||
// View2D View3D
|
||||
class View3D : public vtkm::rendering::View
|
||||
{
|
||||
public:
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename MapperType,
|
||||
typename CanvasType,
|
||||
typename WorldAnnotatorType>
|
||||
VTKM_CONT_EXPORT
|
||||
View3D(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))
|
||||
: View(scene, mapper, canvas, annotator, camera, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
this->GetScene().Render(
|
||||
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void RenderScreenAnnotations()
|
||||
{
|
||||
if (this->GetScene().GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
|
||||
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void 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;
|
||||
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));
|
||||
this->BoxAnnotation.SetExtents(this->GetScene().GetSpatialBounds());
|
||||
this->BoxAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator());
|
||||
|
||||
vtkm::Vec<vtkm::Float32,3> lookAt = this->GetCamera().GetLookAt();
|
||||
vtkm::Vec<vtkm::Float32,3> position = this->GetCamera().GetPosition();
|
||||
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);
|
||||
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);
|
||||
this->XAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->XAxisAnnotation.SetMoreOrLessTickAdjustment(xrel < .3 ? -1 : 0);
|
||||
this->XAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
this->YAxisAnnotation.SetAxis(1);
|
||||
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);
|
||||
this->YAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->YAxisAnnotation.SetMoreOrLessTickAdjustment(yrel < .3 ? -1 : 0);
|
||||
this->YAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
this->ZAxisAnnotation.SetAxis(2);
|
||||
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);
|
||||
this->ZAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->ZAxisAnnotation.SetMoreOrLessTickAdjustment(zrel < .3 ? -1 : 0);
|
||||
this->ZAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
|
||||
private:
|
||||
// 3D-specific annotations
|
||||
vtkm::rendering::BoundingBoxAnnotation BoxAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D XAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D YAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D ZAxisAnnotation;
|
||||
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
||||
};
|
||||
|
||||
class View2D : public vtkm::rendering::View
|
||||
{
|
||||
public:
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename MapperType,
|
||||
typename CanvasType,
|
||||
typename WorldAnnotatorType>
|
||||
VTKM_CONT_EXPORT
|
||||
View2D(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))
|
||||
: View(scene, mapper, canvas, annotator, camera, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
|
||||
this->GetScene().Render(
|
||||
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void RenderScreenAnnotations()
|
||||
{
|
||||
vtkm::Float32 viewportLeft;
|
||||
vtkm::Float32 viewportRight;
|
||||
vtkm::Float32 viewportTop;
|
||||
vtkm::Float32 viewportBottom;
|
||||
this->GetCamera().GetRealViewport(
|
||||
this->GetCanvas().GetWidth(), this->GetCanvas().GetHeight(),
|
||||
viewportLeft, viewportRight, viewportBottom, viewportTop);
|
||||
|
||||
this->HorizontalAxisAnnotation.SetColor(vtkm::rendering::Color(1,1,1));
|
||||
this->HorizontalAxisAnnotation.SetScreenPosition(
|
||||
viewportLeft, viewportBottom, viewportRight, viewportBottom);
|
||||
vtkm::Bounds viewRange = this->GetCamera().GetViewRange2D();
|
||||
this->HorizontalAxisAnnotation.SetRangeForAutoTicks(viewRange.X.Min,
|
||||
viewRange.X.Max);
|
||||
this->HorizontalAxisAnnotation.SetMajorTickSize(0, .05, 1.0);
|
||||
this->HorizontalAxisAnnotation.SetMinorTickSize(0, .02, 1.0);
|
||||
this->HorizontalAxisAnnotation.SetLabelAlignment(TextAnnotation::HCenter,
|
||||
TextAnnotation::Top);
|
||||
this->HorizontalAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
vtkm::Float32 windowaspect =
|
||||
vtkm::Float32(this->GetCanvas().GetWidth()) /
|
||||
vtkm::Float32(this->GetCanvas().GetHeight());
|
||||
|
||||
this->VerticalAxisAnnotation.SetColor(Color(1,1,1));
|
||||
this->VerticalAxisAnnotation.SetScreenPosition(
|
||||
viewportLeft, viewportBottom, viewportLeft, viewportTop);
|
||||
this->VerticalAxisAnnotation.SetRangeForAutoTicks(viewRange.Y.Min,
|
||||
viewRange.Y.Max);
|
||||
this->VerticalAxisAnnotation.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
||||
this->VerticalAxisAnnotation.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
||||
this->VerticalAxisAnnotation.SetLabelAlignment(TextAnnotation::Right,
|
||||
TextAnnotation::VCenter);
|
||||
this->VerticalAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
const vtkm::rendering::Scene &scene = this->GetScene();
|
||||
if (scene.GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(scene.GetActor(0).GetScalarRange().Min,
|
||||
scene.GetActor(0).GetScalarRange().Max,
|
||||
5);
|
||||
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// 2D-specific annotations
|
||||
vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation;
|
||||
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
}
|
||||
} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_View_h
|
||||
|
100
vtkm/rendering/View2D.cxx
Normal file
100
vtkm/rendering/View2D.cxx
Normal file
@ -0,0 +1,100 @@
|
||||
//============================================================================
|
||||
// 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 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
void View2D::Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
|
||||
this->GetScene().Render(
|
||||
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
void View2D::RenderScreenAnnotations()
|
||||
{
|
||||
vtkm::Float32 viewportLeft;
|
||||
vtkm::Float32 viewportRight;
|
||||
vtkm::Float32 viewportTop;
|
||||
vtkm::Float32 viewportBottom;
|
||||
this->GetCamera().GetRealViewport(
|
||||
this->GetCanvas().GetWidth(), this->GetCanvas().GetHeight(),
|
||||
viewportLeft, viewportRight, viewportBottom, viewportTop);
|
||||
|
||||
this->HorizontalAxisAnnotation.SetColor(vtkm::rendering::Color(1,1,1));
|
||||
this->HorizontalAxisAnnotation.SetScreenPosition(
|
||||
viewportLeft, viewportBottom, viewportRight, viewportBottom);
|
||||
vtkm::Bounds viewRange = this->GetCamera().GetViewRange2D();
|
||||
this->HorizontalAxisAnnotation.SetRangeForAutoTicks(viewRange.X.Min,
|
||||
viewRange.X.Max);
|
||||
this->HorizontalAxisAnnotation.SetMajorTickSize(0, .05, 1.0);
|
||||
this->HorizontalAxisAnnotation.SetMinorTickSize(0, .02, 1.0);
|
||||
this->HorizontalAxisAnnotation.SetLabelAlignment(TextAnnotation::HCenter,
|
||||
TextAnnotation::Top);
|
||||
this->HorizontalAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
vtkm::Float32 windowaspect =
|
||||
vtkm::Float32(this->GetCanvas().GetWidth()) /
|
||||
vtkm::Float32(this->GetCanvas().GetHeight());
|
||||
|
||||
this->VerticalAxisAnnotation.SetColor(Color(1,1,1));
|
||||
this->VerticalAxisAnnotation.SetScreenPosition(
|
||||
viewportLeft, viewportBottom, viewportLeft, viewportTop);
|
||||
this->VerticalAxisAnnotation.SetRangeForAutoTicks(viewRange.Y.Min,
|
||||
viewRange.Y.Max);
|
||||
this->VerticalAxisAnnotation.SetMajorTickSize(.05 / windowaspect, 0, 1.0);
|
||||
this->VerticalAxisAnnotation.SetMinorTickSize(.02 / windowaspect, 0, 1.0);
|
||||
this->VerticalAxisAnnotation.SetLabelAlignment(TextAnnotation::Right,
|
||||
TextAnnotation::VCenter);
|
||||
this->VerticalAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
const vtkm::rendering::Scene &scene = this->GetScene();
|
||||
if (scene.GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(scene.GetActor(0).GetScalarRange().Min,
|
||||
scene.GetActor(0).GetScalarRange().Max,
|
||||
5);
|
||||
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
void View2D::RenderWorldAnnotations()
|
||||
{
|
||||
// 2D views don't have world annotations.
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
74
vtkm/rendering/View2D.h
Normal file
74
vtkm/rendering/View2D.h
Normal file
@ -0,0 +1,74 @@
|
||||
//============================================================================
|
||||
// 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 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 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_View2D_h
|
||||
#define vtk_m_rendering_View2D_h
|
||||
|
||||
#include <vtkm/rendering/View.h>
|
||||
|
||||
#include <vtkm/rendering/AxisAnnotation2D.h>
|
||||
#include <vtkm/rendering/ColorBarAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class View2D : public vtkm::rendering::View
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
View2D(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Color &backgroundColor =
|
||||
vtkm::rendering::Color(0,0,0,1))
|
||||
: View(scene, mapper, canvas, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
View2D(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::Color &backgroundColor =
|
||||
vtkm::rendering::Color(0,0,0,1))
|
||||
: View(scene, mapper, canvas, camera, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Paint() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void RenderScreenAnnotations() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void RenderWorldAnnotations() VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
// 2D-specific annotations
|
||||
vtkm::rendering::AxisAnnotation2D HorizontalAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation2D VerticalAxisAnnotation;
|
||||
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_View2D_h
|
138
vtkm/rendering/View3D.cxx
Normal file
138
vtkm/rendering/View3D.cxx
Normal file
@ -0,0 +1,138 @@
|
||||
//============================================================================
|
||||
// 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 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
void View3D::Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
this->GetScene().Render(
|
||||
this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
void View3D::RenderScreenAnnotations()
|
||||
{
|
||||
if (this->GetScene().GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(
|
||||
this->GetScene().GetActor(0).GetScalarRange(), 5);
|
||||
this->ColorBarAnnotation.SetColorTable(
|
||||
this->GetScene().GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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));
|
||||
this->BoxAnnotation.SetExtents(this->GetScene().GetSpatialBounds());
|
||||
this->BoxAnnotation.Render(this->GetCamera(), this->GetWorldAnnotator());
|
||||
|
||||
vtkm::Vec<vtkm::Float32,3> lookAt = this->GetCamera().GetLookAt();
|
||||
vtkm::Vec<vtkm::Float32,3> position = this->GetCamera().GetPosition();
|
||||
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);
|
||||
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);
|
||||
this->XAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->XAxisAnnotation.SetMoreOrLessTickAdjustment(xrel < .3 ? -1 : 0);
|
||||
this->XAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
this->YAxisAnnotation.SetAxis(1);
|
||||
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);
|
||||
this->YAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->YAxisAnnotation.SetMoreOrLessTickAdjustment(yrel < .3 ? -1 : 0);
|
||||
this->YAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
|
||||
this->ZAxisAnnotation.SetAxis(2);
|
||||
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);
|
||||
this->ZAxisAnnotation.SetLabelFontOffset(vtkm::Float32(size / 15.f));
|
||||
this->ZAxisAnnotation.SetMoreOrLessTickAdjustment(zrel < .3 ? -1 : 0);
|
||||
this->ZAxisAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
77
vtkm/rendering/View3D.h
Normal file
77
vtkm/rendering/View3D.h
Normal file
@ -0,0 +1,77 @@
|
||||
//============================================================================
|
||||
// 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 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 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_View3D_h
|
||||
#define vtk_m_rendering_View3D_h
|
||||
|
||||
#include <vtkm/rendering/View.h>
|
||||
|
||||
#include <vtkm/rendering/AxisAnnotation3D.h>
|
||||
#include <vtkm/rendering/BoundingBoxAnnotation.h>
|
||||
#include <vtkm/rendering/ColorBarAnnotation.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class View3D : public vtkm::rendering::View
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
View3D(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Color &backgroundColor =
|
||||
vtkm::rendering::Color(0,0,0,1))
|
||||
: View(scene, mapper, canvas, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
View3D(const vtkm::rendering::Scene &scene,
|
||||
const vtkm::rendering::Mapper &mapper,
|
||||
const vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera,
|
||||
const vtkm::rendering::Color &backgroundColor =
|
||||
vtkm::rendering::Color(0,0,0,1))
|
||||
: View(scene, mapper, canvas, camera, backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Paint() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void RenderScreenAnnotations() VTKM_OVERRIDE;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
void RenderWorldAnnotations() VTKM_OVERRIDE;
|
||||
|
||||
private:
|
||||
// 3D-specific annotations
|
||||
vtkm::rendering::BoundingBoxAnnotation BoxAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D XAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D YAxisAnnotation;
|
||||
vtkm::rendering::AxisAnnotation3D ZAxisAnnotation;
|
||||
vtkm::rendering::ColorBarAnnotation ColorBarAnnotation;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_View3D_h
|
@ -27,7 +27,8 @@
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
|
||||
namespace vtkm {
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
#include <vtkm/rendering/MapperRayTracer.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
#include <vtkm/rendering/MapperVolume.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include <vtkm/rendering/CanvasEGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
@ -24,7 +24,8 @@
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include <vtkm/rendering/CanvasOSMesa.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
Loading…
Reference in New Issue
Block a user