Support for 2D rendering. And some general clean up.

This commit is contained in:
Dave Pugmire 2016-04-18 16:42:59 -04:00
parent d40f1b8bf9
commit 1af37d0102
12 changed files with 560 additions and 284 deletions

@ -21,6 +21,7 @@
#define vtk_m_rendering_Plot_h
#include <vtkm/rendering/SceneRenderer.h>
#include <vtkm/rendering/View.h>
#include <vector>
namespace vtkm {
@ -44,12 +45,15 @@ public:
template<typename SceneRendererType, typename SurfaceType>
VTKM_CONT_EXPORT
void Render(SceneRendererType &sr,
SurfaceType &)//surface)
SurfaceType &, //surface
vtkm::rendering::View &view)
{
//??????
//feed surface into sr somehow??
//TODO: Get rid of surface.
sr.SetActiveColorTable(colorTable);
sr.RenderCells(cellSet, coords, scalarField,
colorTable, scalarBounds);
colorTable, view, scalarBounds);
}
vtkm::cont::DynamicCellSet cellSet;

@ -52,9 +52,9 @@ public:
virtual void Finish() {}
VTKM_CONT_EXPORT
virtual void SetViewToWorldSpace(vtkm::rendering::View3D &, bool) {}
virtual void SetViewToWorldSpace(vtkm::rendering::View &, bool) {}
VTKM_CONT_EXPORT
void SetViewportClipping(vtkm::rendering::View3D &, bool) {}
void SetViewportClipping(vtkm::rendering::View &, bool) {}
VTKM_CONT_EXPORT
virtual void SaveAs(const std::string &) {}

@ -51,7 +51,7 @@ public:
if (!ctx)
throw vtkm::cont::ErrorControlBadValue("OSMesa context creation failed.");
rgba.resize(width*height*4);
if (!OSMesaMakeCurrent(ctx, &rgba[0], GL_FLOAT, width, height))
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);
@ -81,7 +81,7 @@ public:
}
VTKM_CONT_EXPORT
virtual void SetViewToWorldSpace(vtkm::rendering::View3D &v, bool clip)
virtual void SetViewToWorldSpace(vtkm::rendering::View &v, bool clip)
{
vtkm::Float32 oglP[16], oglM[16];
@ -89,6 +89,15 @@ public:
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(oglP);
/*
std::cout<<"Proj: pos: "<<v.view3d.pos<<std::endl;
std::cout<<" up: "<<v.view3d.up<<std::endl;
std::cout<<" lookAt: "<<v.view3d.lookAt<<std::endl;
std::cout<<" near/far: "<<v.view3d.nearPlane<<" "<<v.view3d.farPlane<<std::endl;
std::cout<<" fov: "<<v.view3d.fieldOfView<<std::endl;
printMatrix(oglP);
*/
CreateOGLMatrix(v.CreateViewMatrix(), oglM);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(oglM);
@ -97,24 +106,24 @@ public:
}
VTKM_CONT_EXPORT
virtual void SetViewportClipping(vtkm::rendering::View3D &v, bool clip)
virtual void SetViewportClipping(vtkm::rendering::View &v, bool clip)
{
if (clip)
{
vtkm::Float32 vl, vr, vt, vb;
v.GetRealViewport(vl,vr,vt,vb);
double x = vtkm::Float32(v.Width)*(1.+vl)/2.;
double y = vtkm::Float32(v.Height)*(1.+vb)/2.;
double a = vtkm::Float32(v.Width)*(vr-vl)/2.;
double b = vtkm::Float32(v.Height)*(vt-vb)/2.;
glViewport(int(float(v.Width)*(1.+vl)/2.),
int(float(v.Height)*(1.+vb)/2.),
int(float(v.Width)*(vr-vl)/2.),
int(float(v.Height)*(vt-vb)/2.));
double x = vtkm::Float32(v.width)*(1.+vl)/2.;
double y = vtkm::Float32(v.height)*(1.+vb)/2.;
double a = vtkm::Float32(v.width)*(vr-vl)/2.;
double b = vtkm::Float32(v.height)*(vt-vb)/2.;
glViewport(int(float(v.width)*(1.+vl)/2.),
int(float(v.height)*(1.+vb)/2.),
int(float(v.width)*(vr-vl)/2.),
int(float(v.height)*(vt-vb)/2.));
}
else
{
glViewport(0,0, v.Width, v.Height);
glViewport(0,0, v.width, v.height);
}
}
@ -145,7 +154,8 @@ public:
{
std::ofstream of(fileName.c_str());
of<<"P6"<<std::endl<<width<<" "<<height<<std::endl<<255<<std::endl;
for (int i=height-1; i>=0; i--)
int hi = static_cast<int>(height);
for (int i=hi-1; i>=0; i--)
for (std::size_t j=0; j < width; j++)
{
const vtkm::Float32 *tuple = &(rgba[i*width*4 + j*4]);

@ -21,6 +21,7 @@
#define vtk_m_rendering_Scene_h
#include <vtkm/rendering/Plot.h>
#include <vtkm/rendering/View.h>
#include <vector>
namespace vtkm {
@ -40,12 +41,13 @@ public:
template<typename SceneRendererType, typename SurfaceType>
VTKM_CONT_EXPORT
void Render(SceneRendererType &sceneRenderer,
SurfaceType &surface)
SurfaceType &surface,
vtkm::rendering::View &view)
{
for (std::size_t i = 0; i < plots.size(); i++)
{
sceneRenderer.StartScene();
plots[i].Render(sceneRenderer, surface);
plots[i].Render(sceneRenderer, surface, view);
sceneRenderer.EndScene();
}
}
@ -56,11 +58,18 @@ class Scene2D : public Scene
public:
Scene2D() {}
template<typename SceneRendererType>
template<typename SceneRendererType, typename SurfaceType>
VTKM_CONT_EXPORT
void Render(vtkm::rendering::View3D &vtkmNotUsed(view),
SceneRendererType &vtkmNotUsed(sceneRenderer) )
void Render(SceneRendererType &sceneRenderer,
SurfaceType &surface,
vtkm::rendering::View &view)
{
for (std::size_t i = 0; i < plots.size(); i++)
{
sceneRenderer.StartScene();
plots[i].Render(sceneRenderer, surface, view);
sceneRenderer.EndScene();
}
}
};

@ -39,23 +39,12 @@ public:
virtual ~SceneRenderer()
{}
VTKM_CONT_EXPORT
virtual void SetView(vtkm::rendering::View3D &v)
{
View = v;
}
VTKM_CONT_EXPORT
virtual vtkm::rendering::View3D& GetView()
{
return View;
}
VTKM_CONT_EXPORT
virtual void RenderCells(const vtkm::cont::DynamicCellSet &cellset,
const vtkm::cont::CoordinateSystem &coords,
vtkm::cont::Field &scalarField, //This should be const
const vtkm::rendering::ColorTable &colorTable,
vtkm::rendering::View &view,
vtkm::Float64 *scalarBounds=NULL) = 0;
VTKM_CONT_EXPORT
@ -95,7 +84,6 @@ public:
protected:
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,4> > ColorMap;
vtkm::Vec<vtkm::Float32,4> BackgroundColor;
View3D View;
};
}} //namespace vtkm::rendering
#endif //vtk_m_rendering_SceneRenderer_h

