19 Commits

Author SHA1 Message Date
AndreaRigoni
52580d8cde refactor: migrate voxel data storage to DataAllocator for CUDA 2026-02-28 10:05:39 +00:00
AndreaRigoni
07915295cb feat: fix signaling and implement a ping-pong signal/slot test 2026-02-28 08:58:04 +00:00
AndreaRigoni
d56758d0b3 refactor: Update CMake build system and streamline Core object serialization and property handling. 2026-02-21 16:16:28 +00:00
AndreaRigoni
7ded15d596 chore: remove LTK, MOC, and QVTKViewport2 components. 2026-02-21 15:40:21 +00:00
AndreaRigoni
c04722c2bb refactor: reformat type introspection code and remove ObjectProps system. 2026-02-21 10:45:25 +00:00
AndreaRigoni
8566ceb662 feat: add condaenv.yml for environment setup and update README.md with detailed build instructions. 2026-02-20 18:05:40 +00:00
AndreaRigoni
5ae2e106ab added conanfile 2026-02-20 17:27:30 +00:00
c526f61f8c Merge pull request #3 from OpenCMT/andrea-dev
fix mismatch Origin - Position
2025-09-25 17:38:45 +02:00
AndreaRigoni
54997fe0ac fix mismatch Origin - Position 2025-09-25 17:34:23 +02:00
94bad596ed Merge pull request #2 from OpenCMT/andrea-dev
fix export to Vti
2025-09-23 18:52:54 +02:00
AndreaRigoni
fc909da400 fix export to Vti 2025-09-23 18:21:11 +02:00
b0240dc807 Merge pull request #1 from OpenCMT/andrea-dev
Andrea dev
2025-09-18 13:12:12 +02:00
AndreaRigoni
591cc9d8bc add version 0.6 - make external build possible 2025-09-05 18:04:54 +02:00
AndreaRigoni
2e401f6fc5 add posibility to compile in build directory 2025-09-04 16:12:38 +02:00
AndreaRigoni
91abd56587 fix Root needs for C++17 2025-09-04 16:11:57 +02:00
AndreaRigoni
01ff8a0a0d update 2025-09-02 13:01:55 +02:00
AndreaRigoni
b86e27a9c4 add VTK save early 2025-09-02 12:42:46 +02:00
Paolo Andreetto
820730bc84 New root dicts 2023-09-01 14:14:06 +02:00
Paolo Andreetto
06c363ab8c Workaround for CentOS7 2023-04-04 16:31:30 +02:00
109 changed files with 3966 additions and 8106 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
CMakeFiles/ CMakeFiles/
build/ build/
.cache/

8
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"clangd.fallbackFlags": [
"-I${workspaceFolder}/src",
"-I/home/share/micromamba/envs/mutom/include",
"-I/home/rigoni/.conan2/p/eigen5481853932f72/p/include/eigen3"
],
"clangd.semanticHighlighting.enable": true
}

View File

@@ -15,16 +15,16 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "build path for
mark_as_advanced(EXECUTABLE_OUTPUT_PATH) mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
## Install directories ## ## Install directories ##
set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") set(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(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(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") set(INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
if(WIN32 AND NOT CYGWIN) if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake) set(DEF_INSTALL_CMAKE_DIR CMake)
else() else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME}) set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
endif() endif()
set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# Make relative paths absolute (needed later on) # Make relative paths absolute (needed later on)
foreach(p LIB BIN INC DATA CMAKE) foreach(p LIB BIN INC DATA CMAKE)
@@ -58,7 +58,7 @@ endif()
set(CMAKE_CXX_WARNING_OPTION "" CACHE STRING "Warning level -WAll to verbose all warnings") 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_VERBOSE_MAKEFILE FALSE CACHE STRING "Verbose compile output switch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}")

View File

@@ -41,15 +41,15 @@ macro(uLib_add_shared_library name)
install(TARGETS ${mname} install(TARGETS ${mname}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
# PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev # PUBLIC_HEADER DESTINATION ${INSTALL_INC_DIR} COMPONENT dev
) )
endif(SOURCES) endif(SOURCES)
if(HEADERS) if(HEADERS)
foreach(header ${HEADERS}) foreach(header ${HEADERS})
install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name}) install(FILES ${header} DESTINATION ${INSTALL_INC_DIR}/${name})
endforeach(header) endforeach(header)
endif(HEADERS) endif(HEADERS)
@@ -70,7 +70,7 @@ macro(uLib_add_target name)
install(TARGETS ${name} install(TARGETS ${name}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
) )
ENDMACRO(uLib_add_target) ENDMACRO(uLib_add_target)
@@ -82,7 +82,7 @@ ENDMACRO(uLib_add_target)
# TESTS and LIBRARIES must be defined # TESTS and LIBRARIES must be defined
macro(uLib_add_tests name) macro(uLib_add_tests name)
foreach(tn ${TESTS}) foreach(tn ${TESTS})
add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp) add_executable(${tn} ${tn}.cpp)
add_test(NAME ${tn} COMMAND ${tn}) add_test(NAME ${tn} COMMAND ${tn})
target_link_libraries(${tn} ${LIBRARIES}) target_link_libraries(${tn} ${LIBRARIES})

View File

@@ -3,15 +3,22 @@
##### CMAKE LISTS ############################################################## ##### CMAKE LISTS ##############################################################
################################################################################ ################################################################################
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 3.26)
## -------------------------------------------------------------------------- ## ## -------------------------------------------------------------------------- ##
project(uLib) project(uLib)
# CUDA Toolkit seems to be missing locally. Toggle ON if nvcc is made available.
option(USE_CUDA "Enable CUDA support" ON)
if(USE_CUDA)
enable_language(CUDA)
add_compile_definitions(USE_CUDA)
endif()
# The version number. # The version number.
set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 5) set(PROJECT_VERSION_MINOR 6)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
@@ -33,19 +40,31 @@ message(STATUS "Module path = ${CMAKE_MODULE_PATH}")
## GLOBALS ------------------------------------------------------------------ ## ## GLOBALS ------------------------------------------------------------------ ##
set(PACKAGE_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin # -- move to GnuInstallDirs
CACHE PATH "Installation directory for executables") # ref: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
set(PACKAGE_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/ include(GNUInstallDirs)
CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
set(PACKAGE_INSTALL_INC_DIR ${CMAKE_INSTALL_PREFIX}/include/${PACKAGE_NAME} CACHE PATH "Location of header files (.../include)" )
CACHE PATH "Installation directory for headers") set(INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR}/${PACKAGE_NAME}
set(PACKAGE_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE_NAME} CACHE PATH "Location of configuration files (.../etc)" )
CACHE PATH "Installation directory for data files") set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR}/${PACKAGE_NAME}
set(PACKAGE_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PACKAGE_NAME} CACHE PATH "Location of executable files (.../bin)" )
CACHE PATH "Installation directory for CMake files") set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}
CACHE PATH "Location of library files (.../lib)" )
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
CACHE PATH "Location of cmake files (.../lib/cmake)" )
set(INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}/${PACKAGE_NAME}
CACHE PATH "Location of data files (.../share)" )
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src) set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
# this is used to be exported in build target
# ( to compile against build directory instead of install )
set(ULIB_SOURCE_DIR ${PROJECT_SOURCE_DIR})
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.") 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_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
@@ -60,44 +79,60 @@ set(CMAKE_CXX_WARNING_OPTION ""
set(CMAKE_VERBOSE_MAKEFILE FALSE set(CMAKE_VERBOSE_MAKEFILE FALSE
CACHE STRING "Verbose compile output switch") CACHE STRING "Verbose compile output switch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_WARNING_OPTION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UULIB_SERIALIZATION_ON") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UULIB_SERIALIZATION_ON -Wno-cpp")
# CTEST framework
include(CTest)
enable_testing()
#enable_testing()
## FIND PACKAGES ------------------------------------------------------------ ## ## FIND PACKAGES ------------------------------------------------------------ ##
set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.45.0 COMPONENTS program_options REQUIRED) message(STATUS "CMAKE_PREFIX_PATH is ${CMAKE_PREFIX_PATH}")
find_package(Boost 1.45.0 COMPONENTS program_options serialization unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
find_package(Eigen3 CONFIG REQUIRED) find_package(Eigen3 CONFIG REQUIRED)
include(${EIGEN3_USE_FILE}) get_target_property(EIGEN3_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${EIGEN3_INCLUDE_DIRS})
find_package(ROOT CONFIG REQUIRED) find_package(ROOT CONFIG REQUIRED)
include(${ROOT_USE_FILE}) include(${ROOT_USE_FILE})
find_package(VTK REQUIRED find_package(VTK REQUIRED)
COMPONENTS CommonColor # include(${VTK_USE_FILE})
CommonCore
FiltersCore
FiltersModeling
FiltersSources option(CENTOS_SUPPORT "VTK definitions for CentOS" OFF)
IOLegacy if(CENTOS_SUPPORT)
IOXML find_package(VTK CONFIG REQUIRED)
IOXMLParser include(${VTK_USE_FILE})
ImagingCore else()
InteractionStyle find_package(VTK REQUIRED
InteractionWidgets COMPONENTS CommonColor
RenderingAnnotation CommonCore
RenderingContextOpenGL2 FiltersCore
RenderingCore FiltersModeling
RenderingFreeType FiltersSources
RenderingGL2PSOpenGL2 IOLegacy
RenderingOpenGL2 IOXML
RenderingVolumeOpenGL2) IOXMLParser
ImagingCore
InteractionStyle
InteractionWidgets
RenderingAnnotation
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
RenderingVolumeOpenGL2)
endif()
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h) set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m) set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m)
@@ -136,7 +171,7 @@ configure_file("${PROJECT_SOURCE_DIR}/CMakeConfig.in.h"
"${PROJECT_BINARY_DIR}/config.h") "${PROJECT_BINARY_DIR}/config.h")
install(FILES "${PROJECT_BINARY_DIR}/config.h" install(FILES "${PROJECT_BINARY_DIR}/config.h"
DESTINATION ${PACKAGE_INSTALL_INC_DIR}) DESTINATION ${INSTALL_INC_DIR})
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ## ## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
@@ -181,8 +216,8 @@ add_subdirectory(${SRC_DIR}/Vtk)
# Create the FooBarConfig.cmake and FooBarConfigVersion files # Create the FooBarConfig.cmake and FooBarConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}" # file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
"${PACKAGE_INSTALL_INC_DIR}") # "${INSTALL_INC_DIR}")
# ... for the build tree # ... for the build tree
#set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}") #set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
@@ -191,21 +226,53 @@ file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
# ... for the install tree # ... for the install tree
set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}") set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(uLibConfig.cmake.in # [ removed for the configure_config_file ]
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake" # configure_file(uLibConfig.cmake.in
@ONLY) # "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
# @ONLY)
# ... for both # ... for both
configure_file(uLibConfigVersion.cmake.in configure_file(uLibConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY) "${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
# from CMake 3.x configure file shall be created using a dedicated function
# see: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html
#
include(CMakePackageConfigHelpers)
configure_package_config_file(uLibConfig.cmake.in
"${PROJECT_BINARY_DIR}/uLibConfig.cmake"
INSTALL_DESTINATION ${INSTALL_CMAKE_DIR}
PATH_VARS
INSTALL_LIB_DIR
INSTALL_INC_DIR
INSTALL_BIN_DIR
INSTALL_CMAKE_DIR
INSTALL_ETC_DIR
INSTALL_DATA_DIR
ULIB_SOURCE_DIR
ULIB_SHARED_LIBRARIES
# NO_SET_AND_CHECK_MACRO
# NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(FILES "${PROJECT_BINARY_DIR}/uLibConfig.cmake"
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" "${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake"
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}" DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev) COMPONENT dev)
# this is a special target file for the build tree
# it is used also to identify if we are using a build direcory
# to link a project against uLib. see: uLibConfig.cmake ( IF )
export (TARGETS ${ULIB_SHARED_LIBRARIES}
FILE "${PROJECT_BINARY_DIR}/uLibTargets-build.cmake"
# NAMESPACE "uLib::"
)
# Install the export set for use with the install-tree # Install the export set for use with the install-tree
install(EXPORT "${PROJECT_NAME}Targets" install(EXPORT "uLibTargets"
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}" FILE "uLibTargets.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev) COMPONENT dev)

9
CMakeUserPresets.json Normal file
View File

@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/CMakePresets.json"
]
}

View File

