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 22:02:17 +00:00
|
|
|
#ifndef vtk_m_rendering_Canvas_h
|
|
|
|
#define vtk_m_rendering_Canvas_h
|
2016-02-09 13:59:26 +00:00
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
2016-06-02 19:04:01 +00:00
|
|
|
#include <vtkm/rendering/Camera.h>
|
2016-02-10 22:06:38 +00:00
|
|
|
#include <vtkm/rendering/Color.h>
|
2016-05-18 19:29:50 +00:00
|
|
|
#include <vtkm/rendering/ColorTable.h>
|
2016-06-08 20:53:32 +00:00
|
|
|
#include <vtkm/rendering/WorldAnnotator.h>
|
2016-02-10 22:06:38 +00:00
|
|
|
|
2016-02-09 13:59:26 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace rendering {
|
|
|
|
|
2016-06-02 22:02:17 +00:00
|
|
|
class Canvas
|
2016-02-09 13:59:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-06-01 17:37:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-05-31 22:40:41 +00:00
|
|
|
Canvas(vtkm::Id width=1024,
|
2016-06-11 18:09:51 +00:00
|
|
|
vtkm::Id height=1024)
|
|
|
|
: Width(0), Height(0)
|
2016-06-01 17:37:03 +00:00
|
|
|
{
|
2016-05-31 22:40:41 +00:00
|
|
|
this->ResizeBuffers(width, height);
|
2016-06-01 17:37:03 +00:00
|
|
|
}
|
2016-02-09 13:59:26 +00:00
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
virtual ~Canvas() { }
|
|
|
|
|
2016-05-31 22:40:41 +00:00
|
|
|
virtual void Initialize() = 0;
|
|
|
|
virtual void Activate() = 0;
|
|
|
|
virtual void Clear() = 0;
|
|
|
|
virtual void Finish() = 0;
|
|
|
|
|
2016-06-05 05:31:10 +00:00
|
|
|
typedef vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,4> > ColorBufferType;
|
|
|
|
typedef vtkm::cont::ArrayHandle<vtkm::Float32> DepthBufferType;
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetWidth() const { return this->Width; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetHeight() const { return this->Height; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const ColorBufferType &GetColorBuffer() const { return this->ColorBuffer; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
ColorBufferType &GetColorBuffer() { return this->ColorBuffer; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
const DepthBufferType &GetDepthBuffer() const { return this->DepthBuffer; }
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
DepthBufferType &GetDepthBuffer() { return this->DepthBuffer; }
|
|
|
|
|
2016-05-31 22:40:41 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ResizeBuffers(vtkm::Id width, vtkm::Id height)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(width >= 0);
|
|
|
|
VTKM_ASSERT(height >= 0);
|
|
|
|
|
|
|
|
vtkm::Id numPixels = width*height;
|
|
|
|
if (this->ColorBuffer.GetNumberOfValues() != numPixels)
|
|
|
|
{
|
|
|
|
this->ColorBuffer.Allocate(numPixels);
|
|
|
|
}
|
|
|
|
if (this->DepthBuffer.GetNumberOfValues() != numPixels)
|
|
|
|
{
|
|
|
|
this->DepthBuffer.Allocate(numPixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->Width = width;
|
|
|
|
this->Height = height;
|
|
|
|
}
|
|
|
|
|
2016-06-05 05:31:10 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-11 18:09:51 +00:00
|
|
|
const vtkm::rendering::Color &GetBackgroundColor() const
|
2016-06-05 05:31:10 +00:00
|
|
|
{
|
|
|
|
return this->BackgroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void SetBackgroundColor(const vtkm::rendering::Color &color)
|
|
|
|
{
|
|
|
|
this->BackgroundColor = color;
|
|
|
|
}
|
|
|
|
|
2016-05-31 22:40:41 +00:00
|
|
|
// If a subclass uses a system that renderers to different buffers, then
|
|
|
|
// these should be overridden to copy the data to the buffers.
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RefreshColorBuffer() { }
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual void RefreshDepthBuffer() { }
|
2016-02-09 13:59:26 +00:00
|
|
|
|
2016-06-01 17:37:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-06 14:29:17 +00:00
|
|
|
virtual void SetViewToWorldSpace(const vtkm::rendering::Camera &, bool) {}
|
2016-06-01 17:37:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-06 14:29:17 +00:00
|
|
|
virtual void SetViewToScreenSpace(const vtkm::rendering::Camera &, bool) {}
|
2016-06-01 17:37:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-06-06 14:29:17 +00:00
|
|
|
void SetViewportClipping(const vtkm::rendering::Camera &, bool) {}
|
2016-02-10 22:06:38 +00:00
|
|
|
|
2016-06-01 17:37:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2016-05-31 22:40:41 +00:00
|
|
|
virtual void SaveAs(const std::string &fileName)
|
|
|
|
{
|
|
|
|
this->RefreshColorBuffer();
|
|
|
|
std::ofstream of(fileName.c_str());
|
|
|
|
of<<"P6"<<std::endl<<this->Width<<" "<<this->Height<<std::endl<<255<<std::endl;
|
|
|
|
ColorBufferType::PortalConstControl colorPortal =
|
|
|
|
this->ColorBuffer.GetPortalConstControl();
|
|
|
|
for (vtkm::Id yIndex=this->Height-1; yIndex>=0; yIndex--)
|
|
|
|
{
|
|
|
|
for (vtkm::Id xIndex=0; xIndex < this->Width; xIndex++)
|
|
|
|
{
|
|
|
|
vtkm::Vec<vtkm::Float32,4> tuple =
|
|
|
|
colorPortal.Get(yIndex*this->Width + xIndex);
|
|
|
|
of<<(unsigned char)(tuple[0]*255);
|
|
|
|
of<<(unsigned char)(tuple[1]*255);
|
|
|
|
of<<(unsigned char)(tuple[2]*255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
}
|
2016-02-09 13:59:26 +00:00
|
|
|
|
2016-06-01 17:37:03 +00:00
|
|
|
virtual void AddLine(vtkm::Float64, vtkm::Float64,
|
|
|
|
vtkm::Float64, vtkm::Float64,
|
|
|
|
vtkm::Float32,
|
2016-06-06 14:29:17 +00:00
|
|
|
const vtkm::rendering::Color &) const {}
|
2016-06-01 17:37:03 +00:00
|
|
|
virtual void AddColorBar(vtkm::Float32, vtkm::Float32,
|
2016-06-02 19:04:01 +00:00
|
|
|
vtkm::Float32, vtkm::Float32,
|
2016-06-01 17:37:03 +00:00
|
|
|
const vtkm::rendering::ColorTable &,
|
2016-06-06 14:29:17 +00:00
|
|
|
bool) const {}
|
2016-06-01 17:37:03 +00:00
|
|
|
virtual void AddText(vtkm::Float32, vtkm::Float32,
|
|
|
|
vtkm::Float32,
|
|
|
|
vtkm::Float32,
|
|
|
|
vtkm::Float32,
|
|
|
|
vtkm::Float32, vtkm::Float32,
|
|
|
|
Color,
|
2016-06-06 14:29:17 +00:00
|
|
|
std::string) const {}
|
2016-05-09 20:32:27 +00:00
|
|
|
|
2016-06-08 20:53:32 +00:00
|
|
|
/// Creates a WorldAnnotator of a type that is paired with this Canvas. Other
|
|
|
|
/// types of world annotators might work, but this provides a default.
|
|
|
|
///
|
|
|
|
/// The WorldAnnotator is created with the C++ new keyword (so it should be
|
|
|
|
/// deleted with delete later). A pointer to the created WorldAnnotator is
|
|
|
|
/// returned.
|
|
|
|
///
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual vtkm::rendering::WorldAnnotator *CreateWorldAnnotator() const
|
|
|
|
{
|
|
|
|
return new vtkm::rendering::WorldAnnotator;
|
|
|
|
}
|
|
|
|
|
2016-06-05 05:31:10 +00:00
|
|
|
private:
|
|
|
|
vtkm::Id Width;
|
|
|
|
vtkm::Id Height;
|
2016-06-01 17:37:03 +00:00
|
|
|
vtkm::rendering::Color BackgroundColor;
|
2016-05-31 22:40:41 +00:00
|
|
|
ColorBufferType ColorBuffer;
|
|
|
|
DepthBufferType DepthBuffer;
|
2016-02-09 13:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}} //namespace vtkm::rendering
|
|
|
|
|
2016-06-02 22:02:17 +00:00
|
|
|
#endif //vtk_m_rendering_Canvas_h
|