diff --git a/vtkm/rendering/Plot.h b/vtkm/rendering/Plot.h index f0f412ee6..358c3b652 100644 --- a/vtkm/rendering/Plot.h +++ b/vtkm/rendering/Plot.h @@ -21,6 +21,7 @@ #define vtk_m_rendering_Plot_h #include +#include #include namespace vtkm { @@ -44,12 +45,15 @@ public: template 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; diff --git a/vtkm/rendering/RenderSurface.h b/vtkm/rendering/RenderSurface.h index 98c85ca59..540729ef8 100644 --- a/vtkm/rendering/RenderSurface.h +++ b/vtkm/rendering/RenderSurface.h @@ -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 &) {} diff --git a/vtkm/rendering/RenderSurfaceOSMesa.h b/vtkm/rendering/RenderSurfaceOSMesa.h index e73a89143..88eb6df75 100644 --- a/vtkm/rendering/RenderSurfaceOSMesa.h +++ b/vtkm/rendering/RenderSurfaceOSMesa.h @@ -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(width), static_cast(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: "<=0; i--) + int hi = static_cast(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]); diff --git a/vtkm/rendering/Scene.h b/vtkm/rendering/Scene.h index 8fcd18315..1cb798ebf 100644 --- a/vtkm/rendering/Scene.h +++ b/vtkm/rendering/Scene.h @@ -21,6 +21,7 @@ #define vtk_m_rendering_Scene_h #include +#include #include namespace vtkm { @@ -40,12 +41,13 @@ public: template 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 + template 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(); + } } }; diff --git a/vtkm/rendering/SceneRenderer.h b/vtkm/rendering/SceneRenderer.h index 2803a1959..cc647a4de 100644 --- a/vtkm/rendering/SceneRenderer.h +++ b/vtkm/rendering/SceneRenderer.h @@ -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 > ColorMap; vtkm::Vec BackgroundColor; - View3D View; }; }} //namespace vtkm::rendering #endif //vtk_m_rendering_SceneRenderer_h diff --git a/vtkm/rendering/SceneRendererGL.h b/vtkm/rendering/SceneRendererGL.h index 6a82a8782..66099668b 100644 --- a/vtkm/rendering/SceneRendererGL.h +++ b/vtkm/rendering/SceneRendererGL.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 > indices; vtkm::Id numTri; diff --git a/vtkm/rendering/SceneRendererVolume.h b/vtkm/rendering/SceneRendererVolume.h index 3db919388..cd14988c1 100644 --- a/vtkm/rendering/SceneRendererVolume.h +++ b/vtkm/rendering/SceneRendererVolume.h @@ -19,6 +19,7 @@ //============================================================================ #ifndef vtk_m_rendering_SceneRendererVolume_h #define vtk_m_rendering_SceneRendererVolume_h + #include #include #include @@ -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::rendering::raytracing::Camera &camera = Tracer.GetCamera(); - camera.SetParameters(View); + camera.SetParameters(view); Tracer.SetData(vertices, scalarField, coordsBounds, cellSetStructured3D, scalarBounds); Tracer.SetColorMap(ColorMap); std::cout<<"Structured Rendering"< CreateViewMatrix() + { + return View::ViewMtx(pos, lookAt, up); + } + + VTKM_CONT_EXPORT + vtkm::Matrix CreateProjectionMatrix(vtkm::Int32 &width, + vtkm::Int32 &height, + vtkm::Float32 &nearPlane, + vtkm::Float32 &farPlane) + { + vtkm::Matrix 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 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 CreateViewMatrix() + { + vtkm::Vec at((left+right)/2.f, (top+bottom)/2.f, 0.f); + vtkm::Vec pos = at; + pos[2] = 1.f; + vtkm::Vec up(0,1,0); + return View::ViewMtx(pos, at, up); + } + + VTKM_CONT_EXPORT + vtkm::Matrix CreateProjectionMatrix(vtkm::Float32 &size, + vtkm::Float32 &near, + vtkm::Float32 &far, + vtkm::Float32 &aspect) + { + vtkm::Matrix 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 ViewMtx(const vtkm::Vec &pos, + const vtkm::Vec &at, + const vtkm::Vec &up) + { + vtkm::Vec viewDir = pos-at; + vtkm::Vec right = vtkm::Cross(up,viewDir); + vtkm::Vec ru = vtkm::Cross(viewDir,right); + + vtkm::Normalize(viewDir); + vtkm::Normalize(right); + vtkm::Normalize(ru); + + vtkm::Matrix 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 Up; - vtkm::Vec LookAt; - vtkm::Vec 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 CreateViewMatrix() + { + if (viewType == View::VIEW_3D) + return view3d.CreateViewMatrix(); + else + return view2d.CreateViewMatrix(); + } + VTKM_CONT_EXPORT + vtkm::Matrix 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(width)*(r-l)) / (static_cast(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 CreateViewMatrix() - { - vtkm::Normalize(Up); - vtkm::Matrix viewMatrix; - vtkm::MatrixIdentity(viewMatrix); - vtkm::Vec viewDir = Position - LookAt; //looking down the neg z axis - vtkm::Normalize(viewDir); - vtkm::Vec right = vtkm::Cross(Up,viewDir); - vtkm::Vec 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 CreateProjectionMatrix() - { - AspectRatio = vtkm::Float32(Width) / vtkm::Float32(Height); - vtkm::Matrix projectionMatrix; - vtkm::MatrixIdentity(projectionMatrix); - vtkm::Float32 fovRad = (FieldOfView * 3.1415926f)/180.f; - fovRad = vtkm::Tan( fovRad * 0.5f); - std::cout<<"Field of View "<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 &mat) - { - std::cout<(width); + vtkm::Float32 maxvh = (vt-vb) * static_cast(height); + vtkm::Float32 waspect = maxvw / maxvh; + vtkm::Float32 daspect = (view2d.right - view2d.left) / (view2d.top - view2d.bottom); + daspect *= view2d.xScale; + //cerr << "waspect="< lookAt = totalExtent * (mag * .5f); - view.LookAt = totalExtent * (mag * .5f); - vtkm::Vec 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::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(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: "< 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(coordsBounds[0]) - off; + view.view2d.right = static_cast(coordsBounds[1]) + off; + view.view2d.bottom = static_cast(coordsBounds[2]) - off; + view.view2d.top = static_cast(coordsBounds[3]) + off; + view.nearPlane = 1.f; + view.farPlane = 100.f; + view.width = w; + view.height = h; + + /* + std::cout<<"View2d: l/r: "< 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::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 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::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); } diff --git a/vtkm/rendering/testing/UnitTestSceneRendererVolume.cxx b/vtkm/rendering/testing/UnitTestSceneRendererVolume.cxx index 1fa289710..9dfb3d546 100644 --- a/vtkm/rendering/testing/UnitTestSceneRendererVolume.cxx +++ b/vtkm/rendering/testing/UnitTestSceneRendererVolume.cxx @@ -18,62 +18,99 @@ // this software. //============================================================================ #include +#include +#include +#include +#include #include #include #include + 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 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(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 sceneRenderer; - vtkm::rendering::View3D &view = sceneRenderer.GetView(); + std::cout<<"View3d: pos: "< 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 "< lookAt = totalExtent * (mag * .5f); - view.LookAt = totalExtent * (mag * .5f); - vtkm::Vec 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 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::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); }