@@ -7,3 +7,57 @@ base toolkit library
CMT Cosmic Muon Tomography reconstruction, analysis and imaging software CMT Cosmic Muon Tomography reconstruction, analysis and imaging software
Developed by University of Padova and INFN Sezione di Padova Italy Developed by University of Padova and INFN Sezione di Padova Italy
## Build Instructions
This project relies on `conan` (v2) for dependency management (Eigen3, Boost) and `cmake` for configuration. VTK is provided through the micromamba/conda-forge environment.
### Prerequisites
This project requires a `conda` or `micromamba` environment containing the necessary global tools like **ROOT**, **VTK**, and **Conan** (v2). We provide a `condaenv.yml` file to quickly build this environment.
#### Installing Micromamba (Optional)
If you do not have `conda` installed, `micromamba` is a fast and lightweight alternative. You can install it on Linux via:
```bash
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
```
#### Creating the Environment
You can create and activate the environment using either `micromamba` or `conda`.
**Using Micromamba:**
```bash
micromamba env create -f condaenv.yml
micromamba activate mutom
```
**Using Conda:**
```bash
conda env create -f condaenv.yml
conda activate mutom
```
### Configure and Build
1. **Configure Conan profile (if you haven't yet on your machine):**
```bash
conan profile detect
```
2. **Install Conan dependencies:**
```bash
conan install . --output-folder=build --build=missing
```
3. **Configure the project with CMake:**
```bash
cmake --preset conan-release
```
*(Alternatively: `cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release`)*
4. **Build the project:**
```bash
cmake --build build -j10
```

36
build.log Normal file
View File

@@ -0,0 +1,36 @@
make: Entering directory '/home/rigoni/devel/cmt/ulib/build'
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/VoxImage.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/TriangleMesh.cpp.o
[ 30%] Building CXX object src/Core/CMakeFiles/mutomCore.dir/Options.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/Dense.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/StructuredGrid.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/VoxRaytracer.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/StructuredData.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/Structured2DGrid.cpp.o
[ 30%] Building CXX object src/Math/CMakeFiles/mutomMath.dir/Structured4DGrid.cpp.o
[ 33%] Linking CXX shared library libmutomCore.so
[ 33%] Built target mutomCore
[ 36%] Linking CXX shared library libmutomMath.so
[ 36%] Built target mutomMath
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/vtkContainerBox.cpp.o
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/uLibVtkInterface.cxx.o
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/vtkStructuredGrid.cpp.o
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/vtkMuonScatter.cxx.o
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/uLibVtkViewer.cpp.o
[ 63%] Generating mutomRootDict.cxx, libmutomRootDict_rdict.pcm, libmutomRootDict.rootmap
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/vtkVoxImage.cpp.o
[ 63%] Building CXX object src/Vtk/CMakeFiles/mutomVtk.dir/vtkVoxRaytracerRepresentation.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorSkinHit.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorHit.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorMCTrack.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorInfo.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/RootMuonScatter.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorPrimaryVertex.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/muCastorMuDetDIGI.cpp.o
[ 90%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/SkinDetectorWriter.cpp.o
[ 93%] Building CXX object src/Root/CMakeFiles/mutomRoot.dir/mutomRootDict.cxx.o
[ 96%] Linking CXX shared library libmutomVtk.so
[ 96%] Built target mutomVtk
[100%] Linking CXX shared library libmutomRoot.so
[100%] Built target mutomRoot
make: Leaving directory '/home/rigoni/devel/cmt/ulib/build'

7
conanfile.txt Normal file
View File

@@ -0,0 +1,7 @@
[requires]
eigen/3.4.0
boost/1.83.0
[generators]
CMakeDeps
CMakeToolchain

10
condaenv.yml Normal file
View File

@@ -0,0 +1,10 @@
name: mutom
channels:
- conda-forge
dependencies:
- compiler-rt
- make
- cmake
- conan
- root
- vtk

60
docs/usage/usage.md Normal file
View File

@@ -0,0 +1,60 @@
# Usage and Installation Guide
## Requirements
### Compiling with CUDA Support
The library supports running VoxImage filtering operations directly on CUDA cores via transparent RAM/VRAM memory transfers.
By default, the `CMakeLists.txt` build system sets `USE_CUDA=ON` and will attempt to locate `nvcc` and the NVIDIA CUDA Toolkit. If the toolkit is missing, `CMake` will fail unless you explicitly configure the project with `-DUSE_CUDA=OFF`.
### 1. Installing CUDA Environment via Micromamba
If you are developing inside an isolated Conda/Micromamba environment (e.g., `mutom`), you can inject the CUDA compilers directly into your environment rather than relying on global system dependencies:
```bash
# Add the conda-forge channel if not already available
micromamba config append channels conda-forge
# Install nvcc and the necessary CUDA toolkit components
micromamba install cuda-nvcc
```
Verify your installation:
```bash
nvcc --version
```
### 2. Building the Project
Configure and compile the project using standard CMake flows:
```bash
mkdir -p build && cd build
# Configure CMake
# (Optional) Explicitly toggle CUDA: cmake -DUSE_CUDA=ON ..
cmake ..
# Compile the project and tests
make -j $(nproc)
```
### 3. Validating CUDA Support
You can verify that the CUDA kernels are launching correctly and allocating device memory through `DataAllocator` by running the mathematical unit tests.
```bash
# From the build directory
./src/Math/testing/VoxImageFilterTest
# Output should show:
# "Data correctly stayed in VRAM after CUDA execution!"
```
## How It Works Under The Hood
The `DataAllocator<T>` container automatically wraps memory allocations to transparently map to CPU RAM, or GPU VRAM. Standard iteration automatically pulls data backwards using implicit `MoveToRAM()` calls.
Filters using `#ifdef USE_CUDA` explicitly dictate `<buffer>.MoveToVRAM()` allocating directly on device bounds seamlessly. Fallbacks to Host compute iterations handle themselves automatically. Chaining specific filters together safely chains continuous VRAM operations avoiding costly Host copies in between iterations.

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,9 @@
set(HEADERS Options.h set(HEADERS Archives.h Array.h Collection.h Debug.h Export.h Function.h Macros.h Mpl.h Object.h Options.h Serializable.h Signal.h Singleton.h SmartPointer.h StaticInterface.h StringReader.h Types.h Uuid.h Vector.h)
StaticInterface.h)
set(SOURCES Options.cpp) set(SOURCES Archives.cpp Debug.cpp Object.cpp Options.cpp Serializable.cpp Signal.cpp Uuid.cpp)
set(LIBRARIES ${Boost_PROGRAM_OPTIONS_LIBRARY}) set(LIBRARIES Boost::program_options)
set(libname ${PACKAGE_LIBPREFIX}Core) set(libname ${PACKAGE_LIBPREFIX}Core)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE) set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -18,10 +17,12 @@ target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname} install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib) LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Core)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -23,95 +23,85 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_EXPORT_H #ifndef U_CORE_EXPORT_H
#define U_CORE_EXPORT_H #define U_CORE_EXPORT_H
#include <utility>
#include <cstddef> // NULL #include <cstddef> // NULL
#include <iostream> #include <iostream>
#include <utility>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_polymorphic.hpp> #include <boost/type_traits/is_polymorphic.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/and.hpp> #include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp> #include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/mpl/not.hpp>
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
#include <boost/serialization/static_warning.hpp>
#include <boost/serialization/assume_abstract.hpp> #include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
#include <boost/serialization/force_include.hpp> #include <boost/serialization/force_include.hpp>
#include <boost/serialization/singleton.hpp> #include <boost/serialization/singleton.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/archive/detail/register_archive.hpp> #include <boost/archive/detail/register_archive.hpp>
#include "Core/Archives.h" #include "Core/Archives.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace uLib { namespace uLib {
namespace Archive { namespace Archive {
namespace detail { namespace detail {
namespace extra_detail { namespace extra_detail {
template<class T> template <class T> struct guid_initializer {
struct guid_initializer void export_guid(boost::mpl::false_) const {
{ // generates the statically-initialized objects whose constructors
void export_guid(mpl::false_) const { // register the information allowing serialization of T objects
// generates the statically-initialized objects whose constructors // through pointers to their base classes.
// register the information allowing serialization of T objects boost::archive::detail::instantiate_ptr_serialization(
// through pointers to their base classes. (T *)0, 0, uLib::Archive::detail::adl_tag());
boost::archive::detail:: }
instantiate_ptr_serialization((T*)0, 0, void export_guid(boost::mpl::true_) const {}
uLib::Archive::detail::adl_tag()); guid_initializer const &export_guid() const {
} BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
void export_guid(mpl::true_) const { // note: exporting an abstract base class will have no effect
} // and cannot be used to instantitiate serialization code
guid_initializer const & export_guid() const { // (one might be using this in a DLL to instantiate code)
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value); // BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
// note: exporting an abstract base class will have no effect export_guid(boost::serialization::is_abstract<T>());
// and cannot be used to instantitiate serialization code return *this;
// (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<typename T> template <typename T> struct init_guid;
struct init_guid;
} // anonymous } // namespace extra_detail
} // namespace detail } // namespace detail
} // namespace Archive } // namespace Archive
} // namespace uLib } // namespace uLib
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
namespace uLib { \
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \ namespace Archive { \
namespace uLib { \ namespace detail { \
namespace Archive { \ namespace extra_detail { \
namespace detail { \ template <> struct init_guid<T> { \
namespace extra_detail { \ static guid_initializer<T> const &g; \
template<> \ }; \
struct init_guid< T > { \ guid_initializer<T> const &init_guid<T>::g = \
static guid_initializer< T > const & g; \ ::boost::serialization::singleton< \
}; \ guid_initializer<T>>::get_mutable_instance() \
guid_initializer< T > const & init_guid< T >::g = \ .export_guid(); \
::boost::serialization::singleton< \ } \
guid_initializer< T > \ } \
>::get_mutable_instance().export_guid(); \ } \
}}}} \ } \
/**/ /**/
#endif // EXPORT_H #endif // EXPORT_H

View File

@@ -14,7 +14,6 @@ library_include_HEADERS = \
Macros.h \ Macros.h \
Mpl.h \ Mpl.h \
Object.h \ Object.h \
ObjectProps.h \
Options.h \ Options.h \
Serializable.h \ Serializable.h \
Signal.h \ Signal.h \

View File

@@ -23,178 +23,128 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "config.h" #include "config.h"
#include "Object.h" #include "Object.h"
#include "Vector.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" #include "boost/archive/polymorphic_binary_iarchive.hpp"
#include "boost/archive/polymorphic_binary_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_xml_oarchive.hpp"
namespace uLib { namespace uLib {
const char *Version::PackageName = PACKAGE_NAME;
const char *Version::PackageName = PACKAGE_NAME;
const char *Version::VersionNumber = PACKAGE_VERSION; const char *Version::VersionNumber = PACKAGE_VERSION;
const char *Version::Release = "x"; //SVN_REVISION; const char *Version::Release = "x"; // SVN_REVISION;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Object Private // // Object Private //
class ObjectPrivate { class ObjectPrivate {
public: public:
struct Signal {
GenericMFPtr sigptr;
std::string sigstr;
SignalBase *signal;
};
struct Signal { struct Slot {
GenericMFPtr sigptr; GenericMFPtr sloptr;
std::string sigstr; std::string slostr;
SignalBase *signal; };
};
struct Slot { Vector<Signal> sigv;
GenericMFPtr sloptr; Vector<Slot> slov;
std::string slostr;
};
Vector<Signal> sigv;
Vector<Slot> slov;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// OBJECT IMPLEMENTATION // OBJECT IMPLEMENTATION
Object::Object() : d(new ObjectPrivate) {}
Object::Object(const Object &copy) : d(new ObjectPrivate(*copy.d)) {}
Object::Object() : Object::~Object() { delete d; }
d(new ObjectPrivate)
{}
Object::Object(const Object &copy) : void Object::DeepCopy(const Object &copy) {
ObjectPropable(copy), // should lock to be tread safe //
d(new ObjectPrivate(*copy.d)) memcpy(d, copy.d, sizeof(ObjectPrivate));
{} // ERROR! does not copy parameters ... <<<< FIXXXXX
Object::~Object() {
delete d;
} }
void Object::DeepCopy(const Object &copy) void Object::SaveXml(std::ostream &os, Object &ob) {
{ Archive::xml_oarchive ar(os);
// should lock to be tread safe // ar << boost::serialization::make_nvp("Object", ob);
memcpy(d,copy.d,sizeof(ObjectPrivate));
// ERROR! does not copy parameters ... <<<< FIXXXXX
} }
void Object::LoadXml(std::istream &is, Object &ob) {
Archive::xml_iarchive ar(is);
ar >> boost::serialization::make_nvp("Object", ob);
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 // FINIRE
void Object::SaveConfig(std::ostream &os, int version) void Object::SaveConfig(std::ostream &os, int version) {
{ Archive::xml_oarchive ar(os);
Archive::xml_oarchive ar(os);
ObjectPropable::serialize(ar,0);
} }
void Object::LoadConfig(std::istream &is, int version) void Object::LoadConfig(std::istream &is, int version) {
{ Archive::xml_iarchive ar(is);
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<ObjectPrivate::Signal>::Iterator itr;
for (itr = d->sigv.begin(); itr < d->sigv.end(); itr++) {
void Object::PrintSelf(std::ostream &o) const o << " signal:[ " << itr->sigstr << " ]\n";
{ }
o << "OBJECT signals: ------------------\n"; o << "--------------------------------------\n\n";
Vector<ObjectPrivate::Signal>::Iterator itr;
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
{
o << " signal:[ " << itr->sigstr << " ]\n";
}
o << "--------------------------------------\n\n";
} }
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr,
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name) const char *name) {
{ ObjectPrivate::Signal s = {fptr, std::string(name), sig};
ObjectPrivate::Signal s = {fptr,std::string(name),sig}; d->sigv.push_back(s);
d->sigv.push_back(s); return true;
} }
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) bool Object::addSlotImpl(GenericMFPtr fptr, const char *name) {
{ ObjectPrivate::Slot s = {fptr, std::string(name)};
ObjectPrivate::Slot s = {fptr,std::string(name)}; d->slov.push_back(s);
d->slov.push_back(s); return true;
} }
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const {
{ for (int i = 0; i < d->sigv.size(); ++i) {
for(int i=0; i<d->sigv.size(); ++i) if (d->sigv[i].sigptr == fptr)
{ return d->sigv[i].signal;
if(d->sigv[i].sigptr == fptr) }
return d->sigv[i].signal; return NULL;
}
return NULL;
} }
SignalBase *Object::findSignalImpl(const char *name) const SignalBase *Object::findSignalImpl(const char *name) const {
{ std::string in(name);
std::string in(name); for (int i = 0; i < d->sigv.size(); ++i) {
for(int i=0; i<d->sigv.size(); ++i) if (d->sigv[i].sigstr == in)
{ return d->sigv[i].signal;
if(d->sigv[i].sigstr == in) }
return d->sigv[i].signal; return NULL;
}
return NULL;
} }
GenericMFPtr *Object::findSlotImpl(const char *name) const GenericMFPtr *Object::findSlotImpl(const char *name) const {
{ std::string in(name);
std::string in(name); for (int i = 0; i < d->slov.size(); ++i) {
for(int i=0; i<d->slov.size(); ++i) if (d->slov[i].slostr == in)
{ return &d->slov[i].sloptr;
if(d->slov[i].slostr == in) }
return &d->slov[i].sloptr; return NULL;
}
return NULL;
} }
// std::ostream & // std::ostream &
// operator << (std::ostream &os, uLib::Object &ob) // operator << (std::ostream &os, uLib::Object &ob)
// { // {
@@ -218,10 +168,4 @@ GenericMFPtr *Object::findSlotImpl(const char *name) const
// return is; // return is;
// } // }
} // namespace uLib
} // uLib

View File

@@ -23,200 +23,185 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OBJECT_H #ifndef U_CORE_OBJECT_H
#define U_CORE_OBJECT_H #define U_CORE_OBJECT_H
#include <iostream> #include <iostream>
// WARNING: COPILE ERROR if this goes after mpl/vector // // WARNING: COPILE ERROR if this goes after mpl/vector //
//#include "Core/Vector.h" // #include "Core/Vector.h"
#include "Core/Types.h"
#include "Core/Debug.h" #include "Core/Debug.h"
#include "Core/Types.h"
#include "Core/Function.h" #include "Core/Function.h"
#include "Core/Signal.h" #include "Core/Signal.h"
#include "Core/Mpl.h" #include "Core/Mpl.h"
#include "Core/Serializable.h" #include "Core/Serializable.h"
#include "Core/ObjectProps.h"
#include "Core/Uuid.h" #include "Core/Uuid.h"
namespace boost { namespace boost {
namespace archive { namespace archive {
class polymorphic_iarchive; class polymorphic_iarchive;
class polymorphic_oarchive; class polymorphic_oarchive;
} // archive } // namespace archive
} // boost } // namespace boost
namespace uLib { namespace uLib {
class Version { class Version {
public: public:
static const char *PackageName; static const char *PackageName;
static const char *VersionNumber; static const char *VersionNumber;
static const char *Release; static const char *Release;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//// OBJECT //////////////////////////////////////////////////////////////////// //// OBJECT ////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/** /**
* @brief Object class is the object base implementation for uLib Framework. * @brief Object class is the object base implementation for uLib Framework.
*/ */
class Object : public ObjectPropable class Object {
{
public: public:
// std::string name; // std::string name;
// void PrintName() { std::cout << "Ob name: " << name << "\n"; } // void PrintName() { std::cout << "Ob name: " << name << "\n"; }
Object(); Object();
Object(const Object &copy); Object(const Object &copy);
~Object(); ~Object();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// PARAMETERS // // PARAMETERS //
// FIXX !!! // FIXX !!!
virtual void DeepCopy(const Object &copy); virtual void DeepCopy(const Object &copy);
////////////////////////////////////////////////////////////////////////////
// SERIALIZATION //
//////////////////////////////////////////////////////////////////////////// template <class ArchiveT>
// SERIALIZATION // void serialize(ArchiveT &ar, const unsigned int version) {}
template <class ArchiveT>
void save_override(ArchiveT &ar, const unsigned int version) {}
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) { void SaveConfig(std::ostream &os, int version = 0);
ObjectPropable::serialize(ar,version); 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;
return false;
}
// Qt5 style connector //
template <typename Func1, typename Func2>
static bool
connect(typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof) {
SignalBase *sigb = sender->findOrAddSignal(sigf);
ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(sigb, slof,
receiver);
return true;
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(sigb, slof,
receiver);
return true;
}
template <typename FuncT>
inline
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
addSignal(FuncT fun, const char *name) {
typedef
typename Signal<typename FunctionPointer<FuncT>::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) {
return this->addSlotImpl(GenericMFPtr(fun), name);
}
template <typename FuncT>
inline
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
findSignal(FuncT fptr) {
typedef
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
}
template <typename FuncT>
inline
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
findOrAddSignal(FuncT fptr) {
typedef
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type
SigT;
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
if (!sig) {
sig = NewSignal(fptr);
addSignalImpl(sig, fptr, "signal_name_to_be_implemented");
} }
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {} return (SigT *)sig;
}
void SaveConfig(std::ostream &os, int version = 0); inline SignalBase *findSignal(const char *name) const {
void LoadConfig(std::istream &is, int version = 0); return findSignalImpl(name);
}
static void SaveXml(std::ostream &os, Object &ob); inline GenericMFPtr *findSlot(const char *name) const {
static void LoadXml(std::istream &is, Object &ob); return findSlotImpl(name);
}
void PrintSelf(std::ostream &o) const;
inline const Object &operator=(const Object &copy) {
//////////////////////////////////////////////////////////////////////////// this->DeepCopy(copy);
// SIGNALS // return *this;
}
// 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 <typename Func1, typename Func2>
static bool connect( typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof)
{
SignalBase *sigb = sender->findOrAddSignal(sigf);
typedef boost::signals2::signal<typename FunctionPointer<Func2>::SignalSignature> SigT;
ConnectSignal(sigb,slof,receiver);
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal(sigb,slof,receiver);
}
template< typename FuncT >
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
addSignal(FuncT fun, const char *name) {
typedef typename Signal<typename FunctionPointer<FuncT>::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<typename FunctionPointer<FuncT>::SignalSignature>::type *
findSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
}
template < typename FuncT >
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
findOrAddSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionPointer<FuncT>::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 &copy)
{ this->DeepCopy(copy); return *this; }
private: private:
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name); bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
bool addSlotImpl(GenericMFPtr fptr, const char *name); bool addSlotImpl(GenericMFPtr fptr, const char *name);
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const; SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
SignalBase *findSignalImpl(const char *name) const; SignalBase *findSignalImpl(const char *name) const;
GenericMFPtr *findSlotImpl(const char *name) const; GenericMFPtr *findSlotImpl(const char *name) const;
friend class boost::serialization::access; friend class boost::serialization::access;
friend class ObjectPrivate; friend class ObjectPrivate;
class ObjectPrivate *d; class ObjectPrivate *d;
}; };
} // namespace uLib
} // uLib
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//std::ostream & operator << (std::ostream &os, uLib::Object &ob); // std::ostream & operator << (std::ostream &os, uLib::Object &ob);
//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); // std::istream & operator >> (std::istream &is, uLib::Object &ob);
#endif // U_OBJECT_H #endif // U_OBJECT_H

View File

@@ -1,278 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <boost/algorithm/string/replace.hpp>
#include <Core/Mpl.h>
#include <Core/Types.h>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// 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<char*>(props())+offset); */ \
return *props()->ptr<ObjectProps>(); } \
typedef uLib::mpl::bool_<true>::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 <class T>
struct IsA : has_propable_trait<T> {};
/** Lambda to get Props member type */
template <class T>
struct props_type {
typedef typename T::ObjectProps type;
};
template <typename T>
struct get_props {
/** CFList has result but this method check for has BaseList */
typedef typename detail::TypeIntrospection::child_first<T>::type CFTypeList;
/** Filter List items that have not Propable feature */
typedef typename mpl::filter_view< CFTypeList, IsA<mpl::_> >::type FilteredCFTypeList;
/** Get Props from each Parent in Seq */
typedef typename mpl::transform_view< FilteredCFTypeList, props_type<mpl::_> >::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<T>::Childs CFBaseList;
/** Filter Parents that have not Propable feature */
typedef typename mpl::filter_view< CFBaseList, IsA<mpl::_> >::type FilteredCFBaseList;
};
// TODO: convert to pp const value,
// (non so se sia possibile con il dinamic casting intanto funziona cosi' )
template <typename T1, typename T2>
static unsigned int measure_offset(T1 base, T2 derived) {
return reinterpret_cast<char*>(derived) - reinterpret_cast<char*>(base);
}
struct initializer {
template <class _ObjectT>
struct lambda_init_object {
_ObjectT *o;
lambda_init_object(_ObjectT *o) : o(o) {}
template<class T> 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 <class T>
static void init_object_baselist(T *o) {
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFBaseList CFBaseList;
mpl::for_each<CFBaseList>(lambda_init_object<T>(o));
}
/**
* This calls the internal init_properties() virtual function only if
* object is propable ( implementation if not propable )
*/
template <class T>
static
typename boost::enable_if<mpl::not_<IsA<T> >,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 <class T>
static
typename boost::enable_if<IsA<T>,void>::type
init_object(T *o) {
o->init_properties();
}
};
template <class ThisClass, class Archive>
struct serialize_baselist {
ThisClass & m_object;
Archive & m_ar;
serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
// T is taken fron get_props<BaseList>::FilteredPList types to get
// type_info_name that is the type name defined by Type macro
typedef typename props_type<T>::type PType;
std::string name(TypeIntrospection::access<T>::type_info::name);
boost::algorithm::replace_all(name,"::","_");
m_ar & boost::serialization::make_nvp(
name.c_str() ,
boost::serialization::base_object<PType>(m_object));
}
};
};
} // detail
struct ObjectPropsBase {
virtual ~ObjectPropsBase() {}
virtual ObjectPropsBase *copy() = 0;
template <class T> inline T *ptr() { return dynamic_cast<T*>(this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {}
};
template <class T>
struct ObjectPropsImpl :
ObjectPropsBase,
ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props<T>::type)
{
typedef ObjectPropsImpl<T> ThisClass;
typedef typename uLib::detail::ObjectProps::get_props<T>::type CFList;
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFTypeList FilteredCFTypeList;
ObjectPropsBase *copy() { return new ThisClass(*this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
boost::serialization::void_cast_register<ThisClass,ObjectPropsBase>();
mpl::for_each<FilteredCFTypeList>(detail::ObjectProps::serialize_baselist<ThisClass,ArchiveT>(*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 <class T> inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr<typename T::ObjectProps>(); else exit(1); }
template <class T> inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr<typename T::ObjectProps>(); else return NULL; }
protected:
ObjectPropsBase *props() const { return m_props; }
template <class T> inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl<T>; }
/** NOT working dynamic cache casting */
template <class T> inline unsigned int props_offset(T *ptr) const
{ if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr<T>()); else return -1; }
template<class ArchiveT> 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

View File

@@ -31,6 +31,9 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
//class boost::program_options::error_with_option_name; //class boost::program_options::error_with_option_name;
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>(); //template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
@@ -74,6 +77,23 @@ void Options::parse_config_file(const char *fname)
} }
} }
void Options::save_config_file(const char *fname) {
std::ofstream os;
os.open(fname);
using boost::property_tree::ptree;
ptree root;
std::cout << m_configuration << "\n";
std::cout << m_global << "\n";
write_ini( std::cout, root );
}
bool Options::count(const char *str) const bool Options::count(const char *str) const
{ {
return (m_vm.count(str)); return (m_vm.count(str));

View File

@@ -160,6 +160,8 @@ public:
void parse_config_file(const char *fname); void parse_config_file(const char *fname);
void save_config_file(const char *fname);
template <typename T> template <typename T>
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) { static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v); boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_SERIALIZABLE_H #ifndef U_SERIALIZABLE_H
#define U_SERIALIZABLE_H #define U_SERIALIZABLE_H
@@ -38,9 +36,6 @@ TODO:
*/ */
#include <boost/serialization/access.hpp> #include <boost/serialization/access.hpp>
#include <boost/serialization/export.hpp> #include <boost/serialization/export.hpp>
@@ -48,26 +43,22 @@ TODO:
#include <boost/mpl/remove_if.hpp> #include <boost/mpl/remove_if.hpp>
#include <boost/serialization/nvp.hpp> #include <boost/serialization/nvp.hpp>
//#include <boost/archive/xml_iarchive.hpp> // #include <boost/archive/xml_iarchive.hpp>
//#include <boost/archive/xml_oarchive.hpp> // #include <boost/archive/xml_oarchive.hpp>
//#include <boost/archive/text_iarchive.hpp> // #include <boost/archive/text_iarchive.hpp>
//#include <boost/archive/text_oarchive.hpp> // #include <boost/archive/text_oarchive.hpp>
//#include "boost/archive/polymorphic_iarchive.hpp" // #include "boost/archive/polymorphic_iarchive.hpp"
//#include "boost/archive/polymorphic_oarchive.hpp" // #include "boost/archive/polymorphic_oarchive.hpp"
#include <boost/preprocessor/comma_if.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/comma_if.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/tuple/to_seq.hpp> #include <boost/preprocessor/tuple/to_seq.hpp>
#include "Core/Mpl.h"
#include "Core/ObjectProps.h"
#include "Core/Archives.h" #include "Core/Archives.h"
#include "Core/Export.h" #include "Core/Export.h"
#include "Core/Mpl.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -80,63 +71,47 @@ namespace serialization {
// ACCESS 2 // // ACCESS 2 //
template <class T> struct access2 {}; template <class T> struct access2 {};
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------ // NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
template<class T> template <class T> class hrp : public wrapper_traits<const hrp<T>> {
class hrp : const char *m_name;
public wrapper_traits<const hrp< T > > T *m_value;
{ std::string *m_str;
const char *m_name;
T *m_value;
std::string *m_str;
public: public:
explicit hrp(const char * name_, T &t) : explicit hrp(const char *name_, T &t)
m_str(new std::string), : m_str(new std::string), m_name(name_), m_value(&t) {}
m_name(name_), m_value(&t) {}
const char * name() const { const char *name() const { return this->m_name; }
return this->m_name;
}
template <class Archivex>
template<class Archivex> void save(Archivex &ar, const unsigned int /* file_version */) const {
void save( Archivex & ar, const unsigned int /* file_version */) const { //// ar.operator<<(const_value());
//// ar.operator<<(const_value()); // std::stringstream ss;
// std::stringstream ss; // uLib::Archive::hrt_oarchive har(ss);
// uLib::Archive::hrt_oarchive har(ss); // har << make_nvp(m_name,*m_value);
// har << make_nvp(m_name,*m_value); // // (*m_str) = ss.str();
// // (*m_str) = ss.str(); //// ar.operator << (make_nvp(m_name, ss.str());
//// ar.operator << (make_nvp(m_name, ss.str()); }
} template <class Archivex>
template<class Archivex> void load(Archivex &ar, const unsigned int /* file_version */) {
void load( Archivex & ar, const unsigned int /* file_version */) { // ar.operator>>(value());
// ar.operator>>(value()); }
} BOOST_SERIALIZATION_SPLIT_MEMBER()
BOOST_SERIALIZATION_SPLIT_MEMBER()
}; };
template <class T>
template<class T>
inline inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const const
#endif #endif
hrp< T > make_hrp(const char * name, T & t){ hrp<T> make_hrp(const char *name, T &t) {
return hrp< T >(name, t); return hrp<T>(name, t);
} }
#define HRP(name) \ #define HRP(name) boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
} // serialization
} // boost
} // namespace serialization
} // namespace boost
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -151,9 +126,7 @@ hrp< T > make_hrp(const char * name, T & t){
namespace uLib { namespace uLib {
#define _AR_OP(r, data, elem) data &BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
#define NVP(data) BOOST_SERIALIZATION_NVP(data) #define NVP(data) BOOST_SERIALIZATION_NVP(data)
@@ -166,51 +139,53 @@ namespace uLib {
// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED // SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT #ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT #define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__) #define ULIB_SERIALIZE_OBJECT(_Ob, ...) \
# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob, __VA_ARGS__)
#define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
#else #else
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \ #define ULIB_SERIALIZABLE(_Ob) \
ULIB_CLASS_EXPORT_KEY(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) ULIB_CLASS_EXPORT_KEY(_Ob)
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__) #define ULIB_SERIALIZE(_Ob, ...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \ #define ULIB_SERIALIZE_DERIVED(_Ob, ...) \
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob, __VA_ARGS__)
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__) #define ULIB_SERIALIZABLE_OBJECT(_Ob) \
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name) ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name) #define ULIB_SERIALIZE_OBJECT(_Ob, ...) \
_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob, __VA_ARGS__)
#define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
#define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
#endif #endif
#define ULIB_SERIALIZE_ACCESS \
friend class boost::serialization::access; \
template <class T> friend class boost::serialization::access2;
#define ULIB_SERIALIZE_ACCESS \ #define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \
friend class boost::serialization::access; \ BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass)
template <class T> friend class boost::serialization::access2;
#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \ #define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \
BOOST_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)
#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 */ /** 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(_Base, _Derived) \
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data) 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)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -220,38 +195,57 @@ namespace uLib {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) // // INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) //
#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name); #define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar &BOOST_SERIALIZATION_NVP(name);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \ #define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class, Archive) \
template void Class::serialize(Archive &ar,const unsigned int); 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_SERIALIZE_FUNC_OP(r, data, elem) \
_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data, elem);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
typedef boost::mpl::bool_<true> serializable; \
typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \
void PrintSerializableListId() { boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); } \
template <class ArchiveT> void serialize(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void serialize_parents(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
template <class ArchiveT> 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 <class ArchiveT> 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<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \
{ ::new(o)_Ob(); o->init_parameters(); } }}\
template <class ArchiveT> void _Ob::save_override(ArchiveT &ar, const unsigned int version)
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
typedef boost::mpl::bool_<true> serializable; \
typedef boost::mpl::remove_if<TypeList, IsUnSerializable>::type \
SerilizableTypeList; \
void PrintSerializableListId() { \
boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); \
} \
template <class ArchiveT> \
void serialize(ArchiveT &ar, const unsigned int version); \
template <class ArchiveT> \
void serialize_parents(ArchiveT &ar, const unsigned int version); \
template <class ArchiveT> \
void save_override(ArchiveT &ar, const unsigned int version);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob, ...) \
template <class ArchiveT> \
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 <class ArchiveT> \
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 <class ArchiveT> \
inline void load_construct_data(ArchiveT &ar, _Ob *o, \
const unsigned int file_version) { \
::new (o) _Ob(); \
o->init_parameters(); \
} \
} \
} \
template <class ArchiveT> \
void _Ob::save_override(ArchiveT &ar, const unsigned int version)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -261,152 +255,171 @@ namespace uLib {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// UNINTRUSIVE SERIALIZATION // UNINTRUSIVE SERIALIZATION
#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object<elem>(ob)); #define _UNAR_OP(r, data, elem) \
ar &boost::serialization::make_nvp( \
BOOST_PP_STRINGIZE(elem), boost::serialization::base_object<elem>(ob));
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \ #define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class, Archive) \
template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i); 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)
#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 // NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
// different implementation // different implementation
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \ #define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
namespace boost { namespace serialization { \ namespace boost { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \ namespace serialization { \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \ template <class ArchiveT> \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }} void serialize(ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> \
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \ void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int version); \
namespace boost { namespace serialization { \ template <> struct access2<_Ob> { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \ template <class ArchiveT> \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \ static void save_override(ArchiveT &ar, _Ob &ob, \
serialize_parents(ar,ob,version); \ const unsigned int 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 <class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \
template <class ArchiveT> void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \
template <class ArchiveT> 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 <class ArchiveT> 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<class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> 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 <class ArchiveT> 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)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \
namespace boost { \
namespace serialization { \
template <class ArchiveT> \
void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \
template <class ArchiveT> \
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 <class ArchiveT> \
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 <class ArchiveT> \
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 <class ArchiveT> \
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 <class ArchiveT> \
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 <class ArchiveT> \
void serialize(ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> \
void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2<_Ob> { \
template <class ArchiveT> \
static void save_override(ArchiveT &ar, _Ob &ob, \
const unsigned int version); \
}; \
} \
}
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob, ...) \
namespace boost { \
namespace serialization { \
template <class ArchiveT> \
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 <class ArchiveT> \
inline void load_construct_data(ArchiveT &ar, _Ob *ob, \
const unsigned int file_version) { \
::new (ob) _Ob(); \
} \
template <class ArchiveT> \
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 <class ArchiveT> \
void boost::serialization::access2<_Ob>::save_override( \
ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) \
boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), ob.name)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace detail { namespace detail {
struct Serializable { struct Serializable {
/** /**
* Serializable trait to check if an object type is serializable. * Serializable trait to check if an object type is serializable.
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive * This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
* cases a has_serialize trait should be implemented * cases a has_serialize trait should be implemented
*/ */
template <class T> template <class T> struct serializable_trait : mpl::bool_<false> {};
struct serializable_trait : mpl::bool_<false> {};
/**
* IsA Serializable Implementation Template
*/
template <class T>
struct IsA : serializable_trait<T> {};
template <class ThisClass, class Archive>
struct serialize_baseobject {
ThisClass & m_object;
Archive & m_ar;
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
m_ar & boost::serialization::make_nvp(
typeid(T).name() ,
boost::serialization::base_object<T>(m_object));
}
};
/**
* IsA Serializable Implementation Template
*/
template <class T> struct IsA : serializable_trait<T> {};
template <class ThisClass, class Archive> struct serialize_baseobject {
ThisClass &m_object;
Archive &m_ar;
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
m_ar &boost::serialization::make_nvp(
typeid(T).name(), boost::serialization::base_object<T>(m_object));
}
};
}; };
} // namespace detail
} // detail
struct Serializable { struct Serializable {
friend class boost::serialization::access; friend class boost::serialization::access;
template <class T> friend class boost::serialization::access2; template <class T> friend class boost::serialization::access2;
virtual ~Serializable() {} virtual ~Serializable() {}
protected: protected:
}; };
} // namespace uLib
} // uLib
#endif // U_SERIALIZABLE_H #endif // U_SERIALIZABLE_H

View File

@@ -23,21 +23,19 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SIGNAL_H #ifndef U_CORE_SIGNAL_H
#define U_CORE_SIGNAL_H #define U_CORE_SIGNAL_H
#include <boost/typeof/typeof.hpp> #include <boost/typeof/typeof.hpp>
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#include <boost/signals2/slot.hpp>
#include <boost/signals2/signal_type.hpp> #include <boost/signals2/signal_type.hpp>
#include <boost/signals2/slot.hpp>
#include "Function.h" #include "Function.h"
#include <boost/bind/bind.hpp>
using namespace boost::placeholders;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -48,12 +46,15 @@
#define slots #define slots
#define signals /*virtual void init_signals();*/ public #define signals /*virtual void init_signals();*/ public
#define emit #define emit
#define SLOT(a) BOOST_STRINGIZE(a) #define SLOT(a) BOOST_STRINGIZE(a)
#define SIGNAL(a) BOOST_STRINGIZE(a) #define SIGNAL(a) BOOST_STRINGIZE(a)
#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \ #define _ULIB_DETAIL_SIGNAL_EMIT(_name, ...) \
static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \ do { \
sig->operator()(__VA_ARGS__); BOOST_AUTO(sig, this->findOrAddSignal(&_name)); \
if (sig) \
sig->operator()(__VA_ARGS__); \
} while (0)
/** /**
* Utility macro to implement signal emission implementa una delle seguenti: * Utility macro to implement signal emission implementa una delle seguenti:
@@ -66,103 +67,101 @@
* // cast automatico // * // cast automatico //
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0)); * static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
* sig->operator()(); * sig->operator()();
*/ */
#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__) #define ULIB_SIGNAL_EMIT(_name, ...) \
_ULIB_DETAIL_SIGNAL_EMIT(_name, __VA_ARGS__)
namespace uLib { namespace uLib {
// A boost::signal wrapper structure /////////////////////////////////////////// // A boost::signal wrapper structure ///////////////////////////////////////////
// TODO ... // TODO ...
typedef boost::signals2::signal_base SignalBase; typedef boost::signals2::signal_base SignalBase;
template <typename T> template <typename T> struct Signal {
struct Signal { typedef boost::signals2::signal<T> type;
typedef boost::signals2::signal<T> type;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace detail { namespace detail {
template <typename FuncT, typename SigSignature, int arity>
template <typename FuncT, int arity>
struct ConnectSignal {}; struct ConnectSignal {};
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 0 > { struct ConnectSignal<FuncT, SigSignature, 0> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(slof); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(slof);
}
}; };
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 1 > { struct ConnectSignal<FuncT, SigSignature, 1> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver)); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver));
}
}; };
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 2 > { struct ConnectSignal<FuncT, SigSignature, 2> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1)); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver, _1));
}
}; };
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 3 > { struct ConnectSignal<FuncT, SigSignature, 3> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2)); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2));
}
}; };
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 4 > { struct ConnectSignal<FuncT, SigSignature, 4> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3)); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2, _3));
}
}; };
template <typename FuncT> template <typename FuncT, typename SigSignature>
struct ConnectSignal< FuncT, 5 > { struct ConnectSignal<FuncT, SigSignature, 5> {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) { static void connect(SignalBase *sigb, FuncT slof,
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT; typename FunctionPointer<FuncT>::Object *receiver) {
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4)); typedef typename Signal<SigSignature>::type SigT;
} reinterpret_cast<SigT *>(sigb)->connect(
boost::bind(slof, receiver, _1, _2, _3, _4));
}
}; };
} // namespace detail
} // detail template <typename FuncT> SignalBase *NewSignal(FuncT f) {
return new
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type;
template <typename FuncT>
SignalBase *NewSignal(FuncT f) {
// seems to work wow !
return new Signal<void()>::type;
} }
template <typename FuncT> template <typename SigSignature, typename FuncT>
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) void ConnectSignal(SignalBase *sigb, FuncT slof,
{ typename FunctionPointer<FuncT>::Object *receiver) {
detail::ConnectSignal< FuncT, FunctionPointer<FuncT>::arity >::connect(sigb,slof,receiver); detail::ConnectSignal<FuncT, SigSignature,
FunctionPointer<FuncT>::arity>::connect(sigb, slof,
receiver);
} }
} // namespace uLib
} // uLib
#endif // SIGNAL_H #endif // SIGNAL_H

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_TYPES_H #ifndef U_CORE_TYPES_H
#define U_CORE_TYPES_H #define U_CORE_TYPES_H
@@ -33,253 +31,182 @@
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
//#include <ltk/ltktypes.h> // #include <ltk/ltktypes.h>
#include "Core/Macros.h" #include "Core/Macros.h"
#include "Core/Mpl.h" #include "Core/Mpl.h"
namespace uLib { namespace uLib {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace detail { namespace detail {
struct TypeIntrospection { struct TypeIntrospection {
// BOOST IMPL // // BOOST IMPL //
BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info) BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
// SFINAE IMPL // // SFINAE IMPL //
/* /*
template <typename T> template <typename T>
struct has_type_info { struct has_type_info {
typedef char yes[1]; typedef char yes[1];
typedef char no[2]; typedef char no[2];
template <typename U> static yes& test(typename U::type_info::BaseList*); template <typename U> static yes& test(typename U::type_info::BaseList*);
template <typename > static no& test(...); template <typename > static no& test(...);
// struct apply { // struct apply {
static const bool value = sizeof(test<T>(0)) == sizeof(yes); static const bool value = sizeof(test<T>(0)) == sizeof(yes);
typedef boost::mpl::bool_<value> type; typedef boost::mpl::bool_<value> type;
// }; // };
}; };
*/ */
/** IsA Introspectable Object Implementation Template */ /** IsA Introspectable Object Implementation Template */
template <class T> template <class T> struct IsIntrospectable : has_type_info<T> {};
struct IsIntrospectable : has_type_info<T> {};
template <typename T> struct access { template <typename T> struct access {
typedef typename T::type_info type_info; typedef typename T::type_info type_info;
};
template <typename T> struct child_first_impl {
template <class T1, bool cond> struct lambda_CFList_f {
typedef mpl::vector<T1> type;
}; };
template <typename T> template <class T1> struct lambda_CFList_f<T1, true> {
struct child_first_impl { // typedef typename T1::type_info::CFList type;
typedef typename access<T1>::type_info::CFList type;
template <class T1, bool cond>
struct lambda_CFList_f {
typedef mpl::vector<T1> type;
};
template <class T1>
struct lambda_CFList_f<T1,true> {
// typedef typename T1::type_info::CFList type;
typedef typename access<T1>::type_info::CFList type;
};
template <class T1>
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
/** Transforms all Base Type into proper CFList */
typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
, lambda_CFList<mpl::_>
>::type CFListSeq;
/** Folds each CFList into a new sequence */
typedef typename mpl::fold< CFListSeq
, mpl::vector<>
, mpl::copy< mpl::_1
, mpl::back_inserter<mpl::_2>
>
>::type Childs;
/** Add This Class to final CFList sequence */
typedef typename mpl::copy< Childs
, mpl::back_inserter< mpl::vector<T> >
>::type type;
}; };
template <class T1>
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
/** /** Transforms all Base Type into proper CFList */
* Tests if T has a member called type_info then compile type CFList typedef
*/ typename mpl::transform_view<typename access<T>::type_info::BaseList,
template <typename T> lambda_CFList<mpl::_>>::type CFListSeq;
struct child_first : mpl::if_< has_type_info<T>
, child_first_impl<T>
, mpl::vector<>
>::type {};
/** Folds each CFList into a new sequence */
typedef typename mpl::fold<
CFListSeq, mpl::vector<>,
mpl::copy<mpl::_1, mpl::back_inserter<mpl::_2>>>::type Childs;
/** Add This Class to final CFList sequence */
typedef typename mpl::copy<Childs, mpl::back_inserter<mpl::vector<T>>>::type
type;
};
/**
* Tests if T has a member called type_info then compile type CFList
*/
template <typename T>
struct child_first
: mpl::if_<has_type_info<T>, child_first_impl<T>, mpl::vector<>>::type {};
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TYPE ADAPTERS // FINIRE !!! // TYPE ADAPTERS // FINIRE !!!
//#define _REPETITION_V(vz,vn,vdata) // #define _REPETITION_V(vz,vn,vdata)
//template < class TypeList >
//class TypeAdapterInputInterface {
// virtual ~TypeAdapterInputInterface() {}
//public:
// template < class TypeList >
// class TypeAdapterInputInterface {
// virtual ~TypeAdapterInputInterface() {}
// public:
// virtual void operator()(int val) {} // virtual void operator()(int val) {}
// virtual void operator()(std::string val) {} // virtual void operator()(std::string val) {}
//}; //};
} // namespace detail
} // detail ////////////////////////////////////////////////////////////////////
#define CONSTEXPR BOOST_CONSTEXPR #define CONSTEXPR BOOST_CONSTEXPR
// typedef ltk::Real_t Real_t;
//typedef ltk::Real_t Real_t;
#ifndef LTK_DOUBLE_PRECISION #ifndef LTK_DOUBLE_PRECISION
typedef float Real_t; typedef float Real_t;
#else #else
typedef double Real_t; typedef double Real_t;
#endif #endif
//typedef ltk::Id_t Id_t; // typedef ltk::Id_t Id_t;
typedef id_t Id_t; typedef id_t Id_t;
////typedef ltk::Size_t Size_t; ////typedef ltk::Size_t Size_t;
//typedef ltk::Pointer_t Pointer_t; // typedef ltk::Pointer_t Pointer_t;
typedef void * Pointer_t; typedef void *Pointer_t;
typedef bool Bool_t; //Boolean (0=false, 1=true) (bool) typedef bool Bool_t; // Boolean (0=false, 1=true) (bool)
//--- bit manipulation --------------------------------------------------------- //--- bit manipulation ---------------------------------------------------------
#ifndef BIT #ifndef BIT
#define BIT(n) (1ULL << (n)) #define BIT(n) (1ULL << (n))
#endif #endif
#ifndef SETBIT #ifndef SETBIT
#define SETBIT(n,i) ((n) |= BIT(i)) #define SETBIT(n, i) ((n) |= BIT(i))
#endif #endif
#ifndef CLRBIT #ifndef CLRBIT
#define CLRBIT(n,i) ((n) &= ~BIT(i)) #define CLRBIT(n, i) ((n) &= ~BIT(i))
#endif #endif
#ifndef TESTBIT #ifndef TESTBIT
#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0)) #define TESTBIT(n, i) ((Bool_t)(((n) & BIT(i)) != 0))
#endif #endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TYPE INTROSPECTION FOR OBJECTS // // TYPE INTROSPECTION FOR OBJECTS //
#define uLibTypeMacro(thisClass, ...) \
\
#define uLibTypeMacro(thisClass,...) \ /* Friendship detail for accessing introspection */ \
\ template <typename> friend class uLib::detail::TypeIntrospection::access; \
/* Friendship detail for accessing introspection */ \ \
template <typename> friend class uLib::detail::TypeIntrospection::access; \ /* type info structure*/ public: \
\ /* in GCC 4.8 must be public or dynamic_cast wont work */ \
/* type info structure*/ public: \ struct type_info { \
/* in GCC 4.8 must be public or dynamic_cast wont work */ \ /*WARNING: -std=c++0x required for this! */ \
struct type_info { \ constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
/*WARNING: -std=c++0x required for this! */ \ typedef BOOST_PP_VARIADIC_ELEM(0, __VA_ARGS__) BaseClass; \
constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \ typedef thisClass ThisClass; \
typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \ typedef uLib::mpl::vector<__VA_ARGS__, thisClass> TypeList; \
typedef thisClass ThisClass; \ typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \ typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type \
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \ CFList; \
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \ }; \
}; \ \
\ public: \
public: \ typedef type_info::BaseClass BaseClass; \
typedef type_info::BaseClass BaseClass; \ virtual const char *type_name() const { return type_info::name; } \
virtual const char *type_name() const { return type_info::name; } \ /**/
/* Object Props fwd declaration*/ \
struct ObjectProps; \
/**/
/** /**
* TypeList inheritance introspection * TypeList inheritance introspection
*/ */
struct TypeIntrospection { struct TypeIntrospection {
template <typename T> template <typename T>
struct child_first : detail::TypeIntrospection::child_first<T> {}; struct child_first : detail::TypeIntrospection::child_first<T> {};
}; };
// SISTEMARE // // SISTEMARE //
struct PrintTypeId { struct PrintTypeId {
template <class T> template <class T> void operator()(T) const {
void operator()(T) const std::cout << typeid(T).name() << std::endl;
{ std::cout << typeid(T).name() << std::endl; } }
template <typename SeqT> template <typename SeqT> static void PrintMplSeq(SeqT *p = NULL) {
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); } boost::mpl::for_each<SeqT>(PrintTypeId());
}
template <typename Class> template <typename Class> static void PrintType(Class *p = NULL) {
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; } std::cout << typeid(Class).name() << std::endl;
}
}; };
} // namespace uLib
} // uLib
#endif // U_CORE_TYPES_H #endif // U_CORE_TYPES_H

