Merge branch 'fresh_smelling_branch' into 'master'
Add GLFW unit test. Simplify the test code with a class templated on mapper, canvas and view. See merge request !518
This commit is contained in:
commit
be7a8d5019
102
CMake/FindGLFW.cmake
Normal file
102
CMake/FindGLFW.cmake
Normal file
@ -0,0 +1,102 @@
|
||||
##=============================================================================
|
||||
##
|
||||
## 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.
|
||||
##
|
||||
##=============================================================================
|
||||
# Try to find EGL library and include dir.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLFW_FOUND
|
||||
# GLFW_INCLUDE_DIR
|
||||
# GLFW_LIBRARY
|
||||
#
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
if (WIN32)
|
||||
find_path( GLFW_INCLUDE_DIR
|
||||
NAMES
|
||||
GLFW/glfw3.h
|
||||
PATHS
|
||||
${PROJECT_SOURCE_DIR}/shared_external/glfw/include
|
||||
${PROJECT_SOURCE_DIR}/../shared_external/glfw/include
|
||||
${GLFW_LOCATION}/include
|
||||
$ENV{GLFW_LOCATION}/include
|
||||
$ENV{PROGRAMFILES}/GLFW/include
|
||||
${GLFW_LOCATION}
|
||||
$ENV{GLFW_LOCATION}
|
||||
DOC "The directory where GLFW/glfw3.h resides" )
|
||||
if(ARCH STREQUAL "x86")
|
||||
find_library( GLFW_LIBRARY
|
||||
NAMES
|
||||
glfw3
|
||||
PATHS
|
||||
${GLFW_LOCATION}/lib
|
||||
$ENV{GLFW_LOCATION}/lib
|
||||
$ENV{PROGRAMFILES}/GLFW/lib
|
||||
DOC "The GLFW library")
|
||||
else()
|
||||
find_library( GLFW_LIBRARY
|
||||
NAMES
|
||||
glfw3
|
||||
PATHS
|
||||
${GLFW_LOCATION}/lib
|
||||
$ENV{GLFW_LOCATION}/lib
|
||||
$ENV{PROGRAMFILES}/GLFW/lib
|
||||
DOC "The GLFW library")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (${CMAKE_HOST_UNIX})
|
||||
find_path( GLFW_INCLUDE_DIR
|
||||
NAMES
|
||||
GLFW/glfw3.h
|
||||
PATHS
|
||||
${GLFW_LOCATION}/include
|
||||
$ENV{GLFW_LOCATION}/include
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/sw/include
|
||||
/opt/local/include
|
||||
NO_DEFAULT_PATH
|
||||
DOC "The directory where GLFW/glfw3.h resides"
|
||||
)
|
||||
find_library( GLFW_LIBRARY
|
||||
NAMES
|
||||
glfw3 glfw
|
||||
PATHS
|
||||
${GLFW_LOCATION}/lib
|
||||
$ENV{GLFW_LOCATION}/lib
|
||||
/usr/lib64
|
||||
/usr/lib
|
||||
/usr/local/lib64
|
||||
/usr/local/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
/usr/lib/x86_64-linux-gnu
|
||||
NO_DEFAULT_PATH
|
||||
DOC "The GLFW library")
|
||||
endif ()
|
||||
|
||||
find_package_handle_standard_args(GLFW DEFAULT_MSG
|
||||
GLFW_INCLUDE_DIR
|
||||
GLFW_LIBRARY
|
||||
)
|
||||
|
||||
mark_as_advanced( GLFW_FOUND )
|
@ -39,6 +39,7 @@ set(VTKm_AVAILABLE_COMPONENTS
|
||||
OpenGL
|
||||
OSMesa
|
||||
EGL
|
||||
GLFW
|
||||
Interop
|
||||
TBB
|
||||
CUDA
|
||||
@ -143,6 +144,18 @@ macro(vtkm_configure_component_EGL)
|
||||
)
|
||||
endmacro(vtkm_configure_component_EGL)
|
||||
|
||||
macro(vtkm_configure_component_GLFW)
|
||||
vtkm_configure_component_OpenGL()
|
||||
|
||||
find_package(GLFW ${VTKm_FIND_PACKAGE_QUIETLY})
|
||||
|
||||
vtkm_finish_configure_component(GLFW
|
||||
DEPENDENT_VARIABLES VTKm_OpenGL_FOUND GLFW_FOUND
|
||||
ADD_INCLUDES ${GLFW_INCLUDE_DIR}
|
||||
ADD_LIBRARIES ${GLFW_LIBRARY}
|
||||
)
|
||||
endmacro(vtkm_configure_component_GLFW)
|
||||
|
||||
macro(vtkm_configure_component_Interop)
|
||||
vtkm_configure_component_OpenGL()
|
||||
|
||||
|
0
CMakeLists.txt
Executable file → Normal file
0
CMakeLists.txt
Executable file → Normal file
@ -66,12 +66,15 @@ endif()
|
||||
find_package(OpenGL ${VTKm_FIND_PACKAGE_QUIETLY})
|
||||
if(OPENGL_FOUND)
|
||||
set(headers ${headers} ${opengl_headers})
|
||||
|
||||
|
||||
|
||||
find_package(EGL ${VTKm_FIND_PACKAGE_QUIETLY})
|
||||
if(EGL_FOUND)
|
||||
set(headers ${headers} ${egl_headers})
|
||||
endif()
|
||||
set(headers ${headers} ${egl_headers})
|
||||
endif()
|
||||
find_package(GLFW ${VTKm_FIND_PACKAGE_QUIETLY})
|
||||
if(GLFW_FOUND)
|
||||
set(headers ${headers} ${glfw_headers})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasEGL(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024)
|
||||
: CanvasGL()
|
||||
: CanvasGL(width,height)
|
||||
{
|
||||
ctx = NULL;
|
||||
this->ResizeBuffers(width, height);
|
||||
|
@ -41,8 +41,9 @@ class CanvasGL : public Canvas
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasGL()
|
||||
: Canvas(0,0)
|
||||
CanvasGL(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024)
|
||||
: Canvas(width,height)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
CanvasOSMesa(vtkm::Id width=1024,
|
||||
vtkm::Id height=1024)
|
||||
: CanvasGL()
|
||||
: CanvasGL(width,height)
|
||||
{
|
||||
ctx = NULL;
|
||||
this->ResizeBuffers(width, height);
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
add_subdirectory(osmesa)
|
||||
add_subdirectory(egl)
|
||||
add_subdirectory(glfw)
|
||||
|
||||
set(unit_tests
|
||||
UnitTestMapperRayTracer.cxx
|
||||
|
93
vtkm/rendering/testing/RenderTest.h
Normal file
93
vtkm/rendering/testing/RenderTest.h
Normal file
@ -0,0 +1,93 @@
|
||||
//============================================================================
|
||||
// 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_testing_RenderTest_h
|
||||
#define vtk_m_rendering_testing_RenderTest_h
|
||||
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
namespace testing {
|
||||
|
||||
template <typename ViewType>
|
||||
inline void
|
||||
SetCamera(vtkm::rendering::Camera &camera,
|
||||
const vtkm::Bounds &coordBounds);
|
||||
|
||||
template <>
|
||||
inline void
|
||||
SetCamera<vtkm::rendering::View3D>(vtkm::rendering::Camera &camera,
|
||||
const vtkm::Bounds &coordsBounds)
|
||||
{
|
||||
camera = vtkm::rendering::Camera();
|
||||
camera.ResetToBounds(coordsBounds);
|
||||
camera.Azimuth(static_cast<vtkm::Float32>(45.0));
|
||||
camera.Elevation(static_cast<vtkm::Float32>(45.0));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void
|
||||
SetCamera<vtkm::rendering::View2D>(vtkm::rendering::Camera &camera,
|
||||
const vtkm::Bounds &coordsBounds)
|
||||
{
|
||||
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::MODE_2D);
|
||||
camera.SetViewRange2D(coordsBounds);
|
||||
camera.SetClippingRange(1.f, 100.f);
|
||||
camera.SetViewport(-0.7f, +0.7f, -0.7f, +0.7f);
|
||||
}
|
||||
|
||||
template <typename MapperType,typename CanvasType, typename ViewType>
|
||||
void
|
||||
Render(const vtkm::cont::DataSet &ds,
|
||||
const std::string &fieldNm,
|
||||
const vtkm::rendering::ColorTable &colorTable,
|
||||
const std::string &outputFile)
|
||||
{
|
||||
MapperType mapper;
|
||||
CanvasType canvas(512,512);
|
||||
vtkm::rendering::Scene scene;
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
colorTable));
|
||||
vtkm::rendering::Camera camera;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
SetCamera<ViewType>(camera,
|
||||
ds.GetCoordinateSystem().GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()));
|
||||
|
||||
ViewType view(scene, mapper, canvas, camera,
|
||||
vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
}
|
||||
|
||||
}}} // namespace vtkm::rendering::testing
|
||||
|
||||
#endif //vtk_m_rendering_testing_RenderTest_h
|
@ -26,114 +26,28 @@
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace {
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
//set up a default view
|
||||
camera = vtkm::rendering::Camera();
|
||||
camera.ResetToBounds(coordsBounds);
|
||||
camera.Azimuth(static_cast<vtkm::Float32>(vtkm::Pi_4()));
|
||||
camera.Elevation(static_cast<vtkm::Float32>(vtkm::Pi_4()));
|
||||
|
||||
std::cout << "Camera3d: pos: " << camera.GetPosition() << std::endl;
|
||||
std::cout << " lookAt: " << camera.GetLookAt() << std::endl;
|
||||
std::cout << " up: " << camera.GetViewUp() << std::endl;
|
||||
std::cout << " near/far: " << camera.GetClippingRange() << std::endl;
|
||||
std::cout << " fieldOfView: " << camera.GetFieldOfView() << std::endl;
|
||||
}
|
||||
|
||||
void Set2DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
//set up a default view
|
||||
|
||||
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::MODE_2D);
|
||||
camera.SetViewRange2D(coordsBounds);
|
||||
camera.SetClippingRange(1.f, 100.f);
|
||||
|
||||
// Give it some space for other annotations like a color bar
|
||||
camera.SetViewport(-0.7f, +0.7f, -0.7f, +0.7f);
|
||||
|
||||
std::cout << "Camera2D: Viewport: " << camera.GetViewport() << std::endl;
|
||||
std::cout << " ClippingRange: " << camera.GetClippingRange() << 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::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasEGL canvas(W,H);
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
|
||||
//TODO: W/H in view. bg in view (view sets canvas/renderer).
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
||||
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.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::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set2DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasEGL canvas(W,H);
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
vtkm::rendering::View2D view(scene, mapper, canvas, camera, bg);
|
||||
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
typedef vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> M;
|
||||
typedef vtkm::rendering::CanvasEGL C;
|
||||
typedef vtkm::rendering::View3D V3;
|
||||
typedef vtkm::rendering::View2D V2;
|
||||
|
||||
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");
|
||||
vtkm::rendering::ColorTable colorTable("thermal");
|
||||
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRegularDataSet0(),
|
||||
"pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DExplicitDataSet4(),
|
||||
"pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V2>(maker.Make2DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect2D.pnm");
|
||||
}
|
||||
} //namespace
|
||||
|
||||
|
28
vtkm/rendering/testing/glfw/CMakeLists.txt
Normal file
28
vtkm/rendering/testing/glfw/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
#============================================================================
|
||||
## 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 2014 Sandia Corporation.
|
||||
## Copyright 2014 UT-Battelle, LLC.
|
||||
## Copyright 2014 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.
|
||||
##============================================================================
|
||||
|
||||
vtkm_configure_component_GLFW()
|
||||
if (VTKm_GLFW_FOUND)
|
||||
set(unit_tests ${unit_tests}
|
||||
UnitTestMapperGLFW.cxx
|
||||
)
|
||||
VTKm_unit_tests(SOURCES ${unit_tests})
|
||||
endif()
|
||||
|
90
vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx
Normal file
90
vtkm/rendering/testing/glfw/UnitTestMapperGLFW.cxx
Normal file
@ -0,0 +1,90 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/CanvasGL.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace {
|
||||
static const vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id which = 0, NUM_DATASETS = 4;
|
||||
static bool done = false;
|
||||
|
||||
static void
|
||||
keyCallback(GLFWwindow* vtkmNotUsed(window), int key,
|
||||
int vtkmNotUsed(scancode), int action, int vtkmNotUsed(mods))
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE)
|
||||
done = true;
|
||||
if (action == 1)
|
||||
which = (which+1) % NUM_DATASETS;
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
std::cout<<"Press any key to cycle through datasets. ESC to quit."<<std::endl;
|
||||
|
||||
typedef vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> M;
|
||||
typedef vtkm::rendering::CanvasGL C;
|
||||
typedef vtkm::rendering::View3D V3;
|
||||
typedef vtkm::rendering::View2D V2;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::rendering::ColorTable colorTable("thermal");
|
||||
|
||||
glfwInit();
|
||||
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "GLFW Test", NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
|
||||
while (!glfwWindowShouldClose(window) && !done)
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
if (which == 0)
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRegularDataSet0(),
|
||||
"pointvar", colorTable, "reg3D.pnm");
|
||||
else if (which == 1)
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect3D.pnm");
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DExplicitDataSet4(),
|
||||
"pointvar", colorTable, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<M,C,V2>(maker.Make2DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect2D.pnm");
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
}
|
||||
} //namespace
|
||||
|
||||
int UnitTestMapperGLFW(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(RenderTests);
|
||||
}
|
@ -26,116 +26,30 @@
|
||||
#include <vtkm/rendering/View.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
|
||||
namespace {
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
//set up a default view
|
||||
camera = vtkm::rendering::Camera();
|
||||
camera.ResetToBounds(coordsBounds);
|
||||
camera.Azimuth(45.0f);
|
||||
camera.Elevation(45.0f);
|
||||
|
||||
std::cout << "Camera3d: pos: " << camera.GetPosition() << std::endl;
|
||||
std::cout << " lookAt: " << camera.GetLookAt() << std::endl;
|
||||
std::cout << " up: " << camera.GetViewUp() << std::endl;
|
||||
std::cout << " near/far: " << camera.GetClippingRange() << std::endl;
|
||||
std::cout << " fieldOfView: " << camera.GetFieldOfView() << std::endl;
|
||||
}
|
||||
|
||||
void Set2DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
//set up a default view
|
||||
|
||||
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::MODE_2D);
|
||||
camera.SetViewRange2D(coordsBounds);
|
||||
camera.SetClippingRange(1.f, 100.f);
|
||||
|
||||
// Give it some space for other annotations like a color bar
|
||||
camera.SetViewport(-0.7f, +0.7f, -0.7f, +0.7f);
|
||||
|
||||
std::cout << "Camera2D: Viewport: " << camera.GetViewport() << std::endl;
|
||||
std::cout << " ClippingRange: " << camera.GetClippingRange() << 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::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasOSMesa canvas(W,H);
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
|
||||
//TODO: W/H in view. bg in view (view sets canvas/renderer).
|
||||
vtkm::rendering::View3D view(scene, mapper, canvas, camera, bg);
|
||||
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.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::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set2DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasOSMesa canvas(W,H);
|
||||
|
||||
scene.AddActor(vtkm::rendering::Actor(ds.GetCellSet(),
|
||||
ds.GetCoordinateSystem(),
|
||||
ds.GetField(fieldNm),
|
||||
vtkm::rendering::ColorTable(ctName)));
|
||||
vtkm::rendering::View2D view(scene, mapper, canvas, camera, bg);
|
||||
|
||||
view.Initialize();
|
||||
view.Paint();
|
||||
view.SaveAs(outputFile);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
typedef vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> M;
|
||||
typedef vtkm::rendering::CanvasOSMesa C;
|
||||
typedef vtkm::rendering::View3D V3;
|
||||
typedef vtkm::rendering::View2D V2;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::rendering::ColorTable colorTable("thermal");
|
||||
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRegularDataSet0(),
|
||||
"pointvar", colorTable, "reg3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V3>(maker.Make3DExplicitDataSet4(),
|
||||
"pointvar", colorTable, "expl3D.pnm");
|
||||
vtkm::rendering::testing::Render<M,C,V2>(maker.Make2DRectilinearDataSet0(),
|
||||
"pointvar", colorTable, "rect2D.pnm");
|
||||
}
|
||||
|
||||
//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 UnitTestMapperOSMesa(int, char *[])
|
||||
|
Loading…
Reference in New Issue
Block a user