@ -46,10 +46,11 @@ public:
VTKM_CONT_EXPORT
virtual void RenderCells(const vtkm::cont::DynamicCellSet &cellset,
const vtkm::cont::CoordinateSystem &coords,
vtkm::cont::Field &scalarField,
const vtkm::rendering::ColorTable &colorTable,
vtkm::Float64 *scalarBounds)
const vtkm::cont::CoordinateSystem &coords,
vtkm::cont::Field &scalarField,
const vtkm::rendering::ColorTable &colorTable,
vtkm::rendering::View &,
vtkm::Float64 *scalarBounds)
{
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > indices;
vtkm::Id numTri;

@ -19,6 +19,7 @@
//============================================================================
#ifndef vtk_m_rendering_SceneRendererVolume_h
#define vtk_m_rendering_SceneRendererVolume_h
#include <vtkm/rendering/ColorTable.h>
#include <vtkm/rendering/Triangulator.h>
#include <vtkm/rendering/SceneRenderer.h>
@ -51,6 +52,7 @@ public:
const vtkm::cont::CoordinateSystem &coords,
vtkm::cont::Field &scalarField,
const vtkm::rendering::ColorTable &, //colorTable
vtkm::rendering::View &view,
vtkm::Float64 *scalarBounds=NULL) //scalarBounds=NULL)
{
vtkm::cont::DynamicArrayHandleCoordinateSystem dynamicCoordsHandle = coords.GetData();
@ -73,7 +75,7 @@ public:
//if(dynamicCoordsHandle.IsArrayHandleType(vtkm::cont::ArrayHandleUniformPointCoordinates()))
vertices = dynamicCoordsHandle.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
vtkm::rendering::raytracing::Camera<DeviceAdapter> &camera = Tracer.GetCamera();
camera.SetParameters(View);
camera.SetParameters(view);
Tracer.SetData(vertices, scalarField, coordsBounds, cellSetStructured3D, scalarBounds);
Tracer.SetColorMap(ColorMap);
std::cout<<"Structured Rendering"<<std::endl;

@ -26,132 +26,227 @@
namespace vtkm {
namespace rendering {
class View3D
class View
{
class View3D
{
public:
VTKM_CONT_EXPORT
View3D() : fieldOfView(0.f)
{}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
{
return View::ViewMtx(pos, lookAt, up);
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Int32 &width,
vtkm::Int32 &height,
vtkm::Float32 &nearPlane,
vtkm::Float32 &farPlane)
{
vtkm::Matrix<vtkm::Float32,4,4> mtx;
vtkm::MatrixIdentity(mtx);
vtkm::Float32 AspectRatio = vtkm::Float32(width) / vtkm::Float32(height);
vtkm::Float32 fovRad = (fieldOfView * 3.1415926f)/180.f;
fovRad = vtkm::Tan( fovRad * 0.5f);
vtkm::Float32 size = nearPlane * fovRad;
vtkm::Float32 left = -size * AspectRatio;
vtkm::Float32 right = size * AspectRatio;
vtkm::Float32 bottom = -size;
vtkm::Float32 top = size;
mtx(0,0) = 2.f * nearPlane / (right - left);
mtx(1,1) = 2.f * nearPlane / (top - bottom);
mtx(0,2) = (right + left) / (right - left);
mtx(1,2) = (top + bottom) / (top - bottom);
mtx(2,2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
mtx(3,2) = -1.f;
mtx(2,3) = -(2.f * farPlane * nearPlane) / (farPlane - nearPlane);
mtx(3,3) = 0.f;
return mtx;
}
vtkm::Vec<vtkm::Float32,3> up, lookAt, pos;
vtkm::Float32 fieldOfView;
};
class View2D
{
public:
VTKM_CONT_EXPORT
View2D() : left(0.f), right(0.f), top(0.f), bottom(0.f), xScale(1.f)
{}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
{
vtkm::Vec<vtkm::Float32,3> at((left+right)/2.f, (top+bottom)/2.f, 0.f);
vtkm::Vec<vtkm::Float32,3> pos = at;
pos[2] = 1.f;
vtkm::Vec<vtkm::Float32,3> up(0,1,0);
return View::ViewMtx(pos, at, up);
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Float32 &size,
vtkm::Float32 &near,
vtkm::Float32 &far,
vtkm::Float32 &aspect)
{
vtkm::Matrix<vtkm::Float32,4,4> mtx(0.f);
vtkm::Float32 L = -size/2.f * aspect;
vtkm::Float32 R = size/2.f * aspect;
vtkm::Float32 B = -size/2.f;
vtkm::Float32 T = size/2.f;
mtx(0,0) = 2.f/(R-L);
mtx(1,1) = 2.f/(T-B);
mtx(2,2) = -2.f/(far-near);
mtx(0,3) = -(R+L)/(R-L);
mtx(1,3) = -(T+B)/(T-B);
mtx(2,3) = -(far+near)/(far-near);
mtx(3,3) = 1.f;
return mtx;
}
vtkm::Float32 left, right, top, bottom;
vtkm::Float32 xScale;
};
private:
static VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> ViewMtx(const vtkm::Vec<vtkm::Float32,3> &pos,
const vtkm::Vec<vtkm::Float32,3> &at,
const vtkm::Vec<vtkm::Float32,3> &up)
{
vtkm::Vec<vtkm::Float32,3> viewDir = pos-at;
vtkm::Vec<vtkm::Float32,3> right = vtkm::Cross(up,viewDir);
vtkm::Vec<vtkm::Float32,3> ru = vtkm::Cross(viewDir,right);
vtkm::Normalize(viewDir);
vtkm::Normalize(right);
vtkm::Normalize(ru);
vtkm::Matrix<vtkm::Float32,4,4> mtx;
vtkm::MatrixIdentity(mtx);
mtx(0,0) = right[0];
mtx(0,1) = right[1];
mtx(0,2) = right[2];
mtx(1,0) = ru[0];
mtx(1,1) = ru[1];
mtx(1,2) = ru[2];
mtx(2,0) = viewDir[0];
mtx(2,1) = viewDir[1];
mtx(2,2) = viewDir[2];
mtx(0,3) = -vtkm::dot(right,pos);
mtx(1,3) = -vtkm::dot(ru,pos);
mtx(2,3) = -vtkm::dot(viewDir,pos);
return mtx;
}
public:
vtkm::Vec<vtkm::Float32,3> Up;
vtkm::Vec<vtkm::Float32,3> LookAt;
vtkm::Vec<vtkm::Float32,3> Position;
vtkm::Float32 NearPlane;
vtkm::Float32 FarPlane;
vtkm::Float32 FieldOfView;
vtkm::Float32 AspectRatio;
vtkm::Int32 Height;
vtkm::Int32 Width;
enum ViewType { VIEW_2D, VIEW_3D };
ViewType viewType;
View3D view3d;
View2D view2d;
vtkm::Int32 width, height;
vtkm::Float32 nearPlane, farPlane;
vtkm::Float32 vl, vr, vb, vt; //viewport.
VTKM_CONT_EXPORT
View(ViewType vtype=View::VIEW_3D) : width(-1), height(-1), nearPlane(0.f), farPlane(1.f), viewType(vtype),
vl(-1.f), vr(1.f), vb(-1.f), vt(1.f)
{}
VTKM_CONT_EXPORT
View3D()
{
Up[0] = 0.f;
Up[1] = 1.f;
Up[2] = 0.f;
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
{
if (viewType == View::VIEW_3D)
return view3d.CreateViewMatrix();
else
return view2d.CreateViewMatrix();
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix()
{
if (viewType == View::VIEW_3D)
return view3d.CreateProjectionMatrix(width, height, nearPlane, farPlane);
else
{
vtkm::Float32 size = vtkm::Abs(view2d.top-view2d.bottom);
vtkm::Float32 l,r,b,t;
GetRealViewport(l,r,b,t);
vtkm::Float32 aspect = (static_cast<vtkm::Float32>(width)*(r-l)) / (static_cast<vtkm::Float32>(height)*(t-b));
return view2d.CreateProjectionMatrix(size, nearPlane, farPlane, aspect);
}
}
Position[0] = 0.f;
Position[1] = 0.f;
Position[2] = 0.f;
LookAt[0] = 0.f;
LookAt[1] = 0.f;
LookAt[2] = 1.f;
FieldOfView = 60.f;
NearPlane = 1.0f;
FarPlane = 100.0f;
Height = 500;
Width = 500;
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
{
vtkm::Normalize(Up);
vtkm::Matrix<vtkm::Float32,4,4> viewMatrix;
vtkm::MatrixIdentity(viewMatrix);
vtkm::Vec<vtkm::Float32,3> viewDir = Position - LookAt; //looking down the neg z axis
vtkm::Normalize(viewDir);
vtkm::Vec<vtkm::Float32,3> right = vtkm::Cross(Up,viewDir);
vtkm::Vec<vtkm::Float32,3> ru = vtkm::Cross(viewDir,right);
vtkm::Normalize(ru);
vtkm::Normalize(right);
viewMatrix(0,0) = right[0];
viewMatrix(0,1) = right[1];
viewMatrix(0,2) = right[2];
viewMatrix(1,0) = ru[0];
viewMatrix(1,1) = ru[1];
viewMatrix(1,2) = ru[2];
viewMatrix(2,0) = viewDir[0];
viewMatrix(2,1) = viewDir[1];
viewMatrix(2,2) = viewDir[2];
viewMatrix(0,3) = -vtkm::dot(right,Position);
viewMatrix(1,3) = -vtkm::dot(ru,Position);
viewMatrix(2,3) = -vtkm::dot(viewDir,Position);
return viewMatrix;
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix()
{
AspectRatio = vtkm::Float32(Width) / vtkm::Float32(Height);
vtkm::Matrix<vtkm::Float32,4,4> projectionMatrix;
vtkm::MatrixIdentity(projectionMatrix);
vtkm::Float32 fovRad = (FieldOfView * 3.1415926f)/180.f;
fovRad = vtkm::Tan( fovRad * 0.5f);
std::cout<<"Field of View "<<fovRad<<std::endl;
vtkm::Float32 size = NearPlane * fovRad;
vtkm::Float32 left = -size * AspectRatio;
vtkm::Float32 right = size * AspectRatio;
vtkm::Float32 bottom = -size;
vtkm::Float32 top = size;
projectionMatrix(0,0) = 2.f * NearPlane / (right - left);
projectionMatrix(1,1) = 2.f * NearPlane / (top - bottom);
projectionMatrix(0,2) = (right + left) / (right - left);
projectionMatrix(1,2) = (top + bottom) / (top - bottom);
projectionMatrix(2,2) = -(FarPlane + NearPlane) / (FarPlane - NearPlane);
projectionMatrix(3,2) = -1.f;
projectionMatrix(2,3) = -(2.f * FarPlane * NearPlane) / (FarPlane - NearPlane);
projectionMatrix(3,3) = 0.f;
return projectionMatrix;
}
void operator=(const View3D &other)
{
this->Up = other.Up;
this->LookAt = other.LookAt;
this->Position = other.Position;
this->NearPlane = other.NearPlane;
this->FarPlane = other.FarPlane;
this->FieldOfView = other.FieldOfView;
this->Height = other.Height;
this->Width = other.Width;
}
VTKM_CONT_EXPORT
void GetRealViewport(vtkm::Float32 &l, vtkm::Float32 &r,
vtkm::Float32 &b, vtkm::Float32 &t)
{
l = -1;
b = -1;
r = 1;
t = 1;
}
VTKM_CONT_EXPORT
static void PrintMatrix(const vtkm::Matrix<vtkm::Float32,4,4> &mat)
{
std::cout<<mat(0,0)<<","<<mat(0,1)<<","<<mat(0,2)<<","<<mat(0,3)<<std::endl;
std::cout<<mat(1,0)<<","<<mat(1,1)<<","<<mat(1,2)<<","<<mat(1,3)<<std::endl;
std::cout<<mat(2,0)<<","<<mat(2,1)<<","<<mat(2,2)<<","<<mat(2,3)<<std::endl;
std::cout<<mat(3,0)<<","<<mat(3,1)<<","<<mat(3,2)<<","<<mat(3,3)<<std::endl;
}
};
class View2D
{
public:
View2D() {}
VTKM_CONT_EXPORT
void GetRealViewport(vtkm::Float32 &l, vtkm::Float32 &r,
vtkm::Float32 &b, vtkm::Float32 &t)
{
if (viewType == View::VIEW_3D)
{
l = vl;
r = vr;
b = vb;
t = vt;
}
else
{
vtkm::Float32 maxvw = (vr-vl) * static_cast<vtkm::Float32>(width);
vtkm::Float32 maxvh = (vt-vb) * static_cast<vtkm::Float32>(height);
vtkm::Float32 waspect = maxvw / maxvh;
vtkm::Float32 daspect = (view2d.right - view2d.left) / (view2d.top - view2d.bottom);
daspect *= view2d.xScale;
//cerr << "waspect="<<waspect << " \tdaspect="<<daspect<<endl;
const bool center = true; // if false, anchor to bottom-left
if (waspect > daspect)
{
vtkm::Float32 new_w = (vr-vl) * daspect / waspect;
if (center)
{
l = (vl+vr)/2.f - new_w/2.f;
r = (vl+vr)/2.f + new_w/2.f;
}
else
{
l = vl;
r = vl + new_w;
}
b = vb;
t = vt;
}
else
{
vtkm::Float32 new_h = (vt-vb) * waspect / daspect;
if (center)
{
b = (vb+vt)/2.f - new_h/2.f;
t = (vb+vt)/2.f + new_h/2.f;
}
else
{
b = vb;
t = vb + new_h;
}
l = vl;
r = vr;
}
}
}
};
}} // namespace vtkm::rendering
#endif // vtk_m_rendering_View_h

@ -29,6 +29,61 @@
namespace vtkm {
namespace rendering {
template<typename SceneType, typename SceneRendererType, typename SurfaceType>
class Window
{
public:
SceneType scene;
SceneRendererType sceneRenderer;
SurfaceType surface;
vtkm::rendering::Color bgColor;
vtkm::rendering::View view;
VTKM_CONT_EXPORT
Window(const SceneType &s,
const SceneRendererType &sr,
const SurfaceType &surf,
const vtkm::rendering::View &v,
const vtkm::rendering::Color &bg=vtkm::rendering::Color(0,0,0,1)) :
scene(s), sceneRenderer(sr), bgColor(bg), surface(surf), view(v)
{
sceneRenderer.SetBackgroundColor(bgColor);
}
VTKM_CONT_EXPORT
void Initialize()
{
surface.Initialize();
}
VTKM_CONT_EXPORT
void Paint()
{
surface.Activate();
surface.Clear();
SetupForWorldSpace();
scene.Render(sceneRenderer, surface, view);
surface.Finish();
}
VTKM_CONT_EXPORT
void SaveAs(const std::string &fileName)
{
surface.SaveAs(fileName);
}
private:
VTKM_CONT_EXPORT
void SetupForWorldSpace(bool viewportClip=true)
{
//view.SetupMatrices();
surface.SetViewToWorldSpace(view, viewportClip);
}
};
#if 0
// Window2D Window3D
template<typename SceneRendererType, typename SurfaceType>
class Window3D
@ -38,7 +93,7 @@ public:
vtkm::rendering::Scene3D scene;
SceneRendererType sceneRenderer;
SurfaceType surface;
//vtkm::rendering::View3D view;
vtkm::rendering::View3D view;
VTKM_CONT_EXPORT
Window3D(const vtkm::rendering::Scene3D &s,
@ -79,8 +134,7 @@ private:
void SetupForWorldSpace(bool viewportClip=true)
{
//view.SetupMatrices();
surface.SetViewToWorldSpace(sceneRenderer.GetView(),
viewportClip);
surface.SetViewToWorldSpace(view,viewportClip);
}
};
@ -102,6 +156,7 @@ public:
{
}
};
#endif
}} //namespace vtkm::rendering

@ -149,14 +149,14 @@ public:
}
VTKM_CONT_EXPORT
void SetParameters(View3D &view)
void SetParameters(View &view)
{
this->SetUp(view.Up);
this->SetLookAt(view.LookAt);
this->SetPosition(view.Position);
this->SetFieldOfView(view.FieldOfView);
this->SetHeight(view.Height);
this->SetWidth(view.Width);
this->SetUp(view.view3d.up);
this->SetLookAt(view.view3d.lookAt);
this->SetPosition(view.view3d.pos);
this->SetFieldOfView(view.view3d.fieldOfView);
this->SetHeight(view.height);
this->SetWidth(view.width);
}
@ -363,4 +363,4 @@ public:
} //create rays
}; // class camera
}}}//namespace vtkm::rendering::raytracing
#endif //vtk_m_rendering_raytracing_Camera_h
#endif //vtk_m_rendering_raytracing_Camera_h