View File

@@ -16,18 +16,17 @@ set( TESTS
SerializeTest SerializeTest
SerializeDreadDiamondTest SerializeDreadDiamondTest
DreadDiamondParameters DreadDiamondParameters
ObjectPropableTest
UuidTest UuidTest
TypeIntrospectionTraversal TypeIntrospectionTraversal
OptionsTest OptionsTest
PingPongTest
) )
set(LIBRARIES set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
${Boost_SERIALIZATION_LIBRARY} Boost::serialization
${Boost_SIGNALS_LIBRARY} Boost::program_options
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
) )
uLib_add_tests(${uLib-module}) uLib_add_tests(Core)

View File

@@ -19,7 +19,6 @@ TESTS = SmartPointerTest \
SerializeTest \ SerializeTest \
SerializeDreadDiamondTest \ SerializeDreadDiamondTest \
DreadDiamondParameters \ DreadDiamondParameters \
ObjectPropableTest \
TypeIntrospectionTraversal \ TypeIntrospectionTraversal \
OptionsTest OptionsTest

View File

@@ -1,237 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#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;
}

View File

@@ -0,0 +1,52 @@
#include "Core/Object.h"
#include "Core/Signal.h"
#include "testing-prototype.h"
#include <iostream>
using namespace uLib;
class Ping : public Object {
public:
signals:
void PingSignal(int count);
public slots:
void OnPong(int count) {
std::cout << "Ping received Pong " << count << std::endl;
if (count > 0)
ULIB_SIGNAL_EMIT(Ping::PingSignal, count - 1);
}
};
void Ping::PingSignal(int count) { ULIB_SIGNAL_EMIT(Ping::PingSignal, count); }
class Pong : public Object {
public:
signals:
void PongSignal(int count);
public slots:
void OnPing(int count) {
std::cout << "Pong received Ping " << count << std::endl;
if (count > 0)
ULIB_SIGNAL_EMIT(Pong::PongSignal, count - 1);
}
};
void Pong::PongSignal(int count) { ULIB_SIGNAL_EMIT(Pong::PongSignal, count); }
int main() {
BEGIN_TESTING(PingPong);
Ping ping;
Pong pong;
std::cout << "Connecting ping to pong" << std::endl;
Object::connect(&ping, &Ping::PingSignal, &pong, &Pong::OnPing);
std::cout << "Connecting pong to ping" << std::endl;
Object::connect(&pong, &Pong::PongSignal, &ping, &Ping::OnPong);
std::cout << "Emitting PingSignal(5)" << std::endl;
ping.PingSignal(5);
END_TESTING;
return 0;
}

View File

@@ -23,13 +23,10 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream> #include <fstream>
#include <typeinfo> #include <iostream>
#include <string> #include <string>
#include <typeinfo>
#include "Core/Object.h" #include "Core/Object.h"
@@ -37,78 +34,43 @@
using namespace uLib; using namespace uLib;
struct A : Object {
uLibTypeMacro(A, Object) A() : numa(5552368) {}
int numa;
struct A : Object {
uLibTypeMacro(A,Object)
A() : numa(5552368) {}
int numa;
}; };
ULIB_SERIALIZABLE_OBJECT(A) ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) { ULIB_SERIALIZE_OBJECT(A, Object) { ar &AR(numa); }
ar & AR(numa);
}
struct B : virtual Object { struct B : virtual Object {
uLibTypeMacro(B,Object) uLibTypeMacro(B, Object) B() : numb(5552369) {}
B() : numb(5552369) {} int numb;
int numb;
}; };
ULIB_SERIALIZABLE_OBJECT(B) ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); } ULIB_SERIALIZE_OBJECT(B, Object) { ar &AR(numb); }
struct C : B { struct C : B {
uLibTypeMacro(C,B) uLibTypeMacro(C, B) C() : numc(5552370) {}
C() : numc(5552370) {} int numc;
int numc;
}; };
ULIB_SERIALIZABLE_OBJECT(C) ULIB_SERIALIZABLE_OBJECT(C)
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); } ULIB_SERIALIZE_OBJECT(C, B) { ar &AR(numc); }
struct D : A,B { struct D : A, B {
uLibTypeMacro(D,A,B) uLibTypeMacro(D, A, B)
D() : numd(5552371) {} D()
int numd; : numd(5552371) {}
int numd;
}; };
ULIB_SERIALIZABLE_OBJECT(D) ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); } ULIB_SERIALIZE_OBJECT(D, A, B) { ar &AR(numd); }
int main() {
A o;
Archive::xml_oarchive(std::cout) << NVP(o);
main() {
A o; o.init_properties();
Archive::xml_oarchive(std::cout) << NVP(o);
} }

View File

@@ -23,20 +23,16 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include "Core/Object.h"
#include "Core/Archives.h" #include "Core/Archives.h"
#include "Core/Object.h"
#include "testing-prototype.h" #include "testing-prototype.h"
using namespace uLib; using namespace uLib;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -45,63 +41,51 @@ using namespace uLib;
struct V3f { struct V3f {
float x,y,z; float x, y, z;
V3f() V3f() { x = y = z = 0; }
{ x = y = z =0; }
V3f(float x, float y, float z) : V3f(float x, float y, float z) : x(x), y(y), z(z) {}
x(x), y(y), z(z) {}
template <class Archive> template <class Archive> void serialize(Archive &ar, unsigned int v) {
void serialize (Archive &ar,unsigned int v) { ar & "<" & NVP(x) & NVP(y) & NVP(z) & ">";
ar }
& "<" & NVP(x) & NVP(y) & NVP(z) & ">";
}
}; };
ULIB_CLASS_EXPORT_KEY(V3f); ULIB_CLASS_EXPORT_KEY(V3f);
ULIB_CLASS_EXPORT_IMPLEMENT(V3f); ULIB_CLASS_EXPORT_IMPLEMENT(V3f);
inline std::ostream &operator<<(std::ostream &o, const V3f &v) {
inline std::ostream & Archive::hrt_oarchive(o) << v;
operator <<(std::ostream &o, const V3f &v) { return o;
Archive::hrt_oarchive(o) << v;
return o;
} }
inline std::istream & inline std::istream &operator>>(std::istream &is, V3f &v) {
operator >>(std::istream &is, V3f &v) { Archive::hrt_iarchive(is) >> v;
Archive::hrt_iarchive(is) >> v; return is;
return is;
} }
int test_V3f() { int test_V3f() {
// testing human readble archive with simple serializable structure // // testing human readble archive with simple serializable structure //
V3f v1(1,2,3),v2,v3,v4; V3f v1(1, 2, 3), v2, v3, v4;
std::cout << "v --> " << v1 << "\n"; std::cout << "v --> " << v1 << "\n";
std::stringstream ss; ss << v1; std::stringstream ss;
std::cout << "ss.v --> " << ss.str() << "\n"; ss << v1;
std::cout << "ss.v --> " << ss.str() << "\n";
Archive::hrt_iarchive ar(ss); ar >> v2; Archive::hrt_iarchive ar(ss);
std::cout << "v2 --> " << v2 << "\n"; ar >> v2;
std::cout << "v2 --> " << v2 << "\n";
std::stringstream("<2 3 4>") >> v3; std::stringstream("<2 3 4>") >> v3;
std::cout << "v3 --> " << v3 << "\n"; std::cout << "v3 --> " << v3 << "\n";
// std::cout << "insert V3f string to parse: "; std::cin >> v4; // std::cout << "insert V3f string to parse: "; std::cin >> v4;
// std::cout << "v4 --> " << v4 << "\n"; // std::cout << "v4 --> " << v4 << "\n";
return (1); return (1);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -109,104 +93,72 @@ int test_V3f() {
// OBJECT SERIALIZATION // // OBJECT SERIALIZATION //
class A : public virtual Object { class A : public virtual Object {
uLibTypeMacro(A,Object) uLibTypeMacro(A, Object) ULIB_SERIALIZE_ACCESS public : A() : m_a(5552368) {}
ULIB_SERIALIZE_ACCESS
public:
A() : m_a(5552368) {}
properties() { void init_properties();
std::string p_a; std::string p_a;
};
uLibRefMacro(a, int);
uLibRefMacro (a,int);
private: private:
int m_a; int m_a;
}; };
void A::init_properties() { void A::init_properties() { p_a = "A property string"; }
$_init();
$$.p_a = "A property string";
}
ULIB_SERIALIZABLE_OBJECT(A) ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) { ULIB_SERIALIZE_OBJECT(A, Object) {
ar ar & "Object A : " & "--> m_a = " & AR(m_a) & "\n" & "Object A properties: " &
& "Object A : " "---> p_a = " & AR(p_a) & "\n";
& "--> 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() { int testing_xml_class() {
A a; a.init_properties(); A a;
a.init_properties();
{ {
std::ofstream file("test.xml"); std::ofstream file("test.xml");
Archive::xml_oarchive(file) << NVP(a); Archive::xml_oarchive(file) << NVP(a);
} }
a.a() = 0; a.a() = 0;
a.$$.p_a = "zero string"; a.p_a = "zero string";
{ {
std::ifstream file("test.xml"); std::ifstream file("test.xml");
Archive::xml_iarchive(file) >> NVP(a); Archive::xml_iarchive(file) >> NVP(a);
} }
Archive::xml_oarchive(std::cout) << NVP(a); Archive::xml_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); return (a.a() == 5552368 && a.p_a == "A property string");
} }
int testing_hrt_class() { int testing_hrt_class() {
A a; a.init_properties(); A a;
a.init_properties();
{ {
std::ofstream file("test.xml"); std::ofstream file("test.xml");
Archive::hrt_oarchive(file) << NVP(a); Archive::hrt_oarchive(file) << NVP(a);
} }
a.a() = 0; a.a() = 0;
a.$$.p_a = "zero string"; a.p_a = "zero string";
{ {
// ERRORE FIX ! // ERRORE FIX !
// std::ifstream file("test.xml"); // std::ifstream file("test.xml");
// Archive::hrt_iarchive(file) >> NVP(a); // Archive::hrt_iarchive(file) >> NVP(a);
} }
Archive::hrt_oarchive(std::cout) << NVP(a); Archive::hrt_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" ); return (a.a() == 5552368 && a.p_a == "A property string");
} }
int main() { int main() {
BEGIN_TESTING(Serialize Test); BEGIN_TESTING(Serialize Test);
TEST1( test_V3f() ); TEST1(test_V3f());
TEST1( testing_xml_class() ); TEST1(testing_xml_class());
// testing_hrt_class(); ///// << ERRORE in HRT with properties // testing_hrt_class(); ///// << ERRORE in HRT with properties
END_TESTING; END_TESTING;
} }

View File

@@ -23,93 +23,63 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h" #include "Core/Object.h"
#include "Core/Signal.h" #include "Core/Signal.h"
#include "Core/Types.h"
#include "testing-prototype.h"
using namespace uLib; using namespace uLib;
class Ob1 : public Object { class Ob1 : public Object {
public: public:
signals: signals:
void V0(); void V0();
int V1(int a);
void V1(int a);
}; };
// should be done by moc // // should be done by moc //
void Ob1::V0() { void Ob1::V0() { ULIB_SIGNAL_EMIT(Ob1::V0); }
ULIB_SIGNAL_EMIT(Ob1::V0);
}
int Ob1::V1(int a) {
ULIB_SIGNAL_EMIT(Ob1::V1,a);
}
void Ob1::V1(int a) { ULIB_SIGNAL_EMIT(Ob1::V1, a); }
class Ob2 : public Object { class Ob2 : public Object {
public slots: public slots:
void PrintV0() { void PrintV0() { std::cout << "Ob2 prints V0\n" << std::flush; }
std::cout << "Ob2 prints V0\n" << std::flush;
}
}; };
class Ob3 : public Object { class Ob3 : public Object {
public slots: public slots:
void PrintV0() { void PrintV0() { std::cout << "Ob3 prints V0\n" << std::flush; }
std::cout << "Ob3 prints V0\n" << std::flush;
}
void PrintNumber(int n) { void PrintNumber(int n) {
std::cout << "Ob3 is printing number: " << n << "\n"; std::cout << "Ob3 is printing number: " << n << "\n";
} }
}; };
int main() { int main() {
BEGIN_TESTING(Signals); BEGIN_TESTING(Signals);
Ob1 ob1; Ob1 ob1;
Ob2 ob2; Ob2 ob2;
Ob3 ob3; Ob3 ob3;
Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0); Object::connect(&ob1, &Ob1::V0, &ob2, &Ob2::PrintV0);
Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0); Object::connect(&ob1, &Ob1::V0, &ob3, &Ob3::PrintV0);
Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber); Object::connect(&ob1, &Ob1::V1, &ob3, &Ob3::PrintNumber);
// not working yet // not working yet
// Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0()) // Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0())
ob1.PrintSelf(std::cout); ob1.PrintSelf(std::cout);
emit ob1.V0(); emit ob1.V0();
emit ob1.V1(5552368); emit ob1.V1(5552368);
END_TESTING; END_TESTING;
} }

View File

@@ -23,90 +23,73 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream> #include <iostream>
#include "testing-prototype.h" #include "testing-prototype.h"
#include <Core/StaticInterface.h> #include <Core/StaticInterface.h>
namespace uLib { namespace uLib {
//// INTERFACE TO COMPLEX CLASS ///// //// INTERFACE TO COMPLEX CLASS /////
namespace Interface { namespace Interface {
struct Test { struct Test {
MAKE_TRAITS MAKE_TRAITS
template<class Self> void check_structural() { template <class Self> void check_structural() {
uLibCheckFunction(Self,test,bool,int,float); uLibCheckFunction(Self, test, bool, int, float);
uLibCheckMember(Self,testmemb,int); uLibCheckMember(Self, testmemb, int);
} }
}; };
} } // namespace Interface
struct Test { struct Test {
bool test(int i, float f){} bool test(int i, float f) { return true; }
int testmemb; int testmemb;
}; };
//// INTERFAC TO SIMPLE CLASS /////////// //// INTERFAC TO SIMPLE CLASS ///////////
namespace Interface { namespace Interface {
struct Simple { struct Simple {
MAKE_TRAITS MAKE_TRAITS
template<class Self> void check_structural() { template <class Self> void check_structural() {
uLibCheckMember(Self,memb1,int); uLibCheckMember(Self, memb1, int);
uLibCheckMember(Self,memb2,float); uLibCheckMember(Self, memb2, float);
} }
}; };
} } // namespace Interface
struct Simple { struct Simple {
int memb1; int memb1;
float memb2; float memb2;
}; };
///////////////////////// /////////////////////////
template <class T> template <class T> class UseTest {
class UseTest {
public: public:
UseTest() { UseTest() {
Interface::IsA<T,Interface::Test>(); Interface::IsA<T, Interface::Test>();
T t; T t;
int i; float f; int i;
t.test(i,f); float f;
} t.test(i, f);
}
}; };
template <class T> template <class T> class UseSimple {
class UseSimple {
public: public:
UseSimple() { UseSimple() { Interface::IsA<T, Interface::Simple>(); }
Interface::IsA<T,Interface::Simple>();
}
}; };
} // namespace uLib
int main() {
BEGIN_TESTING(Static Interface);
uLib::UseTest<uLib::Test> u;
uLib::UseSimple<uLib::Simple> s;
END_TESTING;
} }
int main()
{
BEGIN_TESTING(Static Interface);
uLib::UseTest<uLib::Test> u;
uLib::UseSimple<uLib::Simple> s;
END_TESTING;
}

View File

@@ -2,5 +2,11 @@ set(HEADERS MuonScatter.h MuonError.h MuonEvent.h)
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE) set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
install(FILES ${HEADERS} install(FILES ${HEADERS}
DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Detectors) DESTINATION ${INSTALL_INC_DIR}/Detectors)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -1,18 +1,15 @@
# TESTS # TESTS
set( TESTS set( TESTS
GDMLSolidTest # GDMLSolidTest
HierarchicalEncodingTest HierarchicalEncodingTest
) )
#set(LIBRARIES set(LIBRARIES
# ${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
# ${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
# ${PACKAGE_LIBPREFIX}Detectors Boost::serialization
# ${Boost_SERIALIZATION_LIBRARY} Boost::program_options
# ${Boost_SIGNALS_LIBRARY} Eigen3::Eigen
# ${Boost_PROGRAM_OPTIONS_LIBRARY} ${ROOT_LIBRARIES}
# ${Eigen_LIBRARY} )
# ${Geant4_LIBRARIES} uLib_add_tests(Detectors)
# ${ROOT_LIBRARIES}
#)
uLib_add_tests(${uLib-module})

View File

@@ -1,35 +0,0 @@
# 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

View File

@@ -1,18 +0,0 @@
#-------------------------------------------------
#
# 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

View File

@@ -1,453 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.4.1, 2012-09-03T09:43:56. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QString" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QString" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">System</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">1</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Target.DesktopTarget</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 4.7.4 for GCC (Qt SDK) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">3</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 4.7.4 for GCC (Qt SDK) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">3</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 in PATH (System) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">4</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.3">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 in PATH (System) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">4</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.4">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 (System) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">5</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.5">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 (System) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">5</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">6</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">No deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">false</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">false</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">QVTKViewport2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">QVTKViewport2.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">false</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QString">{f8bb0047-7f6e-45df-9cc8-e746abebf883}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">10</value>
</data>
</qtcreator>

View File

@@ -1,38 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <QtGui/QApplication>
#include "vtkviewport.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
VtkViewport w;
w.show();
return a.exec();
}

View File

@@ -1,41 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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;
}

View File

@@ -1,49 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <QWidget>
namespace Ui {
class VtkViewport;
}
class VtkViewport : public QWidget
{
Q_OBJECT
public:
explicit VtkViewport(QWidget *parent = 0);
~VtkViewport();
private:
Ui::VtkViewport *ui;
};
#endif // VTKVIEWPORT_H

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VtkViewport</class>
<widget class="QWidget" name="VtkViewport">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>536</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>140</x>
<y>170</y>
<width>161</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Hello World !</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -27,6 +27,8 @@
#ifndef U_MATH_BITCODE_H #ifndef U_MATH_BITCODE_H
#define U_MATH_BITCODE_H #define U_MATH_BITCODE_H
#include <iostream>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/mpl/vector_c.hpp> #include <boost/mpl/vector_c.hpp>
@@ -34,6 +36,7 @@
#include <Math/Dense.h> #include <Math/Dense.h>
namespace uLib { namespace uLib {

View File

@@ -1,3 +1,4 @@
set(HEADERS ContainerBox.h set(HEADERS ContainerBox.h
Dense.h Dense.h
Geometry.h Geometry.h
@@ -31,8 +32,9 @@ set(SOURCES VoxRaytracer.cpp
Structured2DGrid.cpp Structured2DGrid.cpp
Structured4DGrid.cpp) Structured4DGrid.cpp)
set(LIBRARIES ${Eigen_LIBRARY} set(LIBRARIES Eigen3::Eigen
${ROOT_LIBRARIES}) ${ROOT_LIBRARIES}
${VTK_LIBRARIES})
set(libname ${PACKAGE_LIBPREFIX}Math) set(libname ${PACKAGE_LIBPREFIX}Math)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE) set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -44,10 +46,16 @@ set_target_properties(${libname} PROPERTIES
SOVERSION ${PROJECT_SOVERSION}) SOVERSION ${PROJECT_SOVERSION})
target_link_libraries(${libname} ${LIBRARIES}) target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname} install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib) LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Math) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

232
src/Math/DataAllocator.h Normal file
View File

@@ -0,0 +1,232 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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_DATAALLOCATOR_H
#define U_MATH_DATAALLOCATOR_H
#include <algorithm>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <vector>
#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif
namespace uLib {
enum class MemoryDevice { RAM, VRAM };
template <typename T> class DataAllocator {
public:
DataAllocator()
: m_Size(0), m_RamData(nullptr), m_VramData(nullptr),
m_Device(MemoryDevice::RAM) {}
DataAllocator(size_t size)
: m_Size(size), m_RamData(new T[size]()), m_VramData(nullptr),
m_Device(MemoryDevice::RAM) {}
DataAllocator(const DataAllocator<T> &other)
: m_Size(other.m_Size), m_RamData(nullptr), m_VramData(nullptr),
m_Device(other.m_Device) {
if (m_Size > 0) {
if (other.m_RamData) {
m_RamData = new T[m_Size];
std::memcpy(m_RamData, other.m_RamData, m_Size * sizeof(T));
}
#ifdef USE_CUDA
if (other.m_VramData) {
cudaMalloc((void **)&m_VramData, m_Size * sizeof(T));
cudaMemcpy(m_VramData, other.m_VramData, m_Size * sizeof(T),
cudaMemcpyDeviceToDevice);
}
#endif
}
}
~DataAllocator() {
if (m_RamData) {
delete[] m_RamData;
}
#ifdef USE_CUDA
if (m_VramData) {
cudaFree(m_VramData);
}
#endif
}
DataAllocator &operator=(const DataAllocator &other) {
if (this != &other) {
resize(other.m_Size);
m_Device = other.m_Device;
if (other.m_RamData) {
if (!m_RamData)
m_RamData = new T[m_Size];
std::memcpy(m_RamData, other.m_RamData, m_Size * sizeof(T));
}
#ifdef USE_CUDA
if (other.m_VramData) {
if (!m_VramData)
cudaMalloc((void **)&m_VramData, m_Size * sizeof(T));
cudaMemcpy(m_VramData, other.m_VramData, m_Size * sizeof(T),
cudaMemcpyDeviceToDevice);
}
#endif
}
return *this;
}
void MoveToRAM() {
if (m_Device == MemoryDevice::RAM)
return;
if (!m_RamData && m_Size > 0)
m_RamData = new T[m_Size]();
#ifdef USE_CUDA
if (m_VramData && m_Size > 0) {
cudaMemcpy(m_RamData, m_VramData, m_Size * sizeof(T),
cudaMemcpyDeviceToHost);
}
#endif
m_Device = MemoryDevice::RAM;
}
void MoveToVRAM() {
if (m_Device == MemoryDevice::VRAM)
return;
#ifdef USE_CUDA
if (!m_VramData && m_Size > 0) {
cudaMalloc((void **)&m_VramData, m_Size * sizeof(T));
}
if (m_RamData && m_Size > 0) {
cudaMemcpy(m_VramData, m_RamData, m_Size * sizeof(T),
cudaMemcpyHostToDevice);
}
#endif
m_Device = MemoryDevice::VRAM;
}
void resize(size_t size) {
if (m_Size == size)
return;
T *newRam = nullptr;
T *newVram = nullptr;
if (size > 0) {
newRam = new T[size]();
if (m_RamData) {
std::memcpy(newRam, m_RamData, std::min(m_Size, size) * sizeof(T));
}
#ifdef USE_CUDA
cudaMalloc((void **)&newVram, size * sizeof(T));
if (m_VramData) {
cudaMemcpy(newVram, m_VramData, std::min(m_Size, size) * sizeof(T),
cudaMemcpyDeviceToDevice);
}
#endif
}
if (m_RamData)
delete[] m_RamData;
#ifdef USE_CUDA
if (m_VramData)
cudaFree(m_VramData);
#endif
m_Size = size;
m_RamData = newRam;
m_VramData = newVram;
}
size_t size() const { return m_Size; }
T &at(size_t index) {
MoveToRAM();
if (index >= m_Size)
throw std::out_of_range("Index out of range");
return m_RamData[index];
}
const T &at(size_t index) const {
const_cast<DataAllocator *>(this)->MoveToRAM();
if (index >= m_Size)
throw std::out_of_range("Index out of range");
return m_RamData[index];
}
T &operator[](size_t index) {
MoveToRAM();
return m_RamData[index];
}
const T &operator[](size_t index) const {
const_cast<DataAllocator *>(this)->MoveToRAM();
return m_RamData[index];
}
T *data() { return (m_Device == MemoryDevice::RAM) ? m_RamData : m_VramData; }
const T *data() const {
return (m_Device == MemoryDevice::RAM) ? m_RamData : m_VramData;
}
T *GetRAMData() { return m_RamData; }
const T *GetRAMData() const { return m_RamData; }
T *GetVRAMData() { return m_VramData; }
const T *GetVRAMData() const { return m_VramData; }
MemoryDevice GetDevice() const { return m_Device; }
// Iterator support for RAM operations
T *begin() {
MoveToRAM();
return m_RamData;
}
T *end() {
MoveToRAM();
return m_RamData + m_Size;
}
const T *begin() const {
const_cast<DataAllocator *>(this)->MoveToRAM();
return m_RamData;
}
const T *end() const {
const_cast<DataAllocator *>(this)->MoveToRAM();
return m_RamData + m_Size;
}
private:
size_t m_Size;
T *m_RamData;
T *m_VramData;
MemoryDevice m_Device;
};
} // namespace uLib
#endif // U_MATH_DATAALLOCATOR_H

View File

@@ -23,9 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
/* /*
* <one line to give the program's name and a brief idea of what it does.> * <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2012 Andrea Rigoni Garola <andrea@pcimg05> * Copyright (C) 2012 Andrea Rigoni Garola <andrea@pcimg05>
@@ -47,7 +44,6 @@
* *
*/ */
#ifndef ULIB_DENSEMATRIX_H #ifndef ULIB_DENSEMATRIX_H
#define ULIB_DENSEMATRIX_H #define ULIB_DENSEMATRIX_H
@@ -55,27 +51,29 @@
#include <Eigen/Dense> #include <Eigen/Dense>
//// BOOST SERIALIZATION /////////////////////////////////////////////////////// //// BOOST SERIALIZATION ///////////////////////////////////////////////////////
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/array.hpp> #include <boost/serialization/array.hpp>
#include <boost/serialization/string.hpp>
namespace boost { namespace boost {
namespace serialization { namespace serialization {
template<class Archive, class Scalar, int RowsAtCompileTime, int ColsAtCompileTime> template <class Archive, class Scalar, int RowsAtCompileTime,
void serialize(Archive & ar, ::Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> & m, const unsigned int /*version*/) { int ColsAtCompileTime>
ar & boost::serialization::make_array(m.data(), RowsAtCompileTime * ColsAtCompileTime); void serialize(Archive &ar,
::Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> &m,
const unsigned int /*version*/) {
ar &boost::serialization::make_array(m.data(),
RowsAtCompileTime * ColsAtCompileTime);
} }
} // serialization } // namespace serialization
} // boost } // namespace boost
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -84,178 +82,163 @@ void serialize(Archive & ar, ::Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCo
// this is needed by boost::lexical_cast to cope with Eigens Vectors /////////// // this is needed by boost::lexical_cast to cope with Eigens Vectors ///////////
namespace Eigen { namespace Eigen {
template <typename T, int size> template <typename T, int size>
std::istream & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) { std::istream &operator>>(std::istream &is, Eigen::Matrix<T, size, 1> &vec) {
std::string str; std::string str;
for( unsigned int i=0; i<size; i++) { for (unsigned int i = 0; i < size; i++) {
is >> std::skipws; is >> std::skipws;
is >> str; is >> str;
if(is.fail()) vec(i) = 0; if (is.fail())
else vec(i) = boost::lexical_cast<T>(str); vec(i) = 0;
} else
return is; vec(i) = boost::lexical_cast<T>(str);
}
return is;
} }
template <typename T, int size> template <typename T, int size>
std::ostream & operator << (std::ostream &os, const Eigen::Matrix<T,size,1> &vec) { std::ostream &operator<<(std::ostream &os,
os << vec.transpose(); const Eigen::Matrix<T, size, 1> &vec) {
return os; os << vec.transpose();
return os;
} }
} // Eigen } // namespace Eigen
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace uLib { namespace uLib {
typedef id_t Id_t; typedef id_t Id_t;
typedef int Scalari; typedef int Scalari;
typedef unsigned int Scalarui; typedef unsigned int Scalarui;
typedef long Scalarl; typedef long Scalarl;
typedef unsigned long Scalarul; typedef unsigned long Scalarul;
typedef float Scalarf; typedef float Scalarf;
typedef double Scalard; typedef double Scalard;
typedef Eigen::Matrix<int, 1, 1> Matrix1i;
typedef Eigen::Matrix<int,1,1> Matrix1i;
typedef Eigen::Matrix2i Matrix2i; typedef Eigen::Matrix2i Matrix2i;
typedef Eigen::Matrix3i Matrix3i; typedef Eigen::Matrix3i Matrix3i;
typedef Eigen::Matrix4i Matrix4i; typedef Eigen::Matrix4i Matrix4i;
typedef Eigen::Matrix<float,1,1> Matrix1f; typedef Eigen::Matrix<float, 1, 1> Matrix1f;
typedef Eigen::Matrix2f Matrix2f; typedef Eigen::Matrix2f Matrix2f;
typedef Eigen::Matrix3f Matrix3f; typedef Eigen::Matrix3f Matrix3f;
typedef Eigen::Matrix4f Matrix4f; typedef Eigen::Matrix4f Matrix4f;
typedef Eigen::Matrix<int,1,1> Vector1i; typedef Eigen::Matrix<int, 1, 1> Vector1i;
typedef Eigen::Vector2i Vector2i; typedef Eigen::Vector2i Vector2i;
typedef Eigen::Vector3i Vector3i; typedef Eigen::Vector3i Vector3i;
typedef Eigen::Vector4i Vector4i; typedef Eigen::Vector4i Vector4i;
typedef Eigen::Matrix<float,1,1> Vector1f; typedef Eigen::Matrix<float, 1, 1> Vector1f;
typedef Eigen::Vector2f Vector2f; typedef Eigen::Vector2f Vector2f;
typedef Eigen::Vector3f Vector3f; typedef Eigen::Vector3f Vector3f;
typedef Eigen::Vector4f Vector4f; typedef Eigen::Vector4f Vector4f;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Vector String interaction /////////////////////////////////////////////////// // Vector String interaction ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/*! Given a string consisting of a series of doubles with some /*! Given a string consisting of a series of doubles with some
* delimiter, return an Eigen::Vector populated with those * delimiter, return an Eigen::Vector populated with those
* values, in the same order as they are given in the string. * values, in the same order as they are given in the string.
* *
* \param vec A double vector to be populated with the results * \param vec A double vector to be populated with the results
* \param str A string to be parsed as a series of doubles. * \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 * \param delim Delimiters of the text (a typical default is " ," for comma and
* * space-delimited text
*/ *
*/
template <typename T, int size> template <typename T, int size>
void VectorxT_StringTo(Eigen::Matrix<T,size,1> &vec, std::string str, const char *delim = " ,;\t\n") { void VectorxT_StringTo(Eigen::Matrix<T, size, 1> &vec, std::string str,
std::vector<std::string> strvec; const char *delim = " ,;\t\n") {
std::vector<std::string> strvec;
boost::algorithm::trim_if( str, boost::algorithm::is_any_of(delim)); 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); boost::algorithm::split(strvec, str, boost::algorithm::is_any_of(delim),
boost::algorithm::token_compress_on);
for( unsigned int i=0; i<size; i++) { for (unsigned int i = 0; i < size; i++) {
vec(i) = boost::lexical_cast<T>(strvec[i]); vec(i) = boost::lexical_cast<T>(strvec[i]);
} }
} }
template <typename T, int size> template <typename T, int size>
std::string VectorxT_ToString(const Eigen::Matrix<T,size,1> &vec) { std::string VectorxT_ToString(const Eigen::Matrix<T, size, 1> &vec) {
std::stringstream sst; std::stringstream sst;
sst << vec.transpose(); sst << vec.transpose();
return sst.str(); return sst.str();
} }
// template <typename T, int size>
//template <typename T, int size> // Eigen::Matrix<T,size,1> & operator >> (std::istream &is,
//Eigen::Matrix<T,size,1> & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) { // Eigen::Matrix<T,size,1> &vec) {
//} // }
template <typename T, int size> template <typename T, int size>
void operator>> (std::string& str, Eigen::Matrix<T,size,1> &vec){ void operator>>(std::string &str, Eigen::Matrix<T, size, 1> &vec) {
VectorxT_StringTo(vec,str); VectorxT_StringTo(vec, str);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS VECTORS ////////////////////////////////////////////////// ////// HOMOGENEOUS VECTORS //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <bool p> template <bool p> class _HPoint3f : public Eigen::Matrix<Scalarf, 4, 1> {
class _HPoint3f : public Eigen::Matrix< Scalarf,4,1 > {
public: public:
typedef Eigen::Matrix< Scalarf,4,1 > BaseClass; typedef Eigen::Matrix<Scalarf, 4, 1> BaseClass;
_HPoint3f<p>() : BaseClass(0,0,0,p) {} _HPoint3f() : BaseClass(0, 0, 0, p) {}
_HPoint3f<p>(float x,float y,float z) : BaseClass(x,y,z,p) {} _HPoint3f(float x, float y, float z) : BaseClass(x, y, z, p) {}
_HPoint3f<p>(Vector3f &in) : BaseClass(in.homogeneous()) { this->operator()(3) = p; } _HPoint3f(Vector3f &in) : BaseClass(in.homogeneous()) {
this->operator()(3) = p;
}
void operator delete(void* _p, size_t _s) {} void operator delete(void *_p, size_t _s) {}
// This constructor allows to construct MyVectorType from Eigen expressions // This constructor allows to construct MyVectorType from Eigen expressions
template<typename OtherDerived> template <typename OtherDerived>
inline _HPoint3f<p>(const Eigen::MatrixBase<OtherDerived>& other) inline _HPoint3f(const Eigen::MatrixBase<OtherDerived> &other)
: BaseClass(other) : BaseClass(other) {}
{ }
// This method allows to assign Eigen expressions to Vector3H
template<typename OtherDerived>
inline _HPoint3f<p> & operator= (const Eigen::MatrixBase <OtherDerived>& other)
{
this->BaseClass::operator=(other);
return *this;
}
// This method allows to assign Eigen expressions to Vector3H
template <typename OtherDerived>
inline _HPoint3f &operator=(const Eigen::MatrixBase<OtherDerived> &other) {
this->BaseClass::operator=(other);
return *this;
}
}; };
typedef _HPoint3f<false> HVector3f; typedef _HPoint3f<false> HVector3f;
typedef _HPoint3f<true> HPoint3f; typedef _HPoint3f<true> HPoint3f;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS LINE ////////////////////////////////////////////////// ////// HOMOGENEOUS LINE //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct _HLine3f {
struct _HLine3f HPoint3f origin;
{ HVector3f direction;
HPoint3f origin;
HVector3f direction;
}; };
typedef struct _HLine3f HLine3f; typedef struct _HLine3f HLine3f;
inline std::ostream& inline std::ostream &operator<<(std::ostream &stream, const HLine3f &line) {
operator<< (std::ostream& stream, const HLine3f &line) { stream << "HLine3f(" << "pt[" << line.origin.transpose() << "] , dr["
stream << "HLine3f(" << "pt[" << line.origin.transpose() <<"] , dr[" << line.direction.transpose() << "]) "; << line.direction.transpose() << "]) ";
return stream; return stream;
} }
struct _HError3f {
HVector3f position_error;
HVector3f direction_error;
struct _HError3f
{
HVector3f position_error;
HVector3f direction_error;
}; };
typedef struct _HError3f HError3f; typedef struct _HError3f HError3f;
inline std::ostream& inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) {
operator<< (std::ostream& stream, const HError3f &err) { stream << "HError3f(" << "ept[" << err.position_error.transpose()
stream << "HError3f(" << "ept[" << err.position_error.transpose() <<"] , edr[" << err.direction_error.transpose() << "]) "; << "] , edr[" << err.direction_error.transpose() << "]) ";
return stream; return stream;
}
} }
} // namespace uLib
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -269,13 +252,9 @@ ULIB_SERIALIZABLE(uLib::HPoint3f)
ULIB_SERIALIZABLE(uLib::HVector3f) ULIB_SERIALIZABLE(uLib::HVector3f)
ULIB_SERIALIZABLE(uLib::HLine3f) ULIB_SERIALIZABLE(uLib::HLine3f)
ULIB_SERIALIZABLE(uLib::HError3f) ULIB_SERIALIZABLE(uLib::HError3f)
#endif // ULIB_SERIALIZATION_ON #endif // ULIB_SERIALIZATION_ON
#endif // U_DENSEMATRIX_H
#endif // U_DENSEMATRIX_H

View File

@@ -110,6 +110,17 @@ public:
inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); } inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); }
inline void Rotate(const float angle, Vector3f axis)
{
axis.normalize(); // prehaps not necessary ( see eigens )
Eigen::AngleAxisf ax(angle,axis);
this->m_T.rotate(Eigen::Quaternion<float>(ax));
}
inline void Rotate(const Vector3f euler_axis) {
float angle = euler_axis.norm();
Rotate(angle,euler_axis);
}
inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); } inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); }

View File

