commit b14311ce0976debbb11568d9f17291aa7936d512 Author: AndreaRigoni Date: Tue Apr 17 15:39:10 2018 +0200 switch to git no-history version diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..129c2ad --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +/** + * CMT - Written and Mantained by: + * + * A. Rigoni ( andrea.rigoni@pd.infn.it ) + * M. Furlan ( matteo.furlan@pd.infn.it ) + * S. Vanini ( sara.vanini@pd.infn.it ) + * + **/ diff --git a/CMake/FindEigen3.cmake b/CMake/FindEigen3.cmake new file mode 100644 index 0000000..9c546a0 --- /dev/null +++ b/CMake/FindEigen3.cmake @@ -0,0 +1,81 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, +# Copyright (c) 2008, 2009 Gael Guennebaud, +# Copyright (c) 2009 Benoit Jacob +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_check_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) + if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK FALSE) + else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK TRUE) + endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + + if(NOT EIGEN3_VERSION_OK) + + message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " + "but at least version ${Eigen3_FIND_VERSION} is required") + endif(NOT EIGEN3_VERSION_OK) +endmacro(_eigen3_check_version) + +if (EIGEN3_INCLUDE_DIR) + + # in cache already + _eigen3_check_version() + set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) + +else (EIGEN3_INCLUDE_DIR) + + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + PATHS + ${CMAKE_INSTALL_PREFIX}/include + ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES eigen3 eigen + ) + + if(EIGEN3_INCLUDE_DIR) + _eigen3_check_version() + endif(EIGEN3_INCLUDE_DIR) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) + + mark_as_advanced(EIGEN3_INCLUDE_DIR) + +endif(EIGEN3_INCLUDE_DIR) + diff --git a/CMake/FindGEANT4.cmake b/CMake/FindGEANT4.cmake new file mode 100644 index 0000000..b351c08 --- /dev/null +++ b/CMake/FindGEANT4.cmake @@ -0,0 +1,63 @@ +# - Try to find GEANT4 +# Once done this will define +# +# GEANT4_FOUND - system has GEANT4 +# GEANT4_INCLUDE_DIR - the GEANT4 include directory +# GEANT4_LIBRARIES - The libraries needed to use GEANT4 +# GEANT4_DEFINITIONS - Compiler switches required for using GEANT4 +# + +if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR) + SET (GEANT4_INCLUDE_DIR GEANT4_INCLUDE_DIR-NOTFOUND) + SET (GEANT4_LIB_DIR GEANT4_LIB_DIR-NOTFOUND) + SET (GEANT4_PLISTS_LIB_DIR GEANT4_PLISTS_LIB_DIR-NOTFOUND) + SET (GEANT4_DIR GEANT4_DIR-NOTFOUND) +endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR) + +MESSAGE(STATUS "Looking for GEANT4...") + +FIND_PATH(GEANT4_DIR NAMES env.sh PATHS + ${SIMPATH}/transport/geant4 + ${SIMPATH}/transport/geant4/source + NO_DEFAULT_PATH +) + +FIND_PATH(GEANT4_INCLUDE_DIR NAMES G4Event.hh PATHS + ${SIMPATH}/transport/geant4/include + NO_DEFAULT_PATH +) + +SET(GEANT4_INCLUDE_DIR +${SIMPATH}/transport/geant4/include +${SIMPATH}/transport/geant4/source/interfaces/common/include +${SIMPATH}/transport/geant4/physics_lists/hadronic/Packaging/include +${SIMPATH}/transport/geant4/physics_lists/hadronic/QGSP/include +) + +FIND_PATH(GEANT4_LIB_DIR NAMES libG4baryons.so libG4baryons.dylib PATHS + ${SIMPATH}/transport/geant4/lib/Linux-g++ + ${SIMPATH}/transport/geant4/lib/Linux-icc + ${SIMPATH}/transport/geant4/lib + NO_DEFAULT_PATH +) + +IF (GEANT4_LIB_DIR) + SET(GEANT4_LIBRARY_DIR ${GEANT4_LIB_DIR}) +ENDIF (GEANT4_LIB_DIR) + +if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR) + set(GEANT4_FOUND TRUE) +endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR) + +if (GEANT4_FOUND) + if (NOT GEANT4_FIND_QUIETLY) + MESSAGE(STATUS "Looking for GEANT4... - found ${GEANT4_LIBRARY_DIR}") +# message(STATUS "Found ${GEANT4_LIBRARY_DIR}") + endif (NOT GEANT4_FIND_QUIETLY) + SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4_LIBRARY_DIR}) +else (GEANT4_FOUND) + if (GEANT4_FIND_REQUIRED) + message(FATAL_ERROR "Looking for GEANT4... - Not found") + endif (GEANT4_FIND_REQUIRED) +endif (GEANT4_FOUND) + diff --git a/CMake/FindGEANT4VMC.cmake b/CMake/FindGEANT4VMC.cmake new file mode 100644 index 0000000..5dec1b5 --- /dev/null +++ b/CMake/FindGEANT4VMC.cmake @@ -0,0 +1,97 @@ +# - Try to find GEANT4VMC +# Once done this will define +# +# GEANT4VMC_FOUND - system has GEANT3 +# GEANT4VMC_INCLUDE_DIR - the GEANT3 include directory +# GEANT4VMC_LIBRARIES - The libraries needed to use GEANT3 +# GEANT4VMC_DEFINITIONS - Compiler switches required for using GEANT3 +# + +if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR) + SET (GEANT4VMC_INCLUDE_DIR GEANT4VMC_INCLUDE_DIR-NOTFOUND) + SET (GEANT4VMC_LIB_DIR GEANT4VMC_LIB_DIR-NOTFOUND) + SET (GEANT4VMC_PLISTS_LIB_DIR GEANT4VMC_PLISTS_LIB_DIR-NOTFOUND) +endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR) + +MESSAGE(STATUS "Looking for GEANT4VMC...") + +FIND_PATH(GEANT4VMC_INCLUDE_DIR NAMES TG4G3Units.h PATHS + ${SIMPATH}/transport/geant4_vmc/include + NO_DEFAULT_PATH +) + +set(GEANT4VMC_INCLUDE_DIR +${SIMPATH}/transport/geant4_vmc/source/global/include +${SIMPATH}/transport/geant4_vmc/source/geometry/include +${SIMPATH}/transport/geant4_vmc/source/digits+hits/include +${SIMPATH}/transport/geant4_vmc/source/physics/include +${SIMPATH}/transport/geant4_vmc/source/event/include +${SIMPATH}/transport/geant4_vmc/source/run/include +${SIMPATH}/transport/geant4_vmc/source/interfaces/include +${SIMPATH}/transport/geant4_vmc/source/visualization/include +${SIMPATH}/transport/geant4_vmc/include +${SIMPATH}/transport/vgm/packages/BaseVGM/include +${SIMPATH}/transport/vgm/packages/ClhepVGM/include +${SIMPATH}/transport/vgm/packages/Geant4GM/include +${SIMPATH}/transport/vgm/packages/RootGM/include +${SIMPATH}/transport/vgm/packages/VGM/include +${SIMPATH}/transport/vgm/packages/XmlVGM/include +) + + +FIND_PATH(GEANT4VMC_LIBRARY_DIR NAMES libgeant4vmc.so libgeant4vmc.dylib PATHS + ${SIMPATH}/transport/geant4_vmc/lib/tgt_linux + ${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxicc + ${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxx8664gcc + ${SIMPATH}/transport/geant4_vmc/lib + NO_DEFAULT_PATH +) + +# check for existence of header file, which is needed in CbmRunConfiguration +# The file is only present in old versions of VMC +FIND_FILE(GEANT4_MODULAR_PHYSICS_LIST TG4ModularPhysicsList.h PATHS + ${GEANT4VMC_INCLUDE_DIR} + NO_DEFAULT_PATH +) + +if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR) + if (NOT GEANT4VMC_FIND_QUIETLY) + MESSAGE(STATUS "Looking for GEANT4VMC... - found ${GEANT4VMC_LIBRARY_DIR}") + endif (NOT GEANT4VMC_FIND_QUIETLY) +else (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR) + if (GEANT4VMC_FIND_REQUIRED) + message(FATAL_ERROR "Looking for GEANT4VMC... - Not found ") + endif (GEANT4VMC_FIND_REQUIRED) +endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR) + + +MESSAGE(STATUS "Looking for VGM...") + +FIND_PATH(VGM_LIBRARY_DIR NAMES libBaseVGM.so libBaseVGM.dylib PATHS + ${SIMPATH}/transport/vgm/lib/Linux-g++ + ${SIMPATH}/transport/vgm.2.08.04/lib/Linux-g++ + ${SIMPATH}/transport/vgm/lib/Linux-icc + ${SIMPATH}/transport/vgm/lib + NO_DEFAULT_PATH +) + +if (VGM_LIBRARY_DIR) + if (NOT GEANT4VMC_FIND_QUIETLY) + MESSAGE(STATUS "Looking for VGM... - found ${VGM_LIBRARY_DIR}") + endif (NOT GEANT4VMC_FIND_QUIETLY) +else (VGM_LIBRARY_DIR) + if (GEANT4VMC_FIND_REQUIRED) + message(FATAL_ERROR "Looking for VGM... - Not found ") + endif (GEANT4VMC_FIND_REQUIRED) +endif (VGM_LIBRARY_DIR) + + +if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR) + set(GEANT4VMC_FOUND TRUE) +endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR) + +if (GEANT4VMC_FOUND) + SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4VMC_LIBRARY_DIR} + ${VGM_LIBRARY_DIR}) +endif (GEANT4VMC_FOUND) + diff --git a/CMake/FindROOT.cmake b/CMake/FindROOT.cmake new file mode 100644 index 0000000..55942d0 --- /dev/null +++ b/CMake/FindROOT.cmake @@ -0,0 +1,280 @@ +# - Find ROOT instalation +# This module tries to find the ROOT installation on your system. +# It tries to find the root-config script which gives you all the needed information. +# If the system variable ROOTSYS is set this is straight forward. +# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH. +# If you need an other path you should add this path to this varaible. +# The root-config script is then used to detect basically everything else. +# This module defines a number of key variables and macros. + +# F.Uhlig@gsi.de (fairroot.gsi.de) + + +MESSAGE(STATUS "Looking for Root...") + +SET(ROOT_CONFIG_SEARCHPATH + /usr/bin + /usr/local/bin + ${SIMPATH}/tools/root/bin + $ENV{ROOTSYS}/bin +) + +SET(ROOT_DEFINITIONS "") + +SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE) + +SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND) + +FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS + ${ROOT_CONFIG_SEARCHPATH} + NO_DEFAULT_PATH) + +IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") + MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please + set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the + subdirectory cmake/modules.") +ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") + STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE}) + SET( ENV{ROOTSYS} ${test}) + set( ROOTSYS ${test}) +ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") + + +IF (ROOT_CONFIG_EXECUTABLE) + + SET(ROOT_FOUND FALSE) + + EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION) + + MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root") + MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ") + + # we need at least version 5.00/00 + IF (NOT ROOT_MIN_VERSION) + SET(ROOT_MIN_VERSION "5.00/00") + ENDIF (NOT ROOT_MIN_VERSION) + + # now parse the parts of the user given version string into variables + STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}") + STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}") + STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}") + + # and now the version string given by qmake + STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}") + STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}") + STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}") + + IF (found_root_major_vers LESS 5) + MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"") + ENDIF (found_root_major_vers LESS 5) + + # compute an overall version number which can be compared at once + MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}") + MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}") + + IF (found_vers LESS req_vers) + SET(ROOT_FOUND FALSE) + SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE) + ELSE (found_vers LESS req_vers) + SET(ROOT_FOUND TRUE) + ENDIF (found_vers LESS req_vers) + +ENDIF (ROOT_CONFIG_EXECUTABLE) + + +IF (ROOT_FOUND) + + # ask root-config for the library dir + # Set ROOT_LIBRARY_DIR + + EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} + ARGS "--libdir" + OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP ) + + IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}") + SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} ) + ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}") + MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,") + MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.") + ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}") + + # ask root-config for the binary dir + EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} + ARGS "--bindir" + OUTPUT_VARIABLE root_bins ) + SET(ROOT_BINARY_DIR ${root_bins}) + + # ask root-config for the include dir + EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} + ARGS "--incdir" + OUTPUT_VARIABLE root_headers ) + SET(ROOT_INCLUDE_DIR ${root_headers}) + # CACHE INTERNAL "") + + # ask root-config for the library varaibles + EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} +# ARGS "--noldflags --noauxlibs --libs" + ARGS "--glibs" + OUTPUT_VARIABLE root_flags ) + +# STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags}) +# STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags}) +# REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}") + + SET(ROOT_LIBRARIES ${root_flags} -lGeom) + + # Make variables changeble to the advanced user + MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS) + + # Set ROOT_INCLUDES + SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR}) + + SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR}) + + ####################################### + # + # Check the executables of ROOT + # ( rootcint ) + # + ####################################### + + FIND_PROGRAM(ROOT_CINT_EXECUTABLE + NAMES rootcint + PATHS ${ROOT_BINARY_DIR} + NO_DEFAULT_PATH + ) + +ENDIF (ROOT_FOUND) + + + + ########################################### + # + # Macros for building ROOT dictionary + # + ########################################### + +MACRO (ROOT_GENERATE_DICTIONARY_OLD ) + + set(INFILES "") + + foreach (_current_FILE ${ARGN}) + + IF (${_current_FILE} MATCHES "^.*\\.h$") + IF (${_current_FILE} MATCHES "^.*Link.*$") + set(LINKDEF_FILE ${_current_FILE}) + ELSE (${_current_FILE} MATCHES "^.*Link.*$") + set(INFILES ${INFILES} ${_current_FILE}) + ENDIF (${_current_FILE} MATCHES "^.*Link.*$") + ELSE (${_current_FILE} MATCHES "^.*\\.h$") + IF (${_current_FILE} MATCHES "^.*\\.cxx$") + set(OUTFILE ${_current_FILE}) + ELSE (${_current_FILE} MATCHES "^.*\\.cxx$") + set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE}) + ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$") + ENDIF (${_current_FILE} MATCHES "^.*\\.h$") + + endforeach (_current_FILE ${ARGN}) + +# MESSAGE("INFILES: ${INFILES}") +# MESSAGE("OutFILE: ${OUTFILE}") +# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}") +# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}") + + STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}") +# MESSAGE("BLA: ${bla}") + SET (OUTFILES ${OUTFILE} ${bla}) + + ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES} + COMMAND ${ROOT_CINT_EXECUTABLE} + ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES}) + +# MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}") + +ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD) + + ########################################### + # + # Macros for building ROOT dictionary + # + ########################################### + +MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN) + + set(INCLUDE_DIRS) + + foreach (_current_FILE ${INCLUDE_DIRS_IN}) + set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE}) + endforeach (_current_FILE ${INCLUDE_DIRS_IN}) + + +# MESSAGE("INFILES: ${INFILES}") +# MESSAGE("OutFILE: ${OUTFILE}") +# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}") +# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}") + + STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}") +# MESSAGE("BLA: ${bla}") + SET (OUTFILES ${OUTFILE} ${bla}) + + + if (CMAKE_SYSTEM_NAME MATCHES Linux) + ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES} + COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE} + ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE}) + else (CMAKE_SYSTEM_NAME MATCHES Linux) + if (CMAKE_SYSTEM_NAME MATCHES Darwin) + ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES} + COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE} + ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE}) + endif (CMAKE_SYSTEM_NAME MATCHES Darwin) + endif (CMAKE_SYSTEM_NAME MATCHES Linux) + +ENDMACRO (ROOT_GENERATE_DICTIONARY) + + + + + + + + + + +MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME) + + get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH) + get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT) + get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE) + set(shell_script_name "${file_name}.sh") + + #MESSAGE("PATH: ${path_name}") + #MESSAGE("Ext: ${file_extension}") + #MESSAGE("Name: ${file_name}") + #MESSAGE("Shell Name: ${shell_script_name}") + + string(REPLACE ${PROJECT_SOURCE_DIR} + ${PROJECT_BINARY_DIR} new_path ${path_name} + ) + + #MESSAGE("New PATH: ${new_path}") + + file(MAKE_DIRECTORY ${new_path}/data) + + CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH}) + set(MY_LD_LIBRARY_PATH ${output}) + set(my_script_name ${SCRIPT_FULL_NAME}) + + if(CMAKE_SYSTEM MATCHES Darwin) + configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in + ${new_path}/${shell_script_name} + ) + else(CMAKE_SYSTEM MATCHES Darwin) + configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in + ${new_path}/${shell_script_name} + ) + endif(CMAKE_SYSTEM MATCHES Darwin) + + EXEC_PROGRAM(/bin/chmod ARGS "u+x ${new_path}/${shell_script_name}") + +ENDMACRO (GENERATE_ROOT_TEST_SCRIPT) diff --git a/CMake/FindROOTv6.cmake b/CMake/FindROOTv6.cmake new file mode 100644 index 0000000..f62c6a1 --- /dev/null +++ b/CMake/FindROOTv6.cmake @@ -0,0 +1,164 @@ +# - Finds ROOT instalation +# This module sets up ROOT information +# It defines: +# ROOT_FOUND If the ROOT is found +# ROOT_INCLUDE_DIR PATH to the include directory +# ROOT_LIBRARIES Most common libraries +# ROOT_LIBRARY_DIR PATH to the library directory +# +# Updated by K. Smith (ksmith37@nd.edu) to properly handle +# dependncies in ROOT_GENERATE_DICTIONARY + +set(ROOT_ROOTSYS $ENV{ROOTSYS} CACHE PATH "path of root installation") + + +unset(ROOT_CONFIG_EXECUTABLE CACHE) +find_program(ROOT_CONFIG_EXECUTABLE root-config + PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH) + +if(NOT ROOT_CONFIG_EXECUTABLE) + set(ROOT_FOUND FALSE) +else() + set(ROOT_FOUND TRUE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix + OUTPUT_VARIABLE ROOTSYS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --version + OUTPUT_VARIABLE ROOT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir + OUTPUT_VARIABLE ROOT_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs --evelibs + OUTPUT_VARIABLE ROOT_LIBRARIES + OUTPUT_STRIP_TRAILING_WHITESPACE) + + #set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lThread -lMinuit -lHtml -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lProof) + #set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lProofPlayer -lMLP -lSpectrum -lEve -lRGL -lGed -lXMLParser -lPhysics) + set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE + ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR) + +mark_as_advanced(ROOT_CONFIG_EXECUTABLE) + +include(CMakeParseArguments) +unset(ROOT_CINT_EXECUTABLE CACHE) +find_program(ROOT_CINT_EXECUTABLE rootcint PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH ) +mark_as_advanced(ROOT_CINT_EXECUTABLE) + + +unset(ROOT_GENREFLEX_EXECUTABLE CACHE) +find_program(ROOT_GENREFLEX_EXECUTABLE genreflex PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH) +mark_as_advanced(ROOT_GENREFLEX_EXECUTABLE) + +find_package(GCCXML) + +include(uLibDebugMacro) +#---------------------------------------------------------------------------- +# function ROOT_GENERATE_DICTIONARY( dictionary +# header1 header2 ... +# LINKDEF linkdef1 ... +# OPTIONS opt1...) +function(ROOT_GENERATE_DICTIONARY dictionary) + CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN}) + message(" -- generating rootcint dictionary --------------------------------------- ") + #---Get the list of include directories------------------ + get_directory_property(incdirs INCLUDE_DIRECTORIES) + set(includedirs) + foreach( d ${incdirs}) + set(includedirs ${includedirs} -I${d}) + endforeach() + #---Get the list of header files------------------------- + set(headerfiles) + foreach(fp ${ARG_UNPARSED_ARGUMENTS}) + find_file(headerFile ${fp} PATHS ${incdirs}) + set(headerfiles ${headerfiles} ${headerFile}) + debug(headerFile) + unset(headerFile CACHE) + endforeach() + #---Get LinkDef.h file------------------------------------ + set(linkdefs) + foreach( f ${ARG_LINKDEF}) + find_file(linkFile ${f} PATHS ${incdirs}) + set(linkdefs ${linkdefs} ${linkFile}) + debug(linkdefs) + unset(linkFile CACHE) + endforeach() + #---call rootcint------------------------------------------ + add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h + COMMAND ${ROOT_CINT_EXECUTABLE} -cint -f ${dictionary}.cxx + -c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} + DEPENDS ${headerfiles} ${linkdefs} VERBATIM) + message(" -- ---------------------------------------------------------------------- ") +endfunction() + +#---------------------------------------------------------------------------- +# function REFLEX_GENERATE_DICTIONARY(dictionary +# header1 header2 ... +# SELECTION selectionfile ... +# OPTIONS opt1...) +function(REFLEX_GENERATE_DICTIONARY dictionary) + CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN}) + #---Get the list of header files------------------------- + set(headerfiles) + foreach(fp ${ARG_UNPARSED_ARGUMENTS}) + file(GLOB files ${fp}) + if(files) + foreach(f ${files}) + set(headerfiles ${headerfiles} ${f}) + endforeach() + else() + set(headerfiles ${headerfiles} ${fp}) + endif() + endforeach() + #---Get Selection file------------------------------------ + if(IS_ABSOLUTE ${ARG_SELECTION}) + set(selectionfile ${ARG_SELECTION}) + else() + set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION}) + endif() + #---Get the list of include directories------------------ + get_directory_property(incdirs INCLUDE_DIRECTORIES) + set(includedirs) + foreach( d ${incdirs}) + set(includedirs ${includedirs} -I${d}) + endforeach() + #---Get preprocessor definitions-------------------------- + get_directory_property(defs COMPILE_DEFINITIONS) + foreach( d ${defs}) + set(definitions ${definitions} -D${d}) + endforeach() + #---Nanes and others--------------------------------------- + set(gensrcdict ${dictionary}.cpp) + if(MSVC) + set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"") + else() + #set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'") + set(gccxmlopts) + endif() + #set(rootmapname ${dictionary}Dict.rootmap) + #set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict) + #---Check GCCXML and get path----------------------------- + if(GCCXML) + get_filename_component(gccxmlpath ${GCCXML} PATH) + else() + message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable") + endif() + #---Actual command---------------------------------------- + add_custom_command(OUTPUT ${gensrcdict} ${rootmapname} + COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile} + --gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions} + DEPENDS ${headerfiles} ${selectionfile}) +endfunction() + diff --git a/CMake/FindReadLine.cmake b/CMake/FindReadLine.cmake new file mode 100644 index 0000000..70ec5b8 --- /dev/null +++ b/CMake/FindReadLine.cmake @@ -0,0 +1,23 @@ +# Base Io build system +# Written by Jeremy Tregunna +# +# Find libreadline. + +FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h readline/history.h) + +SET(READLINE_NAMES ${READLINE_NAMES} readline libreadline history libhistory) +FIND_LIBRARY(READLINE_LIBRARY NAMES ${READLINE_NAMES} PATH) + +IF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY) + SET(READLINE_FOUND TRUE) +ENDIF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY) + +IF(READLINE_FOUND) + IF(NOT Readline_FIND_QUIETLY) + MESSAGE(STATUS "Found Readline: ${READLINE_LIBRARY}") + ENDIF (NOT Readline_FIND_QUIETLY) +ELSE(READLINE_FOUND) + IF(Readline_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find readline") + ENDIF(Readline_FIND_REQUIRED) +ENDIF (READLINE_FOUND) diff --git a/CMake/FindVTK.cmake b/CMake/FindVTK.cmake new file mode 100644 index 0000000..6b1772f --- /dev/null +++ b/CMake/FindVTK.cmake @@ -0,0 +1,141 @@ +# - Find a VTK installation or build tree. +# The following variables are set if VTK is found. If VTK is not +# found, VTK_FOUND is set to false. +# VTK_FOUND - Set to true when VTK is found. +# VTK_USE_FILE - CMake file to use VTK. +# VTK_MAJOR_VERSION - The VTK major version number. +# VTK_MINOR_VERSION - The VTK minor version number +# (odd non-release). +# VTK_BUILD_VERSION - The VTK patch level +# (meaningless for odd minor). +# VTK_INCLUDE_DIRS - Include directories for VTK +# VTK_LIBRARY_DIRS - Link directories for VTK libraries +# VTK_KITS - List of VTK kits, in CAPS +# (COMMON,IO,) etc. +# VTK_LANGUAGES - List of wrapped languages, in CAPS +# (TCL, PYHTON,) etc. +# The following cache entries must be set by the user to locate VTK: +# VTK_DIR - The directory containing VTKConfig.cmake. +# This is either the root of the build tree, +# or the lib/vtk directory. This is the +# only cache entry. +# The following variables are set for backward compatibility and +# should not be used in new code: +# USE_VTK_FILE - The full path to the UseVTK.cmake file. +# This is provided for backward +# compatibility. Use VTK_USE_FILE +# instead. +# + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.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 License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Assume not found. +SET(VTK_FOUND 0) + +# VTK 4.0 did not provide VTKConfig.cmake. +IF("${VTK_FIND_VERSION}" VERSION_LESS 4.1) + SET(_VTK_40_ALLOW 1) + IF(VTK_FIND_VERSION) + SET(_VTK_40_ONLY 1) + ENDIF() +ENDIF() + +# Construct consitent error messages for use below. +SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.") +IF(_VTK_40_ALLOW) + SET(VTK_DIR_DESCRIPTION "${VTK_DIR_DESCRIPTION} For VTK 4.0, this is the location of UseVTK.cmake. This is either the root of the build tree or PREFIX/include/vtk for an installation.") +ENDIF() +SET(VTK_DIR_MESSAGE "VTK not found. Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}") + +# Check whether VTK 4.0 has already been found. +IF(_VTK_40_ALLOW AND VTK_DIR) + IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake) + SET(VTK_FOUND 1) + INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings. + ENDIF() +ENDIF() + +# Use the Config mode of the find_package() command to find VTKConfig. +# If this succeeds (possibly because VTK_DIR is already set), the +# command will have already loaded VTKConfig.cmake and set VTK_FOUND. +IF(NOT _VTK_40_ONLY AND NOT VTK_FOUND) + FIND_PACKAGE(VTK QUIET NO_MODULE) +ENDIF() + +# Special search for VTK 4.0. +IF(_VTK_40_ALLOW AND NOT VTK_DIR) + # Old scripts may set these directories in the CMakeCache.txt file. + # They can tell us where to find VTKConfig.cmake. + SET(VTK_DIR_SEARCH_LEGACY "") + IF(VTK_BINARY_PATH AND USE_BUILT_VTK) + SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH}) + ENDIF(VTK_BINARY_PATH AND USE_BUILT_VTK) + IF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK) + SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} + ${VTK_INSTALL_PATH}/lib/vtk) + ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK) + + # Look for UseVTK.cmake in build trees or under /include/vtk. + FIND_PATH(VTK_DIR + NAMES UseVTK.cmake + PATH_SUFFIXES vtk-4.0 vtk + HINTS $ENV{VTK_DIR} + + PATHS + + # Support legacy cache files. + ${VTK_DIR_SEARCH_LEGACY} + + # Read from the CMakeSetup registry entries. It is likely that + # VTK will have been recently built. + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9] + [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10] + + # Help the user find it if we cannot. + DOC "The ${VTK_DIR_DESCRIPTION}" + ) + + IF(VTK_DIR) + IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake) + SET(VTK_FOUND 1) + INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings. + ELSE() + # We found the wrong version. Pretend we did not find it. + SET(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE) + ENDIF() + ENDIF() +ENDIF() + +#----------------------------------------------------------------------------- +IF(VTK_FOUND) + # Set USE_VTK_FILE for backward-compatability. + SET(USE_VTK_FILE ${VTK_USE_FILE}) +ELSE(VTK_FOUND) + # VTK not found, explain to the user how to specify its location. + IF(VTK_FIND_REQUIRED) + MESSAGE(FATAL_ERROR ${VTK_DIR_MESSAGE}) + ELSE(VTK_FIND_REQUIRED) + IF(NOT VTK_FIND_QUIETLY) + MESSAGE(STATUS ${VTK_DIR_MESSAGE}) + ENDIF(NOT VTK_FIND_QUIETLY) + ENDIF(VTK_FIND_REQUIRED) +ENDIF(VTK_FOUND) diff --git a/CMake/FinduLib.cmake b/CMake/FinduLib.cmake new file mode 100644 index 0000000..63470df --- /dev/null +++ b/CMake/FinduLib.cmake @@ -0,0 +1,62 @@ +# - Finds ROOT instalation +# This module sets up ROOT information +# It defines: +# ULIB_FOUND If the uLib is found +# ULIB_INCLUDE_DIRS PATH to the include directory +# ULIB_LIBRARIES Most common libraries +# ULIB_LIBRARY_DIRS PATH to the library directory +# + +include(uLibFindDependencies) +include(uLibDebugMacro) + +## CONFIG FIND -------------------------------------------------------------- ## + +set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake") +unset(ULIB_CONFIG) +find_package(ULIB ${ULIB_PACKAGE_VERSION} CONFIG + NAMES uLib + PATH_SUFFIXES ${ULIB_PACKAGE_NAME} +) + +debug(ULIB_CONFIG) +debug(ULIB_CONSIDERED_CONFIGS) +debug(ULIB_CONSIDERED_VERSIONS) +debug(ULIB_INCLUDE_DIRS) +debug(ULIB_LIBRARIES) + +if(ULIB_CONFIG) + set(ULIB_FOUND true) +endif() + +## MODULE FIND -------------------------------------------------------------- ## + +#find_path(uLib_INCLUDE_DIR +# NAMES ulib.h +# PATH_SUFFIXES mutom-0.2 +#) +#debug(uLib_INCLUDE_DIR) + +#find_file(uLib_USE_FILE +# NAMES uLib_exported_targets.cmake +# PATHS lib lib64 +# PATH_SUFFIXES mutom-0.2 +#) +#debug(uLib_USE_FILE) + +#find_library(uLib_LIBRARY +# NAMES libmutomCore.so +# PATH_SUFFIXES mutom-0.2 +# ) +#debug(uLib_LIBRARY) + +##set( uLib_PROCESS_INCLUDES uLib_INCLUDE_DIR ULIB_INCLUDE_DIRS ) +##set( uLib_PROCESS_LIBS uLib_LIBRARY ULIB_LIBRARIES ) +##libfind_process(uLib) + +#set( ULIB_INCLUDE_DIRS ${uLib_INCLUDE_DIR} ) +#set( ULIB_LIBRARIES ${uLib_LIBRARY} ) +#include(FindPackageHandleStandardArgs) +#find_package_handle_standard_args(uLib DEFAULT_MSG +# uLib_LIBRARY uLib_INCLUDE_DIR) +#mark_as_advanced(uLib_INCLUDE_DIR uLib_LIBRARY) diff --git a/CMake/clean-all.cmake b/CMake/clean-all.cmake new file mode 100644 index 0000000..dc152af --- /dev/null +++ b/CMake/clean-all.cmake @@ -0,0 +1,11 @@ +set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt + ${CMAKE_BINARY_DIR}/cmake_install.cmake + ${CMAKE_BINARY_DIR}/Makefile + ${CMAKE_BINARY_DIR}/CMakeFiles +) + +foreach(file ${cmake_generated}) + if (EXISTS ${file}) + file(REMOVE_RECURSE ${file}) + endif() +endforeach(file) diff --git a/CMake/rmake.in b/CMake/rmake.in new file mode 100644 index 0000000..0d16648 --- /dev/null +++ b/CMake/rmake.in @@ -0,0 +1,47 @@ +#!/bin/bash + +# CONNECTION ---------------------------------------------------------------- ## +USER=@REMOTE_BUILD_USER@ +MACHINES="@REMOTE_BUILD_MACHINES@" +SSH=@REMOTE_BUILD_SSHBIN@ +PORT=@REMOTE_BUILD_SSHPORT@ + +# BUILD --------------------------------------------------------------------- ## + +MAKE=@REMOTE_BUILD_MAKEBIN@ +BUILD_DIR=@REMOTE_BUILD_BULIDIR@ +SOURCE_DIR=@REMOTE_BUILD_SRCDIR@ +CURRENT_DIR=`pwd` +ARGS=$@ + + +# FIND RELATIVE PATH -------------------------------------------------------- ## + +function relpath { +# both $1 and $2 are absolute paths +# returns $2 relative to $1 +source=$1 +target=$2 +common_part=$source +back= +while [ "${target#$common_part}" = "${target}" ]; do + common_part=$(dirname $common_part) + back="../${back}" +done +echo ${back}${target#$common_part/} +} + +CURRENT_SRCDIR=$(cd -- ${CURRENT_DIR}/$(relpath $BUILD_DIR/ $SOURCE_DIR/)/ && pwd) + + + +for m in ${MACHINES}; do + echo "building into machine: ${m}" + echo "remote commands: --------------------------------------------------------------------------------------------------------------" + echo "source dir = ${SOURCE_DIR}" + echo "build dir = ${BUILD_DIR}" + echo "repath to LOCAL MACHINE source dir = ${CURRENT_SRCDIR}" + echo "${SSH} -p ${PORT} ${USER}@${m} ${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g' 3>&1 1>&2 2>&3" + echo " ------------------------------------------------------------------------------------------------------------------------------" + ${SSH} -p ${PORT} ${USER}@${m} "${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g'" 3>&1 1>&2 2>&3 +done diff --git a/CMake/uLibCommon.cmake b/CMake/uLibCommon.cmake new file mode 100644 index 0000000..55a4950 --- /dev/null +++ b/CMake/uLibCommon.cmake @@ -0,0 +1,65 @@ +include(uLibMacros) +include_guard(ULIB_COMMON_CMAKE) + +include(uLibDebugMacro) + +## DIRECTORIES -------------------------------------------------------------- ## + +set(ULIB_PARENT_PATH "${PROJECT_SOURCE_DIR}") +message(STATUS "Setting uLib parent path to: ${ULIB_PARENT_PATH}") + +## Build directories ## +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "build path for lib") +mark_as_advanced(LIBRARY_OUTPUT_PATH) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "build path for binaries") +mark_as_advanced(EXECUTABLE_OUTPUT_PATH) + +## Install directories ## +set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") +set(PACKAGE_INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries") +set(PACKAGE_INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers") +set(PACKAGE_INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files") +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR CMake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME}) +endif() +set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") + +# Make relative paths absolute (needed later on) +foreach(p LIB BIN INC DATA CMAKE) + set(var PACKAGE_INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() + mark_as_advanced(PACKAGE_INSTALL_${p}_DIR) + debug(PACKAGE_INSTALL_${p}_DIR) +endforeach() + +# add the binary tree to the search path for include files +# so that we will find config.h +set(SRC_DIR ${PROJECT_SOURCE_DIR}/src) +include_directories(${PROJECT_BINARY_DIR}) +include_directories(${SRC_DIR}) + + +## GLOBAL OPTIONS ----------------------------------------------------------- ## + +# Set a default build type to RELEASE WITH DEBUG INFO if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed") + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +set(CMAKE_CXX_WARNING_OPTION "" CACHE STRING "Warning level -WAll to verbose all warnings") +set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE STRING "Verbose compile output switch") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}") + + + + diff --git a/CMake/uLibConfigHeader.cmake b/CMake/uLibConfigHeader.cmake new file mode 100644 index 0000000..363bbe3 --- /dev/null +++ b/CMake/uLibConfigHeader.cmake @@ -0,0 +1,57 @@ +include(uLibMacros) +include_guard(ULIB_CONFIG_HEADER_CMAKE) + + +## CONFIG ------------------------------------------------------------------- ## + +message("/////////// CONFIG HEADER //////////////") + +include(CheckIncludeFiles) +include(CheckFunctionExists) +include(CheckSymbolExists) + +## force to use PP variadics (FIX) ## +set(BOOST_PP_VARIADICS ON) + +message(STATUS "PROJECT NAME = ${PROJECT_NAME}") +message(STATUS "PACKAGE VERSION = ${PACKAGE_VERSION}") +message(STATUS "PACKAGE NAME = ${PACKAGE_NAME}") +execute_process(COMMAND "svnversion" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE SVN_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE ) + +message(STATUS "SVN REVISION = ${SVN_REVISION}") + +CHECK_INCLUDE_FILES(inittypes.h HAVE_INITTYPES_H) +CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H) +CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H) +CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H) + +CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H) +CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H) +CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC) +CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H) + +CHECK_INCLUDE_FILES(math.h HAVE_MATH_H) +CHECK_FUNCTION_EXISTS(fsetround HAVE_FSETROUND) +CHECK_FUNCTION_EXISTS(floor HAVE_FLOOR) +CHECK_FUNCTION_EXISTS(pow HAVE_POW) +CHECK_FUNCTION_EXISTS(sqrt HAVE_SQRT) + +CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP) +CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR) +CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H) +CHECK_INCLUDE_FILES(string.h HAVE_STRING_H) + +CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H) +CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) + +CHECK_INCLUDE_FILES(assert.h HAVE_ASSERT_H) + + +configure_file( + "${PROJECT_SOURCE_DIR}/CMakeConfig.in.h" + "${PROJECT_BINARY_DIR}/config.h" + ) diff --git a/CMake/uLibDebugMacro.cmake b/CMake/uLibDebugMacro.cmake new file mode 100644 index 0000000..1529ae3 --- /dev/null +++ b/CMake/uLibDebugMacro.cmake @@ -0,0 +1,54 @@ +include(uLibMacros) +include_guard(ULIB_DEBUG_MACRO_CMAKE) + + +set(CMAKE_CONFIGURE_DEBUG_ENABLE ON CACHE BOOL "cmake configure debugger") +set(CMAKE_CONFIGURE_DEBUG_LIST OFF CACHE BOOL "cmake debugger show list enable") +mark_as_advanced( + CMAKE_CONFIGURE_DEBUG_ENABLE + CMAKE_CONFIGURE_DEBUG_LIST +) + +macro(debug str) + if(CMAKE_CONFIGURE_DEBUG_ENABLE) + set(var ${${str}}) + list(LENGTH var len) + if((${len} GREATER 1) AND CMAKE_CONFIGURE_DEBUG_LIST) + message(STATUS "[DEBUG] [${str}] list: ") + foreach(item ${var}) + message(STATUS " -> ${item}") + endforeach() + else() + message(STATUS "[DEBUG] [${str}] ${var}") + endif() + endif() +endmacro() + +macro(debug_list str) + if(CMAKE_CONFIGURE_DEBUG_ENABLE) + set(var ${${str}}) + list(LENGTH var len) + if((${len} GREATER 1)) + message(STATUS "[DEBUG] [${str}] list: ") + foreach(item ${var}) + message(STATUS " -> ${item}") + endforeach() + else() + message(STATUS "[DEBUG] [${str}] ${var}") + endif() + endif() +endmacro() + +macro(debug_package str) + if(CMAKE_CONFIGURE_DEBUG_ENABLE) + set(have ${str}_FOUND) + if(${have}) + debug("${str}_INCLUDE_DIRS") + debug("${str}_LIBRARIES") + debug("${str}_LIBRARY_DIRS") + debug("${str}_DEFINITIONS") + else(${have}) + message(WARNING "package ${str} not found") + endif(${have}) + endif(CMAKE_CONFIGURE_DEBUG_ENABLE) +endmacro() diff --git a/CMake/uLibFindDependencies.cmake b/CMake/uLibFindDependencies.cmake new file mode 100644 index 0000000..6c6bb92 --- /dev/null +++ b/CMake/uLibFindDependencies.cmake @@ -0,0 +1,122 @@ +include(uLibMacros) +include_guard(ULIB_FIND_DEPENDENCIES_CMAKE) + +include(uLibDebugMacro) + +################################################################################ +## PKG FIND ## +message("/////////// LOOKING FOR EXTERNAL PACKAGES //////////////") + +## BOOST ## +message(STATUS "## BOOST ##") +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +find_package(Boost 1.45.0 COMPONENTS serialization signals program_options REQUIRED) +if(Boost_FOUND) + set(HAVE_BOOST true) +endif(Boost_FOUND) +include_directories(${Boost_INCLUDE_DIRS}) + +## OPEN MP ## +message(STATUS "## OPEN MP ##") +find_package(OpenMP) +option(OpenMP_ACTIVE "Activate OpenMP parallel compilation" ON) +if(OPENMP_FOUND AND OpenMP_ACTIVE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" ) +endif(OPENMP_FOUND AND OpenMP_ACTIVE) + +## EIGEN ## +message(STATUS "## EIGEN ##") +# option(USE_EIGEN ON) ## REQUIRED +find_package(Eigen3 REQUIRED) +debug(EIGEN3_INCLUDE_DIR) +include_directories(${EIGEN3_INCLUDE_DIR}) + +## ROOT ## +message(STATUS "## ROOT ##") +option(ULIB_USE_ROOT "Activate use of Root integration" ON) +### <<<--- ROOT IS REQUIRED FOR THE MOMENT ### +#if(ULIB_USE_ROOT) +#include(/etc/root/cmake/FindROOT.cmake) +find_package(ROOT REQUIRED) +if(ROOT_FOUND) + set(HAVE_ROOT true) + include_directories(${ROOT_INCLUDE_DIR}) + link_directories(${ROOT_LIBRARY_DIR}) + debug(ROOT_INCLUDE_DIR) + debug(ROOT_LIBRARY_DIR) + debug(ROOT_LIBRARIES) +else() + message(WARNING "Root not found") +endif(ROOT_FOUND) +#endif(ULIB_USE_ROOT) + + +## VTK ## +option(ULIB_USE_VTK "Activate use of Vtk Visual Pipelines" ON) +if(ULIB_USE_VTK) + message(STATUS "## VTK ##") + message(STATUS "Looking for VTK...") + set(VTK_DIR "PATH/TO/VTK/BUILD/DIRECTORY") + mark_as_advanced(VTK_DIR) + find_package(VTK REQUIRED) + include(${VTK_USE_FILE}) + #message(STATUS "VTK included libraries: ${VTK_LIBRARIES}") + debug(VTK_USE_FILE) + debug(VTK_INCLUDE_DIRS) + debug(VTK_LIBRARY_DIRS) + debug(VTK_LIBRARIES) +# get_directory_property(compile_def COMPILE_DEFINITIONS) +# debug(compile_def) +endif(ULIB_USE_VTK) + + +## GEANT ## +option(ULIB_USE_GEANT4 "Activate use of GEANT Integration" ON) +message(STATUS "## GEANT 4 ##") +#include(FindGEANT4) # disabled using system finder +find_package(Geant4) +set(GEANT4_FOUND Geant4_DIR) +if(GEANT4_FOUND AND ULIB_USE_GEANT4) + message(STATUS "Looking for Geant4... - Geant4 found in ${Geant4_DIR}") + set(HAVE_GEANT4 true) + include_directories(${Geant4_INCLUDE_DIRS}) # Add -I type paths + add_definitions(${Geant4_DEFINITIONS}) # Add -D type defs + debug_package(Geant4) +endif(GEANT4_FOUND AND ULIB_USE_GEANT4) + +## QT4 ## +option(ULIB_USE_QT4 "Activate use of Qt Framework" ON) +if(ULIB_USE_QT4) + message(STATUS "## QT4 ##") + find_package(Qt4) +# include_directories(${Qt4_INCLUDE_DIRS}) +# debug(Qt4_INCLUDE_DIRS) +endif(ULIB_USE_QT4) + +## QT5 ## +option(ULIB_USE_QT5 "Activate use of Qt Framework" ON) +if(ULIB_USE_QT5) + message(STATUS "## QT5 ##") + find_package(Qt5Widgets) +# include_directories(${Qt5_INCLUDE_DIRS}) +# debug(Qt5_INCLUDE_DIRS) +endif(ULIB_USE_QT5) + +## READLINE ## +message(STATUS "## READLINE ##") +find_package(ReadLine) +include_directories(${READLINE_INCLUDE_DIR}) +debug(READLINE_INCLUDE_DIR) + +## STD MATH REQUIRED ## +#message(STATUS "## STD MATH ##") +set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h) +set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m) + + + +################################################################################ diff --git a/CMake/uLibGenerateRMake.cmake b/CMake/uLibGenerateRMake.cmake new file mode 100644 index 0000000..962ce0b --- /dev/null +++ b/CMake/uLibGenerateRMake.cmake @@ -0,0 +1,47 @@ + + +include(uLibMacros) +include(uLibDebugMacro) + +## MAKE REMOTE -------------------------------------------------------------- ## + +#set(BUILD_REMOTE_MACHINES "10.62.19.4" CACHE STRING "remote build in cloud machine") +#set(BUILD_REMOTE_USER "rigoni" CACHE STRING "remote build user") +#set(BUILD_REMOTE_CMD "${SSH_COMMAND} ${BUILD_REMOTE_USER}@${BUILD_REMOTE_MACHINES} \"make -C \"") +#add_custom_target(cloud COMMAND ${SSH_COMMAND}) + + + +set(REMOTE_BUILD_USER "$ENV{USER}" CACHE STRING "ssh remote build user name") + +execute_process(COMMAND hostname -I OUTPUT_VARIABLE HOSTNAME_IP) +set(REMOTE_BUILD_MACHINES ${HOSTNAME_IP} CACHE STRING "ssh remote build machines") + +find_file(SSH_EXECUTABLE ssh PATHS /bin/local/bin /usr/bin /bin) +set(REMOTE_BUILD_SSHBIN ${SSH_EXECUTABLE} CACHE FILEPATH "ssh remote build command path") +set(REMOTE_BUILD_SSHPORT 22 CACHE STRING "ssh remote build port") + +find_file(MAKE_EXECUTABLE make PATHS /usr/local/bin /usr/bin /bin) +set(REMOTE_BUILD_MAKEBIN ${MAKE_EXECUTABLE} CACHE FILEPATH "ssh remote build make path") +set(REMOTE_BUILD_BULIDIR ${PROJECT_BINARY_DIR} CACHE PATH "ssh remote build build path") +set(REMOTE_BUILD_SRCDIR ${PROJECT_SOURCE_DIR} CACHE PATH "ssh remote build source path") + +message("remote build ----------------------------------------------------------") +debug(REMOTE_BUILD_USER) +debug(REMOTE_BUILD_MACHINES) +debug(REMOTE_BUILD_SSHBIN) +debug(REMOTE_BUILD_SSHPORT) +debug(REMOTE_BUILD_MAKEBIN) +message("-----------------------------------------------------------------------") + + +find_file(RMAKE_IN_FILE rmake.in PATHS ${CMAKE_MODULE_PATH}) +configure_file( + "${RMAKE_IN_FILE}" + "${PROJECT_BINARY_DIR}/CMake/rmake" @ONLY +) + +file(COPY "${PROJECT_BINARY_DIR}/CMake/rmake" + DESTINATION "${PROJECT_BINARY_DIR}" + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/CMake/uLibMacros.cmake b/CMake/uLibMacros.cmake new file mode 100644 index 0000000..608dd7c --- /dev/null +++ b/CMake/uLibMacros.cmake @@ -0,0 +1,12 @@ +#if(ULIB_MACROS_CMAKE) +# return() +#endif() +#set(ULIB_MACROS_CMAKE 1) + + +function(include_guard var) + if(${var}) + return() + endif() + set(${var} 1) +endfunction() diff --git a/CMake/uLibTargetMacros.cmake b/CMake/uLibTargetMacros.cmake new file mode 100644 index 0000000..6dca895 --- /dev/null +++ b/CMake/uLibTargetMacros.cmake @@ -0,0 +1,186 @@ + +include(uLibMacros) +include_guard(ULIB_TARGET_MACRO_CMAKE) + +## adds library target +macro(uLib_add_library name) + add_library(${name} ${ARGN}) + if(NOT ULIB_INSTALL_NO_LIBRARIES) + set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name}) + endif(NOT ULIB_INSTALL_NO_LIBRARIES) +endmacro(uLib_add_library) + +################################################################################ +## Add SHARED library target ## + +# HEADERS and SOURCES must be defined as list of library headers and sources +macro(uLib_add_shared_library name) + if(COMMAND cmake_policy) + # cmake_policy( SET CMP0022 NEW ) + endif(COMMAND cmake_policy) + + set(mname ${PACKAGE_LIBPREFIX}${name}) + + if(SOURCES) + uLib_add_library(${mname} SHARED ${SOURCES}) + set(shared ${ULIB_SHARED_LIBRARIES}) + list(APPEND shared ${mname}) + set(ULIB_SHARED_LIBRARIES ${shared} PARENT_SCOPE) + source_group("${project_name}\\${name}" FILES ${SOURCES}) + set_target_properties(${mname} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_SOVERSION} + INTERFACE_LINK_LIBRARIES "${LIBRARIES}" + LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- ok for cmake from 2.12 ? + IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- breaks cmake after 2.11 ? +# PUBLIC_HEADER "" + ) + debug(LIBRARIES) + + install(TARGETS ${mname} + EXPORT "${PROJECT_NAME}Targets" + RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin + LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib + # PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev + ) + endif(SOURCES) + + if(HEADERS) + foreach(header ${HEADERS}) + install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name}) + endforeach(header) + endif(HEADERS) + +endmacro(uLib_add_shared_library) + + +################################################################################ +## Add Target ## + +macro(uLib_add_target name) + debug(${name}) + add_executable(${name} ${ARGN}) + set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name}) + + set(exported ${ULIB_EXPORTED_TARGETS}) + list(APPEND exported ${name}) + set(ULIB_EXPORTED_TARGETS ${exported} PARENT_SCOPE) + + install(TARGETS ${name} + EXPORT "${PROJECT_NAME}Targets" + RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin + ) +ENDMACRO(uLib_add_target) + + + +################################################################################ +## TESTS ## + +# TESTS and LIBRARIES must be defined +macro(uLib_add_tests name) + foreach(tn ${TESTS}) + add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp) + add_test(${tn} ${tn}) + + # adds dependencies to all selected modules in uLib + # foreach(module ${ULIB_SELECTED_MODULES}) + # add_dependencies(${tn} ${project_name}${module}) + # endforeach(module) + + # adds libraries dependencies + foreach(library ${LIBRARIES}) + target_link_libraries(${tn} ${library}) + endforeach(library) + + endforeach(tn) + + # custom target to compile all tests + add_custom_target(all-${name}-tests) + add_dependencies(all-${name}-tests ${TESTS}) +endmacro(uLib_add_tests name) + + +################################################################################ +## UTILS ## + +# UTILS and LIBRARIES must be defined +macro(uLib_add_utils name) + foreach(tn ${UTILS}) + add_executable(${tn} ${tn}.cpp) + install(TARGETS ${tn} RUNTIME DESTINATION bin) + + # adds dependencies to all selected modules in uLib + # foreach(module ${ULIB_SELECTED_MODULES}) + # add_dependencies(${tn} ${project_name}${module}) + # endforeach(module) + + # adds libraries dependencies + foreach(library ${LIBRARIES}) + target_link_libraries(${tn} ${library}) + endforeach(library) + + endforeach(tn) + + # custom target to compile all tests + add_custom_target(all-${name}) + add_dependencies(all-${name} ${UTILS}) + +endmacro(uLib_add_utils name) + + + + + + +function(get_gcc_compile_flags target out_flags) + string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" name) + set(flags "${${name}} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILER_ARG1}") + get_target_property(value ${target} COMPILE_FLAGS) + if (value) + list(APPEND flags ${value}) + endif() + get_target_property(value ${target} TYPE) + get_target_property(value ${target} COMPILE_DEFINITIONS) + if (value) + foreach(item ${value}) + list(APPEND flags "-D${item}") + endforeach() + endif() + STRING(TOUPPER "COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE}" name) + get_target_property(value ${target} ${name}) + if (value) + foreach(item ${value}) + list(APPEND flags "-D${item}") + endforeach() + endif() + get_directory_property(value DEFINITIONS) + if (value) + list(APPEND flags ${value}) + endif() + get_directory_property(value INCLUDE_DIRECTORIES) + if (value) + foreach(item ${value}) + list(APPEND flags "-I${item}") + endforeach() + endif() + set(${out_flags} ${flags} PARENT_SCOPE) +endfunction() + +function(get_gcc_link_flags target out_flags) + set(flags) + get_target_property(value ${target} LINK_FLAGS_RELEASE) + if (value) + message(STATUS "-> ${flags}") + list(APPEND flags ${value}) + endif() + get_directory_property(value LINK_DIRECTORIES) + if (value) + message(STATUS "-> ${flags}") + foreach(item ${value}) + list(APPEND flags "-L${item}") + endforeach() + endif() + message(STATUS "-> ${flags}") + set(${out_flags} ${flags} PARENT_SCOPE) +endfunction() diff --git a/CMakeConfig.in.h b/CMakeConfig.in.h new file mode 100644 index 0000000..3080ed2 --- /dev/null +++ b/CMakeConfig.in.h @@ -0,0 +1,128 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +#ifndef HAVE_CONFIG_H +#define HAVE_CONFIG_H + +/* Compiler must have variadic macros */ +//#cmakedefine BOOST_PP_VARIADICS + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ASSERT_H + +/* Defined if the requested minimum BOOST version is satisfied */ +#cmakedefine HAVE_BOOST + +/* Define to 1 if you have */ +#cmakedefine HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP + +/* Define to 1 if you have */ +#cmakedefine HAVE_BOOST_ARRAY_HPP + +/* Define to 1 if you have */ +#cmakedefine HAVE_BOOST_PROGRAM_OPTIONS_HPP + +/* Define to 1 if you have */ +#cmakedefine HAVE_BOOST_SIGNAL_HPP + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H + +/* Define to 1 if you have the `fesetround' function. */ +#cmakedefine HAVE_FESETROUND + +/* Define to 1 if you have the `floor' function. */ +#cmakedefine HAVE_FLOOR + +/* Having Geant4 installed */ +#cmakedefine HAVE_GEANT4 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H + +/* Define if you have libreadline */ +#cmakedefine HAVE_LIBREADLINE + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#cmakedefine HAVE_MALLOC + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if you have the `pow' function. */ +#cmakedefine HAVE_POW + +/* Having root installed */ +#cmakedefine HAVE_ROOT + +/* Define to 1 if you have the `sqrt' function. */ +#cmakedefine HAVE_SQRT + +/* Define to 1 if stdbool.h conforms to C99. */ +#cmakedefine HAVE_STDBOOL_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have the `strdup' function. */ +#cmakedefine HAVE_STRDUP + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define to 1 if you have the `strstr' function. */ +#cmakedefine HAVE_STRSTR + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define to 1 if the system has the type `_Bool'. */ +#cmakedefine HAVE__BOOL + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#cmakedefine LT_OBJDIR + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "@PACKAGE_URL@" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS + +/* SVN revision number */ +#cmakedefine SVN_REVISION "@SVN_REVISION@" + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +#endif // HAVE_CONFIG_H diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..51b1a8b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,237 @@ + +################################################################################ +##### CMAKE LISTS ############################################################## +################################################################################ + +cmake_minimum_required (VERSION 2.6) + +execute_process(COMMAND "clear") +message("//////////////////////////////////////////////////////////////////////") +message("/////////////////// CMAKE PJOJECT CONFIGURATION //////////////////////") +message("//////////////////////////////////////////////////////////////////////") + +## -------------------------------------------------------------------------- ## + +project(uLib) + +# The version number. +set(PROJECT_VERSION_MAJOR 0) +set(PROJECT_VERSION_MINOR 2) +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") +set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") + +set(PACKAGE_VERSION ${PROJECT_VERSION}) +set(PACKAGE_NAME "mutom-${PROJECT_VERSION}" CACHE STRING "name of the package defined inside code (config.h)") +set(PACKAGE_LIBPREFIX "mutom" CACHE STRING "suffix for each library component name") +set(PACKAGE_URL "http:://mutom.pd.infn.it" CACHE STRING "url of the project") +set(PACKAGE_AUTHOR "Andrea Rigoni Garola ") + + +## MACROS ------------------------------------------------------------------- ## + +set(ULIB_CMAKE_DIR "${PROJECT_SOURCE_DIR}/CMake") +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) +message(STATUS "Module path: ${CMAKE_MODULE_PATH}") + +include(uLibMacros) +include(uLibDebugMacro) +include(uLibTargetMacros) +include(uLibGenerateRMake) + + + +## GLOBALS ------------------------------------------------------------------ ## + +include(uLibCommon) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") ## Add flags here ## + +enable_testing() + +## FIND PACKAGES ------------------------------------------------------------ ## + +include(uLibFindDependencies) + + +## CONFIG ------------------------------------------------------------------- ## + +include(uLibConfigHeader) + +## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ## + +## select modules ## +set(ULIB_SELECTED_MODULES + ltk + Core + Math + Detectors + Root +) + +## uLib_add_shared_library puts names there +set(ULIB_SHARED_LIBRARIES) + +if(ULIB_USE_VTK) + LIST(APPEND ULIB_SELECTED_MODULES Vtk) +endif(ULIB_USE_VTK) + +## this gets ulib modules into a variable ## +function(uLib_modules result) + set(out) + foreach(module ${ULIB_SELECTED_MODULES}) + list(APPEND out ${PACKAGE_LIBPREFIX}${module}) + endforeach(module) + set(${result} "${out}" PARENT_SCOPE) +endfunction() + + +## ENTERING MODULES SUBDIRECTORIES ## +message("/////////// SELECTED MODULES //////////////") +foreach(module ${ULIB_SELECTED_MODULES}) + message(STATUS "adding module: ${module}") + set( uLib-module ${module}) + include_directories(${SRC_DIR}/${module}) + add_subdirectory(${SRC_DIR}/${module}) +endforeach(module) + +## SINGLE LIBRARY LINKING ## (work in progress ... ) +option(ULIB_SINGLELIBRARY "Link everything to a single library" OFF) +if(ULIB_SINGLELIBRARY) +# set(modgrp) +# foreach(module ${ULIB_SELECTED_MODULES}) +# set(grpn srcgrp_${module}) +# list(APPEND modgrp ${grpn}) +# endforeach(module) +# add_library(${project_name} SHARED ${srcgrp_Core}) +endif(ULIB_SINGLELIBRARY) + +## UTILITIES ## +add_subdirectory("${SRC_DIR}/utils/make_recipe") + + +## PKG CONFIG compatible file ----------------------------------------------- ## + +set(PKGCONFIG_FILE_ENABLE OFF CACHE BOOL "enable pkg-config file") +if(PKGCONFIG_FILE_ENABLE) +message("/////////// PKG-CONFIG DISTILLER //////////////") +set(PKGCONFIG_FILE_DESTDIR "/lib/pkgconfig/" CACHE PATH "destination path for pkg-config file") +set(PKGCONFIG_LIBS) + +message(STATUS "[cflags] ${CMAKE_C_FLAGS}") +message(STATUS "[cxxflags] ${CMAKE_CXX_FLAGS}") + +foreach(module ${ULIB_SHARED_LIBRARIES}) +set(PKGCONFIG_LIBS "${PKGCONFIG_LIBS} ${CMAKE_LINK_LIBRARY_FLAG}${module}") +endforeach(module) +message(STATUS "[libs] ${PKGCONFIG_LIBS}") + +set(PKGCONFIG_FLAGS) +#add_custom_target(Dummy) + +# add the executable +uLib_add_target(Dummy test.cpp) +target_link_libraries(Dummy ${PACKAGE_LIBPREFIX}Core) +target_link_libraries(Dummy ${Boost_SERIALIZATION_LIBRARY}) +target_link_libraries(Dummy ${Boost_SIGNALS_LIBRARY}) +target_link_libraries(Dummy ${Boost_PROGRAM_OPTIONS_LIBRARY}) +target_link_libraries(Dummy ${Geant4_LIBRARIES}) +target_link_libraries(Dummy ${ROOT_LIBRARIES}) +target_link_libraries(Dummy ${VTK_LIBRARIES}) + +get_gcc_compile_flags(Dummy, gcc_flags_list) +foreach(item ${gcc_flags_list}) + message(STATUS "[gcc cflags] ${item}") + set(PKGCONFIG_FLAGS "${PKGCONFIG_FLAGS} ${item}") +endforeach(item) +message(STATUS "[includes] ${PKGCONFIG_FLAGS}") + +get_gcc_link_flags(Dummy, gcc_flags_list) +foreach(item ${gcc_flags_list}) + message(STATUS "[gcc libs] ${item}") +endforeach(item) + +configure_file( + "${PROJECT_SOURCE_DIR}/CMakePkgConfig.pc.in" + "${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc" + ) +INSTALL_FILES(${PKGCONFIG_FILE_DESTDIR} FILES ${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc) + +message("///////////////////////////////////////////") +endif(PKGCONFIG_FILE_ENABLE) + + + + + +## INSTALLS AND EXPORTS ----------------------------------------------------- ## + +#export(PACKAGE uLib) +export(PACKAGE ULIB) +export(TARGETS ${ULIB_SHARED_LIBRARIES} ${ULIB_EXPORTED_TARGETS} + FILE "${PROJECT_BINARY_DIR}/uLibTargets.cmake" ) +#export(TARGETS ${ULIB_EXPORTED_TARGETS} +# FILE "${PROJECT_BINARY_DIR}/uLibExeTargets.cmake" ) + + +# Create the FooBarConfig.cmake and FooBarConfigVersion files +file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}" + "${PACKAGE_INSTALL_INC_DIR}") +# ... for the build tree +set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}") +configure_file(uLibConfig.cmake.in + "${PROJECT_BINARY_DIR}/uLibConfig.cmake" @ONLY) +# ... for the install tree +set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}") +configure_file(uLibConfig.cmake.in + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake" @ONLY) +# ... for both +configure_file(uLibConfigVersion.cmake.in + "${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY) + +# Install the FooBarConfig.cmake and FooBarConfigVersion.cmake +install(FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake" + "${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" + DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev) + +# Install the export set for use with the install-tree +install(EXPORT "${PROJECT_NAME}Targets" DESTINATION + "${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev) + +install(FILES ${PROJECT_SOURCE_DIR}/ulib.h DESTINATION ${PACKAGE_INSTALL_INC_DIR}) + + + +## dummy main executable ---------------------------------------------------- ## + +message("Sara's debug....") +message(${ROOT_LIBRARIES}) + +# add the executable +add_executable(Coretest test.cpp) +target_link_libraries(Coretest ${PACKAGE_LIBPREFIX}Core) +#target_link_libraries(Coretest ${Boost_SERIALIZATION_LIBRARY}) +#target_link_libraries(Coretest ${Boost_SIGNALS_LIBRARY}) +#target_link_libraries(Coretest ${Boost_PROGRAM_OPTIONS_LIBRARY}) +#target_link_libraries(Coretest ${Geant4_LIBRARIES}) +target_link_libraries(Coretest ${ROOT_LIBRARIES}) +target_link_libraries(Coretest ${VTK_LIBRARIES}) + +#message( "---------------------------------------------------------------------" ) +#execute_process(COMMAND +# "ls" +## "cmake --find-package -DNAME=uLib -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=COMPILE" +# ) +#message( "---------------------------------------------------------------------" ) + +## -------------------------------------------------------------------------- ## + + +# TODO clean also subdirectories +add_custom_target(clean-cmake-files + COMMAND ${CMAKE_COMMAND} -P ${ULIB_CMAKE_DIR}/clean-all.cmake +) + + + + + diff --git a/CMakePkgConfig.pc.in b/CMakePkgConfig.pc.in new file mode 100644 index 0000000..408288f --- /dev/null +++ b/CMakePkgConfig.pc.in @@ -0,0 +1,13 @@ + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Mutom Library (INFN) +Description: Library for Muon Tomography experiments. +Url: @PACKAGE_URL@ +Version: @PACKAGE_VERSION@ +Requires: eigen3 +Libs: -L${libdir} @PKGCONFIG_LIBS@ +Cflags: @CMAKE_C_FLAGS@ @CMAKE_CXX_FLAGS@ @PKGCONFIG_INCLUDES@ diff --git a/src/Core/Archives.cpp b/src/Core/Archives.cpp new file mode 100644 index 0000000..017868d --- /dev/null +++ b/src/Core/Archives.cpp @@ -0,0 +1,92 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + + + +#include "Core/Archives.h" + +//#define BOOST_ARCHIVE_SOURCE +#include + +// explicitly instantiate for this type of xml stream +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include + + +namespace boost { +namespace archive { + + + +template class detail::archive_serializer_map ; +template class basic_xml_oarchive ; +template class xml_oarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_xml_iarchive ; +template class xml_iarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_text_oarchive ; +template class text_oarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_text_iarchive ; +template class text_iarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_text_oarchive ; +template class text_oarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_text_iarchive ; +template class text_iarchive_impl ; + +template class detail::archive_serializer_map ; +template class basic_xml_oarchive ; +template class xml_oarchive_impl ; + + + + +} // namespace archive +} // namespace boost diff --git a/src/Core/Archives.h b/src/Core/Archives.h new file mode 100644 index 0000000..d9f9071 --- /dev/null +++ b/src/Core/Archives.h @@ -0,0 +1,781 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_ARCHIVES_H +#define U_CORE_ARCHIVES_H + + +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include "StringReader.h" + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// FWD DECLARATIONS OF ARCHIVES // + + + + +namespace uLib { +namespace Archive { + +class xml_iarchive; +class xml_oarchive; +class text_iarchive; +class text_oarchive; +class log_archive; + + +} +} + + +namespace boost { +namespace archive { +namespace detail { +template class polymorphic_oarchive_route; +template class polymorphic_iarchive_route; +} +} +} + +namespace boost { +namespace serialization { + template struct hrp; +} +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES REGISTRATION // + + +namespace uLib { +namespace Archive { +namespace detail { +struct adl_tag {}; +} +} +} + +namespace boost { +namespace archive { +namespace detail { +// This function gets called, but its only purpose is to participate +// in overload resolution with the functions declared by +// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below. +template +void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {} +} +} +} + +// The function declaration generated by this macro never actually +// gets called, but its return type gets instantiated, and that's +// enough to cause registration of serialization functions between +// Archive and any exported Serializable type. See also: +// boost/serialization/export.hpp +# define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \ +namespace boost { namespace archive { namespace detail { \ + \ +template \ +BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \ +instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}} + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES IO INTERFACES // + + +namespace boost { +namespace archive { +namespace detail { + +/** + * Custom implementation of boost interface_iarchive to add new operators + */ +template +class uLib_interface_iarchive +{ +protected: + uLib_interface_iarchive(){}; +public: + ///////////////////////////////////////////////////////// + // archive public interface + typedef mpl::bool_ is_loading; + typedef mpl::bool_ is_saving; + + // return a pointer to the most derived class + Archive * This(){ + return static_cast(this); + } + + template + const basic_pointer_iserializer * + register_type(T * = NULL){ + const basic_pointer_iserializer & bpis = + boost::serialization::singleton< + pointer_iserializer + >::get_const_instance(); + this->This()->register_basic_serializer(bpis.get_basic_serializer()); + return & bpis; + } + template + Archive & operator>>(T & t){ + this->This()->load_override(t, 0); + return * this->This(); + } + + // the & operator + template + Archive & operator&(T & t){ + return *(this->This()) >> t; + } + + // the == operator + template + Archive & operator == (T & t) { + return this->operator &(t); + } + + // the != operator for human readable access + template + Archive & operator != (T & t) { + std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! + return * this->This(); + } +}; + + +/** + * Custom implementation of boost interface_oarchive to add new operators + */ +template +class uLib_interface_oarchive { +protected: + uLib_interface_oarchive(){}; +public: + ///////////////////////////////////////////////////////// + // archive public interface + typedef mpl::bool_ is_loading; + typedef mpl::bool_ is_saving; + + // return a pointer to the most derived class + Archive * This(){ + return static_cast(this); + } + + template + const basic_pointer_oserializer * + register_type(const T * = NULL){ + const basic_pointer_oserializer & bpos = + boost::serialization::singleton< + pointer_oserializer + >::get_const_instance(); + this->This()->register_basic_serializer(bpos.get_basic_serializer()); + return & bpos; + } + + template + Archive & operator<<(T & t){ + // to get access you must redefine save_override by typing + // "using save_override" in archive impl + this->This()->save_override(t, 0); + return * this->This(); + } + + // the & operator + template + Archive & operator&(T & t){ + #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + return * this->This() << const_cast(t); + #else + return * this->This() << t; + #endif + } + + // the == operator + template + Archive & operator == (T & t) { + return this->operator &(t); + } + + // the != operator for human readable access + template + Archive & operator != (T & t) { + std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS ! + return * this->This(); + } +}; + + + +// DECLARE INTERFACE SPECIALIZATIONS /////////////////////////////////////////// +// With this declarations all uLib archive Implementation will use their own +// extended interface // + +template <> +class interface_iarchive : public + uLib_interface_iarchive {}; + +template <> +class interface_oarchive : public + uLib_interface_oarchive {}; + +template <> +class interface_iarchive : public + uLib_interface_iarchive {}; + +template <> +class interface_oarchive : public + uLib_interface_oarchive {}; + +template <> +class interface_oarchive : public + uLib_interface_oarchive {}; + + +//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!! +//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \ +// template \ +// struct inherit_nofold : \ +// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \ +// {}; + +//// Multiple size declaration // +//BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~) + +//#undef _INERIT_NOFOLD_H +//#undef _INERIT_NOFOLD_V + + +} // detail +} // archive +} // boost + + + + + + + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES DEFINITIONS // + +namespace boost { +namespace archive { + +//template +//inline void load_const_override(Archive & ar, const char *t ){ +// typedef typename mpl::identity >::type typex; +// typex::invoke(ar, t); +//} + +//template +//inline void load(Archive & ar, T &t){ +// // if this assertion trips. It means we're trying to load a +// // const object with a compiler that doesn't have correct +// // funtion template ordering. On other compilers, this is +// // handled below. +// // detail::check_const_loading< T >(); +// typedef +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// mpl::identity > +// > +// > +// >::type typex; +// typex::invoke(ar, t); +//} + + + +} +} + + + + +namespace uLib { + +namespace Archive { + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// POLYMORPHIC // + + +//class polymorphic_iarchive : +// public boost::archive::polymorphic_iarchive { + +//public: +// void load_override(const char *t, BOOST_PFTO int) +// { +// boost::archive::load_const_override(* this->This(), const_cast(t)); +// } + +//}; + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// XML // + +class xml_iarchive : + public boost::archive::xml_iarchive_impl +{ + typedef xml_iarchive Archive; + typedef boost::archive::xml_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_xml_iarchive; + friend class boost::archive::load_access; +public: + xml_iarchive(std::istream & is, unsigned int flags = 0) : + xml_iarchive_impl(is, flags) + {} + + using basic_xml_iarchive::load_override; + + // Anything not an attribute should be a name value pair as nvp or hrp + typedef boost::archive::detail::common_iarchive detail_common_iarchive; + template + void load_override( + #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + const + #endif + boost::serialization::hrp< T > & t, + int v + ){ + this->This()->load_start(t.name()); + this->detail_common_iarchive::load_override(t.value(), 0); +// t.stov(); + this->This()->load_end(t.name()); + } + + + // class_name_type can't be handled here as it depends upon the + // char type used by the stream. So require the derived implementation. + // derived in this case is xml_iarchive_impl or base .. + using base::load_override; + + void load_override(const char *str, int v) { + // StringReader sr(basic_text_iprimitive::is); + // sr >> str; + } + + ~xml_iarchive(){}; +}; + +//typedef boost::archive::detail::polymorphic_iarchive_route< +//boost::archive::xml_iarchive_impl +//> polymorphic_xml_iarchive; + +template +struct polymorphic_iarchive_route : + boost::archive::detail::polymorphic_iarchive_route +{ + virtual void load(const char * t){ + ArchiveImpl::load(t); + } +}; + + +class polymorphic_xml_iarchive : + public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl > +{ + // give serialization implementation access to this class +// friend class boost::archive::detail::interface_iarchive; +// friend class boost::archive::basic_xml_iarchive; +// friend class boost::archive::load_access; +public: + virtual void load_override(const char *str, int v) { + ; + } +}; + + + +class xml_oarchive : + public boost::archive::xml_oarchive_impl +{ + typedef xml_oarchive Archive; + typedef boost::archive::xml_oarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_xml_oarchive; + friend class boost::archive::save_access; +public: + xml_oarchive(std::ostream & os, unsigned int flags = 0) : + boost::archive::xml_oarchive_impl(os, flags) + {} + + // example of implementing save_override for const char* // + // void save_override(const char *t, int) { + // std::cout << "found char: " << t << "\n"; + // } + + using basic_xml_oarchive::save_override; + + // special treatment for name-value pairs. + typedef boost::archive::detail::common_oarchive detail_common_oarchive; + template + void save_override( + #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + const + #endif + ::boost::serialization::hrp< T > & t, + int v + ){ + this->This()->save_start(t.name()); +// t.vtos(); +// this->detail_common_oarchive::save_override(t.const_value(), 0); + this->This()->save_end(t.name()); + } + + void save_override(const char *str, int v) { + // Do not save any human decoration string // + // basic_text_oprimitive::save(str); + } + + ~xml_oarchive(){} +}; + +//typedef boost::archive::detail::polymorphic_oarchive_route< +//boost::archive::xml_oarchive_impl +//> polymorphic_xml_oarchive; + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// TEXT // + +class text_iarchive : + public boost::archive::text_iarchive_impl +{ + typedef text_iarchive Archive; + typedef boost::archive::text_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_text_iarchive; + friend class boost::archive::load_access; +public: + text_iarchive(std::istream & is, unsigned int flags = 0) : + text_iarchive_impl(is, flags) + {} + + using basic_text_iarchive::load_override; + + void load_override(boost::archive::object_id_type & t, int) {} + + // class_name_type can't be handled here as it depends upon the + // char type used by the stream. So require the derived implementation. + // derived in this case is xml_iarchive_impl or base .. + using base::load_override; + + void load_override(const char *str, int v) { + StringReader sr(basic_text_iprimitive::is); + sr >> str; + } + + ~text_iarchive() {}; +}; + +typedef text_iarchive naked_text_iarchive; + +//typedef boost::archive::detail::polymorphic_iarchive_route< +//naked_text_iarchive +//> polymorphic_text_iarchive; + + + +class text_oarchive : + public boost::archive::text_oarchive_impl +{ + typedef text_oarchive Archive; + typedef boost::archive::text_oarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_text_oarchive; + friend class boost::archive::save_access; +public: + text_oarchive(std::ostream & os, unsigned int flags = 0) : + boost::archive::text_oarchive_impl(os, flags) + {} + + using basic_text_oarchive::save_override; + + void save_override(const char *str, int v) { + basic_text_oprimitive::save(str); + } + + ~text_oarchive(){} +}; + +//typedef boost::archive::detail::polymorphic_oarchive_route< +//boost::archive::text_oarchive_impl +//> polymorphic_text_oarchive; + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// SIMPLE HUMAN READABLE TEXT // + +class hrt_iarchive : + public boost::archive::text_iarchive_impl +{ + typedef hrt_iarchive Archive; + typedef boost::archive::text_iarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_iarchive; + friend class boost::archive::basic_text_iarchive; + friend class boost::archive::load_access; +public: + hrt_iarchive(std::istream & is, unsigned int flags = 0) : + base(is, flags | boost::archive::no_header ) + {} + + using basic_text_iarchive::load_override; + + // hide all archive props // + void load_override( boost::archive::object_id_type & t, int) {} + void load_override( boost::archive::object_reference_type & t, int) {} + void load_override( boost::archive::version_type & t, int) {} + void load_override( boost::archive::class_id_type & t, int) {} + void load_override( boost::archive::class_id_optional_type & t, int) {} + void load_override( boost::archive::class_id_reference_type & t, int){} + void load_override( boost::archive::class_name_type & t, int) {} + void load_override( boost::archive::tracking_type & t, int) {} + + // class_name_type can't be handled here as it depends upon the + // char type used by the stream. So require the derived implementation. + // derived in this case is xml_iarchive_impl or base .. + using base::load_override; + + void load_override(const char *str, int v) { + StringReader sr(basic_text_iprimitive::is); + sr >> str; + } + + ~hrt_iarchive() {}; +}; + + +class hrt_oarchive : + public boost::archive::text_oarchive_impl + { + typedef hrt_oarchive Archive; + typedef boost::archive::text_oarchive_impl base; + + // give serialization implementation access to this class + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_text_oarchive; + friend class boost::archive::save_access; + public: + hrt_oarchive(std::ostream & os, unsigned int flags = 0) : + base(os, flags | boost::archive::no_header ) + {} + + using basic_text_oarchive::save_override; + + void save_override(const boost::archive::object_id_type & t, int) {} + void save_override(const boost::archive::object_reference_type & t, int) {} + void save_override(const boost::archive::version_type & t, int) {} + void save_override(const boost::archive::class_id_type & t, int) {} + void save_override(const boost::archive::class_id_optional_type & t, int) {} + void save_override(const boost::archive::class_id_reference_type & t, int){} + void save_override(const boost::archive::class_name_type & t, int) {} + void save_override(const boost::archive::tracking_type & t, int) {} + + + void save_override(const char *str, int v) { + basic_text_oprimitive::save(str); + } + + ~hrt_oarchive(){} + }; + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// XML FOR LOG OUTPUT PURPOUSE // + +///////////////////////////////////////////////////////////////////////// +// log data to an output stream. This illustrates a simpler implemenation +// of text output which is useful for getting a formatted display of +// any serializable class. Intended to be useful as a debugging aid. +class log_archive : + /* protected ? */ + public boost::archive::xml_oarchive_impl +{ + typedef boost::archive::xml_oarchive_impl base; + typedef log_archive Archive; + // give serialization implementation access to this clas + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::basic_xml_oarchive; + friend class boost::archive::save_access; + +public: + + void save_override(const char *str, int v) { + // Do not save any human decoration string // + // basic_text_oprimitive::save(str); + } + + template + void save_override(T & t, BOOST_PFTO int){ + base::save_override(boost::serialization::make_nvp(NULL, t), 0); + } + + // activate this if you want to trap non nvp objects // + // template + // void save_override(T & t, BOOST_PFTO int) + // { + // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >)); + // // this->detail_common_oarchive::save_override(t, 0); + // } + + template + void save_override(const boost::serialization::nvp & t, int){ + base::save_override(t, 0); + } + + + // specific overrides for attributes - not name value pairs so we + // want to trap them before the above "fall through" + // since we don't want to see these in the output - make them no-ops. + void save_override(const boost::archive::object_id_type & t, int) {} + void save_override(const boost::archive::object_reference_type & t, int) {} + void save_override(const boost::archive::version_type & t, int) {} + void save_override(const boost::archive::class_id_type & t, int) {} + void save_override(const boost::archive::class_id_optional_type & t, int) {} + void save_override(const boost::archive::class_id_reference_type & t, int){} + void save_override(const boost::archive::class_name_type & t, int) {} + void save_override(const boost::archive::tracking_type & t, int) {} + + +public: + log_archive(std::ostream & os, unsigned int flags = 0) : + boost::archive::xml_oarchive_impl( + os, + flags | boost::archive::no_header + ) + {} +}; + +//typedef boost::archive::detail::polymorphic_oarchive_route< +//boost::archive::xml_oarchive_impl +//> polymorphic_log_archive; + + + + +} // Archive + + + +} // uLib + + +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_iarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_oarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_iarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_oarchive) +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive) + +//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_iarchive) +//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_oarchive) +//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_iarchive) +//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive) +//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive) + + + + +#endif // U_CORE_ARCHIVES_H diff --git a/src/Core/Array.h b/src/Core/Array.h new file mode 100644 index 0000000..0e42f07 --- /dev/null +++ b/src/Core/Array.h @@ -0,0 +1,72 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_ARRAY_H +#define U_CORE_ARRAY_H + +#include // std::array + +#include "Types.h" + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//// ERROR NOT WORKING CLASS, USE VECTOR INSTEAD ////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +namespace uLib { + +template< typename T, Size_t size > +class Array : public std::array { + +}; + + +template< typename T, Size_t size > +class SmartArray : public SmartPointer< Array > { + typedef SmartPointer< Array > ptr; +public: + SmartArray() : ptr(new Array()) { } + SmartArray( const SmartArray ©) : ptr(copy) { } + virtual ~SmartArray() {} + + T& operator[](unsigned int p) { + return ptr::get()->at(p); + } + + + +}; + + + +} + +#endif // ARRAY_H diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt new file mode 100644 index 0000000..3e27cb6 --- /dev/null +++ b/src/Core/CMakeLists.txt @@ -0,0 +1,46 @@ + +set(HEADERS + Archives.h + Array.h + Collection.h + Debug.h + Export.h + Function.h + Macros.h + Mpl.h + Object.h + ObjectProps.h + Options.h + Serializable.h + Signal.h + Singleton.h + SmartPointer.h + StaticInterface.h + StringReader.h + Types.h + Uuid.h + Vector.h + CommaInitializer.h + Timer.h +) + +SET(SOURCES + Archives.cpp + Object.cpp + Options.cpp + Serializable.cpp + Signal.cpp + Uuid.cpp +) + +set(LIBRARIES + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${ROOT_LIBRARIES} + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math +) + +uLib_add_shared_library(${uLib-module}) +add_subdirectory(testing) diff --git a/src/Core/Collection.h b/src/Core/Collection.h new file mode 100644 index 0000000..1ebe1ce --- /dev/null +++ b/src/Core/Collection.h @@ -0,0 +1,100 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_COLLECTION_H +#define U_CORE_COLLECTION_H + +#include +#include + +#include "SmartPointer.h" +#include "Vector.h" + +//////////////////////////////////////////////////////////////////////////////// +/////// COLLECTION TEMPLATE ////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Implements concept of unordered collection of elements + +namespace uLib { + +namespace Abstract { + +template +class Collection { +public: + virtual ~Collection() {} + + virtual void AddItem(T obj) =0; + virtual void RemoveItem(int i) =0; + virtual int GetNumberOfItems() =0; + virtual T& At(unsigned int i) =0; + + virtual void PrintSelf(std::ostream &o) =0; +}; + +} + + +template +class Collection : public Abstract::Collection { + +public: + Collection() : data() {} + Collection(int size) : data(size) {} + ~Collection() {} + + inline void AddItem(T obj) { data->push_back(obj); } + inline void RemoveItem(int i) { data.remove_element(i); } + inline int GetNumberOfItems() { return data->size(); } + + inline T& At(unsigned int i) { return data->at(i); } + inline T& operator[] (unsigned int i) { return data->at(i); } + + inline void PrintSelf(std::ostream &o); + +private: + SmartVector data; +}; + + +template +void Collection::PrintSelf(std::ostream &o) +{ + o << " *** uLib Collection *** \n"; + o << " n. of items = " << this->GetNumberOfItems() << "\n"; +} + + +} + + + + + + + +#endif // COLLECTION_H diff --git a/src/Core/CommaInitializer.h b/src/Core/CommaInitializer.h new file mode 100644 index 0000000..262b918 --- /dev/null +++ b/src/Core/CommaInitializer.h @@ -0,0 +1,89 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#ifndef U_CORE_COMMAINITIALIZER_H +#define U_CORE_COMMAINITIALIZER_H + +namespace uLib { + +// Comma Initializer template ... +// ContentT should provide operator[] and resize() methods. +// Waiting for Static interface check + +template < typename ContainerT, typename ContentT > +struct CommaInitializer +{ + inline explicit CommaInitializer(ContainerT *container, ContentT s) + : container(container) + { + this->index = 0; + container->resize(1); + this->container->operator[](0) = s; + } + inline CommaInitializer & operator, (ContentT s) { + this->index++; + container->resize(index + 1); + this->container->operator[](this->index) = s; + return *this; + } + + ContainerT *container; + unsigned int index; +}; + + +// Comma Initializer template for fixed array... +// ContentT should provide operator[] and size() methods. +// Waiting for Static interface check + +template < typename ContainerT, typename ContentT > +struct CommaInitializerFixed +{ + inline explicit CommaInitializerFixed(ContainerT *container, ContentT s) + : container(container) + { + this->index = 0; + this->container->operator[](0) = s; + } + inline CommaInitializerFixed & operator, (ContentT s) { + this->index++; + this->container->operator[](this->index) = s; + return *this; + } + + ContainerT *container; + unsigned int index; +}; + + + + + + +} // uLib + + + +#endif // COMMAINITIALIZER_H diff --git a/src/Core/Debug.cpp b/src/Core/Debug.cpp new file mode 100644 index 0000000..09603cb --- /dev/null +++ b/src/Core/Debug.cpp @@ -0,0 +1,31 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Debug.h" + + diff --git a/src/Core/Debug.h b/src/Core/Debug.h new file mode 100644 index 0000000..cd70930 --- /dev/null +++ b/src/Core/Debug.h @@ -0,0 +1,148 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_DEBUG_H +#define U_CORE_DEBUG_H + + + +#include "ltk/ltkdebug.h" +#include "Macros.h" +#include "Types.h" +#include "Mpl.h" +#include "Vector.h" + +#include +#include + +namespace uLib { + + +namespace detail { + +struct DebugAdapterInterface { + virtual ~DebugAdapterInterface() {} + + virtual void operator()(char val) {} + virtual void operator()(unsigned char val) {} + virtual void operator()(short val) {} + virtual void operator()(unsigned short val) {} + virtual void operator()(int val) {} + virtual void operator()(unsigned int val) {} + virtual void operator()(long val) {} + virtual void operator()(unsigned long val) {} + + virtual void operator()(float val) {} + virtual void operator()(double val) {} + + virtual void operator()(std::string val) {} +}; + + +struct DebugAdapter { + struct AnyCastAdapterBase { + virtual ~AnyCastAdapterBase(){} + virtual void operator()(SmartPointer &ad, boost::any &val) {} + }; + + template < typename T > + struct AnyCastAdapter : AnyCastAdapterBase { + void operator()(SmartPointer &ad, boost::any &val) { ad->operator()(boost::any_cast(val)); } + }; + + struct DItem { + DItem(){} + template DItem(std::string str, T &t) : + m_adapter(new AnyCastAdapter()), + m_name(str), + m_value(t) { } + + SmartPointer m_adapter; + std::string m_name; + boost::any m_value; + }; + +}; + + +} // detail + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// text ADAPTER + +class DebugAdapterText : public detail::DebugAdapterInterface { + std::ostream &m_out; +public: + DebugAdapterText(std::ostream &o) : m_out(o) {} + void operator()(int val) { m_out << "debug: " << val << "\n"; } + void operator()(std::string val) { m_out << "debug: " << val << "\n"; } +}; + + + + + +class Debug { + typedef detail::DebugAdapterInterface AdapterInterface; + typedef SmartPointer Adapter; + typedef detail::DebugAdapter::DItem DItem; +public: + + template void operator() (std::string str, T &t) { m_v.push_back(DItem(str,t)); } + + void AddAdapter(AdapterInterface &ad) { m_a.push_back(Adapter(ad)); } + + void Update() { + foreach(Adapter &ad, m_a) { + foreach(DItem &item, m_v) { + item.m_adapter->operator()(ad, item.m_value); + } + } + } + +private: + Vector m_v; + Vector m_a; +}; + + + + + + +} // uLib + + + + + + + +#endif // DEBUG_H diff --git a/src/Core/DebugArchives.cpp b/src/Core/DebugArchives.cpp new file mode 100644 index 0000000..3620d7a --- /dev/null +++ b/src/Core/DebugArchives.cpp @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + + +#include +#include "DebugArchives.h" + +namespace uLib { +namespace Archive { +namespace detail { + +basic_Root_Ttree_oprimitive::basic_Root_Ttree_oprimitive(const char *tree_name) +{ + m_tree = new TTree(tree_name,tree_name); +} + +basic_Root_Ttree_oprimitive::~basic_Root_Ttree_oprimitive() +{ + m_tree->Write(); + m_tree->ResetBranchAddresses(); + m_tree->Delete(); +} + +} // detail +} // Archive +} // uLib + diff --git a/src/Core/DebugArchives.h b/src/Core/DebugArchives.h new file mode 100644 index 0000000..1109635 --- /dev/null +++ b/src/Core/DebugArchives.h @@ -0,0 +1,289 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_DEBUGARCHIVES_H +#define U_CORE_DEBUGARCHIVES_H + +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include "Archives.h" +#include "StringReader.h" + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// FWD DECLARATIONS OF ARCHIVES // + + +namespace uLib { +namespace Archive { + +class Root_debug_archive; + +} +} + + +namespace boost { +namespace archive { +namespace detail { +template class polymorphic_oarchive_route; +template class polymorphic_iarchive_route; +} +} +} + +namespace boost { +namespace serialization { + template struct hrp; +} +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES REGISTRATION // + +// in Archives.h + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES IO INTERFACES // + + +namespace boost { +namespace archive { +namespace detail { + + +// DECLARE INTERFACE SPECIALIZATIONS /////////////////////////////////////////// +// With this declarations all uLib archive Implementation will use their own +// extended interface // + +template <> +class interface_iarchive : public + uLib_interface_iarchive {}; + + +} // detail +} // archive +} // boost + + + + + + + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ARCHIVES DEFINITIONS // + +namespace boost { +namespace archive { + +//template +//inline void load_const_override(Archive & ar, const char *t ){ +// typedef typename mpl::identity >::type typex; +// typex::invoke(ar, t); +//} + +//template +//inline void load(Archive & ar, T &t){ +// // if this assertion trips. It means we're trying to load a +// // const object with a compiler that doesn't have correct +// // funtion template ordering. On other compilers, this is +// // handled below. +// // detail::check_const_loading< T >(); +// typedef +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// BOOST_DEDUCED_TYPENAME mpl::eval_if, +// mpl::identity > +// ,//else +// mpl::identity > +// > +// > +// >::type typex; +// typex::invoke(ar, t); +//} + + + +} +} + +// ROOT FWD +class TTree; +/////////// + + +namespace uLib { +namespace Archive { + +namespace detail { + +class basic_Root_Ttree_oprimitive +{ + TTree *m_tree; + + + +public: + basic_Root_Ttree_oprimitive(const char *tree_name); + ~basic_Root_Ttree_oprimitive(); + +}; + +} // detail + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// XML FOR LOG OUTPUT PURPOUSE // + +/////////////////////////////////////////////////////////////////////////// +//// log data to an output stream. This illustrates a simpler implemenation +//// of text output which is useful for getting a formatted display of +//// any serializable class. Intended to be useful as a debugging aid. +class Root_debug_archive : + /* protected ? */ + public boost::archive::detail::common_oarchive +{ + typedef boost::archive::detail::common_oarchive base; + typedef Root_debug_archive Archive; + + // give serialization implementation access to this clas + friend class boost::archive::detail::interface_oarchive; + friend class boost::archive::save_access; + +public: + +// void save_override(const char *str, int v) { +// // Do not save any human decoration string // +// // basic_text_oprimitive::save(str); +// } + +// template +// void save_override(T & t, BOOST_PFTO int){ +// base::save_override(boost::serialization::make_nvp(NULL, t), 0); +// } + +// // activate this if you want to trap non nvp objects // +// // template +// // void save_override(T & t, BOOST_PFTO int) +// // { +// // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >)); +// // // this->detail_common_oarchive::save_override(t, 0); +// // } + +// template +// void save_override(const boost::serialization::nvp & t, int){ +// base::save_override(t, 0); +// } + + +// // specific overrides for attributes - not name value pairs so we +// // want to trap them before the above "fall through" +// // since we don't want to see these in the output - make them no-ops. +// void save_override(const boost::archive::object_id_type & t, int) {} +// void save_override(const boost::archive::object_reference_type & t, int) {} +// void save_override(const boost::archive::version_type & t, int) {} +// void save_override(const boost::archive::class_id_type & t, int) {} +// void save_override(const boost::archive::class_id_optional_type & t, int) {} +// void save_override(const boost::archive::class_id_reference_type & t, int){} +// void save_override(const boost::archive::class_name_type & t, int) {} +// void save_override(const boost::archive::tracking_type & t, int) {} + + +//public: +// Root_debug_archive(std::ostream & os, unsigned int flags = 0) : +// boost::archive::xml_oarchive_impl( +// os, +// flags | boost::archive::no_header +// ) +// {} +}; + + + + + +} // Archive +} // uLib + + + +ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::Root_debug_archive) + + + + + + +#endif // U_CORE_DEBUGARCHIVES_H diff --git a/src/Core/Export.h b/src/Core/Export.h new file mode 100644 index 0000000..1b43cd0 --- /dev/null +++ b/src/Core/Export.h @@ -0,0 +1,117 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_EXPORT_H +#define U_CORE_EXPORT_H + +#include +#include // NULL +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include // for guid_defined only +#include +#include +#include +#include + +#include + + +#include "Core/Archives.h" + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + + +namespace uLib { +namespace Archive { +namespace detail { +namespace extra_detail { + +template +struct guid_initializer +{ + void export_guid(mpl::false_) const { + // generates the statically-initialized objects whose constructors + // register the information allowing serialization of T objects + // through pointers to their base classes. + boost::archive::detail:: + instantiate_ptr_serialization((T*)0, 0, + uLib::Archive::detail::adl_tag()); + } + void export_guid(mpl::true_) const { + } + guid_initializer const & export_guid() const { + BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value); + // note: exporting an abstract base class will have no effect + // and cannot be used to instantitiate serialization code + // (one might be using this in a DLL to instantiate code) + //BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value); + export_guid(boost::serialization::is_abstract< T >()); + return *this; + } +}; + +template +struct init_guid; + +} // anonymous +} // namespace detail +} // namespace Archive +} // namespace uLib + + + +#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \ + namespace uLib { \ + namespace Archive { \ + namespace detail { \ + namespace extra_detail { \ + template<> \ + struct init_guid< T > { \ + static guid_initializer< T > const & g; \ + }; \ + guid_initializer< T > const & init_guid< T >::g = \ + ::boost::serialization::singleton< \ + guid_initializer< T > \ + >::get_mutable_instance().export_guid(); \ + }}}} \ +/**/ + +#endif // EXPORT_H diff --git a/src/Core/Flags.h b/src/Core/Flags.h new file mode 100644 index 0000000..1ce1a2d --- /dev/null +++ b/src/Core/Flags.h @@ -0,0 +1,54 @@ +#ifndef FLAGS_H +#define FLAGS_H + +#include + +namespace uLib { + +template +class Flags +{ + int i; +public: + typedef Enum enum_type; + CONSTEXPR inline Flags(const Flags &f) : i(f.i) {} + CONSTEXPR inline Flags(Enum f) : i(f) {} + CONSTEXPR inline Flags() : i(0) {} + + inline Flags &operator=(const Flags &f) { i = f.i; return *this; } + inline Flags &operator&=(int mask) { i &= mask; return *this; } + inline Flags &operator&=(uint mask) { i &= mask; return *this; } + inline Flags &operator|=(Flags f) { i |= f.i; return *this; } + inline Flags &operator|=(Enum f) { i |= f; return *this; } + inline Flags &operator^=(Flags f) { i ^= f.i; return *this; } + inline Flags &operator^=(Enum f) { i ^= f; return *this; } + + CONSTEXPR inline operator int() const { return i; } + + CONSTEXPR inline Flags operator|(Flags f) const { return Flags(Enum(i | f.i)); } + CONSTEXPR inline Flags operator|(Enum f) const { return Flags(Enum(i | f)); } + CONSTEXPR inline Flags operator^(Flags f) const { return Flags(Enum(i ^ f.i)); } + CONSTEXPR inline Flags operator^(Enum f) const { return Flags(Enum(i ^ f)); } + CONSTEXPR inline Flags operator&(int mask) const { return Flags(Enum(i & mask)); } + CONSTEXPR inline Flags operator&(uint mask) const { return Flags(Enum(i & mask)); } + CONSTEXPR inline Flags operator&(Enum f) const { return Flags(Enum(i & f)); } + CONSTEXPR inline Flags operator~() const { return Flags(Enum(~i)); } + + CONSTEXPR inline bool operator!() const { return !i; } + + inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); } +}; + +#define ULIB_OPERATORS_FOR_FLAGS(Flags) \ +CONSTEXPR inline QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) \ +{ return QFlags(f1) | f2; } \ +CONSTEXPR inline QFlags operator|(Flags::enum_type f1, QFlags f2) \ +{ return f2 | f1; } + + +} // uLib + + + + +#endif // FLAGS_H diff --git a/src/Core/Function.h b/src/Core/Function.h new file mode 100644 index 0000000..7fe720d --- /dev/null +++ b/src/Core/Function.h @@ -0,0 +1,155 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_FUNCTION_H +#define U_CORE_FUNCTION_H + +#include + +#include +#include + +#include +#include +#include +//#include + + +namespace uLib { + + + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +// type synthesize ( please read: boost implementation synthesize.hpp ) // +//////////////////////////////////////////////////////////////////////////////// +// TODO: change this to boost implementation // +// return a reference to function ... as the boost signal signature wants + +template +struct FunctionTypes {}; + +template +struct FunctionTypes< R(O::*)() > { + typedef R ref(); + typedef R (ptr)(); + typedef O obj; +}; + +template +struct FunctionTypes< R(O::*)(T0) > { + typedef R ref(T0); + typedef R (ptr)(T0); + typedef O obj; +}; + +template +struct FunctionTypes< R(O::*)(T0,T1) > { + typedef R ref(T0,T1); + typedef R (ptr)(T0,T1); + typedef O obj; +}; + +template +struct FunctionTypes< R(O::*)(T0,T1,T2) > { + typedef R ref(T0,T1,T2); + typedef R (ptr)(T0,T1,T2); + typedef O obj; +}; + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Function pointers // + +template +struct FunctionPointer { + typedef typename boost::function_types::function_type::type Signature; + typedef typename FunctionTypes::ref SignalSignature; + enum { + arity = boost::function_types::function_arity::value, + ismfp = boost::is_member_function_pointer::value + }; + + typedef boost::mpl::bool_< ismfp > HasObjectType; + typedef typename FunctionTypes::obj Object; + typedef boost::function_traits< Signature > Traits; + + virtual void PrintSelf( std::ostream &o ) { + o << "[fp: " << typeid(Signature).name() + << " arity: " << arity << "]\n"; } +}; + + + + +//////// generic mfp container object ///////////////////////////////////////// + +class GenericMFPtr { + typedef void (GenericMFPtr::*_MFPtrStub_t)(); +public: + + typedef _MFPtrStub_t Type; + + GenericMFPtr() {} + + template + GenericMFPtr(T in) { + m_ptr = reinterpret_cast<_MFPtrStub_t>(in); + } + + template + inline bool operator == (T in) { + return m_ptr == reinterpret_cast<_MFPtrStub_t>(in); + } + + inline bool operator == (const GenericMFPtr &in) { + return m_ptr == in.m_ptr; + } + + Type operator()() { return m_ptr; } + + _MFPtrStub_t m_ptr; +private: +}; + +} // uLib + + + + +#endif // FUNCTION_H diff --git a/src/Core/Macros.h b/src/Core/Macros.h new file mode 100644 index 0000000..f582562 --- /dev/null +++ b/src/Core/Macros.h @@ -0,0 +1,133 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_MACROS_H +#define U_CORE_MACROS_H + +//#ifndef HAVE_CONFIG_H +// #include "config.h" +//#endif + +#include + +#define uLibAssert(condition) assert(condition) + + +// Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility // +// http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol // +#if defined _WIN32 || defined __CYGWIN__ + #ifdef BUILDING_DLL + #ifdef __GNUC__ + #define DLL_PUBLIC __attribute__ ((dllexport)) + #else + #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif + #else + #ifdef __GNUC__ + #define DLL_PUBLIC __attribute__ ((dllimport)) + #else + #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. + #endif + #endif + #define DLL_LOCAL +#else + #if __GNUC__ >= 4 + #define DLL_PUBLIC __attribute__ ((visibility ("default"))) + #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) + #else + #define DLL_PUBLIC + #define DLL_LOCAL + #endif +#endif + + + +// foreach Qt style +#ifndef foreach +#include "boost/foreach.hpp" +#define foreach(ref, list) BOOST_FOREACH(ref,list) +#endif + + + +#define uLibVGetMacro(name,type) \ + virtual inline const type Get##name() const = 0; + +#define uLibVSetMacro(name,type) \ + virtual inline void Set##name(const type name) = 0; + +#define uLibVGetSetMacro(name,type) \ + uLibVGet(name,type); \ + uLibVSet(name,type); + +#define uLibVRefMacro(name,type) \ + virtual inline type & name() = 0; + + + +#define uLibGetMacro(name,type) \ + inline type Get##name() const { return this->m_##name; } + +#define uLibConstRefMacro(name,type) \ + inline const type & name() const { return this->m_##name; } + +// verificare necessita' di typecast // +#define uLibSetMacro(name,type) \ + inline void Set##name(type name) { this->m_##name = name; } + +#define uLibGetSetMacro(name,type) \ + inline type Get##name() const { return this->m_##name; } \ + uLibSetMacro(name,type); + +#define uLibRefMacro(name,type) \ + inline type & name() { return this->m_##name; } + + +/* Following macros override usual branch prediction of compiler + * These are to be used in conditional statement whose result might + * be Bayesian biased: + * + * // previous_line + * if (likely(a>1)) { // block_1 } + * else { block_2 } + * + * will write the block_1 code right after previous line, without using + * compiler branch prediction for results. Otherwise + * + * // previous_line + * if (unlikely(a>1)) { // block_1 } + * else { block_2 } + * + * will write block_2 after previous_line, leaving block_1 after + * (usually after the end of the whole function! Use with care!) + */ + +#define unlikely(expr) __builtin_expect(!!(expr), 0) + +#define likely(expr) __builtin_expect(!!(expr), 1) + +#endif // MACROS_H diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am new file mode 100644 index 0000000..2bb1092 --- /dev/null +++ b/src/Core/Makefile.am @@ -0,0 +1,41 @@ +SUBDIRS = . + +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Core + +library_include_HEADERS = \ + Archives.h \ + Array.h \ + Collection.h \ + Debug.h \ + Export.h \ + Function.h \ + Macros.h \ + Mpl.h \ + Object.h \ + ObjectProps.h \ + Options.h \ + Serializable.h \ + Signal.h \ + Singleton.h \ + SmartPointer.h \ + StaticInterface.h \ + StringReader.h \ + Types.h \ + Uuid.h \ + Vector.h + + +_CORE_SOURCES = \ + Archives.cpp \ + Debug.cpp \ + Object.cpp \ + Options.cpp \ + Serializable.cpp \ + Signal.cpp \ + Uuid.cpp + + +noinst_LTLIBRARIES = libmutomcore.la +libmutomcore_la_SOURCES = ${_CORE_SOURCES} diff --git a/src/Core/Mpl.h b/src/Core/Mpl.h new file mode 100644 index 0000000..d7f0130 --- /dev/null +++ b/src/Core/Mpl.h @@ -0,0 +1,139 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MPL_H +#define U_MPL_H + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +/** + * Max size of nofold inerited capability + */ +#ifndef ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE +# define ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE 10 +#endif + +namespace uLib { + +namespace mpl { + +using namespace boost::mpl; +using namespace boost::mpl::placeholders; + +//using boost::enable_if; + +namespace detail { + +/** + * Inerit nofold implementation, set ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE to + * desired max derivation size keeping in mind that total size accounts all + * mutiple inherited classes. + */ +template +struct inherit_nofold {}; + +// Horizontal repetition macro // +#define _INERIT_NOFOLD_H(hz,hn,hdata) \ + BOOST_PP_COMMA_IF(hn) \ + mpl::at >::type + +// Veritical repetition macro // +#define _INERIT_NOFOLD_V(vz,vn,vdata) \ + template \ + struct inherit_nofold : \ + BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \ + {}; + +// Multiple size declaration // +BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~) + +#undef _INERIT_NOFOLD_H +#undef _INERIT_NOFOLD_V + + +} // detail + +/** + * Build a derivation tuple from mpl type sequence. + * The same behavior can be obtained by inherit_linearly but folding derivation + * results in a hard to read debugging + */ +template +struct inherit_nofold { + typedef detail::inherit_nofold< TypeSeq, mpl::size::type::value > type; +}; + +/** INHERIT LINEARLY standard utility macro */ +#define ULIB_MPL_INHERIT_SEQ(_TypeList) \ + uLib::mpl::inherit_linearly< _TypeList, mpl::inherit< mpl::_1, mpl::_2 > >::type + +/** INHERIT NOFOLD utility macro (see struct inherit_nofold template) */ +#define ULIB_MPL_INHERIT_NOFOLD_SEQ(_TypeList) \ + uLib::mpl::inherit_nofold< _TypeList >::type + + + + +template< class T> +struct type { + +}; + +template +struct nvp { + nvp() : name(N) {} + const char *name; + typedef T type; +}; + + +} // mpl + +} // uLib + +#endif // MPL_H diff --git a/src/Core/Object.cpp b/src/Core/Object.cpp new file mode 100644 index 0000000..1c6d690 --- /dev/null +++ b/src/Core/Object.cpp @@ -0,0 +1,227 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + + +#include "config.h" + +#include "Object.h" +#include "Vector.h" + +#include "boost/archive/polymorphic_xml_oarchive.hpp" +#include "boost/archive/polymorphic_xml_iarchive.hpp" +#include "boost/archive/polymorphic_text_oarchive.hpp" +#include "boost/archive/polymorphic_text_iarchive.hpp" +#include "boost/archive/polymorphic_binary_oarchive.hpp" +#include "boost/archive/polymorphic_binary_iarchive.hpp" + + + +namespace uLib { + + +const char *Version::PackageName = PACKAGE_NAME; +const char *Version::VersionNumber = PACKAGE_VERSION; +const char *Version::Release = "x"; //SVN_REVISION; + + +//////////////////////////////////////////////////////////////////////////////// +// Object Private // + +class ObjectPrivate { +public: + + struct Signal { + GenericMFPtr sigptr; + std::string sigstr; + SignalBase *signal; + }; + + struct Slot { + GenericMFPtr sloptr; + std::string slostr; + }; + + + Vector sigv; + Vector slov; +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// OBJECT IMPLEMENTATION + + + +Object::Object() : + d(new ObjectPrivate) +{} + +Object::Object(const Object ©) : + ObjectPropable(copy), + d(new ObjectPrivate(*copy.d)) +{} + +Object::~Object() { + delete d; +} + +void Object::DeepCopy(const Object ©) +{ + // should lock to be tread safe // + memcpy(d,copy.d,sizeof(ObjectPrivate)); + // ERROR! does not copy parameters ... <<<< FIXXXXX +} + + + + + +void Object::SaveXml(std::ostream &os, Object &ob) +{ + Archive::xml_oarchive ar(os); + ar << boost::serialization::make_nvp("Object",ob); +} + +void Object::LoadXml(std::istream &is, Object &ob) +{ + Archive::xml_iarchive ar(is); + ar >> boost::serialization::make_nvp("Object",ob); +} + + +// FINIRE +void Object::SaveConfig(std::ostream &os, int version) +{ + Archive::xml_oarchive ar(os); + ObjectPropable::serialize(ar,0); +} + +void Object::LoadConfig(std::istream &is, int version) +{ + if(!props()) this->init_properties(); + Archive::xml_iarchive ar(is); + ObjectPropable::serialize(ar,0); +} + + + + + +void Object::PrintSelf(std::ostream &o) const +{ + o << "OBJECT signals: ------------------\n"; + Vector::Iterator itr; + for(itr = d->sigv.begin(); itrsigv.end(); itr++) + { + o << " signal:[ " << itr->sigstr << " ]\n"; + } + o << "--------------------------------------\n\n"; +} + + +bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name) +{ + ObjectPrivate::Signal s = {fptr,std::string(name),sig}; + d->sigv.push_back(s); +} + +bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) +{ + ObjectPrivate::Slot s = {fptr,std::string(name)}; + d->slov.push_back(s); +} + +SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const +{ + for(int i=0; isigv.size(); ++i) + { + if(d->sigv[i].sigptr == fptr) + return d->sigv[i].signal; + } + return NULL; +} + +SignalBase *Object::findSignalImpl(const char *name) const +{ + std::string in(name); + for(int i=0; isigv.size(); ++i) + { + if(d->sigv[i].sigstr == in) + return d->sigv[i].signal; + } + return NULL; +} + +GenericMFPtr *Object::findSlotImpl(const char *name) const +{ + std::string in(name); + for(int i=0; islov.size(); ++i) + { + if(d->slov[i].slostr == in) + return &d->slov[i].sloptr; + } + return NULL; +} + + + + +// std::ostream & +// operator << (std::ostream &os, uLib::Object &ob) +// { +// uLib::Object *op = &ob; +// uLib::Archive::hrt_oarchive (os) << op; +// return os; +// } + +// std::ostream & +// operator << (std::ostream &os, uLib::Object *ob) +// { +// uLib::Archive::hrt_oarchive(os) << ob; +// return os; +// } + +// std::istream & +// operator >> (std::istream &is, uLib::Object &ob) +// { +// // uLib::Object *op = &ob; +// uLib::Archive::hrt_iarchive(is) >> ob; +// return is; +// } + + + + +} // uLib + + + diff --git a/src/Core/Object.h b/src/Core/Object.h new file mode 100644 index 0000000..9a61e7b --- /dev/null +++ b/src/Core/Object.h @@ -0,0 +1,222 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_OBJECT_H +#define U_CORE_OBJECT_H + +#include + +// WARNING: COPILE ERROR if this goes after mpl/vector // +//#include "Core/Vector.h" + +#include "Core/Types.h" +#include "Core/Debug.h" + +#include "Core/Function.h" +#include "Core/Signal.h" + +#include "Core/Mpl.h" +#include "Core/Serializable.h" +#include "Core/ObjectProps.h" +#include "Core/Uuid.h" + +namespace boost { +namespace archive { +class polymorphic_iarchive; +class polymorphic_oarchive; +} // archive +} // boost + + +namespace uLib { + + +class Version { +public: + static const char *PackageName; + static const char *VersionNumber; + static const char *Release; +}; + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//// OBJECT //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + + +/** + * @brief Object class is the object base implementation for uLib Framework. + */ +class Object : public ObjectPropable +{ + + +public: + // std::string name; + // void PrintName() { std::cout << "Ob name: " << name << "\n"; } + + Object(); + Object(const Object ©); + ~Object(); + + //////////////////////////////////////////////////////////////////////////// + // PARAMETERS // + + // FIXX !!! + virtual void DeepCopy(const Object ©); + + + //////////////////////////////////////////////////////////////////////////// + // SERIALIZATION // + + template void serialize(ArchiveT &ar, const unsigned int version) { + ObjectPropable::serialize(ar,version); + } + template void save_override(ArchiveT &ar,const unsigned int version) {} + + void SaveConfig(std::ostream &os, int version = 0); + void LoadConfig(std::istream &is, int version = 0); + + static void SaveXml(std::ostream &os, Object &ob); + static void LoadXml(std::istream &is, Object &ob); + + + + //////////////////////////////////////////////////////////////////////////// + // SIGNALS // + + // Qt4 style connector // + static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) { + // // NOT WORKING YET // + // 1) find slot pointer from name + // SignalBase *sig = ob1->findSignal(signal_name); + // GenericMFPtr *slo = receiver->findSlot(slot_name); + // if(sig && slo) + // return Object::connect(sig,slo->operator ()(),receiver); + // else return false; + } + + // Qt5 style connector // + template + static bool connect( typename FunctionPointer::Object *sender, Func1 sigf, + typename FunctionPointer::Object *receiver, Func2 slof) + { + SignalBase *sigb = sender->findOrAddSignal(sigf); + typedef boost::signals2::signal::SignalSignature> SigT; + ConnectSignal(sigb,slof,receiver); + } + + template + static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) { + ConnectSignal(sigb,slof,receiver); + } + + + template< typename FuncT > + inline typename Signal::SignalSignature>::type * + addSignal(FuncT fun, const char *name) { + typedef typename Signal::SignalSignature>::type SigT; + SignalBase *sig = NewSignal(fun); + addSignalImpl(sig,fun,name); + return (SigT *)sig; + } + + template< typename FuncT> + inline bool addSlot(FuncT fun, const char *name) { + this->addSlotImpl(GenericMFPtr(fun),name); + } + + template < typename FuncT > + inline typename Signal::SignalSignature>::type * + findSignal(FuncT fptr) + { + typedef typename Signal::SignalSignature>::type SigT; + return (SigT *)findSignalImpl(GenericMFPtr(fptr)); + } + + template < typename FuncT > + inline typename Signal::SignalSignature>::type * + findOrAddSignal(FuncT fptr) + { + typedef typename Signal::SignalSignature>::type SigT; + SignalBase *sig = findSignalImpl(GenericMFPtr(fptr)); + if(!sig) { + sig = NewSignal(fptr); + addSignalImpl(sig,fptr,"signal_name_to_be_implemented"); + } + return (SigT *)sig; + } + + + inline SignalBase * + findSignal(const char *name) const + { + return findSignalImpl(name); + } + + inline GenericMFPtr * + findSlot(const char *name) const + { + return findSlotImpl(name); + } + + + void PrintSelf(std::ostream &o) const; + + inline const Object& operator = (const Object ©) + { this->DeepCopy(copy); return *this; } + + +private: + bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name); + bool addSlotImpl(GenericMFPtr fptr, const char *name); + SignalBase *findSignalImpl(const GenericMFPtr &fptr) const; + SignalBase *findSignalImpl(const char *name) const; + GenericMFPtr *findSlotImpl(const char *name) const; + + friend class boost::serialization::access; + friend class ObjectPrivate; + class ObjectPrivate *d; +}; + + + +} // uLib + +//////////////////////////////////////////////////////////////////////////////// + +//std::ostream & operator << (std::ostream &os, uLib::Object &ob); +//std::ostream & operator << (std::ostream &os, uLib::Object *ob); +//std::istream & operator >> (std::istream &is, uLib::Object &ob); + + +#endif // U_OBJECT_H diff --git a/src/Core/ObjectProps.h b/src/Core/ObjectProps.h new file mode 100644 index 0000000..b789d84 --- /dev/null +++ b/src/Core/ObjectProps.h @@ -0,0 +1,278 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_OBJECTPROPS_H +#define U_OBJECTPROPS_H + + + +#include + +#include +#include + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// MACROS // + + +#define ULIB_props() \ + public: struct ObjectProps; \ + virtual void init_properties(); \ + inline struct ObjectProps &p() { /* static const unsigned int offset = props_offset(this); */ \ + /* NON FUNZIA! return * (struct ObjectProps *)(reinterpret_cast(props())+offset); */ \ + return *props()->ptr(); } \ + typedef uLib::mpl::bool_::type propable_trait; \ + public: struct DLL_PUBLIC ObjectProps + +#define properties() ULIB_props() + +#define default(vlaue) + +#define $$ p() + +#define $(_name) props_ref<_name>() + +#define $_init() \ + if(props(this)) return; \ + props_new(this); \ + uLib::detail::ObjectProps::initializer::init_object_baselist(this); + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +namespace boost { +namespace serialization { +class access; +} +} + + +namespace uLib { + +namespace detail { + +struct ObjectProps { + + /** Define a trait has_member to find if an Object is Propable*/ + BOOST_MPL_HAS_XXX_TRAIT_DEF(propable_trait) + + /** IsA ProbapleObject Implementation Template */ + template + struct IsA : has_propable_trait {}; + + /** Lambda to get Props member type */ + template + struct props_type { + typedef typename T::ObjectProps type; + }; + + template + struct get_props { + + /** CFList has result but this method check for has BaseList */ + typedef typename detail::TypeIntrospection::child_first::type CFTypeList; + + /** Filter List items that have not Propable feature */ + typedef typename mpl::filter_view< CFTypeList, IsA >::type FilteredCFTypeList; + + /** Get Props from each Parent in Seq */ + typedef typename mpl::transform_view< FilteredCFTypeList, props_type >::type type; + + + // qui sotto ho un problema che ho temporaneamente tamponato // + // ovvero ho usato child_first_impl per ottenere la lista delle basi // + // vorrei farlo facendo un pop_back ma non va forse perche il tipo // + // non e' corretto. // + + /** Get Parent list from CFTypeList */ + typedef typename detail::TypeIntrospection::child_first_impl::Childs CFBaseList; + + /** Filter Parents that have not Propable feature */ + typedef typename mpl::filter_view< CFBaseList, IsA >::type FilteredCFBaseList; + }; + + + + // TODO: convert to pp const value, + // (non so se sia possibile con il dinamic casting intanto funziona cosi' ) + template + static unsigned int measure_offset(T1 base, T2 derived) { + return reinterpret_cast(derived) - reinterpret_cast(base); + } + + struct initializer { + + template + struct lambda_init_object { + _ObjectT *o; + lambda_init_object(_ObjectT *o) : o(o) {} + template void operator()(T) { + o->T::init_properties(); + } + }; + + + /** + * This calls the internal init_properties() virtual function for each + * object parent defined in BaseList only if it is propable + */ + template + static void init_object_baselist(T *o) { + typedef typename uLib::detail::ObjectProps::get_props::FilteredCFBaseList CFBaseList; + mpl::for_each(lambda_init_object(o)); + } + + /** + * This calls the internal init_properties() virtual function only if + * object is propable ( implementation if not propable ) + */ + template + static + typename boost::enable_if >,void>::type + init_object(T *o) { + ; // do nothing // + } + + /** + * This calls the internal init_properties() virtual function only if + * object is propable ( implementation if propable ) + */ + template + static + typename boost::enable_if,void>::type + init_object(T *o) { + o->init_properties(); + } + + }; + + template + struct serialize_baselist { + ThisClass & m_object; + Archive & m_ar; + serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {} + template void operator()(T &o) { + // T is taken fron get_props::FilteredPList types to get + // type_info_name that is the type name defined by Type macro + typedef typename props_type::type PType; + std::string name(TypeIntrospection::access::type_info::name); + boost::algorithm::replace_all(name,"::","_"); + m_ar & boost::serialization::make_nvp( + name.c_str() , + boost::serialization::base_object(m_object)); + } + }; + +}; + +} // detail + + + + + +struct ObjectPropsBase { + virtual ~ObjectPropsBase() {} + virtual ObjectPropsBase *copy() = 0; + + template inline T *ptr() { return dynamic_cast(this); } + + template void serialize(ArchiveT &ar, const unsigned int version) {} +}; + + + +template +struct ObjectPropsImpl : + ObjectPropsBase, + ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props::type) +{ + typedef ObjectPropsImpl ThisClass; + typedef typename uLib::detail::ObjectProps::get_props::type CFList; + typedef typename uLib::detail::ObjectProps::get_props::FilteredCFTypeList FilteredCFTypeList; + ObjectPropsBase *copy() { return new ThisClass(*this); } + + template void serialize(ArchiveT &ar, const unsigned int version) { + boost::serialization::void_cast_register(); + mpl::for_each(detail::ObjectProps::serialize_baselist(*this,ar)); + } +}; + + +class ObjectPropable { + + ObjectPropsBase *m_props; + friend class uLib::detail::ObjectProps; + friend class boost::serialization::access; +public: + ObjectPropable() : m_props(NULL) {} + ObjectPropable(const ObjectPropable &c) { if(c.m_props) m_props = c.m_props->copy(); else m_props = NULL; } + ~ObjectPropable() { if(m_props) delete m_props; } + + + template inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr(); else exit(1); } + template inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr(); else return NULL; } +protected: + ObjectPropsBase *props() const { return m_props; } + template inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl; } + + /** NOT working dynamic cache casting */ + template inline unsigned int props_offset(T *ptr) const + { if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr()); else return -1; } + + + template void serialize(ArchiveT &ar, const unsigned int version) { + if(m_props) ar & boost::serialization::make_nvp("properties",m_props); + } + +public: + /** + * ObjectPropable is not directly propable itself to prevent Basclass + * duplication in inherit_nofold. And for the same reason ANY VIRTUAL BASE + * SHOULD NOT BE PROPABLE + */ + virtual void init_properties() {} + +}; + +} // uLib + + + + + + + +#endif // U_OBJECTPROPS_H diff --git a/src/Core/Options.cpp b/src/Core/Options.cpp new file mode 100644 index 0000000..bcd8bff --- /dev/null +++ b/src/Core/Options.cpp @@ -0,0 +1,87 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include +#include "Core/Options.h" + +#include + + +//class boost::program_options::error_with_option_name; +//template<> boost::program_options::typed_value boost::program_options::value(); +//template<> boost::program_options::typed_value boost::program_options::value(int *); + + +namespace uLib { + +Options::Options(const char *str) : + m_global(str), + m_configuration("Configuration") +{} + +void Options::parse_command_line(int argc, char *argv[]) { + boost::program_options::store(boost::program_options::parse_command_line(argc,argv,m_global),m_vm); + boost::program_options::notify(m_vm); + + if(m_vm.count("help")) { + std::cout << "\n" << m_global << "\n"; + if(m_configuration.options().size()) { + std::cout << "\n" << m_configuration << "\n\n"; + } + exit(1); + } +} + +void Options::parse_config_file(std::string &str) +{ + this->parse_config_file(str.c_str()); +} + +void Options::parse_config_file(const char *fname) +{ + std::ifstream is; + is.open(fname); + boost::program_options::options_description fileopt; + fileopt.add(m_global).add(m_configuration); + if(is.is_open()) { + boost::program_options::store(boost::program_options::parse_config_file(is,fileopt,true),m_vm); + boost::program_options::notify(m_vm); + } +} + +bool Options::count(const char *str) const +{ + return (m_vm.count(str)); +} + + +} // uLib + + + + diff --git a/src/Core/Options.h b/src/Core/Options.h new file mode 100644 index 0000000..edd1899 --- /dev/null +++ b/src/Core/Options.h @@ -0,0 +1,179 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_OPTIONS_H +#define U_CORE_OPTIONS_H + +#include + +namespace uLib { + +namespace detail { + +struct Options { + + /** + * Wrapper for boost program_options easy init syntax + */ + class options_description_easy_init { + typedef boost::program_options::options_description_easy_init InitClass; + InitClass m_init; + public: + options_description_easy_init(InitClass init) : + m_init(init) {} + + + options_description_easy_init& + operator()(const char* name, + const char* description) + { + m_init(name,description); + return *this; + } + + options_description_easy_init& + operator()(const char* name, + const boost::program_options::value_semantic* s) + { + m_init(name,s); + return *this; + } + + + options_description_easy_init& + operator()(const char* name, + const boost::program_options::value_semantic* s, + const char* description) + { + m_init(name,s,description); + return *this; + } + + + template + options_description_easy_init& + operator()(const char* name, + T * value, + const T default_value, + const char* description) + { + m_init(name, + boost::program_options::value(value)->default_value(default_value), + description); + return *this; + } + + template + options_description_easy_init& + operator()(const char* name, + T * value, + const char* description) + { + assert(value); + m_init(name, + boost::program_options::value(value)->default_value(*value), + description); + return *this; + } + + template + options_description_easy_init& + operator()(const char* name, + T * value, + const T default_value) + { + m_init(name, + boost::program_options::value(value)->default_value(default_value)); + return *this; + } + + template + options_description_easy_init& + operator()(const char* name, + T * value) + { + assert(value); + m_init(name, + boost::program_options::value(value)->default_value(*value)); + return *this; + } + + }; + +}; // Options + +} // detail + + + +class Options { + boost::program_options::options_description m_global; + boost::program_options::options_description m_configuration; + boost::program_options::positional_options_description m_posdesc; + boost::program_options::variables_map m_vm; + +public: + typedef detail::Options::options_description_easy_init initType; + + Options(const char *str = "Program options"); + + initType add_options() { + return initType(m_global.add_options()); + } + + initType add_config_options() { + return initType(m_configuration.add_options()); + } + + void add_positional_option(const char *name, int max_count) { + // TODO: + // m_posdesc(name,max_count); + } + + void parse_command_line(int argc, char *argv[]); + + void parse_config_file(std::string &str); + + void parse_config_file(const char *fname); + + template + static inline boost::program_options::typed_value* value(T *v, T dvalue) { + boost::program_options::typed_value *r = boost::program_options::value(v); + r->default_value(dvalue); + return r; + } + + bool count(const char *str) const; + +}; + + +} // uLib + + + +#endif // U_CORE_OPTIONS_H diff --git a/src/Core/Serializable.cpp b/src/Core/Serializable.cpp new file mode 100644 index 0000000..5efc2ea --- /dev/null +++ b/src/Core/Serializable.cpp @@ -0,0 +1,95 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "boost/archive/polymorphic_xml_oarchive.hpp" +#include "boost/archive/polymorphic_xml_iarchive.hpp" +#include "boost/archive/polymorphic_text_oarchive.hpp" +#include "boost/archive/polymorphic_text_iarchive.hpp" +#include "boost/archive/polymorphic_binary_oarchive.hpp" +#include "boost/archive/polymorphic_binary_iarchive.hpp" + +#include "Serializable.h" + + +using namespace uLib; + + + +//void Serializable::SaveXml(std::ostream &os, const char *name) +//{ +// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_xml_oarchive(os); +// this->Save(*xoa); +// delete xoa; +//} + +//void Serializable::LoadXml(std::istream &is, const char *name) +//{ +// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_xml_iarchive(is); +// this->Load(*xia,this); +// delete xia; +//} + +//void Serializable::SaveText(std::ostream &os, const char *name) +//{ +// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_text_oarchive(os); +// this->Save(*xoa); +// delete xoa; +//} + +//void Serializable::LoadText(std::istream &is, const char *name) +//{ +// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_text_iarchive(is); +// this->Load(*xia,this); +// delete xia; +//} + +//void Serializable::SaveBin(std::ostream &os, const char *name) +//{ +// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_binary_oarchive(os); +// this->Save(*xoa); +// delete xoa; +//} + +//void Serializable::LoadBin(std::istream &is, const char *name) +//{ +// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_binary_iarchive(is); +// Serializable::Load(*xia,this); +// delete xia; +//} + + +//void Serializable::Save(boost::archive::polymorphic_oarchive &ar, Serializable *ob) +//{ +// ar << boost::serialization::make_nvp("Object",ob); +//} + +//void Serializable::Load(boost::archive::polymorphic_iarchive &ar, Serializable *ob) +//{ +// ar >> boost::serialization::make_nvp("Object",ob); +//} + + diff --git a/src/Core/Serializable.h b/src/Core/Serializable.h new file mode 100644 index 0000000..85221ce --- /dev/null +++ b/src/Core/Serializable.h @@ -0,0 +1,412 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_SERIALIZABLE_H +#define U_SERIALIZABLE_H + +/* Serialization: + + + +TODO: +* Problema nella serializzazione delle properties in test_archive +* implementare human readable make_hrp ... non riesco.. + +*/ + + + + +#include +#include + +#include +#include +#include + +//#include +//#include +//#include +//#include +//#include "boost/archive/polymorphic_iarchive.hpp" +//#include "boost/archive/polymorphic_oarchive.hpp" + +#include +#include +#include +#include +#include + + +#include "Core/Mpl.h" +#include "Core/ObjectProps.h" +#include "Core/Archives.h" +#include "Core/Export.h" + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// BOOST SERIALIZATION ADD-ON + +namespace boost { +namespace serialization { + +// ACCESS 2 // +template struct access2 {}; + + +// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------ +template +class hrp : + public wrapper_traits > +{ + const char *m_name; + T *m_value; + std::string *m_str; + +public: + explicit hrp(const char * name_, T &t) : + m_str(new std::string), + m_name(name_), m_value(&t) {} + + const char * name() const { + return this->m_name; + } + + + template + void save( Archivex & ar, const unsigned int /* file_version */) const { + //// ar.operator<<(const_value()); + // std::stringstream ss; + // uLib::Archive::hrt_oarchive har(ss); + // har << make_nvp(m_name,*m_value); + // // (*m_str) = ss.str(); + //// ar.operator << (make_nvp(m_name, ss.str()); + } + template + void load( Archivex & ar, const unsigned int /* file_version */) { +// ar.operator>>(value()); + } + BOOST_SERIALIZATION_SPLIT_MEMBER() +}; + + +template +inline +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING +const +#endif +hrp< T > make_hrp(const char * name, T & t){ + return hrp< T >(name, t); +} + +#define HRP(name) \ + boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name) + + +} // serialization +} // boost + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// ULIB SERIALIZATION + +namespace uLib { + + + +#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem); + +#define NVP(data) BOOST_SERIALIZATION_NVP(data) + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// SERIALIZTION MACROS // + +// !!! WARNING !!! INTRUSIVE SERIALIZATION IS ACTUALLY NOT WORKING FEATURE +// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED + +#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT +# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT +# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__) +# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name) +#else +# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \ + ULIB_CLASS_EXPORT_KEY(_Ob) +# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) +# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__) +# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \ + ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob) +# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__) +# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) +# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name) +# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name) +#endif + + +#define ULIB_SERIALIZE_ACCESS \ + friend class boost::serialization::access; \ + template friend class boost::serialization::access2; + +#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \ + BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) + +#define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \ + BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) \ + BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass::ObjectProps) \ + BOOST_CLASS_EXPORT_KEY(uLib::ObjectPropsImpl<_FullNamespaceClass>) + + +#define _SERIALIZE_IMPL_SEQ \ + (uLib::Archive::text_iarchive) \ + (uLib::Archive::text_oarchive) \ + (uLib::Archive::hrt_iarchive) \ + (uLib::Archive::hrt_oarchive) \ + (uLib::Archive::xml_iarchive) \ + (uLib::Archive::xml_oarchive) \ + (uLib::Archive::log_archive) + + +/** Solving virtual class check problem */ +#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; } +#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data) + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) // + +#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name); + +#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \ + template void Class::serialize(Archive &ar,const unsigned int); + +#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem); + +#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \ + typedef boost::mpl::bool_ serializable; \ + typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \ + void PrintSerializableListId() { boost::mpl::for_each(PrintTypeId()); } \ + template void serialize(ArchiveT &ar,const unsigned int version); \ + template void serialize_parents(ArchiveT &ar,const unsigned int version); \ + template void save_override(ArchiveT &ar,const unsigned int version); + +#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \ + template void _Ob::serialize(ArchiveT &ar, const unsigned int version) { \ + boost::serialization::void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); \ + _Ob::serialize_parents(ar,version); \ + _Ob::save_override(ar,version); }\ + template void _Ob::serialize_parents(ArchiveT &ar, const unsigned int v) { \ + BOOST_PP_SEQ_FOR_EACH(_AR_OP,ar,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); } \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \ + ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \ + namespace boost { \ + namespace serialization { \ + template inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \ + { ::new(o)_Ob(); o->init_parameters(); } }}\ + template void _Ob::save_override(ArchiveT &ar, const unsigned int version) + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// UNINTRUSIVE SERIALIZATION + +#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object(ob)); + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \ + template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i); + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data,elem) + + +// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two +// different implementation + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \ + namespace boost { namespace serialization { \ + template void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \ + template void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \ + template <> struct access2< _Ob > { template static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }} + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \ + namespace boost { namespace serialization { \ + template void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \ + template void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \ + serialize_parents(ar,ob,version); \ + access2< _Ob >::save_override(ar,ob,version); } }}\ + ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\ + template void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version) + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,...) \ + namespace boost { namespace serialization { \ + template void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \ + BOOST_PP_IF(BOOST_PP_VARIADIC_SIZE((__VA_ARGS__)),BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__)));,) } \ + template void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \ + serialize_parents(ar,ob,version); \ + access2< _Ob >::save_override (ar,ob,version); } }}\ + ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ) \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \ + template void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version) + + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \ + namespace boost { namespace serialization { \ + template void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \ + template void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \ + template <> struct access2< _Ob > { template static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \ + template void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \ + template void save_override (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); }} + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \ + namespace boost { namespace serialization { \ + template void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \ + /* PP serialize */ BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); \ + /* MPL serialize */ /*uLib::mpl::for_each<_Ob::BaseList>(uLib::detail::Serializable::serialize_baseobject<_Ob,ArchiveT>(ob,ar) );*/ } \ + template inline void load_construct_data(ArchiveT & ar, _Ob *ob, const unsigned int file_version) { \ + ::new(ob)_Ob(); uLib::detail::ObjectProps::initializer::init_object(ob); } \ + template void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \ + void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); /*fix*/ \ + serialize_parents(ar,ob,version); \ + access2< _Ob >::save_override (ar,ob,version); } }}\ + ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\ + template void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version) + +#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) \ + namespace boost { namespace serialization { \ + template void serialize (ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) { \ + save_override (ar,ob,version); } }}\ + BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob::ObjectProps,_SERIALIZE_IMPL_SEQ)\ + ULIB_CLASS_EXPORT_IMPLEMENT(_Ob::ObjectProps) \ + ULIB_CLASS_EXPORT_IMPLEMENT(uLib::ObjectPropsImpl<_Ob>) \ + template void boost::serialization::save_override(ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) + + +#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name),ob.name) + + + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + + +namespace detail { + +struct Serializable { + + /** + * Serializable trait to check if an object type is serializable. + * This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive + * cases a has_serialize trait should be implemented + */ + template + struct serializable_trait : mpl::bool_ {}; + + /** + * IsA Serializable Implementation Template + */ + template + struct IsA : serializable_trait {}; + + template + struct serialize_baseobject { + ThisClass & m_object; + Archive & m_ar; + serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {} + template void operator()(T &o) { + m_ar & boost::serialization::make_nvp( + typeid(T).name() , + boost::serialization::base_object(m_object)); + } + }; + + +}; + + +} // detail + + + + + +struct Serializable { + friend class boost::serialization::access; + template friend class boost::serialization::access2; + virtual ~Serializable() {} +protected: +}; + + + + + +} // uLib + + + + + + +#endif // U_SERIALIZABLE_H diff --git a/src/Core/Signal.cpp b/src/Core/Signal.cpp new file mode 100644 index 0000000..f99873b --- /dev/null +++ b/src/Core/Signal.cpp @@ -0,0 +1,28 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + diff --git a/src/Core/Signal.h b/src/Core/Signal.h new file mode 100644 index 0000000..624dd49 --- /dev/null +++ b/src/Core/Signal.h @@ -0,0 +1,168 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_SIGNAL_H +#define U_CORE_SIGNAL_H + +#include + +#include +#include +#include + +#include "Function.h" + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Signals macro // + +#define default(vlaue) +#define slots +#define signals /*virtual void init_signals();*/ public +#define emit +#define SLOT(a) BOOST_STRINGIZE(a) +#define SIGNAL(a) BOOST_STRINGIZE(a) + +#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \ + static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \ + sig->operator()(__VA_ARGS__); + +/** + * Utility macro to implement signal emission implementa una delle seguenti: + * + * // metodo standard con cast // + * SignalBase * sig = this->findSignal((void (Ob1::*)(void))&Ob1::V0); + * typedef Signal::type SigT; + * if(sig) reinterpret_cast(sig)->operator()(); + * + * // cast automatico // + * static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0)); + * sig->operator()(); +*/ +#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__) + + +namespace uLib { + + +// A boost::signal wrapper structure /////////////////////////////////////////// + +// TODO ... + +typedef boost::signals2::signal_base SignalBase; + +template +struct Signal { + typedef boost::signals2::signal type; +}; + + + +//////////////////////////////////////////////////////////////////////////////// + + +namespace detail { + + +template +struct ConnectSignal {}; + +template +struct ConnectSignal< FuncT, 0 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(slof); + } +}; + +template +struct ConnectSignal< FuncT, 1 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof,receiver)); + } +}; + +template +struct ConnectSignal< FuncT, 2 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1)); + } +}; + +template +struct ConnectSignal< FuncT, 3 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2)); + } +}; + +template +struct ConnectSignal< FuncT, 4 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3)); + } +}; + +template +struct ConnectSignal< FuncT, 5 > { + static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) { + typedef typename Signal::SignalSignature>::type SigT; + reinterpret_cast(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4)); + } +}; + + +} // detail + + + +template +SignalBase *NewSignal(FuncT f) { + // seems to work wow ! + return new Signal::type; +} + +template +void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer::Object *receiver) +{ + detail::ConnectSignal< FuncT, FunctionPointer::arity >::connect(sigb,slof,receiver); +} + + + + +} // uLib + +#endif // SIGNAL_H diff --git a/src/Core/Singleton.h b/src/Core/Singleton.h new file mode 100644 index 0000000..be50548 --- /dev/null +++ b/src/Core/Singleton.h @@ -0,0 +1,46 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_SINGLETON_H +#define U_CORE_SINGLETON_H + +#include + + +namespace uLib { + +template +struct Singleton : boost::serialization::singleton { + +}; + + +} + + + +#endif // SINGLETON_H diff --git a/src/Core/SmartPointer.h b/src/Core/SmartPointer.h new file mode 100644 index 0000000..ac49cda --- /dev/null +++ b/src/Core/SmartPointer.h @@ -0,0 +1,111 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_SMARTPOINTER_H +#define U_CORE_SMARTPOINTER_H + + +namespace uLib { + +template +class SmartPointer { + typedef T element_type; +public: + + explicit + SmartPointer(T* ptr = NULL) : m_counter(0) { + if(!ptr) ptr = new T; + if (ptr) m_counter = new ReferenceCounter(ptr); + } + + // TakeReference // + SmartPointer(T &ref) : m_counter(new ReferenceCounter(&ref,0)) { } + + SmartPointer(const SmartPointer& copy) throw () { + acquire(copy.m_counter); + } + + SmartPointer(SmartPointer * copy) throw () { + acquire(copy->m_counter); + } + + virtual ~SmartPointer() { release(); } + + SmartPointer & operator=(const SmartPointer& copy) { + if (this != ©) + { + release(); + acquire(copy.m_counter); + } + return *this; + } + + T & operator*() const throw () { return *m_counter->ptr; } + T * operator->() const throw () { return m_counter->ptr; } + + T * get() const throw () { + return m_counter ? m_counter->ptr : 0; } + bool unique() const throw () { + return (m_counter ? m_counter->count == 1 : true); } + + + private: + + struct ReferenceCounter + { + ReferenceCounter(T* ptr = 0, unsigned c = 1) : ptr(ptr), count(c) { } + T* ptr; + unsigned count; + } * m_counter; + + // increment the count + void acquire(ReferenceCounter* c) throw () + { + m_counter = c; + if (c && c->count>0) ++c->count; + } + + // decrement the count, delete if it is 0 + void release() { + if (m_counter) { + if (--m_counter->count == 0) { + delete m_counter->ptr; + } + if (m_counter->count <= 0) { + delete m_counter; + m_counter = NULL; + } + } + } + +}; + + + +} + +#endif // SMARTPOINTER_H diff --git a/src/Core/StaticInterface.h b/src/Core/StaticInterface.h new file mode 100644 index 0000000..cb26039 --- /dev/null +++ b/src/Core/StaticInterface.h @@ -0,0 +1,77 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_STATICINTERFACE_H +#define U_CORE_STATICINTERFACE_H + +namespace uLib { + +#define MAKE_TRAITS ; // TODO + +#define uLibCheckFunction(class_name,name,out, ... ) \ +{ out (class_name::*x)(__VA_ARGS__) = &class_name::name; (void) x; } + +#define uLibCheckConstFunction(class_name,name,out,...) \ +{ out (class_name::*x)(__VA_ARGS__) const = &class_name::name; (void) x; } + +#define uLibCheckMember(class_name,name,type) \ +{ class_name x; type *y = &x.name; (void) y; } + + +namespace Interface { + +// EXAMPLE : +//template struct Voxel { +// MAKE_TRAITS; +// template void check_structural() { +// { float & (Self::*x)() = &Self::Density; (void) x; } +// { int & (Self::*x)() = &Self::TrackCount; (void) x; } +// } +//protected: +// ~Voxel() {} +//}; + +template +static inline void IsA() { + (void) ((void (SI::*)()) &SI::template check_structural); +} + +// not working +//template +//struct StaticIsA { +// void test() { +// static const void (SI::*x)() = SI::template check_structural; +// } +//}; + +} + + + +} + +#endif // STATICINTERFACE_H diff --git a/src/Core/StringReader.h b/src/Core/StringReader.h new file mode 100644 index 0000000..3b7aa6c --- /dev/null +++ b/src/Core/StringReader.h @@ -0,0 +1,94 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_STRINGREADER_H +#define U_CORE_STRINGREADER_H + +#include +#include + +#include "Core/Vector.h" +#include +#include + + +// RIPENSARE COMPLETAMENTE !!! + +namespace uLib { + +struct StringReader { + + std::istream & m_is; + + StringReader(std::istream &is) : m_is(is) {} + + void ReadString(const char *str) { + // // clean compared string // + // char chars[] = " \t\n"; + // for (unsigned int i = 0; i < strlen(chars); ++i) + // { cmps.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); } + + // SISTEMARE !!! + + int pos = 0; + char c; + while( pos < strlen(str) ) { + while( IsEscape(str[pos])) pos++; + if ( pos >= strlen(str) ) break; + while( IsEscape(c = m_is.get()) ); + if (c == str[pos] ) pos++; + else pos = 0; + } + } + + static inline bool IsEscape(char c){ + const char *escapes = " \r\n\t"; + for ( int i = 0 ; i < 4 ; ++i) { + if(c == escapes[i]) return true; + } + return false; + } + +}; + +template +inline StringReader & operator >> (StringReader &isr, T &t) { + isr.m_is >> t; + return isr; +} + +inline StringReader & operator >> (StringReader &isr, const char *str) { + isr.ReadString(str); + return isr; +} + + + +} // uLib + + +#endif // STRINGREADER_H diff --git a/src/Core/Timer.h b/src/Core/Timer.h new file mode 100644 index 0000000..aa2485f --- /dev/null +++ b/src/Core/Timer.h @@ -0,0 +1,28 @@ +#ifndef TIMER_H +#define TIMER_H + +#include + + +//////////////////////////////////////////////////////////////////////////////// +// Timer ///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +class Timer +{ +public: + void Start() { gettimeofday(&m_start, NULL); } + + double StopWatch() { + gettimeofday(&m_end, NULL); + double timeSec = m_end.tv_sec - m_start.tv_sec + + (m_end.tv_usec - m_start.tv_usec)*1E-6; + return timeSec; + } + +private: + struct timeval m_start, m_end; +}; + + +#endif // TIMER_H diff --git a/src/Core/Types.h b/src/Core/Types.h new file mode 100644 index 0000000..e2782d2 --- /dev/null +++ b/src/Core/Types.h @@ -0,0 +1,276 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_TYPES_H +#define U_CORE_TYPES_H + +#include +#include + +#include + +#include + +#include "Core/Macros.h" +#include "Core/Mpl.h" + + + + + + + +namespace uLib { + + +//////////////////////////////////////////////////////////////////////////////// + +namespace detail { + +struct TypeIntrospection { + + // BOOST IMPL // + BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info) + + // SFINAE IMPL // + /* + template + struct has_type_info { + typedef char yes[1]; + typedef char no[2]; + template static yes& test(typename U::type_info::BaseList*); + template static no& test(...); + // struct apply { + static const bool value = sizeof(test(0)) == sizeof(yes); + typedef boost::mpl::bool_ type; + // }; + }; + */ + + /** IsA Introspectable Object Implementation Template */ + template + struct IsIntrospectable : has_type_info {}; + + template struct access { + typedef typename T::type_info type_info; + }; + + template + struct child_first_impl { + + template + struct lambda_CFList_f { + typedef mpl::vector type; + }; + + template + struct lambda_CFList_f { + // typedef typename T1::type_info::CFList type; + typedef typename access::type_info::CFList type; + }; + + template + struct lambda_CFList : lambda_CFList_f::value> {}; + + /** Transforms all Base Type into proper CFList */ + typedef typename mpl::transform_view < typename access::type_info::BaseList + , lambda_CFList + >::type CFListSeq; + + /** Folds each CFList into a new sequence */ + typedef typename mpl::fold< CFListSeq + , mpl::vector<> + , mpl::copy< mpl::_1 + , mpl::back_inserter + > + >::type Childs; + + /** Add This Class to final CFList sequence */ + typedef typename mpl::copy< Childs + , mpl::back_inserter< mpl::vector > + >::type type; + }; + + + /** + * Tests if T has a member called type_info then compile type CFList + */ + template + struct child_first : mpl::if_< has_type_info + , child_first_impl + , mpl::vector<> + >::type {}; + + +}; + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// TYPE ADAPTERS // FINIRE !!! + +//#define _REPETITION_V(vz,vn,vdata) + + +//template < class TypeList > +//class TypeAdapterInputInterface { +// virtual ~TypeAdapterInputInterface() {} +//public: + + + +// virtual void operator()(int val) {} +// virtual void operator()(std::string val) {} +//}; + + + + + + + +} // detail //////////////////////////////////////////////////////////////////// + + +#define CONSTEXPR BOOST_CONSTEXPR + + +typedef ltk::Real_t Real_t; +typedef ltk::Id_t Id_t; +//typedef ltk::Size_t Size_t; +typedef ltk::Pointer_t Pointer_t; +typedef bool Bool_t; //Boolean (0=false, 1=true) (bool) + +//--- bit manipulation --------------------------------------------------------- +#ifndef BIT +#define BIT(n) (1ULL << (n)) +#endif + +#ifndef SETBIT +#define SETBIT(n,i) ((n) |= BIT(i)) +#endif + +#ifndef CLRBIT +#define CLRBIT(n,i) ((n) &= ~BIT(i)) +#endif + +#ifndef TESTBIT +#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0)) +#endif + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// TYPE INTROSPECTION FOR OBJECTS // + + + +#define uLibTypeMacro(thisClass,...) \ + \ + /* Friendship detail for accessing introspection */ \ + template friend class uLib::detail::TypeIntrospection::access; \ + \ + /* type info structure*/ public: \ + /* in GCC 4.8 must be public or dynamic_cast wont work */ \ + struct type_info { \ + /*WARNING: -std=c++0x required for this! */ \ + constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \ + typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \ + typedef thisClass ThisClass; \ + typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \ + typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \ + typedef uLib::detail::TypeIntrospection::child_first::type CFList; \ + }; \ + \ + public: \ + typedef type_info::BaseClass BaseClass; \ + virtual const char *type_name() const { return type_info::name; } \ + /* Object Props fwd declaration*/ \ + struct ObjectProps; \ + /**/ + + +/** + * TypeList inheritance introspection + */ +struct TypeIntrospection { + template + struct child_first : detail::TypeIntrospection::child_first {}; + +}; + + + + + + +// SISTEMARE // +struct PrintTypeId { + template + void operator()(T) const + { std::cout << typeid(T).name() << std::endl; } + + template + static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each(PrintTypeId()); } + + template + static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; } +}; + + + + + + + +} // uLib + +#endif // U_CORE_TYPES_H + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Core/Uuid.cpp b/src/Core/Uuid.cpp new file mode 100644 index 0000000..0270de8 --- /dev/null +++ b/src/Core/Uuid.cpp @@ -0,0 +1,45 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "Uuid.h" +#include "Singleton.h" + +using namespace uLib; + +uLib::uuid_t uLib::uLib_dns_uuid; +TypeRegister* TypeRegister::s_Instance = new TypeRegister(); + +TypeRegister::TypeRegister() : + BaseClass(uLib_dns_uuid) +{} + +TypeRegister * TypeRegister::Controller() { + return TypeRegister::s_Instance; +} + + + diff --git a/src/Core/Uuid.h b/src/Core/Uuid.h new file mode 100644 index 0000000..4787655 --- /dev/null +++ b/src/Core/Uuid.h @@ -0,0 +1,163 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_UUID_H +#define U_CORE_UUID_H + +#include + +#include +#include +#include +#include + +#include "Core/Mpl.h" +#include "Core/Vector.h" +#include "Core/Object.h" + + +namespace uLib { + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Object Registration // + + +typedef boost::uuids::uuid uuid_t; + +extern uuid_t uLib_dns_uuid; + +template < typename T > +class type_id : public boost::uuids::uuid { +public: + type_id() : + m_size(sizeof(T)), + uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name())) + { + std::cout << "Request for register new type\n" << + "name: " << typeid(T).name() << "\n" << + "uuid: " << to_string(*this) << "\n"; + } + + explicit type_id(boost::uuids::uuid const& u) + : boost::uuids::uuid(u) {} + + operator boost::uuids::uuid() { + return static_cast(*this); + } + + operator boost::uuids::uuid() const { + return static_cast(*this); + } + + unsigned int size() const { return m_size; } + +private: + unsigned int m_size; +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// TYPE REGISTER // + +namespace detail { + +class TypeRegister { + typedef boost::uuids::name_generator IDGen_t; +public: + struct RegisterEntry { + uuid_t id; + int size; + }; + + TypeRegister(uuid_t const &dns) : + gen(dns) {} + + + template< typename T > + RegisterEntry * AddType(T *t = NULL) { + RegisterEntry en = { gen(typeid(T).name()), sizeof(T) }; + for(int i=0; i < m_registry.size(); ++i) + if(en.id == m_registry[i].id) return &(m_registry[i]); + m_registry.push_back(en); + return &m_registry.back(); + } + + void PrintSelf(std::ostream &o) { + std::cout << "RegisterController: \n"; + for (int i=0; i m_registry; + +}; + +} // detail + + + + +class TypeRegister : public detail::TypeRegister { +public: + typedef detail::TypeRegister BaseClass; + typedef detail::TypeRegister::RegisterEntry Entry; + + static TypeRegister* Controller(); + +private: + TypeRegister(); // Blocks constructor + static TypeRegister *s_Instance; // Singleton instance +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// OBJECT REGISTER // + + + +} // uLib + +#endif // UUID_H diff --git a/src/Core/Vector.h b/src/Core/Vector.h new file mode 100644 index 0000000..04d6342 --- /dev/null +++ b/src/Core/Vector.h @@ -0,0 +1,178 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_VECTOR_H +#define U_CORE_VECTOR_H + +#include +#include + +#include +#include +#include + + +namespace uLib { + +// Vector Implemetation ... wraps std::vector +template +class Vector : public std::vector > +{ + typedef std::vector< T,std::allocator > BaseClass; + typedef std::allocator Allocator; +public: + typedef T TypeData; + typedef __gnu_cxx::__normal_iterator Iterator; + typedef __gnu_cxx::__normal_iterator ConstIterator; + + typedef CommaInitializer< Vector , T > VectorCommaInit; + + Vector(unsigned int size) : BaseClass(size) {} + Vector(unsigned int size, T &value) : BaseClass(size,value) {} + Vector() : BaseClass(0) {} + + inline VectorCommaInit operator <<(T scalar) { + return VectorCommaInit(this, scalar); + } + + inline void PrintSelf(std::ostream &o); + + void remove_element(unsigned int index) { + std::swap(this->at(index),this->back()); + this->pop_back(); + } + + void remove_element(T &t) { + std::swap(t, this->back()); + this->pop_back(); + } + +}; + +template +void Vector::PrintSelf(std::ostream &o) +{ + o << " *** uLib Vector *** \n"; + o << " n. of items = " << this->size() << "\n"; + for(int i=0; i< this->size(); ++i) + o << (T)this->at(i) << " "; + o << "\n"; +} + +template +std::ostream & operator << (std::ostream &o, const Vector &v) { + for(int i=0; i< v.size(); ++i) + o << (T)v.at(i) << " "; + o << "\n"; + return o; +} + +template +std::ofstream & operator << (std::ofstream &o, const Vector &v) { + for(int i=0; i< v.size(); ++i) + o << (T)v.at(i) << " "; + return o; +} + + +template < typename T > +std::istream & operator >> (std::istream &is, Vector &v) { + T value; + while( is >> value ) { + if(is.fail()) v.push_back(0); + else v.push_back( value ); + } + return is; +} + + + +// Smart pointer Vector Implementation // + + +template +class SmartVector : public SmartPointer< Vector > { + typedef SmartPointer< Vector > Base; +public: + + SmartVector() : Base(new Vector()) { } + SmartVector( const SmartVector ©) : Base(copy) { } + SmartVector(unsigned int size) : Base(new Vector((int)size)) { } + + virtual ~SmartVector() {} + + T& operator[](int p) { + return Base::get()->at(p); + } + + void swap_elements(unsigned int first, unsigned int second) { + std::swap(Base::get()->at(first),Base::get()->at(second)); + } + + void remove_element(unsigned int index) { + std::swap(Base::get()->at(index),Base::get()->back()); + Base::get()->pop_back(); + } + + void remove_element(T &t) { + std::swap(t, Base::get()->back()); + Base::get()->pop_back(); + } +}; + + + + +// ------ Utils ------------------------------------------------------------- // + + + +// RIFARE con iteratore ! +template +inline const unsigned long +VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp) +{ + _Tp it = _it; + _Tp end = _end-1; + for(it; it != end;) + { + if (_comp(*it,value)) ++it; + else if(_comp(*end,value)) std::swap(*it,*end--); + else --end; + } + return it - _it; +} + + + +} // uLib + + + + + +#endif // VECTOR_H diff --git a/src/Core/testing/BoostAccumulatorTest.cpp b/src/Core/testing/BoostAccumulatorTest.cpp new file mode 100644 index 0000000..fabf75a --- /dev/null +++ b/src/Core/testing/BoostAccumulatorTest.cpp @@ -0,0 +1,88 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include +#include +#include +#include +#include +#include + + +#include "testing-prototype.h" + +using namespace boost::accumulators; + +using namespace boost; +using namespace boost::accumulators; + +typedef accumulator_set > acc; +typedef iterator_range >::iterator > histogram_type; + +template +class data_filler +{ +public: + data_filler(){} + T operator()() { return rand()/(T)RAND_MAX; } +}; + + +int main(int argc, char** argv) +{ + + //create some random data + std::vector data(100); + std::generate(data.begin(), data.end(), data_filler()); + int c = data.size();//cache size for histogramm. + + //create an accumulator + acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10); + + //fill accumulator + for (int j = 0; j < c; ++j) + { + myAccumulator(data[j]); + } + + histogram_type hist = density(myAccumulator); + + double total = 0.0; + + for( int i = 0; i < hist.size(); i++ ) + { + std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl; + total += hist[i].second; + } + + std::cout << "Total: " << total << std::endl; //should be 1 (and it is) + + return 0; +} diff --git a/src/Core/testing/BoostTest.cpp b/src/Core/testing/BoostTest.cpp new file mode 100644 index 0000000..d22aa12 --- /dev/null +++ b/src/Core/testing/BoostTest.cpp @@ -0,0 +1,64 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include + +#include "Core/Object.h" +#include "Core/Options.h" + +#include "Core/Singleton.h" + +#include "testing-prototype.h" + +using namespace uLib; + + +struct A : Object { + A() : a(0) {} + int a; +}; + + +int main(int argc, char **argv) +{ + BEGIN_TESTING(Boost Mock); + + A &a = Singleton::get_mutable_instance(); + a.a = 5552368; + + const A &aa = Singleton::get_const_instance(); + + std::cout << a.a << "\n"; + std::cout << aa.a << "\n"; + + TEST1( a.a == 5552368 ); + TEST1( aa.a == 5552368 ); + + END_TESTING; +} diff --git a/src/Core/testing/CMakeLists.txt b/src/Core/testing/CMakeLists.txt new file mode 100644 index 0000000..a9ae42a --- /dev/null +++ b/src/Core/testing/CMakeLists.txt @@ -0,0 +1,33 @@ + +# TESTS +set( TESTS + SmartVectorTest + VectorTest + ObjectFlagsTest + ObjectParametersTest + ObjectCopyTest + StaticInterfaceTest + CommaInitTest + DebugTTreeDumpTest + BoostTest + BoostAccumulatorTest + PropertiesTest + SignalTest + SerializeTest + SerializeDreadDiamondTest + DreadDiamondParameters + ObjectPropableTest + UuidTest + TypeIntrospectionTraversal + OptionsTest +) + +set(LIBRARIES + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${ROOT_LIBRARIES} +) +uLib_add_tests(${uLib-module}) diff --git a/src/Core/testing/CommaInitTest.cpp b/src/Core/testing/CommaInitTest.cpp new file mode 100755 index 0000000..a23f265 --- /dev/null +++ b/src/Core/testing/CommaInitTest.cpp @@ -0,0 +1,57 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include "testing-prototype.h" +#include "Core/Vector.h" + +#include + +#define test_print(file,str,...) \ + printf(str,__VA_ARGS__) + +using namespace uLib; + +int main() +{ + BEGIN_TESTING( Comma Init ); + + Vector test; + + test << 1,2,3,4,5; + + test.PrintSelf(std::cout); + + + test_print(stdout,"ciao %d \n",5); + + printf("ciao\n"); + + END_TESTING; +} diff --git a/src/Core/testing/DebugTTreeDumpTest.cpp b/src/Core/testing/DebugTTreeDumpTest.cpp new file mode 100644 index 0000000..c40b75d --- /dev/null +++ b/src/Core/testing/DebugTTreeDumpTest.cpp @@ -0,0 +1,118 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include "testing-prototype.h" +#include "Core/Debug.h" + +#include +#include +#include + +#include +#include +#include + + +#include +#include +#include +#include +#include +#include + +using namespace uLib; + + + +class DebugAdapterTTree : public detail::DebugAdapterInterface { + TTree *m_tree; +public: + + DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {} + ~DebugAdapterTTree() { delete m_tree; } + + void operator()(int val) { + std::cout << "debugger 2 prints: " << val << "\n"; + } +}; + + + + +int main(int argc, char **argv) +{ + + { + Debug debug; + DebugAdapterText adapter(std::cout); + DebugAdapterTTree treead("test"); + + debug.AddAdapter(adapter); + debug.AddAdapter(treead); + + int a = 5552368; + debug("a",a); + + std::string str = "ciao"; + debug("str",str); + + debug.Update(); + } + + + // TestTObject *test = new TestTObject; + + + TFile *file = new TFile("test_file.root","RECREATE"); + file->cd(); + TTree *tree = new TTree; +// tree->Branch("test",&test); + +// for(int i=0;i<10;++i) { +// test->a = i; +// test->b = -i; +// tree->Fill(); +// } + tree->Write(); + + gApplication = new TApplication("My ROOT Application", &argc, argv); + TBrowser *tbr = new TBrowser("test"); + tbr->Show(); + + + gApplication->Run(); + + return 0; +} + + + + + diff --git a/src/Core/testing/DreadDiamondParameters.cpp b/src/Core/testing/DreadDiamondParameters.cpp new file mode 100644 index 0000000..fa1b3fe --- /dev/null +++ b/src/Core/testing/DreadDiamondParameters.cpp @@ -0,0 +1,80 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include +#include +#include + + + +#include "boost/archive/xml_oarchive.hpp" +#include "boost/archive/xml_iarchive.hpp" + +#include "testing-prototype.h" + +#include "Core/Object.h" +#include "Math/Dense.h" +#include "Core/Mpl.h" + + +using namespace uLib; + + +////////////////////////////////////////////////////////////////////////////// + + +int main() { + + + + +} + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Core/testing/Flags.h b/src/Core/testing/Flags.h new file mode 100644 index 0000000..f6a8d1b --- /dev/null +++ b/src/Core/testing/Flags.h @@ -0,0 +1,76 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CORE_FLAGS_H +#define U_CORE_FLAGS_H + +namespace uLib { + +template class Flags +{ + T i; +public: + typedef T EnumT; + + inline Flags(const Flags &f) : i(f.i) {} + inline Flags() : i((T)0) {} + inline Flags(T f) : i(f) {} + + inline Flags &operator=(const Flags &f) { i = f.i; return *this; } + inline Flags &operator&=(T mask) { i &= mask; return *this; } + + inline Flags &operator|=(const Flags f) { i |= f.i; return *this; } + inline Flags &operator|=(const T f) { i |= f; return *this; } + inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; } + inline Flags &operator^=(const T f) { i ^= f; return *this; } + + inline Flags operator|(const Flags f) const { return Flags(i | f.i); } + inline Flags operator|(const T f) const { return Flags(i | f); } + inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); } + inline Flags operator^(const T f) const { return Flags(i ^ f); } + inline Flags operator&(const Flags f) const { return Flags(i & f.i); } + inline Flags operator&(const T f) const { return Flags(i & f); } + inline Flags operator~() const { return Flags(~i); } + + inline bool operator !() const { return !i; } + inline bool testFlag(const T f) const + { return (i & f) == f && (f != 0 || i == f ); } + // inline bool operator==(const T f) const { return i==f; } + + inline T operator()() { return i; } + inline operator T() const { return i; } +}; + + +typedef Flags Flags2B; +typedef Flags Flags4B; +typedef Flags Flags8B; + +} // uLib + + +#endif // FLAGS_H diff --git a/src/Core/testing/Makefile.am b/src/Core/testing/Makefile.am new file mode 100644 index 0000000..882b9fd --- /dev/null +++ b/src/Core/testing/Makefile.am @@ -0,0 +1,38 @@ +include $(top_srcdir)/Common.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + +# if HAVE_CHECK +TESTS = SmartPointerTest \ + SmartVectorTest \ + VectorTest \ + ObjectFlagsTest \ + ObjectParametersTest \ + ObjectCopyTest \ + StaticInterfaceTest \ + CommaInitTest \ + DebugTTreeDumpTest \ + BoostTest \ + BoostAccumulatorTest \ + PropertiesTest \ + SignalTest \ + SerializeTest \ + SerializeDreadDiamondTest \ + DreadDiamondParameters \ + ObjectPropableTest \ + TypeIntrospectionTraversal \ + OptionsTest + +# UuidTest + +# else +# TEST = +# endif + +LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT) + +check_PROGRAMS = $(TESTS) + + +all: $(TESTS) + diff --git a/src/Core/testing/ObjectCopyTest.cpp b/src/Core/testing/ObjectCopyTest.cpp new file mode 100644 index 0000000..5e1ddc9 --- /dev/null +++ b/src/Core/testing/ObjectCopyTest.cpp @@ -0,0 +1,50 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include + +#include "testing-prototype.h" +#include "Core/Types.h" +#include "Core/Object.h" + + +using namespace uLib; + + + + +int main() +{ + BEGIN_TESTING(ObjectParameters); + + + + + END_TESTING; +} diff --git a/src/Core/testing/ObjectFlagsTest.cpp b/src/Core/testing/ObjectFlagsTest.cpp new file mode 100644 index 0000000..58c1b3c --- /dev/null +++ b/src/Core/testing/ObjectFlagsTest.cpp @@ -0,0 +1,69 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" +#include "Core/Object.h" + + +using namespace uLib; + + +//class Derived : public uLib::Object { +//public: +// Derived(int flags) : uLib::Object(flags) {} +// enum Flags { +// a = 1<<0, // 1 +// b = 1<<1, // 2 +// c = 1<<2 // 4 +// }; +//}; + + + + + +int main() { + BEGIN_TESTING(ObjectFlags); + +// Object o(2); +// o.flags() = 4; +// o.flags() |= 1; +// TEST1( o.flags() == 5); +// o.flags() &= 1; +// TEST1( o.flags() == 1); +// TEST1( o.flags().testFlag(1) ); + +// Derived d( Derived::a | Derived::b); +// d.flags() = Derived::c; +// d.flags() |= Derived::a; +// TEST1( d.flags() == Derived::a | Derived::c); +// d.flags() &= 1; +// TEST1( d.flags() == Derived::a); +// TEST1( d.flags().testFlag(Derived::a) ); + + END_TESTING +} diff --git a/src/Core/testing/ObjectParametersTest.cpp b/src/Core/testing/ObjectParametersTest.cpp new file mode 100644 index 0000000..5a5cc4d --- /dev/null +++ b/src/Core/testing/ObjectParametersTest.cpp @@ -0,0 +1,61 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include +#include +#include + +#include "boost/archive/xml_oarchive.hpp" +#include "boost/archive/xml_iarchive.hpp" + +#include "Core/Object.h" +#include "Math/Dense.h" + +#include "testing-prototype.h" + + + + +using namespace uLib; + + + + +int main() { + +} + + + + + + + + + diff --git a/src/Core/testing/ObjectPropableTest.cpp b/src/Core/testing/ObjectPropableTest.cpp new file mode 100644 index 0000000..9e319db --- /dev/null +++ b/src/Core/testing/ObjectPropableTest.cpp @@ -0,0 +1,237 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include +#include +#include + + +#include "Core/Types.h" +#include "Core/Object.h" +#include "Core/ObjectProps.h" +#include "Core/StringReader.h" +#include "Math/Dense.h" + +#include "boost/archive/text_oarchive.hpp" +#include "boost/archive/text_iarchive.hpp" + + +#include "testing-prototype.h" + + + + +using namespace uLib; + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// STRUCTURES // + + +struct A : virtual Object { + + uLibTypeMacro(A, Object) + + properties() { + int p_a; + Vector3f p_3f; + }; + + int m_a; +}; + +void A::init_properties() { + $_init(); + $$.p_a = 0; + $$.p_3f << 1,2,3; +} + +ULIB_SERIALIZABLE_OBJECT(A) +ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); } +ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); } + + + + +struct B : A { + uLibTypeMacro(B,A) + + properties() { + std::string p; + }; + + B() : m_b(324) {} + + int m_b; +}; + + +void B::init_properties() { + $_init(); + $$.p = "ciao"; +} + +ULIB_SERIALIZABLE_OBJECT(B) +ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); } +ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); } + + + +struct C { + int m_c; + std::string m_str; +}; + +ULIB_SERIALIZABLE(C) +ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); } + + + +struct D : virtual Object, B { + uLibTypeMacro(D,Object,B) + + properties() { + C p_c; + }; +}; + +void D::init_properties() { + $_init(); + $$.p_c.m_c = 1234; +} + +ULIB_SERIALIZABLE_OBJECT(D) +ULIB_SERIALIZE_OBJECT(D,Object) {} +ULIB_SERIALIZE_OBJECT_PROPS(D) { + ar & AR(p_c); +} + + + +class E : public C, public D { + uLibTypeMacro(E,D,C) +public: + E() : m_Ea(5552368) {} + int m_Ea; +}; + +ULIB_SERIALIZABLE_OBJECT(E) +ULIB_SERIALIZE_OBJECT(E,C,D) { + ar & AR(m_Ea); +} + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// TESTS // + + +int test_xml_direct() { + // TEST ARCHIVE SAVE AND LOAD direct // + E o; o.init_properties(); + o.$$.p_c.m_str = "works"; + { + std::ofstream file("test.xml"); + Archive::xml_oarchive ar(file); + ar << NVP(o); + } + o.$$.p_c.m_str = "hola"; + { + std::ifstream file("test.xml"); + Archive::xml_iarchive ar(file); + ar >> NVP(o); + } + std::cout << o.$$.p_c.m_str << "\n"; + return ( o.$$.p_c.m_str == "works" ); +} + + +int test_xml_pointer() { + // TEST ARCHIVE SAVE AND LOAD from pointer // + E *o = new E; o->init_properties(); + o->$$.p_c.m_str = "works"; + { + std::ofstream file("test.xml"); + Archive::xml_oarchive ar(file); + ar << NVP(o); + } + o->$$.p_c.m_str = "hola"; + { + std::ifstream file("test.xml"); + Archive::xml_iarchive ar(file); + ar >> NVP(o); + } + std::cout << o->$$.p_c.m_str << "\n"; + return ( o->$$.p_c.m_str == "works" ); +} + + +int test_xml_objsave() { + // TEST SELF SAVE + E o; o.init_properties(); + o.$(B).p = "works"; + { + std::ofstream file("test.xml"); + Object::SaveXml(file,o); + } + o.$(B).p = "hola"; + { + std::ifstream file("test.xml"); + Object::LoadXml(file,o); + } + + std::cout << o.$(B).p << "\n"; + return ( o.$(B).p == "works" ); +} + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// MAIN // + +int main() +{ + BEGIN_TESTING(PropableTest); + + TEST1( test_xml_direct() ); + TEST1( test_xml_pointer() ); + TEST1( test_xml_objsave() ); + + END_TESTING; +} + + diff --git a/src/Core/testing/OptionsTest.cpp b/src/Core/testing/OptionsTest.cpp new file mode 100644 index 0000000..5463ae7 --- /dev/null +++ b/src/Core/testing/OptionsTest.cpp @@ -0,0 +1,72 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include + + + +#include "Core/Object.h" +#include "Core/Options.h" +#include "testing-prototype.h" + + +using namespace uLib; + + + + +int main(int argc, char **argv) +{ + BEGIN_TESTING(Boost ProgramOptions); + + + std::string optfile("configuration.ini"); + int a = 0; + int b = 0; + Options opt; + + opt.add_options() + ("help", "printout help") + ("value",&a,"value") + ("config",&optfile,"config_file"); + + opt.add_config_options() + ("B.value",&b,"b vlaue"); + + opt.parse_command_line(argc,argv); + opt.parse_config_file(optfile.c_str()); + + std::cout << "a = " << a << "\n"; + std::cout << "b = " << b << "\n"; + + + END_TESTING; +} + + diff --git a/src/Core/testing/PropertiesTest.cpp b/src/Core/testing/PropertiesTest.cpp new file mode 100644 index 0000000..23e4c4e --- /dev/null +++ b/src/Core/testing/PropertiesTest.cpp @@ -0,0 +1,96 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include + + +#include "Core/Object.h" +#include "testing-prototype.h" + +#define emit + + + + +template +class property +{ + typedef boost::signals2::signal& )> signal_t; + +public: + property() : m_changed(new signal_t) {} + property(const T in) : value(in) , m_changed(new signal_t) {} + + inline operator T const & () const { return value; } + inline operator T & () { return value; } + inline T & operator = (const T &i) { value = i; return value; } + template T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only. + inline signal_t & valueChanged() { return *m_changed; } + +private: + T value; + boost::shared_ptr m_changed; +}; + + +//template +//class property { +// typedef boost::signals2::signal signal_t; + +//public: +// property() : m_changed() {} +// property(const T in) : value(in) , m_changed() {} + +// inline operator T const & () const { return value; } +// inline operator T & () { valueChanged()(value); return value; } +// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; } +// template T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only. +// inline signal_t &valueChanged() { return m_changed; } + +//private: +// property(const property &); +// property &operator = (const property&); + +// T value; +// signal_t m_changed; +//}; + +// test generic void function slot // +void PrintSlot(const property &i) { std::cout << "slot called, new value = " << i << "!\n"; } + + + + + +int main() +{ + + +} diff --git a/src/Core/testing/SerializeDreadDiamondTest.cpp b/src/Core/testing/SerializeDreadDiamondTest.cpp new file mode 100644 index 0000000..5bd3a57 --- /dev/null +++ b/src/Core/testing/SerializeDreadDiamondTest.cpp @@ -0,0 +1,114 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include +#include +#include + +#include "Core/Object.h" + +#include "testing-prototype.h" + +using namespace uLib; + + + + + + + +struct A : Object { + uLibTypeMacro(A,Object) + A() : numa(5552368) {} + int numa; +}; + + +ULIB_SERIALIZABLE_OBJECT(A) +ULIB_SERIALIZE_OBJECT(A,Object) { + ar & AR(numa); +} + +struct B : virtual Object { + uLibTypeMacro(B,Object) + B() : numb(5552369) {} + int numb; +}; + +ULIB_SERIALIZABLE_OBJECT(B) +ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); } + + +struct C : B { + uLibTypeMacro(C,B) + C() : numc(5552370) {} + int numc; +}; + +ULIB_SERIALIZABLE_OBJECT(C) +ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); } + +struct D : A,B { + uLibTypeMacro(D,A,B) + + D() : numd(5552371) {} + int numd; +}; + +ULIB_SERIALIZABLE_OBJECT(D) +ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); } + + + +main() { + A o; o.init_properties(); + + Archive::xml_oarchive(std::cout) << NVP(o); + +} + + + + + + + + + + + + + + + + + + + + diff --git a/src/Core/testing/SerializeTest.cpp b/src/Core/testing/SerializeTest.cpp new file mode 100644 index 0000000..f15660a --- /dev/null +++ b/src/Core/testing/SerializeTest.cpp @@ -0,0 +1,249 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include + +#include "Core/Object.h" +#include "Core/Archives.h" +#include "ParticlePhysics/MuonTomography/MuonScatter.h" + +#include "testing-prototype.h" + +using namespace uLib; + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// MANUAL SERIALIZATION // + +struct V3f { + + float x,y,z; + V3f() + { x = y = z =0; } + + V3f(float x, float y, float z) : + x(x), y(y), z(z) {} + + template + void serialize (Archive &ar,unsigned int v) { + ar + & "<" & NVP(x) & NVP(y) & NVP(z) & ">"; + } +}; + +ULIB_CLASS_EXPORT_KEY(V3f); +ULIB_CLASS_EXPORT_IMPLEMENT(V3f); + + +inline std::ostream & +operator <<(std::ostream &o, const V3f &v) { + Archive::hrt_oarchive(o) << v; + return o; +} + +inline std::istream & +operator >>(std::istream &is, V3f &v) { + Archive::hrt_iarchive(is) >> v; + return is; +} + + + + +int test_V3f() { + // testing human readble archive with simple serializable structure // + + V3f v1(1,2,3),v2,v3,v4; + std::cout << "v --> " << v1 << "\n"; + + std::stringstream ss; ss << v1; + std::cout << "ss.v --> " << ss.str() << "\n"; + + Archive::hrt_iarchive ar(ss); ar >> v2; + std::cout << "v2 --> " << v2 << "\n"; + + std::stringstream("<2 3 4>") >> v3; + std::cout << "v3 --> " << v3 << "\n"; + + // std::cout << "insert V3f string to parse: "; std::cin >> v4; + // std::cout << "v4 --> " << v4 << "\n"; + return (1); +} + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// OBJECT SERIALIZATION // + +class A : public virtual Object { + uLibTypeMacro(A,Object) + ULIB_SERIALIZE_ACCESS +public: + A() : m_a(5552368) {} + + properties() { + std::string p_a; + }; + + uLibRefMacro (a,int); +private: + int m_a; +}; + +void A::init_properties() { + $_init(); + $$.p_a = "A property string"; +} + +ULIB_SERIALIZABLE_OBJECT(A) +ULIB_SERIALIZE_OBJECT(A,Object) { + ar + & "Object A : " + & "--> m_a = " & AR(m_a) + & "\n"; +} + +ULIB_SERIALIZE_OBJECT_PROPS(A) { + ar + & "Object A properties: " + & "---> p_a = " & AR(p_a) & "\n"; +} + + + +int testing_xml_class() { + + A a; a.init_properties(); + + { + std::ofstream file("test.xml"); + Archive::xml_oarchive(file) << NVP(a); + } + a.a() = 0; + a.$$.p_a = "zero string"; + { + std::ifstream file("test.xml"); + Archive::xml_iarchive(file) >> NVP(a); + } + + Archive::xml_oarchive(std::cout) << NVP(a); + return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); +} + +int testing_hrt_class() { + + A a; a.init_properties(); + + { + std::ofstream file("test.xml"); + Archive::hrt_oarchive(file) << NVP(a); + } + a.a() = 0; + a.$$.p_a = "zero string"; + { + // ERRORE FIX ! + // std::ifstream file("test.xml"); + // Archive::hrt_iarchive(file) >> NVP(a); + } + + Archive::hrt_oarchive(std::cout) << NVP(a); + return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); +} + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// MUON SCATTER EXAMPLE // + +int testing_mu() +{ + std::stringstream ss; + + MuonScatter mu; + mu.SetMomentumIn(555); + mu.SetMomentumOut(2368); + { + std::ofstream file("test.txt"); + file << mu; + } + + mu.SetMomentumIn(0); + mu.SetMomentumOut(0); + { + std::ifstream file("test.txt"); + file >> mu; + } + + std::cout << mu << "\n"; + + +} + + + + + + +int main() { + BEGIN_TESTING(Serialize Test); + + TEST1( test_V3f() ); + TEST1( testing_xml_class() ); + // testing_hrt_class(); ///// << ERRORE in HRT with properties + TEST1( testing_mu() ); + + END_TESTING; +} + + + + + + + + + + + + + diff --git a/src/Core/testing/SignalTest.cpp b/src/Core/testing/SignalTest.cpp new file mode 100644 index 0000000..491af54 --- /dev/null +++ b/src/Core/testing/SignalTest.cpp @@ -0,0 +1,115 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include + + +#include "testing-prototype.h" +#include "Core/Types.h" +#include "Core/Object.h" +#include "Core/Signal.h" + + +using namespace uLib; + + + + +class Ob1 : public Object { +public: + + +signals: + void V0(); + + int V1(int a); + +}; + + + + +// should be done by moc // +void Ob1::V0() { + ULIB_SIGNAL_EMIT(Ob1::V0); +} + +int Ob1::V1(int a) { + ULIB_SIGNAL_EMIT(Ob1::V1,a); +} + + + + + +class Ob2 : public Object { + +public slots: + void PrintV0() { + std::cout << "Ob2 prints V0\n" << std::flush; + } +}; + +class Ob3 : public Object { + +public slots: + void PrintV0() { + std::cout << "Ob3 prints V0\n" << std::flush; + } + + void PrintNumber(int n) { + std::cout << "Ob3 is printing number: " << n << "\n"; + } +}; + + + + +int main() { + BEGIN_TESTING(Signals); + + Ob1 ob1; + Ob2 ob2; + Ob3 ob3; + + Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0); + Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0); + Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber); + + // not working yet + // Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0()) + + ob1.PrintSelf(std::cout); + + emit ob1.V0(); + emit ob1.V1(5552368); + + END_TESTING; +} + + diff --git a/src/Core/testing/SmartPointerTest.cpp b/src/Core/testing/SmartPointerTest.cpp new file mode 100644 index 0000000..5a2e129 --- /dev/null +++ b/src/Core/testing/SmartPointerTest.cpp @@ -0,0 +1,94 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include "Core/SmartPointer.h" +#include "testing-prototype.h" + +using namespace uLib; + +namespace Test { + +struct ObjectMockInterface { + virtual void PrintValue()=0; + virtual int& Value()=0; +}; + +class ObjectMock : ObjectMockInterface { + int value; +public: + int& Value() { return value; } + void PrintValue() { std::cout << "Value: " << value << "\n"; } + +}; +} // Test + + +bool test_smpt(SmartPointer &p) { + + SmartPointer spt = p; + spt->Value() = 5552368; + { + SmartPointer copy = spt; + copy->Value() = 123; + } + return (spt->Value() == 123); +} + + + + + +int main () { + BEGIN_TESTING(SmartPointer); + + // HOLD REFERENCE // + { + SmartPointer spt(new Test::ObjectMock); + TEST1(test_smpt(spt)); + } + { + SmartPointer spt; + TEST1(test_smpt(spt)); + } + { + SmartPointer spt = new SmartPointer; + TEST1(test_smpt(spt)); + } + + // TAKE REFERENCE // + { + Test::ObjectMock obj; + SmartPointer spt(obj); + TEST1(test_smpt(spt)); + } + + + + END_TESTING; +} diff --git a/src/Core/testing/SmartVectorTest.cpp b/src/Core/testing/SmartVectorTest.cpp new file mode 100644 index 0000000..13b6232 --- /dev/null +++ b/src/Core/testing/SmartVectorTest.cpp @@ -0,0 +1,120 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#include "testing-prototype.h" +#include "Core/Vector.h" +#include "Core/Object.h" + +using namespace uLib; + +static int instanziated_objects_number; + +class ObjectTest : public Object { +public: + ObjectTest() { + data[0] = 0; + data[1] = 1; + data[2] = 2; + instanziated_objects_number++; + } + ObjectTest(const ObjectTest ©) { + data[0] = copy.data[0]; + data[1] = copy.data[1]; + data[2] = copy.data[2]; + instanziated_objects_number++; + } + + ~ObjectTest() + { + instanziated_objects_number--; + } + float data[3]; +}; + +int main() { + BEGIN_TESTING(SmartVector); + + instanziated_objects_number =0; + + + ///////////////////////// SMART POINTER FUNCIONALITY /////////////////////// + + // int smart vector // + SmartVector sv(10); + for (int i=0;i<10;++i) + sv[i] = i; + // new shallow copy inside a code block // + { + SmartVector newsv = sv; + newsv[5] = 5552368; + TEST1(sv[5] == newsv[5]); + } + // verify that newsv destruction does not delete instance // + TEST1( sv[5] == 5552368 ); + + SmartVector svo(10); + for (int i=0;i<10;++i) + svo[i] = ObjectTest(); + + TEST1(instanziated_objects_number == 10); + { + SmartVector newsvo = svo; + newsvo[5].data[1] = 5552368.0; + TEST1(svo[5].data[1] == newsvo[5].data[1]); + TEST1(instanziated_objects_number == 10); + } + TEST1(instanziated_objects_number == 10); + + + + /////////////////////////// ITERATOR FUNCIONALITY ////////////////////////// + + + Vector v(10); + Vector::Iterator it; + + int i=1; + for(it=v.begin() ; it==v.end(); it++, i++) + *it = i; + + for(i = 0; i::ConstIterator cit; + i=1; + for(cit=v.begin(); cit==v.end(); cit++, i++) + TEST1( *cit == i+1 ); + + + END_TESTING +} + + + + diff --git a/src/Core/testing/StaticInterfaceTest.cpp b/src/Core/testing/StaticInterfaceTest.cpp new file mode 100644 index 0000000..a618c44 --- /dev/null +++ b/src/Core/testing/StaticInterfaceTest.cpp @@ -0,0 +1,112 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include "testing-prototype.h" +#include + + + +namespace uLib { + +//// INTERFACE TO COMPLEX CLASS ///// + +namespace Interface { +struct Test { + MAKE_TRAITS + template void check_structural() { + uLibCheckFunction(Self,test,bool,int,float); + uLibCheckMember(Self,testmemb,int); + } +}; +} + +struct Test { + bool test(int i, float f){} + int testmemb; +}; + + + +//// INTERFAC TO SIMPLE CLASS /////////// + +namespace Interface { +struct Simple { + MAKE_TRAITS + template void check_structural() { + uLibCheckMember(Self,memb1,int); + uLibCheckMember(Self,memb2,float); + } +}; +} + +struct Simple { + int memb1; + float memb2; +}; + + +///////////////////////// + +template +class UseTest { +public: + UseTest() { + Interface::IsA(); + T t; + int i; float f; + t.test(i,f); + } +}; + +template +class UseSimple { +public: + UseSimple() { + Interface::IsA(); + } +}; + + + +} + +int main() +{ + BEGIN_TESTING(Static Interface); + + + + uLib::UseTest u; + + uLib::UseSimple s; + + END_TESTING; +} + diff --git a/src/Core/testing/TypeIntrospectionTraversal.cpp b/src/Core/testing/TypeIntrospectionTraversal.cpp new file mode 100644 index 0000000..c163939 --- /dev/null +++ b/src/Core/testing/TypeIntrospectionTraversal.cpp @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include +#include +#include + + +#include "Core/Types.h" +#include "Core/Object.h" + + +#include "testing-prototype.h" + +using namespace uLib; + + + + + + + +int main() { + + + +} diff --git a/src/Core/testing/UuidTest.cpp b/src/Core/testing/UuidTest.cpp new file mode 100644 index 0000000..1445df3 --- /dev/null +++ b/src/Core/testing/UuidTest.cpp @@ -0,0 +1,45 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#include "Core/Object.h" +#include "Core/Uuid.h" + +#include "testing-prototype.h" + + +using namespace uLib; + +int main() +{ + BEGIN_TESTING(uuid); + + + + END_TESTING; +} diff --git a/src/Core/testing/VectorTest.cpp b/src/Core/testing/VectorTest.cpp new file mode 100644 index 0000000..6fee192 --- /dev/null +++ b/src/Core/testing/VectorTest.cpp @@ -0,0 +1,84 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include "testing-prototype.h" + +#include + +template < typename T > +struct __Cmp { + bool operator()(const T &data, const float value) { + return data <= value; + } +}; + + + + +template +inline const unsigned long +VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp) + { + + _Tp it = _it; + _Tp end = _end-1; + for(it; it != end; ) + { + if ( _comp(*it, value) ) it++; + else if( _comp(*end, value) ) + { + std::swap(*it,*end--); + } + else --end; + } + return it - _it; +} + + +int main() +{ + BEGIN_TESTING(Vector); + + uLib::Vector v; + v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3; + + + + int id = VectorSplice(v.begin(),v.end(),3,__Cmp()); + + std::cout << "id: " << id << "\n"; + std::cout << "vector: "; + for(uLib::Vector::Iterator it = v.begin(); it!=v.end(); it++) + std::cout << *it <<" "; + std::cout << std::endl; +// std::sort(v.begin(),v.end(),LT()); + + + END_TESTING; +} + diff --git a/src/Core/testing/testing-prototype.h b/src/Core/testing/testing-prototype.h new file mode 100644 index 0000000..39f4e6c --- /dev/null +++ b/src/Core/testing/testing-prototype.h @@ -0,0 +1,37 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#define BEGIN_TESTING(name) \ +static int _fail = 0; \ +printf("..:: Testing " #name " ::..\n"); + +#define TEST1(val) _fail += (val)==0 +#define TEST0(val) _fail += (val)!=0 +#define END_TESTING return _fail; + diff --git a/src/Detectors/CMakeLists.txt b/src/Detectors/CMakeLists.txt new file mode 100644 index 0000000..3820ba9 --- /dev/null +++ b/src/Detectors/CMakeLists.txt @@ -0,0 +1,38 @@ +# HEADERS +set(HEADERS + DetectorChamber.h + ExperimentFitEvent.h + GeantEvent.h + HitMC.h + MuonScatter.h + MuonEvent.h + MuonError.h + ChamberHitEvent.h + Hit.h + LinearFit.h + Solid.h + Matter.h + Scene.h +) + + +# SOURCES +set(SOURCES + Solid.cpp + Scene.cpp +) + +set(LIBRARIES + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Eigen_LIBRARY} + ${Geant4_LIBRARIES} + ${ROOT_LIBRARIES} + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math + ${PACKAGE_LIBPREFIX}Detectors +) + +uLib_add_shared_library(${uLib-module}) +add_subdirectory(testing) diff --git a/src/Detectors/ChamberHitEvent.h b/src/Detectors/ChamberHitEvent.h new file mode 100644 index 0000000..7fbe98e --- /dev/null +++ b/src/Detectors/ChamberHitEvent.h @@ -0,0 +1,56 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CHAMBERHITEVENT_H +#define U_CHAMBERHITEVENT_H + +#include "Core/Vector.h" +#include "Hit.h" +#include "ChamberDetector.h" + +namespace uLib { + +class ChamberHitEventData +{ +public: + uLibConstRefMacro (Hits, Vector ) + uLibGetMacro (Idv, ChamberDetector::ID) +private: + friend class ChamberHitEvent; + Vector m_Hits; + DetectorChamber::ID m_Idv; // -> chamber/view +}; + +class ChamberHitEvent : public ChamberHitEventData { +public: + uLibRefMacro (Hits, Vector ) + uLibSetMacro (Idv, ChamberDetector::ID) +}; + +} + +#endif // CHAMBERHITEVENT_H diff --git a/src/Detectors/DetectorChamber.h b/src/Detectors/DetectorChamber.h new file mode 100644 index 0000000..a5ed09f --- /dev/null +++ b/src/Detectors/DetectorChamber.h @@ -0,0 +1,48 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CHAMBERDETECTOR_H +#define U_CHAMBERDETECTOR_H + +#include "Core/Types.h" +#include "Math/ContainerBox.h" + +namespace uLib { + + +class DetectorChamber : public ContainerBox { + +public: + +private: +}; + + +} + + +#endif // CHAMBERDETECTOR_H diff --git a/src/Detectors/ExperimentFitEvent.h b/src/Detectors/ExperimentFitEvent.h new file mode 100644 index 0000000..8a08427 --- /dev/null +++ b/src/Detectors/ExperimentFitEvent.h @@ -0,0 +1,48 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_EXPERIMENTFITEVENT_H +#define U_EXPERIMENTFITEVENT_H + +namespace uLib { + + +class ExperimentFitEventData { +public: + +private: + +}; + + + + + +} + + +#endif // EXPERIMENTFITEVENT_H diff --git a/src/Detectors/GeantEvent.h b/src/Detectors/GeantEvent.h new file mode 100644 index 0000000..33d26aa --- /dev/null +++ b/src/Detectors/GeantEvent.h @@ -0,0 +1,69 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_GEANTEVENT_H +#define U_GEANTEVENT_H + +#include "Core/Types.h" +#include "Core/Vector.h" +#include "Math/Dense.h" + +#include "ChamberHitEvent.h" + +namespace uLib { + +class GeantEventData { +public: + uLibGetMacro (EventID, Id_t ) + uLibGetMacro (Momentum,Scalarf ) + uLibConstRefMacro (GenPos, Vector3f) + uLibConstRefMacro (GenDir, Vector3f) + uLibConstRefMacro (ChEvents,Vector) + +private: + friend class GeantEvent; + Id_t m_EventID; + Scalarf m_Momentum; + Vector3f m_GenPos; + Vector3f m_GenDir; + Vector m_ChEvents; +}; + +class GeantEvent { +public: + uLibSetMacro (EventID, Id_t ) + uLibSetMacro (Momentum,Scalarf ) + uLibRefMacro (GenPos, Vector3f) + uLibRefMacro (GenDir, Vector3f) + uLibRefMacro (ChEvents,Vector) +}; + + +} + + +#endif // GEANTEVENT_H diff --git a/src/Detectors/HierarchicalEncoding.h b/src/Detectors/HierarchicalEncoding.h new file mode 100644 index 0000000..16abffb --- /dev/null +++ b/src/Detectors/HierarchicalEncoding.h @@ -0,0 +1,41 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#ifndef U_DETECTORS_HIERARCHICALENCODING_H +#define U_DETECTORS_HIERARCHICALENCODING_H + +#include + +namespace uLib { + + + +} // uLib + + + + + +#endif // HIERARCHICALENCODING_H diff --git a/src/Detectors/Hit.h b/src/Detectors/Hit.h new file mode 100644 index 0000000..1261417 --- /dev/null +++ b/src/Detectors/Hit.h @@ -0,0 +1,70 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef HIT_H +#define HIT_H + +#include "Math/BitCode.h" + +namespace uLib { + + + + + +class HitRawCode_CMSDrift : + public BitCode4 +{ + typedef unsigned short T; +public: + HitRawCode_CMSDrift() : BitCode4(0) {} + HitRawCode_CMSDrift(const Vector4i &v) : BitCode4(v) {} + HitRawCode_CMSDrift(T Chamber, T ROB, T TDC, T Channel ) { + (*this) << Chamber, ROB, TDC, Channel; + } + + inline T Chamber() const { return m_data.bitf.field1; } + inline void SetChamber(const T data) { m_data.bitf.field1 = data; } + inline T ROB() const { return m_data.bitf.field2; } + inline void SetROB(const T data) { m_data.bitf.field2 = data; } + inline T TDC() const { return m_data.bitf.field3; } + inline void SetTDC(const T data) { m_data.bitf.field3 = data; } + inline T Channel() const { return m_data.bitf.field4; } + inline void SetChannel(const T data) { m_data.bitf.field4 = data; } + +}; + + + + + + + + + +} +#endif // HIT_H diff --git a/src/Detectors/HitMC.h b/src/Detectors/HitMC.h new file mode 100644 index 0000000..95404b2 --- /dev/null +++ b/src/Detectors/HitMC.h @@ -0,0 +1,67 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_HITMC_H +#define U_HITMC_H + +#include "Core/Macros.h" +#include "Math/Dense.h" +#include "Hit.h" + +namespace uLib { + + +class HitMCData : public HitData{ +public: + enum Type { + PrimaryMu, + SecondaryMu, + DeltaRay + }; + + uLibConstRefMacro(Position,HPoint3f) + uLibGetMacro(Type, enum Type) + +private: + HPoint3f m_Position; + enum Type m_Type; +}; + + +class HitMC : public HitMCData { +public: + uLibRefMacro(Position,HPoint3f) + uLibSetMacro(Type, enum Type) +}; + + + +} + + + +#endif // HITMC_H diff --git a/src/Detectors/LinearFit.h b/src/Detectors/LinearFit.h new file mode 100644 index 0000000..9419e69 --- /dev/null +++ b/src/Detectors/LinearFit.h @@ -0,0 +1,73 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_LINEARFIT_H +#define U_LINEARFIT_H + +#include "Core/Macros.h" +#include "Math/Dense.h" +#include "ChamberDetector.h" + + +namespace uLib { + +class LinearFitData { +public: + uLibConstRefMacro(Position,Vector2f) + uLibConstRefMacro(Slope,Vector2f) + uLibConstRefMacro(PositionError,Vector2f) + uLibConstRefMacro(SlopeError,Vector2f) + uLibGetMacro(HitsNumber,int) + uLibGetMacro(Idv,ChamberDetector::ID) + +private: + friend class LinearFit; + Vector2f m_Position; + Vector2f m_Slope; + Vector2f m_PositionError; + Vector2f m_SlopeError; + int m_HitsNumber; + DetectorChamber::ID m_Idv; +}; + + +class LinearFit : public LinearFitData { +public: + uLibRefMacro(Position,Vector2f) + uLibRefMacro(Slope,Vector2f) + uLibRefMacro(PositionError,Vector2f) + uLibRefMacro(SlopeError,Vector2f) + uLibSetMacro(HitsNumber,int) + uLibSetMacro(Idv,ChamberDetector::ID) +}; + + + +} + + +#endif // LINEARFIT_H diff --git a/src/Detectors/Makefile.am b/src/Detectors/Makefile.am new file mode 100644 index 0000000..b420a03 --- /dev/null +++ b/src/Detectors/Makefile.am @@ -0,0 +1,25 @@ +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Detectors +library_include_HEADERS = DetectorChamber.h \ + ExperimentFitEvent.h \ + GeantEvent.h \ + HitMC.h \ + MuonScatter.h \ + MuonEvent.h \ + MuonError.h \ + ChamberHitEvent.h \ + Hit.h \ + LinearFit.h \ + Solid.h \ + Matter.h \ + Scene.h + +_DETECTORS_SOURCES = \ + Solid.cpp \ + Scene.cpp + +noinst_LTLIBRARIES = libmutomdetectors.la +libmutomdetectors_la_SOURCES = ${_DETECTORS_SOURCES} + + diff --git a/src/Detectors/Matter.h b/src/Detectors/Matter.h new file mode 100644 index 0000000..04815c0 --- /dev/null +++ b/src/Detectors/Matter.h @@ -0,0 +1,71 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef MATTER_H +#define MATTER_H + +#include "Core/Object.h" + +class G4Element; +class G4Material; + +namespace uLib { + + +//////////////////////////////////////////////////////////////////////////////// +//// ELEMENT /////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +class Element { +public: + + uLibRefMacro(G4Data,G4Element *) +private: + G4Element *m_G4Data; +}; + + + +//////////////////////////////////////////////////////////////////////////////// +//// MATERIAL ////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +class Material : public Object { +public: + + uLibRefMacro(G4Data,G4Material *) +private: + G4Material *m_G4Data; +}; + + + +} + + +#endif // MATTER_H diff --git a/src/Detectors/MuonError.h b/src/Detectors/MuonError.h new file mode 100644 index 0000000..47aa570 --- /dev/null +++ b/src/Detectors/MuonError.h @@ -0,0 +1,58 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MUONERROR_H +#define U_MUONERROR_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +namespace uLib { + + +class MuonErrorData { + friend class MuonError; +public: + uLibConstRefMacro(Theta,Scalarf) + uLibConstRefMacro(Phi,Scalarf) +private: + Scalarf m_Theta; + Scalarf m_Phi; +}; + + +class MuonError : public MuonErrorData { +public: + uLibRefMacro(Theta,Scalarf) + uLibRefMacro(Phi,Scalarf) +}; + + +} // end ulib space + + +#endif // U_MUONERROR_H diff --git a/src/Detectors/MuonEvent.h b/src/Detectors/MuonEvent.h new file mode 100644 index 0000000..72e5c9b --- /dev/null +++ b/src/Detectors/MuonEvent.h @@ -0,0 +1,75 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MUONEVENT_H +#define U_MUONEVENT_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +namespace uLib { + + +class MuonEventData { + friend class MuonEvent; +public: + uLibConstRefMacro(LineIn,HLine3f) + uLibConstRefMacro(LineOut,HLine3f) + uLibGetMacro(Momentum,Scalarf) + +private: + HLine3f m_LineIn; + HLine3f m_LineOut; + Scalarf m_Momentum; +}; + + +class MuonEvent : public MuonEventData { +public: + uLibRefMacro(LineIn,HLine3f) + uLibRefMacro(LineOut,HLine3f) + uLibRefMacro(Momentum,Scalarf) + +}; + +inline std::ostream& +operator<< (std::ostream& stream, const MuonEventData &mu) { + stream << " MuonEventData: --------------- \n" + << " P: " << mu.GetMomentum() << "\n" + << " IN: " << mu.LineIn() << "\n" + << " OUT: " << mu.LineOut() << "\n" + << " ------------------------------ \n"; + return stream; +} + + + +} // end ulib space + + + +#endif // U_MUONEVENT_H diff --git a/src/Detectors/MuonScatter.h b/src/Detectors/MuonScatter.h new file mode 100644 index 0000000..48552d9 --- /dev/null +++ b/src/Detectors/MuonScatter.h @@ -0,0 +1,80 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifndef U_MUONSCATTER_H +#define U_MUONSCATTER_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +namespace uLib { + + +class MuonScatter { +public: + uLibConstRefMacro(LineIn,HLine3f) + uLibConstRefMacro(ErrorIn,HError3f) + uLibConstRefMacro(LineOut,HLine3f) + uLibConstRefMacro(ErrorOut,HError3f) + + uLibRefMacro(LineIn,HLine3f) + uLibRefMacro(ErrorIn,HError3f) + uLibRefMacro(LineOut,HLine3f) + uLibRefMacro(ErrorOut,HError3f) + uLibSetMacro(Momentum,Scalarf) + uLibSetMacro(MomentumPrime,Scalarf) + + uLibGetMacro(Momentum,Scalarf) + uLibGetMacro(MomentumPrime,Scalarf) + +protected: + HLine3f m_LineIn; + HLine3f m_LineOut; + HError3f m_ErrorIn; + HError3f m_ErrorOut; + Scalarf m_Momentum; + Scalarf m_MomentumPrime; +}; + +typedef MuonScatter MuonScatterData; + +inline std::ostream& +operator<< (std::ostream& stream, const MuonScatterData &mu) { + stream << " MuonScatterData: ------------- \n" + << " P: " << mu.GetMomentum() << " Pprim: " << mu.GetMomentumPrime() << "\n" + << " IN: " << mu.LineIn() << "\n" + << " " << mu.ErrorIn() << "\n" + << " OUT: " << mu.LineOut() << "\n" + << " " << mu.ErrorOut() <<"\n" + << " ------------------------------ \n"; + return stream; +} + +} + +#endif // U_MUONSCATTER_H diff --git a/src/Detectors/Scene.cpp b/src/Detectors/Scene.cpp new file mode 100644 index 0000000..5cdfdd8 --- /dev/null +++ b/src/Detectors/Scene.cpp @@ -0,0 +1,74 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + + +#include +#include +#include + +#include "Core/Vector.h" +#include "Matter.h" +#include "Solid.h" + +#include "Scene.h" + + +namespace uLib { + + +class DetectorsScenePimpl { + +public: + + + // members // + //Vector m_Solids; +}; + + + + +DetectorsScene::DetectorsScene() : + d(new DetectorsScenePimpl()) +{} + +DetectorsScene::~DetectorsScene() +{ + delete d; +} + +void DetectorsScene::AddSolid(const Solid &solid) +{ +// d->m_Solids.push_back(solid); +} + + + + + +} diff --git a/src/Detectors/Scene.h b/src/Detectors/Scene.h new file mode 100644 index 0000000..e7c7edb --- /dev/null +++ b/src/Detectors/Scene.h @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef SCENE_H +#define SCENE_H + +#include "Core/Object.h" +#include "Core/Vector.h" +#include "Solid.h" + +namespace uLib { + + +class DetectorsScene : public Object { +public: + DetectorsScene(); + ~DetectorsScene(); + + + void AddSolid(const Solid &solid); + +private: + class DetectorsScenePimpl *d; +}; + + +} +#endif // SCENE_H diff --git a/src/Detectors/Solid.cpp b/src/Detectors/Solid.cpp new file mode 100644 index 0000000..46597b2 --- /dev/null +++ b/src/Detectors/Solid.cpp @@ -0,0 +1,114 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +// G4 Solid // +#include +#include +#include + +// Tessellated solid // +#include +#include +#include + + +#include "Math/Dense.h" + +#include "Solid.h" + +namespace uLib { + +class DetectorsSolidPimpl { +public: + static G4ThreeVector getG4Vector3f(const Vector3f &vector) { + return G4ThreeVector( vector(0), vector(1), vector(2) ); + } +}; + + + +Solid::Solid() : + m_Logical (new G4LogicalVolume(NULL,NULL,"unnamed_solid")), + m_Material(NULL) +{} + +Solid::Solid(const char *name) : + m_Logical(new G4LogicalVolume(NULL,NULL,name)), + m_Material(NULL) +{} + + + +void Solid::SetNistMaterial(const char *name) +{ + G4NistManager *nist = G4NistManager::Instance(); + if (m_Material) delete m_Material; + m_Material = nist->FindOrBuildMaterial(name); + m_Logical->SetMaterial(m_Material); +} + +void Solid::SetMaterial(G4Material *material) +{ + if(material) + { + m_Material = material; + m_Logical->SetMaterial(material); + } +} + + + + + + + + + + +TessellatedSolid::TessellatedSolid(const char *name) : + BaseClass(name), + m_Solid(new G4TessellatedSolid(name)) +{} + + +void TessellatedSolid::SetMesh(TriangleMesh &mesh) +{ + G4TessellatedSolid *ts = this->m_Solid; + for (int i=0; iAddFacet((G4VFacet *)facet); + } + this->m_Logical->SetSolid(ts); +} + + +} diff --git a/src/Detectors/Solid.h b/src/Detectors/Solid.h new file mode 100644 index 0000000..7babd27 --- /dev/null +++ b/src/Detectors/Solid.h @@ -0,0 +1,86 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef SOLID_H +#define SOLID_H + +#include "Core/Object.h" +#include "Math/Dense.h" +#include "Math/TriangleMesh.h" +#include "Detectors/Matter.h" + +class G4Material; +class G4LogicalVolume; +class G4TessellatedSolid; + + +namespace uLib { + +class Solid : public Object { +public: + + Solid(); + Solid(const char *name); + + void SetNistMaterial(const char *name); + + void SetMaterial(G4Material *material); + + uLibGetMacro(Material,G4Material *) + uLibGetMacro(Logical,G4LogicalVolume *) + +protected: + G4Material *m_Material; + G4LogicalVolume *m_Logical; +}; + + + + + +class TessellatedSolid : public Solid { + typedef Solid BaseClass; + +public: + TessellatedSolid(const char *name); + + void SetMesh(TriangleMesh &mesh); + + uLibGetMacro(Solid,G4TessellatedSolid *) +private: + G4TessellatedSolid *m_Solid; +}; + + + + +} + + + + +#endif // SOLID_H diff --git a/src/Detectors/testing/CMakeLists.txt b/src/Detectors/testing/CMakeLists.txt new file mode 100644 index 0000000..d3bff8f --- /dev/null +++ b/src/Detectors/testing/CMakeLists.txt @@ -0,0 +1,18 @@ +# TESTS +set( TESTS + GDMLSolidTest + HierarchicalEncodingTest +) + +#set(LIBRARIES +# ${PACKAGE_LIBPREFIX}Core +# ${PACKAGE_LIBPREFIX}Math +# ${PACKAGE_LIBPREFIX}Detectors +# ${Boost_SERIALIZATION_LIBRARY} +# ${Boost_SIGNALS_LIBRARY} +# ${Boost_PROGRAM_OPTIONS_LIBRARY} +# ${Eigen_LIBRARY} +# ${Geant4_LIBRARIES} +# ${ROOT_LIBRARIES} +#) +uLib_add_tests(${uLib-module}) diff --git a/src/Detectors/testing/GDMLSolidTest.cpp b/src/Detectors/testing/GDMLSolidTest.cpp new file mode 100644 index 0000000..3c8843f --- /dev/null +++ b/src/Detectors/testing/GDMLSolidTest.cpp @@ -0,0 +1,72 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include + +#include +#include + +#include +#include +#include +#include + +#include +//#include +//#include + + +#include "Detectors/Solid.h" +#include "testing-prototype.h" + + + + +int main() +{ + +// G4RunManager* runManager = new G4RunManager; + + G4NistManager *nist = G4NistManager::Instance(); + G4Material *air = nist->FindOrBuildMaterial("G4_AIR"); + + + + G4Box *box = new G4Box("box",5,5,5); + + G4LogicalVolume box_lv(NULL,NULL,"box test"); + box_lv.SetSolid(box); + box_lv.SetMaterial(air); + G4PVPlacement box_pl(0,G4ThreeVector(),&box_lv,"box test",0,0,0); + + G4GDMLParser parser; + + parser.Write("test_out.gdml",&box_lv); + + +} diff --git a/src/Detectors/testing/HierarchicalEncodingTest.cpp b/src/Detectors/testing/HierarchicalEncodingTest.cpp new file mode 100644 index 0000000..b02d6da --- /dev/null +++ b/src/Detectors/testing/HierarchicalEncodingTest.cpp @@ -0,0 +1,50 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#include +#include + +#include "testing-prototype.h" + +using namespace uLib; + +int main() { + BEGIN_TESTING(Hierarchical Encoding); + + + HitRawCode_CMSDrift code; + code = Vector4i(5,6,2,8); + + + + Vector4i v = code; + + + std::cout << code << "\n"; + std::cout << v << "\n"; + + END_TESTING; +} + diff --git a/src/Detectors/testing/Makefile.am b/src/Detectors/testing/Makefile.am new file mode 100644 index 0000000..cd956fc --- /dev/null +++ b/src/Detectors/testing/Makefile.am @@ -0,0 +1,16 @@ + +include $(top_srcdir)/Common.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + +# if HAVE_CHECK +TESTS = GDMLSolidTest + +# else +# TEST = +# endif + +LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la + +check_PROGRAMS = $(TESTS) + diff --git a/src/Detectors/testing/testing-prototype.h b/src/Detectors/testing/testing-prototype.h new file mode 100644 index 0000000..39f4e6c --- /dev/null +++ b/src/Detectors/testing/testing-prototype.h @@ -0,0 +1,37 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#define BEGIN_TESTING(name) \ +static int _fail = 0; \ +printf("..:: Testing " #name " ::..\n"); + +#define TEST1(val) _fail += (val)==0 +#define TEST0(val) _fail += (val)!=0 +#define END_TESTING return _fail; + diff --git a/src/Gui/Qt/QVTKViewport2/Makefile.am b/src/Gui/Qt/QVTKViewport2/Makefile.am new file mode 100644 index 0000000..c6e1b8c --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/Makefile.am @@ -0,0 +1,35 @@ +# SUBDIRS = . + +include $(top_srcdir)/Common.am + +DISTSOURCES = vtkviewport.cpp main.cpp +DISTHEADERS_MOC = +DISTHEADERS_NO_MOC = +FORMS = vtkviewport.ui + +FORMHEADERS = $(FORMS:.ui=.h) +MOC_CC = $(FORMS:.ui=.moc.cpp) $(DISTHEADERS_MOC:.h=.moc.cpp) + +bin_PROGRAMS = QTVtkViewport + +BUILT_SOURCES = $(FORMHEADERS) $(MOC_CC) +CLEANFILES = $(BUILT_SOURCES) + +EXTRA_DIST = $(FORMS) +QTVtkViewport_SOURCES = $(DISTSOURCES) $(DISTHEADERS_MOC) $(DISTHEADERS_NO_MOC) +nodist_QTVtkViewport_SOURCES = $(MOC_CC) + +QTVtkViewport_LDADD = $(top_srcdir)/libmutom.la + + +.ui.h: $(FORMS) + $(UIC) -o ui_$@ $< + +.ui.hpp: $(FORMS_HPP) + $(UIC) -o $@ $< + +.h.moc.cpp: + $(MOC) -o $@ $< + + +SUFFIXES = .h .ui .moc.cpp diff --git a/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro b/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro new file mode 100644 index 0000000..6a3a510 --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro @@ -0,0 +1,18 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2012-08-30T18:59:53 +# +#------------------------------------------------- + +QT += core gui + +TARGET = QVTKViewport2 +TEMPLATE = app + + +SOURCES += main.cpp\ + vtkviewport.cpp + +HEADERS += vtkviewport.h + +FORMS += vtkviewport.ui diff --git a/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro.user b/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro.user new file mode 100644 index 0000000..419ba5a --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/QVTKViewport2.pro.user @@ -0,0 +1,453 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + System + false + 4 + true + 1 + true + 0 + true + 1 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + 0 + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Desktop Qt 4.7.4 for GCC (Qt SDK) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 3 + false + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Desktop Qt 4.7.4 for GCC (Qt SDK) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 3 + false + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.7.0 in PATH (System) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 4 + false + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.7.0 in PATH (System) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 4 + false + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.7.0 (System) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 5 + false + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.7.0 (System) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2 + 5 + false + + 6 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + + + false + false + false + false + false + false + false + false + true + true + 0.01 + 0.01 + 10 + 10 + false + false + 25 + 25 + + + true + true + valgrind + valgrind + + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + + + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + + QVTKViewport2 + + Qt4ProjectManager.Qt4RunConfiguration + 2 + + QVTKViewport2.pro + false + false + + + 3768 + true + false + false + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {f8bb0047-7f6e-45df-9cc8-e746abebf883} + + + ProjectExplorer.Project.Updater.FileVersion + 10 + + diff --git a/src/Gui/Qt/QVTKViewport2/main.cpp b/src/Gui/Qt/QVTKViewport2/main.cpp new file mode 100644 index 0000000..aabcdd9 --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/main.cpp @@ -0,0 +1,38 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include "vtkviewport.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + VtkViewport w; + w.show(); + + return a.exec(); +} diff --git a/src/Gui/Qt/QVTKViewport2/vtkviewport.cpp b/src/Gui/Qt/QVTKViewport2/vtkviewport.cpp new file mode 100644 index 0000000..77629da --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/vtkviewport.cpp @@ -0,0 +1,41 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "vtkviewport.h" +#include "ui_vtkviewport.h" + +VtkViewport::VtkViewport(QWidget *parent) : + QWidget(parent), + ui(new Ui::VtkViewport) +{ + ui->setupUi(this); +} + +VtkViewport::~VtkViewport() +{ + delete ui; +} diff --git a/src/Gui/Qt/QVTKViewport2/vtkviewport.h b/src/Gui/Qt/QVTKViewport2/vtkviewport.h new file mode 100644 index 0000000..09c2d7d --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/vtkviewport.h @@ -0,0 +1,49 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKVIEWPORT_H +#define VTKVIEWPORT_H + +#include + +namespace Ui { +class VtkViewport; +} + +class VtkViewport : public QWidget +{ + Q_OBJECT + +public: + explicit VtkViewport(QWidget *parent = 0); + ~VtkViewport(); + +private: + Ui::VtkViewport *ui; +}; + +#endif // VTKVIEWPORT_H diff --git a/src/Gui/Qt/QVTKViewport2/vtkviewport.ui b/src/Gui/Qt/QVTKViewport2/vtkviewport.ui new file mode 100644 index 0000000..095019b --- /dev/null +++ b/src/Gui/Qt/QVTKViewport2/vtkviewport.ui @@ -0,0 +1,32 @@ + + + VtkViewport + + + + 0 + 0 + 580 + 536 + + + + Form + + + + + 140 + 170 + 161 + 41 + + + + Hello World ! + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..4709f04 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = ltk Core Math Detectors Root + + diff --git a/src/Math/Accumulator.h b/src/Math/Accumulator.h new file mode 100644 index 0000000..ca711ba --- /dev/null +++ b/src/Math/Accumulator.h @@ -0,0 +1,334 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_DATABINNING_H +#define U_DATABINNING_H + +#include "Core/Vector.h" +#include "Dense.h" + + +namespace uLib { + + + +// TODO: USE BOOST ACCUMULATORS // + + +template +class Accumulator_Mean { + typedef std::pair Tmean; +public: + Accumulator_Mean() { + m_Means.push_back( Tmean(0,0) ); + } + + void operator()(const T data) { + T tmp = 0; + // for(typename std::vector::iterator it = m_Means.begin(); it < m_Means.back(); ++it) + // tmp += it->first/it->second; + for(int i=0; i::iterator it = m_Means.begin(); it < m_Means.end(); ++it) { + // mean += it->first/it->second; } + for(int i=0; i m_Means; +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// accumulator Trim // + +template < typename T, int subsample_size=200 > +class Accumulator_ABTrim { + +public: + Accumulator_ABTrim() : + m_Avg(0), + m_InternalCount(0), + m_SizeA(0), + m_SizeB(0), + m_IdA(0), + m_IdB(0) + {} + + Accumulator_ABTrim(const Accumulator_ABTrim &c) { +# pragma omp critical + { + m_Avg = c.m_Avg; + m_InternalCount = c.m_InternalCount; + m_SizeA = c.m_SizeA; + m_SizeB = c.m_SizeB; + m_IdA = c.m_IdA; + m_IdB = c.m_IdB; + memcpy (m_Av, c.m_Av, sizeof (m_Av)); + } + } + + void operator += (T value) { + if(m_InternalCount > subsample_size) { + // array complete and counter over subsample // + if( m_SizeA > 0 && value < m_ValA ) { + ;// m_Avg += m_ValA; + } + else if (m_SizeB > 0 && value > m_ValB) + { + ;// m_Avg += m_ValB; + } + else + { + m_Avg += value; + m_InternalCount++; + } + } + else if(m_InternalCount >=0) { + // array complete + if(m_SizeA > 0 && value < m_ValA) + { + m_Avg += m_ValA; + m_Av[m_IdA] = value; + for (unsigned int i=0; i < m_SizeA; i++) + if(m_Av[i] > m_Av[m_IdA]) + { m_IdA = i; m_ValA = m_Av[i]; } + } + else if(m_SizeB > 0 && value > m_ValB) + { + m_Avg += m_ValB; + m_Av[m_IdB] = value; + for (unsigned int i=m_SizeA; i < m_SizeA+m_SizeB; i++) + if(m_Av[i] < m_Av[m_IdB]) + { m_IdB = i; m_ValB = m_Av[i]; } + } + else { + m_Avg += value; + } + m_InternalCount++; + } + else { // m_InternalCount < 0 + // array is not fullfilled + m_Av[m_SizeA+m_SizeB+m_InternalCount] = value; + m_InternalCount++; + if(m_InternalCount == 0) { + std::sort(m_Av,m_Av+m_SizeA+m_SizeB); + if(m_SizeA > 0) { + m_IdA = m_SizeA-1; + m_ValA = m_Av[m_IdA]; + } + if(m_SizeB > 0) { + m_IdB = m_SizeA; + m_ValB = m_Av[m_SizeA]; + } + } + } + } + + T operator()() { + if(m_InternalCount <= 0) { + std::sort(m_Av, m_Av+m_SizeA+m_SizeB+m_InternalCount); + return m_Av[ (m_SizeA+m_SizeB+m_InternalCount) / 2]; // median value // + } + else { +// return (m_Avg + m_ValA * m_SizeA + m_ValB * m_SizeB) / +// (m_InternalCount + m_SizeA + m_SizeB); + return (m_Avg) / m_InternalCount; + } + } + + void SetABTrim(int a, int b) { + if(a+b > subsample_size/2) { + m_SizeA = a/(a+b) * subsample_size/2; + m_SizeB = b/(a+b) * subsample_size/2; + } + else { + m_SizeA = a; + m_SizeB = b; + } + m_Avg = 0; + m_InternalCount = -m_SizeA-m_SizeB; + } + + +private: + T m_Av[subsample_size/2]; + T m_Avg, m_ValA, m_ValB; + int m_IdA, m_IdB, m_InternalCount; + int m_SizeA, m_SizeB; +}; + + + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Clip Accumulator // + +template < typename T, int subsample_size=200 > +class Accumulator_ABClip { + +public: + Accumulator_ABClip() : + m_Avg(0), + m_InternalCount(0), + m_SizeA(0), + m_SizeB(0), + m_IdA(0), + m_IdB(0) + {} + + Accumulator_ABClip(const Accumulator_ABClip &c) { +# pragma omp critical + { + m_Avg = c.m_Avg; + m_InternalCount = c.m_InternalCount; + m_SizeA = c.m_SizeA; + m_SizeB = c.m_SizeB; + m_IdA = c.m_IdA; + m_IdB = c.m_IdB; + memcpy (m_Av, c.m_Av, sizeof (m_Av)); + } + } + + void operator += (T value) { + if(m_InternalCount > subsample_size) { + // array complete and counter over subsample // + if( m_SizeA > 0 && value < m_ValA ) { + m_Avg += m_ValA; + } + else if (m_SizeB > 0 && value > m_ValB) { + m_Avg += m_ValB; + } + else { + m_Avg += value; + } + m_InternalCount++; + } + else if(m_InternalCount >=0) { + // array complete + if(m_SizeA > 0 && value < m_ValA) + { + m_Avg += m_ValA; + m_Av[m_IdA] = value; + for (unsigned int i=0; i < m_SizeA; i++) + if(m_Av[i] > m_Av[m_IdA]) + { m_IdA = i; m_ValA = m_Av[i]; } + } + else if(m_SizeB > 0 && value > m_ValB) + { + m_Avg += m_ValB; + m_Av[m_IdB] = value; + for (unsigned int i=m_SizeA; i < m_SizeA+m_SizeB; i++) + if(m_Av[i] < m_Av[m_IdB]) + { m_IdB = i; m_ValB = m_Av[i]; } + } + else { + m_Avg += value; + } + m_InternalCount++; + } + else { // m_InternalCount < 0 + // array is not fullfilled + m_Av[m_SizeA+m_SizeB+m_InternalCount] = value; + m_InternalCount++; + if(m_InternalCount == 0) { + std::sort(m_Av,m_Av+m_SizeA+m_SizeB); + if(m_SizeA > 0) { + m_IdA = m_SizeA-1; + m_ValA = m_Av[m_IdA]; + } + if(m_SizeB > 0) { + m_IdB = m_SizeA; + m_ValB = m_Av[m_SizeA]; + } + } + } + } + + T operator()() { + if(m_InternalCount <= 0) { + std::sort(m_Av, m_Av+m_SizeA+m_SizeB+m_InternalCount); + return m_Av[ (m_SizeA+m_SizeB+m_InternalCount) / 2]; // median value // + } + else { + return (m_Avg + m_ValA * m_SizeA + m_ValB * m_SizeB) / + (m_InternalCount + m_SizeA + m_SizeB); + } + } + + void SetABTrim(int a, int b) { + if(a+b > subsample_size/2) { + m_SizeA = a/(a+b) * subsample_size/2; + m_SizeB = b/(a+b) * subsample_size/2; + } + else { + m_SizeA = a; + m_SizeB = b; + } + m_Avg = 0; + m_InternalCount = -m_SizeA-m_SizeB; + } + + +private: + T m_Av[subsample_size/2]; + T m_Avg, m_ValA, m_ValB; + int m_IdA, m_IdB, m_InternalCount; + int m_SizeA, m_SizeB; +}; + + + + + +} // uLib + + + + +#endif // U_DATABINNING_H diff --git a/src/Math/BitCode.h b/src/Math/BitCode.h new file mode 100644 index 0000000..8ca3581 --- /dev/null +++ b/src/Math/BitCode.h @@ -0,0 +1,250 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + +#ifndef U_MATH_BITCODE_H +#define U_MATH_BITCODE_H + +#include +#include +//#include +#include + +#include +#include +#include + +namespace uLib { + + +template < typename ContainerT, typename ContentT > +struct CommaInitializerBitCode +{ + inline explicit CommaInitializerBitCode(ContainerT *container, ContentT s) + : container(container) + { + this->index = 0; + this->container->operator()().field1 = s; + } + inline CommaInitializerBitCode & operator, (ContentT s) { + this->index++; + if(index < container->size()) { + if(index == 1) container->operator()().field2 = s; + if(index == 2) container->operator()().field3 = s; + if(index == 3) container->operator()().field4 = s; + } + return *this; + } + + ContainerT *container; + unsigned int index; +}; + + + + +template +class BitCode2 +{ +protected: + typedef T Type; + typedef BitCode2 ThisClass; + typedef CommaInitializerBitCode< ThisClass, T > CommaInit; + BOOST_STATIC_ASSERT_MSG( boost::is_unsigned::value == 1, "CODE TYPE MUST BE UNSIGNED" ); + BOOST_STATIC_ASSERT( L1+L2 == sizeof(T)*8 ); + +public: + struct BitField { + T field1 : L1; + T field2 : L2; + }; + union CodeSet { + BitField bitf; + T value; + } m_data; + + BitCode2() {} + BitCode2(const T& data) { m_data.value = data; } + BitCode2(const Vector2i & data) { + (*this) << data(0),data(1); + } + inline CommaInit operator <<(T scalar) { return CommaInit(this, scalar); } + static const int size() { return 2; } + + BitField & operator()() { return m_data.bitf; } + const BitField & operator()() const { return m_data.bitf; } + operator Vector2i () { return Vector2i(m_data.bitf.field1, + m_data.bitf.field2); } + + void set(const T data) { m_data.value = data; } + T get() const { return m_data.value; } +}; + +template +std::ostream & +operator << (std::ostream &o, const BitCode2 &code) { + o << code().field1 << "," << code().field2; + return o; +} + + + + + + + +template +class BitCode3 +{ +protected: + typedef T Type; + typedef BitCode3 ThisClass; + typedef CommaInitializerBitCode< ThisClass, T > CommaInit; + BOOST_STATIC_ASSERT_MSG( boost::is_unsigned::value == 1, "CODE TYPE MUST BE UNSIGNED" ); + BOOST_STATIC_ASSERT( L1+L2+L3 == sizeof(T)*8 ); + +public: + struct BitField { + T field1 : L1; + T field2 : L2; + T field3 : L3; + }; + union CodeSet { + BitField bitf; + T value; + } m_data; + + + BitCode3() {} + BitCode3(const T& data) { m_data.value = data; } + BitCode3(const Vector3i & data) { + (*this) << data(0),data(1),data(2); + } + inline CommaInit operator <<(T scalar) { return CommaInit(this, scalar); } + static const int size() { return 3; } + + BitField & operator()() { return m_data.bitf; } + const BitField & operator()() const { return m_data.bitf; } + operator Vector3i () { return Vector3i(m_data.bitf.field1, + m_data.bitf.field2, + m_data.bitf.field3); } + + void set(const T data) { m_data.value = data; } + T get() const { return m_data.value; } +}; + +template +std::ostream & +operator << (std::ostream &o, const BitCode3 &code) { + o << code().field1 << "," << code().field2 << "," << code().field3; + return o; +} + + + + + + + +template +class BitCode4 +{ +protected: + typedef T Type; + typedef BitCode4 ThisClass; + typedef CommaInitializerBitCode< ThisClass, T > CommaInit; + BOOST_STATIC_ASSERT_MSG( boost::is_unsigned::value == 1, "CODE TYPE MUST BE UNSIGNED" ); + BOOST_STATIC_ASSERT( L1+L2+L3+L4 == sizeof(T)*8 ); +public: + struct BitField { + T field1 : L1; + T field2 : L2; + T field3 : L3; + T field4 : L4; + }; + union CodeSet { + BitField bitf; + T value; + } m_data; + + BitCode4() {} + BitCode4(const T& data) { m_data.value = data; } + BitCode4(const Vector4i & data) { + (*this) << data(0),data(1),data(2),data(3); + } + inline CommaInit operator << (T scalar) { return CommaInit(this, scalar); } + static const int size() { return 4; } + + BitField & operator()() { return m_data.bitf; } + const BitField & operator()() const { return m_data.bitf; } + operator Vector4i () { return Vector4i(m_data.bitf.field1, + m_data.bitf.field2, + m_data.bitf.field3, + m_data.bitf.field4); } + + void set(const T data) { m_data.value = data; } + T get() const { return m_data.value; } + + + +}; + +template +std::ostream & +operator << (std::ostream &o, const BitCode4 &code) { + o << code().field1 << "," << code().field2 << "," << code().field3 << "," << code().field4; + return o; +} + + + +template +class BitCode { + typedef boost::mpl::vector_c BitSet; + T m_data; + +public: + + struct value_printer + { + template< typename U > void operator()(U x) + { std::cout << x << '\n'; } + }; + void PrintSelf( ) { +// boost::mpl::for_each( value_printer() ); +// std::cout << boost::mpl::at_c< BitSet,1 >::type::value << "\n"; + } + + int Get(unsigned short field) const { + return boost::mpl::at_c< BitSet, field >::type::value; + } +}; + + + +} // uLib + + +#endif // BITCODE_H diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt new file mode 100644 index 0000000..93e923b --- /dev/null +++ b/src/Math/CMakeLists.txt @@ -0,0 +1,50 @@ + +# HEADERS +set(HEADERS + ContainerBox.h + Dense.h + Geometry.h + Transform.h + StructuredData.h + StructuredGrid.h + VoxImage.h + VoxRaytracer.h + Utils.h + VoxImageFilter.h + VoxImageFilter.hpp + VoxImageFilterLinear.hpp + VoxImageFilterMedian.hpp + VoxImageFilterABTrim.hpp + VoxImageFilterBilateral.hpp + VoxImageFilterThreshold.hpp + VoxImageFilter2ndStat.hpp + VoxImageFilterCustom.hpp + Accumulator.h + TriangleMesh.h + BitCode.h +) + + +# SOURCES +set(SOURCES + VoxRaytracer.cpp + StructuredData.cpp + StructuredGrid.cpp + VoxImage.cpp + TriangleMesh.cpp + Dense.cpp +) + +set(LIBRARIES + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Eigen_LIBRARY} + ${ROOT_LIBRARIES} + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math +) + + +uLib_add_shared_library(${uLib-module}) +add_subdirectory(testing) diff --git a/src/Math/ContainerBox.h b/src/Math/ContainerBox.h new file mode 100644 index 0000000..12bd4cf --- /dev/null +++ b/src/Math/ContainerBox.h @@ -0,0 +1,98 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CONTAINERBOX_H +#define U_CONTAINERBOX_H + +#include "Geometry.h" + + +namespace uLib { + + + +class ContainerBox : public AffineTransform { +public: + ContainerBox() : m_LocalT(this) {} + + ContainerBox(const ContainerBox ©) : + m_LocalT(this), + AffineTransform(copy) + { + // FIX for performance // + this->SetOrigin(copy.GetOrigin()); + this->SetSize(copy.GetSize()); + } + + inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); } + + inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); } + + void SetSize(const Vector3f &v) { + Vector3f pos = this->GetOrigin(); + m_LocalT = AffineTransform(this); + m_LocalT.Scale(v); + m_LocalT.SetPosition(pos); + } + + inline Vector3f GetSize() const { return m_LocalT.GetScale(); } + + // FIX... // + inline void FlipLocalAxes(int first, int second) + { m_LocalT.FlipAxes(first,second); } + + Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); } + + inline Vector4f GetWorldPoint(const Vector4f &v) const { + return m_LocalT.GetWorldMatrix() * v; + } + + inline Vector4f GetWorldPoint(const float x, const float y, const float z) { + return this->GetWorldPoint(Vector4f(x,y,z,1)); + } + + inline Vector4f GetLocalPoint(const Vector4f &v) const { + return m_LocalT.GetWorldMatrix().inverse() * v; + } + + inline Vector4f GetLocalPoint(const float x, const float y, const float z) { + return this->GetLocalPoint(Vector4f(x,y,z,1)); + } + + +protected: + +private: + AffineTransform m_LocalT; +}; + + +} + + + +#endif // CONTAINERBOX_H diff --git a/src/Math/Dense.cpp b/src/Math/Dense.cpp new file mode 100644 index 0000000..22c50e5 --- /dev/null +++ b/src/Math/Dense.cpp @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Dense.h" +#include "Core/Archives.h" + +ULIB_SERIALIZE(uLib::HPoint3f) { + ar & boost::serialization::make_nvp(NULL,boost::serialization::base_object(ob)); +} + + +ULIB_SERIALIZE(uLib::HVector3f) { + ar & boost::serialization::make_nvp(NULL,boost::serialization::base_object(ob)); +} + + +ULIB_SERIALIZE(uLib::HLine3f) { + ar + & "HLine -> ( origin: " & AR(origin) & "; direction: " & AR(direction) & ") "; +} + +ULIB_SERIALIZE(uLib::HError3f) { + ar + & "HLine -> ( poserr: " & AR(position_error) & "; direrr: " & AR(direction_error) & ") "; +} + + diff --git a/src/Math/Dense.h b/src/Math/Dense.h new file mode 100644 index 0000000..3912610 --- /dev/null +++ b/src/Math/Dense.h @@ -0,0 +1,280 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +/* + * + * Copyright (C) 2012 Andrea Rigoni Garola + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + + +#ifndef ULIB_DENSEMATRIX_H +#define ULIB_DENSEMATRIX_H + +#include + +#include +#include "Core/Types.h" +#include "Core/Serializable.h" + + + +//// BOOST SERIALIZATION /////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include + + +namespace boost { +namespace serialization { + +template +void serialize(Archive & ar, ::Eigen::Matrix & m, const unsigned int /*version*/) { + ar & boost::serialization::make_array(m.data(), RowsAtCompileTime * ColsAtCompileTime); +} + +} // serialization +} // boost + +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// EIGEN VECTOR STREAM INTERACTIONS //////////////////////////////////////////// +// this is needed by boost::lexical_cast to cope with Eigens Vectors /////////// +namespace Eigen { +template +std::istream & operator >> (std::istream &is, Eigen::Matrix &vec) { + std::string str; + for( unsigned int i=0; i> std::skipws; + is >> str; + if(is.fail()) vec(i) = 0; + else vec(i) = boost::lexical_cast(str); + } + return is; +} +template +std::ostream & operator << (std::ostream &os, const Eigen::Matrix &vec) { + os << vec.transpose(); + return os; +} +} // Eigen +//////////////////////////////////////////////////////////////////////////////// + + + +namespace uLib { + + +typedef int Scalari; +typedef unsigned int Scalarui; +typedef long Scalarl; +typedef unsigned long Scalarul; +typedef float Scalarf; +typedef double Scalard; + + + +typedef Eigen::Matrix Matrix1i; +typedef Eigen::Matrix2i Matrix2i; +typedef Eigen::Matrix3i Matrix3i; +typedef Eigen::Matrix4i Matrix4i; + +typedef Eigen::Matrix Matrix1f; +typedef Eigen::Matrix2f Matrix2f; +typedef Eigen::Matrix3f Matrix3f; +typedef Eigen::Matrix4f Matrix4f; + +typedef Eigen::Matrix Vector1i; +typedef Eigen::Vector2i Vector2i; +typedef Eigen::Vector3i Vector3i; +typedef Eigen::Vector4i Vector4i; + +typedef Eigen::Matrix Vector1f; +typedef Eigen::Vector2f Vector2f; +typedef Eigen::Vector3f Vector3f; +typedef Eigen::Vector4f Vector4f; + + + + +//////////////////////////////////////////////////////////////////////////////// +// Vector String interaction /////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +/*! Given a string consisting of a series of doubles with some +* delimiter, return an Eigen::Vector populated with those +* values, in the same order as they are given in the string. +* +* \param vec A double vector to be populated with the results +* \param str A string to be parsed as a series of doubles. +* \param delim Delimiters of the text (a typical default is " ," for comma and space-delimited text +* +*/ +template +void VectorxT_StringTo(Eigen::Matrix &vec, std::string str, const char *delim = " ,;\t\n") { + std::vector strvec; + + boost::algorithm::trim_if( str, boost::algorithm::is_any_of(delim)); + boost::algorithm::split(strvec,str,boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on); + + for( unsigned int i=0; i(strvec[i]); + } +} + +template +std::string VectorxT_ToString(const Eigen::Matrix &vec) { + std::stringstream sst; + sst << vec.transpose(); + return sst.str(); +} + + +//template +//Eigen::Matrix & operator >> (std::istream &is, Eigen::Matrix &vec) { +//} + +template +void operator>> (std::string& str, Eigen::Matrix &vec){ + VectorxT_StringTo(vec,str); +} + + +//////////////////////////////////////////////////////////////////////////////// +////// HOMOGENEOUS VECTORS ////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +template +class _HPoint3f : public Eigen::Matrix< Scalarf,4,1 > { +public: + typedef Eigen::Matrix< Scalarf,4,1 > BaseClass; + + _HPoint3f

() : BaseClass(0,0,0,p) {} + _HPoint3f

(float x,float y,float z) : BaseClass(x,y,z,p) {} + _HPoint3f

(Vector3f &in) : BaseClass(in.homogeneous()) { this->operator()(3) = p; } + + void operator delete(void* _p, size_t _s) {} + + // This constructor allows to construct MyVectorType from Eigen expressions + template + inline _HPoint3f

(const Eigen::MatrixBase& other) + : BaseClass(other) + { } + + // This method allows to assign Eigen expressions to Vector3H + template + inline _HPoint3f

& operator= (const Eigen::MatrixBase & other) + { + this->BaseClass::operator=(other); + return *this; + } + +}; +typedef _HPoint3f HVector3f; +typedef _HPoint3f HPoint3f; + + + + +//////////////////////////////////////////////////////////////////////////////// +////// HOMOGENEOUS LINE ////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +struct _HLine3f +{ + HPoint3f origin; + HVector3f direction; +}; +typedef struct _HLine3f HLine3f; + +inline std::ostream& +operator<< (std::ostream& stream, const HLine3f &line) { + stream << "HLine3f(" << "pt[" << line.origin.transpose() <<"] , dr[" << line.direction.transpose() << "]) "; + return stream; +} + + + + +struct _HError3f +{ + HVector3f position_error; + HVector3f direction_error; +}; +typedef struct _HError3f HError3f; + +inline std::ostream& +operator<< (std::ostream& stream, const HError3f &err) { + stream << "HError3f(" << "ept[" << err.position_error.transpose() <<"] , edr[" << err.direction_error.transpose() << "]) "; + return stream; +} + + +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// SERIALIZTION // + +ULIB_SERIALIZABLE(uLib::HPoint3f) + +ULIB_SERIALIZABLE(uLib::HVector3f) + + +ULIB_SERIALIZABLE(uLib::HLine3f) + +ULIB_SERIALIZABLE(uLib::HError3f) + + + + + +#endif // U_DENSEMATRIX_H diff --git a/src/Math/Geometry.h b/src/Math/Geometry.h new file mode 100644 index 0000000..c2c9912 --- /dev/null +++ b/src/Math/Geometry.h @@ -0,0 +1,60 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_GEOMETRY_H +#define U_GEOMETRY_H + +#include "Core/Object.h" +#include "Math/Dense.h" +#include "Math/Transform.h" + +namespace uLib { + +class Geometry : public AffineTransform { +public: + + inline Vector4f GetWorldPoint(const Vector4f &v) const { + return this->GetWorldMatrix() * v; + } + + inline Vector4f GetWorldPoint(const float x, const float y, const float z) { + return this->GetWorldPoint(Vector4f(x,y,z,1)); + } + + inline Vector4f GetLocalPoint(const Vector4f &v) const { + return this->GetWorldMatrix().inverse() * v; + } + + inline Vector4f GetLocalPoint(const float x, const float y, const float z) { + return this->GetLocalPoint(Vector4f(x,y,z,1)); + } +}; + + +} + +#endif // GEOMETRY_H diff --git a/src/Math/Makefile.am b/src/Math/Makefile.am new file mode 100644 index 0000000..e8add8c --- /dev/null +++ b/src/Math/Makefile.am @@ -0,0 +1,42 @@ +SUBDIRS = . + +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Math +library_include_HEADERS = ContainerBox.h \ + Dense.h \ + Geometry.h \ + Transform.h \ + StructuredData.h\ + StructuredGrid.h\ + VoxImage.h \ + VoxRaytracer.h \ + Utils.h \ + VoxImageFilter.h\ + VoxImageFilter.hpp \ + VoxImageFilterLinear.hpp \ + VoxImageFilterMedian.hpp \ + VoxImageFilterABTrim.hpp \ + VoxImageFilterBilateral.hpp \ + VoxImageFilterThreshold.hpp \ + VoxImageFilter2ndStat.hpp \ + VoxImageFilterCustom.hpp \ + Accumulator.h \ + TriangleMesh.h + + +_MATH_SOURCES = \ + VoxRaytracer.cpp \ + StructuredData.cpp \ + StructuredGrid.cpp \ + VoxImage.cpp \ + TriangleMesh.cpp \ + Dense.cpp + + + + +noinst_LTLIBRARIES = libmutommath.la +libmutommath_la_SOURCES = ${_MATH_SOURCES} + + diff --git a/src/Math/Polydata.h b/src/Math/Polydata.h new file mode 100644 index 0000000..4cd462f --- /dev/null +++ b/src/Math/Polydata.h @@ -0,0 +1,48 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef POLYDATA_H +#define POLYDATA_H + +#include "Core/Object.h" + +namespace uLib { + +class Polydata : public Object { + +public: + + + +}; + + +} + + + +#endif // POLYDATA_H diff --git a/src/Math/Quote.h b/src/Math/Quote.h new file mode 100644 index 0000000..f10f042 --- /dev/null +++ b/src/Math/Quote.h @@ -0,0 +1,49 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MATH_QUOTE_H +#define U_MATH_QUOTE_H + +#include "Math/Dense.h" + +namespace uLib { + +class Quote : public Vector2f { +public: + + + uLibRefMacro(Offset,Scalarf); + +private: + Scalarf m_Offset; +}; + + +} // uLib + + +#endif // QUOTE_H diff --git a/src/Math/StructuredData.cpp b/src/Math/StructuredData.cpp new file mode 100644 index 0000000..456747a --- /dev/null +++ b/src/Math/StructuredData.cpp @@ -0,0 +1,80 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "StructuredData.h" + +using namespace uLib; + +StructuredData::StructuredData(const Vector3i &size) : + m_Dims(size) +{ + SetDataOrder(); +} + +void StructuredData::SetDims(const Vector3i &size) +{ + this->m_Dims = size; + SetDataOrder(); +} + +void StructuredData::SetDataOrder(StructuredData::Order order) +{ + int i = order & 0x3; + int j = (order >> 2) & 0x3; + int k = (order >> 4) & 0x3; + this->m_Increments[i] = 1; + this->m_Increments[j] = m_Dims[i]; + this->m_Increments[k] = m_Dims[i] * m_Dims[j]; + this->m_DataOrder = order; +} + +bool StructuredData::IsInsideGrid(const Vector3i &v) const +{ + int vok = 1; + vok *= (v(0) >= 0 && v(0) < m_Dims[0]); + vok *= (v(1) >= 0 && v(1) < m_Dims[1]); + vok *= (v(2) >= 0 && v(2) < m_Dims[2]); + return vok; +} + + + +Vector3i StructuredData::UnMap(int index) const +{ + Vector3i v( 0,0,0 ); + Vector3i iv = m_Increments; + int id = 0; + for(int k=0; k<3; ++k) { + int inc = iv.maxCoeff(&id); + v(id) = index / inc; + index -= v(id) * inc; + iv(id) = 0; + } + return v; +} + + diff --git a/src/Math/StructuredData.h b/src/Math/StructuredData.h new file mode 100644 index 0000000..f92b6d0 --- /dev/null +++ b/src/Math/StructuredData.h @@ -0,0 +1,101 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef STRUCTUREDDATA_H +#define STRUCTUREDDATA_H + +#include "Core/Macros.h" +#include "Core/Object.h" +#include "Math/Dense.h" + +namespace uLib { + +class StructuredData : public Object { +public: + typedef Object BaseClass; + enum _Order + { + CustomOrder = 0, + XYZ = 0 | 1 << 2 | 2 << 4, + XZY = 0 | 2 << 2 | 1 << 4, + YXZ = 1 | 0 << 2 | 2 << 4, + YZX = 2 | 0 << 2 | 1 << 4, + ZXY = 1 | 2 << 2 | 0 << 4, + ZYX = 2 | 1 << 2 | 0 << 4 + }; + + typedef enum _Order Order; + + StructuredData(const Vector3i &size); + + StructuredData(const StructuredData ©) : + BaseClass(copy), + m_DataOrder(copy.m_DataOrder), + m_Dims(copy.m_Dims), + m_Increments(copy.m_Increments) + {} + + + uLibGetMacro(Dims,Vector3i) + + void SetDims(const Vector3i &size); + + uLibGetSetMacro(Increments,Vector3i) + + void SetDataOrder(Order order = YXZ); + + uLibGetMacro(DataOrder,Order) + + bool IsInsideGrid(const Vector3i &v) const; + + inline int Map(Vector3i index) const; + + Vector3i UnMap(int index) const; + +private: + Order m_DataOrder; + Vector3i m_Dims; + Vector3i m_Increments; //TODO: make this line matrix // +}; + + + +// --- INLINES -------------------------------------------------------------- // + + +inline int StructuredData::Map(Vector3i index) const +{ + return (m_Increments.transpose() * index); +} + + + + + +} + +#endif // STRUCTUREDDATA_H diff --git a/src/Math/StructuredGrid.cpp b/src/Math/StructuredGrid.cpp new file mode 100644 index 0000000..89b0548 --- /dev/null +++ b/src/Math/StructuredGrid.cpp @@ -0,0 +1,66 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "StructuredGrid.h" + +namespace uLib { + +StructuredGrid::StructuredGrid(const Vector3i &size) : + StructuredData(size) +{} + +bool StructuredGrid::IsInsideBounds(const Vector4f &pt) const +{ + Vector4f ptl = this->GetLocalPoint(pt); + int result = 0; + for ( int i=0; i<3 ;++i) { + result += ptl(i) > (float)this->GetDims()(i); + result += ptl(i) < 0; + } + return result == 0; +} + +Vector3i StructuredGrid::Find(const HPoint3f &pt) const +{ + Vector3i out; + HPoint3f p = GetLocalPoint(pt); + out << (int)floor(p(0)), + (int)floor(p(1)), + (int)floor(p(2)); + return out; +} + +void StructuredGrid::PrintSelf(std::ostream &o) +{ + o << "uLib Structured Grid: \n" + << "dim = " << this->GetDims().transpose() << "\n" + << "spacing = " << this->GetSpacing().transpose() << "\n"; +} + + +} diff --git a/src/Math/StructuredGrid.h b/src/Math/StructuredGrid.h new file mode 100644 index 0000000..a389332 --- /dev/null +++ b/src/Math/StructuredGrid.h @@ -0,0 +1,75 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MATH_STRUCTUREDGRID_H +#define U_MATH_STRUCTUREDGRID_H + +#include "Core/Object.h" +#include "Math/ContainerBox.h" +#include "Math/StructuredData.h" + +namespace uLib { + + +class StructuredGrid : public ContainerBox, public StructuredData { + typedef ContainerBox BaseClass; +public: + StructuredGrid(const Vector3i &size); + + // TODO: Add SetSize of Container .. adjusting spacing // + + using ContainerBox::SetOrigin; + + inline void SetSpacing(const Vector3f &spacing); + + inline Vector3f GetSpacing() const; + + bool IsInsideBounds(const Vector4f &pt) const; + + Vector3i Find(const HPoint3f &pt) const; + + void PrintSelf(std::ostream &o); +}; + + + +// --- INLINES -------------------------------------------------------------- // + +inline void StructuredGrid::SetSpacing(const Vector3f &spacing) +{ + ContainerBox::SetSize(spacing); +} + +inline Vector3f StructuredGrid::GetSpacing() const +{ + return ContainerBox::GetSize(); +} + + +} + +#endif // STRUCTUREDGRID_H diff --git a/src/Math/Transform.h b/src/Math/Transform.h new file mode 100644 index 0000000..9982a89 --- /dev/null +++ b/src/Math/Transform.h @@ -0,0 +1,139 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * Copyright (C) 2012 Andrea Rigoni Garola + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + + +#ifndef U_TRANSFORM_H +#define U_TRANSFORM_H + +#include +#include + + +namespace uLib { + +//////////////////////////////////////////////////////////////////////////////// +///////// AFFINE TRANSFORM WRAPPER ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +class AffineTransform { +protected: + Eigen::Affine3f m_T; + AffineTransform *m_Parent; +public: + AffineTransform() : + m_T(Matrix4f::Identity()), + m_Parent(NULL) + {} + + AffineTransform(AffineTransform *parent) : + m_T(Matrix4f::Identity()), + m_Parent(parent) + {} + + AffineTransform(const AffineTransform ©) : + m_T(copy.m_T), + m_Parent(copy.m_Parent) + {} + + Eigen::Affine3f& GetTransform() { return m_T; } + uLibGetSetMacro(Parent,AffineTransform *) + + inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; } + inline Matrix4f& GetMatrix () { return m_T.matrix(); } + + Matrix4f GetWorldMatrix() const + { + if(!m_Parent) return m_T.matrix(); + else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A // + } + + inline void SetPosition(const Vector3f &v) { this->m_T.translation() = v; } + + inline Vector3f GetPosition() const { return this->m_T.translation(); } + + inline void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; } + + inline Matrix3f GetRotation() const { return this->m_T.rotation(); } + + inline void Translate(const Vector3f &v) { this->m_T.translate(v); } + + inline void Scale(const Vector3f &v) { this->m_T.scale(v); } + + inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX + + + inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); } + + + inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); } + + inline void QuaternionRotate(const Vector4f &q) + { this->m_T.rotate(Eigen::Quaternion(q)); } + + inline void EulerYZYRotate(const Vector3f &e) { + Matrix3f mat; + mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY()) + * Eigen::AngleAxisf(e.y(), Vector3f::UnitZ()) + * Eigen::AngleAxisf(e.z(), Vector3f::UnitY()); + m_T.rotate(mat); + } + + inline void FlipAxes(int first, int second) + { + Matrix3f mat = Matrix3f::Identity(); + mat.col(first).swap(mat.col(second)); + m_T.rotate(mat); + } +}; + + + +} + + + +#endif//U_TRANSFORM_H diff --git a/src/Math/TriangleMesh.cpp b/src/Math/TriangleMesh.cpp new file mode 100644 index 0000000..d8828ef --- /dev/null +++ b/src/Math/TriangleMesh.cpp @@ -0,0 +1,69 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "TriangleMesh.h" + + +namespace uLib { + +void TriangleMesh::PrintSelf(std::ostream &o) +{ + o << " // ------- TRIANGLE MESH ------- // \n" ; + o << " #Points : " << m_Points.size() << "\n"; + o << " #Triang : " << m_Triangles.size() << "\n"; + for(int i=0; i < m_Triangles.size(); ++i ) { + o << " - triangle[" << i << "]" << + " " << m_Triangles[i](0) << + "->(" << m_Points[m_Triangles[i](0)].transpose() << ") " << + " " << m_Triangles[i](1) << + "->(" << m_Points[m_Triangles[i](1)].transpose() << ") " << + " " << m_Triangles[i](2) << + "->(" << m_Points[m_Triangles[i](2)].transpose() << ") " << + " \n"; + } + o << " // ----------------------------- // \n"; +} + +void TriangleMesh::AddPoint(const Vector3f &pt) +{ + this->m_Points.push_back(pt); +} + +void TriangleMesh::AddTriangle(const Id_t *id) +{ + Vector3i triangle(id[0],id[1],id[2]); + this->m_Triangles.push_back(triangle); +} + +void TriangleMesh::AddTriangle(const Vector3i &id) +{ + this->m_Triangles.push_back(id); +} + + +} diff --git a/src/Math/TriangleMesh.h b/src/Math/TriangleMesh.h new file mode 100644 index 0000000..0fdebac --- /dev/null +++ b/src/Math/TriangleMesh.h @@ -0,0 +1,59 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef TRIANGLEMESH_H +#define TRIANGLEMESH_H + +#include "Core/Object.h" +#include "Core/Vector.h" +#include "Math/Dense.h" + +namespace uLib { + +class TriangleMesh : public Object { + +public: + void PrintSelf(std::ostream &o); + + void AddPoint(const Vector3f &pt); + + void AddTriangle(const Id_t *id); + void AddTriangle(const Vector3i &id); + + uLibRefMacro(Points,Vector) + uLibRefMacro(Triangles,Vector) + +private: + Vector m_Points; + Vector m_Triangles; + +}; + +} + + +#endif // TRIANGLEMESH_H diff --git a/src/Math/Utils.h b/src/Math/Utils.h new file mode 100644 index 0000000..55d62f4 --- /dev/null +++ b/src/Math/Utils.h @@ -0,0 +1,53 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_UTILS_H +#define U_UTILS_H + +#include +#include +#include + +#define fastSign(x) ((x>0)-(x<0)) + +namespace uLib { + +inline bool isFinite(float x) { + return (x<=FLT_MAX && x>= -FLT_MAX); +} + +inline bool isFinite(double x) { + return (x<=DBL_MAX && x>= -DBL_MAX); +} + +template int sign(T val) { + return (T(0) < val) - (val < T(0)); +} + +} + +#endif // UTILS_H diff --git a/src/Math/VoxImage.cpp b/src/Math/VoxImage.cpp new file mode 100644 index 0000000..55c4e36 --- /dev/null +++ b/src/Math/VoxImage.cpp @@ -0,0 +1,193 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include + +#include "VoxImage.h" + + +namespace uLib { + +void Abstract::VoxImage::ExportToVtk (const char *file, bool density_type) +{ + FILE * vtk_file = fopen(file,"wb"); + assert(vtk_file); + Abstract::VoxImage *voxels = this; + float norm; + if (density_type) { + norm = 1; + } else norm = 1.E6; + int nx = voxels->GetDims()(0); + int ny = voxels->GetDims()(1); + int nz = voxels->GetDims()(2); + + fprintf(vtk_file, + "# vtk DataFile Version 2.0\n" + "Image Builder vtk output\n" + "ASCII\n" + "DATASET STRUCTURED_POINTS\n" + "DIMENSIONS %d %d %d\n" + "SPACING %f %f %f\n" + "ORIGIN %f %f %f\n" + "POINT_DATA %d\n" + "SCALARS volume_scalars float 1\n" + "LOOKUP_TABLE default\n", + nx , ny , nz , + voxels->GetSpacing()(0), + voxels->GetSpacing()(1), + voxels->GetSpacing()(2), + voxels->GetPosition()(0), // FIX FOR ORIGIN // + voxels->GetPosition()(1), + voxels->GetPosition()(2), + nx * ny * nz + ); + + Vector3i index(0,0,0); + for (int zv = 0; zv < nz; ++zv) { + for (int yv = 0; yv < ny; ++yv) { + for (int xv = 0; xv < nx; ++xv) { + index << xv,yv,zv; + // write voxel density in mrad^2/cm // + float density = (voxels->GetValue(index)) * norm; + fprintf(vtk_file, "%f ", density); + } + } + } + + fclose(vtk_file); + printf("%s vtk file saved\n",file); +} + +int Abstract::VoxImage::ImportFromVtk(const char *file) +{ + FILE * vtk_file = fopen(file, "r"); + if (!vtk_file) return false; + + char word[20]; + int dx, dy, dz, n_tot; + float sx, sy, sz, ox, oy, oz; + do { + fscanf(vtk_file, "%s", word); + } while (strcmp(word, "DIMENSIONS")); + fscanf(vtk_file, "%d %d %d", &dx, &dy, &dz); + do { + fscanf(vtk_file, "%s", word); + } while (strcmp(word, "SPACING")); + fscanf(vtk_file, "%f %f %f", &sx, &sy, &sz); + do { + fscanf(vtk_file, "%s", word); + } while (strcmp(word, "ORIGIN")); + fscanf(vtk_file, "%f %f %f", &ox, &oy, &oz); + do { + fscanf(vtk_file, "%s", word); + } while (strcmp(word, "POINT_DATA")); + fscanf(vtk_file, "%d", &n_tot); + do { + fscanf(vtk_file, "%s", word); + } while (strcmp(word, "default")); + + this->SetDims(Vector3i(dx,dy,dz)); + this->SetSpacing(Vector3f(sx,sy,sz)); + this->SetPosition(Vector3f(ox,oy,oz)); + + for (int k = 0; k < dz; ++k) { + for (int j = 0; j < dy; ++j) { + for (int i = 0; i < dx; ++i) { + Vector3i idx(i, j, k); + float tmp_val; + fscanf(vtk_file, "%f", &tmp_val); + //this->SetValue(idx,fabs(tmp_val)*1E-6); + this->SetValue(idx,tmp_val*1E-6); + } + } + } + fclose(vtk_file); + return true; +} + +void Abstract::VoxImage::ExportToVtkXml(const char *file, bool density_type) +{ + // Not implemented yet // + FILE * vtk_file = fopen(file,"wb"); + assert(vtk_file); + Abstract::VoxImage *voxels = this; + float norm; + if (density_type) { + norm = 40000; + } else norm = 1.E6; + int nx = voxels->GetDims()(0); + int ny = voxels->GetDims()(1); + int nz = voxels->GetDims()(2); + + fprintf(vtk_file, + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + "\n", + nx, ny, nz, + voxels->GetPosition()(0), // FIX FOR ORIGIN // + voxels->GetPosition()(1), + voxels->GetPosition()(2), + voxels->GetSpacing()(0), + voxels->GetSpacing()(1), + voxels->GetSpacing()(2), + nx, ny, nz + ); + Vector3i index(0,0,0); + for (int zv = 0; zv < nz; ++zv) { + for (int yv = 0; yv < ny; ++yv) { + for (int xv = 0; xv < nx; ++xv) { + index << xv,yv,zv; + // write voxel density in mrad^2/cm // + float density = fabs(voxels->GetValue(index)) * norm; + fprintf(vtk_file, "%f ", density); + } + } + } + fprintf(vtk_file, + "\n \n \n"); + + fprintf(vtk_file, + "\n \n \n"); + fclose(vtk_file); + printf("%s vtk file saved\n",file); +} + + + + +} + diff --git a/src/Math/VoxImage.h b/src/Math/VoxImage.h new file mode 100644 index 0000000..45db72c --- /dev/null +++ b/src/Math/VoxImage.h @@ -0,0 +1,493 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_MATH_VOXIMAGE_H +#define U_MATH_VOXIMAGE_H + +#include "Core/Vector.h" +#include "Core/StaticInterface.h" +#include "Math/Dense.h" +#include "Math/StructuredGrid.h" + +#include +#include + +namespace uLib { + +//////////////////////////////////////////////////////////////////////////////// +// ABSTRACT VOX IMAGE ////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace Abstract { + +class VoxImage : public uLib::StructuredGrid { +public: + typedef uLib::StructuredGrid BaseClass; + + virtual float GetValue(const Vector3i &id) const = 0; + virtual float GetValue(const int id) const = 0; + virtual void SetValue(const Vector3i &id, float value) = 0; + virtual void SetValue(const int id, float value) = 0; + + virtual void SetDims(const Vector3i &size) = 0; + + void ExportToVtk(const char *file, bool density_type = 0); + void ExportToVtkXml(const char *file, bool density_type = 0); + int ImportFromVtk(const char *file); + +protected: + + virtual ~VoxImage() {} + VoxImage(const Vector3i &size) : BaseClass(size) {} +}; + +} + +//////////////////////////////////////////////////////////////////////////////// +// VOXEL //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace Interface { +struct Voxel { + template void check_structural() { + uLibCheckMember(Self,Value, Scalarf); + } +}; +} + +struct Voxel { + Scalarf Value; +}; + + +//////////////////////////////////////////////////////////////////////////////// +// VOX IMAGE ///////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +template< typename T > +class VoxImage : public Abstract::VoxImage { +public: + typedef Abstract::VoxImage BaseClass; + + VoxImage(); + + VoxImage(const Vector3i &size); + + VoxImage(const VoxImage ©) : + BaseClass(copy) + { + this->m_Data = copy.m_Data; + } + + uLibRefMacro(Data,Vector) + inline const Vector& ConstData() const { return m_Data; } + + inline const T& At(int i) const { return m_Data.at(i); } + inline const T& At(const Vector3i &id) const { return m_Data.at(Map(id)); } + inline T& operator[](unsigned int i) { return m_Data[i]; } + inline T& operator[](const Vector3i &id) { return m_Data[Map(id)]; } + + // this implements Abstract interface // + inline Scalarf GetValue(const Vector3i &id) const { + return this->At(id).Value; + } + inline Scalarf GetValue(const int id) const { + return this->At(id).Value; + } + + inline void SetValue(const Vector3i &id, Scalarf value) { + this->operator [](id).Value = value; + } + inline void SetValue(const int id, float value) { + this->operator [](id).Value = value; + } + + inline void SetDims(const Vector3i &size) { + this->m_Data.resize(size.prod()); + BaseClass::BaseClass::SetDims(size); // FIX horrible coding style ! + } + + inline VoxImage clipImage(const Vector3i begin, const Vector3i end) const; + inline VoxImage clipImage(const HPoint3f begin, const HPoint3f end) const; + inline VoxImage clipImage(const float density) const; + inline VoxImage clipImage(const float densityMin, const float densityMax) const; + + inline VoxImage maskImage(const HPoint3f begin, const HPoint3f end, float value) const; + inline VoxImage maskImage(const float threshold, float belowValue=0, float aboveValue=0) const; + inline VoxImage fixVoxels(const float threshold, float tolerance) const; + inline VoxImage fixVoxels(const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end) const; + inline VoxImage fixVoxelsAroundPlane(const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end, bool aboveAir) const; + inline VoxImage fixVoxels(const HPoint3f begin, const HPoint3f end) const; + inline VoxImage Abs() const; + + inline void SelectScalarfComponent(T &element, Scalarf *scalar); + + inline void InitVoxels(T t); + + // MATH OPERATORS // + inline void operator *=(Scalarf scalar) { + for(unsigned int i = 0; i < m_Data.size(); ++i) + m_Data[i].Value *= scalar; + } + inline void operator +=(Scalarf scalar) { + for(unsigned int i = 0; i < m_Data.size(); ++i) + m_Data[i].Value += scalar; + } + inline void operator /=(Scalarf scalar) { + for(unsigned int i = 0; i < m_Data.size(); ++i) + m_Data[i].Value /= scalar; + } + inline void operator -=(Scalarf scalar) { + for(unsigned int i = 0; i < m_Data.size(); ++i) + m_Data[i].Value -= scalar; + } + + // MATH VoxImage Operators // + template + void operator +=(VoxImage &sibling) { + if (this->GetDims() != sibling.GetDims()) { + //printf("Warning when adding VoxImages: I'm NOT doing it!\n"); + return; + }// WARNING! You must Warn the user! + for(unsigned int i = 0; i < m_Data.size(); ++i) { + m_Data[i].Value += sibling.At(i).Value; + } + } + + template + void operator -=(VoxImage &sibling) { + if (this->GetDims() != sibling.GetDims()) { + //printf("Warning when subtracting VoxImages: I'm NOT doing it!\n"); + return; + }// WARNING! You must Warn the user! + for(unsigned int i = 0; i < m_Data.size(); ++i) { + m_Data[i].Value -= sibling.At(i).Value; + } + } + + template + void operator *=(VoxImage &sibling) { + if (this->GetDims() != sibling.GetDims()) { + //printf("Warning when multiplying VoxImages: I'm NOT doing it!\n"); + return; + }// WARNING! You must Warn the user! + for(unsigned int i = 0; i < m_Data.size(); ++i) { + m_Data[i].Value *= sibling.At(i).Value; + } + } + + template + void operator /=(VoxImage &sibling) { + if (this->GetDims() != sibling.GetDims()) { + //printf("Warning when dividing VoxImages: I'm NOT doing it!\n"); + return; + }// WARNING! You must Warn the user! + for(unsigned int i = 0; i < m_Data.size(); ++i) { + m_Data[i].Value /= sibling.At(i).Value; + } + } + +private: + Vector m_Data; +}; + + +template +VoxImage::VoxImage() : + m_Data(0), + BaseClass(Vector3i(0,0,0)) +{ Interface::IsA (); /* structural check for T */ } + +template +VoxImage::VoxImage(const Vector3i &size) : + m_Data(size.prod()), + BaseClass(size) +{ Interface::IsA (); /* structural check for T */ } + + +template +VoxImage VoxImage::clipImage(const Vector3i begin, const Vector3i end) const +{ + Vector3i dim = (end-begin)+Vector3i(1,1,1); + VoxImage out(*this); + out.SetDims(dim); + out.SetPosition(this->GetPosition() + this->GetSpacing().cwiseProduct(begin.cast()) ); + + for(uint x = 0; xAt(begin + id); + } + return out; +} + +template +VoxImage VoxImage::clipImage(const HPoint3f begin, const HPoint3f end) const +{ + Vector3i v1 = this->Find(begin); + Vector3i v2 = this->Find(end); + return this->clipImage(v1,v2); +} + +template +VoxImage VoxImage::clipImage(const float density) const +{ + Vector3i v1 = this->GetDims(); + Vector3i v2 = Vector3i(0,0,0); + for(uint i=0; i< this->m_Data.size(); ++i) { + if( this->GetValue(i) >= density ) { + Vector3i id = this->UnMap(i); + v1 = v1.array().min(id.array()); + v2 = v2.array().max(id.array()); + } + } + return this->clipImage(v1,v2); +} + +template +VoxImage VoxImage::clipImage(const float densityMin, const float densityMax) const +{ + Vector3i v1 = this->GetDims(); + Vector3i v2 = Vector3i(0,0,0); + for(uint i=0; i< this->m_Data.size(); ++i) { + if( this->GetValue(i) >= densityMin && this->GetValue(i) <= densityMax) { + Vector3i id = this->UnMap(i); + v1 = v1.array().min(id.array()); + v2 = v2.array().max(id.array()); + } + } + return this->clipImage(v1,v2); +} + +template +VoxImage VoxImage::maskImage(const HPoint3f begin, const HPoint3f end, float value) const +{ + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + Vector3i voxB = this->Find(begin); + Vector3i voxE = this->Find(end); + + Vector3i ID; + + for(int ix=voxB(0); ix +VoxImage VoxImage::maskImage(const float threshold, float belowValue, float aboveValue) const +{ + std::cout << "VoxImage: maskImage, fixing voxels under threshold " << threshold; + if(belowValue) + std::cout << " at value " << belowValue; + else + std::cout << " at -value"; + std::cout << ", voxels above threshold at value "; + if(aboveValue) + std::cout << aboveValue; + else + std::cout << "found"; + + + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + for(uint i=0; i< this->m_Data.size(); ++i) { + // skip negative voxels: they are already frozen + if( this->GetValue(i) >= 0 ){ + // voxels under threshold + if( this->GetValue(i) <= threshold*1.E-6 ){ + if(belowValue){ + // std::cout << "vox " << i << ", " << this->GetValue(i); + // std::cout << " ----> set to " << -1.*belowValue*1.E-6 << std::endl; + out.SetValue(i,-1.*belowValue*1.E-6);} + else + out.SetValue(i,-1.*this->GetValue(i)); + } + // voxels over threshold + else{ + if(aboveValue) + out.SetValue(i,aboveValue*1.E-6); + else + out.SetValue(i,this->GetValue(i)); + } + } + } + return out; +} + +template +VoxImage VoxImage::fixVoxels(const float threshold, float tolerance) const +{ + std::cout << "VoxImage: fixing voxels with value " << threshold << std::endl; + + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + for(uint i=0; i< this->m_Data.size(); ++i) { + // voxels around threshold + if( fabs(this->GetValue(i) - threshold*1.E-6) < tolerance* 1.E-6 ){ +// std::cout << "vox " << i << ", " << this->GetValue(i); +// std::cout << " ----> set to " << -1.*this->GetValue(i) << std::endl; + out.SetValue(i,-1.*this->GetValue(i)); + } + } + return out; +} + +template +VoxImage VoxImage::Abs() const +{ + std::cout << "VoxImage: set abs voxels value " << std::endl; + + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + for(uint i=0; i< this->m_Data.size(); ++i) + out.SetValue(i,fabs(this->GetValue(i))); + + return out; +} + +template +VoxImage VoxImage::fixVoxels( const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end) const +{ + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + Vector3i voxB = this->Find(begin); + Vector3i voxE = this->Find(end); + + Vector3i ID; + + for(int ix=voxB(0); ixGetValue(ID) - threshold*1.E-6) < tolerance*1.E-6 ){ + out.SetValue(ID,-1.*this->GetValue(ID)); + } + } + + return out; +} + +template +VoxImage VoxImage::fixVoxels(const HPoint3f begin, const HPoint3f end) const +{ + VoxImage out(*this); + out.SetDims(this->GetDims()); + out.SetPosition(this->GetPosition()); + + Vector3i voxB = this->Find(begin); + Vector3i voxE = this->Find(end); + + Vector3i ID; + + for(int ix=voxB(0); ixGetValue(ID)); + } + return out; +} + + +template +VoxImage VoxImage::fixVoxelsAroundPlane( const float threshold, float tolerance, const HPoint3f B, const HPoint3f E, bool aboveAir) const +{ + VoxImage out(*this); + Vector3i dim = this->GetDims(); + out.SetDims(dim); + out.SetPosition(this->GetPosition()); + + HPoint3f Bcoll = this->GetPosition().homogeneous(); + + Vector3i ID; + for(int ix=0; ix().cwiseProduct(this->GetSpacing())); + HPoint3f Bvox = Bcoll + HPoint3f(v); + HPoint3f Evox = Bvox + this->GetSpacing().homogeneous(); + HPoint3f V = Bvox + 0.5*(this->GetSpacing().homogeneous()); + + // if distance point (x0,y0) from line by points (x1,y1) and (x2,y2) is less than tolerance + float x1 = B[1]; + float y1 = B[2]; + float x2 = E[1]; + float y2 = E[2]; + float x0 = V[1]; + float y0 = V[2]; + float dist = fabs( (x2-x1)*(y1-y0) - ((x1-x0)*(y2-y1))) / sqrt( (x2-x1)*(x2-x1)+((y2-y1)*(y2-y1))); + float distSign = (x2-x1)*(y1-y0) - ((x1-x0)*(y2-y1)); + + // set voxel air value + if(dist < tolerance){ + //std::cout << "voxel " << iv << ", line " << dist << ", tolerance " << tolerance << std::endl; + out.SetValue(ID,threshold*1.E-6); + } + else + out.SetValue(ID,this->GetValue(ID)); + + if((distSign>0 && aboveAir) || (distSign<0 && !aboveAir) ) + out.SetValue(ID,threshold*1.E-6); + } + return out; +} + + +template +void VoxImage::InitVoxels(T t) +{ + std::fill( m_Data.begin(), m_Data.end(), t ); // warning... stl function // +} + +} + +#endif // VOXIMAGE_H diff --git a/src/Math/VoxImageFilter.h b/src/Math/VoxImageFilter.h new file mode 100644 index 0000000..c9fcf9d --- /dev/null +++ b/src/Math/VoxImageFilter.h @@ -0,0 +1,129 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTER_H +#define VOXIMAGEFILTER_H + +#include "Core/StaticInterface.h" +#include "Core/Object.h" +#include "Math/Dense.h" + +#include "Math/VoxImage.h" + + +namespace uLib { + + +namespace Interface { +struct VoxImageFilterShape { + template void check_structural() { + uLibCheckFunction(Self,operator(),float,float); + uLibCheckFunction(Self,operator(),float,const Vector3f&); + } +}; +} + +template < typename VoxelT > class Kernel; + + +namespace Abstract { +class VoxImageFilter { +public: + virtual void Run() = 0; + + virtual void SetImage(Abstract::VoxImage *image) = 0; + +protected: + virtual ~VoxImageFilter() {} +}; +} + + +template < typename VoxelT, typename AlgorithmT > +class VoxImageFilter : public Abstract::VoxImageFilter, public Object +{ + +public: + VoxImageFilter(const Vector3i &size); + + void Run(); + + void SetKernelNumericXZY(const Vector &numeric); + + void SetKernelSpherical(float (*shape)(float)); + + template < class ShapeT > + void SetKernelSpherical( ShapeT shape ); + + void SetKernelWeightFunction(float (*shape)(const Vector3f &)); + + template < class ShapeT > + void SetKernelWeightFunction( ShapeT shape ); + + uLibGetMacro(KernelData,Kernel) + + uLibGetMacro(Image,VoxImage *) + + void SetImage(Abstract::VoxImage *image); + +protected: + + float Convolve(const VoxImage &buffer, int index); // remove // + + void SetKernelOffset(); + + float Distance2(const Vector3i &v); + + // protected members for algorithm access // + Kernel m_KernelData; + VoxImage *m_Image; + +private: + AlgorithmT *t_Algoritm; + +}; + + + + + + +} + + +#endif // VOXIMAGEFILTER_H + +#include "VoxImageFilter.hpp" + +#include "VoxImageFilterLinear.hpp" +#include "VoxImageFilterThreshold.hpp" +#include "VoxImageFilterMedian.hpp" +#include "VoxImageFilterABTrim.hpp" +#include "VoxImageFilterBilateral.hpp" +#include "VoxImageFilter2ndStat.hpp" +#include "VoxImageFilterCustom.hpp" + diff --git a/src/Math/VoxImageFilter.hpp b/src/Math/VoxImageFilter.hpp new file mode 100644 index 0000000..621c208 --- /dev/null +++ b/src/Math/VoxImageFilter.hpp @@ -0,0 +1,302 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTER_HPP +#define VOXIMAGEFILTER_HPP + +#include +#include "Math/StructuredData.h" +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +namespace uLib { + + +// KERNEL ////////////////////////////////////////////////////////////////////// + +template < typename T > +class Kernel : public StructuredData { + typedef StructuredData BaseClass; +public: + Kernel(const Vector3i &size); + + inline T& operator[](const Vector3i &id) { return m_Data[Map(id)]; } + inline T& operator[](const int &id) { return m_Data[id]; } + inline int GetCenterData() const; + + uLibRefMacro(Data,Vector) + + inline const Vector& ConstData() const { return this->m_Data; } + + void PrintSelf(std::ostream &o) const; + +private: + Vector m_Data; +}; + +template < typename T > +Kernel::Kernel(const Vector3i &size) : + BaseClass(size), + m_Data(size.prod()) +{ + Interface::IsA(); +} + +template < typename T > +inline int Kernel::GetCenterData() const +{ + static int center = Map(this->GetDims() / 2); + return center; +} + +template < typename T > +void Kernel::PrintSelf(std::ostream &o) const +{ + o << " Filter Kernel Dump [XZ_Y]: \n"; + Vector3i index; + o << "\n Value: \n\n" + << "------------------------------------------------- \n"; + for (int y = 0 ; y < this->GetDims()(1); ++y ) { + o << "[y=" << y << "]\n"; + for (int z = 0 ; z < this->GetDims()(2); ++z ) { + for (int x = 0 ; x < this->GetDims()(0); ++x ) { + index << x,y,z; + o << m_Data[Map(index)].Value << " "; + } o << "\n"; + } o << " --------------------------------------------------- \n"; + } + o << "\n Offset: \n" + << "------------------------------------------------- \n"; + for (int y = 0 ; y < this->GetDims()(1); ++y ) { + o << "[y=" << y << "]\n"; + for (int z = 0 ; z < this->GetDims()(2); ++z ) { + for (int x = 0 ; x < this->GetDims()(0); ++x ) { + index << x,y,z; + o << m_Data[Map(index)].Count << " "; + } o << "\n"; + } o << " --------------------------------------------------- \n"; + } +} + +//////////////////////////////////////////////////////////////////////////////// + + + + + + + + +#define _TPL_ template < typename VoxelT , typename AlgorithmT > +#define _TPLT_ VoxelT,AlgorithmT + + + +_TPL_ +VoxImageFilter<_TPLT_>::VoxImageFilter(const Vector3i &size) : + m_KernelData(size), + t_Algoritm(static_cast(this)) +{ + +} + +_TPL_ +void VoxImageFilter<_TPLT_>::Run() +{ + VoxImage buffer = *m_Image; + #pragma omp parallel for + for(int i=0 ; i < m_Image->Data().size() ; ++i) + m_Image->operator [](i).Value = this->t_Algoritm->Evaluate(buffer,i); + #pragma omp barrier +} + +_TPL_ +void VoxImageFilter<_TPLT_>::SetKernelOffset() +{ + Vector3i id(0,0,0); + for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { + for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { + for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { + id << x,y,z; + m_KernelData[id].Count = id.transpose() * m_Image->GetIncrements(); + } + } + } +} + +_TPL_ +float VoxImageFilter<_TPLT_>::Distance2(const Vector3i &v) +{ + Vector3i tmp = v; + const Vector3i &dim = this->m_KernelData.GetDims(); + Vector3i center = dim / 2; + tmp = tmp - center; + center = center.cwiseProduct(center); + tmp = tmp.cwiseProduct(tmp); + return (float)(tmp.sum()) / (float)( center.sum() + 0.25 * + (3 - (dim(0) % 2) - (dim(1) % 2) - (dim(2) % 2))); +} + + +_TPL_ +void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(const Vector &numeric) +{ + // set data order // + StructuredData::Order order = m_KernelData.GetDataOrder(); + //m_KernelData.SetDataOrder(StructuredData::XZY); + Vector3i id; + int index = 0; + for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { + for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { + for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { + id << x,y,z; + m_KernelData[id].Value = numeric[index++]; + } + } + } + //m_KernelData.SetDataOrder(order); +} + +_TPL_ +void VoxImageFilter<_TPLT_>::SetKernelSpherical(float(* shape)(float)) +{ + Vector3i id; + for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { + for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { + for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { + id << x,y,z; + m_KernelData[id].Value = shape(this->Distance2(id)); + } + } + } +} + + +_TPL_ template +void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape) +{ + Interface::IsA(); + Vector3i id; + for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { + for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { + for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { + id << x,y,z; + m_KernelData[id].Value = shape(this->Distance2(id)); + } + } + } +} + +_TPL_ +void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(float (*shape)(const Vector3f &)) +{ + const Vector3i &dim = m_KernelData.GetDims(); + Vector3i id; + Vector3f pt; + for( int y=0 ; y < dim(1); ++y ) { + for( int z=0 ; z < dim(2); ++z ) { + for( int x=0 ; x < dim(0); ++x ) { + // get voxels centroid coords from kernel center // + id << x,y,z; + pt << id(0) - dim(0)/2 + 0.5 * !(dim(0) % 2), + id(1) - dim(1)/2 + 0.5 * !(dim(1) % 2), + id(2) - dim(2)/2 + 0.5 * !(dim(2) % 2); + // compute function using given shape // + m_KernelData[id].Value = shape(pt); + } + } + } +} + +_TPL_ template < class ShapeT > +void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape) +{ + Interface::IsA(); + const Vector3i &dim = m_KernelData.GetDims(); + Vector3i id; + Vector3f pt; + for( int y=0 ; y < dim(1); ++y ) { + for( int z=0 ; z < dim(2); ++z ) { + for( int x=0 ; x < dim(0); ++x ) { + // get voxels centroid coords from kernel center // + id << x,y,z; + pt << id(0) - dim(0)/2 + 0.5 * !(dim(0) % 2), + id(1) - dim(1)/2 + 0.5 * !(dim(1) % 2), + id(2) - dim(2)/2 + 0.5 * !(dim(2) % 2); + // compute function using given shape // + m_KernelData[id].Value = shape(pt); + } + } + } +} + + + + +_TPL_ +void VoxImageFilter<_TPLT_>::SetImage(Abstract::VoxImage *image) +{ + this->m_Image = reinterpret_cast *> (image); + this->SetKernelOffset(); +} + + +_TPL_ +float VoxImageFilter<_TPLT_>::Convolve(const VoxImage &buffer, int index) +{ + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + float conv = 0, ksum = 0; + for (int ik = 0; ik < ker_size; ++ik) { + pos = index + vker[ik].Count - vker[m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + conv += vbuf[pos].Value * vker[ik].Value; + ksum += vker[ik].Value; + } + return conv / ksum; +} + + + +#undef _TPLT_ +#undef _TPL_ + + + + + + + +} + + + + +#endif // VOXIMAGEFILTER_HPP diff --git a/src/Math/VoxImageFilter2ndStat.hpp b/src/Math/VoxImageFilter2ndStat.hpp new file mode 100644 index 0000000..d85acc7 --- /dev/null +++ b/src/Math/VoxImageFilter2ndStat.hpp @@ -0,0 +1,83 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTER2NDSTAT_HPP +#define VOXIMAGEFILTER2NDSTAT_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER ABTRIM ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + +template +class VoxFilterAlgorithm2ndStat : + public VoxImageFilter > { + +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithm2ndStat(const Vector3i &size) : + BaseClass(size) + { } + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + // mean // + float conv = 0, ksum = 0; + for (int ik = 0; ik < ker_size; ++ik) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + conv += vbuf[pos].Value * vker[ik].Value; + ksum += vker[ik].Value; + } + float mean = conv / ksum; + + // rms // + conv = 0; + for (int ik = 0; ik < ker_size; ++ik) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + conv += pow((vbuf[pos].Value * vker[ik].Value) - mean , 2); + } + return conv / (vker.size() - 1) ; + } + + +}; + +} +#endif // VOXIMAGEFILTER2NDSTAT_HPP diff --git a/src/Math/VoxImageFilterABTrim.hpp b/src/Math/VoxImageFilterABTrim.hpp new file mode 100644 index 0000000..0b1799c --- /dev/null +++ b/src/Math/VoxImageFilterABTrim.hpp @@ -0,0 +1,179 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERABTRIM_HPP +#define VOXIMAGEFILTERABTRIM_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER ABTRIM ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + +template +class VoxFilterAlgorithmAbtrim : + public VoxImageFilter > { + + struct KernelSortAscending + { + bool operator()(const VoxelT& e1, const VoxelT& e2) + { return e1.Value < e2.Value; } + }; + +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmAbtrim(const Vector3i &size) : + BaseClass(size) + { + mAtrim = 0; + mBtrim = 0; + } + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + Vector mfh(ker_size); + for (int i = 0; i < ker_size; ++i) + mfh[i].Count = i; //index key for ordering function + for (int ik = 0; ik < ker_size; ik++) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + mfh[ik].Value = vbuf[pos].Value; + } + + std::sort(mfh.begin(), mfh.end(), KernelSortAscending()); + float ker_sum = 0; + float fconv = 0; + for (int ik = 0; ik < mAtrim; ik++) + ker_sum += vker[ mfh[ik].Count ].Value; + for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) { + fconv += mfh[ik].Value * vker[ mfh[ik].Count ].Value; // convloution // + ker_sum += vker[ mfh[ik].Count ].Value; + } + for (int ik = ker_size - mBtrim; ik < ker_size; ik++) + ker_sum += vker[ mfh[ik].Count ].Value; + + return fconv / ker_sum; + } + + inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; } + +private: + int mAtrim; + int mBtrim; +}; + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Roberspierre Filter // + + + +template +class VoxFilterAlgorithmSPR : + public VoxImageFilter > { + + struct KernelSortAscending + { + bool operator()(const VoxelT& e1, const VoxelT& e2) + { return e1.Value < e2.Value; } + }; + +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmSPR(const Vector3i &size) : + BaseClass(size) + { + mAtrim = 0; + mBtrim = 0; + } + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + Vector mfh(ker_size); + for (int i = 0; i < ker_size; ++i) + mfh[i].Count = i; //index key for ordering function + for (int ik = 0; ik < ker_size; ik++) { + pos = index + vker[ik].Count - + vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + mfh[ik].Value = vbuf[pos].Value; + } + + std::sort(mfh.begin(), mfh.end(), KernelSortAscending()); + float spr = vbuf[index].Value; + if( (mAtrim > 0 && spr <= mfh[mAtrim-1].Value) || + (mBtrim > 0 && spr >= mfh[ker_size - mBtrim].Value) ) + { + float ker_sum = 0; + float fconv = 0; + for (int ik = 0; ik < mAtrim; ik++) + ker_sum += vker[ mfh[ik].Count ].Value; + for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) { + fconv += mfh[ik].Value * vker[ mfh[ik].Count ].Value; + ker_sum += vker[ mfh[ik].Count ].Value; + } + for (int ik = ker_size - mBtrim; ik < ker_size; ik++) + ker_sum += vker[ mfh[ik].Count ].Value; + + return fconv / ker_sum; + } + else + return spr; + } + + inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; } + +private: + int mAtrim; + int mBtrim; +}; + + + + +} + +#endif // VOXIMAGEFILTERABTRIM_HPP diff --git a/src/Math/VoxImageFilterBilateral.hpp b/src/Math/VoxImageFilterBilateral.hpp new file mode 100644 index 0000000..ade0f6e --- /dev/null +++ b/src/Math/VoxImageFilterBilateral.hpp @@ -0,0 +1,152 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERBILATERAL_HPP +#define VOXIMAGEFILTERBILATERAL_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER LINEAR ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + + +template +class VoxFilterAlgorithmBilateral : + public VoxImageFilter > { +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmBilateral(const Vector3i &size) : BaseClass(size) { + m_sigma = 1; + } + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + float conv = 0, ksum = 0; + float gamma_smooth; + for (int ik = 0; ik < ker_size; ++ik) { + // if (ik==this->m_KernelData.GetCenterData()) continue; + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + gamma_smooth = compute_gauss( fabs(vbuf[index].Value - vbuf[pos].Value) * 1.E6 ); + conv += vbuf[pos].Value * vker[ik].Value * gamma_smooth; + ksum += vker[ik].Value * gamma_smooth; + } + return conv / ksum; + } + + inline void SetIntensitySigma(const float s) { m_sigma = s; } + +private: + inline float compute_gauss(const float x) { + return 1/(sqrt(2*M_PI)* m_sigma) * exp(-0.5*(x*x)/(m_sigma*m_sigma)); + } + + Scalarf m_sigma; +}; + + +template +class VoxFilterAlgorithmBilateralTrim : + public VoxImageFilter > { + + typedef std::pair FPair; + + struct KernelSortAscending + { + bool operator()(const FPair& e1, const FPair& e2) + { return e1.second < e2.second; } + }; + +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmBilateralTrim(const Vector3i &size) : BaseClass(size) { + m_sigma = 1; + mAtrim = 0; + mBtrim = 0; + } + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int img_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + + + Vector mfh(ker_size); + for (int i = 0; i < ker_size; ++i) + mfh[i].first = vker[i].Value; // kernel value in first + for (int ik = 0; ik < ker_size; ik++) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + img_size) % img_size; + mfh[ik].second = vbuf[pos].Value; // image value in second + } + std::sort(mfh.begin(), mfh.end(), KernelSortAscending()); + + float conv = 0, ksum = 0; + float gamma_smooth; + // for (int ik = 0; ik < mAtrim; ik++) + // ksum += mfh[ik].first; + for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) { + gamma_smooth = compute_gauss( fabs(vbuf[index].Value - mfh[ik].second) * 1.E6 ); + conv += mfh[ik].first * mfh[ik].second * gamma_smooth; + ksum += mfh[ik].first * gamma_smooth; + } + // for (int ik = ker_size - mBtrim; ik < ker_size; ik++) + // ksum += mfh[ik].first; + + return conv / ksum; + } + + inline void SetIntensitySigma(const float s) { m_sigma = s; } + inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; } + +private: + inline float compute_gauss(const float x) { + return 1/(sqrt(2*M_PI)* m_sigma) * exp(-0.5*(x*x)/(m_sigma*m_sigma)); + } + + Scalarf m_sigma; + int mAtrim; + int mBtrim; +}; + +} + +#endif // VOXIMAGEFILTERBILATERAL_HPP diff --git a/src/Math/VoxImageFilterCustom.hpp b/src/Math/VoxImageFilterCustom.hpp new file mode 100644 index 0000000..831dbec --- /dev/null +++ b/src/Math/VoxImageFilterCustom.hpp @@ -0,0 +1,88 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERCUSTOM_HPP +#define VOXIMAGEFILTERCUSTOM_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER CUSTOM ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + +template +class VoxFilterAlgorithmCustom : + public VoxImageFilter > { + + + typedef float (* FunctionPt)(const Vector &); +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmCustom(const Vector3i &size) : + BaseClass(size), m_CustomEvaluate(NULL) + {} + + float Evaluate(const VoxImage &buffer, int index) + { + if(likely(m_CustomEvaluate)) { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + float ker_sum = 0; + Vector mfh(ker_size); + for (int ik = 0; ik < ker_size; ik++) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + mfh[ik] = vbuf[pos].Value * vker[ik].Value; + ker_sum += vker[ik].Value; + } + + return this->m_CustomEvaluate(mfh); + } + else + std::cerr << "Custom evaluate function is NULL \n" << + "No operation performed by filter.\n"; + + } + + uLibSetMacro(CustomEvaluate,FunctionPt) + +private: + FunctionPt m_CustomEvaluate; +}; + +} + + +#endif // VOXIMAGEFILTERCUSTOM_HPP diff --git a/src/Math/VoxImageFilterLinear.hpp b/src/Math/VoxImageFilterLinear.hpp new file mode 100644 index 0000000..14b9112 --- /dev/null +++ b/src/Math/VoxImageFilterLinear.hpp @@ -0,0 +1,69 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERLINEAR_HPP +#define VOXIMAGEFILTERLINEAR_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER LINEAR ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + + +template +class VoxFilterAlgorithmLinear : + public VoxImageFilter > { +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmLinear(const Vector3i &size) : BaseClass(size) {} + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + float conv = 0, ksum = 0; + for (int ik = 0; ik < ker_size; ++ik) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + conv += vbuf[pos].Value * vker[ik].Value; + ksum += vker[ik].Value; + } + return conv / ksum; + } +}; + +} + +#endif // VOXIMAGEFILTERLINEAR_HPP diff --git a/src/Math/VoxImageFilterMedian.hpp b/src/Math/VoxImageFilterMedian.hpp new file mode 100644 index 0000000..e4f88c4 --- /dev/null +++ b/src/Math/VoxImageFilterMedian.hpp @@ -0,0 +1,75 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERMEDIAN_HPP +#define VOXIMAGEFILTERMEDIAN_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER MEDIAN ///////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + +template +class VoxFilterAlgorithmMedian : + public VoxImageFilter > { +public: + typedef VoxImageFilter > BaseClass; + VoxFilterAlgorithmMedian(const Vector3i &size) : BaseClass(size) {} + + float Evaluate(const VoxImage &buffer, int index) + { + const Vector &vbuf = buffer.ConstData(); + const Vector &vker = this->m_KernelData.ConstData(); + int vox_size = vbuf.size(); + int ker_size = vker.size(); + int pos; + + Vector mfh(ker_size); + for (int ik = 0; ik < ker_size; ik++) { + pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; + pos = (pos + vox_size) % vox_size; + mfh[ik] = vbuf[pos].Value * vker[ik].Value; + } + std::sort(mfh.begin(), mfh.end()); + pos = 0; + // count zeroes in filter kernel to move it out of median // + for (int i = 0; i < ker_size; ++i) + if (vker[i].Value == 0.0) pos++; + // median // + pos += (ker_size - pos) / 2; + return mfh[pos]; + } +}; + +} + +#endif // VOXIMAGEFILTERMEDIAN_HPP diff --git a/src/Math/VoxImageFilterThreshold.hpp b/src/Math/VoxImageFilterThreshold.hpp new file mode 100644 index 0000000..e125763 --- /dev/null +++ b/src/Math/VoxImageFilterThreshold.hpp @@ -0,0 +1,78 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXIMAGEFILTERTHRESHOLD_HPP +#define VOXIMAGEFILTERTHRESHOLD_HPP + +#include +#include "Math/VoxImage.h" +#include "VoxImageFilter.h" + +//////////////////////////////////////////////////////////////////////////////// +///// VOXIMAGE FILTER THRESHOLD ////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +namespace uLib { + +template +class VoxFilterAlgorithmThreshold : + public VoxImageFilter > { + + typedef VoxImageFilter > BaseClass; + // ULIB_OBJECT_PARAMETERS(BaseClass) { + // float threshold; + // }; + + float m_threshold; + +public: + VoxFilterAlgorithmThreshold(const Vector3i &size) : BaseClass(size) + { + // init_parameters(); + m_threshold = 0; + } + + inline void SetThreshold(float th) { m_threshold = th; } + + float Evaluate(const VoxImage &buffer, int index) + { + return static_cast(buffer.ConstData().at(index).Value >= + // parameters().threshold); + m_threshold ); + } + +}; + +//template +//inline void VoxFilterAlgorithmThreshold::init_parameters() +//{ +// parameters().threshold = 0; +//} + +} + +#endif // VOXIMAGEFILTERTHRESHOLD_HPP diff --git a/src/Math/VoxImageFilterUser.cpp b/src/Math/VoxImageFilterUser.cpp new file mode 100644 index 0000000..d82fe21 --- /dev/null +++ b/src/Math/VoxImageFilterUser.cpp @@ -0,0 +1,35 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Core/Vector.h" +#include "Dense.h" +#include "VoxImage.h" +#include "VoxImageFilterUser.h" + +using namespace uLib; + diff --git a/src/Math/VoxRaytracer.cpp b/src/Math/VoxRaytracer.cpp new file mode 100644 index 0000000..8ed6330 --- /dev/null +++ b/src/Math/VoxRaytracer.cpp @@ -0,0 +1,251 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "VoxRaytracer.h" +#include "Utils.h" + +inline float fast_sign(float f) { return 1 - 2 * (f < 0); } + +namespace uLib { + +//////////////////////////////////////////////////////////////////////////////// +///// RAY DATA ///////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +void VoxRaytracer::RayData::AddElement(Id_t id, float L) +{ + Element el = {id, L}; + m_Data.push_back(el); + m_TotalLength += L; +} + + +void VoxRaytracer::RayData::AppendRay(const VoxRaytracer::RayData &in) +{ + if (unlikely(!in.m_Data.size())) { + std::cout << "Warinig: PoCA on exit border!\n"; + return; + } + else if (unlikely(!m_Data.size())) { + m_Data = in.m_Data; + std::cout << "Warinig: PoCA on entrance border!\n"; + return; + } + else { + // Opzione 1) un voxel in piu' // + m_Data.reserve(m_Data.size() + in.m_Data.size()); + m_Data.insert(m_Data.end(), in.m_Data.begin(), in.m_Data.end()); + // Opzione 2) merge dei voxel nel poca. + // RayData::Element &e1 = m_Data.back(); + // const RayData::Element &e2 = in.m_Data.front(); + // if(e1.vox_id == e2.vox_id) + // { + // m_Data.reserve(m_Data.size() + in.m_Data.size() - 1); + // e1.L += e2.L; //fix// + // m_Data.insert(m_Data.end(), in.m_Data.begin()+1, in.m_Data.end()); + // } + // else { + // m_Data.reserve(m_Data.size() + in.m_Data.size()); + // m_Data.insert(m_Data.end(), in.m_Data.begin(), in.m_Data.end()); + // } + m_TotalLength += in.m_TotalLength; + } +} + +void VoxRaytracer::RayData::PrintSelf(std::ostream &o) +{ + o << "Ray: total lenght " << m_TotalLength << "\n"; + Vector::Iterator it; + for(it = m_Data.begin(); it < m_Data.end(); ++it) + o << "[ " << (*it).vox_id << ", " << (*it).L << "] \n"; +} + + +//////////////////////////////////////////////////////////////////////////////// +//// RAY TRACER //////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt) +{ + Vector4f s = m_Image->GetLocalPoint(line.direction); + pt = m_Image->GetLocalPoint(line.origin); + + // Considers Structured grid dimensions // + Vector4f dims = m_Image->GetDims().homogeneous().cast(); + pt = pt.cwiseQuotient(dims); + s = s.cwiseQuotient(dims); + + float l = s.head(3).norm(); + Vector3f L(l/s(0), l/s(1), l/s(2)); + + Vector3f offset; + for(int i=0;i<3;++i) + offset(i) = (s(i)>0) - (pt(i)-floor(pt(i))) ; + offset = offset.cwiseProduct(L).cwiseAbs(); + + int id; float d; + for(int loop=0; loop<8; loop++) + { + int check_border = 0; + for ( int i=0; i<3 ;++i) { + check_border += pt(i) > 1; + check_border += pt(i) < 0; + } + if(check_border == 0) { + for(int i=0;i<3;++i) + pt(i) *= (float)dims(i); + pt = m_Image->GetWorldPoint(pt); + return true; + } + + d = offset.minCoeff(&id); + for(int i=0; i<3; ++i) + pt(i) += d / L(i); + + pt(id) = rintf(pt(id)); + + + offset.array() -= d; + offset(id) = fabs(L(id)); + } + for(int i=0;i<3;++i) + pt(i) *= (float)dims(i); + pt = m_Image->GetWorldPoint(pt); + return false; +} + +bool VoxRaytracer::GetExitPoint(const HLine3f &line, HPoint3f &pt) +{ + HLine3f out = line; + out.direction *= -1; + return GetEntryPoint(out,pt); +} + + +VoxRaytracer::RayData VoxRaytracer::TraceBetweenPoints(const HPoint3f &in, + const HPoint3f &out) +const +{ + RayData ray; + Vector4f pt1 = m_Image->GetLocalPoint(in); + Vector4f pt2 = m_Image->GetLocalPoint(out); + Vector4f s = pt2 - pt1; + + float l = s.head(3).norm(); + Vector3f L(l/s(0), l/s(1), l/s(2)); + + // Vector3f scale; // FIXXX + // scale << (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(), + // (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(), + // (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm(); + + Vector3f offset; + for(int i=0;i<3;++i) offset(i) = (s(i)>=0) - (pt1(i)-floor(pt1(i))) ; + offset = offset.cwiseProduct(L).cwiseAbs(); + L = L.cwiseAbs(); + + //---- Check if the ray only crosses one voxel + Vector3i vid = m_Image->Find(in); + if(vid == m_Image->Find(out)){ + ray.AddElement(m_Image->Map(vid),s.norm()); + return ray; + } + + //---- Otherwise, loop until ray is finished + int id; float d; + while(l>0){ + + d = offset.minCoeff(&id); + + if(m_Image->IsInsideGrid(vid)){ + ray.AddElement(m_Image->Map(vid), d * m_scale(id) ); + } + + // nan check // + // if(unlikely(!isFinite(d * scale(id)))) { + // std:: cout << "NAN in raytracer\n"; + // exit(1); + // } + + vid(id) += (int)fast_sign(s(id)); + + l -= d; + offset.array() -= d; + offset(id) = fmin(L(id),l); + } + return ray; +} + +// 20150528 SV for absorbed muons +VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const +{ + RayData ray; + + Vector4f pt = m_Image->GetLocalPoint(line.origin); + Vector4f s = m_Image->GetLocalPoint(line.direction); + + float l = s.head(3).norm(); + // intersection between track and grid when spacing is +1 + Vector3f L(l/s(0), l/s(1), l/s(2)); + + // RayTracer works with a grid of interspace +1 + // Vector3f scale; // FIXXX + // scale << (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(), + // (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(), + // (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm(); + + // offset is the fraction of the segment between grid lines when origin is insiede voxel + // cwiseAbs for having positive distances + Vector3f offset; + for(int i=0;i<3;++i) + offset(i) = (s(i)>=0) - (pt(i)-floor(pt(i))); + offset = offset.cwiseProduct(L).cwiseAbs(); + L = L.cwiseAbs(); + + int id; float d; + Vector3i vid = m_Image->Find(line.origin); + while(m_Image->IsInsideGrid(vid)) + { + // minimun coefficient of offset: id is the coordinate, d is the value + // dependig on which grid line horizontal or vertical it is first intercept + d = offset.minCoeff(&id); + + // add Lij to ray + ray.AddElement(m_Image->Map(vid), d * m_scale(id) ); + + // move to the next voxel + vid(id) += (int)fast_sign(s(id)); + + offset.array() -= d; + offset(id) = L(id); + } + return ray; +} + +} diff --git a/src/Math/VoxRaytracer.h b/src/Math/VoxRaytracer.h new file mode 100644 index 0000000..f4d0ae4 --- /dev/null +++ b/src/Math/VoxRaytracer.h @@ -0,0 +1,92 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VOXRAYTRACER_H +#define VOXRAYTRACER_H + +#include + +#include "Core/Vector.h" +#include "Math/StructuredGrid.h" + +namespace uLib { + +class VoxRaytracer { + +public: + class RayData { + public: + RayData() : m_TotalLength(0) {} + + typedef struct { + Id_t vox_id; + Scalarf L; + } Element; + + inline void AddElement(Id_t id, float L); + + void AppendRay ( const RayData &in); + + uLibConstRefMacro(Data,Vector) + uLibConstRefMacro(TotalLength,Scalarf) + + void PrintSelf(std::ostream &o); + + private: + Vector m_Data; + Scalarf m_TotalLength; + }; + + + public: + VoxRaytracer(StructuredGrid &image) : m_Image(&image) { + m_scale << + (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(), + (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(), + (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm(); + } + + bool GetEntryPoint(const HLine3f &line, HPoint3f &pt); + + bool GetExitPoint(const HLine3f &line, HPoint3f &pt); + + RayData TraceBetweenPoints(const HPoint3f &in, const HPoint3f &out) const; + + RayData TraceLine(const HLine3f &line) const; + + uLibGetMacro(Image,StructuredGrid *) + +private: + StructuredGrid *m_Image; + Vector3f m_scale; +}; + +} + + + +#endif // VOXRAYTRACER_H diff --git a/src/Math/testing/AccumulatorTest.cpp b/src/Math/testing/AccumulatorTest.cpp new file mode 100644 index 0000000..211f334 --- /dev/null +++ b/src/Math/testing/AccumulatorTest.cpp @@ -0,0 +1,108 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Math/Accumulator.h" +#include "testing-prototype.h" + +#include + + +//#include +//#include +//#include + +using namespace uLib; + +int test_ABTrim() { + + Accumulator_ABTrim acc; + + acc.SetABTrim(1,1); + + Vector v; + v << 1,5,5,5,300; + + for(Vector::Iterator itr=v.begin(); itr mean; + TRandom rnd; + const int c = 10000000; + Vector v; + v.reserve(c); + for(int i=0;i +#include + +using namespace uLib; + +int main() { + BEGIN_TESTING(BitCode Test); + + BitCode bc; + + bc.PrintSelf(); + + END_TESTING; +} diff --git a/src/Math/testing/CMakeLists.txt b/src/Math/testing/CMakeLists.txt new file mode 100644 index 0000000..58b89ef --- /dev/null +++ b/src/Math/testing/CMakeLists.txt @@ -0,0 +1,18 @@ + +set(TESTS + MathVectorTest + GeometryTest + ContainerBoxTest + VoxImageTest + VoxRaytracerTest + StructuredDataTest + VoxImageFilterTest + PolicyTest + AccumulatorTest + VoxImageCopyTest + TriangleMeshTest + BitCodeTest +) + + +uLib_add_tests(${uLib-module}) diff --git a/src/Math/testing/ContainerBoxTest.cpp b/src/Math/testing/ContainerBoxTest.cpp new file mode 100644 index 0000000..98fb27e --- /dev/null +++ b/src/Math/testing/ContainerBoxTest.cpp @@ -0,0 +1,94 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "testing-prototype.h" + +#include "Math/Dense.h" +#include "Math/ContainerBox.h" + +#include +#include + + +using namespace uLib; + +int Vector4f0(Vector4f c) +{ + c(3) = 0; + if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) + return 0; + else + return 1; +} + + +int main() +{ + + BEGIN_TESTING(Math ContainerBox); + + ContainerBox Cnt; + +// // Local transform: + Cnt.SetOrigin(Vector3f(-1,-1,-1)); + Cnt.SetSize(Vector3f(2,2,2)); // scaling // + std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n"; + std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n"; + TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) ); + + + ContainerBox Box; + + Box.SetPosition(Vector3f(1,1,1)); + Box.SetSize(Vector3f(2,2,2)); + Box.EulerYZYRotate(Vector3f(0,0,0)); + HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2)); + HPoint3f wp = Box.GetWorldPoint(pt); + TEST0( Vector4f0(wp - HPoint3f(2,3,2)) ); + + +//// // Global +// Cnt.SetPosition(Vector3f(1,1,1)); +// Cnt.EulerYZYRotate(Vector3f(M_PI_2,M_PI_2,0)); +// HPoint3f p = Cnt.GetWorldPoint(1,1,1); +// //std::cout << p.transpose() << "\n"; +// TEST0( Vector4f0(p - HVector3f(2,1,2)) ); +// p = Cnt.GetWorldPoint(1,2,3); +// //std::cout << p.transpose() << "\n"; +// TEST0( Vector4f0(p - HVector3f(4,1,3)) ); + + +// // scaling // + + + + + END_TESTING; +} + + diff --git a/src/Math/testing/GeometryTest.cpp b/src/Math/testing/GeometryTest.cpp new file mode 100644 index 0000000..0e6788f --- /dev/null +++ b/src/Math/testing/GeometryTest.cpp @@ -0,0 +1,98 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" +#include "Math/Dense.h" +#include "Math/Geometry.h" +#include "Math/ContainerBox.h" + +#include +#include + +using namespace uLib; + +int Vector4f0(Vector4f c) +{ + c(3) = 0; + if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) + return 0; + else + return 1; +} + + +int main() +{ + BEGIN_TESTING(Math Geometry); + + ////////////////////////////////////////////////////////////////////////////// + ///////////////// GEOMETRY TESTING /////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + + Geometry Geo; + + Geo.SetPosition(Vector3f(1,1,1)); + Geo.EulerYZYRotate(Vector3f(0,0,0)); + HPoint3f pt = Geo.GetLocalPoint(HPoint3f(2,3,2)); + HPoint3f wp = Geo.GetWorldPoint(pt); + TEST0( Vector4f0(wp - HPoint3f(2,3,2)) ); + + Geo.Scale(Vector3f(2,2,2)); + wp = Geo.GetWorldPoint(HPoint3f(1,1,1)); + TEST0( Vector4f0(wp - HPoint3f(3,3,3)) ); + Geo.Scale(Vector3f( .5 , .5 , .5 )); + + + Geo.EulerYZYRotate(Vector3f(M_PI_2,0,0)); + wp = Geo.GetWorldPoint(HPoint3f(1,1,1)); + TEST0( Vector4f0(wp - HPoint3f(2,2,0)) ); + + Geo.EulerYZYRotate(Vector3f(0,M_PI_2,0)); + wp = Geo.GetWorldPoint(HPoint3f(1,1,1)); + TEST0( Vector4f0(wp - HPoint3f(2,2,2)) ); + + Geo.EulerYZYRotate(Vector3f(0,0,M_PI_2)); + wp = Geo.GetWorldPoint(HPoint3f(1,1,1)); + // std::cout << "Geometry matrix\n" << Geo.GetTransform() << "\n"; + // std::cout << "World 1,1,1 coords\n" << wp << "\n"; + TEST0( Vector4f0(wp - HPoint3f(0,2,2)) ); + + // TESTING FLIP AXES // + + Geo.SetPosition(Vector3f(0,0,0)); + Geo.EulerYZYRotate(Vector3f(-M_PI_2,-M_PI_2,-M_PI_2)); // reset previous + Geo.EulerYZYRotate(Vector3f(M_PI_2,0,0)); // PI_2 along X + Geo.FlipAxes(0,2); // flip X-Z + HPoint3f p = Geo.GetWorldPoint(Vector3f(1,0,0).homogeneous()); + TEST0( Vector4f0(p - HVector3f(1,0,0)) ); // after flip and rotation X->X + + + + END_TESTING; +} + + diff --git a/src/Math/testing/Makefile.am b/src/Math/testing/Makefile.am new file mode 100644 index 0000000..22ea4f1 --- /dev/null +++ b/src/Math/testing/Makefile.am @@ -0,0 +1,28 @@ + +include $(top_srcdir)/Common.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + +# if HAVE_CHECK +TESTS = MathVectorTest \ + GeometryTest \ + ContainerBoxTest \ + VoxImageTest \ + VoxRaytracerTest \ + StructuredDataTest \ + VoxImageFilterTest \ + PolicyTest \ + AccumulatorTest \ + VoxImageCopyTest \ + TriangleMeshTest + +# else +# TEST = +# endif + +LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_ALL) + +all: ${TESTS} + +check_PROGRAMS = $(TESTS) + diff --git a/src/Math/testing/MathVectorTest.cpp b/src/Math/testing/MathVectorTest.cpp new file mode 100644 index 0000000..cb9c086 --- /dev/null +++ b/src/Math/testing/MathVectorTest.cpp @@ -0,0 +1,129 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "testing-prototype.h" +#include "Math/Dense.h" +#include "Math/Geometry.h" + +#include "Core/Archives.h" + +#include +#include + +using namespace uLib; + +int Vector4f0(Vector4f c) +{ + c(3) = 0; + if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) + return 0; + else + return 1; +} + + + + +int main() +{ + BEGIN_TESTING(uLib Math); + + ////////////////////////////////////////////////////////////////////////////// + ///////////////// VECTOR TESTING ///////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + + std::cout << "Testing Vectors\n"; + + { // SIMPLE VECTOR TEST // + HPoint3f p1(1,1,1); // point with const float ctr + HVector3f v1; v1 << 1,1,1,1; // vector with void ctr and comma assignment + TEST0( Vector4f0(p1 - v1)); + } + + { // ROW COLUMN ACCESSOR ORDER TEST // + Matrix2i test; + test << 1,2,3,4; + std::cout << "print row column test "; + std::cout << test(0,0) << " " << + test(0,1) << " " << + test(1,0) << " " << + test(1,1) << " " << "\n"; + + TEST1( test(0,1) == 2 && test(1,0) == 3 ); + } + + + { + Vector3i test(0,0,0); + ++test(1); + std::cout << "increment of single dim inside vector: " << test.transpose() << "\n"; + TEST1( test == Vector3i(0,1,0) ); + } + + { + Matrix4f mat; + mat << 1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1; + + std::cout << "determinant" << mat.determinant() << "\n"; + } + + + { + Matrix1f f; + f << 5; + f.trace(); + + } + + { + Vector3f v(1,2,3); + + std::string str("2 3 5"); + std::istringstream istr(str); + uLib::Archive::hrt_iarchive hi(istr); + hi >> v; + + uLib::Archive::hrt_oarchive ho(std::cout); + ho << v; + } + + { + Vector3f v; + std::string str("2 3 5"); + str >> v; + std::cout << v.transpose() << "\n"; + } + + + END_TESTING; +} + + diff --git a/src/Math/testing/PolicyTest.cpp b/src/Math/testing/PolicyTest.cpp new file mode 100644 index 0000000..dbe2685 --- /dev/null +++ b/src/Math/testing/PolicyTest.cpp @@ -0,0 +1,78 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include "testing-prototype.h" + + + +// Curiously Recurring Template Pattern // + + +template < typename V, typename T > +class Base { +public: + Base(int a) : value(a) { + Algorithm = static_cast(this); + } + + void Print() + { + std::cout << Algorithm->Value() << "\n"; + } + + int value; + V voxel; + T* Algorithm; +}; + + +template < typename V > +class Derived : public Base< V ,Derived > { + typedef Base< V ,Derived > BaseClass; +public: + Derived(int a) : BaseClass(a) {} + int Value() { return this->value+1; } +}; + + + + + +int main() +{ + BEGIN_TESTING(Policy); + + + Derived my(5); + my.Print(); + + Base > my2(5); + my2.Print(); + + END_TESTING; +} diff --git a/src/Math/testing/StructuredDataTest.cpp b/src/Math/testing/StructuredDataTest.cpp new file mode 100644 index 0000000..350f7d3 --- /dev/null +++ b/src/Math/testing/StructuredDataTest.cpp @@ -0,0 +1,93 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" + +#include "Math/Dense.h" +#include "Math/ContainerBox.h" +#include "Math/StructuredData.h" + + +#include + +using namespace uLib; + + +int main() { + BEGIN_TESTING(Structured Data); + + { // testing unmap function //////////////////////////////////////////////// + StructuredData sdata(Vector3i(2,3,4)); + for(int i=0; i < sdata.GetDims().prod() ; ++i) { + Vector3i d = sdata.UnMap(i); + std::cout << "TEST1( sdata.UnMap(" << i << ") == Vector3i(" + << d(0) << "," << d(1) << "," << d(2) << ")); \n"; + } + TEST1( sdata.UnMap(0) == Vector3i(0,0,0)); + TEST1( sdata.UnMap(1) == Vector3i(0,1,0)); + TEST1( sdata.UnMap(2) == Vector3i(0,2,0)); + TEST1( sdata.UnMap(3) == Vector3i(1,0,0)); + TEST1( sdata.UnMap(4) == Vector3i(1,1,0)); + TEST1( sdata.UnMap(5) == Vector3i(1,2,0)); + TEST1( sdata.UnMap(6) == Vector3i(0,0,1)); + TEST1( sdata.UnMap(7) == Vector3i(0,1,1)); + TEST1( sdata.UnMap(8) == Vector3i(0,2,1)); + TEST1( sdata.UnMap(9) == Vector3i(1,0,1)); + TEST1( sdata.UnMap(10) == Vector3i(1,1,1)); + TEST1( sdata.UnMap(11) == Vector3i(1,2,1)); + TEST1( sdata.UnMap(12) == Vector3i(0,0,2)); + TEST1( sdata.UnMap(13) == Vector3i(0,1,2)); + TEST1( sdata.UnMap(14) == Vector3i(0,2,2)); + TEST1( sdata.UnMap(15) == Vector3i(1,0,2)); + TEST1( sdata.UnMap(16) == Vector3i(1,1,2)); + TEST1( sdata.UnMap(17) == Vector3i(1,2,2)); + TEST1( sdata.UnMap(18) == Vector3i(0,0,3)); + TEST1( sdata.UnMap(19) == Vector3i(0,1,3)); + TEST1( sdata.UnMap(20) == Vector3i(0,2,3)); + TEST1( sdata.UnMap(21) == Vector3i(1,0,3)); + TEST1( sdata.UnMap(22) == Vector3i(1,1,3)); + TEST1( sdata.UnMap(23) == Vector3i(1,2,3)); + + + // testing map ///////////////////////////////////////////////////////// + int i=0; + // PREDEFINED ORDER IS YXZ // + for(int z=0; z + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include "testing-prototype.h" + +using namespace uLib; + +int main() +{ + BEGIN_TESTING(Math Structured Grid); + + VoxImage int_grid(Vector3i(100,100,100)); + + int_grid[Vector3i(1,2,3)] = 5552368; + TEST1( int_grid.At(30102) == 5552368 ); + + + // TESTING MAP // + VoxImage test_order(Vector3i(2,2,2)); + int index =0; + for(int z=0;z<2;++z) + for(int y=0;y<2;++y) + for(int x=0;x<2;x++) + { + test_order[Vector3i(x,y,z)] = index; + std::cout << x << " " << y << " " << z << " -> " << + test_order.At(Vector3i(x,y,z)) << "\n"; + index++; + } + test_order.Data().PrintSelf(std::cout); + + int result[8] = {0,2,1,3,4,6,5,7}; + for(int i=0;i<8;++i) + TEST1( test_order.At(i) == result[i] ); + + // TESTING UNMAP // + std::cout << "unmap = " << test_order.UnMap(7).transpose() << "\n"; + TEST1( test_order.UnMap(7) == Vector3i(1,1,1) ); + TEST1( test_order.UnMap(6) == Vector3i(1,0,1) ); + TEST1( test_order.UnMap(5) == Vector3i(0,1,1) ); + // ... + + + + END_TESTING +} diff --git a/src/Math/testing/TriangleMeshTest.cpp b/src/Math/testing/TriangleMeshTest.cpp new file mode 100644 index 0000000..bd89a03 --- /dev/null +++ b/src/Math/testing/TriangleMeshTest.cpp @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "testing-prototype.h" + +#include "Math/TriangleMesh.h" + + +using namespace uLib; + +int main() +{ + BEGIN_TESTING(Triangle Mesh); + + TriangleMesh mesh; + + mesh.AddPoint(Vector3f(0,0,0)); + mesh.AddPoint(Vector3f(0,1,0)); + mesh.AddPoint(Vector3f(1,0,0)); + + mesh.AddTriangle(Vector3i(0,1,2)); + + + mesh.PrintSelf(std::cout); + + END_TESTING; +} diff --git a/src/Math/testing/VoxImageCopyTest.cpp b/src/Math/testing/VoxImageCopyTest.cpp new file mode 100644 index 0000000..b4de751 --- /dev/null +++ b/src/Math/testing/VoxImageCopyTest.cpp @@ -0,0 +1,77 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" + +#include "Math/VoxImage.h" + +using namespace uLib; + + +struct TestVoxel { + Scalarf Value; + unsigned int Count; +}; + +int main() { + BEGIN_TESTING(Math VoxImage Copy); + + { + VoxImage img(Vector3i(10,10,10)); + TestVoxel zero = {0,0}; + img.InitVoxels(zero); + TestVoxel nonzero = {5.552368, 0}; + img[Vector3i(5,1,7)] = nonzero; + img[img.Find(HPoint3f(3,3,3))].Value = 5.552369; + TEST1( img.GetValue(Vector3i(5,1,7)) == 5.552368f ); + + + img.SetOrigin(Vector3f(4,5,6)); + + std::cout << "\n"; + + img.PrintSelf(std::cout); + + VoxImage img2 = img; + img2.PrintSelf(std::cout); + + TEST1( img.GetOrigin() == img2.GetOrigin() ); + TEST1( img.GetSpacing() == img2.GetSpacing() ); + + img2 = img; + + } + + + + + + + + std::cout << "returns " << _fail << "\n"; + END_TESTING; +} diff --git a/src/Math/testing/VoxImageFilterTest.cpp b/src/Math/testing/VoxImageFilterTest.cpp new file mode 100644 index 0000000..e5e0863 --- /dev/null +++ b/src/Math/testing/VoxImageFilterTest.cpp @@ -0,0 +1,150 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "testing-prototype.h" +#include "Math/StructuredGrid.h" + +#include "Math/VoxImage.h" +#include "Math/VoxImageFilter.h" + + + +using namespace uLib; + +struct TestVoxel { + Scalarf Value; + unsigned int Count; +}; + +float GaussianShape(float d) +{ + // normalized manually .. fix // + return 4.5 * exp(-d * 4.5); +} + + +class GaussianShapeClass : public Interface::VoxImageFilterShape { +public: + GaussianShapeClass(float sigma) : + m_sigma(sigma) + {} + + float operator ()(float d) { + return (1/m_sigma) * exp(-d/m_sigma); + } + +private: + float m_sigma; +}; + + +static float MaxInVector(const Vector &v) +{ + float max = 0; + for(int i=0; i max) max = v.at(i); + return max; +} + + +int main() +{ + BEGIN_TESTING(VoxImageFilters); + + VoxImage image(Vector3i(20,30,40)); + image[Vector3i(10,10,10)].Value = 1; + //image[Vector3i(10,10,8)].Value = 1; + image.ExportToVtk("test_filter_original.vtk",0); + + + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + // RPS // + + { + VoxFilterAlgorithmSPR filter(Vector3i(2,3,4)); + + VoxImage filtered = image; + + Vector values; + for(int i=0; i < filter.GetKernelData().GetDims().prod(); ++i) { + values.push_back(1.); + std::cout << values[i] << " "; + } + std::cout << "\n"; + + filter.SetImage(&filtered); + + filter.SetKernelNumericXZY(values); + + filter.SetABTrim(0,2); + + filter.GetKernelData().PrintSelf(std::cout); + + filter.Run(); + + filtered.ExportToVtk("filter_RPS_out.vtk",0); + } + + + + + + { + + VoxImage image(Vector3i(20,30,40)); + image[Vector3i(10,10,10)].Value = 1; + image[Vector3i(9,10,8)].Value = 2; + image.ExportToVtk("test_filter_max_original.vtk",0); + + + + VoxFilterAlgorithmCustom filter(Vector3i(3,3,4)); + + Vector values; + for(int i=0; i < filter.GetKernelData().GetDims().prod(); ++i) { + values.push_back(static_cast(1)); + } + + filter.SetImage(&image); + + filter.SetKernelNumericXZY(values); + + filter.SetCustomEvaluate(MaxInVector); + + filter.Run(); + + image.ExportToVtk("test_filter_max.vtk",0); + } + + + + END_TESTING; +} diff --git a/src/Math/testing/VoxImageTest.cpp b/src/Math/testing/VoxImageTest.cpp new file mode 100644 index 0000000..a6337f9 --- /dev/null +++ b/src/Math/testing/VoxImageTest.cpp @@ -0,0 +1,107 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "testing-prototype.h" +#include "Math/StructuredGrid.h" +#include "Math/VoxImage.h" + +using namespace uLib; + + +struct TestVoxel { + Scalarf Value; + unsigned int Count; +}; + +int main() { + BEGIN_TESTING(Math StructuredGrid); + + { // SIMPLE TESTS // + StructuredGrid img(Vector3i(10,10,10)); + img.SetSpacing(Vector3f(3,3,3)); + TEST1( img.GetWorldPoint(2,0,0) == HPoint3f(6,0,0) ); + TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(3,3,3) ); + + img.SetPosition(Vector3f(1,1,1)); + TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(4,4,4) ); + TEST1( img.GetLocalPoint(4,4,4) == HPoint3f(1,1,1) ); + + TEST0( img.IsInsideBounds(HPoint3f(5,33,-5))); + TEST0( img.IsInsideBounds(HPoint3f(0,0,0))); + TEST1( img.IsInsideBounds(HPoint3f(1,1,1))); + } + + { // TEST WITH ORIGIN // + StructuredGrid img(Vector3i(10,10,10)); + img.SetSpacing(Vector3f(3,3,3)); + img.SetOrigin(Vector3f(-1,1,-1)); + img.SetPosition(Vector3f(1,1,1)); + TEST1( img.GetWorldPoint(1,1,1) == HPoint3f(3,5,3) ); + } + + + { + VoxImage img(Vector3i(10,10,10)); + TestVoxel zero = {0,0}; + img.InitVoxels(zero); + TestVoxel nonzero = {5.552368, 0}; + img[Vector3i(5,1,7)] = nonzero; + img[img.Find(HPoint3f(3,3,3))].Value = 5.552369; + img.ExportToVtk("./test_vox_image.vtk",0); + img.ExportToVtkXml("./test_vox_image.vti",0); + TEST1( img.GetValue(Vector3i(5,1,7)) == 5.552368f ); + } + + { + VoxImage img(Vector3i(4,4,4)); + TestVoxel zero = {0,0}; + img.InitVoxels(zero); + img.SetSpacing(Vector3f(2,2,2)); + img.SetPosition(Vector3f(-4,-4,-4)); + TEST1( img.GetWorldPoint(img.GetLocalPoint(HPoint3f(5,5,5))) == HPoint3f(5,5,5)); + } + + { + VoxImage imgR(Vector3i(0,0,0)); + imgR.ImportFromVtk("./test_vox_image.vtk"); + imgR.ExportToVtk("./read_and_saved.vtk"); + } + + + { + VoxImage img1(Vector3i(5,5,5)); + VoxImage img2; + img2 = img1; + TEST1( img1.GetDims() == img2.GetDims() ); + } + + + + + END_TESTING +} diff --git a/src/Math/testing/VoxRaytracerTest.cpp b/src/Math/testing/VoxRaytracerTest.cpp new file mode 100644 index 0000000..79a7a1d --- /dev/null +++ b/src/Math/testing/VoxRaytracerTest.cpp @@ -0,0 +1,151 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Math/StructuredGrid.h" +#include "Math/VoxRaytracer.h" +#include "testing-prototype.h" + +using namespace uLib; + + +int Vector4f0(Vector4f c) +{ + c(3) = 0; + if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) + return 0; + else + return 1; +} + +//bool Comapare(const &t1, const T2 &t2) +//{ +// int out = 0; +// out += t1.vox_id != t2.vox_id; +// out += (fabs(t1.L) - fabs(t2.L)) > 0.001; +// return out == 0; +//} + + +typedef VoxRaytracer Raytracer; + +int main() +{ + BEGIN_TESTING(Math VoxRaytracer); + + StructuredGrid img(Vector3i(2,2,2)); + img.SetSpacing(Vector3f(2,2,2)); + img.SetPosition(Vector3f(-2,0,-2)); + + { + HLine3f line; + line.origin << 0.1, 4.1, 0.1, 1; + line.direction << 0.1, -0.1, 0.1,0; + Raytracer rt(img); + HPoint3f pt; + TEST1( rt.GetEntryPoint(line,pt) ); + TEST0( Vector4f0( pt - HPoint3f(0.2,4,0.2) ) ); + } + + { + HLine3f line; + line.origin << 4,0,4, 1; + line.direction << -0.1, 0.1, -0.1, 0; + Raytracer rt(img); + HPoint3f pt; + TEST1( rt.GetEntryPoint(line,pt) ); + TEST0( Vector4f0( pt - HPoint3f(2,2,2) ) ); + } + + { // Test a point inside image // + StructuredGrid img(Vector3i(4,4,4)); + img.SetSpacing(Vector3f(2,2,2)); + img.SetPosition(Vector3f(-4,-4,-4)); + Raytracer ray(img); + HPoint3f pt; + HLine3f line; + line.origin = HPoint3f(-3,-3,-3); + // line.direction = HVector3f(1,1,1); // + TEST1( ray.GetEntryPoint(line,pt) ); + TEST1( pt == HPoint3f(-3,-3,-3) ); + + Raytracer::RayData rdata = ray.TraceBetweenPoints(HPoint3f(-3,-3,-3), HPoint3f(3,3,3)); + foreach (const Raytracer::RayData::Element &el, rdata.Data()) + { + std::cout << " " << el.vox_id << " , " << el.L << "\n"; + } + } + + + { + HPoint3f pt1(1,-0.5,1); + HPoint3f pt2(1,4.5,1); + Raytracer rt(img); + + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); + TEST1( ray.Data().size() == 2 ); + TEST1( ray.Data().at(0).vox_id == 6 ); + TEST1( ray.Data().at(1).vox_id == 7 ); + ray.PrintSelf(std::cout); + } + + { + HPoint3f pt1(5,1,1); + HPoint3f pt2(-3,1,1); + Raytracer rt(img); + + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); + TEST1( ray.Data().size() == 2 ); + TEST1( ray.Data().at(0).vox_id == 6 ); + TEST1( ray.Data().at(1).vox_id == 4 ); + ray.PrintSelf(std::cout); + } + + { + HPoint3f pt1(1,1,1); + HPoint3f pt2(-1,3,-1); + Raytracer rt(img); + + Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); + TEST1( ray.Data().size() == 4 ); + TEST1( ray.Data().at(0).vox_id == 6 ); + TEST1( ray.Data().at(1).vox_id == 4 ); + TEST1( ray.Data().at(2).vox_id == 5 ); + TEST1( ray.Data().at(3).vox_id == 1 ); + ray.PrintSelf(std::cout); + } + + END_TESTING +} + + + + + + + + diff --git a/src/Math/testing/testing-prototype.h b/src/Math/testing/testing-prototype.h new file mode 100644 index 0000000..39f4e6c --- /dev/null +++ b/src/Math/testing/testing-prototype.h @@ -0,0 +1,37 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#define BEGIN_TESTING(name) \ +static int _fail = 0; \ +printf("..:: Testing " #name " ::..\n"); + +#define TEST1(val) _fail += (val)==0 +#define TEST0(val) _fail += (val)!=0 +#define END_TESTING return _fail; + diff --git a/src/ParticlePhysics/Geant/Makefile.am b/src/ParticlePhysics/Geant/Makefile.am new file mode 100644 index 0000000..70c690d --- /dev/null +++ b/src/ParticlePhysics/Geant/Makefile.am @@ -0,0 +1,14 @@ +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ParticlePhysics/Geant + +library_include_HEADERS = + +_PPGEANT_SOURCES = + + + +noinst_LTLIBRARIES = libmutomppgeant.la +libmutomppgeant_la_SOURCES = ${_PPGEANT_SOURCES} + + diff --git a/src/ParticlePhysics/MuonTomography/DetectorChamber.h b/src/ParticlePhysics/MuonTomography/DetectorChamber.h new file mode 100644 index 0000000..22aa495 --- /dev/null +++ b/src/ParticlePhysics/MuonTomography/DetectorChamber.h @@ -0,0 +1,47 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#ifndef U_PP_MUTOM_DETECTORCHAMBER_H +#define U_PP_MUTOM_DETECTORCHAMBER_H + +#include + +namespace uLib { + +class ContainerBox; + +class DetectorChamber : public Object { +public: + + virtual ContainerBox & Geometry() {} +protected: + virtual ~DetectorChamber() {} +}; + +} // uLib + + + +#endif // DETECTORCHAMBER_H diff --git a/src/ParticlePhysics/MuonTomography/DriftDetector.h b/src/ParticlePhysics/MuonTomography/DriftDetector.h new file mode 100644 index 0000000..e655929 --- /dev/null +++ b/src/ParticlePhysics/MuonTomography/DriftDetector.h @@ -0,0 +1,53 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_PPHY_DRIFTDETECTOR_H +#define U_PPHY_DRIFTDETECTOR_H + + +#include +#include + +#include "ParticlePhysics/MuonTomography/DetectorChamber.h" + +namespace uLib { + +class DriftDetectorChamber : public DetectorChamber { + + uLibRefMacro(Geometry,ContainerBox) +private: + ContainerBox m_Geometry; +}; + + + + +} // uLib + + + +#endif // U_PPHY_DRIFTDETECTOR_H diff --git a/src/ParticlePhysics/MuonTomography/Hit.h b/src/ParticlePhysics/MuonTomography/Hit.h new file mode 100644 index 0000000..a5b071a --- /dev/null +++ b/src/ParticlePhysics/MuonTomography/Hit.h @@ -0,0 +1,65 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + +#ifndef U_PPMUTOM_HIT_H +#define U_PPMUTOM_HIT_H + +#include +#include + + +namespace uLib { + +template +class Hit { + Code m_Code; + Type m_DriftTime; +}; + + + + + + + +class HitMC { +public: + virtual Id_t GetChamber() = 0; + virtual Vector3f GetPosition() = 0; + virtual Scalarf GetDritfTime() = 0; +protected: + virtual ~HitMC() {} +}; + + + +} // uLib + + + + + +#endif // HIT_H diff --git a/src/ParticlePhysics/MuonTomography/Makefile.am b/src/ParticlePhysics/MuonTomography/Makefile.am new file mode 100644 index 0000000..d169be8 --- /dev/null +++ b/src/ParticlePhysics/MuonTomography/Makefile.am @@ -0,0 +1,11 @@ +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ParticlePhysics/MuonTomography +library_include_HEADERS = + +_PPMUTOM_SOURCES = + +noinst_LTLIBRARIES = libmutomppmutom.la +libmutomppmutom_la_SOURCES = ${_PPMUTOM_SOURCES} + + diff --git a/src/ParticlePhysics/MuonTomography/MuonScatter.h b/src/ParticlePhysics/MuonTomography/MuonScatter.h new file mode 100644 index 0000000..67b195f --- /dev/null +++ b/src/ParticlePhysics/MuonTomography/MuonScatter.h @@ -0,0 +1,89 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_PPMUTOM_MUONSCATTER_H +#define U_PPMUTOM_MUONSCATTER_H + +#include "Core/Macros.h" +#include "Core/Serializable.h" + +#include "Math/Dense.h" + +namespace uLib { + + + +class MuonTrack { + ULIB_SERIALIZE_ACCESS +public: + HLine3f track; + Scalarf momentum; +}; + +class MuonScatter { + ULIB_SERIALIZE_ACCESS +public: + MuonTrack in, out; + MuonTrack error_in, error_out; +}; + + +} // uLib + +ULIB_SERIALIZABLE(uLib::MuonTrack) +ULIB_SERIALIZE(uLib::MuonTrack) { + ar & AR(line); +} + + + +ULIB_SERIALIZABLE(uLib::MuonScatter) +ULIB_SERIALIZE(uLib::MuonScatter) { + ar + & " MuonScatter: ----------------- \n" + & "IN : " & AR(in) & "\n" + & "OUT: " & AR(out) & "\n" + & " ------------------------------ \n"; +} + + +std::ostream & +operator << (std::ostream &o, const uLib::MuonScatter &d) { + uLib::Archive::hrt_oarchive(o) << d; + return o; +} + +inline std::istream & +operator >> (std::istream &is, uLib::MuonScatter &d) +{ + uLib::Archive::hrt_iarchive(is) >> d; + return is; +} + + + +#endif // MUONSCATTER_H diff --git a/src/Root/CMakeLists.txt b/src/Root/CMakeLists.txt new file mode 100644 index 0000000..6e23753 --- /dev/null +++ b/src/Root/CMakeLists.txt @@ -0,0 +1,49 @@ +set(HEADERS + TestTObject.h + RootMathDense.h + RootMuonScatter.h + RootHitRaw.h + muBlastHit.h + muBlastMCTrack.h + muCastorMCTrack.h + muCastorHit.h +) + +set(DICTIONARY_HEADERS + TestTObject.h + RootMathDense.h + RootMuonScatter.h + RootHitRaw.h + muBlastHit.h + muBlastMCTrack.h + muCastorMCTrack.h + muCastorHit.h +) + +SET(SOURCES + TestTObject.cpp + RootMuonScatter.cpp + muBlastHit.cpp + muBlastMCTrack.cpp + muCastorMCTrack.cpp + muCastorHit.cpp +) + +set(LIBRARIES +# ${Boost_SERIALIZATION_LIBRARY} +# ${Boost_SIGNALS_LIBRARY} +# ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${ROOT_LIBRARIES} + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math +) + +include(FindROOTv6) +root_generate_dictionary(uLibRootDict ${DICTIONARY_HEADERS} LINKDEF Linkdef.h) +set_source_files_properties(uLibRootDict.cxx PROPERTIES GENERATED TRUE) +set_source_files_properties(uLibRootDict.h PROPERTIES GENERATED TRUE) +list(APPEND SOURCES uLibRootDict.cxx) + + +uLib_add_shared_library(${uLib-module}) +add_subdirectory(testing) diff --git a/src/Root/Linkdef.h b/src/Root/Linkdef.h new file mode 100644 index 0000000..5ecbdaf --- /dev/null +++ b/src/Root/Linkdef.h @@ -0,0 +1,84 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_ROOT_LINKDEF_H +#define U_ROOT_LINKDEF_H + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclasses; + +#pragma link C++ class TestTObject+; + +using namespace ROOT::Mutom; + +#pragma link C++ class ROOT::Math::Cartesian2D+; +#pragma link C++ class ROOT::Math::Cartesian2D+; +#pragma link C++ class ROOT::Math::Cartesian2D+; + +#pragma link C++ class ROOT::Math::Cartesian3D+; +#pragma link C++ class ROOT::Math::Cartesian3D+; +#pragma link C++ class ROOT::Math::Cartesian3D+; + +#pragma link C++ class Vector2i+; +#pragma link C++ class Vector2f+; +#pragma link C++ class Vector2d+; + +#pragma link C++ class Vector3i+; +#pragma link C++ class Vector3f+; +#pragma link C++ class Vector3d+; + +#pragma link C++ typedef Matrix3i; +#pragma link C++ typedef Matrix3f; +#pragma link C++ typedef Matrix3d; + +#pragma link C++ class Line3f+; +#pragma link C++ class Line3d+; + +#pragma link C++ class MuonTrack+; +#pragma link C++ class MuonScatter+; +#pragma link C++ function MuonScatter::p_mean() const; + +// #pragma link C++ class DetectorChamber+; + +#pragma link C++ class HitRaw+; +#pragma link C++ function HitRaw::Chm() const; +#pragma link C++ function HitRaw::Rob() const; +#pragma link C++ function HitRaw::Tdc() const; +#pragma link C++ function HitRaw::Ch() const; + +#pragma link C++ class muBlastMCTrack+; +#pragma link C++ class muBlastHit+; +#pragma link C++ class muCastorMCTrack+; +#pragma link C++ class muCastorHit+; + +#endif // __CINT__ + +#endif // LINKDEF_H diff --git a/src/Root/Makefile.am b/src/Root/Makefile.am new file mode 100644 index 0000000..868c022 --- /dev/null +++ b/src/Root/Makefile.am @@ -0,0 +1,20 @@ +SUBDIRS = . + +ROOTCINT = `which rootcint` + +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Root + +library_include_HEADERS = TestTObject.h + + +_CORE_SOURCES = TestTObject.cpp + + +MutomDict.cxx: $(library_include_HEADERS) Linkdef.h + $(ROOTCINT) -f $@ -c $(AM_CXXFLAGS) -p $^ + + +noinst_LTLIBRARIES = libmutomroot.la +libmutomroot_la_SOURCES = MutomDict.cxx ${_CORE_SOURCES} diff --git a/src/Root/RootHitMC.h b/src/Root/RootHitMC.h new file mode 100644 index 0000000..eef8541 --- /dev/null +++ b/src/Root/RootHitMC.h @@ -0,0 +1,50 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + +#ifndef ROOTHITMC_H +#define ROOTHITMC_H + +#include +#include + +namespace ROOT { +namespace Mutom { + +class HitMC { +public: + int chm; // chamber id + Vector3f pos; // hit position in local coords + float_t drift; // drift time + enum TMCParticleType ptype; +}; + + + +} // Mutom +} // ROOT + + +#endif // ROOTHITMC_H diff --git a/src/Root/RootHitRaw.h b/src/Root/RootHitRaw.h new file mode 100644 index 0000000..2d617ce --- /dev/null +++ b/src/Root/RootHitRaw.h @@ -0,0 +1,71 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#ifndef ROOTHITRAW_H +#define ROOTHITRAW_H + +#include + +namespace ROOT { +namespace Mutom { + + + +class Hit32 { +public: + Int_t code; + Float_t drift; +}; + +class Hit64 { +public: + Long_t code; + Double_t drift; +}; + + + +class HitRaw +{ +public: +// virtual Int_t Flags() {} +// virtual Int_t Chm() const {} +// virtual Int_t Rob() const {} +// virtual Int_t Tdc() const {} +// virtual Int_t Ch() const {} + virtual void SetFlags (Int_t flags) = 0; + virtual void SetChamber(Int_t cmb) = 0; + virtual void SetChannel(Int_t Rob, Int_t Tdc, Int_t Ch) = 0; +// virtual float operator() ( ) {} +protected: + virtual ~HitRaw() {} +}; + + + +} // Mutom +} // ROOT + +#endif // ROOTHITRAW_H diff --git a/src/Root/RootMathDense.h b/src/Root/RootMathDense.h new file mode 100644 index 0000000..1435d77 --- /dev/null +++ b/src/Root/RootMathDense.h @@ -0,0 +1,68 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef ROOTMATHDENSE_H +#define ROOTMATHDENSE_H + + +#include +#include + +#include + +namespace ROOT { +namespace Mutom { + +typedef ROOT::Math::Cartesian2D Vector2i; +typedef ROOT::Math::Cartesian2D Vector2f; +typedef ROOT::Math::Cartesian2D Vector2d; + +typedef ROOT::Math::Cartesian3D Vector3i; +typedef ROOT::Math::Cartesian3D Vector3f; +typedef ROOT::Math::Cartesian3D Vector3d; + +typedef ROOT::Math::MatRepStd Matrix3i; +typedef ROOT::Math::MatRepStd Matrix3f; +typedef ROOT::Math::MatRepStd Matrix3d; + + +template +struct Line3D +{ + ROOT::Math::Cartesian3D origin,direction; +}; + + +typedef Line3D Line3f; +typedef Line3D Line3d; + + + +} // Mutom +} // ROOT + +#endif // ROOTMATHDENSE_H diff --git a/src/Root/RootMuonCollection.cpp b/src/Root/RootMuonCollection.cpp new file mode 100644 index 0000000..9197eba --- /dev/null +++ b/src/Root/RootMuonCollection.cpp @@ -0,0 +1,18 @@ +#include "RootMuonCollection.h" + + +namespace ROOT { +namespace Mutom { + +// ----- Default constructor ------------------------------------------- +RootMuoncollection::RootMuoncollection() +{ +} + +void RootMuoncollection::addMuon(MuonScatter &mu) +{ + +} + +} // end Mutom +} // end ROOT diff --git a/src/Root/RootMuonCollection.h b/src/Root/RootMuonCollection.h new file mode 100644 index 0000000..cec956b --- /dev/null +++ b/src/Root/RootMuonCollection.h @@ -0,0 +1,22 @@ +#ifndef ROOTMUONCOLLECTION_H +#define ROOTMUONCOLLECTION_H + +#include "RootMuonScatter.h" + +namespace ROOT { +namespace Mutom { + +class RootMuoncollection +{ +public: + RootMuoncollection(); + void addMuon(MuonScatter & mu); + +}; + + +} // Mutom +} // ROOT + + +#endif // ROOTMUONCOLLECTION_H diff --git a/src/Root/RootMuonScatter.cpp b/src/Root/RootMuonScatter.cpp new file mode 100644 index 0000000..010371e --- /dev/null +++ b/src/Root/RootMuonScatter.cpp @@ -0,0 +1,75 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "RootMuonScatter.h" +#include "Detectors/MuonScatter.h" + + +namespace ROOT { +namespace Mutom { + +MuonScatter &operator <<(MuonScatter &rmu, const uLib::MuonScatter &mu) +{ + + rmu.in.X=mu.LineIn().origin(0); + rmu.in.Y=mu.LineIn().origin(1); + rmu.in.Z=mu.LineIn().origin(2); + rmu.in.dirX=mu.LineIn().direction(0); + rmu.in.dirY=mu.LineIn().direction(1); + rmu.in.dirZ=mu.LineIn().direction(2); + + rmu.out.X=mu.LineOut().origin(0); + rmu.out.Y=mu.LineOut().origin(1); + rmu.out.Z=mu.LineOut().origin(2); + rmu.out.dirX=mu.LineOut().direction(0); + rmu.out.dirY=mu.LineOut().direction(1); + rmu.out.dirZ=mu.LineOut().direction(2); + + rmu.in.p = mu.GetMomentum(); + rmu.out.p = mu.GetMomentumPrime(); + + return rmu; +} + +uLib::MuonScatter &operator >>(const MuonScatter &rmu, uLib::MuonScatter &mu) { + + mu.LineIn().origin << rmu.in.X, rmu.in.Y, rmu.in.Z; + mu.LineIn().direction << rmu.in.dirX, rmu.in.dirY, rmu.in.dirZ; + mu.LineOut().origin << rmu.out.X, rmu.out.Y, rmu.out.Z; + mu.LineOut().direction << rmu.out.dirX, rmu.out.dirY, rmu.out.dirZ; + + mu.SetMomentum(rmu.in.p); + mu.SetMomentumPrime(rmu.out.p); + + return mu; +} + + + +} +} + diff --git a/src/Root/RootMuonScatter.h b/src/Root/RootMuonScatter.h new file mode 100644 index 0000000..709281f --- /dev/null +++ b/src/Root/RootMuonScatter.h @@ -0,0 +1,65 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ +#ifndef ROOTMUONSCATTER_H +#define ROOTMUONSCATTER_H + +namespace uLib { +class MuonScatter; +} + +namespace ROOT { +namespace Mutom { + +struct MuonTrack { + float X; + float Y; + float Z; + + float dirX; + float dirY; + float dirZ; + + float p; +}; + +struct MuonScatter { +public: + MuonTrack in, out; + inline float p_mean() const; +}; + +// this is only for testing function link in dictionary ... // +float MuonScatter::p_mean() const { + return (in.p + out.p)/2; +} + +MuonScatter &operator <<(MuonScatter &rmu, const uLib::MuonScatter &mu); +uLib::MuonScatter &operator >>(const MuonScatter &rmu, uLib::MuonScatter &mu); + + +} // Mutom +} // ROOT + +#endif // ROOTMUONSCATTER_H diff --git a/src/Root/TestTObject.cpp b/src/Root/TestTObject.cpp new file mode 100644 index 0000000..31a9535 --- /dev/null +++ b/src/Root/TestTObject.cpp @@ -0,0 +1,29 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + +#include "TestTObject.h" + + +ClassImp(TestTObject) diff --git a/src/Root/TestTObject.h b/src/Root/TestTObject.h new file mode 100644 index 0000000..d7041e7 --- /dev/null +++ b/src/Root/TestTObject.h @@ -0,0 +1,47 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_ROOT_TESTTOBJECT_H +#define U_ROOT_TESTTOBJECT_H + +#include +#include +#include +#include + +class TestTObject : public TObject { +public: + int a,b,c; + TestTObject() : a(1),b(2),c(3) {} + virtual ~TestTObject() {} + ClassDef(TestTObject,1) +}; + + + + +#endif // TESTTOBJECT_H diff --git a/src/Root/muBlastHit.cpp b/src/Root/muBlastHit.cpp new file mode 100644 index 0000000..71c1712 --- /dev/null +++ b/src/Root/muBlastHit.cpp @@ -0,0 +1,65 @@ +//------------------------------------------------ +// The Virtual Monte Carlo examples +// Copyright (C) 2007, 2008 Ivana Hrivnacova +// All rights reserved. +// +// For the licensing terms see geant4_vmc/LICENSE. +// Contact: vmc@pcroot.cern.ch +//------------------------------------------------- + +/// \file muBlastHit.cxx +/// \brief Implementation of the muBlastHit class +/// +/// \author G. Bonomi, F. Zenoni, M. Subieta - INFN + +#include + +#include "muBlastHit.h" + +/// \cond CLASSIMP +ClassImp(muBlastHit) +/// \endcond + +using namespace std; + +//namespace ROOT { +//namespace Mutom { + +//_____________________________________________________________________________ +muBlastHit::muBlastHit() + : fTrackID(-1), + fPdgCode(-1), + fMotherID(-1), + fEvent(-1), + fElemID(-1), + fSectID(-1), + fEdep(0.), + fTime(0.), + fStep(0.), + fMom(), + fPos(), + fLastPos() +{ +/// Default constructor +} +//_____________________________________________________________________________ +muBlastHit::~muBlastHit() +{ +/// Destructor +} +//_____________________________________________________________________________ +void muBlastHit::Print(const Option_t* /*opt*/) const +{ +/// Printing + + cout << " trackID: " << fTrackID + << " ElementID: " << fElemID + << " SectionID: " << fSectID + << " energy deposit (keV): " << fEdep * 1.0e06 + << " position (cm): (" + << fPos[0] << ", " << fPos[1] << ", " << fPos[2] << ")" + << endl; +} +//} // end Mutom +//} // end ROOT + diff --git a/src/Root/muBlastHit.h b/src/Root/muBlastHit.h new file mode 100644 index 0000000..c4d736a --- /dev/null +++ b/src/Root/muBlastHit.h @@ -0,0 +1,126 @@ +#ifndef muBlast_HIT_H +#define muBlast_HIT_H + +//------------------------------------------------ +// The Virtual Monte Carlo examples +// Copyright (C) 2007, 2008 Ivana Hrivnacova +// All rights reserved. +// +// For the licensing terms see geant4_vmc/LICENSE. +// Contact: vmc@pcroot.cern.ch +//------------------------------------------------- + +/// \file muBlastHit.h +/// \brief Definition of the muBlastHit class +/// +/// \authors G. Bonomi, M. Subieta - INFN + +#include +#include + +//namespace ROOT { +//namespace Mutom { + +class muBlastHit : public TObject +{ + public: + muBlastHit(); + virtual ~muBlastHit(); + + // methods + virtual void Print(const Option_t* option = "") const; + + // set methods + /// Set track Id + void SetTrackID (Int_t track) { fTrackID = track; }; + + /// Set particle PDG Code + void SetPdgCode (Int_t pdg) { fPdgCode = pdg; }; + + /// Set Mother ID + void SetMotherID (Int_t mid) { fMotherID = mid; }; + + /// Set track Id + void SetEventNumber (Int_t ievt) { fEvent = ievt; }; + + /// Set Element ID (e.g. fiber, strip) + void SetElemID(Int_t id) { fElemID = id; }; + + /// Set Section ID (e.g. layer, wafer) + void SetSectID(Int_t id) { fSectID = id; }; + + /// Set energy deposit + void SetEdep (Double_t de) { fEdep = de; }; + + /// Set hit time + void SetTime (Double_t dt) { fTime = dt; }; + + /// Set step length + void SetStep (Double_t dl) { fStep = dl; }; + + /// Set momentum + void SetMom (TVector3 xyz) { fMom = xyz; }; + + /// Set hit coordinates + void SetPos (TVector3 xyz) { fPos = xyz; }; + + /// Set last position + void SetLastPos (TVector3 xyz) { fLastPos = xyz; }; + + // + // get methods + + /// \return The track Id + Int_t GetTrackID() { return fTrackID; }; + + /// \return The event number + Int_t GetEventNumber() { return fEvent; }; + + /// \return The Module number + Int_t GetElemID() { return fElemID; }; + + /// \return The Layer number + Int_t GetSectID() { return fSectID; }; + + /// \return The energy deposit + Double_t GetEdep() { return fEdep; }; + + /// \return The hit time + Double_t GetTime() { return fTime; }; + + /// \return The step length + Double_t GetStep() { return fStep; }; + + /// \return The track position + TVector3 GetMom() { return fMom; }; + + // return Hit coordinates (at the entrance of the detector) + TVector3 GetPos() { return fPos; }; + + // return Last position (at the exit of the detector or when decayed) + TVector3 GetLastPos() { return fLastPos; }; + + public: + Int_t fTrackID; // Track Id + Int_t fPdgCode; // Particle PDG Code + Int_t fMotherID; // Particle mother ID (-1 = primary, 0 = secondary, etc..) + Int_t fEvent; // Event Number + Int_t fElemID; // Detector Element ID (e.g. fiber, strip) + Int_t fSectID; // Detector Section/Sector ID (e.g. layer, wafer) + Double_t fEdep; // Energy deposit + Double_t fTime; // Hit time + Double_t fStep; // Step Length + TVector3 fMom; // Track momentum when releasing the hit + TVector3 fPos; // Hit coordinates (at the entrance of the detector) + // 12/03/2012: for the moment, fLastPos is introduced for gDetSD only + TVector3 fLastPos; // Last position (at the exit of the detector or when decayed) + + ClassDef(muBlastHit,1) //muBlastHit +}; + +//} // Mutom +//} // ROOT + +#endif //muBlastt_HIT_H + + diff --git a/src/Root/muBlastMCTrack.cpp b/src/Root/muBlastMCTrack.cpp new file mode 100644 index 0000000..da5411f --- /dev/null +++ b/src/Root/muBlastMCTrack.cpp @@ -0,0 +1,230 @@ +//***************************************************************************************** +// muBlastMCTrack class +// Created at the University of Brescia, Italy +// Date: December 2011 +// Autors: Germano Bonomi germano.bonomi@ing.unibs.it +// Martin Subieta martin.subieta@ing.unibs.it +//****************************************************************************************** + + +#include "Detectors/MuonScatter.h" +#include +#include +#include + +ClassImp(muBlastMCTrack) + +uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muBlastMCTrack &bsmu) { + + /// store muons only if at least two points are stored in track + if(bsmu.fNpoints >= 2) { + mu.LineIn().origin << bsmu.fPntPosX[0], bsmu.fPntPosY[0], bsmu.fPntPosZ[0]; + mu.LineIn().direction << bsmu.fPntMomX[0], bsmu.fPntMomY[0], bsmu.fPntMomZ[0]; + + mu.LineOut().origin << bsmu.fPntPosX[bsmu.fNpoints-1], bsmu.fPntPosY[bsmu.fNpoints-1], bsmu.fPntPosZ[bsmu.fNpoints-1]; + mu.LineOut().direction << bsmu.fPntMomX[bsmu.fNpoints-1], bsmu.fPntMomY[bsmu.fNpoints-1], bsmu.fPntMomZ[bsmu.fNpoints-1]; + + mu.SetMomentum(mu.LineIn().direction.norm()); + mu.SetMomentumPrime(mu.LineOut().direction.norm()); + } + + return mu; +} + +//namespace ROOT { +//namespace Mutom { + + +// ----- Default constructor ------------------------------------------- +muBlastMCTrack::muBlastMCTrack() +{ + fPdgCode = 0; // PDG code of the particle + fMother[0] = 0; // Indices of the mother particles + fDaughter[0] = -1; // Indices of the daughter particles + fMother[1] = 0; // Indices of the mother particles + fDaughter[1] = -1; // Indices of the daughter particles + fPx = 0.; // x component of momentum + fPy = 0.; // y component of momentum + fPz = 0.; // z component of momentum + fE = 0.; // Energy + fVx = 0.; // x of production vertex + fVy = 0.; // y of production vertex + fVz = 0.; // z of production vertex + fVt = 0.; // t of production vertex + + fPointsSize = 0; // Maximum number of points associated to the tracks + fNpoints = 0; // Number of points associated to this track + fPntPosX = 0; // Array of points X + fPntPosY = 0; // Array of points Y + fPntPosZ = 0; // Array of points Z + fPntT = 0; // Array of points Time + fPntMomX = 0; // Array of points Mom X + fPntMomY = 0; // Array of points Mom Y + fPntMomZ = 0; // Array of points Mom Z + fPntE = 0; // Array of points Energy + +} +// ------------------------------------------------------------------------- + + + + +// ----- Constructor from TParticle ------------------------------------ +muBlastMCTrack::muBlastMCTrack(TParticle* part) +{ + + fPdgCode = part->GetPdgCode(); + fMother[0] = part->GetFirstMother(); + fMother[1] = part->GetSecondMother(); + fDaughter[0] = part->GetFirstDaughter(); + fDaughter[1] = part->GetLastDaughter(); + fPx = part->Px(); + fPy = part->Py(); + fPz = part->Pz(); + fE = part->Energy(); + + fVx = part->Vx(); + fVy = part->Vy(); + fVz = part->Vz(); + fVt = part->T(); + + fPointsSize = 0; // Maximum number of points associated to the tracks + fNpoints = 0; // Number of points associated to this track + fPntPosX = 0; // Array of points X + fPntPosY = 0; // Array of points Y + fPntPosZ = 0; // Array of points Z + fPntT = 0; // Array of points Time + fPntMomX = 0; // Array of points Mom X + fPntMomY = 0; // Array of points Mom Y + fPntMomZ = 0; // Array of points Mom Z + fPntE = 0; // Array of points Energy +} +// ------------------------------------------------------------------------- + + + +// ----- Destructor ---------------------------------------------------- +muBlastMCTrack::~muBlastMCTrack() +{ + if (fPntPosX) delete [] fPntPosX; + if (fPntPosY) delete [] fPntPosY; + if (fPntPosZ) delete [] fPntPosZ; + if (fPntT) delete [] fPntT; + if (fPntMomX) delete [] fPntMomX; + if (fPntMomY) delete [] fPntMomY; + if (fPntMomZ) delete [] fPntMomZ; + if (fPntE) delete [] fPntE; +} +// ------------------------------------------------------------------------- +//______________________________________________________________________________ +void muBlastMCTrack::AddPoint(TLorentzVector pos, TLorentzVector mom) +{ + +// Add a point to the track (copied from TGeoTrack::AddPoint) + if (!fPntPosX) { + fPointsSize = 12; // The first time create the array with fPointsSize size + fPntPosX = new Double_t[fPointsSize]; + fPntPosY = new Double_t[fPointsSize]; + fPntPosZ = new Double_t[fPointsSize]; + fPntT = new Double_t[fPointsSize]; + fPntMomX = new Double_t[fPointsSize]; + fPntMomY = new Double_t[fPointsSize]; + fPntMomZ = new Double_t[fPointsSize]; + fPntE = new Double_t[fPointsSize]; + } else { + if (fNpoints>=fPointsSize) { // when needed increase the arrays size by 4 + Int_t newSize = fPointsSize + 4; + // Pos (X, Y, Z) & Time + Double_t *tPosX = new Double_t[newSize]; + memcpy(tPosX, fPntPosX, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosX; + fPntPosX = tPosX; + + Double_t *tPosY = new Double_t[newSize]; + memcpy(tPosY, fPntPosY, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosY; + fPntPosY = tPosY; + + Double_t *tPosZ = new Double_t[newSize]; + memcpy(tPosZ, fPntPosZ, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosZ; + fPntPosZ = tPosZ; + + Double_t *tT = new Double_t[newSize]; + memcpy(tT, fPntT, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntT; + fPntT = tT; + + // Mom (X, Y, Z) & Energy + Double_t *tMomX = new Double_t[newSize]; + memcpy(tMomX, fPntMomX, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomX; + fPntMomX = tMomX; + + Double_t *tMomY = new Double_t[newSize]; + memcpy(tMomY, fPntMomY, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomY; + fPntMomY = tMomY; + + Double_t *tMomZ = new Double_t[newSize]; + memcpy(tMomZ, fPntMomZ, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomZ; + fPntMomZ = tMomZ; + + Double_t *tE = new Double_t[newSize]; + memcpy(tE, fPntE, fNpoints*sizeof(Double_t)); + fPointsSize = newSize; + delete [] fPntE; + fPntE = tE; + } + } + + // Storing the info + fPntPosX[fNpoints] = pos[0]; + fPntPosY[fNpoints] = pos[1]; + fPntPosZ[fNpoints] = pos[2]; + fPntT[fNpoints] = pos[3]; + + fPntMomX[fNpoints] = mom[0]; + fPntMomY[fNpoints] = mom[1]; + fPntMomZ[fNpoints] = mom[2]; + fPntE [fNpoints] = mom[3]; + + fNpoints++; // One more point +} + +//_____________________________________________________________________________ +void muBlastMCTrack::Reset() +{ +/// Delete contained particles, reset particles array and stack. + + fNpoints = 0; + fPointsSize = 0; + if (fPntPosX) delete [] fPntPosX; + if (fPntPosY) delete [] fPntPosY; + if (fPntPosZ) delete [] fPntPosZ; + if (fPntT) delete [] fPntT; + if (fPntMomX) delete [] fPntMomX; + if (fPntMomY) delete [] fPntMomY; + if (fPntMomZ) delete [] fPntMomZ; + if (fPntE) delete [] fPntE; + fPntPosX = 0; + fPntPosY = 0; + fPntPosZ = 0; + fPntT = 0; + fPntMomX = 0; + fPntMomY = 0; + fPntMomZ = 0; + fPntE = 0; + +} + +//} // Mutom +//} // ROOT diff --git a/src/Root/muBlastMCTrack.h b/src/Root/muBlastMCTrack.h new file mode 100644 index 0000000..e0caab1 --- /dev/null +++ b/src/Root/muBlastMCTrack.h @@ -0,0 +1,96 @@ +#ifndef muBlast_MCTRACK_H +#define muBlast_MCTRACK_H + +//######################################## +// muBlastMCTrack class +// Created at the University of Brescia, Italy +// Date: December 2011 +// Autors: Germano Bonomi germano.bonomi@ing.unibs.it +// Martin Subieta martin.subieta@ing.unibs.it +//######################################## + +#include +#include "TObject.h" +#include "TParticle.h" + +class TClonesArray; + + + +namespace uLib { +class MuonScatter; +} + +//namespace ROOT { +//namespace Mutom { +class muBlastMCTrack : public TObject +{ + + public: + + /** Default constructor **/ + muBlastMCTrack(); + + /** Constructor from TParticle **/ + muBlastMCTrack(TParticle* particle); + + /** Destructor **/ + virtual ~muBlastMCTrack(); + void Reset(); + + + /** Accessors **/ + Int_t GetFirstDaughter() const { return fDaughter[0];} + Int_t GetMother() const { return fMother[0];} + + /** Modifiers **/ + virtual void AddPoint(TLorentzVector pos, TLorentzVector mom); + virtual void SetFirstDaughter(Int_t trkid) { fDaughter[0] = trkid; } + virtual void SetLastDaughter(Int_t trkid) { fDaughter[1] = trkid; } + + inline void Dump() { + std::cout << "muBlastMCTrack\n" + << "PDG code: " << fPdgCode << "\n" + << "Momentum: " << fPx << ", " << fPy << ", " << fPz << "\n" + << "Position: " << fVx << ", " << fVy << ", " << fVz << "\n" + << "Npoints: " << fNpoints << "\n"; + return; + } + +//private: +public: + + Int_t fPdgCode; // PDG code of the particle + Int_t fMother[2]; // Indices of the mother particles + Int_t fDaughter[2]; // Indices of the daughter particles + + Double_t fPx; // x component of momentum + Double_t fPy; // y component of momentum + Double_t fPz; // z component of momentum + Double_t fE; // Energy + + Double_t fVx; // x of production vertex + Double_t fVy; // y of production vertex + Double_t fVz; // z of production vertex + Double_t fVt; // t of production vertex + + Int_t fPointsSize; // capacity of points array + Int_t fNpoints; // number of stored points + Double_t *fPntPosX; //[fNpoints] array of points (x) belonging to this track + Double_t *fPntPosY; //[fNpoints] array of points (y) belonging to this track + Double_t *fPntPosZ; //[fNpoints] array of points (z) belonging to this track + Double_t *fPntT; //[fNpoints] array of points (t) belonging to this track + Double_t *fPntMomX; //[fNpoints] array of points (px) belonging to this track + Double_t *fPntMomY; //[fNpoints] array of points (py) belonging to this track + Double_t *fPntMomZ; //[fNpoints] array of points (pz) belonging to this track + Double_t *fPntE; //[fNpoints] array of points (E) belonging to this track + + ClassDef(muBlastMCTrack,1); +}; + +//} // Mutom +//} // ROOT + + +uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muBlastMCTrack &bsmu); +#endif //muBlast_MCTRACK_H diff --git a/src/Root/muCastorHit.cpp b/src/Root/muCastorHit.cpp new file mode 100644 index 0000000..e55b824 --- /dev/null +++ b/src/Root/muCastorHit.cpp @@ -0,0 +1,60 @@ +//------------------------------------------------ +// The Virtual Monte Carlo examples +// Copyright (C) 2007, 2008 Ivana Hrivnacova +// All rights reserved. +// +// For the licensing terms see geant4_vmc/LICENSE. +// Contact: vmc@pcroot.cern.ch +//------------------------------------------------- + +/// \file muCastorHit.cxx +/// \brief Implementation of the muCastorHit class +/// +/// \author G. Bonomi, F. Zenoni, M. Subieta - INFN + +#include + +#include "muCastorHit.h" + +/// \cond CLASSIMP +ClassImp(muCastorHit) +/// \endcond + +using namespace std; + +//_____________________________________________________________________________ +muCastorHit::muCastorHit() + : fTrackID(-1), + fPdgCode(-1), + fMotherID(-1), + fEvent(-1), + fElemID(-1), + fSectID(-1), + fEdep(0.), + fTime(0.), + fStep(0.), + fMom(), + fPos(), + fLastPos() +{ +/// Default constructor +} +//_____________________________________________________________________________ +muCastorHit::~muCastorHit() +{ +/// Destructor +} +//_____________________________________________________________________________ +void muCastorHit::Print(const Option_t* /*opt*/) const +{ +/// Printing + + cout << " trackID: " << fTrackID + << " ElementID: " << fElemID + << " SectionID: " << fSectID + << " energy deposit (keV): " << fEdep * 1.0e06 + << " position (cm): (" + << fPos[0] << ", " << fPos[1] << ", " << fPos[2] << ")" + << endl; +} + diff --git a/src/Root/muCastorHit.h b/src/Root/muCastorHit.h new file mode 100644 index 0000000..f34a7c6 --- /dev/null +++ b/src/Root/muCastorHit.h @@ -0,0 +1,122 @@ +#ifndef muCastor_HIT_H +#define muCastor_HIT_H + +//------------------------------------------------ +// The Virtual Monte Carlo examples +// Copyright (C) 2007, 2008 Ivana Hrivnacova +// All rights reserved. +// +// For the licensing terms see geant4_vmc/LICENSE. +// Contact: vmc@pcroot.cern.ch +//------------------------------------------------- + +/// \file muCastorHit.h +/// \brief Definition of the muCastorHit class +/// +/// \authors G. Bonomi, M. Subieta - INFN + +#include +#include + +class muCastorHit : public TObject +{ + public: + muCastorHit(); + virtual ~muCastorHit(); + + // methods + virtual void Print(const Option_t* option = "") const; + + // + // set methods + + /// Set track Id + void SetTrackID (Int_t track) { fTrackID = track; }; + + /// Set particle PDG Code + void SetPdgCode (Int_t pdg) { fPdgCode = pdg; }; + + /// Set Mother ID + void SetMotherID (Int_t mid) { fMotherID = mid; }; + + /// Set track Id + void SetEventNumber (Int_t ievt) { fEvent = ievt; }; + + /// Set Element ID (e.g. fiber, strip) + void SetElemID(Int_t id) { fElemID = id; }; + + /// Set Section ID (e.g. layer, wafer) + void SetSectID(Int_t id) { fSectID = id; }; + + /// Set energy deposit + void SetEdep (Double_t de) { fEdep = de; }; + + /// Set hit time + void SetTime (Double_t dt) { fTime = dt; }; + + /// Set step length + void SetStep (Double_t dl) { fStep = dl; }; + + /// Set momentum + void SetMom (TVector3 xyz) { fMom = xyz; }; + + /// Set hit coordinates + void SetPos (TVector3 xyz) { fPos = xyz; }; + + /// Set last position + void SetLastPos (TVector3 xyz) { fLastPos = xyz; }; + + // + // get methods + + /// \return The track Id + Int_t GetTrackID() { return fTrackID; }; + + /// \return The event number + Int_t GetEventNumber() { return fEvent; }; + + /// \return The Module number + Int_t GetElemID() { return fElemID; }; + + /// \return The Layer number + Int_t GetSectID() { return fSectID; }; + + /// \return The energy deposit + Double_t GetEdep() { return fEdep; }; + + /// \return The hit time + Double_t GetTime() { return fTime; }; + + /// \return The step length + Double_t GetStep() { return fStep; }; + + /// \return The track position + TVector3 GetMom() { return fMom; }; + + // return Hit coordinates (at the entrance of the detector) + TVector3 GetPos() { return fPos; }; + + // return Last position (at the exit of the detector or when decayed) + TVector3 GetLastPos() { return fLastPos; }; + + public: + Int_t fTrackID; // Track Id + Int_t fPdgCode; // Particle PDG Code + Int_t fMotherID; // Particle mother ID (-1 = primary, 0 = secondary, etc..) + Int_t fEvent; // Event Number + Int_t fElemID; // Detector Element ID (e.g. fiber, strip) + Int_t fSectID; // Detector Section/Sector ID (e.g. layer, wafer) + Double_t fEdep; // Energy deposit + Double_t fTime; // Hit time + Double_t fStep; // Step Length + TVector3 fMom; // Track momentum when releasing the hit + TVector3 fPos; // Hit coordinates (at the entrance of the detector) + // 12/03/2012: for the moment, fLastPos is introduced for gDetSD only + TVector3 fLastPos; // Last position (at the exit of the detector or when decayed) + + ClassDef(muCastorHit,1) //muCastorHit +}; + +#endif //muCastort_HIT_H + + diff --git a/src/Root/muCastorMCTrack.cpp b/src/Root/muCastorMCTrack.cpp new file mode 100644 index 0000000..af88e29 --- /dev/null +++ b/src/Root/muCastorMCTrack.cpp @@ -0,0 +1,227 @@ +//***************************************************************************************** +// muCastorMCTrack class +// Created at the University of Brescia, Italy +// Date: December 2011 +// Autors: Germano Bonomi germano.bonomi@ing.unibs.it +// Martin Subieta martin.subieta@ing.unibs.it +//****************************************************************************************** + +#include + +#include "Detectors/MuonScatter.h" +#include +#include + +using namespace std; + +ClassImp(muCastorMCTrack) +uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muCastorMCTrack &bsmu) { + + /// store muons only if at least two points are stored in track + if(bsmu.fNpoints >= 2) { + mu.LineIn().origin << bsmu.fPntPosX[0], bsmu.fPntPosY[0], bsmu.fPntPosZ[0]; + mu.LineIn().direction << bsmu.fPntMomX[0], bsmu.fPntMomY[0], bsmu.fPntMomZ[0]; + + mu.LineOut().origin << bsmu.fPntPosX[bsmu.fNpoints-1], bsmu.fPntPosY[bsmu.fNpoints-1], bsmu.fPntPosZ[bsmu.fNpoints-1]; + mu.LineOut().direction << bsmu.fPntMomX[bsmu.fNpoints-1], bsmu.fPntMomY[bsmu.fNpoints-1], bsmu.fPntMomZ[bsmu.fNpoints-1]; + + mu.SetMomentum(mu.LineIn().direction.norm()); + mu.SetMomentumPrime(mu.LineOut().direction.norm()); + } + + return mu; +} + +//namespace ROOT { +//namespace Mutom { +// ----- Default constructor ------------------------------------------- +muCastorMCTrack::muCastorMCTrack() +{ + fPdgCode = 0; // PDG code of the particle + fMother[0] = 0; // Indices of the mother particles + fDaughter[0] = -1; // Indices of the daughter particles + fMother[1] = 0; // Indices of the mother particles + fDaughter[1] = -1; // Indices of the daughter particles + fPx = 0.; // x component of momentum + fPy = 0.; // y component of momentum + fPz = 0.; // z component of momentum + fE = 0.; // Energy + fVx = 0.; // x of production vertex + fVy = 0.; // y of production vertex + fVz = 0.; // z of production vertex + fVt = 0.; // t of production vertex + + fPointsSize = 0; // Maximum number of points associated to the tracks + fNpoints = 0; // Number of points associated to this track + fPntPosX = 0; // Array of points X + fPntPosY = 0; // Array of points Y + fPntPosZ = 0; // Array of points Z + fPntT = 0; // Array of points Time + fPntMomX = 0; // Array of points Mom X + fPntMomY = 0; // Array of points Mom Y + fPntMomZ = 0; // Array of points Mom Z + fPntE = 0; // Array of points Energy + +} +// ------------------------------------------------------------------------- + + + +// ----- Constructor from TParticle ------------------------------------ +muCastorMCTrack::muCastorMCTrack(TParticle* part) +{ + + fPdgCode = part->GetPdgCode(); + fMother[0] = part->GetFirstMother(); + fMother[1] = part->GetSecondMother(); + fDaughter[0] = part->GetFirstDaughter(); + fDaughter[1] = part->GetLastDaughter(); + fPx = part->Px(); + fPy = part->Py(); + fPz = part->Pz(); + fE = part->Energy(); + + fVx = part->Vx(); + fVy = part->Vy(); + fVz = part->Vz(); + fVt = part->T(); + + fPointsSize = 0; // Maximum number of points associated to the tracks + fNpoints = 0; // Number of points associated to this track + fPntPosX = 0; // Array of points X + fPntPosY = 0; // Array of points Y + fPntPosZ = 0; // Array of points Z + fPntT = 0; // Array of points Time + fPntMomX = 0; // Array of points Mom X + fPntMomY = 0; // Array of points Mom Y + fPntMomZ = 0; // Array of points Mom Z + fPntE = 0; // Array of points Energy +} +// ------------------------------------------------------------------------- + + + +// ----- Destructor ---------------------------------------------------- +muCastorMCTrack::~muCastorMCTrack() +{ + if (fPntPosX) delete [] fPntPosX; + if (fPntPosY) delete [] fPntPosY; + if (fPntPosZ) delete [] fPntPosZ; + if (fPntT) delete [] fPntT; + if (fPntMomX) delete [] fPntMomX; + if (fPntMomY) delete [] fPntMomY; + if (fPntMomZ) delete [] fPntMomZ; + if (fPntE) delete [] fPntE; +} +// ------------------------------------------------------------------------- +//______________________________________________________________________________ +void muCastorMCTrack::AddPoint(TLorentzVector pos, TLorentzVector mom) +{ + +// Add a point to the track (copied from TGeoTrack::AddPoint) + if (!fPntPosX) { + fPointsSize = 12; // The first time create the array with fPointsSize size + fPntPosX = new Double_t[fPointsSize]; + fPntPosY = new Double_t[fPointsSize]; + fPntPosZ = new Double_t[fPointsSize]; + fPntT = new Double_t[fPointsSize]; + fPntMomX = new Double_t[fPointsSize]; + fPntMomY = new Double_t[fPointsSize]; + fPntMomZ = new Double_t[fPointsSize]; + fPntE = new Double_t[fPointsSize]; + } else { + if (fNpoints>=fPointsSize) { // when needed increase the arrays size by 4 + Int_t newSize = fPointsSize + 4; + // Pos (X, Y, Z) & Time + Double_t *tPosX = new Double_t[newSize]; + memcpy(tPosX, fPntPosX, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosX; + fPntPosX = tPosX; + + Double_t *tPosY = new Double_t[newSize]; + memcpy(tPosY, fPntPosY, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosY; + fPntPosY = tPosY; + + Double_t *tPosZ = new Double_t[newSize]; + memcpy(tPosZ, fPntPosZ, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntPosZ; + fPntPosZ = tPosZ; + + Double_t *tT = new Double_t[newSize]; + memcpy(tT, fPntT, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntT; + fPntT = tT; + + // Mom (X, Y, Z) & Energy + Double_t *tMomX = new Double_t[newSize]; + memcpy(tMomX, fPntMomX, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomX; + fPntMomX = tMomX; + + Double_t *tMomY = new Double_t[newSize]; + memcpy(tMomY, fPntMomY, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomY; + fPntMomY = tMomY; + + Double_t *tMomZ = new Double_t[newSize]; + memcpy(tMomZ, fPntMomZ, fNpoints*sizeof(Double_t)); + fPointsSize *= 2; + delete [] fPntMomZ; + fPntMomZ = tMomZ; + + Double_t *tE = new Double_t[newSize]; + memcpy(tE, fPntE, fNpoints*sizeof(Double_t)); + fPointsSize = newSize; + delete [] fPntE; + fPntE = tE; + } + } + + // Storing the info + fPntPosX[fNpoints] = pos[0]; + fPntPosY[fNpoints] = pos[1]; + fPntPosZ[fNpoints] = pos[2]; + fPntT[fNpoints] = pos[3]; + + fPntMomX[fNpoints] = mom[0]; + fPntMomY[fNpoints] = mom[1]; + fPntMomZ[fNpoints] = mom[2]; + fPntE [fNpoints] = mom[3]; + + fNpoints++; // One more point +} + +//_____________________________________________________________________________ +void muCastorMCTrack::Reset() +{ +/// Delete contained particles, reset particles array and stack. + + fNpoints = 0; + fPointsSize = 0; + if (fPntPosX) delete [] fPntPosX; + if (fPntPosY) delete [] fPntPosY; + if (fPntPosZ) delete [] fPntPosZ; + if (fPntT) delete [] fPntT; + if (fPntMomX) delete [] fPntMomX; + if (fPntMomY) delete [] fPntMomY; + if (fPntMomZ) delete [] fPntMomZ; + if (fPntE) delete [] fPntE; + fPntPosX = 0; + fPntPosY = 0; + fPntPosZ = 0; + fPntT = 0; + fPntMomX = 0; + fPntMomY = 0; + fPntMomZ = 0; + fPntE = 0; + +} +//} // Mutom +//} // ROOT diff --git a/src/Root/muCastorMCTrack.h b/src/Root/muCastorMCTrack.h new file mode 100644 index 0000000..aabc33f --- /dev/null +++ b/src/Root/muCastorMCTrack.h @@ -0,0 +1,96 @@ +#ifndef muCastor_MCTRACK_H +#define muCastor_MCTRACK_H + +//######################################## +// muCastorMCTrack class +// Created at the University of Brescia, Italy +// Date: December 2011 +// Autors: Germano Bonomi germano.bonomi@ing.unibs.it +// Martin Subieta martin.subieta@ing.unibs.it +//######################################## + +#include "vector" +#include "TObject.h" +#include "TParticle.h" + +class TClonesArray; + + +namespace uLib { +class MuonScatter; +} + +//namespace ROOT { +//namespace Mutom { + +class muCastorMCTrack : public TObject +{ + + public: + + /** Default constructor **/ + muCastorMCTrack(); + + /** Constructor from TParticle **/ + muCastorMCTrack(TParticle* particle); + + /** Destructor **/ + virtual ~muCastorMCTrack(); + void Reset(); + + + /** Accessors **/ + Int_t GetFirstDaughter() const { return fDaughter[0];} + Int_t GetMother() const { return fMother[0];} + + /** Modifiers **/ + virtual void AddPoint(TLorentzVector pos, TLorentzVector mom); + virtual void SetFirstDaughter(Int_t trkid) { fDaughter[0] = trkid; } + virtual void SetLastDaughter(Int_t trkid) { fDaughter[1] = trkid; } + + inline void Dump() { + std::cout << "muCastorMCTrack\n" + << "PDG code: " << fPdgCode << "\n" + << "Momentum: " << fPx << ", " << fPy << ", " << fPz << "\n" + << "Position: " << fVx << ", " << fVy << ", " << fVz << "\n" + << "Npoints: " << fNpoints << "\n"; + return; + } + +public: + +/* Private variables - copying private variables of TParticle */ + + Int_t fPdgCode; // PDG code of the particle + Int_t fMother[2]; // Indices of the mother particles + Int_t fDaughter[2]; // Indices of the daughter particles + + Double_t fPx; // x component of momentum + Double_t fPy; // y component of momentum + Double_t fPz; // z component of momentum + Double_t fE; // Energy + + Double_t fVx; // x of production vertex + Double_t fVy; // y of production vertex + Double_t fVz; // z of production vertex + Double_t fVt; // t of production vertex + + Int_t fPointsSize; // capacity of points array + Int_t fNpoints; // number of stored points + Double_t *fPntPosX; //[fNpoints] array of points (x) belonging to this track + Double_t *fPntPosY; //[fNpoints] array of points (y) belonging to this track + Double_t *fPntPosZ; //[fNpoints] array of points (z) belonging to this track + Double_t *fPntT; //[fNpoints] array of points (t) belonging to this track + Double_t *fPntMomX; //[fNpoints] array of points (px) belonging to this track + Double_t *fPntMomY; //[fNpoints] array of points (py) belonging to this track + Double_t *fPntMomZ; //[fNpoints] array of points (pz) belonging to this track + Double_t *fPntE; //[fNpoints] array of points (E) belonging to this track + + ClassDef(muCastorMCTrack,1); + +}; +//} // Mutom +//} // ROOT + +uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muCastorMCTrack &bsmu); +#endif //muCastor_MCTRACK_H diff --git a/src/Root/testing/CMakeLists.txt b/src/Root/testing/CMakeLists.txt new file mode 100644 index 0000000..67cb15a --- /dev/null +++ b/src/Root/testing/CMakeLists.txt @@ -0,0 +1,16 @@ +# TESTS +set( TESTS + RootDebugTest + muBlastMCTrackTest +) + +set(LIBRARIES + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math + ${PACKAGE_LIBPREFIX}Root + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${ROOT_LIBRARIES} +) +uLib_add_tests(${uLib-module}) diff --git a/src/Root/testing/Makefile.am b/src/Root/testing/Makefile.am new file mode 100644 index 0000000..730b659 --- /dev/null +++ b/src/Root/testing/Makefile.am @@ -0,0 +1,20 @@ +include $(top_srcdir)/Common.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + +# if HAVE_CHECK +TESTS = RootDebugTest + +# UuidTest + +# else +# TEST = +# endif + +LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT) + +check_PROGRAMS = $(TESTS) + + +all: $(TESTS) + diff --git a/src/Root/testing/RootDebugTest.cpp b/src/Root/testing/RootDebugTest.cpp new file mode 100644 index 0000000..0735d22 --- /dev/null +++ b/src/Root/testing/RootDebugTest.cpp @@ -0,0 +1,101 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include +#include +#include +#include +#include +#include + +#include "Root/TestTObject.h" +#include "Root/RootMuonScatter.h" + +#include "Detectors/MuonScatter.h" + +TTree * getTree(TFile *m_File, const char *path, const char *name) { + std::string p = std::string("/") + std::string(path); + TDirectory *dir = m_File->GetDirectory(p.c_str()); + if(!dir) { + m_File->mkdir(path); + } + m_File->cd(path); + std::string n = p + std::string("/") + std::string(name); + TObject *obj = m_File->Get(n.c_str()); + if(!obj) { + TTree *tree = new TTree(); + tree->SetName(name); + return tree; + } + else { + return (TTree *)obj; + } +} + + +int main(int argc,char **argv) { + + uLib::MuonScatter u_mu; + ROOT::Mutom::MuonScatter mu; + + TFile *file = new TFile("test_file.root","RECREATE"); + TTree *tree = new TTree("test","Testing MuonScatter dump..."); + + tree->Branch("mu",&mu); + +// mu.in.X = 1; +// mu.in.Y = 2; +// mu.in.Z = 3; +// mu.in.dirX = 4; +// mu.in.dirY = 5; +// mu.in.dirZ = 6; +// mu.in.p = 555; +// mu.out.p = 2368; + + u_mu.LineIn().origin << 3,3,3; + u_mu.LineIn().direction << 5,5,5; + u_mu.LineOut().origin << 1,2,3; + u_mu.LineOut().direction << 4,5,6; + u_mu.SetMomentum(555); + u_mu.SetMomentumPrime(2368); + + mu << u_mu; + + tree->Fill(); + + file->cd(); + tree->Write(); + + gApplication = new TApplication("Application", &argc, argv); + TBrowser *tbr = new TBrowser("test"); + tbr->Show(); + gApplication->Run(); + + return 0; +} diff --git a/src/Root/testing/muBlastMCTrackTest.cpp b/src/Root/testing/muBlastMCTrackTest.cpp new file mode 100644 index 0000000..473d4d9 --- /dev/null +++ b/src/Root/testing/muBlastMCTrackTest.cpp @@ -0,0 +1,47 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +#include "Root/TestTObject.h" +#include "Root/RootMuonScatter.h" + +#include "Detectors/MuonScatter.h" + +#include "Root/muBlastMCTrack.h" + + +int main(int argc,char **argv) { + + TFile *file = new TFile(argv[1]); + TTree *tree = (TTree*) file->Get("muBlastMC"); + if (tree->IsZombie()) { + std::cerr << "Zombie tree\n"; + exit(1); + } + + TClonesArray * track_array = NULL; + tree->GetBranch("muBlastMCTrack")->SetAutoDelete(kFALSE); + tree->SetBranchAddress("muBlastMCTrack",&track_array); + + for(int i=0; iGetEntries(); ++i) { + tree->GetEntry(i); + int trn = track_array->GetEntriesFast(); + std::cout << "---- EV " << i << " : " << trn << " tracks ----------\n"; + for(int j=0; jAt(j); + if(abs(track->fPdgCode) == 13) + track->Dump(); + } + } + return 0; +} diff --git a/src/Vtk/CMakeLists.txt b/src/Vtk/CMakeLists.txt new file mode 100644 index 0000000..c26cf09 --- /dev/null +++ b/src/Vtk/CMakeLists.txt @@ -0,0 +1,39 @@ +set(HEADERS + uLibVtkInterface.h + uLibVtkViewer.h + vtkContainerBox.h + vtkMuonScatter.h + vtkStructuredGrid.h + vtkVoxRaytracerRepresentation.h + vtkVoxImage.h +# vtkHLineRepresentation.h +# vtkTriangleMesh.h +) + +SET(SOURCES + uLibVtkInterface.cxx + uLibVtkViewer.cpp + vtkContainerBox.cpp + vtkMuonScatter.cxx + vtkStructuredGrid.cpp + vtkVoxRaytracerRepresentation.cpp + vtkVoxImage.cpp +) + +set(LIBRARIES + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Eigen_LIBRARY} + ${ROOT_LIBRARIES} + ${Geant4_LIBRARIES} + ${VTK_LIBRARIES} + ${PACKAGE_LIBPREFIX}Core + ${PACKAGE_LIBPREFIX}Math + ${PACKAGE_LIBPREFIX}Detectors + ${PACKAGE_LIBPREFIX}Vtk +) + +uLib_add_shared_library(${uLib-module}) + +add_subdirectory(testing) diff --git a/src/Vtk/Makefile.am b/src/Vtk/Makefile.am new file mode 100644 index 0000000..9d175a5 --- /dev/null +++ b/src/Vtk/Makefile.am @@ -0,0 +1,34 @@ +SUBDIRS = . + +include $(top_srcdir)/Common.am +include Vtk.am + + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Vtk +library_include_HEADERS = uLibVtkInterface.h \ + uLibVtkViewer.h \ + vtkContainerBox.h \ + vtkMuonScatter.h \ + vtkStructuredGrid.h \ + vtkVoxRaytracerRepresentation.h \ + vtkVoxImage.h +# vtkHLineRepresentation.h \ +# vtkTriangleMesh.h + + +_VTK_SOURCES = uLibVtkInterface.cxx \ + uLibVtkViewer.cpp \ + vtkContainerBox.cpp \ + vtkMuonScatter.cxx \ + vtkStructuredGrid.cpp \ + vtkVoxRaytracerRepresentation.cpp \ + vtkVoxImage.cpp +#vtkTriangleMesh.cpp + + + +noinst_LTLIBRARIES = libconvtk.la +libconvtk_la_SOURCES = ${_VTK_SOURCES} +libconvtk_la_LIBADD = $(AM_LIBS_ALL) + + diff --git a/src/Vtk/Vtk.am b/src/Vtk/Vtk.am new file mode 100644 index 0000000..27e030a --- /dev/null +++ b/src/Vtk/Vtk.am @@ -0,0 +1,93 @@ + + +#if VTK_5_x +_VTK_LIBS = -lQVTK \ + -lLSDyna \ + -lMapReduceMPI \ + -lmpistubs \ + -lvtkalglib \ + -lvtkCharts \ + -lvtkCommon \ + -lvtkDICOMParser \ + -lvtkexoIIc \ + -lvtkFiltering \ + -lvtkftgl \ + -lvtkGenericFiltering \ + -lvtkGraphics \ + -lvtkHybrid \ + -lvtkImaging \ + -lvtkInfovis \ + -lvtkmetaio \ + -lvtkNetCDF_cxx \ + -lvtkNetCDF \ + -lvtkproj4 \ + -lvtkRendering \ + -lvtksqlite \ + -lvtksys \ + -lvtkverdict \ + -lvtkViews \ + -lvtkVolumeRendering \ + -lvtkWidgets + +AM_CFLAGS += $(VTK_CFLAGS) +AM_CXXFLAGS += $(VTK_CXXFLAGS) +AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS) + +#else +#_VTK_LIBS = \ +# -lvtkRenderingOpenGL-6.0 \ +# -lvtkImagingHybrid-6.0 \ +# -lvtkIOImage-6.0 \ +# -lvtkCommonDataModel-6.0 \ +# -lvtkCommonMath-6.0 \ +# -lvtkCommonCore-6.0 \ +# -lvtksys-6.0 \ +# -lvtkCommonMisc-6.0 \ +# -lvtkCommonSystem-6.0 \ +# -lvtkCommonTransforms-6.0 \ +# -lvtkCommonExecutionModel-6.0 \ +# -lvtkDICOMParser-6.0 \ +# -lvtkIOCore-6.0 \ +# -lvtkzlib-6.0 \ +# -lvtkmetaio-6.0 \ +# -lvtkjpeg-6.0 \ +# -lvtkpng-6.0 \ +# -lvtktiff-6.0 \ +# -lvtkImagingCore-6.0 \ +# -lvtkRenderingCore-6.0 \ +# -lvtkFiltersExtraction-6.0 \ +# -lvtkFiltersCore-6.0 \ +# -lvtkFiltersGeneral-6.0 \ +# -lvtkCommonComputationalGeometry-6.0 \ +# -lvtkFiltersStatistics-6.0 \ +# -lvtkImagingFourier-6.0 \ +# -lvtkalglib-6.0 \ +# -lvtkFiltersGeometry-6.0 \ +# -lvtkFiltersSources-6.0 \ +# -lvtkIOXMLParser-6.0 \ +# -lvtkexpat-6.0 \ +# -lvtkRenderingAnnotation-6.0 \ +# -lvtkImagingColor-6.0 \ +# -lvtkRenderingFreeType-6.0 \ +# -lvtkfreetype-6.0 \ +# -lvtkftgl-6.0 \ +# -lvtkInteractionStyle-6.0 \ +# -lvtkRenderingVolumeOpenGL-6.0 \ +# -lvtkRenderingVolume-6.0 \ +# -lvtkIOXML-6.0 \ +# -lvtkIOGeometry-6.0 \ +# -lvtkjsoncpp-6.0 \ +# -lvtkInteractionWidgets-6.0 \ +# -lvtkFiltersHybrid-6.0 \ +# -lvtkImagingSources-6.0 \ +# -lvtkFiltersModeling-6.0 \ +# -lvtkImagingGeneral-6.0 \ +# -lvtkIOLegacy-6.0 \ +# -lvtkRenderingFreeTypeOpenGL-6.0 + + + +#AM_CFLAGS += $(VTK_CFLAGS) +#AM_CXXFLAGS += $(VTK_CXXFLAGS) -rdynamic +#AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS) -lGLU -lSM -lICE -lX11 -lXext -lSM -lICE -lX11 -lXext -lXt -lm -ldl -lGL +#endif diff --git a/src/Vtk/testing/CMakeLists.txt b/src/Vtk/testing/CMakeLists.txt new file mode 100644 index 0000000..33a3847 --- /dev/null +++ b/src/Vtk/testing/CMakeLists.txt @@ -0,0 +1,13 @@ +# TESTS +set( TESTS + vtkViewerTest + vtkContainerBoxTest + vtkMuonScatter + vtkStructuredGridTest + vtkVoxRaytracerTest + vtkVoxImageTest +# vtkTriangleMeshTest +) + +include(${VTK_USE_FILE}) +uLib_add_tests(${uLib-module}) diff --git a/src/Vtk/testing/Makefile.am b/src/Vtk/testing/Makefile.am new file mode 100644 index 0000000..4cc3180 --- /dev/null +++ b/src/Vtk/testing/Makefile.am @@ -0,0 +1,21 @@ + +include $(top_srcdir)/Common.am +include ../Vtk.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + +# if HAVE_CHECK +TESTS = \ + vtkViewerTest \ + vtkContainerBoxTest \ + vtkMuonScatter \ + vtkStructuredGridTest \ + vtkVoxRaytracerTest \ + vtkVoxImageTest +# vtkTriangleMeshTest + +all: $(TESTS) + +LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_ALL) +check_PROGRAMS = $(TESTS) + diff --git a/src/Vtk/testing/testVtkWriter.cpp b/src/Vtk/testing/testVtkWriter.cpp new file mode 100644 index 0000000..5f8dc2d --- /dev/null +++ b/src/Vtk/testing/testVtkWriter.cpp @@ -0,0 +1,95 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include +#include +#include +#include + +#include + + +#include +#include + +int main(int, char *[]) +{ + // Create an image data + vtkSmartPointer imageData = + vtkSmartPointer::New(); + + // Specify the size of the image data + imageData->SetDimensions(10,20,15); +#if VTK_MAJOR_VERSION <= 5 + imageData->SetNumberOfScalarComponents(1); + imageData->SetScalarTypeToDouble(); +#else + imageData->AllocateScalars(VTK_DOUBLE,1); +#endif + + int* dims = imageData->GetDimensions(); + // int dims[3]; // can't do this + + std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl; + + std::cout << "Number of points: " << imageData->GetNumberOfPoints() << std::endl; + std::cout << "Number of cells: " << imageData->GetNumberOfCells() << std::endl; + + // Fill every entry of the image data with "2.0" + for (int z = 0; z < dims[2]; z++) + { + for (int y = 0; y < dims[1]; y++) + { + for (int x = 0; x < dims[0]; x++) + { + double* pixel = static_cast(imageData->GetScalarPointer(x,y,z)); + pixel[0] = (double)x+y+z; + } + } + } + + // imageData->GetCellData()->SetScalars(imageData->GetPointData()->GetScalars()); + + vtkSmartPointer ptoc = + vtkSmartPointer::New(); + + ptoc->SetInputConnection(imageData->GetProducerPort()); + + ptoc->Update(); + + vtkSmartPointer writer = + vtkSmartPointer::New(); + + + writer->SetInput(ptoc->GetImageDataOutput()); + writer->SetFileTypeToASCII(); + writer->SetFileName("output.vtk"); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/src/Vtk/testing/testing-prototype.h b/src/Vtk/testing/testing-prototype.h new file mode 100644 index 0000000..c801261 --- /dev/null +++ b/src/Vtk/testing/testing-prototype.h @@ -0,0 +1,41 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#include "Vtk/uLibVtkInterface.h" + + +#define BEGIN_TESTING(name) \ +static int _fail = 0; \ +printf("..:: Testing " #name " ::..\n"); + +#define TEST1(val) _fail += (val)==0 +#define TEST0(val) _fail += (val)!=0 +#define END_TESTING return _fail; + + diff --git a/src/Vtk/testing/vtkContainerBoxTest.cpp b/src/Vtk/testing/vtkContainerBoxTest.cpp new file mode 100644 index 0000000..7c477ef --- /dev/null +++ b/src/Vtk/testing/vtkContainerBoxTest.cpp @@ -0,0 +1,53 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "Vtk/uLibVtkViewer.h" + +#include "Math/ContainerBox.h" +#include "Vtk/vtkContainerBox.h" + +#include "testing-prototype.h" + +using namespace uLib; + +int main() { + BEGIN_TESTING(vtk ContainerBox Test); + + Vtk::Viewer v_viewer; + + ContainerBox box; + box.SetSize(Vector3f(2,3,4)); + box.SetPosition(Vector3f(1,2,3)); + + Vtk::vtkContainerBox v_box(box); + + v_viewer.AddPuppet(v_box); + v_viewer.Start(); + + + END_TESTING; +} diff --git a/src/Vtk/testing/vtkMuonScatter.cpp b/src/Vtk/testing/vtkMuonScatter.cpp new file mode 100644 index 0000000..2c9e7ca --- /dev/null +++ b/src/Vtk/testing/vtkMuonScatter.cpp @@ -0,0 +1,62 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "Detectors/MuonScatter.h" +#include "Vtk/vtkMuonScatter.h" + +#include "Vtk/uLibVtkViewer.h" + +#include "testing-prototype.h" + +using namespace uLib; + +int main() +{ + MuonScatter event; + event.LineIn().direction << 0, -1, 1, 0; + event.LineIn().origin << 0, 1, -1, 1; + + event.LineOut().direction << 0, -1, 0, 0; + event.LineOut().origin << 0, -1, 0, 1; + + Vtk::vtkMuonScatter v_event(event); + v_event.AddPocaPoint(HPoint3f(0,0,0)); + + v_event.SaveToXMLFile("vtk_testing_muonevent.vtp"); + + Vtk::Viewer viewer; + +// Vtk::Tie tms; +// tms.DoAction(); +// Vtk::Tie vms; +// vms.DoAction(); + + viewer.AddPuppet(v_event); + viewer.Start(); + + return 0; +} diff --git a/src/Vtk/testing/vtkStructuredGridTest.cpp b/src/Vtk/testing/vtkStructuredGridTest.cpp new file mode 100644 index 0000000..ffbc89b --- /dev/null +++ b/src/Vtk/testing/vtkStructuredGridTest.cpp @@ -0,0 +1,51 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Math/StructuredGrid.h" + +#include "Vtk/vtkStructuredGrid.h" +#include "Vtk/uLibVtkViewer.h" + +#include "testing-prototype.h" + +using namespace uLib; + +int main() +{ + + StructuredGrid grid(Vector3i(10,10,100)); + grid.SetSpacing(Vector3f(3,1,1)); + + Vtk::vtkStructuredGrid grid_viewer(grid); + + Vtk::Viewer viewer; + viewer.AddPuppet(grid_viewer); + viewer.Start(); + + return 0; +} diff --git a/src/Vtk/testing/vtkTriangleMeshTest.cpp b/src/Vtk/testing/vtkTriangleMeshTest.cpp new file mode 100644 index 0000000..5d12e6d --- /dev/null +++ b/src/Vtk/testing/vtkTriangleMeshTest.cpp @@ -0,0 +1,75 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Math/TriangleMesh.h" +#include "Vtk/vtkTriangleMesh.h" +#include "testing-prototype.h" + +using namespace uLib; + + +int main() +{ + BEGIN_TESTING(Vtk Triangle Mesh); + +// { // SIMPLE TESTS // + + +// TriangleMesh mesh; + +// mesh.AddPoint(Vector3f(0,0,0)); +// mesh.AddPoint(Vector3f(0,1,0)); +// mesh.AddPoint(Vector3f(1,0,0)); + +// mesh.AddTriangle(Vector3i(0,1,2)); + +// mesh.PrintSelf(std::cout); + + +// vtkTriangleMesh v_mesh(mesh); +// v_mesh.Update(); + +// TestingRenderWidow(&v_mesh); +// } + + { // SIMPLE TESTS // + + TriangleMesh mesh; + + vtkTriangleMesh v_mesh(mesh); + + v_mesh.ReadFromStlFile("prova.stl"); + + mesh.PrintSelf(std::cout); + + TestingRenderWidow(&v_mesh); + } + + + END_TESTING; +} diff --git a/src/Vtk/testing/vtkViewerTest.cpp b/src/Vtk/testing/vtkViewerTest.cpp new file mode 100644 index 0000000..22a42f8 --- /dev/null +++ b/src/Vtk/testing/vtkViewerTest.cpp @@ -0,0 +1,71 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include "testing-prototype.h" + +using namespace uLib; + +int main() +{ + BEGIN_TESTING(vtk Viewer Test); + + Vtk::Viewer v_viewer; + + + vtkSmartPointer cube = vtkSmartPointer::New(); + cube->SetXLength(10); + cube->SetYLength(10); + cube->SetZLength(10); + cube->Update(); + + vtkSmartPointer mapper = + vtkSmartPointer::New(); + mapper->SetInputConnection(cube->GetOutputPort()); + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + v_viewer.addProp(actor); + v_viewer.GetRenderer()->Render(); + v_viewer.Start(); + + END_TESTING; +} + diff --git a/src/Vtk/testing/vtkVoxImageTest.cpp b/src/Vtk/testing/vtkVoxImageTest.cpp new file mode 100644 index 0000000..579bf62 --- /dev/null +++ b/src/Vtk/testing/vtkVoxImageTest.cpp @@ -0,0 +1,102 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Math/VoxImage.h" +#include "Vtk/vtkVoxImage.h" +#include "Vtk/uLibVtkViewer.h" + +#include "testing-prototype.h" + +using namespace uLib; + +struct TestVoxel { + Scalarf Value; + unsigned int Count; +}; + +int main() +{ + BEGIN_TESTING(Vtk Vox Image); + + TestVoxel zero = {0,0}; + TestVoxel nonzero = {5.5*1E-6,100}; + +// { // SIMPLE TESTS // +// VoxImage img(Vector3i(10,10,10)); +// img.SetSpacing(Vector3f(3,3,3)); + +// img.InitVoxels(zero); +// img[Vector3i(3,3,3)] = nonzero; + +// Vtk::vtkVoxImage vtk_img(img); + +// vtk_img.SaveToXMLFile("test.vti"); +// vtk_img.setShadingPreset(0); + +// // vtk_img.ReadFromVKTFile("error.vtk"); + +// // VoxImage img2 = img; + +// // Vtk::vtkVoxImage vtk_img2(img2); + +// // img2.ExportToVtk("error_saved.vtk",0); + +// // vtk_img2.SaveToXMLFile("error_saved.vti"); + +// Vtk::Viewer viewer; +// viewer.AddPuppet(vtk_img); +// viewer.Start(); +// } + + { // SIMPLE TESTS // + VoxImage img(Vector3i(10,10,1)); + img.SetSpacing(Vector3f(3,3,3)); + + img.InitVoxels(zero); + img[Vector3i(3,3,0)] = nonzero; + + Vtk::vtkVoxImage vtk_img(img); + + vtk_img.ReadFromVKTFile("test.vtk"); + vtk_img.Update(); + + // vtk_img.SaveToXMLFile("test.vti"); + // vtk_img.setShadingPreset(0); + + // Vtk::vtkVoxImage vtk_img2(img2); + // img2.ExportToVtk("error_saved.vtk",0); + // vtk_img2.SaveToXMLFile("error_saved.vti"); + + Vtk::Viewer viewer; + viewer.AddPuppet(vtk_img); + viewer.Start(); + } + + + END_TESTING; +} diff --git a/src/Vtk/testing/vtkVoxRaytracerTest.cpp b/src/Vtk/testing/vtkVoxRaytracerTest.cpp new file mode 100644 index 0000000..aa1d264 --- /dev/null +++ b/src/Vtk/testing/vtkVoxRaytracerTest.cpp @@ -0,0 +1,156 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include +#include +#include + + +#include +#include + +#include "Vtk/vtkMuonScatter.h" +#include "Vtk/vtkStructuredGrid.h" +#include "Vtk/vtkVoxRaytracerRepresentation.h" +#include "Vtk/uLibVtkViewer.h" + +// remove +#include + +#include "testing-prototype.h" + +using namespace uLib; + + + +class vtkWidgetCallback : public vtkCommand +{ +public: + static vtkWidgetCallback *New() { return new vtkWidgetCallback; } + + void SetTracer(Vtk::vtkVoxRaytracerRepresentation *parent) + { + this->vtk_raytr = parent; + } + + void SetMuon (uLib::MuonScatter *muon) { this->muon = muon; } + + void SetAnnotation ( vtkCornerAnnotation *annotation) { + this->annotation = annotation; + } + + virtual void Execute(vtkObject *caller, unsigned long, void*) + { + char str[40]; + vtk_raytr->SetMuon(*muon); + if(annotation) + { + sprintf(str,"total length = %f",vtk_raytr->GetRay().TotalLength()); + annotation->SetText(1,str); + for(int i=0; iGetRay().Data().size(); ++i) + { + std::cout << "L[" << i << "] = " + << vtk_raytr->GetRay().Data().at(i).L << "\n"; + } + std::cout << "\n"; + } + } + +private: + vtkWidgetCallback() : + vtk_raytr(NULL), + muon(NULL), + annotation(NULL) {} + + uLib::VoxRaytracer *raytracer; + Vtk::vtkVoxRaytracerRepresentation *vtk_raytr; + uLib::MuonScatter *muon; + vtkCornerAnnotation *annotation; +}; + + + + +int main() +{ + BEGIN_TESTING(vtk VoxRaytracer); + + + // muon scatter // + MuonScatter muon; + muon.LineIn().origin << -6, 12, -6, 1; + muon.LineIn().direction << 1 , -1 , 1 , 0; + muon.LineOut().origin << 6 , -4 , 6 , 1; + muon.LineOut().direction << 1 , -1 , 1 , 0; + + Vtk::vtkMuonScatter v_muon(muon); + + + // structured grid // + StructuredGrid grid(Vector3i(12,10,12)); + grid.SetSpacing(Vector3f(1,1,1)); + grid.SetPosition(Vector3f(0,0,0)); + + + Vtk::vtkStructuredGrid v_grid(grid); + + + // voxraytracer // + VoxRaytracer rt(grid); + HPoint3f pt; + rt.GetEntryPoint(muon.LineIn(),pt); + std::cout << pt.transpose() << "\n"; + + Vtk::vtkVoxRaytracerRepresentation v_rt(rt); + v_rt.SetMuon(muon); + v_rt.SetRayColor(Vector4f(1,0,0,1)); + + // // renderer // + Vtk::Viewer viewer; + + // widget // + vtkBoxWidget *widget = v_grid.GetWidget(); + + + vtkWidgetCallback *cbk = vtkWidgetCallback::New(); + cbk->SetTracer(&v_rt); + cbk->SetMuon(&muon); + cbk->SetAnnotation(viewer.GetAnnotation()); + widget->AddObserver(vtkCommand::InteractionEvent, cbk); + widget->SetInteractor(viewer.GetInteractor()); + widget->PlaceWidget(); + widget->On(); + + viewer.AddPuppet(v_grid); + viewer.AddPuppet(v_rt); + viewer.AddPuppet(v_muon); + viewer.Start(); + + + END_TESTING; +} diff --git a/src/Vtk/uLibVtkInterface.cxx b/src/Vtk/uLibVtkInterface.cxx new file mode 100644 index 0000000..15a06a6 --- /dev/null +++ b/src/Vtk/uLibVtkInterface.cxx @@ -0,0 +1,238 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#if VTK_MAJOR_VERSION <= 5 +# +#else +# include +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "uLibVtkInterface.h" + + + + + + + +namespace uLib { +namespace Vtk { + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// POLYDATA // + + +void Polydata::SaveToFile(const char *vtk_file) +{ + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetFileName(vtk_file); + vtkPolyData * data = GetPolyData(); + if(data) { +# if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(data->GetProducerPort()); +# else + writer->SetInputData(data); +# endif + writer->Update(); + } +} + +void Polydata::SaveToXMLFile(const char *vtp_file) +{ + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetFileName(vtp_file); + vtkPolyData * data = GetPolyData(); + if(data) { +# if VTK_MAJOR_VERSION <= 5 + writer->SetInputConnection(data->GetProducerPort()); +# else + writer->SetInputData(data); +# endif + writer->Update(); + } +} + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// PUPPET // + +// PIMPL -------------------------------------------------------------------- // + +class PuppetData { +public: + PuppetData() : + m_Renderers(vtkRendererCollection::New()), + m_Assembly(vtkPropAssembly::New()) + {} + + ~PuppetData() { + m_Renderers->RemoveAllItems(); + m_Assembly->GetParts()->RemoveAllItems(); + m_Renderers->Delete(); + m_Assembly->Delete(); + } + + // members // + vtkRendererCollection *m_Renderers; + vtkPropAssembly *m_Assembly; +}; + +// -------------------------------------------------------------------------- // + + + + +Puppet::Puppet() : d(new PuppetData) { } + +Puppet::~Puppet() +{ + delete d; +} + +vtkProp *Puppet::GetProp() +{ + if (d->m_Assembly->GetParts()->GetNumberOfItems() == 1) + { + // d->m_Assembly->GetParts()->InitTraversal(); + // return d->m_Assembly->GetParts()->GetNextProp(); + return d->m_Assembly->GetParts()->GetLastProp(); + } + else return d->m_Assembly; +} + +void Puppet::SetProp(vtkProp *prop) +{ + if(prop) d->m_Assembly->AddPart(prop); +} + +void Puppet::RemoveProp(vtkProp *prop) +{ + // TODO +} + + +vtkPropCollection *Puppet::GetProps() +{ + return d->m_Assembly->GetParts(); +} + +void Puppet::ConnectRenderer(vtkRenderer *renderer) +{ + if(renderer) { + this->GetRenderers()->AddItem(renderer); + if(d->m_Assembly->GetParts()->GetNumberOfItems() == 1) + renderer->AddActor(this->GetProp()); + else if(d->m_Assembly->GetParts()->GetNumberOfItems() >0) + { + vtkPropCollection *props = d->m_Assembly->GetParts(); + props->InitTraversal(); + for (int i=0; iGetNumberOfItems(); ++i) + renderer->AddActor(props->GetNextProp()); + } + } +} + +void Puppet::DisconnectRenderer(vtkRenderer *renderer) +{ + if(renderer) { + if(this->GetProp()) + renderer->RemoveViewProp(this->GetProp()); + else if(d->m_Assembly->GetParts()->GetNumberOfItems() >0) + { + vtkPropCollection *props = d->m_Assembly->GetParts(); + props->InitTraversal(); + for (int i=0; iGetNumberOfItems(); ++i) + renderer->RemoveViewProp(props->GetNextProp()); + } + this->GetRenderers()->RemoveItem(renderer); + } +} + +void Puppet::ConnectViewer(Viewer *viewer) +{ + // TODO +} + +void Puppet::DisonnectViewer(Viewer *viewer) +{ + // TODO +} + +vtkRendererCollection *Puppet::GetRenderers() const +{ + return d->m_Renderers; +} + +void Puppet::PrintSelf(std::ostream &o) const +{ + o << "Props Assembly: \n"; + d->m_Assembly->PrintSelf(o,vtkIndent(1)); + + o << "Connected Renderers: \n"; + d->m_Renderers->PrintSelf(o,vtkIndent(1)); +} + + + + + + + + + + +} // Vtk +} // uLib diff --git a/src/Vtk/uLibVtkInterface.h b/src/Vtk/uLibVtkInterface.h new file mode 100644 index 0000000..1e2687a --- /dev/null +++ b/src/Vtk/uLibVtkInterface.h @@ -0,0 +1,124 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef ULIBVTKINTERFACE_H +#define ULIBVTKINTERFACE_H + + + +#include +#include + +#include +#include + + + +// vtk classes forward declaration // +class vtkProp; +class vtkPolyData; +class vtkPropCollection; +class vtkRenderer; +class vtkRendererCollection; + + +namespace uLib { +namespace Vtk { + + + +//template +//class Tie { + +//public: +// typedef T Content; + + +//}; + + + +class Puppet : public Object +{ + uLibTypeMacro(Puppet, Object) +public: + Puppet(); + ~Puppet(); + + virtual vtkProp * GetProp(); + + virtual vtkPropCollection * GetProps(); + + void ConnectRenderer(vtkRenderer *renderer); + + void DisconnectRenderer(vtkRenderer *renderer); + + void ConnectViewer(class Viewer *viewer); + + void DisonnectViewer(class Viewer *viewer); + + vtkRendererCollection * GetRenderers() const; + + + virtual void PrintSelf(std::ostream &o) const; + + virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor) { (void)interactor; } + +protected: + + void SetProp(vtkProp *prop); + + void RemoveProp(vtkProp *prop); + +private: + friend class PuppetData; + class PuppetData *d; +}; + + + + +class Polydata { +public: + + virtual vtkPolyData * GetPolyData() const { return NULL; } + + virtual void SaveToFile(const char *vtk_file); + + virtual void SaveToXMLFile(const char *vtp_file); + +protected: + virtual ~Polydata() {} +}; + + +} // vtk +} // uLib + + + +#endif // ULIBVTKINTERFACE_H diff --git a/src/Vtk/uLibVtkViewer.cpp b/src/Vtk/uLibVtkViewer.cpp new file mode 100644 index 0000000..0f50e5d --- /dev/null +++ b/src/Vtk/uLibVtkViewer.cpp @@ -0,0 +1,190 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "uLibVtkViewer.h" + +namespace uLib { +namespace Vtk { + +template <> +class Tie { +public: + void DoAction() { + std::cout << " VIEWER TIE !!! \n"; + } +}; + + +//// PIMPL ///////////////////////////////////////////////////////////////////// + +class ViewerPimpl { +public: + ViewerPimpl() : + m_RenderWindow(vtkRenderWindow::New()), + m_Renderer(vtkRenderer::New()), + m_Annotation(vtkCornerAnnotation::New()), + m_Marker(vtkOrientationMarkerWidget::New()) + { + this->InstallPipe(); + } + + ~ViewerPimpl() { + this->UninstallPipe(); + + m_Annotation->Delete(); + m_Marker->Delete(); + m_Renderer->Delete(); + m_RenderWindow->Delete(); + } + + // members // + vtkRenderer *m_Renderer; + vtkRenderWindow *m_RenderWindow; + vtkCornerAnnotation *m_Annotation; + vtkOrientationMarkerWidget *m_Marker; + +private: + void InstallPipe() + { + m_RenderWindow->AddRenderer(m_Renderer); + vtkSmartPointer renderWindowInteractor = + vtkSmartPointer::New(); + renderWindowInteractor->SetRenderWindow(m_RenderWindow); + + // annotation // + m_Annotation->GetTextProperty()->SetColor(1,1,1); + m_Annotation->GetTextProperty()->SetFontFamilyToArial(); + m_Annotation->GetTextProperty()->SetOpacity(0.5); + m_Annotation->SetMaximumFontSize(10); + m_Annotation->SetText(0,"uLib VTK Viewer - OpenCMT all right reserved."); + m_Renderer->AddViewProp(m_Annotation); + + // orientation marker // + vtkSmartPointer axes = + vtkSmartPointer::New(); + m_Marker->SetInteractor(renderWindowInteractor); + m_Marker->SetOrientationMarker(axes); + m_Marker->SetViewport(0.0,0.0,0.2,0.2); + m_Marker->SetEnabled(true); + m_Marker->InteractiveOff(); + + // Must be rendered here in Vtk-6.0 or seg-fault // + m_RenderWindow->Render(); + } + + void UninstallPipe() { + m_Renderer->RemoveAllViewProps(); + m_Renderer->Clear(); + } + +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +///// VTK VIEWER ////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +Viewer::Viewer() : d(new ViewerPimpl) {} + +Viewer::~Viewer() { delete d; } + + +void Viewer::addProp(vtkProp *prop) +{ + d->m_Renderer->AddActor(prop); + d->m_Renderer->Render(); +} + +void Viewer::RemoveProp(vtkProp *prop) +{ + d->m_Renderer->RemoveViewProp(prop); + d->m_Renderer->Render(); +} + +void Viewer::AddPuppet(Puppet &prop) +{ + prop.ConnectRenderer(d->m_Renderer); + d->m_Renderer->Render(); +} + +void Viewer::RemovePuppet(Puppet &prop) +{ + prop.DisconnectRenderer(d->m_Renderer); + d->m_Renderer->Render(); +} + +void Viewer::Start() +{ + d->m_RenderWindow->GetInteractor()->Start(); +} + +vtkCornerAnnotation *Viewer::GetAnnotation() +{ + return d->m_Annotation; +} + +vtkRenderer *Viewer::GetRenderer() +{ + return d->m_Renderer; +} + +vtkRenderWindowInteractor *Viewer::GetInteractor() +{ + return d->m_RenderWindow->GetInteractor(); +} + +void Viewer::Reset() +{ + d->m_Renderer->ResetCameraClippingRange(); + d->m_Renderer->ResetCamera(); + d->m_Renderer->Render(); +} + + +} // vtk +} // uLib + diff --git a/src/Vtk/uLibVtkViewer.h b/src/Vtk/uLibVtkViewer.h new file mode 100644 index 0000000..cc9e8a9 --- /dev/null +++ b/src/Vtk/uLibVtkViewer.h @@ -0,0 +1,90 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef ULIBVTKVIEWER_H +#define ULIBVTKVIEWER_H + +#include "uLibVtkInterface.h" + + +class vtkProp; +class vtk3DWidget; +class vtkCornerAnnotation; +class vtkRenderWindowInteractor; +class vtkRenderer; + +namespace uLib { +namespace Vtk { + + +template +class Tie { +public: + void DoAction() { + std::cout << "Tie::DoAction -> generic Tie does nothing\n"; + } +}; + + +class Viewer { + +public: + Viewer(); + ~Viewer(); + + + void AddPuppet(Puppet &prop); + + void RemovePuppet(Puppet &prop); + + void AddWidget(vtk3DWidget *widget); + + void Reset(); + + void Start(); + + vtkCornerAnnotation *GetAnnotation(); + + vtkRenderer * GetRenderer(); + + vtkRenderWindowInteractor * GetInteractor(); + + void addProp(vtkProp *prop); + + void RemoveProp(vtkProp *prop); + +private: + class ViewerPimpl *d; +}; + +template <> class Tie; + + +} // vtk +} // uLib + +#endif // ULIBVTKVIEWER_H diff --git a/src/Vtk/vtkContainerBox.cpp b/src/Vtk/vtkContainerBox.cpp new file mode 100644 index 0000000..43eb430 --- /dev/null +++ b/src/Vtk/vtkContainerBox.cpp @@ -0,0 +1,154 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vtkContainerBox.h" + +namespace uLib { +namespace Vtk { + + +// PIMPL -------------------------------------------------------------------- // + +class vtkContainerBoxPimpl { +public: + vtkContainerBoxPimpl() : + m_Cube(vtkActor::New()), + m_Axes(vtkActor::New()), + m_Pivot(vtkActor::New()), + m_Content(NULL) + {} + + ~vtkContainerBoxPimpl() + { + m_Cube->Delete(); + m_Axes->Delete(); + m_Pivot->Delete(); + } + + // MEMBERS // + vtkActor *m_Cube; + vtkActor *m_Axes; + vtkActor *m_Pivot; + vtkContainerBox::Content *m_Content; +}; + +// -------------------------------------------------------------------------- // + + + + +vtkContainerBox::vtkContainerBox(vtkContainerBox::Content &content) : + d( new vtkContainerBoxPimpl) +{ + d->m_Content = &content; + this->InstallPipe(); +} + +vtkContainerBox::~vtkContainerBox() +{ + delete d; +} + +vtkPolyData *vtkContainerBox::GetPolyData() const +{ + // TODO +} + +void vtkContainerBox::InstallPipe() +{ + if(!d->m_Content) return; + Content *c = d->m_Content; + + // CUBE + vtkSmartPointer cube = vtkSmartPointer::New(); + Vector3f p = c->GetPosition(); + cube->SetCenter(p(0),p(1),p(2)); + Vector4f p1 = c->GetWorldPoint(HPoint3f(0,0,0)); + Vector4f p2 = c->GetWorldPoint(HPoint3f(1,1,1)); + vtkSmartPointer line = vtkSmartPointer::New(); + line->SetPoint1(p1(0),p1(1),p1(2)); + line->SetPoint2(p2(0),p2(1),p2(2)); + line->Update(); + cube->SetBounds(line->GetOutput()->GetBounds()); + vtkSmartPointer mapper = + vtkSmartPointer::New(); + mapper->SetInputConnection(cube->GetOutputPort()); + mapper->Update(); + d->m_Cube->SetMapper(mapper); + d->m_Cube->GetProperty()->SetRepresentationToWireframe(); + d->m_Cube->GetProperty()->SetAmbient(0.7); + + // AXES // + vtkSmartPointer axes = vtkSmartPointer::New(); + axes->SetOrigin(p1(0),p1(1),p1(2)); + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(axes->GetOutputPort()); + mapper->Update(); + d->m_Axes->SetMapper(mapper); + Vector3f s = c->GetSize(); + // d->m_Axes->SetScale(s(0),s(1),s(2)); + d->m_Axes->GetProperty()->SetLineWidth(3); + d->m_Axes->GetProperty()->SetAmbient(0.4); + d->m_Axes->GetProperty()->SetSpecular(0); + + // PIVOT // + axes = vtkSmartPointer::New(); + axes->SetOrigin(p(0),p(1),p(2)); + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(axes->GetOutputPort()); + mapper->Update(); + d->m_Pivot->SetMapper(mapper); + s = c->GetScale(); + // d->m_Pivot->SetScale(s(0),s(1),s(2)); + d->m_Pivot->GetProperty()->SetLineWidth(3); + d->m_Pivot->GetProperty()->SetAmbient(0.4); + d->m_Pivot->GetProperty()->SetSpecular(0); + + this->SetProp(d->m_Cube); + this->SetProp(d->m_Axes); + this->SetProp(d->m_Pivot); +} + + + +} // vtk +} // uLib diff --git a/src/Vtk/vtkContainerBox.h b/src/Vtk/vtkContainerBox.h new file mode 100644 index 0000000..1cebf48 --- /dev/null +++ b/src/Vtk/vtkContainerBox.h @@ -0,0 +1,57 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_VTKCONTAINERBOX_H +#define U_VTKCONTAINERBOX_H + + +#include "uLibVtkInterface.h" +#include "Math/ContainerBox.h" + + +namespace uLib { +namespace Vtk { + +class vtkContainerBox : public Puppet, public Polydata { + typedef ContainerBox Content; +public: + vtkContainerBox(Content &content); + ~vtkContainerBox(); + + virtual class vtkPolyData *GetPolyData() const; + +private: + void InstallPipe(); + + friend class vtkContainerBoxPimpl; + class vtkContainerBoxPimpl *d; +}; + +} // vtk +} // uLib + +#endif // VTKCONTAINERBOX_H diff --git a/src/Vtk/vtkHLineRepresentation.h b/src/Vtk/vtkHLineRepresentation.h new file mode 100644 index 0000000..c69ea14 --- /dev/null +++ b/src/Vtk/vtkHLineRepresentation.h @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKHLINEREPRESENTATION_H +#define VTKHLINEREPRESENTATION_H + + + +class vtkProp; +class vtkPolyData; + + +namespace uLib { + +class vtkHLineRepresentationDefault { + +public: + vtkHLineRepresentationDefault(); + + +}; + + +} + + + +#endif // VTKHLINEREPRESENTATION_H diff --git a/src/Vtk/vtkMuonContainerScattering.cpp b/src/Vtk/vtkMuonContainerScattering.cpp new file mode 100644 index 0000000..b49a65e --- /dev/null +++ b/src/Vtk/vtkMuonContainerScattering.cpp @@ -0,0 +1,35 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + + +// TO BE CONTINUED // diff --git a/src/Vtk/vtkMuonContainerScattering.h b/src/Vtk/vtkMuonContainerScattering.h new file mode 100644 index 0000000..b1ef9be --- /dev/null +++ b/src/Vtk/vtkMuonContainerScattering.h @@ -0,0 +1,77 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKMUONCONTAINERSCATTERING_H +#define VTKMUONCONTAINERSCATTERING_H + + + +#include "Core/Macros.h" +#include "Math/Dense.h" + +#include "uLibVtkInterface.h" +#include "Detectors/MuonScatter.h" + +class vtkRenderWindowInteractor; + +namespace uLib { + +class vtkMuonContainerScattering : public Abstract::uLibVtkPolydata { + typedef MuonScatter Content; +public: + vtkMuonContainerScattering(const MuonScatter &content); + ~vtkMuonScatter(); + + Content& GetContent(); + + void PrintSelf(std::ostream &o) const; + + virtual vtkProp *GetProp(); + + virtual vtkPolyData* GetPolyData() const; + + void AddPocaPoint(HPoint3f poca); + + HPoint3f GetPocaPoint(); + + void vtkStartInteractive(); + +protected: + void ConnectInteractor(vtkRenderWindowInteractor *interactor); + +private: + void InstallPipe(); + + friend class vtkMuonContainerScatteringPimpl; + class vtkMuonContainerScatteringPimpl *d; +}; + + +} + + +#endif // VTKMUONCONTAINERSCATTERING_H diff --git a/src/Vtk/vtkMuonEvent.cxx b/src/Vtk/vtkMuonEvent.cxx new file mode 100644 index 0000000..db34b24 --- /dev/null +++ b/src/Vtk/vtkMuonEvent.cxx @@ -0,0 +1,214 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include "vtkMuonEvent.h" +#include "Math/Dense.h" + +namespace uLib { + +///// CALLBACK ///////////////////////////////////////////////////////////////// + +class vtkWidgetCallback : public vtkCommand +{ +public: + static vtkWidgetCallback *New() + { return new vtkWidgetCallback; } + void SetParent(uLib::vtkMuonEvent *parent) { this->parent = parent; } + virtual void Execute(vtkObject *caller, unsigned long, void*) + { + vtkSmartPointer t = + vtkSmartPointer::New(); + vtkBoxWidget *widget = reinterpret_cast(caller); + widget->GetTransform(t); + //parent->SetTransform(t); + //std::cout << "event\n"; + } +private: + uLib::vtkMuonEvent *parent; +}; + + +//// PIMPL ///////////////////////////////////////////////////////////////////// + +class vtkMuonEventPimpl { + typedef vtkWidgetCallback Callback; +public: + vtkMuonEventPimpl() : + m_Prop(vtkActor::New()), + m_PolyData(NULL), + m_Appender(vtkAppendPolyData::New()), + content(NULL) + {} + + ~vtkMuonEventPimpl() + { + m_Prop->Delete(); + } + + // members // + vtkMuonEvent::Content *content; + vtkPolyData *m_PolyData; + vtkActor *m_Prop; + + vtkAppendPolyData *m_Appender; + vtkBoxWidget *m_WidgetIN, *m_WidgetOUT; + HPoint3f m_Poca; +}; + + + + + + +//////////////////////////////////////////////////////////////////////////////// +///// VTK MUON EVENT ///////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +vtkMuonEvent::vtkMuonEvent(MuonEventData &content) : + d(new vtkMuonEventPimpl) +{ + d->content = &content; + InstallPipe(); +} + +vtkMuonEvent::vtkMuonEvent(const MuonEventData &content) : + d(new vtkMuonEventPimpl) +{ + d->content = const_cast(&content); + InstallPipe(); +} + + +vtkMuonEvent::~vtkMuonEvent() +{ + if (d->m_Prop) d->m_Prop->Delete(); +} + +vtkMuonEvent::Content &vtkMuonEvent::GetContent() +{ + return *d->content; +} + +void vtkMuonEvent::PrintSelf(std::ostream &o) const +{ + o << "..:: MuonEvent ::..\n" \ + "\t[in] Origin > " << d->content->LineIn().origin.transpose() << "\n" << + "\t[in] Direction > " << d->content->LineIn().direction.transpose() << "\n" << + "\t[out] Origin > " << d->content->LineOut().origin.transpose() << "\n" << + "\t[out] Direction > " << d->content->LineOut().direction.transpose()<< "\n" << + "\tMomentum > " << d->content->GetMomentum() << "\n" << + "...................\n"; +} + +vtkProp *vtkMuonEvent::GetProp() +{ + return d->m_Prop; +} + +void vtkMuonEvent::InstallPipe() +{ + + + vtkAppendPolyData *appender = d->m_Appender; + vtkSmartPointer mapper = vtkSmartPointer::New(); + + if(d->content) { + vtkSmartPointer line_in = vtkSmartPointer::New(); + vtkSmartPointer line_out = vtkSmartPointer::New(); + + float distance = (d->content->LineIn().origin - d->content->LineOut().origin).norm() / 10; + + HPoint3f pt; + pt = d->content->LineIn().origin; + line_in->SetPoint1(pt(0),pt(1),pt(2)); + pt= d->content->LineIn().origin + d->content->LineIn().direction * distance; + line_in->SetPoint2(pt(0),pt(1),pt(2)); + pt = d->content->LineOut().origin; + line_out->SetPoint1(pt(0),pt(1),pt(2)); + pt = d->content->LineOut().origin + d->content->LineOut().direction * distance; + line_out->SetPoint2(pt(0),pt(1),pt(2)); + + appender->AddInputConnection(line_in->GetOutputPort()); + appender->AddInputConnection(line_out->GetOutputPort()); + } + + appender->Update(); + mapper->SetInputConnection(appender->GetOutputPort()); + mapper->Update(); + d->m_Prop->SetMapper(mapper); +} + +vtkPolyData *vtkMuonEvent::GetPolyData() const +{ + return d->m_Appender->GetOutput(); +} + +void vtkMuonEvent::AddPocaPoint(HPoint3f poca) +{ + d->m_Poca = poca; + vtkSmartPointer sphere = + vtkSmartPointer::New(); + float size = (d->content->LineIn().origin - d->content->LineOut().origin).head(3).norm(); + size /= 100; + sphere->SetRadius(size); + sphere->SetCenter(poca(0),poca(1),poca(2)); + sphere->Update(); + d->m_Appender->AddInputConnection(sphere->GetOutputPort()); + d->m_Appender->Update(); +} + +HPoint3f vtkMuonEvent::GetPocaPoint() +{ + return d->m_Poca; +} + + + + + +} diff --git a/src/Vtk/vtkMuonEvent.h b/src/Vtk/vtkMuonEvent.h new file mode 100644 index 0000000..310fc08 --- /dev/null +++ b/src/Vtk/vtkMuonEvent.h @@ -0,0 +1,74 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKMUONEVENT_H +#define VTKMUONEVENT_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +#include "uLibVtkInterface.h" +#include "Detectors/MuonEvent.h" + + + + +namespace uLib { + +class vtkMuonEvent : public Abstract::uLibVtkPolydata { + typedef MuonEventData Content; +public: + vtkMuonEvent(const MuonEventData &content); + vtkMuonEvent(MuonEventData &content); + ~vtkMuonEvent(); + + Content& GetContent(); + + void PrintSelf(std::ostream &o) const; + + virtual vtkProp *GetProp(); + + virtual vtkPolyData* GetPolyData() const; + + void AddPocaPoint(HPoint3f poca); + + HPoint3f GetPocaPoint(); + + void vtkStartInteractive(); + + +private: + void InstallPipe(); + + friend class vtkMuonEventPimpl; + class vtkMuonEventPimpl *d; +}; + + +} + +#endif // VTKMUONSCATTER_H diff --git a/src/Vtk/vtkMuonScatter.cxx b/src/Vtk/vtkMuonScatter.cxx new file mode 100644 index 0000000..b3c11d7 --- /dev/null +++ b/src/Vtk/vtkMuonScatter.cxx @@ -0,0 +1,236 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include "vtkMuonScatter.h" +#include "Math/Dense.h" + +namespace uLib { +namespace Vtk { + +///// CALLBACK ///////////////////////////////////////////////////////////////// + +//namespace { + +//class vtkWidgetCallback : public vtkCommand +//{ +//public: +// static vtkWidgetCallback *New() +// { return new vtkWidgetCallback; } +// void SetParent(uLib::vtkMuonScatter *parent) { this->parent = parent; } +// virtual void Execute(vtkObject *caller, unsigned long, void*) +// { +// vtkSmartPointer t = +// vtkSmartPointer::New(); +// vtkBoxWidget *widget = reinterpret_cast(caller); +// widget->GetTransform(t); +// //parent->SetTransform(t); +// //std::cout << "Scatter\n"; +// } +//private: +// uLib::vtkMuonScatter *parent; +//}; + +//} + +//// PIMPL ///////////////////////////////////////////////////////////////////// + +class vtkMuonScatterPimpl { +public: + vtkMuonScatterPimpl() : + m_Content(NULL), + m_LineIn(vtkLineSource::New()), + m_LineOut(vtkLineSource::New()), + m_PolyData(vtkPolyData::New()), + m_SpherePoca(NULL) + {} + + ~vtkMuonScatterPimpl() + { + m_LineIn->Delete(); + m_LineOut->Delete(); + if(m_SpherePoca) m_SpherePoca->Delete(); + } + + // members // + vtkMuonScatter::Content *m_Content; + vtkLineSource *m_LineIn, *m_LineOut; + vtkSphereSource *m_SpherePoca; + vtkPolyData *m_PolyData; +}; + + + + + + +//////////////////////////////////////////////////////////////////////////////// +///// VTK MUON Scatter ///////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +vtkMuonScatter::vtkMuonScatter(MuonScatter &content) : + d(new vtkMuonScatterPimpl) +{ + d->m_Content = &content; + InstallPipe(); +} + +vtkMuonScatter::vtkMuonScatter(const MuonScatter &content) : + d(new vtkMuonScatterPimpl) +{ + d->m_Content = const_cast(&content); + InstallPipe(); +} + + +vtkMuonScatter::~vtkMuonScatter() +{ + delete d; +} + +vtkMuonScatter::Content &vtkMuonScatter::GetContent() +{ + return *d->m_Content; +} + +void vtkMuonScatter::PrintSelf(std::ostream &o) const +{ + // o << d->content; +} + + +void vtkMuonScatter::InstallPipe() +{ + if(d->m_Content) { + vtkLineSource *line_in = d->m_LineIn; + vtkLineSource *line_out = d->m_LineOut; + + float distance = (d->m_Content->LineIn().origin - d->m_Content->LineOut().origin).norm() / 10; + + HPoint3f pt; + pt = d->m_Content->LineIn().origin; + line_in->SetPoint1(pt(0),pt(1),pt(2)); + pt= d->m_Content->LineIn().origin + d->m_Content->LineIn().direction * distance; + line_in->SetPoint2(pt(0),pt(1),pt(2)); + pt = d->m_Content->LineOut().origin; + line_out->SetPoint1(pt(0),pt(1),pt(2)); + pt = d->m_Content->LineOut().origin + d->m_Content->LineOut().direction * distance; + line_out->SetPoint2(pt(0),pt(1),pt(2)); + } + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(d->m_LineIn->GetOutputPort()); + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + this->SetProp(actor); + + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(d->m_LineOut->GetOutputPort()); + actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + this->SetProp(actor); +} + +vtkPolyData *vtkMuonScatter::GetPolyData() const +{ + vtkSmartPointer append = vtkSmartPointer::New(); +//# if VTK_MAJOR_VERSION <= 5 + append->AddInputConnection(d->m_LineIn->GetOutputPort()); + append->AddInputConnection(d->m_LineOut->GetOutputPort()); + if(d->m_SpherePoca) append->AddInputConnection(d->m_SpherePoca->GetOutputPort()); +//# else +// append->AddInputData(d->m_LineIn->GetOutput()); +// append->AddInputData(d->m_LineOut->GetOutput()); +// if(d->m_SpherePoca) append->AddInputData(d->m_SpherePoca->GetOutput()); +//# endif + append->Update(); + d->m_PolyData->DeepCopy(append->GetOutput()); + return d->m_PolyData; +} + +void vtkMuonScatter::AddPocaPoint(HPoint3f poca) +{ + vtkSphereSource *sphere = vtkSphereSource::New(); + float size = (d->m_Content->LineIn().origin - d->m_Content->LineOut().origin).head(3).norm(); + size /= 100; + sphere->SetRadius(size); + sphere->SetCenter(poca(0),poca(1),poca(2)); + sphere->Update(); + d->m_SpherePoca = sphere; + + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(d->m_SpherePoca->GetOutputPort()); + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + this->SetProp(actor); +} + +HPoint3f vtkMuonScatter::GetPocaPoint() +{ + double center[3]; + if(d->m_SpherePoca) { + d->m_SpherePoca->GetCenter(center); + return HPoint3f(center[0],center[1],center[2]); + } + else { + return HPoint3f(0,0,0); + } +} + + +void vtkMuonScatter::ConnectInteractor(vtkRenderWindowInteractor *interactor) +{ + // TODO +} + + + + +} // vtk +} // uLib diff --git a/src/Vtk/vtkMuonScatter.h b/src/Vtk/vtkMuonScatter.h new file mode 100644 index 0000000..7237f98 --- /dev/null +++ b/src/Vtk/vtkMuonScatter.h @@ -0,0 +1,76 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKMUONSCATTER_H +#define VTKMUONSCATTER_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +#include "uLibVtkInterface.h" +#include "Detectors/MuonScatter.h" + +class vtkRenderWindowInteractor; + +namespace uLib { +namespace Vtk { + +class vtkMuonScatter : public Puppet, public Polydata { + typedef MuonScatter Content; +public: + + vtkMuonScatter(const MuonScatter &content); + vtkMuonScatter(MuonScatter &content); + + ~vtkMuonScatter(); + + Content &GetContent(); + + void PrintSelf(std::ostream &o) const; + + virtual vtkPolyData* GetPolyData() const; + + void AddPocaPoint(HPoint3f poca); + + HPoint3f GetPocaPoint(); + + void vtkStartInteractive(); + +protected: + void ConnectInteractor(vtkRenderWindowInteractor *interactor); + +private: + void InstallPipe(); + + friend class vtkMuonScatterPimpl; + class vtkMuonScatterPimpl *d; +}; + +} // vtk +} // uLib + +#endif // VTKMUONSCATTER_H diff --git a/src/Vtk/vtkPolydata.h b/src/Vtk/vtkPolydata.h new file mode 100644 index 0000000..5aa5b27 --- /dev/null +++ b/src/Vtk/vtkPolydata.h @@ -0,0 +1,49 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKPOLYDATA_H +#define VTKPOLYDATA_H + +#include "uLibVtkInterface.h" + + +namespace uLib { + +class vtkPolyData : public Abstract::uLibVtkPolydata { + typedef ::vtkPolyData Content; +public: + + + +}; + + + +} + + +#endif // VTKPOLYDATA_H diff --git a/src/Vtk/vtkStructuredGrid.cpp b/src/Vtk/vtkStructuredGrid.cpp new file mode 100644 index 0000000..e2225ae --- /dev/null +++ b/src/Vtk/vtkStructuredGrid.cpp @@ -0,0 +1,195 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "Math/StructuredGrid.h" +#include "Vtk/vtkStructuredGrid.h" + +namespace uLib { +namespace Vtk { + +//////////////////////////////////////////////////////////////////////////////// +////// PIMPL ////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +class vtkStructuredGridPimpl { + + // ---- WIDGET CBK ------------------------------------------------------ // + class vtkWidgetCallback : public vtkCommand + { + public: + static vtkWidgetCallback *New() { return new vtkWidgetCallback; } + void SetParent(uLib::Vtk::vtkStructuredGrid *parent) { this->parent = parent; } + virtual void Execute(vtkObject *caller, unsigned long, void*) + { + vtkSmartPointer t = + vtkSmartPointer::New(); + vtkBoxWidget *widget = reinterpret_cast(caller); + widget->GetTransform(t); + parent->SetTransform(t); + //std::cout << "event\n"; + } + private: + uLib::Vtk::vtkStructuredGrid *parent; + }; + // ---------------------------------------------------------------------- // + +public: + vtkStructuredGridPimpl(vtkStructuredGrid *parent, StructuredGrid &content) : + p(parent), + m_Content(&content), + m_Actor(vtkActor::New()), + m_Widget(vtkBoxWidget::New()), + m_Transform(vtkTransform::New()) + { + vtkSmartPointer callback = + vtkSmartPointer::New(); + callback->SetParent(p); + m_Widget->AddObserver(vtkCommand::InteractionEvent, callback); + } + + ~vtkStructuredGridPimpl() + { + m_Actor->Delete(); + m_Widget->Delete(); + m_Transform->Delete(); + } + + // members // + vtkActor *m_Actor; + vtkBoxWidget *m_Widget; + StructuredGrid *m_Content; + vtkTransform *m_Transform; +private: + vtkStructuredGrid *p; +}; + + +//////////////////////////////////////////////////////////////////////////////// +////// VTK STRUCTURED GRID ///////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + + +vtkStructuredGrid::vtkStructuredGrid(Content &content) : + d(new vtkStructuredGridPimpl(this,content)) +{ + this->InstallPipe(); +} + +vtkStructuredGrid::~vtkStructuredGrid() +{ + delete d; +} + + +void vtkStructuredGrid::SetTransform(vtkTransform *t) +{ + vtkMatrix4x4 *vmat = t->GetMatrix(); + Matrix4f mat; + for(int i=0; i<4; ++i) + for(int j=0; j<4; ++j) + mat(i,j) = vmat->GetElement(i,j); + d->m_Content->SetMatrix(mat); + + vtkSmartPointer vmat2 = vtkSmartPointer::New(); + mat = d->m_Content->GetWorldMatrix(); + for(int i=0; i<4; ++i) + for(int j=0; j<4; ++j) + vmat2->SetElement(i,j,mat(i,j)); + d->m_Transform->SetMatrix(vmat2); + d->m_Transform->Update(); + this->Update(); +} + +vtkBoxWidget *vtkStructuredGrid::GetWidget() +{ + return d->m_Widget; +} + +void vtkStructuredGrid::Update() +{ + d->m_Actor->GetMapper()->Update(); +} + +void vtkStructuredGrid::InstallPipe() +{ + vtkSmartPointer cube = + vtkSmartPointer::New(); + vtkSmartPointer filter = + vtkSmartPointer::New(); + + vtkSmartPointer vmat = vtkSmartPointer::New(); + Matrix4f mat = d->m_Content->GetWorldMatrix(); + for(int i=0; i<4; ++i) + for(int j=0; j<4; ++j) + vmat->SetElement(i,j,mat(i,j)); + d->m_Transform->SetMatrix(vmat); + filter->SetTransform(d->m_Transform); + filter->SetInputConnection(cube->GetOutputPort()); + + Vector3i dims = d->m_Content->GetDims(); + cube->SetBounds(0,dims(0),0,dims(1),0,dims(2)); + cube->Update(); + filter->Update(); + + vtkSmartPointer mapper = + vtkSmartPointer::New(); + mapper->SetInputConnection(filter->GetOutputPort()); + + d->m_Actor->SetMapper(mapper); + d->m_Actor->GetProperty()->SetRepresentationToSurface(); + d->m_Actor->GetProperty()->SetEdgeVisibility(true); + d->m_Actor->GetProperty()->SetOpacity(0.4); + d->m_Actor->GetProperty()->SetAmbient(0.7); + // set content transform to actor // + this->Update(); + d->m_Widget->SetProp3D(d->m_Actor); + + this->SetProp(d->m_Actor); +} + + +} // vtk +} // uLib diff --git a/src/Vtk/vtkStructuredGrid.h b/src/Vtk/vtkStructuredGrid.h new file mode 100644 index 0000000..93a8df3 --- /dev/null +++ b/src/Vtk/vtkStructuredGrid.h @@ -0,0 +1,67 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_VTKSTRUCTUREDGRID_H +#define U_VTKSTRUCTUREDGRID_H + +#include "Core/Macros.h" +#include "Math/Dense.h" + +#include "uLibVtkInterface.h" +#include "Math/StructuredGrid.h" + + +namespace uLib { +namespace Vtk { + +class vtkStructuredGrid : public Puppet { + typedef StructuredGrid Content; +public: + + vtkStructuredGrid(Content &content); + ~vtkStructuredGrid(); + + void SetTransform(class vtkTransform *t); + + class vtkBoxWidget * GetWidget(); + + void Update(); + + +private: + void InstallPipe(); + + friend class vtkStructuredGridPimpl; + class vtkStructuredGridPimpl *d; +}; + + +} // vtk +} // uLib + + +#endif // VTKSTRUCTUREDGRID_H diff --git a/src/Vtk/vtkTriangleMesh.cpp b/src/Vtk/vtkTriangleMesh.cpp new file mode 100644 index 0000000..4144270 --- /dev/null +++ b/src/Vtk/vtkTriangleMesh.cpp @@ -0,0 +1,227 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "Vtk/vtkTriangleMesh.h" + + +namespace uLib { + + +class vtkTriangleMeshPimpl { +public: + vtkTriangleMeshPimpl(vtkTriangleMesh::Content &content) : + m_content(content), + m_Poly(vtkPolyData::New()), + m_Actor(vtkActor::New()) + { + vtkSmartPointer mapper = + vtkSmartPointer::New(); + mapper->SetInputConnection(m_Poly->GetProducerPort()); + m_Actor->SetMapper(mapper); + } + + ~vtkTriangleMeshPimpl() { + m_Poly->Delete(); + m_Actor->Delete(); + } + + + void vtk2uLib_update(); + void uLib2vtk_update(); + + // members // + TriangleMesh &m_content; + vtkPolyData *m_Poly; + vtkActor *m_Actor; +}; + + +void vtkTriangleMeshPimpl::vtk2uLib_update() +{ + // Assumes that Polys are Triangles !!! // + vtkIdType number_of_points = m_Poly->GetNumberOfPoints(); + vtkIdType number_of_triangles = m_Poly->GetNumberOfPolys(); + + std::cout << "//////\n" << + "number of points = " << number_of_points << "\n" << + "muiber of polys = " << number_of_triangles << "\n" << + "//////\n"; + + + + + + m_content.Points().resize(number_of_points); + for (int i=0; iGetPoint(i); + m_content.Points()[i](0) = point[0]; + m_content.Points()[i](1) = point[1]; + m_content.Points()[i](2) = point[2]; +// std::cout << "pt" << i << " = " << m_content.Points()[i].transpose() << "\n"; + } + + m_content.Triangles().resize(number_of_triangles); + m_Poly->GetPolys()->InitTraversal(); + vtkSmartPointer idList = vtkSmartPointer::New(); + for (int i=0; iGetPolys()->GetNextCell(idList); + m_content.Triangles()[i](0) = idList->GetId(0); + m_content.Triangles()[i](1) = idList->GetId(1); + m_content.Triangles()[i](2) = idList->GetId(2); + } + m_Poly->Update(); + m_Actor->GetMapper()->Update(); +} + +void vtkTriangleMeshPimpl::uLib2vtk_update() +{ + vtkIdType number_of_points = m_content.Points().size(); + vtkIdType number_of_triangles = m_content.Triangles().size(); + + vtkSmartPointer points + = vtkSmartPointer::New(); + points->SetNumberOfPoints(number_of_points); + for (vtkIdType i = 0; i < number_of_points; i++) + { + double x, y, z; + x = m_content.Points().at(i)(0); + y = m_content.Points().at(i)(1); + z = m_content.Points().at(i)(2); + points->SetPoint(i, x, y, z); + } + + vtkSmartPointer polys + = vtkSmartPointer::New(); + for (vtkIdType i = 0; i < number_of_triangles; i++) + { + vtkIdType a, b, c; + a = m_content.Triangles().at(i)(0); + b = m_content.Triangles().at(i)(1); + c = m_content.Triangles().at(i)(2); + polys->InsertNextCell(3); + polys->InsertCellPoint(a); + polys->InsertCellPoint(b); + polys->InsertCellPoint(c); + } + + m_Poly->SetPoints(points); + m_Poly->SetPolys(polys); + m_Poly->Update(); + m_Actor->GetMapper()->Update(); +} + + +// -------------------------------------------------------------------------- // + + + + + +vtkTriangleMesh::vtkTriangleMesh(vtkTriangleMesh::Content &content) : + d(new vtkTriangleMeshPimpl(content)) +{} + +vtkTriangleMesh::~vtkTriangleMesh() +{ + delete d; +} + +void vtkTriangleMesh::ReadFromFile(const char *filename) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename); + reader->Update(); + d->m_Poly->DeepCopy(reader->GetOutput()); + d->vtk2uLib_update(); +} + +void vtkTriangleMesh::ReadFromXMLFile(const char *filename) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename); + reader->Update(); + d->m_Poly->DeepCopy(reader->GetOutput()); + d->vtk2uLib_update(); +} + +void vtkTriangleMesh::ReadFromObjFile(const char *filename) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename); + reader->Update(); + d->m_Poly->DeepCopy(reader->GetOutput()); + d->vtk2uLib_update(); +} + +void vtkTriangleMesh::ReadFromStlFile(const char *filename) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename); + reader->Update(); + d->m_Poly->DeepCopy(reader->GetOutput()); + d->vtk2uLib_update(); +} + +vtkProp *vtkTriangleMesh::GetProp() +{ + return d->m_Actor; +} + +vtkPolyData *vtkTriangleMesh::GetPolyData() const +{ + return d->m_Poly; +} + +void vtkTriangleMesh::Update() +{ + d->uLib2vtk_update(); +} + +} diff --git a/src/Vtk/vtkTriangleMesh.h b/src/Vtk/vtkTriangleMesh.h new file mode 100644 index 0000000..d0a1038 --- /dev/null +++ b/src/Vtk/vtkTriangleMesh.h @@ -0,0 +1,69 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef VTKTRIANGLEMESH_H +#define VTKTRIANGLEMESH_H + + +#include "uLibVtkInterface.h" +#include "Math/TriangleMesh.h" + +class vtkPolyData; + +namespace uLib { + + +class vtkTriangleMesh : public Abstract::uLibVtkPolydata { + typedef TriangleMesh Content; +public: + vtkTriangleMesh(Content &content); + ~vtkTriangleMesh(); + + void ReadFromFile(const char *filename); + + void ReadFromXMLFile(const char *filename); + + void ReadFromObjFile(const char *filename); + + void ReadFromStlFile(const char *filename); + + virtual class vtkProp *GetProp(); + + virtual class vtkPolyData *GetPolyData() const; + + void Update(); + +private: + friend class vtkTriangleMeshPimpl; + class vtkTriangleMeshPimpl *d; +}; + + + +} + +#endif // VTKTRIANGLEMESH_H diff --git a/src/Vtk/vtkVoxImage.cpp b/src/Vtk/vtkVoxImage.cpp new file mode 100644 index 0000000..806ec68 --- /dev/null +++ b/src/Vtk/vtkVoxImage.cpp @@ -0,0 +1,383 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + + +#include + +#include "vtkVoxImage.h" + + +namespace uLib { +namespace Vtk { + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// PIMPL + +class vtkVoxImagePimpl { +public: + vtkVoxImagePimpl(vtkVoxImage::Content &content) : + m_Content(content), + m_Actor(vtkVolume::New()), + m_Image(vtkImageData::New()), + m_Outline(vtkCubeSource::New()), + m_Reader(NULL), + m_Writer(NULL) + {} + + ~vtkVoxImagePimpl() + { + m_Image->Delete(); + m_Actor->Delete(); + m_Outline->Delete(); + } + + void GetContent(); + + void SetContent(); + + // members // + vtkVolume *m_Actor; + vtkImageData *m_Image; + vtkCubeSource *m_Outline; + + // io // + vtkXMLImageDataReader *m_Reader; + vtkXMLImageDataWriter *m_Writer; + + // content // + vtkVoxImage::Content &m_Content; + + // visual // + float m_Window; + float m_Level; +}; + + + +void vtkVoxImagePimpl::GetContent() +{ + // ULIB -> VTK // + const int *dims = static_cast(m_Content.GetDims().data()); + m_Image->SetDimensions(dims); + + float *spacing = m_Content.GetSpacing().data(); + m_Image->SetSpacing(spacing[0],spacing[1],spacing[2]); + + // Warning .. TODO: Read complete Transform matrix // + float *pos = m_Content.GetPosition().data(); + m_Image->SetOrigin(pos[0],pos[1],pos[2]); + + vtkFloatArray *array = vtkFloatArray::SafeDownCast + (m_Image->GetPointData()->GetScalars()); + array->SetNumberOfTuples(m_Content.GetDims().prod()); + Vector3i index(0,0,0); + int i=0; + for (int zv = 0; zv < dims[2]; ++zv) { + for (int yv = 0; yv < dims[1]; ++yv) { + for (int xv = 0; xv < dims[0]; ++xv) { + index << xv,yv,zv; + array->SetValue(i++,m_Content.GetValue(index)); + } + } + } + m_Image->GetPointData()->SetScalars(array); + // m_Image->Update(); +} + +void vtkVoxImagePimpl::SetContent() +{ + // VTK -> ULIB // + int *ext = m_Image->GetExtent(); + int dims[3] = { ext[1]-ext[0] + 1, ext[3]-ext[2] + 1, ext[5]-ext[4] + 1 }; + m_Content.SetDims(Vector3i(dims[0],dims[1],dims[2])); + + double *spacing = m_Image->GetSpacing(); + m_Content.SetSpacing(Vector3f(spacing[0],spacing[1],spacing[2])); + + // Warning .. TODO: Read complete Transform matrix // + double *pos = m_Image->GetOrigin(); + m_Content.SetPosition(Vector3f(pos[0],pos[1],pos[2])); + + vtkFloatArray *array = vtkFloatArray::SafeDownCast + (m_Image->GetPointData()->GetScalars()); + if(array) { + Vector3i index(0,0,0); + int i=0; + for (int zv = 0; zv < dims[2]; ++zv) { + for (int yv = 0; yv < dims[1]; ++yv) { + for (int xv = 0; xv < dims[0]; ++xv) { + index << xv,yv,zv; + m_Content.SetValue(index,array->GetValue(i++)); + } + } + } + } + else { + std::cerr << "Error reading array Value Data\n"; + } +} + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// VTK VOXIMAGE + +vtkVoxImage::vtkVoxImage(Content &content) : + d(new vtkVoxImagePimpl(content)) +{ + init_properties(); + d->GetContent(); + InstallPipe(); +} + +vtkVoxImage::~vtkVoxImage() +{ + delete d; +} + +vtkImageData *vtkVoxImage::GetImageData() +{ + d->GetContent(); + return d->m_Image; +} + +void vtkVoxImage::SaveToXMLFile(const char *fname) +{ + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetFileName(fname); + d->GetContent(); + vtkSmartPointer vtkscale = + vtkSmartPointer::New(); + +# if VTK_MAJOR_VERSION <= 5 + vtkscale->SetInputConnection(d->m_Image->GetProducerPort()); +# else + vtkscale->SetInputData(d->m_Image); +# endif + vtkscale->SetScale(p().writer_factor); + vtkscale->Update(); + writer->SetInputConnection(vtkscale->GetOutputPort()); + writer->Update(); + writer->Write(); +} + +void vtkVoxImage::ReadFromVKTFile(const char *fname) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(fname); + reader->Update(); + if(reader->IsFileStructuredPoints()) + { + vtkSmartPointer vtkscale = + vtkSmartPointer::New(); + vtkscale->SetInputConnection(reader->GetOutputPort()); + vtkscale->SetScale(1/p().writer_factor); + vtkscale->Update(); + + d->m_Image->DeepCopy(vtkscale->GetOutput()); // FIX! (pipe connection) + d->SetContent(); + } + else { + std::cerr << "Error: file does not contain structured points\n"; + } + d->m_Actor->Update(); +} + +void vtkVoxImage::ReadFromXMLFile(const char *fname) +{ + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(fname); + reader->Update(); + vtkSmartPointer vtkscale = + vtkSmartPointer::New(); + vtkscale->SetInputConnection(reader->GetOutputPort()); + vtkscale->SetScale(1/p().writer_factor); + vtkscale->Update(); + + d->m_Image->DeepCopy(vtkscale->GetOutput()); + d->SetContent(); +} + + +void vtkVoxImage::setShadingPreset(int blendType) +{ + vtkSmartVolumeMapper *mapper = + (vtkSmartVolumeMapper *)d->m_Actor->GetMapper(); + vtkVolumeProperty *property = d->m_Actor->GetProperty(); + + static vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New(); + static vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New(); + + float window = 40 / $$.writer_factor; + float level = 20 / $$.writer_factor; + + property->SetColor(colorFun); + property->SetScalarOpacity(opacityFun); + property->SetInterpolationTypeToLinear(); + + if(blendType != 6) { + colorFun->RemoveAllPoints(); + opacityFun->RemoveAllPoints(); + } + + switch (blendType) { + // MIP + // Create an opacity ramp from the window and level values. + // Color is white. Blending is MIP. + case 0: + colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0); + opacityFun->AddSegment(level - 0.5 * window, 0.0, + level + 0.5 * window, 1.0); + mapper->SetBlendModeToMaximumIntensity(); + break; + + // CompositeRamp + // Create a ramp from the window and level values. Use compositing + // without shading. Color is a ramp from black to white. + case 1: + colorFun->AddRGBSegment(level - 0.5 * window, 0.0, 0.0, 0.0, + level + 0.5 * window, 1.0, 1.0, 1.0); + opacityFun->AddSegment(level - 0.5 * window, 0.0, + level + 0.5 * window, 1.0); + mapper->SetBlendModeToComposite(); + property->ShadeOff(); + break; + + // CompositeShadeRamp + // Create a ramp from the window and level values. Use compositing + // with shading. Color is white. + case 2: + colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0); + opacityFun->AddSegment(level - 0.5 * window, 0.0, + level + 0.5 * window, 1.0); + mapper->SetBlendModeToComposite(); + property->ShadeOn(); + break; + + // CT_Skin + // Use compositing and functions set to highlight skin in CT data + // Not for use on RGB data + case 3: + colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0); + colorFun->AddRGBPoint(-1000, .62, .36, .18, 0.5, 0.0); + colorFun->AddRGBPoint(-500, .88, .60, .29, 0.33, 0.45); + colorFun->AddRGBPoint(3071, .83, .66, 1, 0.5, 0.0); + + opacityFun->AddPoint(-3024, 0, 0.5, 0.0); + opacityFun->AddPoint(-1000, 0, 0.5, 0.0); + opacityFun->AddPoint(-500, 1.0, 0.33, 0.45); + opacityFun->AddPoint(3071, 1.0, 0.5, 0.0); + + mapper->SetBlendModeToComposite(); + property->ShadeOn(); + property->SetAmbient(0.1); + property->SetDiffuse(0.9); + property->SetSpecular(0.2); + property->SetSpecularPower(10.0); + property->SetScalarOpacityUnitDistance(0.8919); + break; + + + default: + vtkGenericWarningMacro("Unknown blend type."); + break; + } +} + +void vtkVoxImage::Update() { + d->m_Actor->Update(); + d->m_Outline->SetBounds(d->m_Image->GetBounds()); + d->m_Outline->Update(); +} + +void vtkVoxImage::InstallPipe() +{ + vtkSmartPointer mapper = + vtkSmartPointer::New(); +# if VTK_MAJOR_VERSION <= 5 + mapper->SetInputConnection(d->m_Image->GetProducerPort()); +# else + mapper->SetInputData(d->m_Image); +# endif + mapper->Update(); + + d->m_Actor->SetMapper(mapper); + this->setShadingPreset(0); + mapper->Update(); + + d->m_Outline->SetBounds(d->m_Image->GetBounds()); + vtkSmartPointer mmapper = vtkSmartPointer::New(); + mmapper->SetInputConnection(d->m_Outline->GetOutputPort()); + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mmapper); + actor->GetProperty()->SetRepresentationToWireframe(); + actor->GetProperty()->SetAmbient(0.7); + + // this->SetProp(actor); + this->SetProp(d->m_Actor); +} + + +} // vtk +} // uLib diff --git a/src/Vtk/vtkVoxImage.h b/src/Vtk/vtkVoxImage.h new file mode 100644 index 0000000..6497f0a --- /dev/null +++ b/src/Vtk/vtkVoxImage.h @@ -0,0 +1,88 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_VTKVOXIMAGE_H +#define U_VTKVOXIMAGE_H + +#include +#include + +#include "uLibVtkInterface.h" + + +class vtkImageData; + +namespace uLib { +namespace Vtk { + +class vtkVoxImage : public Puppet { + uLibTypeMacro(vtkVoxImage,Puppet) +public: + properties() + { + float writer_factor; + }; + +public: + typedef Abstract::VoxImage Content; + + vtkVoxImage(Content &content); + + ~vtkVoxImage(); + + vtkImageData * GetImageData(); + + void SaveToXMLFile(const char *fname); + + void ReadFromVKTFile(const char *fname); + + void ReadFromXMLFile(const char *fname); + + void setShadingPreset(int blendType = 2); + + void Update(); + +protected: + void InstallPipe(); + +private: + class vtkVoxImagePimpl *d; +}; + + +inline void vtkVoxImage::init_properties() +{ + $_init(); + $$.writer_factor = 1.E6; +} + + +} // vtk +} // uLib + + +#endif // VTKVOXIMAGE_H diff --git a/src/Vtk/vtkVoxRaytracerRepresentation.cpp b/src/Vtk/vtkVoxRaytracerRepresentation.cpp new file mode 100644 index 0000000..f0e9852 --- /dev/null +++ b/src/Vtk/vtkVoxRaytracerRepresentation.cpp @@ -0,0 +1,459 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#include "vtkVoxRaytracerRepresentation.h" + +#include "Math/VoxRaytracer.h" + +//#include "vtkMuonEvent.h" +#include "vtkMuonScatter.h" + + +namespace uLib { +namespace Vtk { + +///// PIMPL //////////////////////////////////////////////////////////////////// + +class vtkVoxRaytracerRepresentationPimpl { + +public: + vtkVoxRaytracerRepresentationPimpl(VoxRaytracer &content) : + m_Content(&content), + m_Assembly(vtkAssembly::New()), + m_Sphere1(vtkSphereSource::New()), + m_Sphere2(vtkSphereSource::New()), + m_Line1(vtkLineSource::New()), + m_Line2(vtkLineSource::New()), + m_Line3(vtkLineSource::New()), + m_RayLine(vtkAppendPolyData::New()), + m_RayLineActor(vtkActor::New()), + m_RayRepresentation(vtkAppendPolyData::New()), + m_RayRepresentationActor(vtkActor::New()), + m_Transform(vtkTransform::New()) + { + default_radius = content.GetImage()->GetSpacing()(0)/4; + m_Sphere1->SetRadius(default_radius); + m_Sphere2->SetRadius(default_radius); + m_SelectedElement = m_RayLine; + } + ~vtkVoxRaytracerRepresentationPimpl() + { + m_Assembly->Delete(); + m_RayLine->Delete(); + m_RayLineActor->Delete(); + m_RayRepresentationActor->Delete(); + m_Transform->Delete(); + } + + // members // + VoxRaytracer *m_Content; + + Scalarf default_radius; + vtkAssembly *m_Assembly; + vtkAppendPolyData *m_RayLine; + vtkActor *m_RayLineActor; + vtkActor *m_RayRepresentationActor; + vtkSmartPointer m_Transform; + VoxRaytracer::RayData m_Ray; + vtkSmartPointer m_Sphere1,m_Sphere2; + vtkSmartPointer m_Line1, m_Line2, m_Line3; + vtkSmartPointer m_RayRepresentation; + + vtkAppendPolyData *m_SelectedElement; +}; + + + + +//////////////////////////////////////////////////////////////////////////////// +////// VOX RAYTRACER REPRESENTATION /////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + + +vtkVoxRaytracerRepresentation::vtkVoxRaytracerRepresentation(Content &content) : + d(new vtkVoxRaytracerRepresentationPimpl(content)) +{ + InstallPipe(); +} + +vtkVoxRaytracerRepresentation::~vtkVoxRaytracerRepresentation() +{ + delete d; +} + +VoxRaytracer *vtkVoxRaytracerRepresentation::GetRaytracerAlgorithm() +{ + return d->m_Content; +} + +vtkProp *vtkVoxRaytracerRepresentation::GetProp() +{ + return d->m_Assembly; +} + +vtkPolyData *vtkVoxRaytracerRepresentation::GetPolyData() const +{ + std::cout << "get Raytracer polydata\n"; + d->m_SelectedElement->Update(); + return d->m_SelectedElement->GetOutput(); +} + +void vtkVoxRaytracerRepresentation::SetRepresentationElements(vtkVoxRaytracerRepresentation::RepresentationElements el) +{ + switch(el) { + case Vtk::vtkVoxRaytracerRepresentation::RayElements: + d->m_SelectedElement = d->m_RayLine; + break; + case Vtk::vtkVoxRaytracerRepresentation::VoxelsElements: + d->m_SelectedElement = d->m_RayRepresentation; + break; + default: + d->m_SelectedElement = d->m_RayLine; + break; + } +} + + +void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon) +{ + HPoint3f pt1,pt2,src; + src = muon.LineIn().origin; + d->m_Content->GetEntryPoint(muon.LineIn(),pt1); + d->m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2)); + d->m_Line1->SetPoint1(src(0),src(1),src(2)); + d->m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2)); + + HLine3f line_out = muon.LineOut(); + src = line_out.origin; + float *direction = line_out.direction.data(); + for(int i=0;i<3;++i) direction[i] *= -1; + d->m_Content->GetEntryPoint(line_out,pt2); + d->m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2)); + d->m_Line2->SetPoint1(src(0),src(1),src(2)); + d->m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2)); + + d->m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2)); + d->m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2)); + + // Create a vtkPoints object and store the points in it + vtkSmartPointer points = + vtkSmartPointer::New(); + points->InsertNextPoint(pt1(0),pt1(1),pt1(2)); + points->InsertNextPoint(pt2(0),pt2(1),pt2(2)); + + // Create a cell array to store the lines in and add the lines to it + vtkSmartPointer lines = + vtkSmartPointer::New(); + + vtkSmartPointer line = + vtkSmartPointer::New(); + line->GetPointIds()->SetId(0,0); + line->GetPointIds()->SetId(1,1); + lines->InsertNextCell(line); + + // Create a polydata to store everything in + vtkSmartPointer linesPolyData = + vtkSmartPointer::New(); + + // Add the points to the dataset + linesPolyData->SetPoints(points); + + // Add the lines to the dataset + linesPolyData->SetLines(lines); + + d->m_RayLine->RemoveAllInputs(); +# if VTK_MAJOR_VERSION <= 5 + d->m_RayLine->AddInputConnection(linesPolyData->GetProducerPort()); +# else + d->m_RayLine->AddInputData(linesPolyData); +# endif + d->m_RayLine->AddInputConnection(d->m_Line1->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Sphere1->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Line2->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Sphere2->GetOutputPort()); +// d->m_RayLine->AddInputConnection(d->m_Line3->GetOutputPort()); + + + vtkSmartPointer vmat = vtkSmartPointer::New(); + Matrix4f mat = d->m_Content->GetImage()->GetWorldMatrix(); + for(int i=0; i<4; ++i) + for(int j=0; j<4; ++j) + vmat->SetElement(i,j,mat(i,j)); + d->m_Transform->SetMatrix(vmat); + + this->SetRay(pt1,pt2); +} + +void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca) +{ + HPoint3f pt1,pt2,src; + src = muon.LineIn().origin; + d->m_Content->GetEntryPoint(muon.LineIn(),pt1); + d->m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2)); + d->m_Line1->SetPoint1(src(0),src(1),src(2)); + d->m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2)); + + HLine3f line_out = muon.LineOut(); + src = line_out.origin; + float *direction = line_out.direction.data(); + for(int i=0;i<3;++i) direction[i] *= -1; + d->m_Content->GetEntryPoint(line_out,pt2); + d->m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2)); + d->m_Line2->SetPoint1(src(0),src(1),src(2)); + d->m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2)); + + d->m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2)); + d->m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2)); + + // Create a vtkPoints object and store the points in it + vtkSmartPointer points = + vtkSmartPointer::New(); + points->InsertNextPoint(pt1(0),pt1(1),pt1(2)); + points->InsertNextPoint(poca(0),poca(1),poca(2)); + points->InsertNextPoint(pt2(0),pt2(1),pt2(2)); + + // Create a cell array to store the lines in and add the lines to it + vtkSmartPointer lines = + vtkSmartPointer::New(); + + for(unsigned int i = 0; i < 2; i++) + { + vtkSmartPointer line = + vtkSmartPointer::New(); + line->GetPointIds()->SetId(0,i); + line->GetPointIds()->SetId(1,i+1); + lines->InsertNextCell(line); + } + + // Create a polydata to store everything in + vtkSmartPointer linesPolyData = + vtkSmartPointer::New(); + + // Add the points to the dataset + linesPolyData->SetPoints(points); + + // Add the lines to the dataset + linesPolyData->SetLines(lines); + + d->m_RayLine->RemoveAllInputs(); +# if VTK_MAJOR_VERSION <= 5 + d->m_RayLine->AddInputConnection(linesPolyData->GetProducerPort()); +# else + d->m_RayLine->AddInputData(linesPolyData); +# endif + d->m_RayLine->AddInputConnection(d->m_Line1->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Sphere1->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Line2->GetOutputPort()); + d->m_RayLine->AddInputConnection(d->m_Sphere2->GetOutputPort()); +// d->m_RayLine->AddInputConnection(d->m_Line3->GetOutputPort()); + + + vtkSmartPointer poca_sphere = + vtkSmartPointer::New(); + poca_sphere->SetRadius(d->default_radius); + poca_sphere->SetCenter(poca(0),poca(1),poca(2)); + d->m_RayLine->AddInputConnection(poca_sphere->GetOutputPort()); + + + vtkSmartPointer vmat = vtkSmartPointer::New(); + Matrix4f mat = d->m_Content->GetImage()->GetWorldMatrix(); + for(int i=0; i<4; ++i) + for(int j=0; j<4; ++j) + vmat->SetElement(i,j,mat(i,j)); + d->m_Transform->SetMatrix(vmat); + + if(d->m_Content->GetImage()->IsInsideBounds(poca)) + this->SetRay(pt1,poca,pt2); + else + this->SetRay(pt1,pt2); +} + + +void vtkVoxRaytracerRepresentation::SetMuon(vtkMuonScatter &muon) +{ + HPoint3f poca = muon.GetPocaPoint(); + MuonScatter &mu = muon.GetContent(); + this->SetMuon(mu,poca); +} + + +VoxRaytracer::RayData vtkVoxRaytracerRepresentation::GetRay() +{ + return d->m_Ray; +} + +void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f out) +{ + d->m_Ray = d->m_Content->TraceBetweenPoints(in,out); + this->SetRay(&d->m_Ray); +} + +void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f mid, HPoint3f out) +{ + d->m_Ray = d->m_Content->TraceBetweenPoints(in,mid); + d->m_Ray.AppendRay( d->m_Content->TraceBetweenPoints(mid,out) ); + this->SetRay(&d->m_Ray); +} + +void vtkVoxRaytracerRepresentation::SetRay(VoxRaytracer::RayData *ray) +{ + vtkAppendPolyData *appender = d->m_RayRepresentation; + appender->RemoveAllInputs(); + + for(int i=0; iData().size(); ++i) { + int id = ray->Data().at(i).vox_id; + Vector3i idv = d->m_Content->GetImage()->UnMap(id); + vtkSmartPointer cube = + vtkSmartPointer::New(); + cube->SetBounds(idv(0),idv(0)+1,idv(1),idv(1)+1,idv(2),idv(2)+1); + cube->Update(); +# if VTK_MAJOR_VERSION <= 5 + appender->AddInput(cube->GetOutput()); +# else + appender->AddInputData(cube->GetOutput()); +# endif + appender->Update(); + } + +} + +void vtkVoxRaytracerRepresentation::SetVoxelsColor(Vector4f rgba) +{ + this->SetColor(d->m_RayRepresentationActor,rgba); +} + +void vtkVoxRaytracerRepresentation::SetRayColor(Vector4f rgba) +{ + this->SetColor(d->m_RayLineActor,rgba); +} + +void vtkVoxRaytracerRepresentation::SetColor(vtkActor *actor, Vector4f rgba) +{ + if(!actor) return; + vtkProperty *pr = actor->GetProperty(); + pr->SetDiffuseColor( rgba(0), + rgba(1), + rgba(2) ); + pr->SetOpacity( rgba(3) ); + pr->SetDiffuse(1); +} + + + + +void vtkVoxRaytracerRepresentation::InstallPipe() +{ + + vtkSmartPointer append = + vtkSmartPointer::New(); + append->AddInputConnection(d->m_Sphere1->GetOutputPort()); + append->AddInputConnection(d->m_Sphere2->GetOutputPort()); + append->AddInputConnection(d->m_Line1->GetOutputPort()); + append->AddInputConnection(d->m_Line2->GetOutputPort()); + + append->Update(); + vtkSmartPointer mapper = + vtkSmartPointer::New(); + + mapper->SetInputConnection(append->GetOutputPort()); + mapper->Update(); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->GetProperty()->SetColor(0.6,0.6,1); + this->SetProp(actor); + + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(d->m_RayLine->GetOutputPort()); + mapper->Update(); + + d->m_RayLineActor->SetMapper(mapper); + d->m_RayLineActor->GetProperty()->SetColor(1,0,0); + this->SetProp(d->m_RayLineActor); + +// mapper = vtkSmartPointer::New(); +// mapper->SetInputConnection(d->m_Line3->GetOutputPort()); +// mapper->Update(); + +// actor = vtkSmartPointer::New(); +// actor->SetMapper(mapper); +// actor->GetProperty()->SetColor(1,0,0); +// d->m_Assembly->AddPart(actor); + + + vtkSmartPointer polyfilter = + vtkSmartPointer::New(); + + polyfilter->SetInputConnection(d->m_RayRepresentation->GetOutputPort()); + polyfilter->SetTransform(d->m_Transform); + + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(polyfilter->GetOutputPort()); + mapper->Update(); + + vtkActor *vra = d->m_RayRepresentationActor; + vra->SetMapper(mapper); + vra->GetProperty()->SetOpacity(0.2); + vra->GetProperty()->SetEdgeVisibility(true); + vra->GetProperty()->SetColor(0.5,0.5,0.5); + + this->SetProp(vra); +} + + + + + + + +} // vtk +} // uLib diff --git a/src/Vtk/vtkVoxRaytracerRepresentation.h b/src/Vtk/vtkVoxRaytracerRepresentation.h new file mode 100644 index 0000000..57ee264 --- /dev/null +++ b/src/Vtk/vtkVoxRaytracerRepresentation.h @@ -0,0 +1,101 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_VTKVOXRAYTRACERREPRESENTATION_H +#define U_VTKVOXRAYTRACERREPRESENTATION_H + + +#include "Core/Macros.h" +#include "Math/Dense.h" + +#include "uLibVtkInterface.h" + +#include "Detectors/MuonScatter.h" + +#include "Math/StructuredGrid.h" +#include "Math/VoxRaytracer.h" + + +class vtkActor; + +namespace uLib { +namespace Vtk { + +class vtkVoxRaytracerRepresentation : public Puppet { + typedef VoxRaytracer Content; +public: + vtkVoxRaytracerRepresentation(Content &content); + ~vtkVoxRaytracerRepresentation(); + + uLib::VoxRaytracer *GetRaytracerAlgorithm(); + + vtkProp *GetProp(); + + vtkPolyData *GetPolyData() const; + + enum RepresentationElements { + RayElements, + VoxelsElements + }; + void SetRepresentationElements(enum RepresentationElements el); + + void SetMuon(MuonScatter &muon); + + void SetMuon(MuonScatter &muon, HPoint3f poca); + + void SetMuon(class vtkMuonEvent &muon); + + void SetMuon(class vtkMuonScatter &muon); + + VoxRaytracer::RayData GetRay(); + + void SetRay(HPoint3f in, HPoint3f out); + + void SetRay(HPoint3f in, HPoint3f mid, HPoint3f out); + + void SetRay(VoxRaytracer::RayData *ray); + + void SetVoxelsColor(Vector4f rgba); + void SetRayColor(Vector4f rgba); + + + +private: + void InstallPipe(); + + void SetColor(vtkActor *actor, Vector4f rgba); + + friend class vtkVoxRaytracerRepresentationPimpl; + class vtkVoxRaytracerRepresentationPimpl *d; +}; + + +} // vtk +} // uLib + + +#endif // VTKVOXRAYTRACERREPRESENTATION_H diff --git a/src/Vtk/vtkuLibProp.h b/src/Vtk/vtkuLibProp.h new file mode 100644 index 0000000..fd6be35 --- /dev/null +++ b/src/Vtk/vtkuLibProp.h @@ -0,0 +1,51 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_VTKULIBPROP_H +#define U_VTKULIBPROP_H + +class vtkProp; + +namespace uLib { +namespace Abstract { + +class uLibVtkProp { +public: + virtual vtkProp *GetProp() = 0; + +protected: + ~uLibVtkProp() {} +}; + + + + +} + +} + +#endif // VTKULIBPROP_H diff --git a/src/cwchar.h b/src/cwchar.h new file mode 100644 index 0000000..c6f851e --- /dev/null +++ b/src/cwchar.h @@ -0,0 +1,37 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef U_CWCHAR_H +#define U_CWCHAR_H + +// cwchar.h does not exist, should be called "wchar.h" in C or in C++ +// this file serves as a patch to fix a error inclusion done by Root in cint. +// it must be placed in a included project directory + +#include + +#endif // CWCHAR_H diff --git a/src/ltk/CMakeLists.txt b/src/ltk/CMakeLists.txt new file mode 100644 index 0000000..8921da0 --- /dev/null +++ b/src/ltk/CMakeLists.txt @@ -0,0 +1,12 @@ + +set(HEADERS + ltktypes.h + ltkmacros.h + ltkdebug.h +) + +SET(SOURCES) + +set(LIBRARIES) + +uLib_add_shared_library(${uLib-module}) diff --git a/src/ltk/DenseMatrix.h b/src/ltk/DenseMatrix.h new file mode 100644 index 0000000..1214526 --- /dev/null +++ b/src/ltk/DenseMatrix.h @@ -0,0 +1,111 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#ifndef DENSEMATRIX_H +#define DENSEMATRIX_H + +#include "templates.h" +#include "Vector.h" + +BEGIN_NAMESPACE(ltk) + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// MATRIX ////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +C_BEGIN_DECLS + +#define LTK_MATRIX_DECLARE_FUNC(Type,ltkType,Class_name,csize,rsize) \ + inline Type ltkType##_##Class_name##_get(ltkType m, \ + unsigned int c, \ + unsigned int r) \ + { \ + assert(c + r * csize < csize * rsize); \ + return *((ltkType)m + c + r * csize); \ + } \ + inline void ltkType##_##Class_name##_set(ltkType m, \ + unsigned int c, \ + unsigned int r, \ + Type t) \ + { \ + assert (c + r * csize < csize * rsize); \ + *((ltkType)m + c + r * csize) = t; \ + } + + +#define LTK_MATRIX_DECLARE(Type,Type_name,csize,rsize) \ + typedef Type * Type_name; \ + LTK_SIMPLE_ALLOC_FUNC(Type, Type_name,ltk_matrix,csize * rsize) \ + LTK_MATRIX_DECLARE_FUNC(Type,Type_name,ltk_matrix,csize,rsize) + +C_END_DECLS + +#ifdef __cplusplus + +template class ltkDenseMatrix +: public ltkAbstractBuffer< T, csize * rsize > +{ +protected: + typedef ltkDenseMatrix ThisClass; + typedef ltkAbstractBuffer BaseClass; +public: + ltkDenseMatrix() {} + ~ltkDenseMatrix() { } + + inline T* getBuffer() { + return (T*)m_buffer; + } + inline const T* getBuffer() const { + return (const T*)m_buffer; + } + + ThisClass & operator =(const ThisClass &src) { + if (this != &src) { + CType_ltk_matrix_copy(m_buffer, (const CType) src.getBuffer()); + } + } + + typedef struct BaseClass::CommaInit CommaInit; + inline CommaInit operator = (T scalar) { + return this->operator <<(scalar); + } + + +private: + LTK_MATRIX_DECLARE(T,CType, csize, rsize); + T m_buffer [csize * rsize]; +}; + + + + +#endif // __cplusplus + +END_NAMESPACE + +#endif // DENSEMATRIX_H diff --git a/src/ltk/Makefile.am b/src/ltk/Makefile.am new file mode 100644 index 0000000..5f0e5d0 --- /dev/null +++ b/src/ltk/Makefile.am @@ -0,0 +1,6 @@ +include $(top_srcdir)/Common.am + +library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ltk +library_include_HEADERS = ltktypes.h \ + ltkmacros.h \ + ltkdebug.h diff --git a/src/ltk/Object.c b/src/ltk/Object.c new file mode 100644 index 0000000..6269c9a --- /dev/null +++ b/src/ltk/Object.c @@ -0,0 +1,18 @@ +#include "Object.h" + + +static const struct _ltkObjectClass { + size_t class_size; + void (* constructor)(struct _Object *); + void (* destructor) (struct _Object *); + int (* GetElement) (struct _Object *); +} _ObjectClassInstance; + +const struct _ltkObjectClass *ltkObjectClass = &_ObjectClassInstance; + +ltkPointer Object_new(struct _ObjectClass klass) +{ + struct _Object *ob = (struct _Object)malloc(klass->class_size); + klass->constructor(ob); + return ob; +} diff --git a/src/ltk/Object.h b/src/ltk/Object.h new file mode 100644 index 0000000..a39a87a --- /dev/null +++ b/src/ltk/Object.h @@ -0,0 +1,78 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef OBJECT_H +#define OBJECT_H + +#include // for std allocator // +#include // for memcpy // +#include + +#include "templates.h" + +BEGIN_NAMESPACE(ltk) + + +C_BEGIN_DECLS + +struct _ltkObject +{ + int element; +}; + +struct _ltkObjectClass { + size_t class_size; + void (* constructor)(struct _ltkObject *); + void (* destructor) (struct _ltkObject *); + int (* GetElement) (struct _ltkObject *); +}; + +struct _ltkObject *ltk_object_new() +{ + return NULL; +} + + +C_END_DECLS + +#ifdef __cplusplus + +class Object +{ + struct _ltkObject *d; + typedef struct _ltkObject ObjectType; + public: + Object() : d(new ObjectType()) { d->element = 5552368; } + int GetElement() { return d->element; } +}; + +#endif + + +END_NAMESPACE + +#endif //OBJECT_H diff --git a/src/ltk/Vector.h b/src/ltk/Vector.h new file mode 100644 index 0000000..229295b --- /dev/null +++ b/src/ltk/Vector.h @@ -0,0 +1,195 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * File: denseVector.h + * Author: andrea + * + * Created on July 6, 2012, 3:41 PM + */ + +#ifndef VECTOR_H +#define VECTOR_H + +#include // for std allocator // +#include // for memcpy // +#include + +#include "templates.h" + +BEGIN_NAMESPACE(ltk) + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// VECTOR ///////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +C_BEGIN_DECLS + +#define LTK_VECTOR_DECLARE(Type,Type_name,size) \ + typedef Type *Type_name; \ + LTK_SIMPLE_ALLOC_FUNC(Type,Type_name,ltk_vector,size) \ + inline unsigned int Type_name##_ltk_vector_size() { return size; } \ + inline Type Type_name##_ltk_vector_get(Type_name vector, unsigned int i) \ + { return *(vector+i); } \ + inline void Type_name##_ltk_vector_set(Type_name vector, unsigned int i, \ + Type data) { *(vector+i) = data; } + +C_END_DECLS + +#ifdef __cplusplus + +template class ltkVector +: public ltkAbstractBuffer< T, size > +{ + T m_vector [size]; +protected: + typedef ltkVector ThisClass; + typedef ltkAbstractBuffer BaseClass; +public: + ltkVector() {} + ltkVector(const ltkVector ©) { + CType_ltk_vector_copy(m_vector, (const CType) copy.getBuffer()); + } + + virtual ~ltkVector() { } + + inline unsigned int getSize() const { + return size; + } + inline T* getBuffer() { + return (T*)m_vector; + } + inline const T* getBuffer() const { + return (const T*)m_vector; + } + + + + ThisClass & operator =(const ThisClass &src) { + if (this != &src) { + CType_ltk_vector_copy(m_vector, (const CType) src.getBuffer()); + } + } + + typedef struct BaseClass::CommaInit CommaInit; + inline CommaInit operator = (T scalar) { + return this->operator <<(scalar); + } + + // MATH // + inline bool operator ==(const ThisClass &in) { + int test = 0; + for (int i = 0; i < size; ++i) test += this->at(i) != in(i); + return test == 0; + } + + inline bool operator !=(const ThisClass &in) { + return !this->operator ==(in); + } + + inline void operator +=(const ThisClass &in) { + for (int i = 0; i < size; ++i) this->at(i) += in(i); + } + inline void operator -=(const ThisClass &in) { + for (int i = 0; i < size; ++i) this->at(i) -= in(i); + } + inline void operator *=(const ThisClass &in) { + for (int i = 0; i < size; ++i) this->at(i) *= in(i); + } + inline void operator /=(const ThisClass &in) { + for (int i = 0; i < size; ++i) this->at(i) /= in(i); + } + + inline void operator +=(const T t) { + for (int i = 0; i < size; ++i) this->at(i) += t; + } + inline void operator -=(const T t) { + for (int i = 0; i < size; ++i) this->at(i) -= t; + } + inline void operator *=(const T t) { + for (int i = 0; i < size; ++i) this->at(i) *= t; + } + inline void operator /=(const T t) { + for (int i = 0; i < size; ++i) this->at(i) /= t; + } + + inline ThisClass & operator + (const ThisClass &in) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) + in(i); + return *out; + } + inline ThisClass & operator - (const ThisClass &in) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) - in(i); + return *out; + } + + // fix with constructor and product null element ------------- // + inline T operator * (const ThisClass &in) { + T out = 0; + for (int i = 0; i < size; ++i) out += this->at(i) * in(i); + return out; + } + inline T operator / (const ThisClass &in) { + T out = 0; + for (int i = 0; i < size; ++i) out += this->at(i) / in(i); + return out; + } + // ------------------------------------------------------------- // + + inline ThisClass & operator +(const T t) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) + t; + return *out; + } + inline ThisClass & operator -(const T t) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) - t; + return *out; + } + inline ThisClass & operator *(const T t) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) * t; + return *out; + } + inline ThisClass & operator /(const T t) { + ThisClass *out = new ThisClass(); + for (int i = 0; i < size; ++i) out->at(i) = this->at(i) / t; + return *out; + } +private: + LTK_VECTOR_DECLARE(T,CType, size) +}; + +#endif // __cplusplus + + + + +END_NAMESPACE // ltk +#endif /* DENSEVECTOR_H */ + diff --git a/src/ltk/container.h b/src/ltk/container.h new file mode 100644 index 0000000..58dbdc7 --- /dev/null +++ b/src/ltk/container.h @@ -0,0 +1,43 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * File: comma_init.h + * Author: andrea + * + * Created on May 24, 2012, 3:12 PM + */ + +#ifndef CONTAINER_H +#define CONTAINER_H + +#include + + + +#endif /* CONTAINER_H */ + diff --git a/src/ltk/ltk.h b/src/ltk/ltk.h new file mode 100644 index 0000000..38a16f2 --- /dev/null +++ b/src/ltk/ltk.h @@ -0,0 +1,32 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + + +#include "templates.h" +#include "Vector.h" +#include "DenseMatrix.h" diff --git a/src/ltk/ltk_bridge/ltkb.c b/src/ltk/ltk_bridge/ltkb.c new file mode 100644 index 0000000..f1b3d91 --- /dev/null +++ b/src/ltk/ltk_bridge/ltkb.c @@ -0,0 +1,339 @@ +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef MODVERSIONS +# include +#endif +#include +#include +#include + + + +/* methods of the character device */ +static int ltkb_open(struct inode *inode, struct file *filp); +static int ltkb_release(struct inode *inode, struct file *filp); +static int ltkb_mmap(struct file *filp, struct vm_area_struct *vma); +static ssize_t ltkb_read(struct file *filp, + char __user *buffer, + size_t count, + loff_t *offp); +static ssize_t ltkb_write(struct file *filp, + const char __user *buffer, + size_t count, + loff_t *offp); + + +// internal data +// length of the two memory areas +#define NPAGES 16 +// pointer to the vmalloc'd area - alway page aligned +static int *vmalloc_area; +// pointer to the kmalloc'd area, rounded up to a page boundary +static int *kmalloc_area; +// original pointer for kmalloc'd area as returned by kmalloc +static void *kmalloc_ptr; + + +#define BUF_LEN 80 +static int Device_Open = 0; + +static char Message[BUF_LEN]; +/* + * How far did the process reading the message get? + * Useful if the message is larger than the size of the + * buffer we get to fill in device_read. + */ +static char *Message_Ptr; + + +struct ltkb_dev { + struct cdev cdev; // device structure + struct semaphore semaphore; // lock semaphore for race control + char *message; // message passing from/to user + unsigned int size; // size of data stored + unsigned int acl_key; // user access control +}; + +struct ltkb_dev *_ltkb_devices; // devices array // + + + + + +/////// OPEN AND RELEASE /////////////////////////////////////////////////////// +static int ltkb_open(struct inode *inode, struct file *filp) +{ + // insert cdev data in dev structure and file->private_data // + struct ltkb_dev *dev; + dev = container_of (inode->i_cdev, struct ltkb_dev, cdev); + + // this shares dev for all methods // + filp->private_data = dev; + + pr_debug("ltk bridge opened"); + return 0; +} +/* character device last close method */ +static int ltkb_release(struct inode *inode, struct file *filp) +{ + pr_debug("ltk bridge released"); + return 0; +} +// -------------------------------------------------------------------------- // + + + +// kmalloc instancer // +int ltkb_kmem(struct file *filp, struct vm_area_struct *vma) +{ + int ret; + long length = vma->vm_end - vma->vm_start; + + /* check length - do not allow larger mappings than the number of + pages allocated */ + if (length > NPAGES * PAGE_SIZE) + return -EIO; + + /* map the whole physically contiguous area in one piece */ + if ((ret = remap_pfn_range(vma, + vma->vm_start, + virt_to_phys((void *)kmalloc_area) >> PAGE_SHIFT, + length, + vma->vm_page_prot)) < 0) { + return ret; + } + return 0; +} +// vmalloc instancer // +int ltkb_vmem(struct file *filp, struct vm_area_struct *vma) +{ + int ret; + long length = vma->vm_end - vma->vm_start; + unsigned long start = vma->vm_start; + char *vmalloc_area_ptr = (char *)vmalloc_area; + unsigned long pfn; + + /* check length - do not allow larger mappings than the number of + pages allocated */ + if (length > NPAGES * PAGE_SIZE) + return -EIO; + + /* loop over all pages, map it page individually */ + while (length > 0) { + pfn = vmalloc_to_pfn(vmalloc_area_ptr); + if ((ret = remap_pfn_range(vma, start, pfn, PAGE_SIZE, + PAGE_SHARED)) < 0) { + return ret; + } + start += PAGE_SIZE; + vmalloc_area_ptr += PAGE_SIZE; + length -= PAGE_SIZE; + } + return 0; +} + + + +// mmap function // +static int ltkb_mmap(struct file *filp, struct vm_area_struct *vma) +{ + /* at offset 0 we map the vmalloc'd area */ + if (vma->vm_pgoff == 0) { + return ltkb_vmem(filp, vma); + } + /* at offset NPAGES we map the kmalloc'd area */ + if (vma->vm_pgoff == NPAGES) { + return ltkb_kmem(filp, vma); + } + /* at any other offset we return an error */ + return -EIO; +} + + + + +////////////// CHAR DEVICE READ/WRITE ///////////////////////////////////////// +static ssize_t ltkb_read(struct file *filp, /* see include/linux/fs.h */ + char __user *buffer, /* buffer to fill with data */ + size_t length, /* length of the buffer */ + loff_t * offset) +{ + +#ifdef _DEBUG + printk(KERN_INFO "device_read(%p,%s,%d)", filp, buffer, (int)length); +#endif + + return 0; +} + +static ssize_t ltkb_write(struct file *filp, + const char __user *buffer, + size_t length, + loff_t * offset) +{ +#ifdef _DEBUG + printk(KERN_INFO "device_write(%p,%s,%d)", filp, buffer, (int)length); +#endif + return 0; +} +// ------------------------------------------------------------------------- // + + +#define LTKB_IOC_HEADER 'b' + +#define LTKB_IOC_RESET _IO(LTKB_IOC_HEADER, 0) +#define LTKB_IOC_PING _IOWR(LTKB_IOC_HEADER, 1, char) + +#define LTKB_IOC_MAXNR 1 + +////////////// IOCTL /////////////////////////////////////////////////////////// +int ltkb_ioctl(struct inode *inode, struct file *filp, + unsigned int cmd, unsigned long arg) +{ + char c = 0; + int retval = 0; + + /* + * extract the type and number bitfields, and don't decode + * wrong cmds: return ENOTTY (inappropriate ioctl) before access_ok() + */ + if (_IOC_TYPE(cmd) != LTKB_IOC_HEADER) return -ENOTTY; + if (_IOC_NR(cmd) > LTKB_IOC_MAXNR) return -ENOTTY; + + // TODO user access control // + + + switch(cmd) { + case LTKB_IOC_RESET: + if(!capable(CAP_SYS_ADMIN)) + return -EPERM; + // TODO free all memory mapping// + break; + case LTKB_IOC_PING: + retval = __get_user(c,(char __user *)arg); + c++; + retval = __put_user(c,(char __user *)arg); + break; + default: + return -ENOTTY; + } + return retval; + +} +// ------------------------------------------------------------------------- // + + + + + +#ifndef LTKB_MAJOR +#define LTKB_MAJOR 0 +#endif + +#ifndef LTKB_NR_DEVS +#define LTKB_NR_DEVS 4 +#endif + +#ifndef LTKB_DEVICE_NAME +#define LTKB_DEVICE_NAME "ltkb" +#endif + + + +/* the file operations, i.e. all character device methods */ +static struct file_operations ltkb_fops = { + .open = ltkb_open, + .release = ltkb_release, + .read = ltkb_read, + .write = ltkb_write, + .ioctl = ltkb_ioctl, + .mmap = ltkb_mmap, + .owner = THIS_MODULE, +}; + +static int _ltkb_major_number = LTKB_MAJOR; + +// Module init function //////////////////////////////////////////////////////// +static int __init ltkb_init(void) +{ + int i,ret = 0; + dev_t dev = 0; + + // REGISTER DEVICE // + if(_ltkb_major_number) + { + dev = MKDEV(_ltkb_major_number,0); + ret = register_chrdev_region(dev, LTKB_NR_DEVS, LTKB_DEVICE_NAME); + } + else { + ret = alloc_chrdev_region(&dev, 0, LTKB_NR_DEVS, LTKB_DEVICE_NAME ); + _ltkb_major_number = MAJOR(dev); + } + if (ret < 0) { + printk(KERN_WARNING "could not allocate major number %d for ltkb\n", + _ltkb_major_number); + return ret; + } + + // ALLOCATE DEVICES // + _ltkb_devices = kmalloc( LTKB_NR_DEVS * sizeof(struct ltkb_dev), GFP_KERNEL ); + if(!_ltkb_devices) { + printk(KERN_ERR "error allocating device structure in memory"); + return -ENOMEM; + } + memset(_ltkb_devices, 0, LTKB_NR_DEVS * sizeof(struct ltkb_dev)); + + // SETUP DEVICES // + for (i = 0 ; i < LTKB_NR_DEVS ; i++ ) + { + struct ltkb_dev *dev = &_ltkb_devices[i]; + int devno = MKDEV(_ltkb_major_number, i); + cdev_init (&dev->cdev, <kb_fops); + dev->cdev.owner = THIS_MODULE; + dev->cdev.ops = <kb_fops; + ret = cdev_add(&dev->cdev,devno,1); + if(ret) printk(KERN_NOTICE "Error %d adding ltkb%d device", ret, i); + init_MUTEX(&dev->semaphore); + } + printk( KERN_NOTICE "ltk bridge module loaded"); + return ret; +} + +// module release // +static void __exit ltkb_exit(void) +{ + // remove the character deivce // + int i; + dev_t devno = MKDEV(_ltkb_major_number,0); + if(_ltkb_devices) + { + for(i=0;i +#include +#include +#include +#include +#include +#include +#include + +#define LTKB_IOC_HEADER 'b' + +#define LTKB_IOC_RESET _IO(LTKB_IOC_HEADER, 0) +#define LTKB_IOC_PING _IOWR(LTKB_IOC_HEADER, 1, char) + +#define LTKB_IOC_MAXNR 1 + + +int main(void) +{ + int fd; + + if ((fd=open("ltkb0", O_RDWR|O_SYNC))<0) + { + perror("open"); + exit(-1); + } + + char buffer[200] = "hello"; + write(fd, (void *)&buffer, 6); + + char c = 'a'; + printf("%c ",c); + ioctl(fd, LTKB_IOC_PING, &c); + printf("%c ",c); + ioctl(fd, LTKB_IOC_PING, &c); + printf("%c\n",c); + close(fd); + return(0); +} + diff --git a/src/ltk/ltk_bridge/setup.sh b/src/ltk/ltk_bridge/setup.sh new file mode 100755 index 0000000..1886632 --- /dev/null +++ b/src/ltk/ltk_bridge/setup.sh @@ -0,0 +1,21 @@ +#!/bin/sh +module="ltkb" +device="ltkb" +mode="664" + +/sbin/insmod ./$module.ko $* || exit 1 + +rm -f ./${device}[0-3] + +major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices) + +mknod ./${device}0 c $major 0 +mknod ./${device}1 c $major 1 +mknod ./${device}2 c $major 2 +mknod ./${device}3 c $major 3 + +group="mutom" +grep -q '^mutom:' /etc/group || group="adm" + +chgrp $group ./${device}[0-3] +chmod $mode ./${device}[0-3] \ No newline at end of file diff --git a/src/ltk/ltkdebug.c b/src/ltk/ltkdebug.c new file mode 100644 index 0000000..03b5024 --- /dev/null +++ b/src/ltk/ltkdebug.c @@ -0,0 +1,4 @@ + +#include "ltkdebug.h" + + diff --git a/src/ltk/ltkdebug.h b/src/ltk/ltkdebug.h new file mode 100755 index 0000000..fe55a04 --- /dev/null +++ b/src/ltk/ltkdebug.h @@ -0,0 +1,105 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef LTKDEBUG_H +#define LTKDEBUG_H + + +#include "ltkmacros.h" +#include "ltktypes.h" + +//! Provide a string for current function, non-concatenatable +#if defined (__GNUC__) || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L) +# define __func_to_string__ ((const char*) (__func__)) +#else +# define __func_to_string__ ((const char*) ("???")) +#endif + +//! Provide a string for current function in pretty format, non-concatenatable +#if defined (__GNUC__) +# define __pfunc_to_string__ ((const char*) (__PRETTY_FUNCTION__)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L +# define __pfunc_to_string__ ((const char*) (__func__)) +#else +# define __pfunc_to_string__ ((const char*) ("???")) +#endif + + + +//////////////////////////////////////////////////////////////////////////////// +//// Pragma Messages for debug allerts during compilation ///////////////////// +//////////////////////////////////////////////////////////////////////////////// + +#ifdef PRAGMA_MESSAGES +#define DEBUG_DO_PRAGMA(x) _Pragma (#x) +#else +#define DEBUG_DO_PRAGMA(x) ; +#endif + +#define TODO(x) DEBUG_DO_PRAGMA(message ("\n\n [TODO] >> " #x " <<\n")) +#define OPTIMIZE(x) DEBUG_DO_PRAGMA(message ("\n\n [OPTIMIZE] > " #x " <\n")) +#define DUMP(x) DEBUG_DO_PRAGMA(message ("\n\n [DUMP] > " #x " <\n")) + +// ------------------------------------------------------------------------ // + + + +C_BEGIN_DECLS + + +typedef enum +{ + LOG_FLAG_ACTIVE = 1 << 0, + LOG_FLAG_FATAL = 1 << 1, + LOG_LEVEL_ERROR = 1 << 2, + LOG_LEVEL_CRITICAL = 1 << 3, + LOG_LEVEL_WARNING = 1 << 4, + LOG_LEVEL_MESSAGE = 1 << 5, + LOG_LEVEL_INFO = 1 << 6, + LOG_LEVEL_DEBUG = 1 << 7, + LOG_LEVEL_ANNOING = 1 << 8, + LOG_LEVEL_PARANOID = 1 << 9 +} LogLevelFlags; + + + + +void debug_log( + void *handler, + LogLevelFlags flags, + const char *function_name, + const char *message, + ...); + + + +C_END_DECLS + + + + +#endif // LTKDEBUG_H diff --git a/src/ltk/ltkmacros.h b/src/ltk/ltkmacros.h new file mode 100644 index 0000000..c5e921d --- /dev/null +++ b/src/ltk/ltkmacros.h @@ -0,0 +1,61 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * File: macros.h + * Author: andrea + * + * Created on May 23, 2012, 9:01 AM + */ + +#ifndef LTK_MACROS_H +#define LTK_MACROS_H + +// C code in headers, while including them from C++ +#ifdef __cplusplus + +# define C_BEGIN_DECLS extern "C" { +# define C_END_DECLS } + +#define BEGIN_NAMESPACE(name) namespace name { +#define END_NAMESPACE } + +#else + +# define C_BEGIN_DECLS +# define C_END_DECLS + +#define BEGIN_NAMESPACE(name) +#define END_NAMESPACE + +#endif + + + + +#endif /* MACROS_H */ + diff --git a/src/ltk/ltktypes.h b/src/ltk/ltktypes.h new file mode 100644 index 0000000..c243841 --- /dev/null +++ b/src/ltk/ltktypes.h @@ -0,0 +1,127 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef LTK_TYPE_H +#define LTK_TYPE_H + +#include +#include + +//#include "templates.h" +#include "ltkmacros.h" + +#ifdef __cplusplus +# define LTK_TYPECAST(T, Type) static_cast< T >(Type) +#else +# define LTK_TYPECAST(T, Type) ((T)(Type)) +#endif + + +BEGIN_NAMESPACE(ltk) + +C_BEGIN_DECLS + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// TYPE DEFINITIONS ////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + + +typedef void * Pointer_t; +typedef id_t Id_t; +typedef size_t Size_t; + +#ifndef LTK_DOUBLE_PRECISION +typedef float Real_t; +#else +typedef double Real_t; +#endif + +#define LTK_SIGNED_CHAR_MIN LTK_TYPECAST(signed char, 0x80) +#define LTK_SIGNED_CHAR_MAX LTK_TYPECAST(signed char, 0x7f) + +#define LTK_UNSIGNED_CHAR_MIN LTK_TYPECAST(unsigned char, 0u) +#define LTK_UNSIGNED_CHAR_MAX LTK_TYPECAST(unsigned char, 0xffu) + +#define LTK_SHORT_MIN LTK_TYPECAST(short, 0x8000) +#define LTK_SHORT_MAX LTK_TYPECAST(short, 0x7fff) + +#define LTK_UNSIGNED_SHORT_MIN LTK_TYPECAST(unsigned short, 0u) +#define LTK_UNSIGNED_SHORT_MAX LTK_TYPECAST(unsigned short, 0xffffu) + +#define LTK_INT_MIN LTK_TYPECAST(int, ~(~0u >> 1)) +#define LTK_INT_MAX LTK_TYPECAST(int, ~0u >> 1) + +#define LTK_INT8_MIN LTK_TYPECAST(int8_t, 0x80) +#define LTK_INT8_MAX LTK_TYPECAST(int8_t, 0x7f) + +#define LTK_INT16_MIN LTK_TYPECAST(int16_t, 0x8000u) +#define LTK_INT16_MAX LTK_TYPECAST(int16_t, 0x7fffu) + +#define LTK_UNSIGNED_INT16_MIN LTK_TYPECAST(int16_t, 0u) +#define LTK_UNSIGNED_INT16_MAX LTK_TYPECAST(unsigned int16_t, 0xffffu) + +#define LTK_INT32_MIN LTK_TYPECAST(int32_t, 0x80000000u) +#define LTK_INT32_MAX LTK_TYPECAST(int32_t, 0x7fffffffu) + +#define LTK_UNSIGNED_INT32_MIN LTK_TYPECAST(unsigned int32_t, 0u) +#define LTK_UNSIGNED_INT32_MAX LTK_TYPECAST(unsigned int32_t, 0xffffffffu) + +#define LTK_INT64_MIN LTK_TYPECAST(int64_t, 0x8000000000000000u) +#define LTK_INT64_MAX LTK_TYPECAST(int64_t, 0x7fffffffffffffffu) + +#define LTK_UNSIGNED_INT8_MIN LTK_TYPECAST(int8_t, 0u) +#define LTK_UNSIGNED_INT8_MAX LTK_TYPECAST(int8_t, 0xffu) + +#define LTK_UNSIGNED_INT64_MIN LTK_TYPECAST(unsigned int64_t, 0u) +#define LTK_UNSIGNED_INT64_MAX LTK_TYPECAST(unsigned int64_t, \ + 0xffffffffffffffffu) + +#define LTK_UNSIGNED_INT_MIN LTK_TYPECAST(unsigned int, 0) +#define LTK_UNSIGNED_INT_MAX LTK_TYPECAST(unsigned int, ~0u) + +#define LTK_LONG_MIN LTK_TYPECAST(long, ~(~0ul >> 1)) +#define LTK_LONG_MAX LTK_TYPECAST(long, ~0ul >> 1) + +#define LTK_UNSIGNED_LONG_MIN LTK_TYPECAST(unsigned long, 0ul) +#define LTK_UNSIGNED_LONG_MAX LTK_TYPECAST(unsigned long, ~0ul) + +#define LTK_FLOAT_MIN LTK_TYPECAST(float, -1.0e+38f) +#define LTK_FLOAT_MAX LTK_TYPECAST(float, 1.0e+38f) + +#define LTK_DOUBLE_MIN LTK_TYPECAST(double, -1.0e+299) +#define LTK_DOUBLE_MAX LTK_TYPECAST(double, 1.0e+299) + + + + + +C_END_DECLS + +END_NAMESPACE + + +#endif //TYPE_H diff --git a/src/ltk/main.C b/src/ltk/main.C new file mode 100644 index 0000000..fb90774 --- /dev/null +++ b/src/ltk/main.C @@ -0,0 +1,35 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +#include "Object.h" + + +int main() +{ + return 0; +} diff --git a/src/ltk/main.c b/src/ltk/main.c new file mode 100644 index 0000000..12c29cd --- /dev/null +++ b/src/ltk/main.c @@ -0,0 +1,72 @@ + +#include "DenseMatrix.h" +#include "Vector.h" +#include "Object.h" + +#include "vectormath/simd/instrset.h" + +/* LTK_VECTOR_DECLARE(int,LtkInt4,4) */ + +/* LTK_MATRIX_DECLARE(int,LtkInt2x2,2,2) */ +/* LTK_MATRIX_DECLARE(int,LtkInt4x1,4,1) */ +/* LTK_MATRIX_DECLARE(int,LtkInt4x4,4,4) */ + +int test(int a) { return 0; } + + +int main(void) +{ + + // testing dense matrix // + /****************************************************/ + /* LtkInt2x2 a; */ + /* LtkInt4x1 b; */ + /* LtkInt4x4 c; */ + /* LtkInt4 v, w; */ + /* */ + /* v = LtkInt4_ltk_vector_new (); */ + /* w = LtkInt4_ltk_vector_new (); */ + /* */ + /* int i; */ + /* for (i = 0; i < LtkInt4_ltk_vector_size (); ++i) */ + /* { */ + /* LtkInt4_ltk_vector_set (v, i, 0); */ + /* LtkInt4_ltk_vector_set (w, i, 3); */ + /* } */ + /* */ + /* printf ("v = "); */ + /* for (i = 0; i < 4; ++i) */ + /* printf ("%d ", LtkInt4_ltk_vector_get (v, i)); */ + /* printf ("\n"); */ + /* */ + /* printf ("w = "); */ + /* for (i = 0; i < 4; ++i) */ + /* printf ("%d ", LtkInt4_ltk_vector_get (w, i)); */ + /* printf ("\n"); */ + /****************************************************/ + + // testing intrinsics // + printf("INSTRUCTION SET -> %d\n",INSTRSET); + __m128 aligned_float = _mm_setzero_ps(); + float *p = &aligned_float; + printf("%f,%f,%f,%f\n",p[0],p[1],p[2],p[3]); + + // adder // + __m128 a_1,a_2; + a_1 = _mm_set_ps(3,3,3,3); + a_2 = _mm_set_ps(1,2,3,4); + + + aligned_float = _mm_add_ps(a_1,a_2); + p = &aligned_float; printf("%f,%f,%f,%f\n",p[0],p[1],p[2],p[3]); + + + + // testing Objects // + //LTK_MATRIX_DECLARE(TypeName, type, r, c); + // Object *ob = New(ObjectClass); + // int el = ObjectClass->GetElement(ob); + + + return 0; +} diff --git a/src/ltk/templates.c b/src/ltk/templates.c new file mode 100644 index 0000000..a154d1a --- /dev/null +++ b/src/ltk/templates.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include "templates.h" + + +LtkList ltk_list_new() +{ + LtkList list = malloc(sizeof(struct _template_list)); + list->size = 0; + list->start = NULL; + list->end = NULL; + return list; +} + +void ltk_list_nodepush(LtkList list,LtkListNode node) +{ + if(list == NULL) return; + node->next = list->start; + list->start = node; + if(list->end == NULL) list->end = node; + list->size++; +} + +LtkListNode ltk_list_get_start(LtkList list) +{ + if (list==NULL || list->start==NULL) return NULL; + return list->start; +} + +LtkListNode ltk_list_get_end(LtkList list) +{ + if (list==NULL || list->end==NULL) return NULL; + return list->end; +} + +void ltk_list_remove(LtkList list,LtkListNode node) +{ + if (list == NULL || list->start==NULL) return; + struct _template_list_node *node_tofree,*prev; + node_tofree=list->start; + while (node_tofree != node) { + if(node_tofree->next == NULL) return; + prev = node_tofree; + node_tofree = node_tofree->next; + } + if(node_tofree == list->start) list->start = node_tofree->next; + else prev->next = node_tofree->next; + free(node_tofree); +} + +void ltk_list_pop_start(LtkList list) +{ + if (list==NULL || list->start==NULL) return; + struct _template_list_node *nodetofree; + nodetofree=list->start; + list->start = list->start->next; + free(nodetofree); +} + +void ltk_list_pop_end(LtkList list) +{ + if (list==NULL || list->end==NULL) return; + struct _template_list_node *iter; + iter=list->start; + if(iter==list->end) { + free(iter); + list->start = list->end = NULL; + } + else { + while(iter->next!=list->end) iter=iter->next; + free(iter->next); + iter->next = NULL; + list->end = iter; + } + list->size--; +} + +int ltk_list_get_size(LtkList list) +{ + if(list==NULL) return 0; + return list->size; +} + + +LtkListIterator ltk_list_iterator_new(LtkList list) +{ + if(list==NULL || list->start == NULL) return NULL; + return (LtkListIterator)list->start; +} + + diff --git a/src/ltk/templates.h b/src/ltk/templates.h new file mode 100644 index 0000000..00abd01 --- /dev/null +++ b/src/ltk/templates.h @@ -0,0 +1,303 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * + * Copyright (C) 2012 Andrea Rigoni Garola + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifndef TEMPLATES_H +#define TEMPLATES_H + +#include // for std allocator // +#include // for memcpy // +#include + +#include "ltkmacros.h" // default environment // +#include "container.h" // TODO !!! // + +#include + + + + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// ALLOC FUNCTIONS ///////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +C_BEGIN_DECLS + +//inline ltkPointer ltk_malloc(unsigned int size) { return malloc(size); } +//inline void ltk_free (ltkPointer ptr) { free(ptr); } + +#define LTK_SIMPLE_ALLOC_FUNC(Type, ltkType, Class_name, size) \ + inline ltkType ltkType##_##Class_name##_new() \ + { \ + return LTK_TYPECAST(ltkType, malloc(sizeof(Type) * size)); \ + } \ + inline void ltkType##_##Class_name##_delete(ltkType t) \ + { free(t); } \ + inline void ltkType##_##Class_name##_copy(ltkType dst, const ltkType src) \ + { memcpy((ltkPointer)dst, (ltkPointer)src, sizeof(Type) * size ); } + +C_END_DECLS + + + + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// ABSTRACT C BUFFER /////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +C_BEGIN_DECLS + +#define LTK_ABSTRACT_BUFFER_DECLARE_FUNC(Type,ltkType,Class_name,size) \ + inline int ltkType##_##Class_name##_size() { return size; } \ + inline Type ltkType##_##Class_name##_get(ltkType v, unsigned int c) \ + { assert(c < size); return *((ltkType)m + c); } \ + inline void ltkType##_##Class_name##_set(ltkType v, Type t, unsigned int c) \ + { assert(c < size); *((ltkType)m + c) = t; } + +// FINIRE !!! // + +C_END_DECLS + +#ifdef __cplusplus + +template class ltkAbstractBuffer +{ + typedef ltkAbstractBuffer ThisClass; +protected: + typedef T ContentType; + virtual T* getBuffer() = 0; + virtual const T* getBuffer() const = 0; + + struct CommaInit + { + inline explicit CommaInit(ltkAbstractBuffer *container,float s) + : container(container) { + this->index = 0; + this->container->getBuffer()[0] = s; + } + inline CommaInit & operator, (float s) { + this->index++; + assert(index < size); + this->container->getBuffer()[this->index] = s; + return *this; + } + ltkAbstractBuffer *container; + unsigned int index; + }; + +public: + inline CommaInit operator =(T scalar) { + return CommaInit(this, scalar); + } + inline CommaInit operator <<(T scalar) { + return CommaInit(this, scalar); + } + + inline T& at(const unsigned int i) { + return *(this->getBuffer() + i); + } + + inline T & operator[](unsigned int i) { + return *(this->getBuffer() + i); + } + inline const T & operator[](unsigned int i) const { + return *(this->getBuffer() + i); + } + inline T & operator()(unsigned int i) { + return *(this->getBuffer() + i); + } + inline const T & operator()(unsigned int i) const { + return *(this->getBuffer() + i); + } + + +}; + +#endif // __cplusplus + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// ARRAY /////////////////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ + +// COMING SOON // + + + + + + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// DO NOT USE ANYTHING AFTER THIS LINE ... EXPERIMENTAL ////////////////// + + + + + + + + + +/* ////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////// CIRCULAR BUFFER ///////////////////////////// */ +/* ////////////////////////////////////////////////////////////////////////// */ +/* CIRCULAR BUFFER */ + +struct _ltk_template_buffer { + void *pos; + void *head; +}; + +#define LTK_BUFFER_DECLARE(Type, Type_name, size, overlap) \ +typedef struct _ltk_template_buffer *Type_name; \ +inline Type_name Type_name##_ltk_buffer_new() \ +{ Type_name out = (Type_name)ltk_malloc \ + (sizeof(Type) * (size + overlap) + 2); \ + out->head = (void *)out + 2 + overlap * sizeof(Type); \ + out->pos = out->head; \ +return out; } \ +inline void Type_name##_ltk_buffer_free(Type_name buffer) { ltk_free(buffer); }\ + + + +// TO BE CONTINUED.... // + + + + + + + + +///// LtkPTree //////// + +struct _LtkPTreeNode +{ + struct _LtkPTreeNode *parent; +}; +typedef struct _LtkPTreeNode *LtkPtree; + + + + + + + + + + + + +/* + one way list template usable as FIFO or LIFO by macros + Element must be a pointer to a real allocated object. +*/ +// this acts as dummy node, never really instanciated // +struct _template_list_node { + struct _template_list_node *next; +}; +typedef struct _template_list_node *LtkListNode; +#define LTK_LIST_HEADER LtkListNode ltk_list_node_next; + +struct _template_list { + int size; + struct _template_list_node *start; + struct _template_list_node *end; +}; + +typedef struct _template_list *LtkList; +typedef struct _template_list_node *LtkListIterator; + +LtkList ltk_list_new(); +void ltk_list_nodepush(LtkList list,LtkListNode node); +LtkListNode ltk_list_get_start(LtkList list); +LtkListNode ltk_list_get_end(LtkList list); +void ltk_list_remove(LtkList list,LtkListNode node); +void ltk_list_pop_start(LtkList list); +void ltk_list_pop_end(LtkList list); + + +#define LTK_LIST_DECLARE(Type,Type_name) \ + static LtkList (* Type_name##_list_new)(void) = ltk_list_new;\ + void (* Type_name##_list_nodepush)(LtkList list, Type *node) = (void (*)(LtkList, Type *))ltk_list_nodepush; \ + Type * (* Type_name##_list_get_start)(LtkList list) = (Type *(*)(LtkList))ltk_list_get_start; \ + Type * (* Type_name##_list_get_end)(LtkList list) = (Type *(*)(LtkList))ltk_list_get_end; \ + void (* Type_name##_list_remove)(LtkList list, Type *node) = (void (*)(LtkList, Type *))ltk_list_remove; \ + void (* Type_name##_list_pop_start)(LtkList list) = (void (*)(LtkList))ltk_list_pop_start; \ + void (* Type_name##_list_pop_end)(LtkList list) = (void (*)(LtkList))ltk_list_pop_end; + +#define LTK_LIST_DECLARE_KEYACCESS(Type,Type_name,KeyType,key_member_name,key_function) \ + Type * Type_name##_list_key_lookup(LtkList list, KeyType key) { \ + LtkListIterator iter = ltk_list_iterator_new(list); \ + while(iter) { \ + if (key_function( ((Type *)iter)->key_member_name, key )) \ + return (Type *)iter; \ + iter = iter->next; } \ + return NULL; } \ + \ + void Type_name##_list_key_remove(LtkList list, KeyType key) { \ + LtkListNode node = (LtkListNode)Type_name##_list_key_lookup(list,key); \ + if(node) ltk_list_remove(list,node); } \ + + +LtkListIterator ltk_list_iterator_new(LtkList list); + +#endif // TEMPLATES_H diff --git a/src/ltk/test_comma.h b/src/ltk/test_comma.h new file mode 100644 index 0000000..2d69036 --- /dev/null +++ b/src/ltk/test_comma.h @@ -0,0 +1,117 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +/* + * File: test_comma.h + * Author: andrea + * + * Created on May 24, 2012, 4:47 PM + */ + +#ifndef TEST_COMMA_H +#define TEST_COMMA_H + +#include + +struct Vector3 +{ + union + { + struct { float x, y, z; }; + float data[3]; + }; + + struct CommaAssign; + + CommaAssign operator=(float _x) + { + x = _x; + return CommaAssign(this,1); + } + + struct CommaAssign + { + Vector3 *vec3; + int index; + + explicit CommaAssign(Vector3 *vec3, int index) : vec3(vec3) { + this->index = index; + } + CommaAssign operator, (float f) { + vec3->data[index] = f; + return CommaAssign(vec3, index + 1); + } + + }; + +}; + + + +struct Container +{ + union + { + struct { float x, y, z; }; + float data[3]; + }; + + inline float *getBuffer() { + return this->data; + } + + template class CommaAssign + { + private: + T *container; + int index; + + public: + inline explicit CommaAssign(T *container, float s) : container(container) { + this->index = 0; + this->container->getBuffer()[0] = s; + } + + inline CommaAssign& operator, (float s) { + this->index++; + assert(index < size); + this->container->getBuffer()[this->index] = s; + return *this; + } + }; + + CommaAssign operator=(float s) { + return CommaAssign (this, s); + } + +}; + + + + +#endif /* TEST_COMMA_H */ + diff --git a/src/ltk/testing/Makefile.am b/src/ltk/testing/Makefile.am new file mode 100644 index 0000000..1964340 --- /dev/null +++ b/src/ltk/testing/Makefile.am @@ -0,0 +1,37 @@ + +include $(top_srcdir)/Common.am + +#AM_DEFAULT_SOURCE_EXT = .cpp + + + +TESTS = LtkDebugTest \ + LtkFunctionToStringTest + +LDADD = ../../../libmutom-0.1.la +check_PROGRAMS = $(TESTS) + + +#################################################### +# Hybrid c/c++ Ltk Specific tests # +#################################################### + +check_PROGRAMS += Vector-test +Vector_test_SOURCES = Vector.c +TESTS += Vector-test + +check_PROGRAMS += Vector-test-cc +Vector_test_cc_SOURCES = Vector-cc.cpp +TESTS += Vector-test-cc + +check_PROGRAMS += Object-test +Object_test_SOURCES = Object.c +TESTS += Object-test + +check_PROGRAMS += Object-test-cc +Object_test_cc_SOURCES = Object-cc.cpp +TESTS += Object-test-cc + +#################################################### + +AM_COLOR_TESTS = always diff --git a/src/ltk/testing/Object-cc.cpp b/src/ltk/testing/Object-cc.cpp new file mode 100644 index 0000000..011af7f --- /dev/null +++ b/src/ltk/testing/Object-cc.cpp @@ -0,0 +1,40 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" +#include "../Object.h" + +using namespace ltk; + +int main() { + BEGIN_TESTING(Object - cc); + + Object ob; + TEST1( ob.GetElement() == 5552368 ); + + END_TESTING; +} diff --git a/src/ltk/testing/Object.c b/src/ltk/testing/Object.c new file mode 100644 index 0000000..9627bb9 --- /dev/null +++ b/src/ltk/testing/Object.c @@ -0,0 +1,11 @@ +#include "testing-prototype.h" +#include "../Object.h" + + +int main() { + BEGIN_TESTING(Object); + + struct _Object *ob = Object_new(ObjectClass); + + END_TESTING; +} diff --git a/src/ltk/testing/Vector-cc.cpp b/src/ltk/testing/Vector-cc.cpp new file mode 100644 index 0000000..d0d75fc --- /dev/null +++ b/src/ltk/testing/Vector-cc.cpp @@ -0,0 +1,79 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include "testing-prototype.h" +#include "../Vector.h" + +using namespace ltk; + +int main() { + BEGIN_TESTING(Vector - cc); + + typedef ltkVector ltkInt4; + + ltkInt4 v, w; + v = 1, 2, 3, 4; + w = v; + + printf("v -> %d,%d,%d,%d\n", v[0], *(v.getBuffer() + 1), v.at(2), v(3)); + + + // test assign operator + TEST1(v == w); + TEST0(v != w); + + // test accessors + TEST1(v[0] == 1); + TEST1(*(v.getBuffer() + 1) == 2); + TEST1(v.at(2) == 3); + TEST1(v(3) == 4); + + // setter + w << 1, 4, 9, 16; + TEST1(w[0] == 1); + TEST1(w[1] == 4); + TEST1(w[2] == 9); + TEST1(w[3] == 16); + + // math operators + v *= v; + w = 1, 4, 9, 16; + TEST1(v == w); + v /= v; + w = 1, 1, 1, 1; + TEST1(v == w); + v += v; + w = 2, 2, 2, 2; + TEST1(v == w); + + v << 1, 1, -1, 1; + w << -1, 1, 1, 1; + TEST0(v * w); + TEST0(v / w); + + END_TESTING; +} diff --git a/src/ltk/testing/Vector.c b/src/ltk/testing/Vector.c new file mode 100644 index 0000000..f7d1ab7 --- /dev/null +++ b/src/ltk/testing/Vector.c @@ -0,0 +1,14 @@ +#include +#include "testing-prototype.h" +#include "../Vector.h" + + +LTK_VECTOR_DECLARE (float, uFloat4, 4) + +int main() +{ + BEGIN_TESTING (Vector); + uFloat4 f = uFloat4_ltk_vector_new (); + + END_TESTING; +} diff --git a/src/ltk/testing/testing-prototype.h b/src/ltk/testing/testing-prototype.h new file mode 100644 index 0000000..39f4e6c --- /dev/null +++ b/src/ltk/testing/testing-prototype.h @@ -0,0 +1,37 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include + +#define BEGIN_TESTING(name) \ +static int _fail = 0; \ +printf("..:: Testing " #name " ::..\n"); + +#define TEST1(val) _fail += (val)==0 +#define TEST0(val) _fail += (val)!=0 +#define END_TESTING return _fail; + diff --git a/src/utils/copyrights/cr_update.py b/src/utils/copyrights/cr_update.py new file mode 100644 index 0000000..8fe6342 --- /dev/null +++ b/src/utils/copyrights/cr_update.py @@ -0,0 +1,45 @@ +# updates the copyright information for all .cs files +# usage: call recursive_traversal, with the following parameters +# parent directory, old copyright text content, new copyright text content + +import os + +excludedir = ["..\\Lib"] + +def update_source(filename, oldcopyright, copyright): + utfstr = chr(0xef)+chr(0xbb)+chr(0xbf) + fdata = file(filename,"r+").read() + isUTF = False + if (fdata.startswith(utfstr)): + isUTF = True + fdata = fdata[3:] + if (oldcopyright != None): + if (fdata.startswith(oldcopyright)): + fdata = fdata[len(oldcopyright):] + if not (fdata.startswith(copyright)): + print "updating "+filename + fdata = copyright + fdata + if (isUTF): + file(filename,"w").write(utfstr+fdata) + else: + file(filename,"w").write(fdata) + +def recursive_traversal(dir, oldcopyright, copyright): + global excludedir + fns = os.listdir(dir) + print "listing "+dir + for fn in fns: + fullfn = os.path.join(dir,fn) + if (fullfn in excludedir): + continue + if (os.path.isdir(fullfn)): + recursive_traversal(fullfn, oldcopyright, copyright) + else: + if ( fullfn.endswith(".cpp") or fullfn.endswith(".h") or fullfn.endswith(".hpp") or fullfn.endswith(".C") or fullfn.endswith(".cxx") ): + update_source(fullfn, oldcopyright, copyright) + + +oldcright = file("oldcr.txt","r+").read() +cright = file("newcr.txt","r+").read() +recursive_traversal("../../", oldcright, cright) +exit() diff --git a/src/utils/copyrights/newcr.txt b/src/utils/copyrights/newcr.txt new file mode 100644 index 0000000..3ed7526 --- /dev/null +++ b/src/utils/copyrights/newcr.txt @@ -0,0 +1,27 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + diff --git a/src/utils/copyrights/oldcr.txt b/src/utils/copyrights/oldcr.txt new file mode 100644 index 0000000..f781efb --- /dev/null +++ b/src/utils/copyrights/oldcr.txt @@ -0,0 +1,24 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ diff --git a/src/utils/make_recipe/CMakeLists.txt b/src/utils/make_recipe/CMakeLists.txt new file mode 100644 index 0000000..66cc8d9 --- /dev/null +++ b/src/utils/make_recipe/CMakeLists.txt @@ -0,0 +1,37 @@ +set(HEADERS +) + +SET(SOURCES +) + + +## Build target tar file ## +set(CMAKE_TAR_FILE "recipe.tar.gz") +add_custom_command(OUTPUT recipe_tar_data.o + COMMAND tar -zcvf ${CMAKE_TAR_FILE} -C "${CMAKE_CURRENT_SOURCE_DIR}/src" CMakeLists.txt main.cpp -C ${PROJECT_SOURCE_DIR} CMakeConfig.in.h + ## -C ${PROJECT_SOURCE_DIR} CMake + COMMAND objcopy --input binary --output elf64-x86-64 --binary-architecture i386 ${CMAKE_TAR_FILE} ${CMAKE_CURRENT_BINARY_DIR}/recipe_tar_data.o +) + +add_library(recipe_tar_data STATIC recipe_tar_data.o) +set_source_files_properties(recipe_tar_data.o PROPERTIES EXTERNAL_OBJECT true GENERATED true) +set_target_properties(recipe_tar_data PROPERTIES LINKER_LANGUAGE C) + + +set(CMAKE_TAR_FILE "cmake.tar.gz") +add_custom_command(OUTPUT cmake_tar_data.o + COMMAND tar -zcvf ${CMAKE_TAR_FILE} -C ${PROJECT_SOURCE_DIR} CMake "--exclude=CMake/.svn" + COMMAND objcopy --input binary --output elf64-x86-64 --binary-architecture i386 ${CMAKE_TAR_FILE} ${CMAKE_CURRENT_BINARY_DIR}/cmake_tar_data.o +) + +add_library(cmake_tar_data STATIC cmake_tar_data.o) +set_source_files_properties(cmake_tar_data.o PROPERTIES EXTERNAL_OBJECT true GENERATED true) +set_target_properties(cmake_tar_data PROPERTIES LINKER_LANGUAGE C) + + + +uLib_add_target(uLib_config main.cpp) +target_link_libraries(uLib_config cmake_tar_data) +target_link_libraries(uLib_config recipe_tar_data) +target_link_libraries(uLib_config ${PACKAGE_LIBPREFIX}Core) + diff --git a/src/utils/make_recipe/main.cpp b/src/utils/make_recipe/main.cpp new file mode 100644 index 0000000..d4734ff --- /dev/null +++ b/src/utils/make_recipe/main.cpp @@ -0,0 +1,137 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include +#include +#include +#include + +#include "Core/Options.h" + + +using namespace uLib; + +extern "C" { +extern char _binary_recipe_tar_gz_start; +extern char _binary_recipe_tar_gz_end; +extern char _binary_cmake_tar_gz_start; +extern char _binary_cmake_tar_gz_end; +} + + +namespace { +static struct Parameters : Options +{ + std::string project; + Parameters(const char *hello = "Program options") : Options(hello) { + add_options() + ("help,h", "printout help") + // GENERAL // + ("project,p", &project, std::string(), "name of project") + ("cmake,k", "cmake recipe project") + ("cmake-modules,K", "only builds cmake modules directory") + ("libs", "get mutom linker flags") + ("cflags", "get compiler flags") + ; + } +} p; +} // namespace + + +static std::string system_pipe(std::string cmd) { + FILE *pipe = popen(cmd.c_str(),"r"); + if(pipe) { + std::stringstream ss; + int c = fgetc (pipe); + while (c != EOF) { + if(c != '\n') ss << (char)c; + c = fgetc (pipe); + } + return ss.str(); + } + else return std::string(""); +} + + + + + +int main(int argc, char *argv[]) +{ + p.parse_command_line(argc,argv); + + if(p.project != "") { + char dir[300]; + sprintf(dir,"mkdir %s",p.project.c_str()); + system(dir); + chdir(p.project.c_str()); + } + + if(p.count("cmake") || p.count("cmake-modules")) { + std::ofstream file; + file.open("_cmake.tar.gz", std::ios::out | std::ios::binary ); + char* ptr = &_binary_cmake_tar_gz_start; + while ( ptr != &_binary_cmake_tar_gz_end ) + file << *ptr++; + file.close(); + + std::cout << "Deploing CMake files .... \n"; + system("tar -zxvf _cmake.tar.gz"); + system("rm _cmake.tar.gz"); + std::cout << "done ... \n"; + } + + if(p.count("cmake")) { + std::ofstream file; + file.open("_recipe.tar.gz", std::ios::out | std::ios::binary ); + char* ptr = &_binary_recipe_tar_gz_start; + while ( ptr != &_binary_recipe_tar_gz_end ) + file << *ptr++; + file.close(); + + std::cout << "Deploing recipe files .... \n"; + system("tar -zxvf _recipe.tar.gz"); + system("rm _recipe.tar.gz"); + std::cout << "done ... \n"; + } + + if(p.count("cflags")) { + std::cout + << system_pipe("cmake --find-package -DCMAKE_PREFIX_PATH=/usr/local/lib/cmake/mutom-0.2 -DNAME=uLib -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=COMPILE") + << system_pipe("cmake --find-package -DCMAKE_PREFIX_PATH=/usr/local/lib/cmake/mutom-0.2 -DNAME=IB -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=COMPILE"); + } + + if(p.count("libs")) { + std::cout + << system_pipe("cmake --find-package -DCMAKE_PREFIX_PATH=/usr/local/lib/cmake/mutom-0.2 -DNAME=uLib -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=LINK") + << system_pipe("cmake --find-package -DCMAKE_PREFIX_PATH=/usr/local/lib/cmake/mutom-0.2 -DNAME=IB -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=LINK"); + } + + return 0; +} + diff --git a/src/utils/make_recipe/src/CMake b/src/utils/make_recipe/src/CMake new file mode 120000 index 0000000..5b0f7e9 --- /dev/null +++ b/src/utils/make_recipe/src/CMake @@ -0,0 +1 @@ +../../../../CMake \ No newline at end of file diff --git a/src/utils/make_recipe/src/CMakeLists.txt b/src/utils/make_recipe/src/CMakeLists.txt new file mode 100644 index 0000000..05e35c0 --- /dev/null +++ b/src/utils/make_recipe/src/CMakeLists.txt @@ -0,0 +1,104 @@ +################################################################################ +################################################################################ +################################################################################ + +cmake_minimum_required(VERSION 2.6) +project(hello_world) +set(SOURCES + # put your sources here + main.cpp +) + +set(DICTIONARY_HEADERS + # put dictionary headers here +) + +################################################################################ +################################################################################ +################################################################################ +################################################################################ +################################################################################ + + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake") +include(uLibDebugMacro) +include(uLibCommon) +include(uLibFindDependencies) +include(uLibConfigHeader) +include(uLibGenerateRMake) + + +## MUDULE FIND PACKAGE ------------------------------------------------------ ## +#find_package(uLib REQUIRED) # not working at the moment + +## CONFIG FIND PACKAGE ------------------------------------------------------ ## +#set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake") +unset(ULIB_CONFIG) +find_package(ULIB 0.2 CONFIG + NAMES uLib + PATH_SUFFIXES mutom-0.2 +) +if(ULIB_CONFIG) + set(ULIB_FOUND true) +endif() + +unset(IB_CONFIG) +find_package(IB 0.2 CONFIG + PATH_SUFFIXES mutom-0.2 +) +if(IB_CONFIG) + set(IB_FOUND true) +endif() + + +## PROJECT EXECUTABLE ------------------------------------------------------- ## +add_executable(${PROJECT_NAME} ${SOURCES}) + +if(ULIB_FOUND) + include_directories(${ULIB_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME} + ############################################################################ + ## ULIB MODULES ## + mutomCore + mutomMath + mutomDetectors + # mutomVtk + ############################################################################ + + ############################################################################ + # MANUAL INLCLUDE EXTERNAL DEPENDENCIES + # ${Boost_SERIALIZATION_LIBRARY} + # ${Boost_SIGNALS_LIBRARY} + # ${Boost_PROGRAM_OPTIONS_LIBRARY} + # ${Geant4_LIBRARIES} + # ${ROOT_LIBRARIES} + # ${VTK_LIBRARIES} # all VTK libs + ############################################################################ +) +endif(ULIB_FOUND) + +if(IB_FOUND) + include_directories(${IB_INCLUDE_DIRS}) + target_link_libraries(${PROJECT_NAME} mutomIB ) +endif() + + +## ROOT DICTIONARY COMPILE -------------------------------------------------- ## +if(ROOT_FOUND AND DICTIONARY_HEADERS) +include(FindROOTv6) +message("----------- Building Root Dictionary ----------") +debug(DICTIONARY_HEADERS) +debug(ROOT_CINT_EXECUTABLE) +add_library(dictionary STATIC RootDict.cxx) +add_custom_command(OUTPUT RootDict.cxx RootDict.h + COMMAND ${ROOT_CINT_EXECUTABLE} -f RootDict.cxx -c -p ${DICTIONARY_HEADERS} Linkdef.h +) +#root_generate_dictionary(RootDict ${DICTIONARY_HEADERS} LINKDEF Linkdef.h) +set_source_files_properties(RootDict.cxx PROPERTIES GENERATED TRUE) +set_source_files_properties(RootDict.h PROPERTIES GENERATED TRUE) +target_link_libraries(${PROJECT_NAME} dictionary) +endif(ROOT_FOUND AND DICTIONARY_HEADERS) + + + + diff --git a/src/utils/make_recipe/src/main.cpp b/src/utils/make_recipe/src/main.cpp new file mode 100644 index 0000000..40c09ba --- /dev/null +++ b/src/utils/make_recipe/src/main.cpp @@ -0,0 +1,36 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#include +#include + + +int main(int argc, char **argv) +{ + std::cout << "hello uLib user\n"; + return 0; +} diff --git a/src/utils/moc/Makefile b/src/utils/moc/Makefile new file mode 100644 index 0000000..d42bd6d --- /dev/null +++ b/src/utils/moc/Makefile @@ -0,0 +1,24 @@ + + +# Makefile example -- scanner and parser. +# +CXX = g++ -D_DEBUG +LEX = flex +YACC = bison -y -t +YFLAGS = -d +objects = parse.o scan.o + +moc: $(objects) + $(CXX) -o $@ $(objects) -lfl + +parse.o: parse.y + +# parse.h: parse.c +# mv -f y.tab.h parse.h + +scan.o: scan.l + + +clean: + rm -f *.o parse.tab.c parse.tab.h + diff --git a/src/utils/moc/moc_actions.h b/src/utils/moc/moc_actions.h new file mode 100644 index 0000000..db6e97e --- /dev/null +++ b/src/utils/moc/moc_actions.h @@ -0,0 +1,92 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + +#ifndef MOC_ACTION_H +#define MOC_ACTION_H + +#include +#include +#include +#include + +#ifndef NDEBUG +#define DEBUG( ... ) { printf(" /*["); printf( __VA_ARGS__ ); printf("]*/ "); } +#else +#define DEBUG( ... ) ; +#endif + +#define CONCAT( dest , ... ) string_append(dest, __VA_ARGS__, NULL) + +char * string_append(char *first, ... ) { + va_list ap; + va_start (ap, first); /* Initialize the argument list. */ + + char *str_in = first; + char *str = malloc(sizeof(char) * strlen(str_in)); + strcat(str,str_in); + + str_in = va_arg (ap,char *); + while (str_in) { + char *tmp = malloc(sizeof(char) * (strlen(str)+strlen(str_in)) ); + memcpy(tmp,str,strlen(str)); + memcpy(tmp+strlen(str),str_in,strlen(str_in)); + free(str); + str = tmp; + str_in = va_arg (ap,char *); + } + return str; +} + + + + + + +// ACTIONS // + + + +#define SIMPLE_DECLARATION simple_declaration_action + +static int simple_declaration_action(const char *type, const char *ids); + + + + + + +// move to implementation .. // +static int simple_declaration_action(const char *type, const char *ids) { + DEBUG("simple_declaration -> type:\"%s\" decl:\"%s\" ",type,ids); + return 0; +} + + + + + +#endif // MOC_ACTION_H diff --git a/src/utils/moc/parse.y b/src/utils/moc/parse.y new file mode 100644 index 0000000..ba06996 --- /dev/null +++ b/src/utils/moc/parse.y @@ -0,0 +1,1257 @@ +%{ + +#include +#include +#include "moc_actions.h" + +#define EMPTY strdup(""); +#define YYDEBUG 1 +#define YYPRINT(file, type, value) yyprint (file, type, value) + +%} + +// Symbols. // +%union +{ + char *sval; +}; + +%token MOC_PROPERTY MOC_OBJECT_PARAMETERS +%type MOC_monk_seq_opt MOC_monk + + + +%token IDENTIFIER +%token INTEGER FLOATING CHARACTER STRING +%token TYPEDEF_NAME NAMESPACE_NAME CLASS_NAME ENUM_NAME TEMPLATE_NAME + +%token COLONCOLON +%token ELLIPSIS DOTSTAR ADDEQ SUBEQ MULEQ DIVEQ MODEQ +%token XOREQ ANDEQ OREQ SL SR SREQ SLEQ EQ NOTEQ LTEQ GTEQ ANDAND OROR +%token PLUSPLUS MINUSMINUS ARROWSTAR ARROW + + +%token ASM AUTO BOOL BREAK CASE CATCH CHAR CLASS CONST CONST_CAST CONTINUE +%token DEFAULT DELETE DO DOUBLE DYNAMIC_CAST ELSE ENUM EXPLICIT EXPORT EXTERN +%token FALSE FLOAT FOR FRIEND GOTO IF INLINE INT LONG MUTABLE NAMESPACE NEW +%token OPERATOR PRIVATE PROTECTED PUBLIC REGISTER REINTERPRET_CAST RETURN +%token SHORT SIGNED SIZEOF STATIC STATIC_CAST STRUCT SWITCH TEMPLATE THIS +%token THROW TRUE TRY TYPEDEF TYPEID TYPENAME UNION UNSIGNED USING VIRTUAL +%token VOID VOLATILE WCHAR_T WHILE + + + + +%type type_name class_name enum_name typedef_name + +%type simple_type_specifier +%type decl_specifier_seq decl_specifier +%type simple_declaration block_declaration + +%type init_declarator_list init_declarator +%type initializer initializer_clause +%type declarator direct_declarator ptr_operator declarator_id +%type type_specifier type_specifier_seq elaborated_type_specifier class_key nested_name_specifier template_argument_list +%type enum_specifier enumerator_list enumerator_definition enumerator +%type class_or_namespace_name +%type identifier +%type id_expression +%type constant_expression + + +%type declaration_seq_opt +%type TEMPLATE_opt +%type nested_name_specifier_opt +%type expression_list_opt +%type COLONCOLON_opt +%type new_placement_opt +%type new_initializer_opt +%type new_declarator_opt +%type expression_opt +%type statement_seq_opt +%type condition_opt +%type decl_specifier_seq_opt +%type init_declarator_list_opt +%type identifier_opt +%type enumerator_list_opt +%type TYPENAME_opt +%type initializer_opt +%type cv_qualifier_seq_opt +%type exception_specification_opt +%type constant_expression_opt +%type abstract_declarator_opt +%type type_specifier_seq_opt +%type direct_abstract_declarator_opt +%type parameter_declaration_list_opt +%type ELLIPSIS_opt +%type ctor_initializer_opt +%type COMMA_opt +%type member_specification_opt +%type base_clause_opt +%type member_declarator_list_opt +%type SEMICOLON_opt +%type pure_specifier_opt +%type constant_initializer_opt +%type access_specifier_opt +%type VIRTUAL_opt +%type conversion_declarator_opt +%type EXPORT_opt +%type handler_seq_opt +%type assignment_expression_opt +%type type_id_list_opt + + +%error-verbose +//%debug +%% + +MOC_block_seq_opt + : /* empty */ + | MOC_block_seq_opt MOC_uLib_Parameters + | MOC_block_seq_opt MOC_Property + ; + +MOC_Property: + MOC_PROPERTY '(' IDENTIFIER ')' '{' { DEBUG("found property: %s",$3); } + MOC_prop_content_opt + '}' { DEBUG("property ends"); } + ; + +MOC_uLib_Parameters: + MOC_OBJECT_PARAMETERS '(' IDENTIFIER ')' '{' { DEBUG("found parameters: %s",$3); } + MOC_prop_content_opt + '}' { DEBUG("parameters ends"); } + ; + +MOC_prop_content_opt + : + | translation_unit + ; + + +MOC_monk_seq_opt + : { $$ = EMPTY; } + | MOC_monk_seq_opt MOC_monk { $$ = CONCAT($1,$2); } + ; + +MOC_monk + : INT IDENTIFIER ';' { $$ = CONCAT("type:",$1," ","id:",$2," "); } + | CHAR IDENTIFIER ';' { $$ = CONCAT("type:",$1," ","id:",$2," "); } + | decl_specifier_seq_opt decl_specifier_seq_opt ';' { $$ = CONCAT("type:",$1," ","id:",$2," "); } + ; + +/*---------------------------------------------------------------------- + * Lexical elements. + *----------------------------------------------------------------------*/ + +identifier: + IDENTIFIER + ; + +literal: + integer_literal + | character_literal + | floating_literal + | string_literal + | boolean_literal + ; + +integer_literal: + INTEGER + ; + +character_literal: + CHARACTER + ; + +floating_literal: + FLOATING + ; + +string_literal: + STRING + ; + +boolean_literal: + TRUE + | FALSE + ; + +/*---------------------------------------------------------------------- + * Translation unit. + *----------------------------------------------------------------------*/ + +translation_unit: + declaration_seq_opt { DEBUG("t unit"); } + ; + +/*---------------------------------------------------------------------- + * Expressions. + *----------------------------------------------------------------------*/ + +primary_expression: + literal + | THIS + | COLONCOLON identifier + | COLONCOLON operator_function_id + | COLONCOLON qualified_id + | '(' expression ')' + | id_expression + ; + +id_expression: + unqualified_id + | qualified_id + ; + +unqualified_id: + identifier + | operator_function_id + | conversion_function_id + | '~' class_name + | template_id + ; + +qualified_id: + nested_name_specifier TEMPLATE_opt unqualified_id + ; + +nested_name_specifier: + class_or_namespace_name COLONCOLON nested_name_specifier_opt + ; + +class_or_namespace_name: + class_name + | namespace_name + ; + +postfix_expression: + primary_expression + | postfix_expression '[' expression ']' + | postfix_expression '(' expression_list_opt ')' + | simple_type_specifier '(' expression_list_opt ')' + | postfix_expression '.' TEMPLATE_opt COLONCOLON_opt id_expression + | postfix_expression ARROW TEMPLATE_opt COLONCOLON_opt id_expression + | postfix_expression '.' pseudo_destructor_name + | postfix_expression ARROW pseudo_destructor_name + | postfix_expression PLUSPLUS + | postfix_expression MINUSMINUS + | DYNAMIC_CAST '<' type_id '>' '(' expression ')' + | STATIC_CAST '<' type_id '>' '(' expression ')' + | REINTERPRET_CAST '<' type_id '>' '(' expression ')' + | CONST_CAST '<' type_id '>' '(' expression ')' + | TYPEID '(' expression ')' + | TYPEID '(' type_id ')' + ; + +expression_list: + assignment_expression + | expression_list ',' assignment_expression + ; + +pseudo_destructor_name: + COLONCOLON_opt nested_name_specifier_opt type_name COLONCOLON '~' type_name + | COLONCOLON_opt nested_name_specifier_opt '~' type_name + ; + +unary_expression: + postfix_expression + | PLUSPLUS cast_expression + | MINUSMINUS cast_expression + | unary_operator cast_expression + | SIZEOF unary_expression + | SIZEOF '(' type_id ')' + | new_expression + | delete_expression + ; + +unary_operator: + '*' + | '&' + | '+' + | '-' + | '!' + | '~' + ; + +new_expression: + COLONCOLON_opt NEW new_placement_opt new_type_id new_initializer_opt + | COLONCOLON_opt NEW new_placement_opt '(' type_id ')' new_initializer_opt + ; + +new_placement: + '(' expression_list ')' + ; + +new_type_id: + type_specifier_seq new_declarator_opt + ; + +new_declarator: + ptr_operator new_declarator_opt + | direct_new_declarator + ; + +direct_new_declarator: + '[' expression ']' + | direct_new_declarator '[' constant_expression ']' + ; + +new_initializer: + '(' expression_list_opt ')' + ; + +delete_expression: + COLONCOLON_opt DELETE cast_expression + | COLONCOLON_opt DELETE '[' ']' cast_expression + ; + +cast_expression: + unary_expression + | '(' type_id ')' cast_expression + ; + +pm_expression: + cast_expression + | pm_expression DOTSTAR cast_expression + | pm_expression ARROWSTAR cast_expression + ; + +multiplicative_expression: + pm_expression + | multiplicative_expression '*' pm_expression + | multiplicative_expression '/' pm_expression + | multiplicative_expression '%' pm_expression + ; + +additive_expression: + multiplicative_expression + | additive_expression '+' multiplicative_expression + | additive_expression '-' multiplicative_expression + ; + +shift_expression: + additive_expression + | shift_expression SL additive_expression + | shift_expression SR additive_expression + ; + +relational_expression: + shift_expression + | relational_expression '<' shift_expression + | relational_expression '>' shift_expression + | relational_expression LTEQ shift_expression + | relational_expression GTEQ shift_expression + ; + +equality_expression: + relational_expression + | equality_expression EQ relational_expression + | equality_expression NOTEQ relational_expression + ; + +and_expression: + equality_expression + | and_expression '&' equality_expression + ; + +exclusive_or_expression: + and_expression + | exclusive_or_expression '^' and_expression + ; + +inclusive_or_expression: + exclusive_or_expression + | inclusive_or_expression '|' exclusive_or_expression + ; + +logical_and_expression: + inclusive_or_expression + | logical_and_expression ANDAND inclusive_or_expression + ; + +logical_or_expression: + logical_and_expression + | logical_or_expression OROR logical_and_expression + ; + +conditional_expression: + logical_or_expression + | logical_or_expression '?' expression ':' assignment_expression + ; + +assignment_expression: + conditional_expression + | logical_or_expression assignment_operator assignment_expression + | throw_expression + ; + +assignment_operator: + '=' + | MULEQ + | DIVEQ + | MODEQ + | ADDEQ + | SUBEQ + | SREQ + | SLEQ + | ANDEQ + | XOREQ + | OREQ + ; + +expression: + assignment_expression + | expression ',' assignment_expression + ; + +constant_expression: + conditional_expression + ; + +/*---------------------------------------------------------------------- + * Statements. + *----------------------------------------------------------------------*/ + +statement: + labeled_statement + | expression_statement + | compound_statement + | selection_statement + | iteration_statement + | jump_statement + | declaration_statement + | try_block + ; + +labeled_statement: + identifier ':' statement + | CASE constant_expression ':' statement + | DEFAULT ':' statement + ; + +expression_statement: + expression_opt ';' + ; + +compound_statement: + '{' statement_seq_opt '}' + ; + +statement_seq: + statement + | statement_seq statement + ; + +selection_statement: + IF '(' condition ')' statement + | IF '(' condition ')' statement ELSE statement + | SWITCH '(' condition ')' statement + ; + +condition: + expression + | type_specifier_seq declarator '=' assignment_expression + ; + +iteration_statement: + WHILE '(' condition ')' statement + | DO statement WHILE '(' expression ')' ';' + | FOR '(' for_init_statement condition_opt ';' expression_opt ')' statement + ; + +for_init_statement: + expression_statement + | simple_declaration + ; + +jump_statement: + BREAK ';' + | CONTINUE ';' + | RETURN expression_opt ';' + | GOTO identifier ';' + ; + +declaration_statement: + block_declaration + ; + +/*---------------------------------------------------------------------- + * Declarations. + *----------------------------------------------------------------------*/ + +declaration_seq: + declaration + | declaration_seq declaration + ; + +declaration: + block_declaration + | function_definition + | template_declaration + | explicit_instantiation + | explicit_specialization + | linkage_specification + | namespace_definition + ; + +block_declaration: + simple_declaration + | asm_definition + | namespace_alias_definition + | using_declaration + | using_directive + ; + +simple_declaration: + decl_specifier_seq_opt init_declarator_list_opt ';' { SIMPLE_DECLARATION($1,$2); } + ; + +decl_specifier: + storage_class_specifier + | type_specifier + | function_specifier + | FRIEND + | TYPEDEF + ; + +decl_specifier_seq: + decl_specifier_seq_opt decl_specifier { $$ = CONCAT($1,$2); } + ; + +storage_class_specifier: + AUTO + | REGISTER + | STATIC + | EXTERN + | MUTABLE + ; + +function_specifier: + INLINE + | VIRTUAL + | EXPLICIT + ; + +typedef_name: + identifier + ; + +type_specifier: + simple_type_specifier + | class_specifier + | enum_specifier + | elaborated_type_specifier + | cv_qualifier + ; + +simple_type_specifier: + COLONCOLON_opt /*nested_name_specifier_opt*/ type_name { $$ = CONCAT($1,$2); } /*<<<<< FIX DISAMBIGUATION <<<<<<*/ + | CHAR + | WCHAR_T + | BOOL + | SHORT + | INT + | LONG + | SIGNED + | UNSIGNED + | FLOAT + | DOUBLE + | VOID + ; + +type_name: + class_name + | enum_name + | typedef_name + ; + +elaborated_type_specifier: + class_key COLONCOLON_opt nested_name_specifier_opt identifier { $$ = CONCAT($1,$2,$3,$4); } + | ENUM COLONCOLON_opt nested_name_specifier_opt identifier { $$ = CONCAT($1,$2,$3,$4); } + | TYPENAME COLONCOLON_opt nested_name_specifier identifier { $$ = CONCAT($1,$2,$3,$4); } + | TYPENAME COLONCOLON_opt nested_name_specifier identifier '<' template_argument_list '>' { $$ = CONCAT($1,$2,$3,$4,"<",$6,">"); } + ; + +enum_name: + identifier + ; + +enum_specifier: + ENUM identifier_opt '{' enumerator_list_opt '}' { $$ = CONCAT($1,$2,"{",$4,"}"); } + ; + +enumerator_list: + enumerator_definition + | enumerator_list ',' enumerator_definition { $$ = CONCAT($1,",",$3); } + ; + +enumerator_definition: + enumerator + | enumerator '=' constant_expression { $$ = CONCAT($1,"=",$3); } + ; + +enumerator: + identifier + ; + +namespace_name: + original_namespace_name + | namespace_alias + ; + +original_namespace_name: + identifier + ; + +namespace_definition: + named_namespace_definition + | unnamed_namespace_definition + ; + +named_namespace_definition: + original_namespace_definition + | extension_namespace_definition + ; + +original_namespace_definition: + NAMESPACE identifier '{' namespace_body '}' + ; + +extension_namespace_definition: + NAMESPACE original_namespace_name '{' namespace_body '}' + ; + +unnamed_namespace_definition: + NAMESPACE '{' namespace_body '}' + ; + +namespace_body: + declaration_seq_opt + ; + +namespace_alias: + identifier + ; + +namespace_alias_definition: + NAMESPACE identifier '=' qualified_namespace_specifier ';' + ; + +qualified_namespace_specifier: + COLONCOLON_opt nested_name_specifier_opt namespace_name + ; + +using_declaration: + USING TYPENAME_opt COLONCOLON_opt nested_name_specifier unqualified_id ';' + | USING COLONCOLON unqualified_id ';' + ; + +using_directive: + USING NAMESPACE COLONCOLON_opt nested_name_specifier_opt namespace_name ';' + ; + +asm_definition: + ASM '(' string_literal ')' ';' + ; + +linkage_specification: + EXTERN string_literal '{' declaration_seq_opt '}' + | EXTERN string_literal declaration + ; + +/*---------------------------------------------------------------------- + * Declarators. + *----------------------------------------------------------------------*/ + +init_declarator_list: + init_declarator + | init_declarator_list ',' init_declarator { $$ = CONCAT($1,",",$3); } + ; + +init_declarator: + declarator initializer_opt { $$ = CONCAT($1,$2); } + ; + +declarator: + direct_declarator + | ptr_operator declarator { $$ = CONCAT($1,$2); } + ; + +direct_declarator: + declarator_id + | direct_declarator '('parameter_declaration_clause ')' cv_qualifier_seq_opt exception_specification_opt + | direct_declarator '[' constant_expression_opt ']' { $$ = CONCAT($1,"[",$3,"]"); } + | '(' declarator ')' { $$ = CONCAT("(",$2,")"); } + ; + +ptr_operator: + '*' cv_qualifier_seq_opt { $$ = CONCAT("*",$2); } + | '&' { $$ = strdup("&"); } + | COLONCOLON_opt nested_name_specifier '*' cv_qualifier_seq_opt { $$ = CONCAT($1,$2,"*",$4); } + ; + +cv_qualifier_seq: + cv_qualifier cv_qualifier_seq_opt + ; + +cv_qualifier: + CONST + | VOLATILE + ; + +declarator_id: + COLONCOLON_opt id_expression { $$ = CONCAT($1,$2); } + | COLONCOLON_opt nested_name_specifier_opt type_name { $$ = CONCAT($1,$2,$3); } + ; + +type_id: + type_specifier_seq abstract_declarator_opt /*{ $$ = CONCAT($1,$2); }*/ + ; + +type_specifier_seq: + type_specifier type_specifier_seq_opt { $$ = CONCAT($1,$2); } + ; + +abstract_declarator: + ptr_operator abstract_declarator_opt /*{ $$ = CONCAT($1,$2); }*/ + | direct_abstract_declarator + ; + +direct_abstract_declarator: + direct_abstract_declarator_opt '(' parameter_declaration_clause ')' cv_qualifier_seq_opt exception_specification_opt + | direct_abstract_declarator_opt '[' constant_expression_opt ']' + | '(' abstract_declarator ')' + ; + +parameter_declaration_clause: + parameter_declaration_list_opt ELLIPSIS_opt + | parameter_declaration_list ',' ELLIPSIS + ; + +parameter_declaration_list: + parameter_declaration + | parameter_declaration_list ',' parameter_declaration + ; + +parameter_declaration: + decl_specifier_seq declarator + | decl_specifier_seq declarator '=' assignment_expression + | decl_specifier_seq abstract_declarator_opt + | decl_specifier_seq abstract_declarator_opt '=' assignment_expression + ; + +function_definition: + decl_specifier_seq_opt declarator ctor_initializer_opt function_body + | decl_specifier_seq_opt declarator function_try_block + ; + +function_body: + compound_statement + ; + +initializer: + '=' initializer_clause { $$ = strdup($2); } + | '(' expression_list ')' + ; + +initializer_clause: + assignment_expression + | '{' initializer_list COMMA_opt '}' + | '{' '}' + ; + +initializer_list: + initializer_clause + | initializer_list ',' initializer_clause + ; + +/*---------------------------------------------------------------------- + * Classes. + *----------------------------------------------------------------------*/ + +class_name: + identifier + | template_id + ; + +class_specifier: + class_head '{' member_specification_opt '}' + ; + +class_head: + class_key identifier_opt base_clause_opt + | class_key nested_name_specifier identifier base_clause_opt + ; + +class_key: + CLASS + | STRUCT + | UNION + ; + +member_specification: + member_declaration member_specification_opt + | access_specifier ':' member_specification_opt + ; + +member_declaration: + decl_specifier_seq_opt member_declarator_list_opt ';' + | function_definition SEMICOLON_opt + | qualified_id ';' + | using_declaration + | template_declaration + ; + +member_declarator_list: + member_declarator + | member_declarator_list ',' member_declarator + ; + +member_declarator: + declarator pure_specifier_opt + | declarator constant_initializer_opt + | identifier_opt ':' constant_expression + ; + +pure_specifier: + '=' '0' + ; + +constant_initializer: + '=' constant_expression + ; + +/*---------------------------------------------------------------------- + * Derived classes. + *----------------------------------------------------------------------*/ + +base_clause: + ':' base_specifier_list + ; + +base_specifier_list: + base_specifier + | base_specifier_list ',' base_specifier + ; + +base_specifier: + COLONCOLON_opt nested_name_specifier_opt class_name + | VIRTUAL access_specifier_opt COLONCOLON_opt nested_name_specifier_opt class_name + | access_specifier VIRTUAL_opt COLONCOLON_opt nested_name_specifier_opt class_name + ; + +access_specifier: + PRIVATE + | PROTECTED + | PUBLIC + ; + +/*---------------------------------------------------------------------- + * Special member functions. + *----------------------------------------------------------------------*/ + +conversion_function_id: + OPERATOR conversion_type_id + ; + +conversion_type_id: + type_specifier_seq conversion_declarator_opt + ; + +conversion_declarator: + ptr_operator conversion_declarator_opt + ; + +ctor_initializer: + ':' mem_initializer_list + ; + +mem_initializer_list: + mem_initializer + | mem_initializer ',' mem_initializer_list + ; + +mem_initializer: + mem_initializer_id '(' expression_list_opt ')' + ; + +mem_initializer_id: + COLONCOLON_opt nested_name_specifier_opt class_name + | identifier + ; + +/*---------------------------------------------------------------------- + * Overloading. + *----------------------------------------------------------------------*/ + +operator_function_id: + OPERATOR operator + ; + +operator: + NEW + | DELETE + | NEW '[' ']' + | DELETE '[' ']' + | '+' + | '_' + | '*' + | '/' + | '%' + | '^' + | '&' + | '|' + | '~' + | '!' + | '=' + | '<' + | '>' + | ADDEQ + | SUBEQ + | MULEQ + | DIVEQ + | MODEQ + | XOREQ + | ANDEQ + | OREQ + | SL + | SR + | SREQ + | SLEQ + | EQ + | NOTEQ + | LTEQ + | GTEQ + | ANDAND + | OROR + | PLUSPLUS + | MINUSMINUS + | ',' + | ARROWSTAR + | ARROW + | '(' ')' + | '[' ']' + ; + +/*---------------------------------------------------------------------- + * Templates. + *----------------------------------------------------------------------*/ + +template_declaration: + EXPORT_opt TEMPLATE '<' template_parameter_list '>' declaration + ; + +template_parameter_list: + template_parameter + | template_parameter_list ',' template_parameter + ; + +template_parameter: + type_parameter + | parameter_declaration + ; + +type_parameter: + CLASS identifier_opt + | CLASS identifier_opt '=' type_id + | TYPENAME identifier_opt + | TYPENAME identifier_opt '=' type_id + | TEMPLATE '<' template_parameter_list '>' CLASS identifier_opt + | TEMPLATE '<' template_parameter_list '>' CLASS identifier_opt '=' template_name + ; + +template_id: + template_name '<' template_argument_list '>' + ; + +template_name: + identifier + ; + +template_argument_list: + template_argument + | template_argument_list ',' template_argument + ; + +template_argument: + assignment_expression + | type_id + | template_name + ; + +explicit_instantiation: + TEMPLATE declaration + ; + +explicit_specialization: + TEMPLATE '<' '>' declaration + ; + +/*---------------------------------------------------------------------- + * Exception handling. + *----------------------------------------------------------------------*/ + +try_block: + TRY compound_statement handler_seq + ; + +function_try_block: + TRY ctor_initializer_opt function_body handler_seq + ; + +handler_seq: + handler handler_seq_opt + ; + +handler: + CATCH '(' exception_declaration ')' compound_statement + ; + +exception_declaration: + type_specifier_seq declarator + | type_specifier_seq abstract_declarator + | type_specifier_seq + | ELLIPSIS + ; + +throw_expression: + THROW assignment_expression_opt + ; + +exception_specification: + THROW '(' type_id_list_opt ')' + ; + +type_id_list: + type_id + | type_id_list ',' type_id + ; + +/*---------------------------------------------------------------------- + * Epsilon (optional) definitions. + *----------------------------------------------------------------------*/ + +declaration_seq_opt: + { $$ = EMPTY; } + | declaration_seq + ; + +TEMPLATE_opt: + { $$ = EMPTY; } + | TEMPLATE + ; + +nested_name_specifier_opt: + { $$ = EMPTY; } + | nested_name_specifier + ; + +expression_list_opt: + { $$ = EMPTY; } + | expression_list + ; + +COLONCOLON_opt: + { $$ = EMPTY; } + | COLONCOLON { $$ = strdup("::"); } + ; + +new_placement_opt: + { $$ = EMPTY; } + | new_placement + ; + +new_initializer_opt: + { $$ = EMPTY; } + | new_initializer + ; + +new_declarator_opt: + { $$ = EMPTY; } + | new_declarator + ; + +expression_opt: + { $$ = EMPTY; } + | expression + ; + +statement_seq_opt: + { $$ = EMPTY; } + | statement_seq + ; + +condition_opt: + { $$ = EMPTY; } + | condition + ; + +decl_specifier_seq_opt: + { $$ = EMPTY; } + | decl_specifier_seq + ; + +init_declarator_list_opt: + { $$ = EMPTY; } + | init_declarator_list + ; + +identifier_opt: + { $$ = EMPTY; } + | identifier + ; + +enumerator_list_opt: + { $$ = EMPTY; } + | enumerator_list + ; + +TYPENAME_opt: + { $$ = EMPTY; } + | TYPENAME + ; + +initializer_opt: + { $$ = EMPTY; } + | initializer + ; + +cv_qualifier_seq_opt: + { $$ = EMPTY; } + | cv_qualifier_seq + ; + +exception_specification_opt: + { $$ = EMPTY; } + | exception_specification + ; + +constant_expression_opt: + { $$ = EMPTY; } + | constant_expression + ; + +abstract_declarator_opt: + { $$ = EMPTY; } + | abstract_declarator + ; + +type_specifier_seq_opt: + { $$ = EMPTY; } + | type_specifier_seq + ; + +direct_abstract_declarator_opt: + { $$ = EMPTY; } + | direct_abstract_declarator + ; + +parameter_declaration_list_opt: + { $$ = EMPTY; } + | parameter_declaration_list + ; + +ELLIPSIS_opt: + { $$ = EMPTY; } + | ELLIPSIS + ; + +ctor_initializer_opt: + { $$ = EMPTY; } + | ctor_initializer + ; + +COMMA_opt: + { $$ = EMPTY; } + | ',' + ; + +member_specification_opt: + { $$ = EMPTY; } + | member_specification + ; + +base_clause_opt: + { $$ = EMPTY; } + | base_clause + ; + +member_declarator_list_opt: + { $$ = EMPTY; } + | member_declarator_list + ; + +SEMICOLON_opt: + { $$ = EMPTY; } + | ';' + ; + +pure_specifier_opt: + { $$ = EMPTY; } + | pure_specifier + ; + +constant_initializer_opt: + { $$ = EMPTY; } + | constant_initializer + ; + +access_specifier_opt: + { $$ = EMPTY; } + | access_specifier + ; + +VIRTUAL_opt: + { $$ = EMPTY; } + | VIRTUAL + ; + +conversion_declarator_opt: + { $$ = EMPTY; } + | conversion_declarator + ; + +EXPORT_opt: + { $$ = EMPTY; } + | EXPORT + ; + +handler_seq_opt: + { $$ = EMPTY; } + | handler_seq + ; + +assignment_expression_opt: + { $$ = EMPTY; } + | assignment_expression + ; + +type_id_list_opt: + { $$ = EMPTY; } + | type_id_list + ; + + +%% + +int yyerror(char *s) { + printf("error, %s\n", s); + return 1; +} + +void yyprint (FILE *file, + int type, + YYSTYPE value) +{ + if (type == IDENTIFIER) + fprintf (file, "%s", value.sval); + if (type == COLONCOLON) + fprintf (file, "%s", value.sval); + +} + +int main(void) { +/* yydebug = 1;*/ + yyparse(); +} diff --git a/src/utils/moc/sample.cpp b/src/utils/moc/sample.cpp new file mode 100644 index 0000000..8f8f2ff --- /dev/null +++ b/src/utils/moc/sample.cpp @@ -0,0 +1,51 @@ +/*////////////////////////////////////////////////////////////////////////////// +// CMT Cosmic Muon Tomography project ////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova + All rights reserved + + Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > + + ------------------------------------------------------------------ + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3.0 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. + +//////////////////////////////////////////////////////////////////////////////*/ + + + + +typedef int TestInt; + +class DerivedObject { + + +public: + + ULIB_OBJECT_PARAMETERS(test) + { + Bubu *a; + }; + +}; + +int main() { + + ULIB_OBJECT_PARAMETERS(prova) { + int a,b; + char *c; + }; + + return 0; +} diff --git a/src/utils/moc/scan.l b/src/utils/moc/scan.l new file mode 100644 index 0000000..b5ff2d7 --- /dev/null +++ b/src/utils/moc/scan.l @@ -0,0 +1,252 @@ +%option stack +%{ +/* preamble */ +#include +#include +#include "y.tab.h" + +#define PRINT(str) { printf("%s",str); } +#define ENSTATE(st) { yy_push_state(YY_START); BEGIN(st); /*printf("ST[%i]",YY_START);*/ } +#define EXSTATE { BEGIN(yy_top_state()); yy_pop_state(); /*printf("ST[%i]",YY_START);*/ } + +#define SCANTEXT { fill_sval(); } +#define MATCH(name) { ECHO; SCANTEXT; return name; } + +int lineno; +int moc_level = 0; + +static int yywrap(void); +static void skip_until_eol(void); +static void skip_comment(void); +static int check_identifier(const char *); +static int fill_sval(); +%} + +blank [\t\f\v\r ]+ +anyunch <*>. + +intsuffix ([uU][lL]?)|([lL][uU]?) +fracconst ([0-9]*\.[0-9]+)|([0-9]+\.) +exppart [eE][-+]?[0-9]+ +floatsuffix [fFlL] +chartext ([^'])|(\\.) +stringtext ([^"])|(\\.) + +digit [0-9] +hex [0-9A-Fa-f] +letter [A-Z_a-z] +simple_escape_sequence (\\\'|\\\"|\\\?|\\\\|\\a|\\b|\\f|\\n|\\r|\\t|\\v) +octal_escape_sequence (\\[0-7]|\\[0-7][0-7]|\\[0-7][0-7][0-7]) +hexadecimal_escape_sequence (\\x{hex}+) +escape_sequence ({simple_escape_sequence}|{octal_escape_sequence}|{hexadecimal_escape_sequence}) +universal_character_name (\\u{hex}{hex}{hex}{hex}|\\U{hex}{hex}{hex}{hex}{hex}{hex}{hex}{hex}) +non_digit ({letter}|{universal_character_name}) +identifier ({non_digit}({non_digit}|{digit})*) + +begin_comment "/*" +end_comment "*/" +begin_inline_comment "//" +end_inline_comment "\n" + + +%s moc +%x cmt +%x inlcmt + +%% + +"\n" { ++lineno; ECHO; } +{blank} ECHO; + +{begin_comment} { ENSTATE(cmt); ECHO; } +{end_comment} { EXSTATE; ECHO; } + +{begin_inline_comment} { ENSTATE(inlcmt); ECHO; } +{end_inline_comment} { EXSTATE; ECHO; } + + +property { ECHO; ENSTATE(moc); return MOC_PROPERTY; } +ULIB_OBJECT_PARAMETERS { ECHO; ENSTATE(moc); return MOC_OBJECT_PARAMETERS; } +{ + "{" { moc_level++; MATCH('{'); } + "}" { if(!--moc_level)EXSTATE; MATCH('}'); } + + "<%" { MATCH('{'); } + "%>" { MATCH('}'); } + "[" { MATCH('['); } + "<:" { MATCH('['); } + "]" { MATCH(']'); } + ":>" { MATCH(']'); } + "(" { MATCH('('); } + ")" { MATCH(')'); } + ";" { MATCH(';'); } + "::" { MATCH(COLONCOLON); } + ":" { MATCH(':'); } + "..." { MATCH(ELLIPSIS); } + "?" { MATCH('?'); } + "." { MATCH('.'); } + ".*" { MATCH(DOTSTAR); } + "+" { MATCH('+'); } + "-" { MATCH('-'); } + "*" { MATCH('*'); } + "/" { MATCH('/'); } + "%" { MATCH('%'); } + "^" { MATCH('^'); } + "xor" { MATCH('^'); } + "&" { MATCH('&'); } + "bitand" { MATCH('&'); } + "|" { MATCH('|'); } + "bitor" { MATCH('|'); } + "~" { MATCH('~'); } + "compl" { MATCH('~'); } + "!" { MATCH('!'); } + "not" { MATCH('!'); } + "=" { MATCH('='); } + "<" { MATCH('<'); } + ">" { MATCH('>'); } + "+=" { MATCH(ADDEQ); } + "-=" { MATCH(SUBEQ); } + "*=" { MATCH(MULEQ); } + "/=" { MATCH(DIVEQ); } + "%=" { MATCH(MODEQ); } + "^=" { MATCH(XOREQ); } + "xor_eq" { MATCH(XOREQ); } + "&=" { MATCH(ANDEQ); } + "and_eq" { MATCH(ANDEQ); } + "|=" { MATCH(OREQ); } + "or_eq" { MATCH(OREQ); } + "<<" { MATCH(SL); } + ">>" { MATCH(SR); } + "<<=" { MATCH(SLEQ); } + ">>=" { MATCH(SREQ); } + "==" { MATCH(EQ); } + "!=" { MATCH(NOTEQ); } + "not_eq" { MATCH(NOTEQ); } + "<=" { MATCH(LTEQ); } + ">=" { MATCH(GTEQ); } + "&&" { MATCH(ANDAND); } + "and" { MATCH(ANDAND); } + "||" { MATCH(OROR); } + "or" { MATCH(OROR); } + "++" { MATCH(PLUSPLUS); } + "--" { MATCH(MINUSMINUS); } + "," { MATCH(','); } + "->*" { MATCH(ARROWSTAR); } + "->" { MATCH(ARROW); } + + "asm" { MATCH(ASM); } + "auto" { MATCH(AUTO); } + "bool" { MATCH(BOOL); } + "break" { MATCH(BREAK); } + "case" { MATCH(CASE); } + "catch" { MATCH(CATCH); } + "char" { MATCH(CHAR); } + "class" { MATCH(CLASS); } + "const" { MATCH(CONST); } + "const_cast" { MATCH(CONST_CAST); } + "continue" { MATCH(CONTINUE); } + "default" { MATCH(DEFAULT); } + "delete" { MATCH(DELETE); } + "do" { MATCH(DO); } + "double" { MATCH(DOUBLE); } + "dynamic_cast" { MATCH(DYNAMIC_CAST); } + "else" { MATCH(ELSE); } + "enum" { MATCH(ENUM); } + "explicit" { MATCH(EXPLICIT); } + "export" { MATCH(EXPORT); } + "extern" { MATCH(EXTERN); } + "false" { MATCH(FALSE); } + "float" { MATCH(FLOAT); } + "for" { MATCH(FOR); } + "friend" { MATCH(FRIEND); } + "goto" { MATCH(GOTO); } + "if" { MATCH(IF); } + "inline" { MATCH(INLINE); } + "int" { MATCH(INT); } + "long" { MATCH(LONG); } + "mutable" { MATCH(MUTABLE); } + "namespace" { MATCH(NAMESPACE); } + "new" { MATCH(NEW); } + "operator" { MATCH(OPERATOR); } + "private" { MATCH(PRIVATE); } + "protected" { MATCH(PROTECTED); } + "public" { MATCH(PUBLIC); } + "register" { MATCH(REGISTER); } + "reinterpret_cast" { MATCH(REINTERPRET_CAST); } + "return" { MATCH(RETURN); } + "short" { MATCH(SHORT); } + "signed" { MATCH(SIGNED); } + "sizeof" { MATCH(SIZEOF); } + "static" { MATCH(STATIC); } + "static_cast" { MATCH(STATIC_CAST); } + "struct" { MATCH(STRUCT); } + "switch" { MATCH(SWITCH); } + "template" { MATCH(TEMPLATE); } + "this" { MATCH(THIS); } + "throw" { MATCH(THROW); } + "true" { MATCH(TRUE); } + "try" { MATCH(TRY); } + "typedef" { MATCH(TYPEDEF); } + "typeid" { MATCH(TYPEID); } + "typename" { MATCH(TYPENAME); } + "union" { MATCH(UNION); } + "unsigned" { MATCH(UNSIGNED); } + "using" { MATCH(USING); } + "virtual" { MATCH(VIRTUAL); } + "void" { MATCH(VOID); } + "volatile" { MATCH(VOLATILE); } + "wchar_t" { MATCH(WCHAR_T); } + "while" { MATCH(WHILE); } + [a-zA-Z_][a-zA-Z_0-9]* { ECHO; return check_identifier(yytext); } + + "0"[xX][0-9a-fA-F]+{intsuffix}? { ECHO; return INTEGER; } + "0"[0-7]+{intsuffix}? { ECHO; return INTEGER; } + [0-9]+{intsuffix}? { ECHO; return INTEGER; } + + {fracconst}{exppart}?{floatsuffix}? { ECHO; return FLOATING; } + [0-9]+{exppart}{floatsuffix}? { ECHO; return FLOATING; } + + "'"{chartext}*"'" { ECHO; return CHARACTER; } + "L'"{chartext}*"'" { ECHO; return CHARACTER; } + "\""{stringtext}*"\"" { ECHO; return STRING; } + "L\""{stringtext}*"\"" { ECHO; return STRING; } + +} + +%% + +static int yywrap(void) +{ + return 1; +} + + +static int fill_sval() { + int len = strlen(yytext); + if(len) { + yylval.sval = malloc(len); + strncpy(yylval.sval, yytext, len); + } + else { + yylval.sval = strdup(""); + } + return len; +} + +static int check_identifier(const char *s) +{ +/* + switch (s[0]) { + case 'D': return TYPEDEF_NAME; + case 'N': return NAMESPACE_NAME; + case 'C': return CLASS_NAME; + case 'E': return ENUM_NAME; + case 'T': return TEMPLATE_NAME; + } +*/ + + yylval.sval = malloc(strlen(yytext)); + strncpy(yylval.sval, yytext, strlen(yytext)); + return IDENTIFIER; +} + diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..9969c96 --- /dev/null +++ b/test.cpp @@ -0,0 +1,10 @@ + +#include "Core/Object.h" + + + +int main() +{ + uLib::Object obj; + return 0; +} diff --git a/uLib.config b/uLib.config new file mode 100644 index 0000000..e0284f4 --- /dev/null +++ b/uLib.config @@ -0,0 +1,2 @@ +// Add predefined macros for your project here. For example: +// #define THE_ANSWER 42 diff --git a/uLib.creator b/uLib.creator new file mode 100644 index 0000000..e94cbbd --- /dev/null +++ b/uLib.creator @@ -0,0 +1 @@ +[General] diff --git a/uLib.files b/uLib.files new file mode 100644 index 0000000..b70784f --- /dev/null +++ b/uLib.files @@ -0,0 +1,234 @@ +src/Core/testing/ObjectMock/main.cpp +src/Core/testing/ObjectMock/Ob.cpp +src/Core/testing/ObjectMock/Ob.h +src/Core/testing/ObjectMock/Ob1.cpp +src/Core/testing/ObjectMock/Ob1.h +src/Core/testing/ObjectMock/Ob2.cpp +src/Core/testing/ObjectMock/Ob2.h +src/Core/testing/ObjectMock/testing-prototype.h +src/Core/testing/SerializeMock/main.cpp +src/Core/testing/SerializeMock/Ob.cpp +src/Core/testing/SerializeMock/Ob.h +src/Core/testing/SerializeMock/Ob1.cpp +src/Core/testing/SerializeMock/Ob1.h +src/Core/testing/SignalMock/main.cpp +src/Core/testing/SignalMock/main2.cpp +src/Core/testing/SignalMock/Ob.cpp +src/Core/testing/SignalMock/Ob.h +src/Core/testing/SignalMock/Ob1.cpp +src/Core/testing/SignalMock/Ob1.h +src/Core/testing/SignalMock/Ob2.cpp +src/Core/testing/SignalMock/Ob2.h +src/Core/testing/SignalMock/test1.cpp +src/Core/testing/SignalMock/testing-prototype.h +src/Core/testing/BoostAccumulatorTest.cpp +src/Core/testing/BoostTest.cpp +src/Core/testing/CommaInitTest.cpp +src/Core/testing/DebugTTreeDumpTest.cpp +src/Core/testing/DreadDiamondParameters.cpp +src/Core/testing/Flags.h +src/Core/testing/ObjectCopyTest.cpp +src/Core/testing/ObjectFlagsTest.cpp +src/Core/testing/ObjectParametersTest.cpp +src/Core/testing/ObjectPropableTest.cpp +src/Core/testing/OptionsTest.cpp +src/Core/testing/PropertiesTest.cpp +src/Core/testing/SerializeDreadDiamondTest.cpp +src/Core/testing/SerializeTest.cpp +src/Core/testing/SignalTest.cpp +src/Core/testing/SmartPointerTest.cpp +src/Core/testing/SmartVectorTest.cpp +src/Core/testing/StaticInterfaceTest.cpp +src/Core/testing/testing-prototype.h +src/Core/testing/TypeIntrospectionTraversal.cpp +src/Core/testing/UuidTest.cpp +src/Core/testing/VectorTest.cpp +src/Core/Archives.cpp +src/Core/Archives.h +src/Core/Array.h +src/Core/Collection.h +src/Core/CommaInitializer.h +src/Core/Debug.cpp +src/Core/Debug.h +src/Core/DebugArchives.cpp +src/Core/DebugArchives.h +src/Core/Export.h +src/Core/Flags.h +src/Core/Function.h +src/Core/Macros.h +src/Core/Mpl.h +src/Core/Object.cpp +src/Core/Object.h +src/Core/ObjectProps.h +src/Core/Options.cpp +src/Core/Options.h +src/Core/Serializable.cpp +src/Core/Serializable.h +src/Core/Signal.cpp +src/Core/Signal.h +src/Core/Singleton.h +src/Core/SmartPointer.h +src/Core/StaticInterface.h +src/Core/StringReader.h +src/Core/Timer.h +src/Core/Types.h +src/Core/Uuid.cpp +src/Core/Uuid.h +src/Core/Vector.h +src/Detectors/testing/GDMLSolidTest.cpp +src/Detectors/testing/HierarchicalEncodingTest.cpp +src/Detectors/testing/testing-prototype.h +src/Detectors/ChamberHitEvent.h +src/Detectors/DetectorChamber.h +src/Detectors/ExperimentFitEvent.h +src/Detectors/GeantEvent.h +src/Detectors/HierarchicalEncoding.h +src/Detectors/Hit.h +src/Detectors/HitMC.h +src/Detectors/LinearFit.h +src/Detectors/Matter.h +src/Detectors/MuonError.h +src/Detectors/MuonEvent.h +src/Detectors/MuonScatter.h +src/Detectors/Scene.cpp +src/Detectors/Scene.h +src/Detectors/Solid.cpp +src/Detectors/Solid.h +src/Gui/Qt/QVTKViewport2/main.cpp +src/Gui/Qt/QVTKViewport2/vtkviewport.cpp +src/Gui/Qt/QVTKViewport2/vtkviewport.h +src/ltk/ltk_bridge/ltkb.c +src/ltk/ltk_bridge/ltkb_test.c +src/ltk/testing/Object-cc.cpp +src/ltk/testing/Object.c +src/ltk/testing/testing-prototype.h +src/ltk/testing/Vector-cc.cpp +src/ltk/testing/Vector.c +src/ltk/vectormath/simd/instrset.h +src/ltk/vectormath/simd/instrset_detect.cpp +src/ltk/container.h +src/ltk/DenseMatrix.h +src/ltk/ltk.h +src/ltk/ltkdebug.c +src/ltk/ltkdebug.h +src/ltk/ltkmacros.h +src/ltk/ltktypes.h +src/ltk/main.c +src/ltk/Object.c +src/ltk/Object.h +src/ltk/templates.c +src/ltk/templates.h +src/ltk/test_comma.h +src/ltk/Vector.h +src/Math/testing/AccumulatorTest.cpp +src/Math/testing/BitCodeTest.cpp +src/Math/testing/ContainerBoxTest.cpp +src/Math/testing/GeometryTest.cpp +src/Math/testing/MathVectorTest.cpp +src/Math/testing/PolicyTest.cpp +src/Math/testing/StructuredDataTest.cpp +src/Math/testing/StructuredGridTest.cpp +src/Math/testing/testing-prototype.h +src/Math/testing/TriangleMeshTest.cpp +src/Math/testing/VoxImageCopyTest.cpp +src/Math/testing/VoxImageFilterTest.cpp +src/Math/testing/VoxImageTest.cpp +src/Math/testing/VoxRaytracerTest.cpp +src/Math/Accumulator.h +src/Math/BitCode.h +src/Math/ContainerBox.h +src/Math/Dense.cpp +src/Math/Dense.h +src/Math/Geometry.h +src/Math/Polydata.h +src/Math/Quote.h +src/Math/StructuredData.cpp +src/Math/StructuredData.h +src/Math/StructuredGrid.cpp +src/Math/StructuredGrid.h +src/Math/Transform.h +src/Math/TriangleMesh.cpp +src/Math/TriangleMesh.h +src/Math/Utils.h +src/Math/VoxImage.cpp +src/Math/VoxImage.h +src/Math/VoxImageFilter.h +src/Math/VoxImageFilter.hpp +src/Math/VoxImageFilter2ndStat.hpp +src/Math/VoxImageFilterABTrim.hpp +src/Math/VoxImageFilterBilateral.hpp +src/Math/VoxImageFilterCustom.hpp +src/Math/VoxImageFilterLinear.hpp +src/Math/VoxImageFilterMedian.hpp +src/Math/VoxImageFilterThreshold.hpp +src/Math/VoxImageFilterUser.cpp +src/Math/VoxRaytracer.cpp +src/Math/VoxRaytracer.h +src/ParticlePhysics/MuonTomography/DetectorChamber.h +src/ParticlePhysics/MuonTomography/DriftDetector.h +src/ParticlePhysics/MuonTomography/Hit.h +src/ParticlePhysics/MuonTomography/MuonScatter.h +src/Root/testing/muBlastMCTrackTest.cpp +src/Root/testing/RootDebugTest.cpp +src/Root/Linkdef.h +src/Root/muBlastHit.cpp +src/Root/muBlastHit.h +src/Root/muBlastMCTrack.cpp +src/Root/muBlastMCTrack.h +src/Root/RootHitMC.h +src/Root/RootHitRaw.h +src/Root/RootMathDense.h +src/Root/RootMuonCollection.cpp +src/Root/RootMuonCollection.h +src/Root/RootMuonScatter.cpp +src/Root/RootMuonScatter.h +src/Root/TestTObject.cpp +src/Root/TestTObject.h +src/utils/make_recipe/src/main.cpp +src/utils/make_recipe/main.cpp +src/utils/moc/moc_actions.h +src/utils/moc/sample.cpp +src/Vtk/testing/testing-prototype.h +src/Vtk/testing/testVtkWriter.cpp +src/Vtk/testing/vtkContainerBoxTest.cpp +src/Vtk/testing/vtkMuonScatter.cpp +src/Vtk/testing/vtkStructuredGridTest.cpp +src/Vtk/testing/vtkTriangleMeshTest.cpp +src/Vtk/testing/vtkViewerTest.cpp +src/Vtk/testing/vtkVoxImageTest.cpp +src/Vtk/testing/vtkVoxRaytracerTest.cpp +src/Vtk/uLibVtkInterface.cxx +src/Vtk/uLibVtkInterface.h +src/Vtk/uLibVtkViewer.cpp +src/Vtk/uLibVtkViewer.h +src/Vtk/vtkContainerBox.cpp +src/Vtk/vtkContainerBox.h +src/Vtk/vtkHLineRepresentation.h +src/Vtk/vtkMuonContainerScattering.cpp +src/Vtk/vtkMuonContainerScattering.h +src/Vtk/vtkMuonEvent.cxx +src/Vtk/vtkMuonEvent.h +src/Vtk/vtkMuonScatter.cxx +src/Vtk/vtkMuonScatter.h +src/Vtk/vtkPolydata.h +src/Vtk/vtkStructuredGrid.cpp +src/Vtk/vtkStructuredGrid.h +src/Vtk/vtkTriangleMesh.cpp +src/Vtk/vtkTriangleMesh.h +src/Vtk/vtkuLibProp.h +src/Vtk/vtkVoxImage.cpp +src/Vtk/vtkVoxImage.h +src/Vtk/vtkVoxRaytracerRepresentation.cpp +src/Vtk/vtkVoxRaytracerRepresentation.h +src/cwchar.h +CMakeConfig.in.h +test.cpp +ulib.h +vtk_test.cpp +CMakeLists.txt +CMake/FindROOT.cmake +src/Root/muCastorMCTrack.cpp +src/Root/muCastorMCTrack.h +src/Root/CMakeLists.txt +src/Root/muCastorHit.h +src/Root/muCastorHit.cpp diff --git a/uLib.includes b/uLib.includes new file mode 100644 index 0000000..2488045 --- /dev/null +++ b/uLib.includes @@ -0,0 +1,21 @@ +. +src +src/Core +src/Core/testing +src/Core/testing/ObjectMock +src/Core/testing/SerializeMock +src/Core/testing/SignalMock +src/Detectors +src/Detectors/testing +src/Gui/Qt/QVTKViewport2 +src/ltk +src/ltk/testing +src/ltk/vectormath/simd +src/Math +src/Math/testing +src/ParticlePhysics/MuonTomography +src/Root +src/utils/moc +src/Vtk +src/Vtk/testing +CMake diff --git a/uLibConfig.cmake.in b/uLibConfig.cmake.in new file mode 100644 index 0000000..148fc17 --- /dev/null +++ b/uLibConfig.cmake.in @@ -0,0 +1,19 @@ +# - Config file for the FooBar package +# It defines the following variables +# FOOBAR_INCLUDE_DIRS - include directories for FooBar +# FOOBAR_LIBRARIES - libraries to link against +# FOOBAR_EXECUTABLE - the bar executable + +# Compute paths +get_filename_component(ULIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(ULIB_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +# if(NOT TARGET foo AND NOT FooBar_BINARY_DIR) + include("${ULIB_CMAKE_DIR}/uLibTargets.cmake") +# endif() + +# These are IMPORTED targets created by FooBarTargets.cmake +# set(FOOBAR_LIBRARIES foo) +# set(FOOBAR_EXECUTABLE bar) +set(ULIB_LIBRARIES @ULIB_SHARED_LIBRARIES@) diff --git a/uLibConfigVersion.cmake.in b/uLibConfigVersion.cmake.in new file mode 100644 index 0000000..a5f8651 --- /dev/null +++ b/uLibConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@PACKAGE_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/ulib.h b/ulib.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ulib.h @@ -0,0 +1 @@ + diff --git a/vtk_test.cpp b/vtk_test.cpp new file mode 100644 index 0000000..f896a3a --- /dev/null +++ b/vtk_test.cpp @@ -0,0 +1,39 @@ + + + +#include +#include +#include +#include + +#include "Math/Dense.h" + +#include "Math/ContainerBox.h" +#include "Detectors/MuonScatter.h" +#include "Vtk/vtkMuonScatter.h" +#include "Vtk/vtkContainerBox.h" + +int main() +{ + + uLib::MuonScatter event; + event.LineIn().origin << 0,0,0,1; + event.LineIn().direction << 1,1,1,0; + event.LineOut().origin << 5,5,5,1; + event.LineOut().direction << -1,-1,-1,0; + + uLib::Vtk::vtkMuonScatter ms(event); + + uLib::ContainerBox box; + box.SetPosition(uLib::Vector3f(0,2,0)); + box.SetOrigin(uLib::Vector3f(-1,-0.5,-1)); + box.SetSize (uLib::Vector3f(2,-1,2)); + + + + uLib::Vtk::vtkContainerBox vtkbox(box); + + + + return 0; +}