From: riveros Date: Fri, 30 Mar 2012 13:36:45 +0000 (+0200) Subject: Simple DL-Open example X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaCLI.git;a=commitdiff_plain;h=462cbc78485df39d3141c2d1e6137c4b78ab5db2 Simple DL-Open example Used to test dl execution aka sandbox! --- diff --git a/ModuleCall/.dep.inc b/ModuleCall/.dep.inc new file mode 100644 index 0000000..4560e55 --- /dev/null +++ b/ModuleCall/.dep.inc @@ -0,0 +1,5 @@ +# This code depends on make tool being used +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) +ifneq (${DEPFILES},) +include ${DEPFILES} +endif diff --git a/ModuleCall/CMakeLists.txt b/ModuleCall/CMakeLists.txt new file mode 100644 index 0000000..474b985 --- /dev/null +++ b/ModuleCall/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +project (Inter) +set (Inter_VERSION_MAJOR 1) +set (Inter_VERSION_MINOR 0) + +SET(CMAKE_CXX_FLAGS "-ldl -w") + +FIND_PACKAGE (GenerateCLP REQUIRED) +if (GenerateCLP_FOUND) + INCLUDE(${GenerateCLP_USE_FILE}) +endif (GenerateCLP_FOUND) + +FIND_PACKAGE (ModuleDescriptionParser REQUIRED) +if (ModuleDescriptionParser_FOUND) + INCLUDE(${ModuleDescriptionParser_USE_FILE}) +endif (ModuleDescriptionParser_FOUND) + +SET(INCLUDE_DIRS + ${GenerateCLP_BINARY_DIR} + ${GenerateCLP_SOURCE_DIR} + ${ModuleDescriptionParser_BINARY_DIR} + ${ModuleDescriptionParser_SOURCE_DIR} + ) + +SET(LINK_DIRECTORIES + ${GenerateCLP_LINK_DIRECTORY} + ${ModuleDescriptionParser_LINK_DIRECTORY} + ) + +ADD_EXECUTABLE (interoperating_Baby main.cpp CreationTool.cxx) +TARGET_LINK_LIBRARIES (interoperating_Baby ${ModuleDescriptionParser_LIBRARY} ModuleDescriptionParser ) + diff --git a/ModuleCall/CreationTool.cxx b/ModuleCall/CreationTool.cxx new file mode 100644 index 0000000..8203b4d --- /dev/null +++ b/ModuleCall/CreationTool.cxx @@ -0,0 +1,164 @@ +/* + * File: CreationTool.cxx + * Author: riveros + * + * Created on 23 mars 2012, 10:12 + */ + +#include "CreationTool.h" + +std::string Mthd::Aux::toString ( float n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( double n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( long double n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( char n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( unsigned char n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( short n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( unsigned short n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( int n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( long int n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( unsigned int n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( unsigned long n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( unsigned long long n ) { + std::ostringstream oss; + oss << n; + return oss.str( ); +} + +std::string Mthd::Aux::toString ( std::string n ) { + return n; +} + +char* Mthd::Aux::toCharArrray ( float n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( double n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( long double n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( char n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( unsigned char n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( short n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( unsigned short n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( int n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( long int n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( unsigned int n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( long unsigned int n ) { + std::ostringstream oss; + oss << n; + return const_cast < char* > ( oss.str( ).data( ) ); +} + +char* Mthd::Aux::toCharArrray ( std::string n ) { + return const_cast < char* > ( n.data( ) ); +} + +std::string Mthd::Aux::replace_str ( std::string input, std::string old_str, std::string new_str ) { + size_t found = input.find( old_str ); + while ( found != std::string::npos ) { + input.replace( found, old_str.length( ), new_str ); + found = input.find( old_str ); + } + return input; +} + diff --git a/ModuleCall/CreationTool.h b/ModuleCall/CreationTool.h new file mode 100644 index 0000000..1859178 --- /dev/null +++ b/ModuleCall/CreationTool.h @@ -0,0 +1,63 @@ +/* + * File: CreationTool.h + * Author: riveros + * + * Created on 23 mars 2012, 10:12 + */ + +#ifndef CREATIONTOOL_H +#define CREATIONTOOL_H + +#include +#include +#include + +namespace Mthd { + + class Aux { + public: + static std::string toString ( float n ) ; + static std::string toString ( double n ) ; + static std::string toString ( long double n ) ; + + static std::string toString ( char n ) ; + static std::string toString ( unsigned char n ) ; + + static std::string toString ( short n ) ; + static std::string toString ( unsigned short n ) ; + + static std::string toString ( int n ) ; + static std::string toString ( long int n ) ; + static std::string toString ( unsigned int n ) ; + static std::string toString ( unsigned long n ) ; + static std::string toString ( unsigned long long n ) ; + + static std::string toString ( std::string n ) ; + + static char* toCharArrray ( float n ) ; + static char* toCharArrray ( double n ) ; + static char* toCharArrray ( long double n ) ; + + static char* toCharArrray ( char n ) ; + static char* toCharArrray ( unsigned char n ) ; + + static char* toCharArrray ( short n ) ; + static char* toCharArrray ( unsigned short n ) ; + + static char* toCharArrray ( int n ) ; + static char* toCharArrray ( long int n ) ; + static char* toCharArrray ( unsigned int n ) ; + static char* toCharArrray ( long unsigned int n ) ; + + static char* toCharArrray ( std::string n ) ; + + static std::string replace_str ( std::string input , std::string old_str , std::string new_str ) ; + + } ; + +} ; + + + +#endif /* CREATIONTOOL_H */ + diff --git a/ModuleCall/Makefile b/ModuleCall/Makefile new file mode 100644 index 0000000..c4a8046 --- /dev/null +++ b/ModuleCall/Makefile @@ -0,0 +1,193 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 2.8 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Produce verbose output by default. +VERBOSE = 1 + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/local/bin/cmake + +# The command to remove a file. +RM = /usr/local/bin/cmake -E remove -f + +# The program to use to edit the cache. +CMAKE_EDIT_COMMAND = /usr/local/bin/ccmake + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/riveros/NetBeansProjects/ModuleCall + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/riveros/NetBeansProjects/ModuleCall + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/local/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/local/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/riveros/NetBeansProjects/ModuleCall/CMakeFiles /home/riveros/NetBeansProjects/ModuleCall/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/riveros/NetBeansProjects/ModuleCall/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named interoperating_Baby + +# Build rule for target. +interoperating_Baby: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 interoperating_Baby +.PHONY : interoperating_Baby + +# fast build rule for target. +interoperating_Baby/fast: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/build +.PHONY : interoperating_Baby/fast + +CreationTool.o: CreationTool.cxx.o +.PHONY : CreationTool.o + +# target to build an object file +CreationTool.cxx.o: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/CreationTool.cxx.o +.PHONY : CreationTool.cxx.o + +CreationTool.i: CreationTool.cxx.i +.PHONY : CreationTool.i + +# target to preprocess a source file +CreationTool.cxx.i: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/CreationTool.cxx.i +.PHONY : CreationTool.cxx.i + +CreationTool.s: CreationTool.cxx.s +.PHONY : CreationTool.s + +# target to generate assembly for a file +CreationTool.cxx.s: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/CreationTool.cxx.s +.PHONY : CreationTool.cxx.s + +main.o: main.cpp.o +.PHONY : main.o + +# target to build an object file +main.cpp.o: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/main.cpp.o +.PHONY : main.cpp.o + +main.i: main.cpp.i +.PHONY : main.i + +# target to preprocess a source file +main.cpp.i: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/main.cpp.i +.PHONY : main.cpp.i + +main.s: main.cpp.s +.PHONY : main.s + +# target to generate assembly for a file +main.cpp.s: + $(MAKE) -f CMakeFiles/interoperating_Baby.dir/build.make CMakeFiles/interoperating_Baby.dir/main.cpp.s +.PHONY : main.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... interoperating_Baby" + @echo "... rebuild_cache" + @echo "... CreationTool.o" + @echo "... CreationTool.i" + @echo "... CreationTool.s" + @echo "... main.o" + @echo "... main.i" + @echo "... main.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/ModuleCall/bbSlicerDummy.dummy_cxx b/ModuleCall/bbSlicerDummy.dummy_cxx new file mode 100644 index 0000000..462fdea --- /dev/null +++ b/ModuleCall/bbSlicerDummy.dummy_cxx @@ -0,0 +1,50 @@ +#include "bbSlicerDummy.h" +#include "bbSlicerPackage.h" + +namespace bbSlicer { + BBTK_ADD_BLACK_BOX_TO_PACKAGE ( Slicer, Dummy ) + BBTK_BLACK_BOX_IMPLEMENTATION ( Dummy, bbtk::AtomicBlackBox ); + + void Dummy::Process ( ) { + + // GENERATED +_33333_ + // EO GENERATED + this->execute( lib, _argc, _argv ); + + } + + void Dummy::execute ( std::string lib, int _argc, char * _argv[] ) { + void* handle = dlopen( lib.c_str( ), RTLD_NOW | RTLD_GLOBAL ); + if ( ! handle ) { + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n'; + return; + } + typedef int (*method_t )( int argc, char * argv[] ); + // RESET ERROR + dlerror( ); + // PROTOTYPE + method_t myMethod = ( method_t ) dlsym( handle, "ModuleEntryPoint" ); + const char *dlsym_error = dlerror( ); + if ( dlsym_error ) { + std::cerr << "CAN'T LOAD SYMBOL 'ModuleEntryPoint':" << dlsym_error << '\n'; + dlclose( handle ); + return; + } + // METHOD CALL + myMethod( _argc, _argv ); + // CLOSING LIB + dlclose( handle ); + } + + void Dummy::bbUserSetDefaultValues ( ) { + } + + void Dummy::bbUserInitializeProcessing ( ) { + } + + void Dummy::bbUserFinalizeProcessing ( ) { + } +} +// EO namespace bbSlicer + diff --git a/ModuleCall/bbSlicerDummy.dummy_h b/ModuleCall/bbSlicerDummy.dummy_h new file mode 100644 index 0000000..1dd4d56 --- /dev/null +++ b/ModuleCall/bbSlicerDummy.dummy_h @@ -0,0 +1,53 @@ +#ifndef __bbSlicerDummy_h_INCLUDED__ +#define __bbSlicerDummy_h_INCLUDED__ + +#include "bbSlicer_EXPORT.h" +#include "bbtkAtomicBlackBox.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "CreationTool.h" + +namespace bbSlicer { + + class bbSlicer_EXPORT Dummy + : + public bbtk::AtomicBlackBox { + BBTK_BLACK_BOX_INTERFACE ( Dummy , bbtk::AtomicBlackBox ) ; + + // GENERATED ARGS + _11111_ + // EO GENERATED ARGS + + BBTK_PROCESS ( Process ) ; + void Process ( ) ; + private: + void execute ( std::string lib , int _argc , char * _argv[] ) ; + } ; + + BBTK_BEGIN_DESCRIBE_BLACK_BOX ( Dummy , bbtk::AtomicBlackBox ) ; + BBTK_NAME ( "_NNNNN_" ) ; + BBTK_AUTHOR ( "_AAAAA_" ) ; + BBTK_DESCRIPTION ( "_DDDDD_" ) ; + BBTK_CATEGORY ( "_CCCCC_" ) ; + + // GENERATED DESCRPTION + _22222_ + // EO GENERATED DESCRIPTION + + BBTK_END_DESCRIBE_BLACK_BOX ( Dummy ) ; +} + +#endif // __bbSlicerDummy_h_INCLUDED__ + diff --git a/ModuleCall/bbSlicerDummyBackUp.h b/ModuleCall/bbSlicerDummyBackUp.h new file mode 100644 index 0000000..3287b72 --- /dev/null +++ b/ModuleCall/bbSlicerDummyBackUp.h @@ -0,0 +1,34 @@ +#ifndef __bbSlicerDummy_h_INCLUDED__ +#define __bbSlicerDummy_h_INCLUDED__ + +#include "bbSlicer_EXPORT.h" +#include "bbtkAtomicBlackBox.h" + +#include +#include +#include + +namespace bbSlicer +{ +class bbSlicer_EXPORT Dummy:public bbtk::AtomicBlackBox{ + BBTK_BLACK_BOX_INTERFACE(Dummy,bbtk::AtomicBlackBox); +// GENERATED + BBTK_DECLARE_INPUT(In,double); +// EO GENERATED + BBTK_PROCESS(Process); + void Process(); +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(Dummy,bbtk::AtomicBlackBox); +BBTK_NAME("_NNNN"); +BBTK_AUTHOR("_AAAA"); +BBTK_DESCRIPTION("_DDDD"); +BBTK_CATEGORY("_CCCC"); +// GENERATED +BBTK_INPUT(Dummy,In,"input",double,""); +// EO GENERATED +BBTK_END_DESCRIBE_BLACK_BOX(Dummy); +} + +#endif // __bbSlicerDummy_h_INCLUDED__ + diff --git a/ModuleCall/bbSlicerGaussianBlur.cxx b/ModuleCall/bbSlicerGaussianBlur.cxx new file mode 100644 index 0000000..bb99921 --- /dev/null +++ b/ModuleCall/bbSlicerGaussianBlur.cxx @@ -0,0 +1,57 @@ +#include "bbSlicerGaussianBlur.h" +#include "bbSlicerPackage.h" + +namespace bbSlicer { + BBTK_ADD_BLACK_BOX_TO_PACKAGE ( Slicer, GaussianBlur ) + BBTK_BLACK_BOX_IMPLEMENTATION ( GaussianBlur, bbtk::AtomicBlackBox ); + + void GaussianBlur::Process ( ) { + + // GENERATED + +int _argc =3; +std::string lib = "/home/riveros/.slicer/Slicer4-bin/Slicer-build/lib/Slicer-4.0/cli-modules/libGaussianBlurImageFilterLib.so"; +char * _argv[ ] = { Mthd::Aux::toCharArrray( Mthd::Aux::toString( "-s" ) + Mthd::Aux::toString( bbGetInputsigma( ) ) ), +Mthd::Aux::toCharArrray( Mthd::Aux::toString( bbGetInputinputVolume( ) ) ), +Mthd::Aux::toCharArrray( Mthd::Aux::toString( bbGetInputoutputVolume( ) ) ) }; + + // EO GENERATED + this->execute( lib, _argc, _argv ); + + } + + void GaussianBlur::execute ( std::string lib, int _argc, char * _argv[] ) { + void* handle = dlopen( lib.c_str( ), RTLD_NOW | RTLD_GLOBAL ); + if ( ! handle ) { + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n'; + return; + } + typedef int (*method_t )( int argc, char * argv[] ); + // RESET ERROR + dlerror( ); + // PROTOTYPE + method_t myMethod = ( method_t ) dlsym( handle, "ModuleEntryPoint" ); + const char *dlsym_error = dlerror( ); + if ( dlsym_error ) { + std::cerr << "CAN'T LOAD SYMBOL 'ModuleEntryPoint':" << dlsym_error << '\n'; + dlclose( handle ); + return; + } + // METHOD CALL + myMethod( _argc, _argv ); + // CLOSING LIB + dlclose( handle ); + } + + void GaussianBlur::bbUserSetDefaultValues ( ) { + } + + void GaussianBlur::bbUserInitializeProcessing ( ) { + } + + void GaussianBlur::bbUserFinalizeProcessing ( ) { + } +} +// EO namespace bbSlicer + + diff --git a/ModuleCall/bbSlicerGaussianBlur.h b/ModuleCall/bbSlicerGaussianBlur.h new file mode 100644 index 0000000..98aa7bf --- /dev/null +++ b/ModuleCall/bbSlicerGaussianBlur.h @@ -0,0 +1,62 @@ +#ifndef __bbSlicerGaussianBlur_h_INCLUDED__ +#define __bbSlicerGaussianBlur_h_INCLUDED__ + +#include "bbSlicer_EXPORT.h" +#include "bbtkAtomicBlackBox.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "CreationTool.h" + +namespace bbSlicer { + + class bbSlicer_EXPORT GaussianBlur + : + public bbtk::AtomicBlackBox { + BBTK_BLACK_BOX_INTERFACE ( GaussianBlur , bbtk::AtomicBlackBox ) ; + + // GENERATED ARGS + +BBTK_DECLARE_INPUT ( sigma , double ); +BBTK_DECLARE_INPUT ( inputVolume , std::string ); +BBTK_DECLARE_INPUT ( outputVolume , std::string ); + + // EO GENERATED ARGS + + BBTK_PROCESS ( Process ) ; + void Process ( ) ; + private: + void execute ( std::string lib , int _argc , char * _argv[] ) ; + } ; + + BBTK_BEGIN_DESCRIBE_BLACK_BOX ( GaussianBlur , bbtk::AtomicBlackBox ) ; + BBTK_NAME ( "GaussianBlur" ) ; + BBTK_AUTHOR ( "Julien Jomier and Stephen Aylward" ) ; + BBTK_DESCRIPTION ( "Apply a gaussian blurr to an image" ) ; + BBTK_CATEGORY ( "Filtering.Denoising" ) ; + + // GENERATED DESCRPTION + +BBTK_INPUT(GaussianBlur , sigma , "sigma" , double, ""); +BBTK_INPUT(GaussianBlur , inputVolume , "inputVolume" , std::string, ""); +BBTK_INPUT(GaussianBlur , outputVolume , "outputVolume" , std::string, ""); + + // EO GENERATED DESCRIPTION + + BBTK_END_DESCRIBE_BLACK_BOX ( GaussianBlur ) ; +} + +#endif // __bbSlicerGaussianBlur_h_INCLUDED__ + + diff --git a/ModuleCall/cmake_install.cmake b/ModuleCall/cmake_install.cmake new file mode 100644 index 0000000..754308a --- /dev/null +++ b/ModuleCall/cmake_install.cmake @@ -0,0 +1,44 @@ +# Install script for directory: /home/riveros/NetBeansProjects/ModuleCall + +# Set the install prefix +IF(NOT DEFINED CMAKE_INSTALL_PREFIX) + SET(CMAKE_INSTALL_PREFIX "/usr/local") +ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX) +STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + IF(BUILD_TYPE) + STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + ELSE(BUILD_TYPE) + SET(CMAKE_INSTALL_CONFIG_NAME "Debug") + ENDIF(BUILD_TYPE) + MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + +# Set the component getting installed. +IF(NOT CMAKE_INSTALL_COMPONENT) + IF(COMPONENT) + MESSAGE(STATUS "Install component: \"${COMPONENT}\"") + SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + ELSE(COMPONENT) + SET(CMAKE_INSTALL_COMPONENT) + ENDIF(COMPONENT) +ENDIF(NOT CMAKE_INSTALL_COMPONENT) + +# Install shared libraries without execute permission? +IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) + SET(CMAKE_INSTALL_SO_NO_EXE "1") +ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) + +IF(CMAKE_INSTALL_COMPONENT) + SET(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") +ELSE(CMAKE_INSTALL_COMPONENT) + SET(CMAKE_INSTALL_MANIFEST "install_manifest.txt") +ENDIF(CMAKE_INSTALL_COMPONENT) + +FILE(WRITE "/home/riveros/NetBeansProjects/ModuleCall/${CMAKE_INSTALL_MANIFEST}" "") +FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES}) + FILE(APPEND "/home/riveros/NetBeansProjects/ModuleCall/${CMAKE_INSTALL_MANIFEST}" "${file}\n") +ENDFOREACH(file) diff --git a/ModuleCall/interoperating_Baby b/ModuleCall/interoperating_Baby new file mode 100755 index 0000000..72882e8 Binary files /dev/null and b/ModuleCall/interoperating_Baby differ diff --git a/ModuleCall/main.cpp b/ModuleCall/main.cpp new file mode 100644 index 0000000..9f7d71a --- /dev/null +++ b/ModuleCall/main.cpp @@ -0,0 +1,266 @@ +/* + * File: main.cpp + * Author: gabriel + * + * Created on 15 février 2012, 19:50 + */ + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include +#include + +#include "CreationTool.h" + + +/// STD LD_OPEN CALLS /// + +char* getModuleDescription ( std::string lib ) { + void* handle = dlopen( lib.c_str( ), RTLD_NOW | RTLD_GLOBAL ); + if ( ! handle ) { + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n'; + return NULL; + } + typedef char* ( *method_t )( void ); + // RESET ERRORS + dlerror( ); + method_t myMethod = ( method_t ) dlsym( handle, "GetXMLModuleDescription" ); + const char *dlsym_error = dlerror( ); + if ( dlsym_error ) { + std::cerr << "CAN'T LOAD SYMBOL 'GetXMLModuleDescription: " << dlsym_error << '\n'; + dlclose( handle ); + return NULL; + } + // CALLING METHOD + char* descrption = myMethod( ); + // CLOSING LIB + dlclose( handle ); + return descrption; + +} + +void execute ( std::string lib, int _argc, char * _argv[] ) { + void* handle = dlopen( lib.c_str( ), RTLD_NOW | RTLD_GLOBAL ); + if ( ! handle ) { + std::cerr << "CAN'T OPEN LIBRARY: " << dlerror( ) << '\n'; + return; + } + typedef int (*method_t )( int argc, char * argv[] ); + // RESET ERRORS + dlerror( ); + method_t myMethod = ( method_t ) dlsym( handle, "ModuleEntryPoint" ); + const char *dlsym_error = dlerror( ); + if ( dlsym_error ) { + std::cerr << "CAN'T LOAD SYMBOL 'ModuleEntryPoint' " << dlsym_error << '\n'; + dlclose( handle ); + return; + } + // CALLING METHOD + myMethod( _argc, _argv ); + // CLOSING LIB + dlclose( handle ); +} + +/// FILE RELATED /// + +void saveFile ( std::string content, std::string file_name ) { + std::ofstream myfile; + myfile.open( file_name.c_str( ) ); + myfile << content; + myfile.close( ); +} + +std::string loadFile ( std::string filename ) { + std::string line = std::string( "" ); + std::string content = std::string( "" ); + + std::ifstream infile; + infile.open( filename.c_str( ) ); + while ( ! infile.eof( ) ) { + getline( infile, line ); + content += line + "\n"; + line.clear( ); + } + infile.close( ); + return content; + +} + +std::string loadDummyBody ( ) { + return loadFile( "bbSlicerDummy.dummy_cxx" ); +} + +std::string loadDummyHeader ( ) { + return loadFile( "bbSlicerDummy.dummy_h" ); +} + +/// BBTK BOX CREATION /// + +std::string updateBoxDescription ( const ModuleDescription* module, std::string _header ) { + _header = Mthd::Aux::replace_str( _header, "_NNNNN_", Mthd::Aux::replace_str( module->GetTitle( ), " ", "" ) ); + _header = Mthd::Aux::replace_str( _header, "_AAAAA_", module->GetContributor( ) ); + _header = Mthd::Aux::replace_str( _header, "_DDDDD_", module->GetDescription( ) ); + _header = Mthd::Aux::replace_str( _header, "_CCCCC_", module->GetCategory( ) ); + return _header; +} + +std::string updateBoxName ( const ModuleDescription* module, std::string content ) { + std::string _new_box_name = Mthd::Aux::replace_str( module->GetTitle( ), " ", "" ); + content = Mthd::Aux::replace_str( content, "Dummy", _new_box_name ); + return content; +} + +std::string getHeaderFileName ( const ModuleDescription* module ) { + std::string name = Mthd::Aux::replace_str( module->GetTitle( ), " ", "" ); + + return "bbSlicer" + name + ".h"; +} + +std::string getBodyFileName ( const ModuleDescription* module ) { + std::string name = Mthd::Aux::replace_str( module->GetTitle( ), " ", "" ); + + return "bbSlicer" + name + ".cxx"; +} + +std::string updateBoxInputs ( const ModuleDescription* module, std::string content ) { + + std::string _cxx_inputs = std::string( "\n" ); + std::string _cxx_inputs_end = std::string( "\n" ); + std::string _box_name = Mthd::Aux::replace_str( module->GetTitle( ), " ", "" ); + + for ( unsigned long int i = 0; i < module->GetParameterGroups( ).size( ); i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ); + for ( unsigned long int j = 0; j < pGroup.GetParameters( ).size( ); j ++ ) { + ModuleParameter mPara = pGroup.GetParameters( ).at( j ); + _cxx_inputs += + "BBTK_DECLARE_INPUT ( " + + mPara.GetName( ) + " , " + + mPara.GetCPPType( ) + " );\n"; + + _cxx_inputs_end += + "BBTK_INPUT(" + + _box_name + " , " + + mPara.GetName( ) + " , " + + "\"" + mPara.GetName( ) + "\"" + " , " + + mPara.GetCPPType( ) + ", \"\");\n"; + } + } + content = Mthd::Aux::replace_str( content, "_11111_", _cxx_inputs ); + content = Mthd::Aux::replace_str( content, "_22222_", _cxx_inputs_end ); + + return content; +} + +const int getNumberOfArguments ( const ModuleDescription* module ) { + int number = 0; + for ( unsigned long int i = 0; i < module->GetParameterGroups( ).size( ); i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ); + for ( unsigned long int j = 0; j < pGroup.GetParameters( ).size( ); j ++ ) { + + ModuleParameter mPara = pGroup.GetParameters( ).at( j ); + number ++; + } + } + return number; +} + +std::string updateProcessMethod ( const ModuleDescription* module, std::string content, std::string lib ) { + int number = 0; + std::string arg_list = std::string( "" ); + for ( unsigned long int i = 0; i < module->GetParameterGroups( ).size( ); i ++ ) { + ModuleParameterGroup pGroup = module->GetParameterGroups( ).at( i ); + for ( unsigned long int j = 0; j < pGroup.GetParameters( ).size( ); j ++ ) { + + ModuleParameter mPara = pGroup.GetParameters( ).at( j ); + + arg_list += "Mthd::Aux::toCharArrray( "; + if ( mPara.GetFlag( ) != "" ) { + arg_list += "Mthd::Aux::toString( \""; + arg_list += "-" + mPara.GetFlag( ) + "\" "; + arg_list += " ) + "; + + } else if ( mPara.GetLongFlag( ) != "" ) { + arg_list += "Mthd::Aux::toString( \""; + arg_list += "--" + mPara.GetLongFlag( ) + "\" "; + arg_list += " ) + "; + } + + arg_list += "Mthd::Aux::toString( bbGetInput" + mPara.GetName( ) + "( ) )"; + arg_list += " ),\n"; + number ++; + } + + } + arg_list += "_EEENNNDDD_"; + arg_list = Mthd::Aux::replace_str( arg_list, ",\n_EEENNNDDD_", "" ); + std::string _argc = "\nint _argc =" + Mthd::Aux::toString( number ) + ";\n"; + std::string _slib = "std::string lib = \"" + lib + "\";\n"; + std::string _argv = "char * _argv[ ] = { " + arg_list + " };\n"; + return Mthd::Aux::replace_str( content, "_33333_", _argc + _slib + _argv ); +} + +int main ( int argc, char* argv[] ) { + + int _argc = 3; + char * _argv[] = { "-s 20", "/home/riveros/Desktop/Experiments/RA1.mhd", "/home/riveros/Desktop/Experiments/RA1-OUT-MAIN.mhd" }; + std::string gblib = "/home/riveros/.slicer/Slicer4-bin/Slicer-build/lib/Slicer-4.0/cli-modules/libGaussianBlurImageFilterLib.so"; + + execute( gblib, _argc, _argv ); + + /// MODULE INFORMATION /// + const std::string des = getModuleDescription( gblib ); + + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // + // std::cout << des << std::endl << std::endl; + + ModuleDescription module; + ModuleDescriptionParser parser; + + parser.Parse( des, module ); + + /// LOADING DUMMY FILES /// + std::string _body = loadDummyBody( ); + std::string _header = loadDummyHeader( ); + + /// SETTING HEADER FILE /// + _header = updateBoxName( &module, _header ); + _header = updateBoxDescription( &module, _header ); + _header = updateBoxInputs( &module, _header ); + saveFile( _header, getHeaderFileName( &module ) ); + + /// SETTING BODY FILE /// + _body = updateBoxName( &module, _body ); + _body = updateProcessMethod( &module, _body, gblib ); + saveFile( _body, getBodyFileName( &module ) ); + + + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // + // std::cout << _header << std::endl; + // + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // std::cout << "====================================" << std::endl << std::endl; + // + // std::cout << _body << std::endl; + + return EXIT_SUCCESS; +}