@@ -30,6 +30,13 @@
#include "VoxImage.h" #include "VoxImage.h"
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkXMLImageDataReader.h>
#include <vtkXMLImageDataWriter.h>
#include <vtkStringArray.h>
#include <vtkInformation.h>
#include <vtkInformationStringKey.h>
namespace uLib { namespace uLib {
@@ -83,7 +90,103 @@ void Abstract::VoxImage::ExportToVtk (const char *file, bool density_type)
printf("%s vtk file saved\n",file); printf("%s vtk file saved\n",file);
} }
int Abstract::VoxImage::ImportFromVtk(const char *file)
void Abstract::VoxImage::ExportToVti (const char *file, bool density_type, bool compressed)
{
Abstract::VoxImage *voxels = this;
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
image->SetDimensions(voxels->GetDims()(0), voxels->GetDims()(1), voxels->GetDims()(2));
image->SetSpacing(voxels->GetSpacing()(0), voxels->GetSpacing()(1), voxels->GetSpacing()(2));
image->SetOrigin(voxels->GetPosition()(0), voxels->GetPosition()(1), voxels->GetPosition()(2));
image->AllocateScalars(VTK_FLOAT, 1);
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);
size_t npoints = nx*ny*nz;
float *scalar = static_cast<float*>(image->GetScalarPointer());
StructuredData unwrap(*voxels);
unwrap.SetDataOrder(StructuredData::XYZ); // move to XYZ order (VTK)
for (size_t i = 0; i < npoints; i++) {
Vector3i idx = unwrap.UnMap(i);
scalar[i] = static_cast<float>(voxels->GetValue(idx) * norm);
}
// Create a custom string key
static vtkInformationStringKey* ConfigNote =
vtkInformationStringKey::MakeKey("cmt.config", "Config");
// Attach metadata
vtkInformation *info = image->GetInformation();
info->Set(ConfigNote,
"This image was generated with uLib\n"
"-----------------------------------\n"
"Author: Andrea Rigoni\n"
"Version: 0.1\n"
"Date: 2025\n"
);
// std::cout << info->Get(ConfigNote) << std::endl;
vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
writer->SetFileName(file);
writer->SetInputData(image);
if(compressed) {
writer->SetDataModeToBinary();
writer->SetCompressorTypeToZLib();
}
writer->Write();
}
int Abstract::VoxImage::ImportFromVti(const char *file, bool density_type) {
vtkSmartPointer<vtkXMLImageDataReader> reader = vtkSmartPointer<vtkXMLImageDataReader>::New();
reader->SetFileName(file);
reader->Update();
vtkImageData *image = reader->GetOutput();
if(!image) return false;
Abstract::VoxImage *voxels = this;
int nx = image->GetDimensions()[0];
int ny = image->GetDimensions()[1];
int nz = image->GetDimensions()[2];
voxels->SetDims(Vector3i(nx,ny,nz));
voxels->SetSpacing(Vector3f(image->GetSpacing()[0],image->GetSpacing()[1],image->GetSpacing()[2]));
voxels->SetPosition(Vector3f(image->GetOrigin()[0],image->GetOrigin()[1],image->GetOrigin()[2]));
float norm;
if (density_type) {
norm = 1;
} else norm = 1.E6;
size_t npoints = nx*ny*nz;
float *scalar = static_cast<float*>(image->GetScalarPointer());
StructuredData wrap(*voxels);
wrap.SetDataOrder(StructuredData::XYZ);
for (size_t i = 0; i < npoints; i++) {
Vector3i idx = wrap.UnMap(i);
voxels->SetValue(idx, scalar[i] / norm);
}
return true;
}
int Abstract::VoxImage::ImportFromVtk(const char *file, bool density_type)
{ {
FILE * vtk_file = fopen(file, "r"); FILE * vtk_file = fopen(file, "r");
if (!vtk_file) return false; if (!vtk_file) return false;
@@ -115,14 +218,18 @@ int Abstract::VoxImage::ImportFromVtk(const char *file)
this->SetSpacing(Vector3f(sx,sy,sz)); this->SetSpacing(Vector3f(sx,sy,sz));
this->SetPosition(Vector3f(ox,oy,oz)); this->SetPosition(Vector3f(ox,oy,oz));
float norm;
if (density_type) {
norm = 1;
} else norm = 1.E6;
for (int k = 0; k < dz; ++k) { for (int k = 0; k < dz; ++k) {
for (int j = 0; j < dy; ++j) { for (int j = 0; j < dy; ++j) {
for (int i = 0; i < dx; ++i) { for (int i = 0; i < dx; ++i) {
Vector3i idx(i, j, k); Vector3i idx(i, j, k);
float tmp_val; float tmp_val;
fscanf(vtk_file, "%f", &tmp_val); fscanf(vtk_file, "%f", &tmp_val);
//this->SetValue(idx,fabs(tmp_val)*1E-6); this->SetValue(idx,tmp_val / norm);
this->SetValue(idx,tmp_val*1E-6);
} }
} }
} }

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MATH_VOXIMAGE_H #ifndef U_MATH_VOXIMAGE_H
#define U_MATH_VOXIMAGE_H #define U_MATH_VOXIMAGE_H
@@ -36,6 +34,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <vector> #include <vector>
#include "Math/DataAllocator.h"
namespace uLib { namespace uLib {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -46,26 +46,36 @@ namespace Abstract {
class VoxImage : public uLib::StructuredGrid { class VoxImage : public uLib::StructuredGrid {
public: public:
typedef uLib::StructuredGrid BaseClass; typedef uLib::StructuredGrid BaseClass;
virtual float GetValue(const Vector3i &id) const = 0; virtual float GetValue(const Vector3i &id) const = 0;
virtual float GetValue(const int id) const = 0; virtual float GetValue(const int id) const = 0;
virtual void SetValue(const Vector3i &id, float value) = 0; virtual void SetValue(const Vector3i &id, float value) = 0;
virtual void SetValue(const int id, float value) = 0; virtual void SetValue(const int id, float value) = 0;
virtual void SetDims(const Vector3i &size) = 0; virtual void SetDims(const Vector3i &size) = 0;
void ExportToVtk(const char *file, bool density_type = 0); void ExportToVtk(const char *file, bool density_type = 0);
void ExportToVtkXml(const char *file, bool density_type = 0);
int ImportFromVtk(const char *file); // use this function to export to VTK binary format
void ExportToVti(const char *file, bool density_type = 0,
bool compressed = 0);
// this function has been deprecated in favor of ExportToVti
// but it is kept for backward compatibility and because it
// does not depend on vtk library
void ExportToVtkXml(const char *file, bool density_type = 0);
int ImportFromVtk(const char *file, bool density_type = 0);
int ImportFromVti(const char *file, bool density_type = 0);
protected: protected:
virtual ~VoxImage() {}
virtual ~VoxImage() {} VoxImage(const Vector3i &size) : BaseClass(size) {}
VoxImage(const Vector3i &size) : BaseClass(size) {}
}; };
} } // namespace Abstract
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// VOXEL //////////////////////////////////////////////////////////////////// // VOXEL ////////////////////////////////////////////////////////////////////
@@ -73,421 +83,415 @@ protected:
namespace Interface { namespace Interface {
struct Voxel { struct Voxel {
template<class Self> void check_structural() { template <class Self> void check_structural() {
uLibCheckMember(Self,Value, Scalarf); uLibCheckMember(Self, Value, Scalarf);
} }
}; };
} } // namespace Interface
struct Voxel { struct Voxel {
Scalarf Value; Scalarf Value;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// VOX IMAGE ///////////////////////////////////////////////////////////////// // VOX IMAGE /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename T> class VoxImage : public Abstract::VoxImage {
template< typename T >
class VoxImage : public Abstract::VoxImage {
public: public:
typedef Abstract::VoxImage BaseClass; typedef Abstract::VoxImage BaseClass;
VoxImage(); VoxImage();
VoxImage(const Vector3i &size); VoxImage(const Vector3i &size);
VoxImage(const VoxImage<T> &copy) : VoxImage(const VoxImage<T> &copy) : BaseClass(copy) {
BaseClass(copy) this->m_Data = copy.m_Data;
{ }
this->m_Data = copy.m_Data;
inline DataAllocator<T> &Data() { return this->m_Data; }
inline const DataAllocator<T> &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<T> clipImage(const Vector3i begin, const Vector3i end) const;
inline VoxImage<T> clipImage(const HPoint3f begin, const HPoint3f end) const;
inline VoxImage<T> clipImage(const float density) const;
inline VoxImage<T> clipImage(const float densityMin,
const float densityMax) const;
inline VoxImage<T> maskImage(const HPoint3f begin, const HPoint3f end,
float value) const;
inline VoxImage<T> maskImage(const float threshold, float belowValue = 0,
float aboveValue = 0) const;
inline VoxImage<T> fixVoxels(const float threshold, float tolerance) const;
inline VoxImage<T> fixVoxels(const float threshold, float tolerance,
const HPoint3f begin, const HPoint3f end) const;
inline VoxImage<T> fixVoxelsAroundPlane(const float threshold,
float tolerance, const HPoint3f begin,
const HPoint3f end,
bool aboveAir) const;
inline VoxImage<T> fixVoxels(const HPoint3f begin, const HPoint3f end) const;
inline VoxImage<T> 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 <typename S> void operator+=(VoxImage<S> &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;
} }
}
inline std::vector<T> & Data() { return this->m_Data; } template <typename S> void operator-=(VoxImage<S> &sibling) {
inline const std::vector<T>& ConstData() const { return m_Data; } if (this->GetDims() != sibling.GetDims()) {
// printf("Warning when subtracting VoxImages: I'm NOT doing it!\n");
inline const T& At(int i) const { return m_Data.at(i); } return;
inline const T& At(const Vector3i &id) const { return m_Data.at(Map(id)); } } // WARNING! You must Warn the user!
inline T& operator[](unsigned int i) { return m_Data[i]; } for (unsigned int i = 0; i < m_Data.size(); ++i) {
inline T& operator[](const Vector3i &id) { return m_Data[Map(id)]; } m_Data[i].Value -= sibling.At(i).Value;
// 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) { template <typename S> void operator*=(VoxImage<S> &sibling) {
this->operator [](id).Value = value; if (this->GetDims() != sibling.GetDims()) {
} // printf("Warning when multiplying VoxImages: I'm NOT doing it!\n");
inline void SetValue(const int id, float value) { return;
this->operator [](id).Value = value; } // WARNING! You must Warn the user!
for (unsigned int i = 0; i < m_Data.size(); ++i) {
m_Data[i].Value *= sibling.At(i).Value;
} }
}
inline void SetDims(const Vector3i &size) { template <typename S> void operator/=(VoxImage<S> &sibling) {
this->m_Data.resize(size.prod()); if (this->GetDims() != sibling.GetDims()) {
BaseClass::BaseClass::SetDims(size); // FIX horrible coding style ! // printf("Warning when dividing VoxImages: I'm NOT doing it!\n");
} return;
} // WARNING! You must Warn the user!
inline VoxImage<T> clipImage(const Vector3i begin, const Vector3i end) const; for (unsigned int i = 0; i < m_Data.size(); ++i) {
inline VoxImage<T> clipImage(const HPoint3f begin, const HPoint3f end) const; m_Data[i].Value /= sibling.At(i).Value;
inline VoxImage<T> clipImage(const float density) const;
inline VoxImage<T> clipImage(const float densityMin, const float densityMax) const;
inline VoxImage<T> maskImage(const HPoint3f begin, const HPoint3f end, float value) const;
inline VoxImage<T> maskImage(const float threshold, float belowValue=0, float aboveValue=0) const;
inline VoxImage<T> fixVoxels(const float threshold, float tolerance) const;
inline VoxImage<T> fixVoxels(const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end) const;
inline VoxImage<T> fixVoxelsAroundPlane(const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end, bool aboveAir) const;
inline VoxImage<T> fixVoxels(const HPoint3f begin, const HPoint3f end) const;
inline VoxImage<T> 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 <typename S>
void operator +=(VoxImage<S> &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 <typename S>
void operator -=(VoxImage<S> &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 <typename S>
void operator *=(VoxImage<S> &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 <typename S>
void operator /=(VoxImage<S> &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: private:
std::vector<T> m_Data; DataAllocator<T> m_Data;
}; };
template<typename T>
VoxImage<T>::VoxImage() :
m_Data(0),
BaseClass(Vector3i(0,0,0))
{ Interface::IsA <T,Interface::Voxel>(); /* structural check for T */ }
template<typename T>
VoxImage<T>::VoxImage(const Vector3i &size) :
m_Data(size.prod()),
BaseClass(size)
{ Interface::IsA <T,Interface::Voxel>(); /* structural check for T */ }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const Vector3i begin, const Vector3i end) const VoxImage<T>::VoxImage() : m_Data(0), BaseClass(Vector3i(0, 0, 0)) {
{ Interface::IsA<T, Interface::Voxel>(); /* structural check for T */
Vector3i dim = (end-begin)+Vector3i(1,1,1);
VoxImage<T> out(*this);
out.SetDims(dim);
out.SetPosition(this->GetPosition() + this->GetSpacing().cwiseProduct(begin.cast<float>()) );
for(uint x = 0; x<dim(0); ++x )
for(uint y = 0; y<dim(1); ++y )
for(uint z = 0; z<dim(2); ++z )
{
Vector3i id = Vector3i(x,y,z);
out[id] = this->At(begin + id);
}
return out;
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const HPoint3f begin, const HPoint3f end) const VoxImage<T>::VoxImage(const Vector3i &size)
{ : m_Data(size.prod()), BaseClass(size) {
Vector3i v1 = this->Find(begin); Interface::IsA<T, Interface::Voxel>(); /* structural check for T */
Vector3i v2 = this->Find(end);
return this->clipImage(v1,v2);
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const float density) const VoxImage<T> VoxImage<T>::clipImage(const Vector3i begin,
{ const Vector3i end) const {
Vector3i v1 = this->GetDims(); Vector3i dim = (end - begin) + Vector3i(1, 1, 1);
Vector3i v2 = Vector3i(0,0,0); VoxImage<T> out(*this);
for(uint i=0; i< this->m_Data.size(); ++i) { out.SetDims(dim);
if( this->GetValue(i) >= density ) { out.SetPosition(this->GetPosition() +
Vector3i id = this->UnMap(i); this->GetSpacing().cwiseProduct(begin.cast<float>()));
v1 = v1.array().min(id.array());
v2 = v2.array().max(id.array()); for (uint x = 0; x < dim(0); ++x)
} for (uint y = 0; y < dim(1); ++y)
for (uint z = 0; z < dim(2); ++z) {
Vector3i id = Vector3i(x, y, z);
out[id] = this->At(begin + id);
}
return out;
}
template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const HPoint3f begin,
const HPoint3f end) const {
Vector3i v1 = this->Find(begin);
Vector3i v2 = this->Find(end);
return this->clipImage(v1, v2);
}
template <typename T>
VoxImage<T> VoxImage<T>::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); }
return this->clipImage(v1, v2);
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const float densityMin, const float densityMax) const VoxImage<T> VoxImage<T>::clipImage(const float densityMin,
{ const float densityMax) const {
Vector3i v1 = this->GetDims(); Vector3i v1 = this->GetDims();
Vector3i v2 = Vector3i(0,0,0); Vector3i v2 = Vector3i(0, 0, 0);
for(uint i=0; i< this->m_Data.size(); ++i) { for (uint i = 0; i < this->m_Data.size(); ++i) {
if( this->GetValue(i) >= densityMin && this->GetValue(i) <= densityMax) { if (this->GetValue(i) >= densityMin && this->GetValue(i) <= densityMax) {
Vector3i id = this->UnMap(i); Vector3i id = this->UnMap(i);
v1 = v1.array().min(id.array()); v1 = v1.array().min(id.array());
v2 = v2.array().max(id.array()); v2 = v2.array().max(id.array());
}
} }
return this->clipImage(v1,v2); }
return this->clipImage(v1, v2);
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::maskImage(const HPoint3f begin, const HPoint3f end, float value) const VoxImage<T> VoxImage<T>::maskImage(const HPoint3f begin, const HPoint3f end,
{ float value) const {
VoxImage<T> out(*this); VoxImage<T> out(*this);
out.SetDims(this->GetDims()); out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition()); out.SetPosition(this->GetPosition());
Vector3i voxB = this->Find(begin); Vector3i voxB = this->Find(begin);
Vector3i voxE = this->Find(end); Vector3i voxE = this->Find(end);
Vector3i ID; Vector3i ID;
for(int ix=voxB(0); ix<voxE(0); ix++) for (int ix = voxB(0); ix < voxE(0); ix++)
for(int iy=voxB(1); iy<voxE(1); iy++) for (int iy = voxB(1); iy < voxE(1); iy++)
for(int iz=voxB(2); iz<voxE(2); iz++){ for (int iz = voxB(2); iz < voxE(2); iz++) {
ID << ix,iy,iz; ID << ix, iy, iz;
out.SetValue(ID,value*1.E-6); out.SetValue(ID, value * 1.E-6);
} }
return out; return out;
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue, float aboveValue) const VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue,
{ float aboveValue) const {
std::cout << "VoxImage: maskImage, fixing voxels under threshold " << threshold; std::cout << "VoxImage: maskImage, fixing voxels under threshold "
if(belowValue) << threshold;
std::cout << " at value " << belowValue; if (belowValue)
else std::cout << " at value " << belowValue;
std::cout << " at -value"; else
std::cout << ", voxels above threshold at value "; std::cout << " at -value";
if(aboveValue) std::cout << ", voxels above threshold at value ";
std::cout << aboveValue; if (aboveValue)
else std::cout << aboveValue;
std::cout << "found"; else
std::cout << "found";
VoxImage<T> out(*this);
out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition());
VoxImage<T> out(*this); for (uint i = 0; i < this->m_Data.size(); ++i) {
out.SetDims(this->GetDims()); // skip negative voxels: they are already frozen
out.SetPosition(this->GetPosition()); if (this->GetValue(i) >= 0) {
// voxels under threshold
for(uint i=0; i< this->m_Data.size(); ++i) { if (this->GetValue(i) <= threshold * 1.E-6) {
// skip negative voxels: they are already frozen if (belowValue) {
if( this->GetValue(i) >= 0 ){ // std::cout << "vox " << i << ", " <<
// voxels under threshold // this->GetValue(i); std::cout << " ----> set to " <<
if( this->GetValue(i) <= threshold*1.E-6 ){ // -1.*belowValue*1.E-6 << std::endl;
if(belowValue){ out.SetValue(i, -1. * belowValue * 1.E-6);
// std::cout << "vox " << i << ", " << this->GetValue(i); } else
// std::cout << " ----> set to " << -1.*belowValue*1.E-6 << std::endl; out.SetValue(i, -1. * this->GetValue(i));
out.SetValue(i,-1.*belowValue*1.E-6);} }
else // voxels over threshold
out.SetValue(i,-1.*this->GetValue(i)); else {
} if (aboveValue)
// voxels over threshold out.SetValue(i, aboveValue * 1.E-6);
else{ else
if(aboveValue) out.SetValue(i, this->GetValue(i));
out.SetValue(i,aboveValue*1.E-6); }
else
out.SetValue(i,this->GetValue(i));
}
}
} }
return out; }
return out;
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::fixVoxels(const float threshold, float tolerance) const VoxImage<T> VoxImage<T>::fixVoxels(const float threshold,
{ float tolerance) const {
std::cout << "VoxImage: fixing voxels with value " << threshold << std::endl; std::cout << "VoxImage: fixing voxels with value " << threshold << std::endl;
VoxImage<T> out(*this); VoxImage<T> out(*this);
out.SetDims(this->GetDims()); out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition()); out.SetPosition(this->GetPosition());
for(uint i=0; i< this->m_Data.size(); ++i) { 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 <typename T> VoxImage<T> VoxImage<T>::Abs() const {
std::cout << "VoxImage: set abs voxels value " << std::endl;
VoxImage<T> 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 <typename T>
VoxImage<T> VoxImage<T>::fixVoxels(const float threshold, float tolerance,
const HPoint3f begin,
const HPoint3f end) const {
VoxImage<T> 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 < voxE(0); ix++)
for (int iy = voxB(1); iy < voxE(1); iy++)
for (int iz = voxB(2); iz < voxE(2); iz++) {
ID << ix, iy, iz;
// voxels around threshold // voxels around threshold
if( fabs(this->GetValue(i) - threshold*1.E-6) < tolerance* 1.E-6 ){ if (fabs(this->GetValue(ID) - threshold * 1.E-6) < tolerance * 1.E-6) {
// std::cout << "vox " << i << ", " << this->GetValue(i); out.SetValue(ID, -1. * this->GetValue(ID));
// std::cout << " ----> set to " << -1.*this->GetValue(i) << std::endl;
out.SetValue(i,-1.*this->GetValue(i));
} }
} }
return out;
return out;
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::Abs() const VoxImage<T> VoxImage<T>::fixVoxels(const HPoint3f begin,
{ const HPoint3f end) const {
std::cout << "VoxImage: set abs voxels value " << std::endl; VoxImage<T> out(*this);
out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition());
VoxImage<T> out(*this); Vector3i voxB = this->Find(begin);
out.SetDims(this->GetDims()); Vector3i voxE = this->Find(end);
out.SetPosition(this->GetPosition());
for(uint i=0; i< this->m_Data.size(); ++i) Vector3i ID;
out.SetValue(i,fabs(this->GetValue(i)));
return out; for (int ix = voxB(0); ix < voxE(0); ix++)
for (int iy = voxB(1); iy < voxE(1); iy++)
for (int iz = voxB(2); iz < voxE(2); iz++) {
ID << ix, iy, iz;
// voxels around threshold
out.SetValue(ID, -1. * this->GetValue(ID));
}
return out;
} }
template <typename T> template <typename T>
VoxImage<T> VoxImage<T>::fixVoxels( const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end) const VoxImage<T> VoxImage<T>::fixVoxelsAroundPlane(const float threshold,
{ float tolerance, const HPoint3f B,
VoxImage<T> out(*this); const HPoint3f E,
out.SetDims(this->GetDims()); bool aboveAir) const {
out.SetPosition(this->GetPosition()); VoxImage<T> out(*this);
Vector3i dim = this->GetDims();
out.SetDims(dim);
out.SetPosition(this->GetPosition());
Vector3i voxB = this->Find(begin); HPoint3f Bcoll = this->GetPosition().homogeneous();
Vector3i voxE = this->Find(end);
Vector3i ID; Vector3i ID;
for (int ix = 0; ix < dim(0); ix++)
for (int iy = 0; iy < dim(1); iy++)
for (int iz = 0; iz < dim(2); iz++) {
ID << ix, iy, iz;
for(int ix=voxB(0); ix<voxE(0); ix++) // B, E voxel position
for(int iy=voxB(1); iy<voxE(1); iy++) Vector3i iv(ix, iy, iz);
for(int iz=voxB(2); iz<voxE(2); iz++){ Vector3f v =
ID << ix,iy,iz; Vector3f(iv.cast<float>().cwiseProduct(this->GetSpacing()));
// voxels around threshold HPoint3f Bvox = Bcoll + HPoint3f(v);
if( fabs(this->GetValue(ID) - threshold*1.E-6) < tolerance*1.E-6 ){ HPoint3f Evox = Bvox + this->GetSpacing().homogeneous();
out.SetValue(ID,-1.*this->GetValue(ID)); HPoint3f V = Bvox + 0.5 * (this->GetSpacing().homogeneous());
}
}
return out; // 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 <typename T> template <typename T> void VoxImage<T>::InitVoxels(T t) {
VoxImage<T> VoxImage<T>::fixVoxels(const HPoint3f begin, const HPoint3f end) const std::fill(m_Data.begin(), m_Data.end(), t); // warning... stl function //
{
VoxImage<T> 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<voxE(0); ix++)
for(int iy=voxB(1); iy<voxE(1); iy++)
for(int iz=voxB(2); iz<voxE(2); iz++){
ID << ix,iy,iz;
// voxels around threshold
out.SetValue(ID,-1.*this->GetValue(ID));
}
return out;
} }
} // namespace uLib
template <typename T>
VoxImage<T> VoxImage<T>::fixVoxelsAroundPlane( const float threshold, float tolerance, const HPoint3f B, const HPoint3f E, bool aboveAir) const
{
VoxImage<T> 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<dim(0); ix++)
for(int iy=0; iy<dim(1); iy++)
for(int iz=0; iz<dim(2); iz++){
ID << ix,iy,iz;
// B, E voxel position
Vector3i iv(ix,iy,iz);
Vector3f v = Vector3f(iv.cast<float>().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<typename T>
void VoxImage<T>::InitVoxels(T t)
{
std::fill( m_Data.begin(), m_Data.end(), t ); // warning... stl function //
}
}
#endif // VOXIMAGE_H #endif // VOXIMAGE_H

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTER_H #ifndef VOXIMAGEFILTER_H
#define VOXIMAGEFILTER_H #define VOXIMAGEFILTER_H
@@ -33,96 +31,83 @@
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
namespace uLib { namespace uLib {
namespace Interface { namespace Interface {
struct VoxImageFilterShape { struct VoxImageFilterShape {
template <class Self> void check_structural() { template <class Self> void check_structural() {
uLibCheckFunction(Self,operator(),float,float); uLibCheckFunction(Self, operator(), float, float);
uLibCheckFunction(Self,operator(),float,const Vector3f&); uLibCheckFunction(Self, operator(), float, const Vector3f &);
} }
}; };
} } // namespace Interface
template < typename VoxelT > class Kernel;
template <typename VoxelT> class Kernel;
namespace Abstract { namespace Abstract {
class VoxImageFilter { class VoxImageFilter {
public: public:
virtual void Run() = 0; virtual void Run() = 0;
virtual void SetImage(Abstract::VoxImage *image) = 0; virtual void SetImage(Abstract::VoxImage *image) = 0;
protected: protected:
virtual ~VoxImageFilter() {} virtual ~VoxImageFilter() {}
}; };
} } // namespace Abstract
template <typename VoxelT, typename AlgorithmT>
template < typename VoxelT, typename AlgorithmT > class VoxImageFilter : public Abstract::VoxImageFilter {
class VoxImageFilter : public Abstract::VoxImageFilter
{
public: public:
VoxImageFilter(const Vector3i &size); VoxImageFilter(const Vector3i &size);
void Run(); void Run();
void SetKernelNumericXZY(const std::vector<float> &numeric); void SetKernelNumericXZY(const std::vector<float> &numeric);
void SetKernelSpherical(float (*shape)(float)); void SetKernelSpherical(float (*shape)(float));
template < class ShapeT > template <class ShapeT> void SetKernelSpherical(ShapeT shape);
void SetKernelSpherical( ShapeT shape );
void SetKernelWeightFunction(float (*shape)(const Vector3f &)); void SetKernelWeightFunction(float (*shape)(const Vector3f &));
template < class ShapeT > template <class ShapeT> void SetKernelWeightFunction(ShapeT shape);
void SetKernelWeightFunction( ShapeT shape );
inline Kernel<VoxelT> GetKernelData() const { return this->m_KernelData; } inline const Kernel<VoxelT> &GetKernelData() const {
return this->m_KernelData;
}
inline Kernel<VoxelT> &GetKernelData() { return this->m_KernelData; }
inline VoxImage<VoxelT>* GetImage() const { return this->m_Image; } inline VoxImage<VoxelT> *GetImage() const { return this->m_Image; }
void SetImage(Abstract::VoxImage *image); void SetImage(Abstract::VoxImage *image);
protected: protected:
float Convolve(const VoxImage<VoxelT> &buffer, int index); // remove //
float Convolve(const VoxImage<VoxelT> &buffer, int index); // remove // void SetKernelOffset();
void SetKernelOffset(); float Distance2(const Vector3i &v);
float Distance2(const Vector3i &v); // protected members for algorithm access //
Kernel<VoxelT> m_KernelData;
// protected members for algorithm access // VoxImage<VoxelT> *m_Image;
Kernel<VoxelT> m_KernelData;
VoxImage<VoxelT> *m_Image;
private: private:
AlgorithmT *t_Algoritm; AlgorithmT *t_Algoritm;
}; };
} // namespace uLib
}
#endif // VOXIMAGEFILTER_H #endif // VOXIMAGEFILTER_H
#include "VoxImageFilter.hpp" #include "VoxImageFilter.hpp"
#include "VoxImageFilterLinear.hpp" #include "VoxImageFilter2ndStat.hpp"
#include "VoxImageFilterThreshold.hpp"
#include "VoxImageFilterMedian.hpp"
#include "VoxImageFilterABTrim.hpp" #include "VoxImageFilterABTrim.hpp"
#include "VoxImageFilterBilateral.hpp" #include "VoxImageFilterBilateral.hpp"
#include "VoxImageFilter2ndStat.hpp"
#include "VoxImageFilterCustom.hpp" #include "VoxImageFilterCustom.hpp"
#include "VoxImageFilterLinear.hpp"
#include "VoxImageFilterMedian.hpp"
#include "VoxImageFilterThreshold.hpp"

View File

@@ -23,280 +23,238 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTER_HPP #ifndef VOXIMAGEFILTER_HPP
#define VOXIMAGEFILTER_HPP #define VOXIMAGEFILTER_HPP
#include <Math/Dense.h>
#include "Math/StructuredData.h" #include "Math/StructuredData.h"
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
namespace uLib { namespace uLib {
// KERNEL ////////////////////////////////////////////////////////////////////// // KERNEL //////////////////////////////////////////////////////////////////////
template < typename T > template <typename T> class Kernel : public StructuredData {
class Kernel : public StructuredData { typedef StructuredData BaseClass;
typedef StructuredData BaseClass;
public: public:
Kernel(const Vector3i &size); Kernel(const Vector3i &size);
inline T& operator[](const Vector3i &id) { return m_Data[Map(id)]; } inline T &operator[](const Vector3i &id) { return m_Data[Map(id)]; }
inline T& operator[](const int &id) { return m_Data[id]; } inline T &operator[](const int &id) { return m_Data[id]; }
inline int GetCenterData() const; inline int GetCenterData() const;
inline std::vector<T> & Data() { return this->m_Data; } inline DataAllocator<T> &Data() { return this->m_Data; }
inline const std::vector<T>& ConstData() const { return this->m_Data; } inline const DataAllocator<T> &ConstData() const { return this->m_Data; }
void PrintSelf(std::ostream &o) const; void PrintSelf(std::ostream &o) const;
private: private:
std::vector<T> m_Data; DataAllocator<T> m_Data;
}; };
template < typename T > template <typename T>
Kernel<T>::Kernel(const Vector3i &size) : Kernel<T>::Kernel(const Vector3i &size) : BaseClass(size), m_Data(size.prod()) {
BaseClass(size), Interface::IsA<T, Interface::Voxel>();
m_Data(size.prod())
{
Interface::IsA<T,Interface::Voxel>();
} }
template < typename T > template <typename T> inline int Kernel<T>::GetCenterData() const {
inline int Kernel<T>::GetCenterData() const static int center = Map(this->GetDims() / 2);
{ return center;
static int center = Map(this->GetDims() / 2);
return center;
} }
template < typename T > template <typename T> void Kernel<T>::PrintSelf(std::ostream &o) const {
void Kernel<T>::PrintSelf(std::ostream &o) const o << " Filter Kernel Dump [XZ_Y]: \n";
{ Vector3i index;
o << " Filter Kernel Dump [XZ_Y]: \n"; o << "\n Value: \n\n"
Vector3i index; << "------------------------------------------------- \n";
o << "\n Value: \n\n" for (int y = 0; y < this->GetDims()(1); ++y) {
<< "------------------------------------------------- \n"; o << "[y=" << y << "]\n";
for (int y = 0 ; y < this->GetDims()(1); ++y ) { for (int z = 0; z < this->GetDims()(2); ++z) {
o << "[y=" << y << "]\n"; for (int x = 0; x < this->GetDims()(0); ++x) {
for (int z = 0 ; z < this->GetDims()(2); ++z ) { index << x, y, z;
for (int x = 0 ; x < this->GetDims()(0); ++x ) { o << m_Data[Map(index)].Value << " ";
index << x,y,z; }
o << m_Data[Map(index)].Value << " "; o << "\n";
} o << "\n";
} o << " --------------------------------------------------- \n";
} }
o << "\n Offset: \n" o << " --------------------------------------------------- \n";
<< "------------------------------------------------- \n"; }
for (int y = 0 ; y < this->GetDims()(1); ++y ) { o << "\n Offset: \n"
o << "[y=" << y << "]\n"; << "------------------------------------------------- \n";
for (int z = 0 ; z < this->GetDims()(2); ++z ) { for (int y = 0; y < this->GetDims()(1); ++y) {
for (int x = 0 ; x < this->GetDims()(0); ++x ) { o << "[y=" << y << "]\n";
index << x,y,z; for (int z = 0; z < this->GetDims()(2); ++z) {
o << m_Data[Map(index)].Count << " "; for (int x = 0; x < this->GetDims()(0); ++x) {
} o << "\n"; index << x, y, z;
} o << " --------------------------------------------------- \n"; o << m_Data[Map(index)].Count << " ";
}
o << "\n";
} }
o << " --------------------------------------------------- \n";
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define _TPL_ template <typename VoxelT, typename AlgorithmT>
#define _TPLT_ VoxelT, AlgorithmT
#define _TPL_ template < typename VoxelT , typename AlgorithmT >
#define _TPLT_ VoxelT,AlgorithmT
_TPL_ _TPL_
VoxImageFilter<_TPLT_>::VoxImageFilter(const Vector3i &size) : VoxImageFilter<_TPLT_>::VoxImageFilter(const Vector3i &size)
m_KernelData(size), : m_KernelData(size), t_Algoritm(static_cast<AlgorithmT *>(this)) {}
t_Algoritm(static_cast<AlgorithmT *>(this))
{
_TPL_
void VoxImageFilter<_TPLT_>::Run() {
VoxImage<VoxelT> 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_ _TPL_
void VoxImageFilter<_TPLT_>::Run() void VoxImageFilter<_TPLT_>::SetKernelOffset() {
{ Vector3i id(0, 0, 0);
VoxImage<VoxelT> buffer = *m_Image; for (int z = 0; z < m_KernelData.GetDims()(2); ++z) {
#pragma omp parallel for for (int x = 0; x < m_KernelData.GetDims()(0); ++x) {
for(int i=0 ; i < m_Image->Data().size() ; ++i) for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
m_Image->operator [](i).Value = this->t_Algoritm->Evaluate(buffer,i); id << x, y, z;
#pragma omp barrier m_KernelData[id].Count = id.transpose() * m_Image->GetIncrements();
} }
_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_ _TPL_
float VoxImageFilter<_TPLT_>::Distance2(const Vector3i &v) float VoxImageFilter<_TPLT_>::Distance2(const Vector3i &v) {
{ Vector3i tmp = v;
Vector3i tmp = v; const Vector3i &dim = this->m_KernelData.GetDims();
const Vector3i &dim = this->m_KernelData.GetDims(); Vector3i center = dim / 2;
Vector3i center = dim / 2; tmp = tmp - center;
tmp = tmp - center; center = center.cwiseProduct(center);
center = center.cwiseProduct(center); tmp = tmp.cwiseProduct(tmp);
tmp = tmp.cwiseProduct(tmp); return (float)(tmp.sum()) /
return (float)(tmp.sum()) / (float)( center.sum() + 0.25 * (float)(center.sum() +
(3 - (dim(0) % 2) - (dim(1) % 2) - (dim(2) % 2))); 0.25 * (3 - (dim(0) % 2) - (dim(1) % 2) - (dim(2) % 2)));
} }
_TPL_ _TPL_
void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(const std::vector<float> &numeric) void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(
{ const std::vector<float> &numeric) {
// set data order // // set data order //
StructuredData::Order order = m_KernelData.GetDataOrder(); StructuredData::Order order = m_KernelData.GetDataOrder();
//m_KernelData.SetDataOrder(StructuredData::XZY); // m_KernelData.SetDataOrder(StructuredData::XZY);
Vector3i id; Vector3i id;
int index = 0; int index = 0;
for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { for (int z = 0; z < m_KernelData.GetDims()(2); ++z) {
for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { for (int x = 0; x < m_KernelData.GetDims()(0); ++x) {
id << x,y,z; id << x, y, z;
m_KernelData[id].Value = numeric[index++]; m_KernelData[id].Value = numeric[index++];
} }
}
} }
//m_KernelData.SetDataOrder(order); }
// m_KernelData.SetDataOrder(order);
} }
_TPL_ _TPL_
void VoxImageFilter<_TPLT_>::SetKernelSpherical(float(* shape)(float)) void VoxImageFilter<_TPLT_>::SetKernelSpherical(float (*shape)(float)) {
{ Vector3i id;
Vector3i id; for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { for (int z = 0; z < m_KernelData.GetDims()(2); ++z) {
for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { for (int x = 0; x < m_KernelData.GetDims()(0); ++x) {
for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { id << x, y, z;
id << x,y,z; m_KernelData[id].Value = shape(this->Distance2(id));
m_KernelData[id].Value = shape(this->Distance2(id)); }
}
}
} }
}
} }
_TPL_ template <class ShapeT> _TPL_ template <class ShapeT>
void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape) void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape) {
{ Interface::IsA<ShapeT, Interface::VoxImageFilterShape>();
Interface::IsA<ShapeT,Interface::VoxImageFilterShape>(); Vector3i id;
Vector3i id; for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
for( int y=0 ; y < m_KernelData.GetDims()(1); ++y ) { for (int z = 0; z < m_KernelData.GetDims()(2); ++z) {
for( int z=0 ; z < m_KernelData.GetDims()(2); ++z ) { for (int x = 0; x < m_KernelData.GetDims()(0); ++x) {
for( int x=0 ; x < m_KernelData.GetDims()(0); ++x ) { id << x, y, z;
id << x,y,z; m_KernelData[id].Value = shape(this->Distance2(id));
m_KernelData[id].Value = shape(this->Distance2(id)); }
}
}
} }
}
} }
_TPL_ _TPL_
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(float (*shape)(const Vector3f &)) void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(
{ float (*shape)(const Vector3f &)) {
const Vector3i &dim = m_KernelData.GetDims(); const Vector3i &dim = m_KernelData.GetDims();
Vector3i id; Vector3i id;
Vector3f pt; Vector3f pt;
for( int y=0 ; y < dim(1); ++y ) { for (int y = 0; y < dim(1); ++y) {
for( int z=0 ; z < dim(2); ++z ) { for (int z = 0; z < dim(2); ++z) {
for( int x=0 ; x < dim(0); ++x ) { for (int x = 0; x < dim(0); ++x) {
// get voxels centroid coords from kernel center // // get voxels centroid coords from kernel center //
id << x,y,z; id << x, y, z;
pt << id(0) - dim(0)/2 + 0.5 * !(dim(0) % 2), pt << id(0) - dim(0) / 2 + 0.5 * !(dim(0) % 2),
id(1) - dim(1)/2 + 0.5 * !(dim(1) % 2), id(1) - dim(1) / 2 + 0.5 * !(dim(1) % 2),
id(2) - dim(2)/2 + 0.5 * !(dim(2) % 2); id(2) - dim(2) / 2 + 0.5 * !(dim(2) % 2);
// compute function using given shape // // compute function using given shape //
m_KernelData[id].Value = shape(pt); m_KernelData[id].Value = shape(pt);
} }
}
} }
}
} }
_TPL_ template < class ShapeT > _TPL_ template <class ShapeT>
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape) void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape) {
{ Interface::IsA<ShapeT, Interface::VoxImageFilterShape>();
Interface::IsA<ShapeT,Interface::VoxImageFilterShape>(); const Vector3i &dim = m_KernelData.GetDims();
const Vector3i &dim = m_KernelData.GetDims(); Vector3i id;
Vector3i id; Vector3f pt;
Vector3f pt; for (int y = 0; y < dim(1); ++y) {
for( int y=0 ; y < dim(1); ++y ) { for (int z = 0; z < dim(2); ++z) {
for( int z=0 ; z < dim(2); ++z ) { for (int x = 0; x < dim(0); ++x) {
for( int x=0 ; x < dim(0); ++x ) { // get voxels centroid coords from kernel center //
// get voxels centroid coords from kernel center // id << x, y, z;
id << x,y,z; pt << id(0) - dim(0) / 2 + 0.5 * !(dim(0) % 2),
pt << id(0) - dim(0)/2 + 0.5 * !(dim(0) % 2), id(1) - dim(1) / 2 + 0.5 * !(dim(1) % 2),
id(1) - dim(1)/2 + 0.5 * !(dim(1) % 2), id(2) - dim(2) / 2 + 0.5 * !(dim(2) % 2);
id(2) - dim(2)/2 + 0.5 * !(dim(2) % 2); // compute function using given shape //
// compute function using given shape // m_KernelData[id].Value = shape(pt);
m_KernelData[id].Value = shape(pt); }
}
}
} }
}
} }
_TPL_ _TPL_
void VoxImageFilter<_TPLT_>::SetImage(Abstract::VoxImage *image) void VoxImageFilter<_TPLT_>::SetImage(Abstract::VoxImage *image) {
{ this->m_Image = reinterpret_cast<VoxImage<VoxelT> *>(image);
this->m_Image = reinterpret_cast<VoxImage<VoxelT> *> (image); this->SetKernelOffset();
this->SetKernelOffset();
} }
_TPL_ _TPL_
float VoxImageFilter<_TPLT_>::Convolve(const VoxImage<VoxelT> &buffer, int index) float VoxImageFilter<_TPLT_>::Convolve(const VoxImage<VoxelT> &buffer,
{ int index) {
const std::vector<VoxelT> &vbuf = buffer.ConstData(); const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vker = m_KernelData.ConstData(); const DataAllocator<VoxelT> &vker = m_KernelData.ConstData();
int vox_size = vbuf.size(); int vox_size = vbuf.size();
int ker_size = vker.size(); int ker_size = vker.size();
int pos; int pos;
float conv = 0, ksum = 0; float conv = 0, ksum = 0;
for (int ik = 0; ik < ker_size; ++ik) { for (int ik = 0; ik < ker_size; ++ik) {
pos = index + vker[ik].Count - vker[m_KernelData.GetCenterData()].Count; pos = index + vker[ik].Count - vker[m_KernelData.GetCenterData()].Count;
pos = (pos + vox_size) % vox_size; pos = (pos + vox_size) % vox_size;
conv += vbuf[pos].Value * vker[ik].Value; conv += vbuf[pos].Value * vker[ik].Value;
ksum += vker[ik].Value; ksum += vker[ik].Value;
} }
return conv / ksum; return conv / ksum;
} }
#undef _TPLT_ #undef _TPLT_
#undef _TPL_ #undef _TPL_
} // namespace uLib
}
#endif // VOXIMAGEFILTER_HPP #endif // VOXIMAGEFILTER_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTER2NDSTAT_HPP #ifndef VOXIMAGEFILTER2NDSTAT_HPP
#define VOXIMAGEFILTER2NDSTAT_HPP #define VOXIMAGEFILTER2NDSTAT_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER ABTRIM ///////////////////////////////////////////////// ///// VOXIMAGE FILTER ABTRIM /////////////////////////////////////////////////
@@ -39,45 +37,42 @@
namespace uLib { namespace uLib {
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithm2ndStat : class VoxFilterAlgorithm2ndStat
public VoxImageFilter<VoxelT, VoxFilterAlgorithm2ndStat<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithm2ndStat<VoxelT>> {
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithm2ndStat<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithm2ndStat<VoxelT>> BaseClass;
VoxFilterAlgorithm2ndStat(const Vector3i &size) : VoxFilterAlgorithm2ndStat(const Vector3i &size) : BaseClass(size) {}
BaseClass(size)
{ }
float Evaluate(const VoxImage<VoxelT> &buffer, int index) float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
{ const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vbuf = buffer.ConstData(); const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); int vox_size = vbuf.size();
int vox_size = vbuf.size(); int ker_size = vker.size();
int ker_size = vker.size(); int pos;
int pos;
// mean // // mean //
float conv = 0, ksum = 0; float conv = 0, ksum = 0;
for (int ik = 0; ik < ker_size; ++ik) { for (int ik = 0; ik < ker_size; ++ik) {
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; pos = index + vker[ik].Count -
pos = (pos + vox_size) % vox_size; vker[this->m_KernelData.GetCenterData()].Count;
conv += vbuf[pos].Value * vker[ik].Value; pos = (pos + vox_size) % vox_size;
ksum += vker[ik].Value; 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) ;
} }
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);
}
}; };
} } // namespace uLib
#endif // VOXIMAGEFILTER2NDSTAT_HPP #endif // VOXIMAGEFILTER2NDSTAT_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERABTRIM_HPP #ifndef VOXIMAGEFILTERABTRIM_HPP
#define VOXIMAGEFILTERABTRIM_HPP #define VOXIMAGEFILTERABTRIM_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER ABTRIM ///////////////////////////////////////////////// ///// VOXIMAGE FILTER ABTRIM /////////////////////////////////////////////////
@@ -38,142 +36,257 @@
namespace uLib { namespace uLib {
#ifdef USE_CUDA
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmAbtrim : __global__ void ABTrimFilterKernel(const VoxelT *in, VoxelT *out,
public VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT> > { const VoxelT *kernel, int vox_size,
int ker_size, int center_count, int mAtrim,
int mBtrim) {
int index = blockIdx.x * blockDim.x + threadIdx.x;
if (index < vox_size) {
// Allocate space for sorting
extern __shared__ char shared_mem[];
VoxelT *mfh =
(VoxelT *)&shared_mem[threadIdx.x * ker_size * sizeof(VoxelT)];
struct KernelSortAscending for (int i = 0; i < ker_size; ++i) {
{ mfh[i].Count = i;
bool operator()(const VoxelT& e1, const VoxelT& e2) }
{ return e1.Value < e2.Value; }
}; for (int ik = 0; ik < ker_size; ik++) {
int pos = index + kernel[ik].Count - center_count;
if (pos < 0) {
pos += vox_size * ((-pos / vox_size) + 1);
}
pos = pos % vox_size;
mfh[ik].Value = in[pos].Value;
}
// Simple bubble sort for small arrays
for (int i = 0; i < ker_size - 1; i++) {
for (int j = 0; j < ker_size - i - 1; j++) {
if (mfh[j].Value > mfh[j + 1].Value) {
VoxelT temp = mfh[j];
mfh[j] = mfh[j + 1];
mfh[j + 1] = temp;
}
}
}
float ker_sum = 0;
float fconv = 0;
for (int ik = 0; ik < mAtrim; ik++) {
ker_sum += kernel[mfh[ik].Count].Value;
}
for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) {
fconv += mfh[ik].Value * kernel[mfh[ik].Count].Value;
ker_sum += kernel[mfh[ik].Count].Value;
}
for (int ik = ker_size - mBtrim; ik < ker_size; ik++) {
ker_sum += kernel[mfh[ik].Count].Value;
}
out[index].Value = fconv / ker_sum;
}
}
#endif
template <typename VoxelT>
class VoxFilterAlgorithmAbtrim
: public VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT>> {
struct KernelSortAscending {
bool operator()(const VoxelT &e1, const VoxelT &e2) {
return e1.Value < e2.Value;
}
};
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT>> BaseClass;
VoxFilterAlgorithmAbtrim(const Vector3i &size) : VoxFilterAlgorithmAbtrim(const Vector3i &size) : BaseClass(size) {
BaseClass(size) mAtrim = 0;
{ mBtrim = 0;
mAtrim = 0; }
mBtrim = 0;
#ifdef USE_CUDA
void Run() {
if (this->m_Image->Data().GetDevice() == MemoryDevice::VRAM ||
this->m_KernelData.Data().GetDevice() == MemoryDevice::VRAM) {
this->m_Image->Data().MoveToVRAM();
this->m_KernelData.Data().MoveToVRAM();
VoxImage<VoxelT> buffer = *(this->m_Image);
buffer.Data().MoveToVRAM();
int vox_size = buffer.Data().size();
int ker_size = this->m_KernelData.Data().size();
VoxelT *d_img_out = this->m_Image->Data().GetVRAMData();
const VoxelT *d_img_in = buffer.Data().GetVRAMData();
const VoxelT *d_kernel = this->m_KernelData.Data().GetVRAMData();
int center_count =
this->m_KernelData[this->m_KernelData.GetCenterData()].Count;
int threadsPerBlock = 256;
int blocksPerGrid = (vox_size + threadsPerBlock - 1) / threadsPerBlock;
size_t shared_mem_size = threadsPerBlock * ker_size * sizeof(VoxelT);
ABTrimFilterKernel<<<blocksPerGrid, threadsPerBlock, shared_mem_size>>>(
d_img_in, d_img_out, d_kernel, vox_size, ker_size, center_count,
mAtrim, mBtrim);
cudaDeviceSynchronize();
} else {
BaseClass::Run();
}
}
#endif
float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
int vox_size = vbuf.size();
int ker_size = vker.size();
int pos;
std::vector<VoxelT> 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;
} }
float Evaluate(const VoxImage<VoxelT> &buffer, int index) std::sort(mfh.begin(), mfh.end(), KernelSortAscending());
{ float ker_sum = 0;
const std::vector<VoxelT> &vbuf = buffer.ConstData(); float fconv = 0;
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); for (int ik = 0; ik < mAtrim; ik++)
int vox_size = vbuf.size(); ker_sum += vker[mfh[ik].Count].Value;
int ker_size = vker.size(); for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) {
int pos; fconv += mfh[ik].Value * vker[mfh[ik].Count].Value; // convloution //
ker_sum += vker[mfh[ik].Count].Value;
std::vector<VoxelT> 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;
} }
for (int ik = ker_size - mBtrim; ik < ker_size; ik++)
ker_sum += vker[mfh[ik].Count].Value;
inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; } return fconv / ker_sum;
}
inline void SetABTrim(int a, int b) {
mAtrim = a;
mBtrim = b;
}
private: private:
int mAtrim; int mAtrim;
int mBtrim; int mBtrim;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Roberspierre Filter // // Roberspierre Filter //
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmSPR : class VoxFilterAlgorithmSPR
public VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT>> {
struct KernelSortAscending struct KernelSortAscending {
{ bool operator()(const VoxelT &e1, const VoxelT &e2) {
bool operator()(const VoxelT& e1, const VoxelT& e2) return e1.Value < e2.Value;
{ return e1.Value < e2.Value; } }
}; };
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT>> BaseClass;
VoxFilterAlgorithmSPR(const Vector3i &size) : VoxFilterAlgorithmSPR(const Vector3i &size) : BaseClass(size) {
BaseClass(size) mAtrim = 0;
{ mBtrim = 0;
mAtrim = 0; }
mBtrim = 0;
#ifdef USE_CUDA
void Run() {
if (this->m_Image->Data().GetDevice() == MemoryDevice::VRAM ||
this->m_KernelData.Data().GetDevice() == MemoryDevice::VRAM) {
this->m_Image->Data().MoveToVRAM();
this->m_KernelData.Data().MoveToVRAM();
VoxImage<VoxelT> buffer = *(this->m_Image);
buffer.Data().MoveToVRAM();
int vox_size = buffer.Data().size();
int ker_size = this->m_KernelData.Data().size();
VoxelT *d_img_out = this->m_Image->Data().GetVRAMData();
const VoxelT *d_img_in = buffer.Data().GetVRAMData();
const VoxelT *d_kernel = this->m_KernelData.Data().GetVRAMData();
int center_count =
this->m_KernelData[this->m_KernelData.GetCenterData()].Count;
int threadsPerBlock = 256;
int blocksPerGrid = (vox_size + threadsPerBlock - 1) / threadsPerBlock;
size_t shared_mem_size = threadsPerBlock * ker_size * sizeof(VoxelT);
ABTrimFilterKernel<<<blocksPerGrid, threadsPerBlock, shared_mem_size>>>(
d_img_in, d_img_out, d_kernel, vox_size, ker_size, center_count,
mAtrim, mBtrim);
cudaDeviceSynchronize();
} else {
BaseClass::Run();
}
}
#endif
float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
int vox_size = vbuf.size();
int ker_size = vker.size();
int pos;
std::vector<VoxelT> 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;
} }
float Evaluate(const VoxImage<VoxelT> &buffer, int index) std::sort(mfh.begin(), mfh.end(), KernelSortAscending());
{ float spr = vbuf[index].Value;
const std::vector<VoxelT> &vbuf = buffer.ConstData(); if ((mAtrim > 0 && spr <= mfh[mAtrim - 1].Value) ||
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); (mBtrim > 0 && spr >= mfh[ker_size - mBtrim].Value)) {
int vox_size = vbuf.size(); float ker_sum = 0;
int ker_size = vker.size(); float fconv = 0;
int pos; 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;
std::vector<VoxelT> mfh(ker_size); return fconv / ker_sum;
for (int i = 0; i < ker_size; ++i) } else
mfh[i].Count = i; //index key for ordering function return spr;
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()); inline void SetABTrim(int a, int b) {
float spr = vbuf[index].Value; mAtrim = a;
if( (mAtrim > 0 && spr <= mfh[mAtrim-1].Value) || mBtrim = b;
(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: private:
int mAtrim; int mAtrim;
int mBtrim; int mBtrim;
}; };
} // namespace uLib
}
#endif // VOXIMAGEFILTERABTRIM_HPP #endif // VOXIMAGEFILTERABTRIM_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERBILATERAL_HPP #ifndef VOXIMAGEFILTERBILATERAL_HPP
#define VOXIMAGEFILTERBILATERAL_HPP #define VOXIMAGEFILTERBILATERAL_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER LINEAR ///////////////////////////////////////////////// ///// VOXIMAGE FILTER LINEAR /////////////////////////////////////////////////
@@ -38,115 +36,119 @@
namespace uLib { namespace uLib {
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmBilateral : class VoxFilterAlgorithmBilateral
public VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateral<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateral<VoxelT>> {
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateral<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateral<VoxelT>> BaseClass;
VoxFilterAlgorithmBilateral(const Vector3i &size) : BaseClass(size) { VoxFilterAlgorithmBilateral(const Vector3i &size) : BaseClass(size) {
m_sigma = 1; m_sigma = 1;
} }
float Evaluate(const VoxImage<VoxelT> &buffer, int index) float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
{ const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vbuf = buffer.ConstData(); const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); int vox_size = vbuf.size();
int vox_size = vbuf.size(); int ker_size = vker.size();
int ker_size = vker.size(); int pos;
int pos; float conv = 0, ksum = 0;
float conv = 0, ksum = 0; float gamma_smooth;
float gamma_smooth; for (int ik = 0; ik < ker_size; ++ik) {
for (int ik = 0; ik < ker_size; ++ik) { // if (ik==this->m_KernelData.GetCenterData()) continue;
// if (ik==this->m_KernelData.GetCenterData()) continue; pos = index + vker[ik].Count -
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; vker[this->m_KernelData.GetCenterData()].Count;
pos = (pos + vox_size) % vox_size; pos = (pos + vox_size) % vox_size;
gamma_smooth = compute_gauss( fabs(vbuf[index].Value - vbuf[pos].Value) * 1.E6 ); gamma_smooth =
conv += vbuf[pos].Value * vker[ik].Value * gamma_smooth; compute_gauss(fabs(vbuf[index].Value - vbuf[pos].Value) * 1.E6);
ksum += vker[ik].Value * gamma_smooth; conv += vbuf[pos].Value * vker[ik].Value * gamma_smooth;
} ksum += vker[ik].Value * gamma_smooth;
return conv / ksum;
} }
return conv / ksum;
}
inline void SetIntensitySigma(const float s) { m_sigma = s; } inline void SetIntensitySigma(const float s) { m_sigma = s; }
private: private:
inline float compute_gauss(const float x) { inline float compute_gauss(const float x) {
return 1/(sqrt(2*M_PI)* m_sigma) * exp(-0.5*(x*x)/(m_sigma*m_sigma)); return 1 / (sqrt(2 * M_PI) * m_sigma) *
} exp(-0.5 * (x * x) / (m_sigma * m_sigma));
}
Scalarf m_sigma; Scalarf m_sigma;
}; };
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmBilateralTrim : class VoxFilterAlgorithmBilateralTrim
public VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateralTrim<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateralTrim<VoxelT>> {
typedef std::pair<float,float> FPair; typedef std::pair<float, float> FPair;
struct KernelSortAscending struct KernelSortAscending {
{ bool operator()(const FPair &e1, const FPair &e2) {
bool operator()(const FPair& e1, const FPair& e2) return e1.second < e2.second;
{ return e1.second < e2.second; } }
}; };
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateralTrim<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmBilateralTrim<VoxelT>>
VoxFilterAlgorithmBilateralTrim(const Vector3i &size) : BaseClass(size) { BaseClass;
m_sigma = 1; VoxFilterAlgorithmBilateralTrim(const Vector3i &size) : BaseClass(size) {
mAtrim = 0; m_sigma = 1;
mBtrim = 0; mAtrim = 0;
mBtrim = 0;
}
float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
int img_size = vbuf.size();
int ker_size = vker.size();
int pos;
std::vector<FPair> 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 Evaluate(const VoxImage<VoxelT> &buffer, int index) float conv = 0, ksum = 0;
{ float gamma_smooth;
const std::vector<VoxelT> &vbuf = buffer.ConstData(); // for (int ik = 0; ik < mAtrim; ik++)
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); // ksum += mfh[ik].first;
int img_size = vbuf.size(); for (int ik = mAtrim; ik < ker_size - mBtrim; ik++) {
int ker_size = vker.size(); gamma_smooth =
int pos; 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;
std::vector<FPair> 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;
} }
// for (int ik = ker_size - mBtrim; ik < ker_size; ik++)
// ksum += mfh[ik].first;
inline void SetIntensitySigma(const float s) { m_sigma = s; } return conv / ksum;
inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; } }
inline void SetIntensitySigma(const float s) { m_sigma = s; }
inline void SetABTrim(int a, int b) {
mAtrim = a;
mBtrim = b;
}
private: private:
inline float compute_gauss(const float x) { inline float compute_gauss(const float x) {
return 1/(sqrt(2*M_PI)* m_sigma) * exp(-0.5*(x*x)/(m_sigma*m_sigma)); return 1 / (sqrt(2 * M_PI) * m_sigma) *
} exp(-0.5 * (x * x) / (m_sigma * m_sigma));
}
Scalarf m_sigma; Scalarf m_sigma;
int mAtrim; int mAtrim;
int mBtrim; int mBtrim;
}; };
} } // namespace uLib
#endif // VOXIMAGEFILTERBILATERAL_HPP #endif // VOXIMAGEFILTERBILATERAL_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERCUSTOM_HPP #ifndef VOXIMAGEFILTERCUSTOM_HPP
#define VOXIMAGEFILTERCUSTOM_HPP #define VOXIMAGEFILTERCUSTOM_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
#define likely(expr) __builtin_expect(!!(expr), 1) #define likely(expr) __builtin_expect(!!(expr), 1)
@@ -41,50 +39,50 @@
namespace uLib { namespace uLib {
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmCustom : class VoxFilterAlgorithmCustom
public VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT>> {
typedef float (*FunctionPt)(const std::vector<Scalarf> &);
typedef float (* FunctionPt)(const std::vector<Scalarf> &);
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT>> BaseClass;
VoxFilterAlgorithmCustom(const Vector3i &size) : VoxFilterAlgorithmCustom(const Vector3i &size)
BaseClass(size), m_CustomEvaluate(NULL) : BaseClass(size), m_CustomEvaluate(NULL) {}
{}
float Evaluate(const VoxImage<VoxelT> &buffer, int index) float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
{ if (likely(m_CustomEvaluate)) {
if(likely(m_CustomEvaluate)) { const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vbuf = buffer.ConstData(); const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); int vox_size = vbuf.size();
int vox_size = vbuf.size(); int ker_size = vker.size();
int ker_size = vker.size(); int pos;
int pos;
float ker_sum = 0; float ker_sum = 0;
std::vector<Scalarf> mfh(ker_size); std::vector<Scalarf> mfh(ker_size);
for (int ik = 0; ik < ker_size; ik++) { for (int ik = 0; ik < ker_size; ik++) {
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; pos = index + vker[ik].Count -
pos = (pos + vox_size) % vox_size; vker[this->m_KernelData.GetCenterData()].Count;
mfh[ik] = vbuf[pos].Value * vker[ik].Value; pos = (pos + vox_size) % vox_size;
ker_sum += vker[ik].Value; 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";
return this->m_CustomEvaluate(mfh);
} else {
std::cerr << "Custom evaluate function is NULL \n"
<< "No operation performed by filter.\n";
return 0;
} }
}
inline void SetCustomEvaluate(FunctionPt funPt) { this->m_CustomEvaluate = funPt; } inline void SetCustomEvaluate(FunctionPt funPt) {
this->m_CustomEvaluate = funPt;
}
private: private:
FunctionPt m_CustomEvaluate; FunctionPt m_CustomEvaluate;
}; };
} } // namespace uLib
#endif // VOXIMAGEFILTERCUSTOM_HPP #endif // VOXIMAGEFILTERCUSTOM_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERLINEAR_HPP #ifndef VOXIMAGEFILTERLINEAR_HPP
#define VOXIMAGEFILTERLINEAR_HPP #define VOXIMAGEFILTERLINEAR_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER LINEAR ///////////////////////////////////////////////// ///// VOXIMAGE FILTER LINEAR /////////////////////////////////////////////////
@@ -38,32 +36,86 @@
namespace uLib { namespace uLib {
#ifdef USE_CUDA
template <typename VoxelT>
__global__ void LinearFilterKernel(const VoxelT *in, VoxelT *out,
const VoxelT *kernel, int vox_size,
int ker_size, int center_count) {
int index = blockIdx.x * blockDim.x + threadIdx.x;
if (index < vox_size) {
float conv = 0;
float ksum = 0;
for (int ik = 0; ik < ker_size; ++ik) {
int pos = index + kernel[ik].Count - center_count;
if (pos < 0) {
pos += vox_size * ((-pos / vox_size) + 1);
}
pos = pos % vox_size;
conv += in[pos].Value * kernel[ik].Value;
ksum += kernel[ik].Value;
}
out[index].Value = conv / ksum;
}
}
#endif
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmLinear : class VoxFilterAlgorithmLinear
public VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT>> {
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT>> BaseClass;
VoxFilterAlgorithmLinear(const Vector3i &size) : BaseClass(size) {} VoxFilterAlgorithmLinear(const Vector3i &size) : BaseClass(size) {}
float Evaluate(const VoxImage<VoxelT> &buffer, int index) #ifdef USE_CUDA
{ void Run() {
const std::vector<VoxelT> &vbuf = buffer.ConstData(); if (this->m_Image->Data().GetDevice() == MemoryDevice::VRAM ||
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); this->m_KernelData.Data().GetDevice() == MemoryDevice::VRAM) {
int vox_size = vbuf.size();
int ker_size = vker.size(); this->m_Image->Data().MoveToVRAM();
int pos; this->m_KernelData.Data().MoveToVRAM();
float conv = 0, ksum = 0;
for (int ik = 0; ik < ker_size; ++ik) { VoxImage<VoxelT> buffer = *(this->m_Image);
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; buffer.Data().MoveToVRAM();
pos = (pos + vox_size) % vox_size;
conv += vbuf[pos].Value * vker[ik].Value; int vox_size = buffer.Data().size();
ksum += vker[ik].Value; int ker_size = this->m_KernelData.Data().size();
}
return conv / ksum; VoxelT *d_img_out = this->m_Image->Data().GetVRAMData();
const VoxelT *d_img_in = buffer.Data().GetVRAMData();
const VoxelT *d_kernel = this->m_KernelData.Data().GetVRAMData();
int center_count =
this->m_KernelData[this->m_KernelData.GetCenterData()].Count;
int threadsPerBlock = 256;
int blocksPerGrid = (vox_size + threadsPerBlock - 1) / threadsPerBlock;
LinearFilterKernel<<<blocksPerGrid, threadsPerBlock>>>(
d_img_in, d_img_out, d_kernel, vox_size, ker_size, center_count);
cudaDeviceSynchronize();
} else {
BaseClass::Run();
} }
}
#endif
float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const DataAllocator<VoxelT> &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;
}
}; };
} } // namespace uLib
#endif // VOXIMAGEFILTERLINEAR_HPP #endif // VOXIMAGEFILTERLINEAR_HPP

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERMEDIAN_HPP #ifndef VOXIMAGEFILTERMEDIAN_HPP
#define VOXIMAGEFILTERMEDIAN_HPP #define VOXIMAGEFILTERMEDIAN_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "VoxImageFilter.h" #include "VoxImageFilter.h"
#include <Math/Dense.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER MEDIAN ///////////////////////////////////////////////// ///// VOXIMAGE FILTER MEDIAN /////////////////////////////////////////////////
@@ -39,37 +37,38 @@
namespace uLib { namespace uLib {
template <typename VoxelT> template <typename VoxelT>
class VoxFilterAlgorithmMedian : class VoxFilterAlgorithmMedian
public VoxImageFilter<VoxelT, VoxFilterAlgorithmMedian<VoxelT> > { : public VoxImageFilter<VoxelT, VoxFilterAlgorithmMedian<VoxelT>> {
public: public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmMedian<VoxelT> > BaseClass; typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmMedian<VoxelT>> BaseClass;
VoxFilterAlgorithmMedian(const Vector3i &size) : BaseClass(size) {} VoxFilterAlgorithmMedian(const Vector3i &size) : BaseClass(size) {}
float Evaluate(const VoxImage<VoxelT> &buffer, int index) float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
{ const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vbuf = buffer.ConstData(); const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData(); int vox_size = vbuf.size();
int vox_size = vbuf.size(); int ker_size = vker.size();
int ker_size = vker.size(); int pos;
int pos;
std::vector<float> mfh(ker_size); std::vector<float> mfh(ker_size);
for (int ik = 0; ik < ker_size; ik++) { for (int ik = 0; ik < ker_size; ik++) {
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count; pos = index + vker[ik].Count -
pos = (pos + vox_size) % vox_size; vker[this->m_KernelData.GetCenterData()].Count;
mfh[ik] = vbuf[pos].Value * vker[ik].Value; 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];
} }
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];
}
}; };
} } // namespace uLib
#endif // VOXIMAGEFILTERMEDIAN_HPP #endif // VOXIMAGEFILTERMEDIAN_HPP

