mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Consolidate functionality in Canvas classes
Move some of the management of the width, height, and buffers to the base Canvas class. Also, when it makes sense, get the width and height from the rendering system. Also changed the color buffer to be a Vec so that you don't have to manage array offsets by hand. All of these changes snowballed from the observation that the glut example did not properly enable the depth buffer.
This commit is contained in:
parent
c613145706
commit
b01e8391b4
@ -167,7 +167,7 @@ main(int argc, char* argv[])
|
||||
Set3DView(camera, coords, W, H);
|
||||
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasGL surface(W,H,bg);
|
||||
vtkm::rendering::CanvasGL canvas(bg);
|
||||
vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
@ -180,7 +180,7 @@ main(int argc, char* argv[])
|
||||
view = new vtkm::rendering::View3D<vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
|
||||
vtkm::rendering::CanvasGL,
|
||||
vtkm::rendering::WorldAnnotatorGL>(scene, mapper,
|
||||
surface, camera, bg);
|
||||
canvas, camera, bg);
|
||||
view->Initialize();
|
||||
glutMainLoop();
|
||||
|
||||
|
@ -50,10 +50,6 @@ set(opengl_headers
|
||||
WorldAnnotatorGL.h
|
||||
)
|
||||
|
||||
set(glx_headers
|
||||
CanvasGLX.h
|
||||
)
|
||||
|
||||
set(osmesa_headers
|
||||
CanvasOSMesa.h
|
||||
)
|
||||
@ -63,13 +59,10 @@ set(includes)
|
||||
if(OPENGL_FOUND)
|
||||
set(headers ${headers} ${opengl_headers})
|
||||
|
||||
# Is there a better check for GLX?
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(headers ${headers} ${glx_headers})
|
||||
|
||||
find_package(MESA)
|
||||
if (OSMESA_FOUND)
|
||||
set(headers ${headers} ${glx_headers})
|
||||
set(headers ${headers} ${osmesa_headers})
|
||||
list(APPEND includes ${OSMESA_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
@ -35,24 +35,50 @@ class Canvas
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
Canvas(std::size_t width=1024,
|
||||
std::size_t height=1024,
|
||||
Canvas(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024,
|
||||
const vtkm::rendering::Color &color =
|
||||
vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: Width(width), Height(height), BackgroundColor(color)
|
||||
: Width(0), Height(0), BackgroundColor(color)
|
||||
{
|
||||
this->ColorBuffer.resize(width*height*4);
|
||||
this->DepthBuffer.resize(width*height);
|
||||
this->ResizeBuffers(width, height);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Initialize() {}
|
||||
virtual void Initialize() = 0;
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Activate() {}
|
||||
virtual void Activate() = 0;
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear() {}
|
||||
virtual void Clear() = 0;
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Finish() {}
|
||||
virtual void Finish() = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 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() { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void SetViewToWorldSpace(vtkm::rendering::Camera &, bool) {}
|
||||
@ -62,7 +88,26 @@ public:
|
||||
void SetViewportClipping(vtkm::rendering::Camera &, bool) {}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void SaveAs(const std::string &) {}
|
||||
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();
|
||||
}
|
||||
|
||||
virtual void AddLine(vtkm::Float64, vtkm::Float64,
|
||||
vtkm::Float64, vtkm::Float64,
|
||||
@ -80,10 +125,13 @@ public:
|
||||
Color,
|
||||
std::string) {}
|
||||
|
||||
std::size_t Width, Height;
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,4> > ColorBufferType;
|
||||
typedef vtkm::cont::ArrayHandle<vtkm::Float32> DepthBufferType;
|
||||
|
||||
vtkm::Id Width, Height;
|
||||
vtkm::rendering::Color BackgroundColor;
|
||||
std::vector<vtkm::Float32> ColorBuffer;
|
||||
std::vector<vtkm::Float32> DepthBuffer;
|
||||
ColorBufferType ColorBuffer;
|
||||
DepthBufferType DepthBuffer;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -40,14 +40,28 @@ class CanvasGL : public Canvas
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasGL(std::size_t w=1024,
|
||||
std::size_t h=1024,
|
||||
const vtkm::rendering::Color &c =
|
||||
CanvasGL(const vtkm::rendering::Color &c =
|
||||
vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: Canvas(w,h,c)
|
||||
: Canvas(0,0,c)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Initialize()
|
||||
{
|
||||
// Nothing to initialize
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Activate()
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
this->ResizeBuffers(viewport[2], viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
{
|
||||
@ -57,6 +71,7 @@ public:
|
||||
1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Finish()
|
||||
{
|
||||
@ -125,23 +140,30 @@ public:
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void SaveAs(const std::string &fileName)
|
||||
virtual void RefreshColorBuffer()
|
||||
{
|
||||
std::ofstream of(fileName.c_str());
|
||||
of << "P6" << std::endl
|
||||
<< this->Width << " " << this->Height <<std::endl
|
||||
<< 255 << std::endl;
|
||||
int height = static_cast<int>(this->Height);
|
||||
for (int yIndex=height-1; yIndex>=0; yIndex--)
|
||||
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
|
||||
{
|
||||
const vtkm::Float32 *tuple =
|
||||
&(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
|
||||
of<<(unsigned char)(tuple[0]*255);
|
||||
of<<(unsigned char)(tuple[1]*255);
|
||||
of<<(unsigned char)(tuple[2]*255);
|
||||
}
|
||||
of.close();
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->Width);
|
||||
VTKM_ASSERT(viewport[3] == this->Height);
|
||||
|
||||
glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3],
|
||||
GL_RGBA, GL_FLOAT,
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->ColorBuffer.GetPortalControl()));
|
||||
}
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void RefreshDepthBuffer()
|
||||
{
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
VTKM_ASSERT(viewport[2] == this->Width);
|
||||
VTKM_ASSERT(viewport[3] == this->Height);
|
||||
|
||||
glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3],
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT,
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(
|
||||
this->DepthBuffer.GetPortalControl()));
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -152,7 +174,7 @@ public:
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor3fv(c.Components);
|
||||
glColor3f(c.Components[0], c.Components[1], c.Components[2]);
|
||||
|
||||
glLineWidth(linewidth);
|
||||
|
||||
@ -184,10 +206,10 @@ public:
|
||||
vtkm::Float32 x1 = x + w*v1;
|
||||
vtkm::Float32 y0 = y;
|
||||
vtkm::Float32 y1 = y + h;
|
||||
glColor3fv(c0.Components);
|
||||
glColor3f(c0.Components[0], c0.Components[1], c0.Components[2]);
|
||||
glVertex2f(x0,y0);
|
||||
glVertex2f(x0,y1);
|
||||
glColor3fv(c1.Components);
|
||||
glColor3f(c1.Components[0], c1.Components[1], c1.Components[2]);
|
||||
glVertex2f(x1,y1);
|
||||
glVertex2f(x1,y0);
|
||||
}
|
||||
@ -197,10 +219,10 @@ public:
|
||||
vtkm::Float32 x1 = x + w;
|
||||
vtkm::Float32 y0 = y + h*v0;
|
||||
vtkm::Float32 y1 = y + h*v1;
|
||||
glColor3fv(c0.Components);
|
||||
glColor3f(c0.Components[0], c0.Components[1], c0.Components[2]);
|
||||
glVertex2f(x0,y1);
|
||||
glVertex2f(x1,y1);
|
||||
glColor3fv(c1.Components);
|
||||
glColor3f(c1.Components[0], c1.Components[1], c1.Components[2]);
|
||||
glVertex2f(x1,y0);
|
||||
glVertex2f(x0,y0);
|
||||
}
|
||||
@ -222,7 +244,7 @@ public:
|
||||
glTranslatef(x,y,0);
|
||||
glScalef(1.f/windowaspect, 1, 1);
|
||||
glRotatef(angle, 0,0,1);
|
||||
glColor3fv(color.Components);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
RenderText(scale, anchorx, anchory, text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
//============================================================================
|
||||
// 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_CanvasGLX_h
|
||||
#define vtk_m_rendering_CanvasGLX_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
class CanvasGLX : public CanvasGL
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasGLX(std::size_t w=1024,
|
||||
std::size_t h=1024,
|
||||
const vtkm::rendering::Color &c =
|
||||
vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: CanvasGL(w,h,c)
|
||||
{
|
||||
ctx = NULL;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Initialize()
|
||||
{
|
||||
ctx = glXGetCurrentContext();
|
||||
if (!ctx)
|
||||
throw vtkm::cont::ErrorControlBadValue("GL context creation failed.");
|
||||
/*
|
||||
rgba.resize(width*height*4);
|
||||
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)))
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
|
||||
*/
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
{
|
||||
glClearColor(this->BackgroundColor.Components[0],
|
||||
this->BackgroundColor.Components[1],
|
||||
this->BackgroundColor.Components[2], 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Finish()
|
||||
{
|
||||
CanvasGL::Finish();
|
||||
|
||||
|
||||
/* TODO
|
||||
//Copy zbuff into floating point array.
|
||||
unsigned int *raw_zbuff;
|
||||
int zbytes, w, h;
|
||||
GLboolean ret;
|
||||
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
|
||||
if (!ret || static_cast<std::size_t>(w)!=width || static_cast<std::size_t>(h)!=height)
|
||||
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
|
||||
std::size_t npixels = width*height;
|
||||
for (std::size_t i=0; i<npixels; i++)
|
||||
zbuff[i] = float(raw_zbuff[i]) / float(UINT_MAX);
|
||||
*/
|
||||
}
|
||||
|
||||
private:
|
||||
GLXContext ctx;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
||||
#endif //vtk_m_rendering_CanvasGLX_h
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_rendering_CanvasOSMesa_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/Color.h>
|
||||
|
||||
@ -36,8 +37,8 @@ class CanvasOSMesa : public CanvasGL
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasOSMesa(std::size_t w=1024,
|
||||
std::size_t h=1024,
|
||||
CanvasOSMesa(vtkm::Id w=1024,
|
||||
vtkm::Id h=1024,
|
||||
const vtkm::rendering::Color &c =
|
||||
vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: CanvasGL(w,h,c)
|
||||
@ -50,17 +51,31 @@ public:
|
||||
{
|
||||
ctx = OSMesaCreateContextExt(OSMESA_RGBA, 32, 0, 0, NULL);
|
||||
if (!ctx)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
|
||||
this->ColorBuffer.resize(this->Width*this->Height*4);
|
||||
}
|
||||
vtkm::Vec<vtkm::Float32,4> *colorBuffer =
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(this->ColorBuffer.GetPortalControl());
|
||||
if (!OSMesaMakeCurrent(ctx,
|
||||
&this->ColorBuffer[0],
|
||||
reinterpret_cast<vtkm::Float32*>(colorBuffer),
|
||||
GL_FLOAT,
|
||||
static_cast<GLsizei>(this->Width),
|
||||
static_cast<GLsizei>(this->Height)))
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("OSMesa context activation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void RefreshColorBuffer()
|
||||
{
|
||||
// Override superclass because our OSMesa implementation renders right
|
||||
// to the color buffer.
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Activate()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
@ -78,22 +93,28 @@ public:
|
||||
{
|
||||
CanvasGL::Finish();
|
||||
|
||||
// This is disabled because it is handled in RefreshDepthBuffer
|
||||
#if 0
|
||||
//Copy zbuff into floating point array.
|
||||
unsigned int *raw_zbuff;
|
||||
int zbytes, w, h;
|
||||
GLboolean ret;
|
||||
ret = OSMesaGetDepthBuffer(ctx, &w, &h, &zbytes, (void**)&raw_zbuff);
|
||||
if (!ret ||
|
||||
static_cast<std::size_t>(w)!=this->Width ||
|
||||
static_cast<std::size_t>(h)!=this->Height)
|
||||
static_cast<vtkm::Id>(w)!=this->Width ||
|
||||
static_cast<vtkm::Id>(h)!=this->Height)
|
||||
{
|
||||
throw vtkm::cont::ErrorControlBadValue("Wrong width/height in ZBuffer");
|
||||
}
|
||||
std::size_t npixels = this->Width*this->Height;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32>::PortalControl depthPortal =
|
||||
this->DepthBuffer.GetPortalControl();
|
||||
vtkm::Id npixels = this->Width*this->Height;
|
||||
for (vtkm::Id i=0; i<npixels; i++)
|
||||
for (std::size_t i=0; i<npixels; i++)
|
||||
{
|
||||
this->DepthBuffer[i] = float(raw_zbuff[i]) / float(UINT_MAX);
|
||||
depthPortal.Set(i, float(raw_zbuff[i]) / float(UINT_MAX));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -36,79 +36,44 @@ class CanvasRayTracer : public Canvas
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasRayTracer(std::size_t width=1024,
|
||||
std::size_t height=1024,
|
||||
CanvasRayTracer(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024,
|
||||
const vtkm::rendering::Color &color =
|
||||
vtkm::rendering::Color(0.0f,0.0f,0.0f,1.0f))
|
||||
: Canvas(width,height,color)
|
||||
{
|
||||
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
|
||||
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
|
||||
}
|
||||
|
||||
class ClearBuffers : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
vtkm::rendering::Color ClearColor;
|
||||
vtkm::Id NumPixels;
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
ClearBuffers(const vtkm::rendering::Color &clearColor,
|
||||
vtkm::Id numPixels)
|
||||
: ClearColor(clearColor),
|
||||
NumPixels(numPixels)
|
||||
ClearBuffers(const vtkm::rendering::Color &clearColor)
|
||||
: ClearColor(clearColor)
|
||||
{}
|
||||
typedef void ControlSignature(FieldOut<>,
|
||||
ExecObject);
|
||||
typedef void ExecutionSignature(_1,
|
||||
_2,
|
||||
WorkIndex);
|
||||
typedef void ControlSignature(FieldOut<>, FieldOut<>);
|
||||
typedef void ExecutionSignature(_1, _2);
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(vtkm::Float32 &depth,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer,
|
||||
const vtkm::Id &index) const
|
||||
void operator()(vtkm::Vec<vtkm::Float32,4> &color,
|
||||
vtkm::Float32 &depth) const
|
||||
{
|
||||
if(index >= NumPixels) return;
|
||||
color = this->ClearColor.Components;
|
||||
depth = 1.001f;
|
||||
vtkm::Id offset = index * 4;
|
||||
colorBuffer.Set(offset + 0, ClearColor.Components[0]);
|
||||
colorBuffer.Set(offset + 1, ClearColor.Components[1]);
|
||||
colorBuffer.Set(offset + 2, ClearColor.Components[2]);
|
||||
colorBuffer.Set(offset + 3, ClearColor.Components[3]);
|
||||
}
|
||||
}; //class ClearBuffers
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void SaveAs(const std::string &fileName)
|
||||
{
|
||||
std::ofstream of(fileName.c_str());
|
||||
of<<"P6"<<std::endl<<this->Width<<" "<<this->Height<<std::endl<<255<<std::endl;
|
||||
int height = static_cast<int>(this->Height);
|
||||
for (int yIndex=height-1; yIndex>=0; yIndex--)
|
||||
for (std::size_t xIndex=0; xIndex < this->Width; xIndex++)
|
||||
{
|
||||
const vtkm::Float32 *tuple =
|
||||
&(this->ColorBuffer[static_cast<std::size_t>(yIndex)*this->Width*4 + xIndex*4]);
|
||||
of<<(unsigned char)(tuple[0]*255);
|
||||
of<<(unsigned char)(tuple[1]*255);
|
||||
of<<(unsigned char)(tuple[2]*255);
|
||||
}
|
||||
of.close();
|
||||
}
|
||||
virtual void Initialize() { }
|
||||
virtual void Activate() { }
|
||||
virtual void Finish() { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
virtual void Clear()
|
||||
{
|
||||
this->ColorArray = vtkm::cont::make_ArrayHandle(this->ColorBuffer);
|
||||
this->DepthArray = vtkm::cont::make_ArrayHandle(this->DepthBuffer);
|
||||
vtkm::worklet::DispatcherMapField< ClearBuffers >(
|
||||
ClearBuffers( this->BackgroundColor,
|
||||
static_cast<vtkm::Int32>(this->Width*this->Height) ) )
|
||||
.Invoke( this->DepthArray,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(this->ColorArray) );
|
||||
ClearBuffers( this->BackgroundColor ) )
|
||||
.Invoke( this->ColorBuffer, this->DepthBuffer);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> ColorArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> DepthArray;
|
||||
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -26,14 +26,14 @@ namespace vtkm {
|
||||
namespace rendering {
|
||||
/// \brief It's a color!
|
||||
///
|
||||
/// This class provides the basic representation of a color. This class was
|
||||
/// Ported from EAVL. Originally created by Jeremy Meredith, Dave Pugmire,
|
||||
/// This class provides the basic representation of a color. This class was
|
||||
/// Ported from EAVL. Originally created by Jeremy Meredith, Dave Pugmire,
|
||||
/// and Sean Ahern.
|
||||
///
|
||||
class Color
|
||||
{
|
||||
public:
|
||||
vtkm::Float32 Components[4];
|
||||
vtkm::Vec<vtkm::Float32,4> Components;
|
||||
Color()
|
||||
{
|
||||
Components[0] = 0;
|
||||
@ -41,8 +41,8 @@ class Color
|
||||
Components[2] = 0;
|
||||
Components[3] = 1;
|
||||
}
|
||||
Color(vtkm::Float32 r_,
|
||||
vtkm::Float32 g_,
|
||||
Color(vtkm::Float32 r_,
|
||||
vtkm::Float32 g_,
|
||||
vtkm::Float32 b_,
|
||||
vtkm::Float32 a_ = 1.f)
|
||||
{
|
||||
@ -69,8 +69,8 @@ class Color
|
||||
//
|
||||
// Of course, converting in GetComponentAsByte from
|
||||
// 1.0 gives 256, so we need to still clamp to 255
|
||||
// anyway. Again, this is not a problem, because it
|
||||
// doesn't really extend the range of floating point
|
||||
// anyway. Again, this is not a problem, because it
|
||||
// doesn't really extend the range of floating point
|
||||
// values which map to 255.
|
||||
Components[i] = static_cast<vtkm::Float32>(v) / 255.f;
|
||||
// clamp?
|
||||
@ -83,12 +83,12 @@ class Color
|
||||
// Why? Well, we need to set glClearColor
|
||||
// using floats, but the frame buffer comes
|
||||
// back as bytes (and is internally such) in
|
||||
// most cases. In one example -- parallel
|
||||
// most cases. In one example -- parallel
|
||||
// compositing -- we need the byte values
|
||||
// returned from here to match the byte values
|
||||
// returned in the frame buffer. Though
|
||||
// a quick source code inspection of Mesa
|
||||
// led me to believe I should do *255., in
|
||||
// led me to believe I should do *255., in
|
||||
// fact this led to a mismatch. *256. was
|
||||
// actually closer. (And arguably more correct
|
||||
// if you think the byte value 255 should share
|
||||
|
@ -121,19 +121,19 @@ public:
|
||||
s = (s-sMin)/sDiff;
|
||||
|
||||
Color color = ct.MapRGB(s);
|
||||
glColor3fv(color.Components);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p1[0],p1[1],p1[2]);
|
||||
|
||||
s = scalar.GetPortalConstControl().Get(i2);
|
||||
s = (s-sMin)/sDiff;
|
||||
color = ct.MapRGB(s);
|
||||
glColor3fv(color.Components);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p2[0],p2[1],p2[2]);
|
||||
|
||||
s = scalar.GetPortalConstControl().Get(i3);
|
||||
s = (s-sMin)/sDiff;
|
||||
color = ct.MapRGB(s);
|
||||
glColor3fv(color.Components);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
glVertex3f(p3[0],p3[1],p3[2]);
|
||||
}
|
||||
glEnd();
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glColor3fv(c.Components);
|
||||
glColor3f(c.Components[0], c.Components[1], c.Components[2]);
|
||||
|
||||
glLineWidth(linewidth);
|
||||
|
||||
@ -85,7 +85,7 @@ public:
|
||||
MatrixHelpers::CreateOGLMatrix(m, ogl);
|
||||
glPushMatrix();
|
||||
glMultMatrixf(ogl);
|
||||
glColor3fv(color.Components);
|
||||
glColor3f(color.Components[0], color.Components[1], color.Components[2]);
|
||||
RenderText(scale, anchorx, anchory, text);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
@ -79,11 +79,12 @@ public:
|
||||
_4,
|
||||
WorkIndex);
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(const vtkm::Vec<vtkm::Float32,4> &inColor,
|
||||
const vtkm::Float32 &inDepth,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &depthBuffer,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &colorBuffer,
|
||||
const vtkm::Id &index) const
|
||||
void operator()(
|
||||
const vtkm::Vec<vtkm::Float32,4> &inColor,
|
||||
const vtkm::Float32 &inDepth,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32> &depthBuffer,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Vec<vtkm::Float32,4> > &colorBuffer,
|
||||
const vtkm::Id &index) const
|
||||
{
|
||||
if(index >= NumPixels) return;
|
||||
vtkm::Float32 depth = (Proj22 + Proj23 / (-inDepth)) / Proj32;
|
||||
@ -95,12 +96,7 @@ public:
|
||||
vtkm::Id outIdx = static_cast<vtkm::Id>(y * Width + x);
|
||||
//std::cout<<" "<<depth;
|
||||
depthBuffer.Set(outIdx, depth);
|
||||
|
||||
outIdx = outIdx * 4;
|
||||
colorBuffer.Set(outIdx + 0, inColor[0]);
|
||||
colorBuffer.Set(outIdx + 1, inColor[1]);
|
||||
colorBuffer.Set(outIdx + 2, inColor[2]);
|
||||
colorBuffer.Set(outIdx + 3, inColor[3]);
|
||||
colorBuffer.Set(outIdx, inColor);
|
||||
}
|
||||
}; //class SurfaceConverter
|
||||
|
||||
@ -443,12 +439,12 @@ public:
|
||||
this->SubsetWidth * this->SubsetHeight) )
|
||||
.Invoke( this->FrameBuffer,
|
||||
distances,
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(canvas->DepthArray),
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(canvas->ColorArray) );
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Float32>(canvas->DepthBuffer),
|
||||
vtkm::exec::ExecutionWholeArray<vtkm::Vec<vtkm::Float32,4> >(canvas->ColorBuffer) );
|
||||
|
||||
//Force the transfer so the vectors contain data from device
|
||||
canvas->ColorArray.GetPortalControl().Get(0);
|
||||
canvas->DepthArray.GetPortalControl().Get(0);
|
||||
canvas->ColorBuffer.GetPortalControl().Get(0);
|
||||
canvas->DepthBuffer.GetPortalControl().Get(0);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
|
Loading…
Reference in New Issue
Block a user