@ -25,81 +25,156 @@
#include <vtkm/rendering/SceneRendererGL.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
void TestSceneRendererOSMesa()
void Set3DView(vtkm::rendering::View &view,
const vtkm::cont::CoordinateSystem &coords,
vtkm::Int32 w, vtkm::Int32 h)
{
// test regular grid data set
{
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet regularGrid = maker.Make3DRegularDataSet0();
const vtkm::cont::CoordinateSystem coords = regularGrid.GetCoordinateSystem();
vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> sceneRenderer;
vtkm::rendering::View3D &view = sceneRenderer.GetView();
vtkm::Float64 coordsBounds[6]; // Xmin,Xmax,Ymin..
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
vtkm::Float64 coordsBounds[6]; // Xmin,Xmax,Ymin..
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
std::cout<<"Magnitude "<<mag<<std::endl;
vtkm::Normalize(totalExtent);
vtkm::Vec<vtkm::Float32,3> lookAt = totalExtent * (mag * .5f);
view.LookAt = totalExtent * (mag * .5f);
vtkm::Vec<vtkm::Float32,3> up;
up[0] = 0.f;
up[1] = 1.f;
up[2] = 0.f;
view.Up = up;
view.NearPlane = 1.f;
view.FarPlane = 100.f;
view.FieldOfView = 60.f;
view.Height = 500;
view.Width = 500;
view.Position = totalExtent * (mag * 2.f);
vtkm::rendering::ColorTable colorTable("thermal");
sceneRenderer.SetActiveColorTable(colorTable);
sceneRenderer.SetView(view);
vtkm::cont::DataSet expDS = maker.Make3DExplicitDataSet4();
vtkm::cont::DataSet rectDS = maker.Make3DRectilinearDataSet0();
//New way.
vtkm::rendering::Scene3D scene;
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::RenderSurfaceOSMesa surface(512,512,bg);
scene.plots.push_back(vtkm::rendering::Plot(regularGrid.GetCellSet(),
regularGrid.GetCoordinateSystem(),
regularGrid.GetField("pointvar"),
colorTable));
scene.plots.push_back(vtkm::rendering::Plot(expDS.GetCellSet(),
expDS.GetCoordinateSystem(),
expDS.GetField("pointvar"),
colorTable));
/*
scene.plots.push_back(vtkm::rendering::Plot(rectDS.GetCellSet(),
rectDS.GetCoordinateSystem(),
rectDS.GetField("pointvar"),
colorTable));
*/
vtkm::rendering::Window3D<vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
vtkm::rendering::RenderSurfaceOSMesa>
w(scene, sceneRenderer, surface, bg);
w.Initialize();
w.Paint();
w.SaveAs("output.pnm");
}
view = vtkm::rendering::View(vtkm::rendering::View::VIEW_3D);
view.view3d.pos = totalExtent * (mag * 2.f);
view.view3d.up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
view.view3d.lookAt = totalExtent * (mag * .5f);
view.view3d.fieldOfView = 60.f;
view.nearPlane = 1.f;
view.farPlane = 100.f;
view.width = w;
view.height = h;
/*
std::cout<<"View3d: pos: "<<view.view3d.pos<<std::endl;
std::cout<<" lookAt: "<<view.view3d.lookAt<<std::endl;
std::cout<<" up: "<<view.view3d.up<<std::endl;
std::cout<<"near/far/fov: "<<view.nearPlane<<"/"<<view.farPlane<<" "<<view.view3d.fieldOfView<<std::endl;
std::cout<<" w/h: "<<view.width<<"/"<<view.height<<std::endl;
*/
}
void Set2DView(vtkm::rendering::View &view,
const vtkm::cont::CoordinateSystem &coords,
vtkm::Int32 w, vtkm::Int32 h)
{
vtkm::Float64 coordsBounds[6]; // Xmin,Xmax,Ymin..
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
view = vtkm::rendering::View(vtkm::rendering::View::VIEW_2D);
vtkm::Float32 off = 0.5f;
view.view2d.left = static_cast<vtkm::Float32>(coordsBounds[0]) - off;
view.view2d.right = static_cast<vtkm::Float32>(coordsBounds[1]) + off;
view.view2d.bottom = static_cast<vtkm::Float32>(coordsBounds[2]) - off;
view.view2d.top = static_cast<vtkm::Float32>(coordsBounds[3]) + off;
view.nearPlane = 1.f;
view.farPlane = 100.f;
view.width = w;
view.height = h;
/*
std::cout<<"View2d: l/r: "<<view.view2d.left<<" "<<view.view2d.right<<std::endl;
std::cout<<"View2d: b/t: "<<view.view2d.bottom<<" "<<view.view2d.top<<std::endl;
std::cout<<" near/far: "<<view.nearPlane<<"/"<<view.farPlane<<std::endl;
std::cout<<" w/h: "<<view.width<<"/"<<view.height<<std::endl;
*/
}
void Render3D(const vtkm::cont::DataSet &ds,
const std::string &fieldNm,
const std::string &ctName,
const std::string &outputFile)
{
const vtkm::Int32 W = 512, H = 512;
const vtkm::cont::CoordinateSystem coords = ds.GetCoordinateSystem();
vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> sceneRenderer;
vtkm::rendering::View view;
Set3DView(view, coords, W, H);
vtkm::rendering::Scene3D scene;
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::RenderSurfaceOSMesa surface(W,H,bg);
scene.plots.push_back(vtkm::rendering::Plot(ds.GetCellSet(),
ds.GetCoordinateSystem(),
ds.GetField(fieldNm),
vtkm::rendering::ColorTable(ctName)));
//TODO: W/H in window. bg in window (window sets surface/renderer).
vtkm::rendering::Window<vtkm::rendering::Scene3D,
vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
vtkm::rendering::RenderSurfaceOSMesa>
w(scene, sceneRenderer, surface, view, bg);
w.Initialize();
w.Paint();
w.SaveAs(outputFile);
}
void Render2D(const vtkm::cont::DataSet &ds,
const std::string &fieldNm,
const std::string &ctName,
const std::string &outputFile)
{
const vtkm::Int32 W = 512, H = 512;
const vtkm::cont::CoordinateSystem coords = ds.GetCoordinateSystem();
vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> sceneRenderer;
vtkm::rendering::View view;
Set2DView(view, coords, W, H);
vtkm::rendering::Scene2D scene;
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::RenderSurfaceOSMesa surface(W,H,bg);
scene.plots.push_back(vtkm::rendering::Plot(ds.GetCellSet(),
ds.GetCoordinateSystem(),
ds.GetField(fieldNm),
vtkm::rendering::ColorTable(ctName)));
vtkm::rendering::Window<vtkm::rendering::Scene2D,
vtkm::rendering::SceneRendererGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
vtkm::rendering::RenderSurfaceOSMesa>
w(scene, sceneRenderer, surface, view, bg);
w.Initialize();
w.Paint();
w.SaveAs(outputFile);
}
void RenderTests()
{
vtkm::cont::testing::MakeTestDataSet maker;
//3D tests.
Render3D(maker.Make3DRegularDataSet0(),
"pointvar", "thermal", "reg3D.pnm");
Render3D(maker.Make3DRectilinearDataSet0(),
"pointvar", "thermal", "rect3D.pnm");
Render3D(maker.Make3DExplicitDataSet4(),
"pointvar", "thermal", "expl3D.pnm");
//2D tests.
Render2D(maker.Make2DRectilinearDataSet0(),
"pointvar", "thermal", "rect2D.pnm");
}
} //namespace
int UnitTestSceneRendererOSMesa(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestSceneRendererOSMesa);
return vtkm::cont::testing::Testing::Run(RenderTests);
}