View File

@@ -23,11 +23,10 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include <iostream> #include <iostream>
#include "VoxRaytracer.h"
#include "Utils.h" #include "Utils.h"
#include "VoxRaytracer.h"
#define unlikely(expr) __builtin_expect(!!(expr), 0) #define unlikely(expr) __builtin_expect(!!(expr), 0)
@@ -39,215 +38,206 @@ namespace uLib {
///// RAY DATA ///////////////////////////////////////////////////////////////// ///// RAY DATA /////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void VoxRaytracer::RayData::AddElement(Id_t id, float L) void VoxRaytracer::RayData::AddElement(Id_t id, float L) {
{ Element el = {id, L};
Element el = {id, L}; m_Data.push_back(el);
m_Data.push_back(el); m_TotalLength += L;
m_TotalLength += L;
} }
void VoxRaytracer::RayData::AppendRay(const VoxRaytracer::RayData &in) {
void VoxRaytracer::RayData::AppendRay(const VoxRaytracer::RayData &in) if (unlikely(!in.m_Data.size())) {
{ std::cout << "Warinig: PoCA on exit border!\n";
if (unlikely(!in.m_Data.size())) { return;
std::cout << "Warinig: PoCA on exit border!\n"; } else if (unlikely(!m_Data.size())) {
return; m_Data = in.m_Data;
} std::cout << "Warinig: PoCA on entrance border!\n";
else if (unlikely(!m_Data.size())) { return;
m_Data = in.m_Data; } else {
std::cout << "Warinig: PoCA on entrance border!\n"; // Opzione 1) un voxel in piu' //
return; if (in.m_Data.size() > 0) {
} m_Data.insert(m_Data.end(), in.m_Data.begin(), in.m_Data.end());
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;
} }
// 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) void VoxRaytracer::RayData::PrintSelf(std::ostream &o) {
{ o << "Ray: total lenght " << m_TotalLength << "\n";
o << "Ray: total lenght " << m_TotalLength << "\n"; std::vector<Element>::iterator it;
std::vector<Element>::iterator it; for (it = m_Data.begin(); it < m_Data.end(); ++it)
for(it = m_Data.begin(); it < m_Data.end(); ++it) o << "[ " << (*it).vox_id << ", " << (*it).L << "] \n";
o << "[ " << (*it).vox_id << ", " << (*it).L << "] \n";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//// RAY TRACER //////////////////////////////////////////////////////////////// //// RAY TRACER ////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt) {
Vector4f s = m_Image->GetLocalPoint(line.direction);
pt = m_Image->GetLocalPoint(line.origin);
bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt) // Considers Structured grid dimensions //
{ Vector4f dims = m_Image->GetDims().homogeneous().cast<float>();
Vector4f s = m_Image->GetLocalPoint(line.direction); pt = pt.cwiseQuotient(dims);
pt = m_Image->GetLocalPoint(line.origin); s = s.cwiseQuotient(dims);
// Considers Structured grid dimensions // float l = s.head(3).norm();
Vector4f dims = m_Image->GetDims().homogeneous().cast<float>(); Vector3f L(l / s(0), l / s(1), l / s(2));
pt = pt.cwiseQuotient(dims);
s = s.cwiseQuotient(dims);
float l = s.head(3).norm(); Vector3f offset;
Vector3f L(l/s(0), l/s(1), l/s(2)); for (int i = 0; i < 3; ++i)
offset(i) = (s(i) > 0) - (pt(i) - floor(pt(i)));
offset = offset.cwiseProduct(L).cwiseAbs();
Vector3f offset; int id;
for(int i=0;i<3;++i) float d;
offset(i) = (s(i)>0) - (pt(i)-floor(pt(i))) ; for (int loop = 0; loop < 8; loop++) {
offset = offset.cwiseProduct(L).cwiseAbs(); int check_border = 0;
for (int i = 0; i < 3; ++i) {
int id; float d; check_border += pt(i) > 1;
for(int loop=0; loop<8; loop++) check_border += pt(i) < 0;
{
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) if (check_border == 0) {
for (int i = 0; i < 3; ++i)
pt(i) *= (float)dims(i); pt(i) *= (float)dims(i);
pt = m_Image->GetWorldPoint(pt); pt = m_Image->GetWorldPoint(pt);
return false; return true;
}
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 d = offset.minCoeff(&id);
int id; float d; for (int i = 0; i < 3; ++i)
while(l>0){ pt(i) += d / L(i);
d = offset.minCoeff(&id); pt(id) = rintf(pt(id));
if(m_Image->IsInsideGrid(vid)){ offset.array() -= d;
ray.AddElement(m_Image->Map(vid), d * m_scale(id) ); offset(id) = fabs(L(id));
} }
for (int i = 0; i < 3; ++i)
pt(i) *= (float)dims(i);
pt = m_Image->GetWorldPoint(pt);
return false;
}
// nan check // bool VoxRaytracer::GetExitPoint(const HLine3f &line, HPoint3f &pt) {
// if(unlikely(!isFinite(d * scale(id)))) { HLine3f out = line;
// std:: cout << "NAN in raytracer\n"; out.direction *= -1;
// exit(1); return GetEntryPoint(out, pt);
// } }
vid(id) += (int)fast_sign(s(id)); 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;
l -= d; float l = s.head(3).norm();
offset.array() -= d; Vector3f L(l / s(0), l / s(1), l / s(2));
offset(id) = fmin(L(id),l);
} // 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; 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 // 20150528 SV for absorbed muons
VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const {
{ RayData ray;
RayData ray;
Vector4f pt = m_Image->GetLocalPoint(line.origin); Vector4f pt = m_Image->GetLocalPoint(line.origin);
Vector4f s = m_Image->GetLocalPoint(line.direction); Vector4f s = m_Image->GetLocalPoint(line.direction);
float l = s.head(3).norm(); float l = s.head(3).norm();
// intersection between track and grid when spacing is +1 // intersection between track and grid when spacing is +1
Vector3f L(l/s(0), l/s(1), l/s(2)); Vector3f L(l / s(0), l / s(1), l / s(2));
// RayTracer works with a grid of interspace +1 // RayTracer works with a grid of interspace +1
// Vector3f scale; // FIXXX // Vector3f scale; // FIXXX
// scale << (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(), // scale << (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(),
// (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(), // (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(),
// (m_Image->GetWorldMatrix() * Vector4f(0,0,1,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 // offset is the fraction of the segment between grid lines when origin is
// cwiseAbs for having positive distances // insiede voxel cwiseAbs for having positive distances
Vector3f offset; Vector3f offset;
for(int i=0;i<3;++i) for (int i = 0; i < 3; ++i)
offset(i) = (s(i)>=0) - (pt(i)-floor(pt(i))); offset(i) = (s(i) >= 0) - (pt(i) - floor(pt(i)));
offset = offset.cwiseProduct(L).cwiseAbs(); offset = offset.cwiseProduct(L).cwiseAbs();
L = L.cwiseAbs(); L = L.cwiseAbs();
int id; float d; int id;
Vector3i vid = m_Image->Find(line.origin); float d;
while(m_Image->IsInsideGrid(vid)) Vector3i vid = m_Image->Find(line.origin);
{ while (m_Image->IsInsideGrid(vid)) {
// minimun coefficient of offset: id is the coordinate, d is the value // minimun coefficient of offset: id is the coordinate, d is the value
// dependig on which grid line horizontal or vertical it is first intercept // dependig on which grid line horizontal or vertical it is first intercept
d = offset.minCoeff(&id); d = offset.minCoeff(&id);
// add Lij to ray // add Lij to ray
ray.AddElement(m_Image->Map(vid), d * m_scale(id) ); ray.AddElement(m_Image->Map(vid), d * m_scale(id));
// move to the next voxel // move to the next voxel
vid(id) += (int)fast_sign(s(id)); vid(id) += (int)fast_sign(s(id));
offset.array() -= d; offset.array() -= d;
offset(id) = L(id); offset(id) = L(id);
} }
return ray; return ray;
} }
} } // namespace uLib

View File

@@ -23,88 +23,90 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "Math/Accumulator.h" #include "Math/Accumulator.h"
#include "testing-prototype.h" #include "testing-prototype.h"
#include <TRandom.h> #include <TRandom.h>
#include <iostream>
#include <vector>
// #include <boost/accumulators/framework/accumulator_set.hpp>
//#include <boost/accumulators/framework/accumulator_set.hpp> // #include <boost/accumulators/statistics/count.hpp>
//#include <boost/accumulators/statistics/count.hpp> // #include <boost/accumulators/accumulators.hpp>
//#include <boost/accumulators/accumulators.hpp>
using namespace uLib; using namespace uLib;
int test_ABTrim() { int test_ABTrim() {
Accumulator_ABTrim<float> acc; Accumulator_ABTrim<float> acc;
acc.SetABTrim(1,1); acc.SetABTrim(1, 1);
std::vector<float> v; std::vector<float> v;
for(float tmpf : {1,5,5,5,300}) v.push_back(tmpf); for (float tmpf : {1, 5, 5, 5, 300})
//v << 1,5,5,5,300; v.push_back(tmpf);
// v << 1,5,5,5,300;
for(std::vector<float>::iterator itr=v.begin(); itr<v.end(); itr++) for (std::vector<float>::iterator itr = v.begin(); itr < v.end(); itr++)
acc += *itr; acc += *itr;
// TODO missing operator << // TODO missing operator <<
//std::cout << "Accumulating Trim(1,1) vector: " // std::cout << "Accumulating Trim(1,1) vector: "
// << v << " ... out = " << acc() << "\n"; // << v << " ... out = " << acc() << "\n";
return( acc() == 15.0 );
return (acc() == 15.0);
} }
int test_Mean() { int test_Mean() {
Accumulator_Mean<float> mean; Accumulator_Mean<float> mean;
TRandom rnd; TRandom rnd;
const int c = 10000000; const int c = 10000000;
std::vector<float> v; std::vector<float> v;
v.reserve(c); v.reserve(c);
for(int i=0;i<c;++i) v.push_back( rnd.Gaus(2000,5) ); for (int i = 0; i < c; ++i)
v.push_back(rnd.Gaus(2000, 5));
float m = 0;
for(int i=0;i<c;++i) m += v[i];
m /= c;
std::cout << "simple mean: " << m << "\n";
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for(int i=0;i<c;++i) mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
float m = 0;
for (int i = 0; i < c; ++i)
m += v[i];
m /= c;
std::cout << "simple mean: " << m << "\n";
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
mean.AddPass();
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
return 1;
} }
int main(void) { int main(void) {
BEGIN_TESTING(Accumulator); BEGIN_TESTING(Accumulator);
//TEST1( test_ABTrim() ); // TEST1( test_ABTrim() );
test_Mean(); test_Mean();
END_TESTING; END_TESTING;
} }

View File

@@ -17,6 +17,12 @@ set(TESTS
set(LIBRARIES set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
Boost::serialization
Eigen3::Eigen
) )
uLib_add_tests(${uLib-module}) uLib_add_tests(Math)
if(USE_CUDA)
set_source_files_properties(VoxImageFilterTest.cpp PROPERTIES LANGUAGE CUDA)
endif()

View File

@@ -23,30 +23,25 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h" #include "testing-prototype.h"
#include "Math/TriangleMesh.h" #include "Math/TriangleMesh.h"
#include <iostream>
using namespace uLib; using namespace uLib;
int main() int main() {
{ BEGIN_TESTING(Triangle Mesh);
BEGIN_TESTING(Triangle Mesh);
TriangleMesh mesh; TriangleMesh mesh;
mesh.AddPoint(Vector3f(0,0,0)); mesh.AddPoint(Vector3f(0, 0, 0));
mesh.AddPoint(Vector3f(0,1,0)); mesh.AddPoint(Vector3f(0, 1, 0));
mesh.AddPoint(Vector3f(1,0,0)); mesh.AddPoint(Vector3f(1, 0, 0));
mesh.AddTriangle(Vector3i(0,1,2)); mesh.AddTriangle(Vector3i(0, 1, 2));
mesh.PrintSelf(std::cout);
mesh.PrintSelf(std::cout); END_TESTING;
END_TESTING;
} }

View File

@@ -23,128 +23,191 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/StructuredGrid.h" #include "Math/StructuredGrid.h"
#include "testing-prototype.h"
#include "Math/VoxImage.h" #include "Math/VoxImage.h"
#include "Math/VoxImageFilter.h" #include "Math/VoxImageFilter.h"
using namespace uLib; using namespace uLib;
struct TestVoxel { struct TestVoxel {
Scalarf Value; Scalarf Value;
unsigned int Count; unsigned int Count;
}; };
float GaussianShape(float d) float GaussianShape(float d) {
{ // normalized manually .. fix //
// normalized manually .. fix // return 4.5 * exp(-d * 4.5);
return 4.5 * exp(-d * 4.5);
} }
class GaussianShapeClass : public Interface::VoxImageFilterShape { class GaussianShapeClass : public Interface::VoxImageFilterShape {
public: public:
GaussianShapeClass(float sigma) : GaussianShapeClass(float sigma) : m_sigma(sigma) {}
m_sigma(sigma)
{}
float operator ()(float d) { float operator()(float d) { return (1 / m_sigma) * exp(-d / m_sigma); }
return (1/m_sigma) * exp(-d/m_sigma);
}
private: private:
float m_sigma; float m_sigma;
}; };
static float MaxInVector(const std::vector<float> &v) {
static float MaxInVector(const std::vector<float> &v) float max = 0;
{ for (int i = 0; i < v.size(); ++i)
float max = 0; if (v.at(i) > max)
for(int i=0; i<v.size(); ++i) max = v.at(i);
if(v.at(i) > max) max = v.at(i); return max;
return max;
} }
int main() {
BEGIN_TESTING(VoxImageFilters);
int main() VoxImage<TestVoxel> image(Vector3i(20, 30, 40));
{ image[Vector3i(10, 10, 10)].Value = 1;
BEGIN_TESTING(VoxImageFilters); // image[Vector3i(10,10,8)].Value = 1;
image.ExportToVtk("test_filter_original.vtk", 0);
VoxImage<TestVoxel> 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<TestVoxel> filter(Vector3i(2, 3, 4));
VoxImage<TestVoxel> filtered = image;
//////////////////////////////////////////////////////////////////////////// std::vector<float> values;
//////////////////////////////////////////////////////////////////////////// for (int i = 0; i < filter.GetKernelData().GetDims().prod(); ++i) {
//////////////////////////////////////////////////////////////////////////// values.push_back(1.);
// RPS // std::cout << values[i] << " ";
}
std::cout << "\n";
{ filter.SetImage(&filtered);
VoxFilterAlgorithmSPR<TestVoxel> filter(Vector3i(2,3,4));
VoxImage<TestVoxel> filtered = image; filter.SetKernelNumericXZY(values);
std::vector<float> values; filter.SetABTrim(0, 2);
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.GetKernelData().PrintSelf(std::cout);
filter.SetKernelNumericXZY(values); filter.Run();
filter.SetABTrim(0,2); filtered.ExportToVtk("filter_RPS_out.vtk", 0);
}
filter.GetKernelData().PrintSelf(std::cout); {
filter.Run(); VoxImage<TestVoxel> 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);
filtered.ExportToVtk("filter_RPS_out.vtk",0); VoxFilterAlgorithmCustom<TestVoxel> filter(Vector3i(3, 3, 4));
std::vector<float> values;
for (int i = 0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(static_cast<float>(1));
} }
filter.SetImage(&image);
filter.SetKernelNumericXZY(values);
filter.SetCustomEvaluate(MaxInVector);
filter.Run();
{ image.ExportToVtk("test_filter_max.vtk", 0);
}
VoxImage<TestVoxel> image(Vector3i(20,30,40)); ////////////////////////////////////////////////////////////////////////////
image[Vector3i(10,10,10)].Value = 1; // CUDA Allocator Transfer Test //
image[Vector3i(9,10,8)].Value = 2; {
image.ExportToVtk("test_filter_max_original.vtk",0); VoxImage<TestVoxel> image(Vector3i(10, 10, 10));
image[Vector3i(5, 5, 5)].Value = 1;
VoxFilterAlgorithmLinear<TestVoxel> filter(Vector3i(3, 3, 3));
std::vector<float> values;
VoxFilterAlgorithmCustom<TestVoxel> filter(Vector3i(3,3,4)); for (int i = 0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(1.0f);
std::vector<float> values;
for(int i=0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(static_cast<float>(1));
}
filter.SetImage(&image);
filter.SetKernelNumericXZY(values);
filter.SetCustomEvaluate(MaxInVector);
filter.Run();
image.ExportToVtk("test_filter_max.vtk",0);
} }
filter.SetImage(&image);
filter.SetKernelNumericXZY(values);
// Move the kernel data and image data to VRAM to simulate CUDA transfer
filter.GetKernelData().Data().MoveToVRAM();
image.Data().MoveToVRAM();
END_TESTING; // Validate devices
if (filter.GetKernelData().Data().GetDevice() != MemoryDevice::VRAM ||
image.Data().GetDevice() != MemoryDevice::VRAM) {
#ifdef USE_CUDA
std::cerr << "Failed to move memory to VRAM." << std::endl;
#else
std::cout << "DataAllocator correctly simulates VRAM without crashing."
<< std::endl;
#endif
}
// Run the filter; The fallback CPU filter will trigger MoveToRAM
// behind the scenes inside Convolve / Evaluate.
filter.Run();
// Assert it came back to RAM if evaluated on CPU
if (image.Data().GetDevice() != MemoryDevice::RAM) {
#ifdef USE_CUDA
std::cout << "Data correctly stayed in VRAM after CUDA execution!"
<< std::endl;
#else
std::cout << "Data correctly stayed in RAM simulation." << std::endl;
#endif
}
image.ExportToVtk("test_filter_cuda_transfer.vtk", 0);
}
////////////////////////////////////////////////////////////////////////////
// CUDA ABTrim Allocator Transfer Test //
{
VoxImage<TestVoxel> image(Vector3i(10, 10, 10));
image[Vector3i(5, 5, 5)].Value = 10;
image[Vector3i(5, 5, 6)].Value = 2; // Test trimming
VoxFilterAlgorithmAbtrim<TestVoxel> filter(Vector3i(3, 3, 3));
std::vector<float> values;
for (int i = 0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(1.0f);
}
filter.SetImage(&image);
filter.SetKernelNumericXZY(values);
filter.SetABTrim(1, 1); // trim highest and lowest
// Move the kernel data and image data to VRAM to simulate CUDA transfer
filter.GetKernelData().Data().MoveToVRAM();
image.Data().MoveToVRAM();
// Run the filter
filter.Run();
// Ensure data stays on device if CUDA was toggled
if (image.Data().GetDevice() != MemoryDevice::RAM) {
#ifdef USE_CUDA
std::cout << "ABTrim correctly stayed in VRAM after CUDA execution!"
<< std::endl;
#else
std::cout << "ABTrim Data correctly stayed in RAM simulation."
<< std::endl;
#endif
}
image.ExportToVtk("test_filter_abtrim_cuda_transfer.vtk", 0);
}
END_TESTING;
} }

