Commit 382d1c52 authored by Artur Grunau's avatar Artur Grunau
Browse files

Lua scripting: rearrange interface files

All interface files used to live under `scripting/`. However, that
separated them from the code they were binding and clustered them
unnecessarily.

Make each interface file part of the CAMPVis component whose code it's
binding. This fixes the issues mentioned above and makes it possible to
build Lua modules conditionally, depending on what components of CAMPVis
are enabled.

References #1
parent 32780169
......@@ -29,3 +29,6 @@ moc_*.cxx_parameters
# TBB library in ext/
ext/tbb
# SWIG wrapper code
*LUA_wrap.cxx
%module campvis
%include factory.i
%include std_string.i
%import tgt.i
%import "ext/tgt/bindings/tgt.i"
%{
#include "core/properties/genericproperty.h"
#include "core/properties/numericproperty.h"
......
%module vis
%module cvio
%include std_string.i
%import campvis.i
%import "core/bindings/campvis.i"
%{
#include "core/pipeline/visualizationprocessor.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/preprocessing/processors/glimageresampler.h"
#include "modules/vis/processors/volumeexplorer.h"
%}
%inline %{
int first(tgt::ivec2 &v) {
return v[0];
}
%}
namespace campvis {
......@@ -33,30 +26,4 @@ namespace campvis {
campvis::DataNameProperty p_targetImageID;
%mutable;
};
class GlImageResampler : public VisualizationProcessor {
public:
GlImageResampler(campvis::IVec2Property* viewportSizeProp);
~GlImageResampler();
const std::string getName() const;
%immutable;
campvis::DataNameProperty p_inputImage;
campvis::DataNameProperty p_outputImage;
%mutable;
};
class VolumeExplorer : public VisualizationProcessor {
public:
VolumeExplorer(campvis::IVec2Property* viewportSizeProp);
~VolumeExplorer();
const std::string getName() const;
%immutable;
campvis::DataNameProperty p_inputVolume;
campvis::DataNameProperty p_outputImage;
%mutable;
};
}
%module preprocessing
%include std_string.i
%import "core/bindings/campvis.i"
%{
#include "modules/preprocessing/processors/glimageresampler.h"
%}
namespace campvis {
class GlImageResampler : public VisualizationProcessor {
public:
GlImageResampler(campvis::IVec2Property* viewportSizeProp);
~GlImageResampler();
const std::string getName() const;
%immutable;
campvis::DataNameProperty p_inputImage;
campvis::DataNameProperty p_outputImage;
%mutable;
};
}
%module vis
%include std_string.i
%import "core/bindings/campvis.i"
%{
#include "modules/vis/processors/volumeexplorer.h"
%}
namespace campvis {
class VolumeExplorer : public VisualizationProcessor {
public:
VolumeExplorer(campvis::IVec2Property* viewportSizeProp);
~VolumeExplorer();
const std::string getName() const;
%immutable;
campvis::DataNameProperty p_inputVolume;
campvis::DataNameProperty p_outputImage;
%mutable;
};
}
# SWIG wrapper code
/*LUA_wrap.cxx
# Header with SWIG run-time functions
/swigluarun.h
......@@ -30,31 +30,37 @@ FILE(GLOB CampvisScriptingHeaders
)
# Declare Lua modules to be generated by SWIG
SET_SOURCE_FILES_PROPERTIES(tgt.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(tgt-lua-mod lua tgt.i)
SWIG_LINK_LIBRARIES(tgt-lua-mod tgt ${CampvisGlobalExternalLibs})
SET_SOURCE_FILES_PROPERTIES(campvis.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(campvis-lua-mod lua campvis.i)
SWIG_LINK_LIBRARIES(campvis-lua-mod campvis-core tgt ${CampvisGlobalExternalLibs})
SET_SOURCE_FILES_PROPERTIES(vis.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(vis-lua-mod lua vis.i)
SWIG_LINK_LIBRARIES(vis-lua-mod campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
# Place all of CAMPVis' Lua modules in one sub-directory and shorten their names. This is done to
# make Lua modules easier to import and avoid mixing them with other CAMPVis' libraries.
SET(CampvisLuaModules tgt-lua-mod campvis-lua-mod vis-lua-mod)
SET(CampvisLuaModulesDirectory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/lua-mods/")
# Lua modules will be placed in a sub-directory that won't be picked up by Lua automatically. Let
# the code know via a #define what that sub-directory is so that it can instruct Lua to search it.
LIST(APPEND CampvisScriptingDefinitions "-DCAMPVIS_LUA_MODS_PATH=\"${CampvisLuaModulesDirectory}?${CMAKE_SHARED_MODULE_SUFFIX}\"")
FOREACH(LuaMod ${CampvisLuaModules})
STRING(REPLACE "-lua-mod" "" LuaModShortName ${LuaMod})
SET(CampvisBindingDirs ext/tgt core)
# Look for bindings for all enabled CAMPVis modules
FOREACH(ModName ${CampvisModules})
STRING(TOUPPER ${ModName} ModNameUpper)
IF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
LIST(APPEND CampvisBindingDirs "modules/${ModName}")
ENDIF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
ENDFOREACH(ModName ${CampvisModules})
# Declare a Lua module to be generated by SWIG from the specified interface file
MACRO(DECLARE_LUA_MODULE InterfaceFile)
STRING(REGEX REPLACE ".*/([A-Za-z0-9_]+)\\.i" "\\1" LuaModShortName ${InterfaceFile})
SET(LuaModName "${LuaModShortName}-lua-mod")
MESSAGE(STATUS "* ${LuaModShortName}")
SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES SWIG_FLAGS "-I${CampvisHome}")
SWIG_ADD_MODULE(${LuaModName} lua ${InterfaceFile})
SWIG_LINK_LIBRARIES(${LuaModName} tgt campvis-core campvis-modules ${CampvisGlobalExternalLibs})
SET(LuaModFullPath "${CampvisLuaModulesDirectory}${CMAKE_SHARED_LIBRARY_PREFIX}${LuaModShortName}${CMAKE_SHARED_LIBRARY_SUFFIX}")
# The most reliable approach to changing a target's output directory to a sub-directory of the
......@@ -62,12 +68,26 @@ FOREACH(LuaMod ${CampvisLuaModules})
# to invoke a custom command to copy the necessary files after the build finishes. For more
# details see: http://www.cmake.org/pipermail/cmake/2008-June/022358.html
ADD_CUSTOM_COMMAND(
TARGET ${LuaMod}
TARGET ${LuaModName}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CampvisLuaModulesDirectory}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LuaMod}> ${LuaModFullPath}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LuaModName}> ${LuaModFullPath}
)
ENDFOREACH(LuaMod ${CampvisLuaModules})
LIST(APPEND CampvisLuaModules ${LuaModName})
ENDMACRO(DECLARE_LUA_MODULE)
MESSAGE(STATUS "Setting up Lua modules:")
# Generate a Lua module for every interface file found
FOREACH(BindingDir ${CampvisBindingDirs})
FILE(GLOB InterfaceFiles "${CampvisHome}/${BindingDir}/bindings/*.i")
FOREACH(InterfaceFile ${InterfaceFiles})
FILE(RELATIVE_PATH InterfaceFileRelativePath ${CMAKE_CURRENT_SOURCE_DIR} ${InterfaceFile})
DECLARE_LUA_MODULE(${InterfaceFileRelativePath})
ENDFOREACH(InterfaceFile ${InterfaceFiles})
ENDFOREACH(BindingDir ${CampvisBindingDirs})
# Generate header with SWIG run-time functions
......@@ -86,4 +106,5 @@ TARGET_LINK_LIBRARIES(campvis-scripting-test campvis-core campvis-modules tgt ${
ADD_LIBRARY(campvis-scripting
${CampvisScriptingSources} ${CampvisScriptingHeaders}
)
ADD_DEPENDENCIES(campvis-scripting ${CampvisLuaModules})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
require("tgt")
require("cvio")
require("vis")
require("preprocessing")
pipeline = campvis.newPipeline()
function pipeline:ctor()
print("I'm being constructed!")
self.image_reader = vis.MhdImageReader()
self.image_reader = cvio.MhdImageReader()
self.addProcessor(instance, self.image_reader)
local iv = tgt.ivec2(50, 10)
print(vis.first(iv))
print(vis.first(tgt.ivec2_zero))
local ivp = campvis.IVec2Property("a", "b", iv, tgt.ivec2_zero, tgt.ivec2(100, 30))
self.ve = vis.VolumeExplorer(ivp)
self.resampler = vis.GlImageResampler(ivp)
self.resampler = preprocessing.GlImageResampler(ivp)
self.addProcessor(instance, self.resampler)
self.addProcessor(instance, self.ve)
......@@ -33,10 +32,10 @@ function pipeline:init()
self.resampler.p_outputImage:setValue("resampled")
self.resampler.p_outputImage:addSharedProperty(self.ve.p_inputVolume)
local geometry1 = campvis.TFGeometry1D_createQuad(campvis.vec2(0.1, 0.125), campvis.col4(255, 0, 0, 32),
campvis.vec4(255, 0, 0, 32))
local geometry2 = campvis.TFGeometry1D_createQuad(campvis.vec2(.4, .5), campvis.col4(0, 255, 0, 128),
campvis.vec4(0, 255, 0, 128))
local geometry1 = campvis.TFGeometry1D_createQuad(tgt.vec2(0.1, 0.125), tgt.col4(255, 0, 0, 32),
tgt.vec4(255, 0, 0, 32))
local geometry2 = campvis.TFGeometry1D_createQuad(tgt.vec2(.4, .5), tgt.col4(0, 255, 0, 128),
tgt.vec4(0, 255, 0, 128))
local dvrTF = campvis.Geometry1DTransferFunction(128, campvis.vec2(0, 0.05))
dvrTF:addGeometry(geometry1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment