Skip to content
Permalink
Browse files

Merge pull request #464 from sellendk/vtkm

Vtkm
  • Loading branch information
tobiasrau committed Dec 23, 2019
2 parents 044ad8a + 25aaaa6 commit 194ac32eccf791085ec98b315241cb68bec0a0a6
@@ -565,6 +565,60 @@ function(require_external NAME)
mark_as_advanced(FORCE ZLIB_VERSION_PATCH)
mark_as_advanced(FORCE ZLIB_VERSION_TWEAK)

# vtkm
elseif(NAME STREQUAL "vtkm")
if(TARGET vtkm)
return()
endif()

set(VTKM_VER 1.4)

if(WIN32)
set(VTKM_LIB_CONT "lib/vtkm_cont-${VTKM_VER}.lib")
set(VTKM_LIB_DEBUG_CONT "lib/vtkm_cont-${VTKM_VER}.lib")
set(VTKM_LIB_RENDERER "lib/vtkm_rendering-${VTKM_VER}.lib")
set(VTKM_LIB_DEBUG_RENDERER "lib/vtkm_rendering-${VTKM_VER}.lib")
set(VTKM_LIB_WORKLET "lib/vtkm_worklet-${VTKM_VER}.lib")
set(VTKM_LIB_DEBUG_WORKLET "lib/vtkm_worklet-${VTKM_VER}.lib")
else()
include(GNUInstallDirs)
set(VTKM_LIB_CONT "lib/vtkm_cont-${VTKM_VER}.a")
set(VTKM_LIB_DEBUG_CONT "lib/vtkm_cont-${VTKM_VER}.a")
set(VTKM_LIB_RENDERER "lib/vtkm_rendering-${VTKM_VER}.a")
set(VTKM_LIB_DEBUG_RENDERER "lib/vtkm_rendering-${VTKM_VER}.a")
set(VTKM_LIB_WORKLET "lib/vtkm_worklet-${VTKM_VER}.a")
set(VTKM_LIB_DEBUG_WORKLET "lib/vtkm_worklet-${VTKM_VER}.a")
endif()

option(vtkm_ENABLE_CUDA "Option to build vtkm with cuda enabled" OFF)

add_external_project(vtkm
GIT_REPOSITORY https://gitlab.kitware.com/vtk/vtk-m.git
GIT_TAG "v1.4.0"
CMAKE_ARGS
-DBUILD_SHARED_LIBS:BOOL=OFF
-DVTKm_ENABLE_TESTING:BOOL=OFF
-DVTKm_ENABLE_CUDA:BOOL=${vtkm_ENABLE_CUDA}
-DBUILD_TESTING:BOOL=OFF
-VTKm_ENABLE_DEVELOPER_FLAGS:BOOL=OFF
-DCMAKE_BUILD_TYPE=Release
)

add_external_library(vtkm_cont STATIC
PROJECT vtkm
LIBRARY_RELEASE "${VTKM_LIB_CONT}"
LIBRARY_DEBUG "${VTKM_LIB_DEBUG_CONT}")

add_external_library(vtkm_renderer STATIC
PROJECT vtkm
LIBRARY_RELEASE "${VTKM_LIB_RENDERER}"
LIBRARY_DEBUG "${VTKM_LIB_DEBUG_RENDERER}")

add_external_library(vtkm_worklet STATIC
PROJECT vtkm
LIBRARY_RELEASE "${VTKM_LIB_WORKLET}"
LIBRARY_DEBUG "${VTKM_LIB_DEBUG_WORKLET}")

else()
message(FATAL_ERROR "Unknown external required \"${NAME}\"")
endif()
@@ -0,0 +1,67 @@
#
# MegaMol™ vtkm Plugin
# Copyright 2017, by MegaMol Team
# Alle Rechte vorbehalten. All rights reserved.
#
string(TOUPPER mmvtkm EXPORT_NAME)
option(BUILD_${EXPORT_NAME}_PLUGIN "Option to build mmvtkm" OFF)

if(BUILD_${EXPORT_NAME}_PLUGIN)
project(mmvtkm LANGUAGES CXX CUDA)

# Check option dependencies: First list item is always the current build option,
# afterwards list the dependencies.
set(DEP_LIST "${DEP_LIST};BUILD_${EXPORT_NAME}_PLUGIN BUILD_CORE" CACHE INTERNAL "")

# Add externals.
require_external(vtkm)