View File

@@ -92,6 +92,20 @@ int main() {
imgR.ExportToVtk("./read_and_saved.vtk"); imgR.ExportToVtk("./read_and_saved.vtk");
} }
{
VoxImage<TestVoxel> img(Vector3i(4,4,4));
img.InitVoxels({0,0});
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
for (int k=0; k<4; k++) {
img[Vector3i(i,j,k)] = {i+j+k,0};
}
}
}
img.ExportToVti("./vti_saved.vti",0,1);
// img.ImportFromVtkXml("./test_vox_image.vti");
}
{ {
VoxImage<TestVoxel> img1(Vector3i(5,5,5)); VoxImage<TestVoxel> img1(Vector3i(5,5,5));

View File

@@ -23,129 +23,114 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Math/VoxRaytracer.h" #include "Math/VoxRaytracer.h"
#include "Math/StructuredGrid.h"
#include "testing-prototype.h" #include "testing-prototype.h"
#include <iostream>
using namespace uLib; using namespace uLib;
int Vector4f0(Vector4f c) {
int Vector4f0(Vector4f c)
{
c(3) = 0; c(3) = 0;
if ( fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001 ) if (fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001)
return 0; return 0;
else else
return 1; return 1;
} }
//bool Comapare(const &t1, const T2 &t2) // bool Comapare(const &t1, const T2 &t2)
//{ //{
// int out = 0; // int out = 0;
// out += t1.vox_id != t2.vox_id; // out += t1.vox_id != t2.vox_id;
// out += (fabs(t1.L) - fabs(t2.L)) > 0.001; // out += (fabs(t1.L) - fabs(t2.L)) > 0.001;
// return out == 0; // return out == 0;
//} // }
typedef VoxRaytracer Raytracer; typedef VoxRaytracer Raytracer;
int main() int main() {
{ BEGIN_TESTING(Math VoxRaytracer);
BEGIN_TESTING(Math VoxRaytracer);
StructuredGrid img(Vector3i(2,2,2)); StructuredGrid img(Vector3i(2, 2, 2));
img.SetSpacing(Vector3f(2,2,2)); img.SetSpacing(Vector3f(2, 2, 2));
img.SetPosition(Vector3f(-2,0,-2)); img.SetPosition(Vector3f(-2, 0, -2));
{ {
HLine3f line; HLine3f line;
line.origin << 0.1, 4.1, 0.1, 1; line.origin << 0.1, 4.1, 0.1, 1;
line.direction << 0.1, -0.1, 0.1,0; line.direction << 0.1, -0.1, 0.1, 0;
Raytracer rt(img); Raytracer rt(img);
HPoint3f pt; HPoint3f pt;
TEST1( rt.GetEntryPoint(line,pt) ); TEST1(rt.GetEntryPoint(line, pt));
TEST0( Vector4f0( pt - HPoint3f(0.2,4,0.2) ) ); 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));
for (const Raytracer::RayData::Element &el : rdata.Data()) {
std::cout << " " << el.vox_id << " , " << el.L << "\n";
} }
}
{ {
HLine3f line; HPoint3f pt1(1, -0.5, 1);
line.origin << 4,0,4, 1; HPoint3f pt2(1, 4.5, 1);
line.direction << -0.1, 0.1, -0.1, 0; Raytracer rt(img);
Raytracer rt(img);
HPoint3f pt;
TEST1( rt.GetEntryPoint(line,pt) );
TEST0( Vector4f0( pt - HPoint3f(2,2,2) ) );
}
{ // Test a point inside image // Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2);
StructuredGrid img(Vector3i(4,4,4)); TEST1(ray.Data().size() == 2);
img.SetSpacing(Vector3f(2,2,2)); TEST1(ray.Data().at(0).vox_id == 6);
img.SetPosition(Vector3f(-4,-4,-4)); TEST1(ray.Data().at(1).vox_id == 7);
Raytracer ray(img); ray.PrintSelf(std::cout);
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)); {
for(const Raytracer::RayData::Element &el : rdata.Data()) HPoint3f pt1(5, 1, 1);
{ HPoint3f pt2(-3, 1, 1);
std::cout << " " << el.vox_id << " , " << el.L << "\n"; 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,-0.5,1); HPoint3f pt1(1, 1, 1);
HPoint3f pt2(1,4.5,1); HPoint3f pt2(-1, 3, -1);
Raytracer rt(img); Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1,pt2); Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2);
TEST1( ray.Data().size() == 2 ); TEST1(ray.Data().size() == 4);
TEST1( ray.Data().at(0).vox_id == 6 ); TEST1(ray.Data().at(0).vox_id == 6);
TEST1( ray.Data().at(1).vox_id == 7 ); TEST1(ray.Data().at(1).vox_id == 4);
ray.PrintSelf(std::cout); TEST1(ray.Data().at(2).vox_id == 5);
} TEST1(ray.Data().at(3).vox_id == 1);
ray.PrintSelf(std::cout);
}
{ END_TESTING
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
} }

