Commit 337a0caf authored by Robert Maynard's avatar Robert Maynard

Adding the VTKm Accelerators module.

parent 1e3e2f69
##=============================================================================
##
## 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 2012 Sandia Corporation.
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
##=============================================================================
#ensure we link against our dependencies
include(module.cmake)
find_package(VTKm REQUIRED
OPTIONAL_COMPONENTS Serial CUDA TBB
)
set(lib_srcs
vtkmlib/PolyDataConverter.cxx
vtkmlib/UnstructuredGridConverter.cxx
vtkmlib/ArrayConverters.cxx
vtkmlib/CellSetConverters.cxx
vtkmlib/DataSetConverters.cxx
vtkmlib/Storage.cxx
)
#needed to properly setup language wrappers
set(headers
vtkmContour.h
vtkmThreshold.h
vtkmLevelOfDetail.h
vtkmCellAverage.h
vtkmGradient.h
)
#implementation of the algorithms for cpu accelerators
set(cpu_accelerator_srcs
vtkmContour.cxx
vtkmThreshold.cxx
vtkmLevelOfDetail.cxx
vtkmCellAverage.cxx
vtkmCellSetExplicit.cxx
vtkmCellSetSingleType.cxx
vtkmConnectivityExec.cxx
vtkmGradient.cxx
vtkmlib/Portals.cxx
)
#implementation of the algorithms for gpu accelerators
set(cuda_accelerator_srcs
vtkmContour.cu
vtkmThreshold.cu
vtkmLevelOfDetail.cu
vtkmCellAverage.cu
vtkmCellSetExplicit.cu
vtkmCellSetSingleType.cu
vtkmConnectivityExec.cu
vtkmGradient.cu
vtkmlib/Portals.cu
)
set(VTKM_FILTER_INCLUDE_AOS ${VTK_DISPATCH_AOS_ARRAYS})
set(VTKM_FILTER_INCLUDE_SOA ${VTK_DISPATCH_SOA_ARRAYS})
set(VTKM_FILTERS_ARE_BUILT_STATIC false)
if(BUILD_SHARED_LIBS)
set(VTKM_FILTERS_ARE_BUILT_STATIC true)
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/vtkmConfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/vtkmConfig.h" @ONLY)
#mark all the helper classes as being excluded from wrappers
set_source_files_properties(
vtkmlib/PolyDataConverter
vtkmlib/UnstructuredGridConverter
vtkmlib/ArrayConverters
vtkmlib/CellSetConverters
vtkmlib/DataSetConverters
vtkmlib/Storage
vtkmlib/Portals
vtkmCellSetExplicit
vtkmCellSetSingleType
vtkmConnectivityExec
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
)
set(${vtk-module}_HDRS
vtkmTags.h
vtkmFilterPolicy.h
${CMAKE_CURRENT_BINARY_DIR}/vtkmConfig.h
)
#we are building with CUDA support
if(VTKm_CUDA_FOUND)
#need to find cudadevrt
find_library(CUDA_cudadevrt_LIBRARY cudadevrt
PATHS ${CUDA_TOOLKIT_TARGET_DIR}
PATH_SUFFIXES "x64" "lib64" "libx64"
)
########
## cache and clear the CUDA_NVCC_FLAGS so that they aren't passed to
## the linker. FINDCUDA has some problems properly unquoting CUDA_NVCC_FLAGS
## when "generate-code arch..." is used, so we instead patch the options
##
########
set(compile_options)
foreach(f ${CUDA_NVCC_FLAGS})
if(f MATCHES "generate-code ")
string(REPLACE "generate-code " "generate-code=" f "${f}")
endif()
list(APPEND compile_options ${f})
endforeach()
if(BUILD_SHARED_LIBS AND NOT WIN32)
list(APPEND compile_options -Xcompiler=${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY}hidden)
list(APPEND compile_options -Xcompiler=-fPIC)
#nvcc doesn't like the macros in VTK and generates hundreds of warnings
#that are false positives
list(APPEND compile_options --disable-warnings)
endif()
set(seperable_state ${CUDA_SEPARABLE_COMPILATION})
set(cache_flag_state ${CUDA_NVCC_FLAGS})
set(CUDA_NVCC_FLAGS "")
set(CUDA_SEPARABLE_COMPILATION ON)
#Some versions of VTK-m overload the CUDA_LIBRARIES to contain private
if(PRIVATE IN_LIST CUDA_LIBRARIES)
set(cache_cuda_libs ${CUDA_LIBRARIES})
set(cache_devrt_libs ${CUDA_cudadevrt_LIBRARY})
set(CUDA_LIBRARIES ${CUDA_LIBRARIES} vtkFiltersGeneral)
set(CUDA_cudadevrt_LIBRARY PRIVATE ${CUDA_cudadevrt_LIBRARY})
endif()
# CUDA doesn't obey usage requirements so we have to use
# CUDA_INCLUDE_DIRECTORIES, but do get the proper list of
# include dirs I need to query the module system, which
# doesnt exist currently, so we manually call vtk_module_impl
vtk_module_impl()
cuda_include_directories(${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${VTKm_INCLUDE_DIRS}
${vtkAcceleratorsVTKm_DEPENDS_INCLUDE_DIRS})
cuda_add_library(vtkAcceleratorsVTKmCuda STATIC
${cuda_accelerator_srcs}
OPTIONS "${compile_options}"
)
set_target_properties(vtkAcceleratorsVTKmCuda
PROPERTIES POSITION_INDEPENDENT_CODE True)
vtk_module_library(vtkAcceleratorsVTKm
${headers}
${lib_srcs}
)
target_link_libraries(vtkAcceleratorsVTKm
PRIVATE vtkAcceleratorsVTKmCuda ${cache_devrt_libs})
set(CUDA_SEPARABLE_COMPILATION ${seperable_state})
set(CUDA_NVCC_FLAGS_CACHE ${cache_flag_state})
if(cache_cuda_libs)
set(CUDA_LIBRARIES ${cache_cuda_libs})
set(CUDA_cudadevrt_LIBRARY ${CUDA_cudadevrt_LIBRARY})
endif()
else()
vtk_module_library(vtkAcceleratorsVTKm
${headers}
${lib_srcs}
${cpu_accelerator_srcs}
)
endif()
#We need to system up VTK-m as a system include dir so that modules
#such as wrapping that depend on vtkAcceleratorsVTKm properly find
#the headers
target_include_directories(vtkAcceleratorsVTKm PUBLIC ${VTKm_INCLUDE_DIRS})
vtk_module_link_libraries(vtkAcceleratorsVTKm LINK_PRIVATE ${VTKm_LIBRARIES})
target_compile_options(vtkAcceleratorsVTKm PRIVATE ${VTKm_COMPILE_OPTIONS})
#install the required headers to make your own vtkm-vtk filter
if(NOT VTK_INSTALL_NO_DEVELOPMENT)
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/vtkmlib
DESTINATION ${VTK_INSTALL_INCLUDE_DIR}
COMPONENT Development)
endif()
find_package(VTKm REQUIRED COMPONENTS Base)
include_directories(${VTKm_INCLUDE_DIRS})
vtk_add_test_cxx(${vtk-module}CxxTests tests
# TestVTKMGradientAndVorticity.cxx,NO_VALID
TestVTKMLevelOfDetail.cxx
TestVTKMMarchingCubes.cxx
TestVTKMThreshold.cxx
TestVTKMThreshold2.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
RENDERING_FACTORY
)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: TestThreshold.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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.
=========================================================================*/
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkDataSetMapper.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkMaskPoints.h"
#include "vtkmLevelOfDetail.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTestUtilities.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkTriangleFilter.h"
int TestVTKMLevelOfDetail(int argc, char *argv[])
{
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
renWin->AddRenderer(ren.GetPointer());
iren->SetRenderWindow(renWin.GetPointer());
//---------------------------------------------------
// Load file and make only triangles
//---------------------------------------------------
char* fname =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/cow.vtp");
vtkNew<vtkXMLPolyDataReader> reader;
reader->SetFileName(fname);
delete[] fname;
vtkNew<vtkTriangleFilter> clean;
clean->SetInputConnection(reader->GetOutputPort());
clean->Update();
//---------------------------------------------------
// Test LOD filter 4 times
// We will setup 4 instances of the filter at different
// levels of subdivision to make sure it is working properly
//---------------------------------------------------
std::vector< vtkNew<vtkmLevelOfDetail> > levelOfDetails(4);
std::vector< vtkNew<vtkDataSetSurfaceFilter> > surfaces(4);
std::vector< vtkNew<vtkPolyDataMapper> > mappers(4);
std::vector< vtkNew<vtkActor> > actors(4);
for(int i=0; i < 4; ++i)
{
levelOfDetails[i]->SetInputConnection(clean->GetOutputPort());
//subdivision levels of 16, 32, 48, 64
levelOfDetails[i]->SetNumberOfXDivisions( ((i+1) * 16) );
levelOfDetails[i]->SetNumberOfYDivisions( ((i+1) * 16) );
levelOfDetails[i]->SetNumberOfZDivisions( ((i+1) * 16));
surfaces[i]->SetInputConnection(levelOfDetails[i]->GetOutputPort());
mappers[i]->SetInputConnection(surfaces[i]->GetOutputPort());
actors[i]->SetMapper(mappers[i].GetPointer());
actors[i]->SetPosition( i * 10, 0, 0);
ren->AddActor(actors[i].GetPointer());
}
ren->SetBackground(0.1, 0.2, 0.4);
ren->ResetCamera();
ren->GetActiveCamera()->Zoom(6.);
renWin->SetSize(1600, 250);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
//=============================================================================
//
// 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 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkActor.h"
#include "vtkCellData.h"
#include "vtkmContour.h"
#include "vtkElevationFilter.h"
#include "vtkImageData.h"
#include "vtkImageMandelbrotSource.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
namespace
{
template<typename T>
int RunVTKPipeline(T *t, int argc, char* argv[])
{
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
renWin->AddRenderer(ren.GetPointer());
iren->SetRenderWindow(renWin.GetPointer());
vtkNew<vtkmContour> cubes;
cubes->SetInputConnection(t->GetOutputPort());
cubes->SetInputArrayToProcess(
0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "Iterations");
cubes->SetNumberOfContours(1);
cubes->SetValue(0,50.5f);
cubes->ComputeScalarsOn();
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(cubes->GetOutputPort());
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("Elevation");
mapper->SetScalarRange(0.0, 1.0);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
ren->AddActor(actor.GetPointer());
ren->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
} // Anonymous namespace
int TestVTKMMarchingCubes(int argc, char* argv[])
{
//create the sample grid
vtkNew<vtkImageMandelbrotSource> src;
src->SetWholeExtent(0,250,0,250,0,250);
//create a secondary field for interpolation
vtkNew<vtkElevationFilter> elevation;
elevation->SetInputConnection(src->GetOutputPort());
elevation->SetScalarRange(0.0, 1.0);
elevation->SetLowPoint(-1.75, 0.0, 1.0);
elevation->SetHighPoint(0.75, 0.0, 1.0);
//run the pipeline
return RunVTKPipeline(elevation.GetPointer(),argc,argv);
}
//=============================================================================
//
// 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 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkActor.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkmThreshold.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkThreshold.h"
#include "vtkTrivialProducer.h"
namespace
{
void fillElevationArray(vtkFloatArray* elven, vtkImageData* grid)
{
elven->SetName("Elevation");
const vtkIdType size = grid->GetNumberOfPoints();
elven->SetNumberOfValues(size);
double pos[3]={0,0,0};
for(vtkIdType i=0; i < size; ++i)
{
grid->GetPoint(i,pos);
elven->SetValue(i,sqrt(vtkMath::Dot(pos,pos)));
}
}
int RunVTKPipeline(vtkImageData* grid, int argc, char* argv[])
{
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
renWin->AddRenderer(ren.GetPointer());
iren->SetRenderWindow(renWin.GetPointer());
//compute an elevation array
vtkNew<vtkFloatArray> elevationPoints;
fillElevationArray(elevationPoints.GetPointer(), grid);
grid->GetPointData()->AddArray(elevationPoints.GetPointer());
vtkNew<vtkTrivialProducer> producer;
producer->SetOutput(grid);
vtkNew<vtkmThreshold> threshold;
threshold->SetInputConnection(producer->GetOutputPort());
threshold->SetPointsDataTypeToFloat();
threshold->AllScalarsOn();
threshold->ThresholdBetween(0,100);
threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS,"Elevation");
vtkNew<vtkDataSetSurfaceFilter> surface;
surface->SetInputConnection(threshold->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(surface->GetOutputPort());
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("Elevation");
mapper->SetScalarRange(0.0, 100.0);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
ren->AddActor(actor.GetPointer());
ren->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
} // Anonymous namespace
int TestVTKMThreshold(int argc, char* argv[])
{
//create the sample grid
vtkNew<vtkImageData> grid;
int dim = 128;
grid->SetOrigin(0.0, 0.0, 0.0);
grid->SetSpacing(1.0, 1.0, 1.0);
grid->SetExtent(0, dim-1,0, dim-1,0, dim-1);
//run the pipeline
return RunVTKPipeline(grid.GetPointer(), argc, argv);
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestThreshold.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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.
=========================================================================*/
#include "vtkActor.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkmThreshold.h"
#include "vtkElevationFilter.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRTAnalyticSource.h"
int TestVTKMThreshold2(int argc, char *argv[])
{
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
renWin->AddRenderer(ren.GetPointer());
iren->SetRenderWindow(renWin.GetPointer());
//---------------------------------------------------
// Test using different thresholding methods
//---------------------------------------------------
vtkNew<vtkRTAnalyticSource> source;
vtkNew<vtkElevationFilter> elevation;
elevation->SetInputConnection(source->GetOutputPort());
elevation->SetScalarRange(0.0, 1.0);
elevation->SetLowPoint(-10.0, -10.0, -10.0);
elevation->SetHighPoint(10.0, 10.0, 10.0);
vtkNew<vtkmThreshold> threshold;
threshold->SetInputConnection(elevation->GetOutputPort());
threshold->SetInputArrayToProcess(
0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "RTData");
double L=100;
double U=200;
threshold->ThresholdBetween(L,U);
threshold->SetAllScalars(0);
threshold->Update();
threshold->UseContinuousCellRangeOn();
threshold->Update();
vtkNew<vtkDataSetSurfaceFilter> surface;
surface->SetInputConnection(threshold->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(surface->GetOutputPort());
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("Elevation");
mapper->SetScalarRange(0.0, 1.0);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
ren->AddActor(actor.GetPointer());
ren->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
vtk_module(vtkAcceleratorsVTKm
DEPENDS
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersGeneral
vtkFiltersGeometry
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingVolume${VTK_RENDERING_BACKEND}
vtkIOLegacy
vtkIOXML
vtkImagingSources
EXCLUDE_FROM_ALL
)
//=============================================================================
//
// 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 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmCellAverage.cxx"
//=============================================================================
//
// 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 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmCellAverage.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/DataSetConverters.h"
#include "vtkmlib/Storage.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include <vtkm/filter/CellAverage.h>