file(GLOB_RECURSE public_header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.h")
file(GLOB_RECURSE source_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.cpp")
file(GLOB_RECURSE header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "src/*.h")
#file(GLOB_RECURSE library_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "lib/*") # comment this line if implemented as external library
#file(GLOB_RECURSE shader_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "Shaders/*")

set_source_files_properties(source_files PROPERTIES LANGUAGE CUDA)

# external_get_property(vtkm INSTALL_MAIN_DIR)
external_get_property(vtkm SOURCE_DIR)
# message(${SOURCE_DIR})
string(REPLACE "-src" "-build" BUILD_DIR "${SOURCE_DIR}")

# Target definition
#add_library(${PROJECT_NAME} SHARED ${public_header_files} ${header_files} ${shader_files} ${source_files})
add_library(${PROJECT_NAME} SHARED ${public_header_files} ${header_files} ${source_files})
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".mmplg")
target_compile_definitions(${PROJECT_NAME} PRIVATE ${EXPORT_NAME}_EXPORTS)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
"include" "src" "lib"
"${SOURCE_DIR}"
"${BUILD_DIR}/Release/include"
"${SOURCE_DIR}/vtkm/thirdparty/taotuple"
"${SOURCE_DIR}/vtkm/thirdparty/diy"
)
target_link_libraries(${PROJECT_NAME} PRIVATE core vtkm_cont vtkm_renderer vtkm_worklet)

# Installation rules for generated files
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "include")
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Shaders/ DESTINATION "share/shaders")

if(WIN32)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "bin")
install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION "lib")
if(MSVC)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)
endif()
else()
install(TARGETS ${PROJECT_NAME} DESTINATION "lib" EXPORT ${PROJECT_NAME}-target)
endif()

# Grouping in Visual Studio
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER plugins)
source_group("Public Header Files" FILES ${public_header_files})
source_group("Header Files" FILES ${header_files})
source_group("Source Files" FILES ${source_files})
#source_group("Shaders" FILES ${shader_files})
endif()
Binary file not shown.
@@ -0,0 +1,41 @@
# mmvtkm
This plugin is used to render vtkm data using the vtkm libraries.
<img src="ModuleGraph.PNG">

## Prerequisits
CMake:
3.13.1 or above
Generator: Visual Studio 15 2017 x64

VTKm Version: Release build 1.5.0
MegaMol Version from 12.08.2019
Visual Studio Version: Visual Studio Enterprise 2017 Version 15.9.10 or above

## Build
TODO to run MegaMol with VTKm:
* turn on the plugin in cmake
* comment out the line "this->DataFile->Stream >> std::ws;" (should be around line 861) in ..\vtkm-src\vtkm\io\reader\VTKDataSetReaderBase.h

## TODO
* replace glDrawPixels and fix BoundingBox issue
* proper includes of vtkm header in cmake w.r.t. to external project targets
* solve issue with the line in VTKDataSetReaderBase.h
* duel CUDA

## Changelog
#### 07.11.2019
* updated plugin to use latest VTK-m version 1.5.0

#### 01.10.2019
* adapted plugin to new camera

#### 31.08.2019
* fixed issues with inconsistent naming

#### 23.08.2019
* extended cmake to now clone and built vtkm as external project
* the plugin works and can render vtkm data (e.g. the example data grid.vtk provided by vtkm)

#### 09.08.2019
* created the vtkm plugin and removed modules/calls from core
* adapted CMakeList to include headers and libraries automatically
@@ -0,0 +1,97 @@
/*
* VTKM.h
* Copyright (C) 2009-2015 by MegaMol Team
* Alle Rechte vorbehalten.
*/
#ifndef MMVTKM_H_INCLUDED
#define MMVTKM_H_INCLUDED
#if (defined(_MSC_VER) && (_MSC_VER > 1000))
#pragma once
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */


#ifdef _WIN32
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the TRISOUPPLUGIN_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// TRISOUPPLUGIN_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef MMVTKM_EXPORTS
#define MMVTKM_API __declspec(dllexport)
#else
#define MMVTKM_API __declspec(dllimport)
#endif
#else /* _WIN32 */
#define MMVTKM_API
#endif /* _WIN32 */

#include "mmcore/utility/plugins/Plugin200Instance.h"