View File

@@ -5,6 +5,8 @@ set(HEADERS RootMathDense.h
muCastorHit.h muCastorHit.h
muCastorInfo.h muCastorInfo.h
muCastorSkinHit.h muCastorSkinHit.h
muCastorPrimaryVertex.h
muCastorMuDetDIGI.h
SkinDetectorWriter.h) SkinDetectorWriter.h)
set(SOURCES ${HEADERS} RootMuonScatter.cpp set(SOURCES ${HEADERS} RootMuonScatter.cpp
@@ -12,12 +14,16 @@ set(SOURCES ${HEADERS} RootMuonScatter.cpp
muCastorHit.cpp muCastorHit.cpp
muCastorInfo.cpp muCastorInfo.cpp
muCastorSkinHit.cpp muCastorSkinHit.cpp
muCastorPrimaryVertex.cpp
muCastorMuDetDIGI.cpp
SkinDetectorWriter.cpp) SkinDetectorWriter.cpp)
set(DICTIONARY_HEADERS muCastorMCTrack.h set(DICTIONARY_HEADERS muCastorMCTrack.h
muCastorHit.h muCastorHit.h
muCastorInfo.h muCastorInfo.h
muCastorSkinHit.h muCastorSkinHit.h
muCastorPrimaryVertex.h
muCastorMuDetDIGI.h
SkinDetectorWriter.h) SkinDetectorWriter.h)
set(LIBRARIES ${ROOT_LIBRARIES} set(LIBRARIES ${ROOT_LIBRARIES}
@@ -36,7 +42,7 @@ list(APPEND SOURCES ${rDictName}.cxx)
set(R_ARTIFACTS ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}_rdict.pcm set(R_ARTIFACTS ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}_rdict.pcm
${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}.rootmap) ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}.rootmap)
install(FILES ${R_ARTIFACTS} install(FILES ${R_ARTIFACTS}
DESTINATION ${PACKAGE_INSTALL_LIB_DIR}) DESTINATION ${INSTALL_LIB_DIR})
set(libname ${PACKAGE_LIBPREFIX}Root) set(libname ${PACKAGE_LIBPREFIX}Root)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE) set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -45,14 +51,18 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Root PARENT_SCOPE)
add_library(${libname} SHARED ${SOURCES}) add_library(${libname} SHARED ${SOURCES})
set_target_properties(${libname} PROPERTIES set_target_properties(${libname} PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}) SOVERSION ${PROJECT_SOVERSION}
CXX_STANDARD 17)
target_link_libraries(${libname} ${LIBRARIES}) target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname} install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib) LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Root)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
#ifndef U_ROOT_LINKDEF_H #ifndef U_ROOT_LINKDEF_H
#define U_ROOT_LINKDEF_H #define U_ROOT_LINKDEF_H
@@ -35,53 +33,21 @@
#pragma link off all functions; #pragma link off all functions;
#pragma link C++ nestedclasses; #pragma link C++ nestedclasses;
#pragma link C++ class TestTObject+;
using namespace ROOT::Mutom; using namespace ROOT::Mutom;
#pragma link C++ class ROOT::Math::Cartesian2D<int>+; #pragma link C++ class ROOT::Math::Cartesian3D < int> + ;
#pragma link C++ class ROOT::Math::Cartesian2D<float>+; #pragma link C++ class ROOT::Math::Cartesian3D < float> + ;
#pragma link C++ class ROOT::Math::Cartesian2D<double>+; #pragma link C++ class ROOT::Math::Cartesian3D < double> + ;
#pragma link C++ class ROOT::Math::Cartesian3D<int>+;
#pragma link C++ class ROOT::Math::Cartesian3D<float>+;
#pragma link C++ class ROOT::Math::Cartesian3D<double>+;
#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 DetectorChamber+;
#pragma link C++ class HitRaw+; #pragma link C++ class muCastorMCTrack + ;
#pragma link C++ function HitRaw::Chm() const; #pragma link C++ class muCastorHit + ;
#pragma link C++ function HitRaw::Rob() const; #pragma link C++ class muCastorInfo + ;
#pragma link C++ function HitRaw::Tdc() const; #pragma link C++ class muCastorSkinHit + ;
#pragma link C++ function HitRaw::Ch() const; #pragma link C++ class muCastorPrimaryVertex + ;
#pragma link C++ class muCastorMuDetDIGI + ;
#pragma link C++ class muBlastMCTrack+; #pragma link C++ class SkinDetectorWriter + ;
#pragma link C++ class muBlastHit+;
#pragma link C++ class muCastorMCTrack+;
#pragma link C++ class muCastorHit+;
#pragma link C++ class muCastorInfo+;
#pragma link C++ class muCastorSkinHit+;
#pragma link C++ class SkinDetectorWriter+;
#endif // __CINT__ #endif // __CINT__

View File

@@ -0,0 +1,41 @@
/// \file muCastorMuDetDIGI.cxx
/// \brief Implementation of the muCastorMuDetDIGI class
// This class build the DIGI for the scintillator detectors
/// \author G. Bonomi, M. Subieta - INFN
#include <iostream>
#include "muCastorMuDetDIGI.h"
/// \cond CLASSIMP
ClassImp(muCastorMuDetDIGI)
/// \endcond
using namespace std;
//_____________________________________________________________________________
muCastorMuDetDIGI::muCastorMuDetDIGI() :
fDetID(-1),
fLayID(-1),
fTubID(-1),
fDistMC(0.),
fDriftMC(0.),
fDist(0.),
fDrift(0.),
fEnergy(0.)
{}
//_____________________________________________________________________________
muCastorMuDetDIGI::~muCastorMuDetDIGI()
{}
//_____________________________________________________________________________
void muCastorMuDetDIGI::Print(const Option_t* /*opt*/) const
{
cout << " DetID: " << fDetID
<< " LayID: " << fLayID
<< " TubID: " << fTubID
<< " energy deposit (keV): " << fEnergy
<< endl;
}

View File

@@ -0,0 +1,75 @@
#ifndef muCastor_MuDetDIGI_H
#define muCastor_MuDetDIGI_H
/// \file muCastorMuDetDIGI.h
/// \brief Definition of the muCastorMuDetDIGI class
///
/// \authors G. Bonomi, M. Subieta - INFN
#include <TObject.h>
class muCastorMuDetDIGI : public TObject
{
public:
muCastorMuDetDIGI();
virtual ~muCastorMuDetDIGI();
// -------> PUBLIC FUNCTIONS
virtual void Print(const Option_t* option = "") const;
// -------> SET METHODS
/// Set Det ID (Detector module)
void SetDetID(Int_t id) { fDetID = id; };
/// Set Layer ID (Layer [0,5])
void SetLayID(Int_t id) { fLayID = id; };
/// Set Tube ID (Tube inside each layer)
void SetTubID(Int_t id) { fTubID = id; };
void SetDistMC (Double_t v) { fDistMC = v; };
void SetDriftMC (Double_t v) { fDriftMC= v; };
void SetDist (Double_t v) { fDist = v; };
void SetDrift (Double_t v) { fDrift = v; };
// Set energy
void SetEnergy(Double_t e) { fEnergy = e; };
// -------> GET METHODS
/// \return The Module number
Int_t GetDetID() { return fDetID; };
/// \return The Layer number
Int_t GetLayID() { return fLayID; };
/// \return The Tube number
Int_t GetTubID() { return fTubID; };
Double_t GetDistMC() { return fDistMC; };
Double_t GetDriftMC() { return fDriftMC; };
Double_t GetDist() { return fDist; };
Double_t GetDrift() { return fDrift; };
/// \return Get energy
Double_t GetEnergy() { return fEnergy; };
// -------> PRIVATE VARIABLES
private:
Int_t fDetID; // Detector module ID
Int_t fLayID; // Detector layer ID
Int_t fTubID; // Layer tube ID
Double_t fDistMC; // Minimum distance of particle tracks to the wire
Double_t fDriftMC; // Minimum drift time to the wire
Double_t fDist; // Minimum distance of particle tracks to the wire (with smearing)
Double_t fDrift; // Minimum drift time to the wire (with smearing)
Double_t fEnergy; // Energy released in the element
ClassDef(muCastorMuDetDIGI,1) //muCastorMuDetDIGI
};
#endif //muCastorMuDetDIGI_H

View File

@@ -0,0 +1,47 @@
#include <iostream>
#include <limits>
#include "muCastorPrimaryVertex.h"
/// \cond CLASSIMP
ClassImp(muCastorPrimaryVertex)
/// \endcond
using namespace std;
//_____________________________________________________________________________
muCastorPrimaryVertex::muCastorPrimaryVertex() {
/// Default constructor
Reset();
}
//_____________________________________________________________________________
muCastorPrimaryVertex::~muCastorPrimaryVertex()
{
/// Destructor
}
//_____________________________________________________________________________
void muCastorPrimaryVertex::Reset()
{
fPdgCode = 0;
fVx = std::numeric_limits<double>::quiet_NaN();
fVy = std::numeric_limits<double>::quiet_NaN();
fVz = std::numeric_limits<double>::quiet_NaN();
fPx = std::numeric_limits<double>::quiet_NaN();
fPy = std::numeric_limits<double>::quiet_NaN();
fPz = std::numeric_limits<double>::quiet_NaN();
fE = std::numeric_limits<double>::quiet_NaN();
}
//_____________________________________________________________________________
void muCastorPrimaryVertex::Print(const Option_t* /*opt*/) const
{
/// Printing
cout << " Primary particle PDG Code " << fPdgCode << endl;
cout << " Vertex: (" << fVx << ", " << fVy << ", " << fVz << ") cm" << endl;
cout << " Mom: (" << fPx << ", " << fPy << ", " << fPz << ") MeV/c" << endl;
}

View File

@@ -0,0 +1,53 @@
#ifndef muCastor_PVTX_H
#define muCastor_PVTX_H
/// \brief Definition of the muCastorPrimaryVertex class
///
/// \authors G. Bonomi (04/02/2020)
#include <TObject.h>
class muCastorPrimaryVertex : public TObject
{
public:
muCastorPrimaryVertex();
virtual ~muCastorPrimaryVertex();
// -------> PUBLIC FUNCTIONS
virtual void Print(const Option_t* option = "") const;
// -------> SET METHODS
void SetPdgCode(Int_t code) { fPdgCode = code; };
void SetVx(Double_t Vx) { fVx = Vx; };
void SetVy(Double_t Vy) { fVy = Vy; };
void SetVz(Double_t Vz) { fVz = Vz; };
void SetPx(Double_t Px) { fPx = Px; };
void SetPy(Double_t Py) { fPy = Py; };
void SetPz(Double_t Pz) { fPz = Pz; };
void SetE(Double_t E) { fE = E; };
void Reset();
private:
// -------> PRIVATE VARIABLES
Int_t fPdgCode; // PDG code of the particle
Double_t fVx; // x of production vertex
Double_t fVy; // y of production vertex
Double_t fVz; // z of production vertex
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
ClassDef(muCastorPrimaryVertex,1) //muCastorPrimaryVertex
};
#endif //muCastor_PVTX_H

View File

@@ -8,9 +8,8 @@ set(LIBRARIES
${PACKAGE_LIBPREFIX}Core ${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math ${PACKAGE_LIBPREFIX}Math
${PACKAGE_LIBPREFIX}Root ${PACKAGE_LIBPREFIX}Root
${Boost_SERIALIZATION_LIBRARY} Boost::serialization
${Boost_SIGNALS_LIBRARY} Boost::program_options
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
) )
uLib_add_tests(${uLib-module}) uLib_add_tests(Root)

View File

@@ -14,7 +14,7 @@ set(SOURCES uLibVtkInterface.cxx
vtkVoxRaytracerRepresentation.cpp vtkVoxRaytracerRepresentation.cpp
vtkVoxImage.cpp) vtkVoxImage.cpp)
set(LIBRARIES ${Eigen_LIBRARY} set(LIBRARIES Eigen3::Eigen
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
${VTK_LIBRARIES} ${VTK_LIBRARIES}
${PACKAGE_LIBPREFIX}Math) ${PACKAGE_LIBPREFIX}Math)
@@ -31,8 +31,12 @@ target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname} install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets" EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib) LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Vtk) install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

View File

@@ -14,5 +14,5 @@ set(LIBRARIES
${PACKAGE_LIBPREFIX}Vtk ${PACKAGE_LIBPREFIX}Vtk
) )
include(${VTK_USE_FILE}) # include(${VTK_USE_FILE})
uLib_add_tests(${uLib-module}) uLib_add_tests(Vtk)

View File

@@ -37,7 +37,7 @@
#endif #endif
#include <vtkConfigure.h> #include <vtkVersion.h>
#include <vtkProp.h> #include <vtkProp.h>
#include <vtkActor.h> #include <vtkActor.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>

View File

@@ -65,6 +65,7 @@ vtkContainerBox::~vtkContainerBox()
vtkPolyData *vtkContainerBox::GetPolyData() const vtkPolyData *vtkContainerBox::GetPolyData() const
{ {
// TODO // TODO
return NULL;
} }
void vtkContainerBox::InstallPipe() void vtkContainerBox::InstallPipe()

View File

@@ -28,7 +28,7 @@
#ifndef VTKMUONSCATTER_H #ifndef VTKMUONSCATTER_H
#define VTKMUONSCATTER_H #define VTKMUONSCATTER_H
#include <vtkConfigure.h> #include <vtkVersion.h>
#include <vtkSmartPointer.h> #include <vtkSmartPointer.h>
#include <vtkSphereSource.h> #include <vtkSphereSource.h>
#include <vtkAppendPolyData.h> #include <vtkAppendPolyData.h>

View File

@@ -28,11 +28,11 @@
#ifndef U_VTKVOXIMAGE_H #ifndef U_VTKVOXIMAGE_H
#define U_VTKVOXIMAGE_H #define U_VTKVOXIMAGE_H
#include "vtk/vtkVolume.h" #include <vtkVolume.h>
#include "vtk/vtkImageData.h" #include <vtkImageData.h>
#include "vtk/vtkXMLImageDataReader.h" #include <vtkXMLImageDataReader.h>
#include "vtk/vtkXMLImageDataWriter.h" #include <vtkXMLImageDataWriter.h>
#include "vtk/vtkCubeSource.h" #include <vtkCubeSource.h>
#include <Math/VoxImage.h> #include <Math/VoxImage.h>

View File

@@ -1,12 +0,0 @@
set(HEADERS
ltktypes.h
ltkmacros.h
ltkdebug.h
)
SET(SOURCES)
set(LIBRARIES)
uLib_add_shared_library(${uLib-module})

View File

@@ -1,111 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <typename T, unsigned int csize, unsigned int rsize> class ltkDenseMatrix
: public ltkAbstractBuffer< T, csize * rsize >
{
protected:
typedef ltkDenseMatrix<T, csize, rsize> ThisClass;
typedef ltkAbstractBuffer<T, csize * rsize> 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

View File

@@ -1,6 +0,0 @@
include $(top_srcdir)/Common.am
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ltk
library_include_HEADERS = ltktypes.h \
ltkmacros.h \
ltkdebug.h

View File

@@ -1,18 +0,0 @@
#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;
}

View File

@@ -1,78 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <stdlib.h> // for std allocator //
#include <string.h> // for memcpy //
#include <assert.h>
#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

View File

@@ -1,195 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <stdlib.h> // for std allocator //
#include <string.h> // for memcpy //
#include <assert.h>
#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 <typename T, unsigned int size> class ltkVector
: public ltkAbstractBuffer< T, size >
{
T m_vector [size];
protected:
typedef ltkVector<T, size> ThisClass;
typedef ltkAbstractBuffer<T, size> BaseClass;
public:
ltkVector() {}
ltkVector(const ltkVector<T, size> &copy) {
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 */

View File

@@ -1,43 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <assert.h>
#endif /* CONTAINER_H */

View File

@@ -1,32 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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"

View File

@@ -1,339 +0,0 @@
//#include <linux/config.h>
#include <linux/version.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/ioctl.h>
#ifdef MODVERSIONS
# include <linux/modversions.h>
#endif
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>
/* 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, &ltkb_fops);
dev->cdev.owner = THIS_MODULE;
dev->cdev.ops = &ltkb_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<LTKB_NR_DEVS;i++)
cdev_del(&_ltkb_devices[i].cdev);
kfree(_ltkb_devices);
}
unregister_chrdev_region(devno,LTKB_NR_DEVS);
printk( KERN_NOTICE "ltk bridge module unloaded");
}
// ------------------------------------------------------------------------ //
//////////////////// Main Module Init ///////////////////
//
module_init(ltkb_init); //
module_exit(ltkb_exit); //
//
MODULE_DESCRIPTION("ltk bridge memory dispatcher"); //
MODULE_AUTHOR("andrea"); //
MODULE_LICENSE("Not licenced yet"); //
//
/////////////////////////////////////////////////////////

View File

@@ -1,40 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#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);
}

View File

@@ -1,21 +0,0 @@
#!/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]

View File

@@ -1,4 +0,0 @@
#include "ltkdebug.h"

View File

@@ -1,105 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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

View File

@@ -1,61 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 */

View File

@@ -1,127 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <assert.h>
#include <sys/types.h>
//#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

View File

@@ -1,72 +0,0 @@
#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;
}

View File

@@ -1,92 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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;
}

View File

@@ -1,303 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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.
//////////////////////////////////////////////////////////////////////////////*/
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef TEMPLATES_H
#define TEMPLATES_H
#include <stdlib.h> // for std allocator //
#include <string.h> // for memcpy //
#include <assert.h>
#include "ltkmacros.h" // default environment //
#include "container.h" // TODO !!! //
#include <stdio.h>
/* ////////////////////////////////////////////////////////////////////////// */
/* //////////////////////////// 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 <typename T, unsigned int size> class ltkAbstractBuffer
{
typedef ltkAbstractBuffer<T, size> ThisClass;
protected:
typedef T ContentType;
virtual T* getBuffer() = 0;
virtual const T* getBuffer() const = 0;
struct CommaInit
{
inline explicit CommaInit(ltkAbstractBuffer<T, size> *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<T, size> *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

View File

@@ -1,117 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 <assert.h>
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 <typename T, unsigned int size> 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<Container, 3> operator=(float s) {
return CommaAssign<Container, 3 > (this, s);
}
};
#endif /* TEST_COMMA_H */

View File

@@ -1,37 +0,0 @@
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

View File

@@ -1,40 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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;
}

View File

@@ -1,11 +0,0 @@
#include "testing-prototype.h"
#include "../Object.h"
int main() {
BEGIN_TESTING(Object);
struct _Object *ob = Object_new(ObjectClass);
END_TESTING;
}

View File

@@ -1,79 +0,0 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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<int, 4 > 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;
}

View File

@@ -1,14 +0,0 @@
#include <stdio.h>
#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;
}

Some files were not shown because too many files have changed in this diff Show More