@ -18,62 +18,99 @@
// this software.
//============================================================================
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/rendering/Window.h>
#include <vtkm/rendering/RenderSurface.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/Plot.h>
#include <vtkm/rendering/SceneRendererVolume.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
void TestSceneRendererVolume()
void Set3DView(vtkm::rendering::View &view,
const vtkm::cont::CoordinateSystem &coords,
vtkm::Int32 w, vtkm::Int32 h)
{
// test regular grid data set
{
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet regularGrid = maker.Make3DRegularDataSet0();
regularGrid.PrintSummary(std::cout);
vtkm::cont::Field scalarField = regularGrid.GetField("cellvar");
const vtkm::cont::CoordinateSystem coords = regularGrid.GetCoordinateSystem();
vtkm::Float64 coordsBounds[6]; // Xmin,Xmax,Ymin..
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
view = vtkm::rendering::View(vtkm::rendering::View::VIEW_3D);
view.view3d.pos = totalExtent * (mag * 2.f);
view.view3d.up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
view.view3d.lookAt = totalExtent * (mag * .5f);
view.view3d.fieldOfView = 60.f;
view.nearPlane = 1.f;
view.farPlane = 100.f;
view.width = w;
view.height = h;
vtkm::rendering::SceneRendererVolume<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> sceneRenderer;
vtkm::rendering::View3D &view = sceneRenderer.GetView();
std::cout<<"View3d: pos: "<<view.view3d.pos<<std::endl;
std::cout<<" lookAt: "<<view.view3d.lookAt<<std::endl;
std::cout<<" up: "<<view.view3d.up<<std::endl;
std::cout<<"near/far/fov: "<<view.nearPlane<<"/"<<view.farPlane<<" "<<view.view3d.fieldOfView<<std::endl;
std::cout<<" w/h: "<<view.width<<"/"<<view.height<<std::endl;
}
vtkm::Float64 coordsBounds[6]; // Xmin,Xmax,Ymin..
coords.GetBounds(coordsBounds,VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds[1] - coordsBounds[0]);
totalExtent[1] = vtkm::Float32(coordsBounds[3] - coordsBounds[2]);
totalExtent[2] = vtkm::Float32(coordsBounds[5] - coordsBounds[4]);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
std::cout<<"Magnitude "<<mag<<std::endl;
vtkm::Normalize(totalExtent);
vtkm::Vec<vtkm::Float32,3> lookAt = totalExtent * (mag * .5f);
view.LookAt = totalExtent * (mag * .5f);
vtkm::Vec<vtkm::Float32,3> up;
up[0] = 0.f;
up[1] = 1.f;
up[2] = 0.f;
view.Up = up;
view.NearPlane = 1.f;
view.FarPlane = 100.f;
view.FieldOfView = 60.f;
view.Height = 500;
view.Width = 500;
view.Position = totalExtent * (mag * 2.f);
void Render(const vtkm::cont::DataSet &ds,
const std::string &fieldNm,
const std::string &ctName,
const std::string &outputFile)
{
const vtkm::Int32 W = 512, H = 512;
const vtkm::cont::CoordinateSystem coords = ds.GetCoordinateSystem();
vtkm::rendering::SceneRendererVolume<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> sceneRenderer;
vtkm::rendering::View view;
Set3DView(view, coords, W, H);
vtkm::Float64 scalarBounds[2];
scalarField.GetBounds(scalarBounds,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
vtkm::rendering::ColorTable colorTable("thermal");
sceneRenderer.SetActiveColorTable(colorTable);
sceneRenderer.RenderCells(regularGrid.GetCellSet(), coords, scalarField,
colorTable, scalarBounds);
}
vtkm::rendering::Scene3D scene;
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
vtkm::rendering::RenderSurface surface(W,H,bg);
}//TestMortonCodes
scene.plots.push_back(vtkm::rendering::Plot(ds.GetCellSet(),
ds.GetCoordinateSystem(),
ds.GetField(fieldNm),
vtkm::rendering::ColorTable(ctName)));
//TODO: W/H in window. bg in window (window sets surface/renderer).
vtkm::rendering::Window<vtkm::rendering::Scene3D,
vtkm::rendering::SceneRendererVolume<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>,
vtkm::rendering::RenderSurface>
w(scene, sceneRenderer, surface, view, bg);
w.Initialize();
w.Paint();
w.SaveAs(outputFile);
}
void RenderRegular()
{
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet grid = maker.Make3DRegularDataSet0();
Render(grid, "pointvar", "thermal", "VRregular.pnm");
}
void RenderRectilinear()
{
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet grid = maker.Make3DRectilinearDataSet0();
Render(grid, "pointvar", "thermal", "VRrectilinear.pnm");
}
} //namespace
int UnitTestSceneRendererVolume(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestSceneRendererVolume);
return vtkm::cont::testing::Testing::Run(RenderRegular);
return vtkm::cont::testing::Testing::Run(RenderRectilinear);
}