#ifdef MMVTKM_EXPORTS
#ifdef __cplusplus
extern "C" {
#endif

/**
* Returns the version of the MegaMol� plugin api used by this plugin.
*
* @return 200 -- (ver.: 2.00)
*/
MMVTKM_API int mmplgPluginAPIVersion(void);

/**
* Provides compatibility information
*
* @param onError Callback function pointer used when an error occures
*
* @return The compatibility information struct, or nullptr in case of an
* error.
*
* @remarks Always use 'mmplgReleasePluginCompatibilityInfo' to release the
* memory of the returned struct.
*/
MMVTKM_API
::megamol::core::utility::plugins::PluginCompatibilityInfo *
mmplgGetPluginCompatibilityInfo(
::megamol::core::utility::plugins::ErrorCallback onError);

/**
* Releases the memory of a compatibility information struct previously
* returned by 'mmplgGetPluginCompatibilityInfo'
*
* @param ci The compatibility information struct to be released
*/
MMVTKM_API void mmplgReleasePluginCompatibilityInfo(
::megamol::core::utility::plugins::PluginCompatibilityInfo* ci);

/**
* Creates a new instance of this plugin
*
* @param onError Callback function pointer used when an error occures
*
* @return A new instance of this plugin, or nullptr in case of an error
*
* @remarks Always use 'mmplgReleasePluginInstance' to release the memory of
* the returned object.
*/
MMVTKM_API
::megamol::core::utility::plugins::AbstractPluginInstance*
mmplgGetPluginInstance
(::megamol::core::utility::plugins::ErrorCallback onError);

/**
* Releases the memory of the plugin instance previously returned by
* 'mmplgGetPluginInstance'
*
* @param pi The plugin instance to be released
*/
MMVTKM_API void mmplgReleasePluginInstance(
::megamol::core::utility::plugins::AbstractPluginInstance* pi);

#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

#endif /* MMVTKM_H_INCLUDED */
@@ -0,0 +1,106 @@
/*
* mmvtkmDataCall.h (MultiParticleDataCall)
*
* Copyright (C) 2009 by Universitaet Stuttgart (VISUS).
* Alle Rechte vorbehalten.
*/

#ifndef MEGAMOL_MMVTKM_MMVTKMDATACALL_H_INCLUDED
#define MEGAMOL_MMVTKM_MMVTKMDATACALL_H_INCLUDED
#if (defined(_MSC_VER) && (_MSC_VER > 1000))
# pragma once
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */

#include "vtkm/cont/DataSet.h"

#include "mmcore/AbstractGetData3DCall.h"
#include "mmcore/factories/CallAutoDescription.h"
//#include "mmcore/moldyn/SimpleSphericalParticles.h"

namespace megamol {
namespace mmvtkm {

// MEGAMOLCORE_APIEXT template class MEGAMOLCORE_API AbstractParticleDataCall<SimpleSphericalParticles>;


/**
* Call for multi-stream particle data.
*/
class mmvtkmDataCall : public core::AbstractGetData3DCall {
public:
/**
* Answer the name of the objects of this description.
*
* @return The name of the objects of this description.
*/
static const char* ClassName(void) { return "vtkmDataCall"; }

/**
* Answer a human readable description of this module.
*
* @return A human readable description of this module.
*/
static inline const char* Description(void) { return "Transports vtkm data."; }

/**
* Answer the number of functions used for this call.
*
* @return The number of functions used for this call.
*/
static unsigned int FunctionCount(void) { return AbstractGetData3DCall::FunctionCount(); }

/**
* Answer the name of the function used for this call.
*
* @param idx The index of the function to return it's name.
*
* @return The name of the requested function.
*/
static const char* FunctionName(unsigned int idx) { return AbstractGetData3DCall::FunctionName(idx); }

/** Ctor. */
mmvtkmDataCall(void);


/** Dtor. */
virtual ~mmvtkmDataCall(void);

/**
* Assignment operator.
* Makes a deep copy of all members. While for data these are only
* pointers, the pointer to the unlocker object is also copied.
*
* @param rhs The right hand side operand
*
* @return A reference to this
*/
mmvtkmDataCall& operator=(const mmvtkmDataCall& rhs);

/**
* Sets the mmvtkm data set file from the data source
*
* @param filename The file containing the mmvtkm data set
*/
void SetDataSet(vtkm::cont::DataSet* data) { this->mData = data; }

/**
* Returns the mmvtkm data set file from the data source
*
* @return The file containing the mmvtkm data set
*/
vtkm::cont::DataSet* GetDataSet() { return this->mData; }


private:
vtkm::cont::DataSet* mData;
};


/** Description class typedef */
typedef core::factories::CallAutoDescription<mmvtkmDataCall> mmvtkmDataCallDescription;


} /* end namespace mmvtkm */
} /* end namespace megamol */

#endif /* MEGAMOL_MMVTKM_MMVTKMDATACALL_H_INCLUDED */

0 comments on commit 194ac32

Please sign in to comment.
You can’t perform that action at this time.