35 Commits

Author SHA1 Message Date
AndreaRigoni
554eff9b55 add filters in python bindings 2026-03-05 15:03:19 +00:00
AndreaRigoni
42db99759f fix py dense 2026-03-05 14:26:05 +00:00
AndreaRigoni
69920acd61 poetry python build 2026-03-05 12:42:14 +00:00
AndreaRigoni
647d0caa1c feat: Add Python packaging infrastructure and comprehensive bindings for math and vector types. 2026-03-05 11:39:27 +00:00
AndreaRigoni
e69b29a259 add first python bindings 2026-03-05 09:16:15 +00:00
AndreaRigoni
9a59e031ed feat: Implement a custom MetaAllocator for uLib::Vector to enable GPU memory management and integrate CUDA support into the build system. 2026-03-04 20:52:01 +00:00
AndreaRigoni
adedbcc37c feat: add CUDA raytracing benchmark and refactor VoxRaytracer::RayData to use DataAllocator for host/device memory management. 2026-03-04 17:47:18 +00:00
AndreaRigoni
eb76521060 add clangd linting fix 2026-03-04 14:37:02 +00:00
AndreaRigoni
b1fb123026 feat: Implement CUDA support for VoxRaytracer, add CUDA tests for voxel image operations, and update CMake to enable CUDA compilation. 2026-03-04 13:59:45 +00:00
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
Paolo Andreetto
b7c775ee35 Error handling 2023-02-22 11:20:56 +01:00
Paolo Andreetto
7bc4932d09 Missing component for VTK 2023-02-20 16:10:10 +01:00
Paolo Andreetto
8832f47e75 Fixed build for VTK on alma9 2023-02-20 16:08:30 +01:00
Paolo Andreetto
043a44150c New writer class for the skin detector 2023-02-17 14:35:31 +01:00
Paolo Andreetto
fce2a39393 Changed version 2023-01-17 10:36:34 +01:00
Paolo Andreetto
d223a3a308 Restored classes for Castor 2023-01-17 10:36:05 +01:00
Paolo Andreetto
843a2d69cf Removed structures for Castor and muBlast 2020-09-29 15:23:08 +02:00
137 changed files with 7224 additions and 8825 deletions

52
.clangd Normal file
View File

@@ -0,0 +1,52 @@
CompileFlags:
CompilationDatabase: build
Add:
- -I/home/rigoni/devel/cmt/ulib/src
- -isystem/home/share/micromamba/envs/mutom/include
- -isystem/home/share/micromamba/envs/mutom/include/eigen3
- -isystem/home/share/micromamba/envs/mutom/targets/x86_64-linux/include
- -isystem/home/share/micromamba/envs/mutom/lib/gcc/x86_64-conda-linux-gnu/14.3.0/include/c++
- -isystem/isystem/home/share/micromamba/envs/mutom/lib/gcc/x86_64-conda-linux-gnu/14.3.0/include/c++/x86_64-conda-linux-gnu
- -isystem/home/share/micromamba/envs/mutom/x86_64-conda-linux-gnu/sysroot/usr/include
- "--gcc-toolchain=/home/share/micromamba/envs/mutom"
- -D_ULIB_DETAIL_SIGNAL_EMIT
- -DUSE_CUDA
- -std=c++17
- "-D__host__="
- "-D__device__="
- "-D__global__="
- "-D__constant__="
- "-D__shared__="
- "-D__align__(x)="
- "-D__forceinline__=inline"
- "-D__launch_bounds__(x)="
Diagnostics:
UnusedIncludes: None
MissingIncludes: None
---
If:
PathExclude: [/home/rigoni/devel/cmt/ulib/src/.*]
Diagnostics:
Suppress: ["*"]
---
If:
PathMatch: [.*\.cu, .*/src/Math/testing/VoxRaytracerTest.cpp, .*/src/Math/VoxRaytracer.cpp, .*/src/Math/VoxImage.cpp]
CompileFlags:
Add:
- "-x"
- "cuda"
- "--cuda-path=/home/share/micromamba/envs/mutom"
- "--cuda-gpu-arch=sm_61"
- "--gcc-toolchain=/home/share/micromamba/envs/mutom"
- "-L/home/share/micromamba/envs/mutom/lib"
- "-lcudart"
- "-lcuda"
- "-U__host__"
- "-U__device__"
- "-U__global__"
- "-U__constant__"
- "-U__shared__"
- "-U__forceinline__"

11
.gitignore vendored
View File

@@ -1,3 +1,14 @@
CMakeFiles/
build/
.cache/
build_warnings*.log
final_build.log
cmake_configure.log
compile_commands.json
dist/
build_python/
src/Python/uLib/*.so*
src/Python/uLib/*.pyd
src/Python/uLib/*.pyc
src/Python/uLib/__pycache__

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

@@ -0,0 +1,32 @@
{
"clangd.fallbackFlags": [
"-I/home/rigoni/devel/cmt/ulib/src",
"-isystem/home/share/micromamba/envs/mutom/include",
"-isystem/home/share/micromamba/envs/mutom/include/eigen3",
"-isystem/home/share/micromamba/envs/mutom/targets/x86_64-linux/include",
"-isystem/home/share/micromamba/envs/mutom/lib/gcc/x86_64-conda-linux-gnu/14.3.0/include/c++",
"-isystem/home/share/micromamba/envs/mutom/lib/gcc/x86_64-conda-linux-gnu/14.3.0/include/c++/x86_64-conda-linux-gnu",
"-isystem/home/share/micromamba/envs/mutom/x86_64-conda-linux-gnu/sysroot/usr/include",
"--gcc-toolchain=/home/share/micromamba/envs/mutom",
"-D__host__=",
"-D__device__=",
"-D__global__=",
"-D__constant__=",
"-D__shared__=",
"-DUSE_CUDA",
"-D__CUDACC__"
],
"clangd.semanticHighlighting.enable": true,
"clangd.arguments": [
"--compile-commands-dir=build",
"--query-driver=/home/share/micromamba/envs/mutom/bin/g++,/home/share/micromamba/envs/mutom/bin/gcc,/home/share/micromamba/envs/mutom/bin/nvcc",
"--suppress-system-warnings",
"--all-scopes-completion",
"--completion-style=detailed",
"--header-insertion=never",
"-j=4",
"--pch-storage=memory",
"--background-index",
"--log=verbose"
]
}

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)
## Install directories ##
set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(PACKAGE_INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
set(PACKAGE_INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
set(PACKAGE_INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
set(INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
endif()
set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach(p LIB BIN INC DATA CMAKE)
@@ -58,7 +58,7 @@ endif()
set(CMAKE_CXX_WARNING_OPTION "" CACHE STRING "Warning level -WAll to verbose all warnings")
set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE STRING "Verbose compile output switch")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}")
# 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}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib
# PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
# PUBLIC_HEADER DESTINATION ${INSTALL_INC_DIR} COMPONENT dev
)
endif(SOURCES)
if(HEADERS)
foreach(header ${HEADERS})
install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name})
install(FILES ${header} DESTINATION ${INSTALL_INC_DIR}/${name})
endforeach(header)
endif(HEADERS)
@@ -70,7 +70,7 @@ macro(uLib_add_target name)
install(TARGETS ${name}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
)
ENDMACRO(uLib_add_target)
@@ -82,7 +82,7 @@ ENDMACRO(uLib_add_target)
# TESTS and LIBRARIES must be defined
macro(uLib_add_tests name)
foreach(tn ${TESTS})
add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp)
add_executable(${tn} ${tn}.cpp)
add_test(NAME ${tn} COMMAND ${tn})
target_link_libraries(${tn} ${LIBRARIES})
@@ -91,7 +91,9 @@ macro(uLib_add_tests name)
# custom target to compile all tests
add_custom_target(all-${name}-tests)
if(TESTS)
add_dependencies(all-${name}-tests ${TESTS})
endif()
endmacro(uLib_add_tests name)

View File

@@ -3,15 +3,35 @@
##### CMAKE LISTS ##############################################################
################################################################################
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 3.26)
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
## -------------------------------------------------------------------------- ##
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)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -allow-unsupported-compiler")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--diag_suppress=20012\"")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--diag_suppress=20014\"")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--diag_suppress=20015\"")
find_package(CUDAToolkit REQUIRED)
enable_language(CUDA)
set(CMAKE_CUDA_ARCHITECTURES 61)
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
add_compile_definitions(USE_CUDA)
endif()
# The version number.
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 3)
set(PROJECT_VERSION_MINOR 6)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
@@ -33,19 +53,31 @@ message(STATUS "Module path = ${CMAKE_MODULE_PATH}")
## GLOBALS ------------------------------------------------------------------ ##
set(PACKAGE_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin
CACHE PATH "Installation directory for executables")
set(PACKAGE_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/
CACHE PATH "Installation directory for libraries")
set(PACKAGE_INSTALL_INC_DIR ${CMAKE_INSTALL_PREFIX}/include/${PACKAGE_NAME}
CACHE PATH "Installation directory for headers")
set(PACKAGE_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE_NAME}
CACHE PATH "Installation directory for data files")
set(PACKAGE_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PACKAGE_NAME}
CACHE PATH "Installation directory for CMake files")
# -- move to GnuInstallDirs
# ref: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
include(GNUInstallDirs)
set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
CACHE PATH "Location of header files (.../include)" )
set(INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR}/${PACKAGE_NAME}
CACHE PATH "Location of configuration files (.../etc)" )
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR}/${PACKAGE_NAME}
CACHE PATH "Location of executable files (.../bin)" )
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)
# 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)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
@@ -60,27 +92,62 @@ set(CMAKE_CXX_WARNING_OPTION ""
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} -UULIB_SERIALIZATION_ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_WARNING_OPTION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UULIB_SERIALIZATION_ON -Wno-cpp")
# CTEST framework
include(CTest)
enable_testing()
#enable_testing()
## FIND PACKAGES ------------------------------------------------------------ ##
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
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})
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)
include(${ROOT_USE_FILE})
find_package(VTK REQUIRED)
# include(${VTK_USE_FILE})
find_package(pybind11 REQUIRED)
option(CENTOS_SUPPORT "VTK definitions for CentOS" OFF)
if(CENTOS_SUPPORT)
find_package(VTK CONFIG REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(VTK REQUIRED
COMPONENTS CommonColor
CommonCore
FiltersCore
FiltersModeling
FiltersSources
IOLegacy
IOXML
IOXMLParser
ImagingCore
InteractionStyle
InteractionWidgets
RenderingAnnotation
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
RenderingVolumeOpenGL2)
endif()
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m)
@@ -119,7 +186,7 @@ configure_file("${PROJECT_SOURCE_DIR}/CMakeConfig.in.h"
"${PROJECT_BINARY_DIR}/config.h")
install(FILES "${PROJECT_BINARY_DIR}/config.h"
DESTINATION ${PACKAGE_INSTALL_INC_DIR})
DESTINATION ${INSTALL_INC_DIR})
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
@@ -146,6 +213,8 @@ add_subdirectory(${SRC_DIR}/Root)
include_directories(${SRC_DIR}/Vtk)
add_subdirectory(${SRC_DIR}/Vtk)
add_subdirectory(${SRC_DIR}/Python)
#add_subdirectory("${SRC_DIR}/utils/make_recipe")
## Documentation and packages
@@ -164,8 +233,8 @@ add_subdirectory(${SRC_DIR}/Vtk)
# Create the FooBarConfig.cmake and FooBarConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
"${PACKAGE_INSTALL_INC_DIR}")
# file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
# "${INSTALL_INC_DIR}")
# ... for the build tree
#set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
@@ -174,21 +243,53 @@ file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
# ... for the install tree
set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(uLibConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
@ONLY)
# [ removed for the configure_config_file ]
# configure_file(uLibConfig.cmake.in
# "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
# @ONLY)
# ... for both
configure_file(uLibConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
install(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"
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}"
DESTINATION "${INSTALL_CMAKE_DIR}"
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(EXPORT "${PROJECT_NAME}Targets"
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}"
install(EXPORT "uLibTargets"
FILE "uLibTargets.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
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
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'

47
build_python.py Normal file
View File

@@ -0,0 +1,47 @@
import os
import subprocess
import sys
import shutil
def build(setup_kwargs):
"""
Build the C++ extension using CMake.
This function is called by poetry-core during the build process.
The binary is placed directly inside the uLib directory in src/Python.
"""
# Root of the whole project where this build_extension.py is located
project_root = os.path.abspath(os.path.dirname(__file__))
# Where the extension should go
package_dir = os.path.join(project_root, "src/Python/uLib")
# Ensure package directory exists
os.makedirs(package_dir, exist_ok=True)
# Temporary build directory
build_temp = os.path.join(project_root, "build_python")
os.makedirs(build_temp, exist_ok=True)
print(f"--- Running CMake build in {build_temp} ---")
print(f"Project root: {project_root}")
print(f"Target binary dir: {package_dir}")
# CMake configuration
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={package_dir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
"-DCMAKE_BUILD_TYPE=Release",
"-DUSE_CUDA=OFF",
"-G", "Unix Makefiles",
]
# Use micromamba to ensure Boost and VTK are found during the build
subprocess.check_call(["cmake", project_root] + cmake_args, cwd=build_temp)
subprocess.check_call(["cmake", "--build", ".", "--parallel", "--target", "uLib_python"], cwd=build_temp)
# Ensure the package is found by poetry during the wheel creation process.
# Return setup_kwargs for poetry-core.
return setup_kwargs
if __name__ == "__main__":
build({})

8
conanfile.txt Normal file
View File

@@ -0,0 +1,8 @@
[requires]
eigen/3.4.0
boost/1.83.0
pybind11/3.0.2
[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.

7
poetry.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Poetry 2.3.1 and should not be changed by hand.
package = []
[metadata]
lock-version = "2.1"
python-versions = ">=3.9"
content-hash = "db9b4c08b159b17b239e26c67ead7c37b82d9f9eb06550245ae3134c095f98f7"

15
pyproject.toml Normal file
View File

@@ -0,0 +1,15 @@
[tool.poetry]
name = "uLib"
version = "0.6.0"
description = "CMT Cosmic Muon Tomography project uLib python bindings"
authors = ["Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>"]
readme = "README.md"
packages = [{ include = "uLib", from = "src/Python" }]
build = "build_python.py"
[tool.poetry.dependencies]
python = ">=3.9"
[build-system]
requires = ["poetry-core>=2.0.0", "pybind11>=2.6.0", "cmake>=3.12"]
build-backend = "poetry.core.masonry.api"

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARCHIVES_H
#define U_CORE_ARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <iostream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
@@ -40,25 +38,20 @@
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include "StringReader.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES //
namespace uLib {
namespace Archive {
@@ -68,40 +61,36 @@ class text_iarchive;
class text_oarchive;
class log_archive;
}
}
} // namespace Archive
} // namespace uLib
namespace boost {
namespace archive {
namespace detail {
template <class ArchiveImplementation> class polymorphic_oarchive_route;
template <class ArchiveImplementation> class polymorphic_iarchive_route;
}
}
}
} // namespace detail
} // namespace archive
} // namespace boost
namespace boost {
namespace serialization {
template <typename T> struct hrp;
}
}
} // namespace boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION //
namespace uLib {
namespace Archive {
namespace detail {
struct adl_tag {};
}
}
}
} // namespace detail
} // namespace Archive
} // namespace uLib
namespace boost {
namespace archive {
@@ -110,10 +99,11 @@ namespace detail {
// in overload resolution with the functions declared by
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
template <class Serializable>
void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {}
}
}
}
void instantiate_ptr_serialization(Serializable *, int,
uLib::Archive::detail::adl_tag) {}
} // namespace detail
} // namespace archive
} // namespace boost
// The function declaration generated by this macro never actually
// gets called, but its return type gets instantiated, and that's
@@ -121,23 +111,24 @@ void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::ad
// Archive and any exported Serializable type. See also:
// boost/serialization/export.hpp
#define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
namespace boost { namespace archive { namespace detail { \
namespace boost { \
namespace archive { \
namespace detail { \
\
template <class Serializable> \
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}}
BOOST_DEDUCED_TYPENAME \
_ptr_serialization_support<_Archive, Serializable>::type \
instantiate_ptr_serialization(Serializable *, _Archive *, \
uLib::Archive::detail::adl_tag); \
} \
} \
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES //
namespace boost {
namespace archive {
namespace detail {
@@ -145,11 +136,10 @@ namespace detail {
/**
* Custom implementation of boost interface_iarchive to add new operators
*/
template<class Archive>
class uLib_interface_iarchive
{
template <class Archive> class uLib_interface_iarchive {
protected:
uLib_interface_iarchive() {};
public:
/////////////////////////////////////////////////////////
// archive public interface
@@ -157,54 +147,40 @@ public:
typedef mpl::bool_<false> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
Archive *This() { return static_cast<Archive *>(this); }
template <class T>
const basic_pointer_iserializer *
register_type(T * = NULL){
const basic_pointer_iserializer & bpis =
boost::serialization::singleton<
pointer_iserializer<Archive, T>
>::get_const_instance();
const basic_pointer_iserializer *register_type(T * = NULL) {
const basic_pointer_iserializer &bpis = boost::serialization::singleton<
pointer_iserializer<Archive, T>>::get_const_instance();
this->This()->register_basic_serializer(bpis.get_basic_serializer());
return &bpis;
}
template<class T>
Archive & operator>>(T & t){
this->This()->load_override(t, 0);
template <class T> Archive &operator>>(T &t) {
this->This()->load_override(t);
return *this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
return *(this->This()) >> t;
}
template <class T> Archive &operator&(T &t) { return *(this->This()) >> t; }
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
template <class T> Archive &operator==(T &t) { return this->operator&(t); }
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
template <class T> Archive &operator!=(T &t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return *this->This();
}
};
/**
* Custom implementation of boost interface_oarchive to add new operators
*/
template <class Archive>
class uLib_interface_oarchive {
template <class Archive> class uLib_interface_oarchive {
protected:
uLib_interface_oarchive() {};
public:
/////////////////////////////////////////////////////////
// archive public interface
@@ -212,32 +188,25 @@ public:
typedef mpl::bool_<true> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
Archive *This() { return static_cast<Archive *>(this); }
template <class T>
const basic_pointer_oserializer *
register_type(const T * = NULL){
const basic_pointer_oserializer & bpos =
boost::serialization::singleton<
pointer_oserializer<Archive, T>
>::get_const_instance();
const basic_pointer_oserializer *register_type(const T * = NULL) {
const basic_pointer_oserializer &bpos = boost::serialization::singleton<
pointer_oserializer<Archive, T>>::get_const_instance();
this->This()->register_basic_serializer(bpos.get_basic_serializer());
return &bpos;
}
template<class T>
Archive & operator<<(T & t){
template <class T> Archive &operator<<(T &t) {
// to get access you must redefine save_override by typing
// "using save_override" in archive impl
this->This()->save_override(t, 0);
this->This()->save_override(t);
return *this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
template <class T> Archive &operator&(T &t) {
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
return *this->This() << const_cast<const T &>(t);
#else
@@ -246,45 +215,38 @@ public:
}
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
template <class T> Archive &operator==(T &t) { return this->operator&(t); }
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
template <class T> Archive &operator!=(T &t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return *this->This();
}
};
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own
// extended interface //
template <>
class interface_iarchive <uLib::Archive::xml_iarchive> : public
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {};
class interface_iarchive<uLib::Archive::xml_iarchive>
: public uLib_interface_iarchive<uLib::Archive::xml_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::xml_oarchive> : public
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {};
class interface_oarchive<uLib::Archive::xml_oarchive>
: public uLib_interface_oarchive<uLib::Archive::xml_oarchive> {};
template <>
class interface_iarchive <uLib::Archive::text_iarchive> : public
uLib_interface_iarchive <uLib::Archive::text_iarchive> {};
class interface_iarchive<uLib::Archive::text_iarchive>
: public uLib_interface_iarchive<uLib::Archive::text_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::text_oarchive> : public
uLib_interface_oarchive <uLib::Archive::text_oarchive> {};
class interface_oarchive<uLib::Archive::text_oarchive>
: public uLib_interface_oarchive<uLib::Archive::text_oarchive> {};
template <>
class interface_oarchive <uLib::Archive::log_archive> : public
uLib_interface_oarchive <uLib::Archive::log_archive> {};
class interface_oarchive<uLib::Archive::log_archive>
: public uLib_interface_oarchive<uLib::Archive::log_archive> {};
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
// #define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
@@ -299,22 +261,9 @@ class interface_oarchive <uLib::Archive::log_archive> : public
// #undef _INERIT_NOFOLD_H
// #undef _INERIT_NOFOLD_V
} // detail
} // archive
} // boost
} // namespace detail
} // namespace archive
} // namespace boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -332,8 +281,8 @@ namespace archive {
// template<class Archive>
// inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
// typex::invoke(ar, t);
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive>
// >::type typex; typex::invoke(ar, t);
// }
// template<class Archive, class T>
@@ -360,45 +309,36 @@ namespace archive {
// typex::invoke(ar, t);
// }
}
}
} // namespace archive
} // namespace boost
namespace uLib {
namespace Archive {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// POLYMORPHIC //
// class polymorphic_iarchive :
// public boost::archive::polymorphic_iarchive {
// public:
// void load_override(const char *t, BOOST_PFTO int)
// {
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t));
// boost::archive::load_const_override(* this->This(),
// const_cast<char*>(t));
// }
//};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML //
class xml_iarchive :
public boost::archive::xml_iarchive_impl<xml_iarchive>
{
class xml_iarchive : public boost::archive::xml_iarchive_impl<xml_iarchive> {
typedef xml_iarchive Archive;
typedef boost::archive::xml_iarchive_impl<Archive> base;
@@ -406,36 +346,34 @@ class xml_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_xml_iarchive<Archive>;
friend class boost::archive::load_access;
public:
xml_iarchive(std::istream & is, unsigned int flags = 0) :
xml_iarchive_impl<xml_iarchive>(is, flags)
{}
xml_iarchive(std::istream &is, unsigned int flags = 0)
: xml_iarchive_impl<xml_iarchive>(is, flags) {}
using basic_xml_iarchive::load_override;
// Anything not an attribute should be a name value pair as nvp or hrp
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive;
typedef boost::archive::detail::common_iarchive<Archive>
detail_common_iarchive;
template <class T>
void load_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
boost::serialization::hrp< T > & t,
int v
){
boost::serialization::hrp<T> &t) {
this->This()->load_start(t.name());
this->detail_common_iarchive::load_override(t.value(), 0);
this->detail_common_iarchive::load_override(t.value());
// t.stov();
this->This()->load_end(t.name());
}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
void load_override(const char *str) {
// StringReader sr(basic_text_iprimitive::is);
// sr >> str;
}
@@ -448,33 +386,23 @@ public:
//> polymorphic_xml_iarchive;
template <class ArchiveImpl>
struct polymorphic_iarchive_route :
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl>
{
virtual void load(const char * t){
ArchiveImpl::load(t);
}
struct polymorphic_iarchive_route
: boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl> {
virtual void load(const char *t) { ArchiveImpl::load(t); }
};
class polymorphic_xml_iarchive :
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> >
{
class polymorphic_xml_iarchive
: public polymorphic_iarchive_route<
boost::archive::xml_iarchive_impl<xml_iarchive>> {
// give serialization implementation access to this class
// friend class boost::archive::detail::interface_iarchive<Archive>;
// friend class boost::archive::basic_xml_iarchive<Archive>;
// friend class boost::archive::load_access;
public:
virtual void load_override(const char *str, int v) {
;
}
virtual void load_override(const char *str) { ; }
};
class xml_oarchive :
public boost::archive::xml_oarchive_impl<xml_oarchive>
{
class xml_oarchive : public boost::archive::xml_oarchive_impl<xml_oarchive> {
typedef xml_oarchive Archive;
typedef boost::archive::xml_oarchive_impl<Archive> base;
@@ -482,10 +410,10 @@ class xml_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_xml_oarchive<Archive>;
friend class boost::archive::save_access;
public:
xml_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags)
{}
xml_oarchive(std::ostream &os, unsigned int flags = 0)
: boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags) {}
// example of implementing save_override for const char* //
// void save_override(const char *t, int) {
@@ -495,22 +423,21 @@ public:
using basic_xml_oarchive::save_override;
// special treatment for name-value pairs.
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive;
typedef boost::archive::detail::common_oarchive<Archive>
detail_common_oarchive;
template <class T>
void save_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
::boost::serialization::hrp< T > & t,
int v
){
::boost::serialization::hrp<T> &t) {
this->This()->save_start(t.name());
// t.vtos();
// this->detail_common_oarchive::save_override(t.const_value(), 0);
// this->detail_common_oarchive::save_override(t.const_value());
this->This()->save_end(t.name());
}
void save_override(const char *str, int v) {
void save_override(const char *str) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
@@ -527,9 +454,7 @@ public:
////////////////////////////////////////////////////////////////////////////////
// TEXT //
class text_iarchive :
public boost::archive::text_iarchive_impl<text_iarchive>
{
class text_iarchive : public boost::archive::text_iarchive_impl<text_iarchive> {
typedef text_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
@@ -537,21 +462,21 @@ class text_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
text_iarchive(std::istream & is, unsigned int flags = 0) :
text_iarchive_impl<Archive>(is, flags)
{}
text_iarchive(std::istream &is, unsigned int flags = 0)
: text_iarchive_impl<Archive>(is, flags) {}
using basic_text_iarchive::load_override;
void load_override(boost::archive::object_id_type & t, int) {}
void load_override(boost::archive::object_id_type &t) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
void load_override(const char *str) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
@@ -565,11 +490,7 @@ typedef text_iarchive naked_text_iarchive;
// naked_text_iarchive
//> polymorphic_text_iarchive;
class text_oarchive :
public boost::archive::text_oarchive_impl<text_oarchive>
{
class text_oarchive : public boost::archive::text_oarchive_impl<text_oarchive> {
typedef text_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
@@ -577,16 +498,14 @@ class text_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
text_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::text_oarchive_impl<Archive>(os, flags)
{}
text_oarchive(std::ostream &os, unsigned int flags = 0)
: boost::archive::text_oarchive_impl<Archive>(os, flags) {}
using basic_text_oarchive::save_override;
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
void save_override(const char *str) { basic_text_oprimitive::save(str); }
~text_oarchive() {}
};
@@ -595,15 +514,12 @@ public:
// boost::archive::text_oarchive_impl<text_oarchive>
//> polymorphic_text_oarchive;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SIMPLE HUMAN READABLE TEXT //
class hrt_iarchive :
public boost::archive::text_iarchive_impl<hrt_iarchive>
{
class hrt_iarchive : public boost::archive::text_iarchive_impl<hrt_iarchive> {
typedef hrt_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
@@ -611,29 +527,29 @@ class hrt_iarchive :
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
hrt_iarchive(std::istream & is, unsigned int flags = 0) :
base(is, flags | boost::archive::no_header )
{}
hrt_iarchive(std::istream &is, unsigned int flags = 0)
: base(is, flags | boost::archive::no_header) {}
using basic_text_iarchive::load_override;
// hide all archive props //
void load_override( boost::archive::object_id_type & t, int) {}
void load_override( boost::archive::object_reference_type & t, int) {}
void load_override( boost::archive::version_type & t, int) {}
void load_override( boost::archive::class_id_type & t, int) {}
void load_override( boost::archive::class_id_optional_type & t, int) {}
void load_override( boost::archive::class_id_reference_type & t, int){}
void load_override( boost::archive::class_name_type & t, int) {}
void load_override( boost::archive::tracking_type & t, int) {}
void load_override(boost::archive::object_id_type &t) {}
void load_override(boost::archive::object_reference_type &t) {}
void load_override(boost::archive::version_type &t) {}
void load_override(boost::archive::class_id_type &t) {}
void load_override(boost::archive::class_id_optional_type &t) {}
void load_override(boost::archive::class_id_reference_type &t) {}
void load_override(boost::archive::class_name_type &t) {}
void load_override(boost::archive::tracking_type &t) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
void load_override(const char *str) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
@@ -641,10 +557,7 @@ public:
~hrt_iarchive() {};
};
class hrt_oarchive :
public boost::archive::text_oarchive_impl<hrt_oarchive>
{
class hrt_oarchive : public boost::archive::text_oarchive_impl<hrt_oarchive> {
typedef hrt_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
@@ -652,33 +565,27 @@ class hrt_oarchive :
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
hrt_oarchive(std::ostream & os, unsigned int flags = 0) :
base(os, flags | boost::archive::no_header )
{}
hrt_oarchive(std::ostream &os, unsigned int flags = 0)
: base(os, flags | boost::archive::no_header) {}
using basic_text_oarchive::save_override;
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
void save_override(const boost::archive::object_id_type &t) {}
void save_override(const boost::archive::object_reference_type &t) {}
void save_override(const boost::archive::version_type &t) {}
void save_override(const boost::archive::class_id_type &t) {}
void save_override(const boost::archive::class_id_optional_type &t) {}
void save_override(const boost::archive::class_id_reference_type &t) {}
void save_override(const boost::archive::class_name_type &t) {}
void save_override(const boost::archive::tracking_type &t) {}
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
void save_override(const char *str) { basic_text_oprimitive::save(str); }
~hrt_oarchive() {}
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -690,8 +597,7 @@ class hrt_oarchive :
// any serializable class. Intended to be useful as a debugging aid.
class log_archive :
/* protected ? */
public boost::archive::xml_oarchive_impl<log_archive>
{
public boost::archive::xml_oarchive_impl<log_archive> {
typedef boost::archive::xml_oarchive_impl<log_archive> base;
typedef log_archive Archive;
// give serialization implementation access to this clas
@@ -700,66 +606,52 @@ class log_archive :
friend class boost::archive::save_access;
public:
void save_override(const char *str, int v) {
void save_override(const char *str) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
template<class T>
void save_override(T & t, BOOST_PFTO int){
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
template <class T> void save_override(T &t) {
base::save_override(boost::serialization::make_nvp(NULL, t));
}
// activate this if you want to trap non nvp objects //
// template<class T>
// void save_override(T & t, BOOST_PFTO int)
// void save_override(T & t)
// {
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // this->detail_common_oarchive::save_override(t, 0);
// // this->detail_common_oarchive::save_override(t);
// }
template<class T>
void save_override(const boost::serialization::nvp<T> & t, int){
base::save_override(t, 0);
template <class T> void save_override(const boost::serialization::nvp<T> &t) {
base::save_override(t);
}
// specific overrides for attributes - not name value pairs so we
// want to trap them before the above "fall through"
// since we don't want to see these in the output - make them no-ops.
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
void save_override(const boost::archive::object_id_type &t) {}
void save_override(const boost::archive::object_reference_type &t) {}
void save_override(const boost::archive::version_type &t) {}
void save_override(const boost::archive::class_id_type &t) {}
void save_override(const boost::archive::class_id_optional_type &t) {}
void save_override(const boost::archive::class_id_reference_type &t) {}
void save_override(const boost::archive::class_name_type &t) {}
void save_override(const boost::archive::tracking_type &t) {}
public:
log_archive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<log_archive>(
os,
flags | boost::archive::no_header
)
{}
log_archive(std::ostream &os, unsigned int flags = 0)
: boost::archive::xml_oarchive_impl<log_archive>(
os, flags | boost::archive::no_header) {}
};
// typedef boost::archive::detail::polymorphic_oarchive_route<
// boost::archive::xml_oarchive_impl<log_archive>
//> polymorphic_log_archive;
} // namespace Archive
} // Archive
} // uLib
} // namespace uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
@@ -775,7 +667,4 @@ ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
// ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive)
// ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive)
#endif // U_CORE_ARCHIVES_H

View File

@@ -1,10 +1,38 @@
set(HEADERS Options.h
StaticInterface.h)
set(HEADERS
Archives.h
Array.h
Collection.h
DataAllocator.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
)
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 Boost::serialization)
set(libname ${PACKAGE_LIBPREFIX}Core)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -14,14 +42,20 @@ add_library(${libname} SHARED ${SOURCES})
set_target_properties(${libname} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION})
if(USE_CUDA)
set(LIBRARIES ${LIBRARIES} CUDA::cudart)
endif()
target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Core)
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core)
if(BUILD_TESTING)
include(uLibTargetMacros)
add_subdirectory(testing)
endif()

259
src/Core/DataAllocator.h Normal file
View File

@@ -0,0 +1,259 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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(size_t size = 0, bool owns_objects = true)
: m_Size(size), m_RamData(nullptr), m_VramData(nullptr),
m_Device(MemoryDevice::RAM), m_OwnsObjects(owns_objects) {
if (m_Size > 0) {
if (m_OwnsObjects)
m_RamData = new T[m_Size]();
else
m_RamData = static_cast<T *>(::operator new(m_Size * sizeof(T)));
}
}
DataAllocator(const DataAllocator<T> &other)
: m_Size(other.m_Size), m_RamData(nullptr), m_VramData(nullptr),
m_Device(other.m_Device), m_OwnsObjects(other.m_OwnsObjects) {
if (m_Size > 0) {
if (other.m_RamData) {
if (m_OwnsObjects)
m_RamData = new T[m_Size];
else
m_RamData = static_cast<T *>(::operator new(m_Size * sizeof(T)));
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) {
if (m_OwnsObjects)
delete[] m_RamData;
else
::operator delete(m_RamData);
}
#ifdef USE_CUDA
if (m_VramData) {
cudaFree(m_VramData);
}
#endif
}
DataAllocator &operator=(const DataAllocator &other) {
if (this != &other) {
m_OwnsObjects = other.m_OwnsObjects;
resize(other.m_Size);
m_Device = other.m_Device;
if (other.m_RamData) {
if (!m_RamData) {
if (m_OwnsObjects)
m_RamData = new T[m_Size];
else
m_RamData = static_cast<T *>(::operator new(m_Size * sizeof(T)));
}
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) {
if (m_OwnsObjects)
m_RamData = new T[m_Size]();
else
m_RamData = static_cast<T *>(::operator new(m_Size * sizeof(T)));
}
#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) {
if (m_OwnsObjects)
newRam = new T[size]();
else
newRam = static_cast<T *>(::operator new(size * sizeof(T)));
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) {
if (m_OwnsObjects)
delete[] m_RamData;
else
::operator 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;
bool m_OwnsObjects;
};
} // namespace uLib
#endif // U_MATH_DATAALLOCATOR_H

View File

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

View File

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

View File

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

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OBJECT_H
#define U_CORE_OBJECT_H
@@ -33,28 +31,25 @@
// WARNING: COPILE ERROR if this goes after mpl/vector //
// #include "Core/Vector.h"
#include "Core/Types.h"
#include "Core/Debug.h"
#include "Core/Types.h"
#include "Core/Function.h"
#include "Core/Signal.h"
#include "Core/Mpl.h"
#include "Core/Serializable.h"
#include "Core/ObjectProps.h"
#include "Core/Uuid.h"
namespace boost {
namespace archive {
class polymorphic_iarchive;
class polymorphic_oarchive;
} // archive
} // boost
} // namespace archive
} // namespace boost
namespace uLib {
class Version {
public:
static const char *PackageName;
@@ -62,23 +57,14 @@ public:
static const char *Release;
};
////////////////////////////////////////////////////////////////////////////////
//// OBJECT ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* @brief Object class is the object base implementation for uLib Framework.
*/
class Object : public ObjectPropable
{
class Object {
public:
// std::string name;
@@ -94,14 +80,13 @@ public:
// FIXX !!!
virtual void DeepCopy(const Object &copy);
////////////////////////////////////////////////////////////////////////////
// SERIALIZATION //
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
ObjectPropable::serialize(ar,version);
}
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
template <class ArchiveT>
void serialize(ArchiveT &ar, const unsigned int version) {}
template <class ArchiveT>
void save_override(ArchiveT &ar, const unsigned int version) {}
void SaveConfig(std::ostream &os, int version = 0);
void LoadConfig(std::istream &is, int version = 0);
@@ -109,13 +94,12 @@ public:
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) {
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);
@@ -123,51 +107,60 @@ public:
// 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)
{
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);
ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(sigb, slof,
receiver);
return true;
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal(sigb,slof,receiver);
ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(sigb, slof,
receiver);
return true;
}
template <typename FuncT>
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
inline
typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
addSignal(FuncT fun, const char *name) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
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 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;
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;
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);
@@ -176,25 +169,20 @@ public:
return (SigT *)sig;
}
inline SignalBase *
findSignal(const char *name) const
{
inline SignalBase *findSignal(const char *name) const {
return findSignalImpl(name);
}
inline GenericMFPtr *
findSlot(const char *name) const
{
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; }
inline const Object &operator=(const Object &copy) {
this->DeepCopy(copy);
return *this;
}
private:
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
@@ -208,9 +196,7 @@ private:
class ObjectPrivate *d;
};
} // uLib
} // namespace uLib
////////////////////////////////////////////////////////////////////////////////
@@ -218,5 +204,4 @@ private:
// std::ostream & operator << (std::ostream &os, uLib::Object *ob);
// std::istream & operator >> (std::istream &is, uLib::Object &ob);
#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/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
//class boost::program_options::error_with_option_name;
//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
{
return (m_vm.count(str));

View File

@@ -160,6 +160,8 @@ public:
void parse_config_file(const char *fname);
void save_config_file(const char *fname);
template <typename T>
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);

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_SERIALIZABLE_H
#define U_SERIALIZABLE_H
@@ -38,9 +36,6 @@ TODO:
*/
#include <boost/serialization/access.hpp>
#include <boost/serialization/export.hpp>
@@ -55,19 +50,15 @@ TODO:
// #include "boost/archive/polymorphic_iarchive.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/comma_if.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/tuple/to_seq.hpp>
#include "Core/Mpl.h"
#include "Core/ObjectProps.h"
#include "Core/Archives.h"
#include "Core/Export.h"
#include "Core/Mpl.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -80,25 +71,17 @@ namespace serialization {
// ACCESS 2 //
template <class T> struct access2 {};
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
template<class T>
class hrp :
public wrapper_traits<const hrp< T > >
{
template <class T> class hrp : public wrapper_traits<const hrp<T>> {
const char *m_name;
T *m_value;
std::string *m_str;
public:
explicit hrp(const char * name_, T &t) :
m_str(new std::string),
m_name(name_), m_value(&t) {}
const char * name() const {
return this->m_name;
}
explicit hrp(const char *name_, T &t)
: m_str(new std::string), m_name(name_), m_value(&t) {}
const char *name() const { return this->m_name; }
template <class Archivex>
void save(Archivex &ar, const unsigned int /* file_version */) const {
@@ -116,7 +99,6 @@ public:
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
template <class T>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
@@ -126,17 +108,10 @@ hrp< T > make_hrp(const char * name, T & t){
return hrp<T>(name, t);
}
#define HRP(name) \
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
} // serialization
} // boost
#define HRP(name) boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
} // namespace serialization
} // namespace boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -151,8 +126,6 @@ hrp< T > make_hrp(const char * name, T & t){
namespace uLib {
#define _AR_OP(r, data, elem) data &BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
#define NVP(data) BOOST_SERIALIZATION_NVP(data)
@@ -167,22 +140,25 @@ namespace uLib {
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
#define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
#define ULIB_SERIALIZE_OBJECT(_Ob, ...) \
_ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob, __VA_ARGS__)
#define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
#else
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
#define ULIB_SERIALIZABLE(_Ob) \
_ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
ULIB_CLASS_EXPORT_KEY(_Ob)
#define ULIB_SERIALIZE(_Ob, ...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
#define ULIB_SERIALIZE_DERIVED(_Ob, ...) \
_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob, __VA_ARGS__)
#define ULIB_SERIALIZABLE_OBJECT(_Ob) \
_ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob)
#define 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
#define ULIB_SERIALIZE_ACCESS \
friend class boost::serialization::access; \
template <class T> friend class boost::serialization::access2;
@@ -191,26 +167,25 @@ namespace uLib {
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>)
BOOST_CLASS_EXPORT_KEY(_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)
(uLib::Archive::text_iarchive)(uLib::Archive::text_oarchive)( \
uLib::Archive:: \
hrt_iarchive)(uLib::Archive:: \
hrt_oarchive)(uLib::Archive:: \
xml_iarchive)(uLib::Archive:: \
xml_oarchive)(uLib::Archive:: \
log_archive)
/** Solving virtual class check problem */
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; }
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data)
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base, _Derived) \
namespace boost { \
template <> \
struct is_virtual_base_of<_Base, _Derived> : public boost::mpl::true_ {}; \
}
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r, data, elem) \
_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem, data)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -225,33 +200,52 @@ namespace uLib {
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class, Archive) \
template void Class::serialize(Archive &ar, const unsigned int);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem);
#define _ULIB_DETAIL_INTRUSIVE_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);
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)); \
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__))) \
_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)
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,96 +255,134 @@ namespace uLib {
////////////////////////////////////////////////////////////////////////////////
// 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) \
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)
template void boost::serialization::serialize(Archive &ar, Class &ob, \
const unsigned int i);
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r, data, elem) \
_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data, elem)
// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
// different implementation
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
namespace boost { namespace serialization { \
template <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); }; }}
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(_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) { \
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); } }}\
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)
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) { \
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); } }}\
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)
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); }}
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__))); \
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*/ \
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); } }}\
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)
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 {
struct Serializable {
@@ -360,53 +392,34 @@ struct Serializable {
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
* cases a has_serialize trait should be implemented
*/
template <class T>
struct serializable_trait : mpl::bool_<false> {};
template <class T> struct serializable_trait : mpl::bool_<false> {};
/**
* IsA Serializable Implementation Template
*/
template <class T>
struct IsA : serializable_trait<T> {};
template <class T> struct IsA : serializable_trait<T> {};
template <class ThisClass, class Archive>
struct serialize_baseobject {
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));
typeid(T).name(), boost::serialization::base_object<T>(m_object));
}
};
};
} // detail
} // namespace detail
struct Serializable {
friend class boost::serialization::access;
template <class T> friend class boost::serialization::access2;
virtual ~Serializable() {}
protected:
};
} // uLib
} // namespace uLib
#endif // U_SERIALIZABLE_H

View File

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

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_TYPES_H
#define U_CORE_TYPES_H
@@ -38,15 +36,8 @@
#include "Core/Macros.h"
#include "Core/Mpl.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
namespace detail {
@@ -72,23 +63,19 @@ struct TypeIntrospection {
*/
/** IsA Introspectable Object Implementation Template */
template <class T>
struct IsIntrospectable : has_type_info<T> {};
template <class T> struct IsIntrospectable : has_type_info<T> {};
template <typename T> struct access {
typedef typename T::type_info type_info;
};
template <typename T>
struct child_first_impl {
template <typename T> struct child_first_impl {
template <class T1, bool cond>
struct lambda_CFList_f {
template <class T1, bool cond> struct lambda_CFList_f {
typedef mpl::vector<T1> type;
};
template <class T1>
struct lambda_CFList_f<T1,true> {
template <class T1> struct lambda_CFList_f<T1, true> {
// typedef typename T1::type_info::CFList type;
typedef typename access<T1>::type_info::CFList type;
};
@@ -97,39 +84,28 @@ struct TypeIntrospection {
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;
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;
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;
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 {};
struct child_first
: mpl::if_<has_type_info<T>, child_first_impl<T>, mpl::vector<>>::type {};
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -137,30 +113,19 @@ struct TypeIntrospection {
// #define _REPETITION_V(vz,vn,vdata)
// template < class TypeList >
// class TypeAdapterInputInterface {
// virtual ~TypeAdapterInputInterface() {}
// public:
// virtual void operator()(int val) {}
// virtual void operator()(std::string val) {}
//};
} // detail ////////////////////////////////////////////////////////////////////
} // namespace detail
#define CONSTEXPR BOOST_CONSTEXPR
// typedef ltk::Real_t Real_t;
#ifndef LTK_DOUBLE_PRECISION
typedef float Real_t;
@@ -174,8 +139,6 @@ typedef id_t Id_t;
typedef void *Pointer_t;
typedef bool Bool_t; // Boolean (0=false, 1=true) (bool)
//--- bit manipulation ---------------------------------------------------------
#ifndef BIT
#define BIT(n) (1ULL << (n))
@@ -193,14 +156,11 @@ typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
#define TESTBIT(n, i) ((Bool_t)(((n) & BIT(i)) != 0))
#endif
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE INTROSPECTION FOR OBJECTS //
#define uLibTypeMacro(thisClass, ...) \
\
/* Friendship detail for accessing introspection */ \
@@ -215,71 +175,38 @@ typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
typedef thisClass ThisClass; \
typedef uLib::mpl::vector<__VA_ARGS__, thisClass> TypeList; \
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type \
CFList; \
}; \
\
public: \
typedef type_info::BaseClass BaseClass; \
virtual const char *type_name() const { return type_info::name; } \
/* Object Props fwd declaration*/ \
struct ObjectProps; \
/**/
/**
* TypeList inheritance introspection
*/
struct TypeIntrospection {
template <typename T>
struct child_first : detail::TypeIntrospection::child_first<T> {};
};
// SISTEMARE //
struct PrintTypeId {
template <class T>
void operator()(T) const
{ std::cout << typeid(T).name() << std::endl; }
template <class T> void operator()(T) const {
std::cout << typeid(T).name() << std::endl;
}
template <typename SeqT>
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
template <typename SeqT> static void PrintMplSeq(SeqT *p = NULL) {
boost::mpl::for_each<SeqT>(PrintTypeId());
}
template <typename Class>
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
template <typename Class> static void PrintType(Class *p = NULL) {
std::cout << typeid(Class).name() << std::endl;
}
};
} // uLib
} // namespace uLib
#endif // U_CORE_TYPES_H

View File

@@ -23,59 +23,42 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_UUID_H
#define U_CORE_UUID_H
#include <iostream>
#include <vector>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "Core/Mpl.h"
#include "Core/Object.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Object Registration //
typedef boost::uuids::uuid uuid_t;
extern uuid_t uLib_dns_uuid;
template < typename T >
class type_id : public boost::uuids::uuid {
template <typename T> class type_id : public boost::uuids::uuid {
public:
type_id() :
m_size(sizeof(T)),
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name()))
{
std::cout << "Request for register new type\n" <<
"name: " << typeid(T).name() << "\n" <<
"uuid: " << to_string(*this) << "\n";
type_id()
: m_size(sizeof(T)),
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name())) {
std::cout << "Request for register new type\n"
<< "name: " << typeid(T).name() << "\n"
<< "uuid: " << to_string(*this) << "\n";
}
explicit type_id(boost::uuids::uuid const& u)
: boost::uuids::uuid(u) {}
operator boost::uuids::uuid() {
return static_cast<boost::uuids::uuid&>(*this);
}
operator boost::uuids::uuid() const {
return static_cast<boost::uuids::uuid const&>(*this);
}
explicit type_id(boost::uuids::uuid const &u) : boost::uuids::uuid(u) {}
unsigned int size() const { return m_size; }
@@ -83,9 +66,6 @@ private:
unsigned int m_size;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -95,21 +75,20 @@ namespace detail {
class TypeRegister {
typedef boost::uuids::name_generator IDGen_t;
public:
struct RegisterEntry {
uuid_t id;
int size;
};
TypeRegister(uuid_t const &dns) :
gen(dns) {}
TypeRegister(uuid_t const &dns) : gen(dns) {}
template< typename T >
RegisterEntry * AddType(T *t = NULL) {
template <typename T> RegisterEntry *AddType(T *t = NULL) {
RegisterEntry en = {gen(typeid(T).name()), sizeof(T)};
for (int i = 0; i < m_registry.size(); ++i)
if(en.id == m_registry[i].id) return &(m_registry[i]);
if (en.id == m_registry[i].id)
return &(m_registry[i]);
m_registry.push_back(en);
return &m_registry.back();
}
@@ -117,24 +96,17 @@ public:
void PrintSelf(std::ostream &o) {
std::cout << "RegisterController: \n";
for (int i = 0; i < m_registry.size(); ++i)
o << "type [" << i << "]: "
<< to_string(m_registry[i].id) << " "
o << "type [" << i << "]: " << to_string(m_registry[i].id) << " "
<< m_registry[i].size << "\n";
o << "\n";
}
private:
IDGen_t gen;
std::vector<RegisterEntry> m_registry;
};
} // detail
} // namespace detail
class TypeRegister : public detail::TypeRegister {
public:
@@ -148,16 +120,11 @@ private:
static TypeRegister *s_Instance; // Singleton instance
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT REGISTER //
} // uLib
} // namespace uLib
#endif // UUID_H

View File

@@ -23,59 +23,315 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_VECTOR_H
#define U_CORE_VECTOR_H
#include <vector>
#include <iostream>
#include <map>
#include <mutex>
#include <vector>
#include <Core/DataAllocator.h>
#include <Core/StaticInterface.h>
#include <Core/SmartPointer.h>
#include <Core/CommaInitializer.h>
#include <Core/SmartPointer.h>
#include <Core/StaticInterface.h>
namespace uLib {
// MetaAllocator Implementation ...
template <typename T> class MetaAllocator {
public:
using value_type = T;
using pointer = T *;
using const_pointer = const T *;
using reference = T &;
using const_reference = const T &;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
template <class U> struct rebind {
using other = MetaAllocator<U>;
};
MetaAllocator() noexcept = default;
template <class U>
constexpr MetaAllocator(const MetaAllocator<U> &) noexcept {}
T *allocate(std::size_t n) {
if (n == 0)
return nullptr;
DataAllocator<T> *da = new DataAllocator<T>(n, false);
T *ptr = da->GetRAMData();
std::lock_guard<std::mutex> lock(GetMutex());
GetAllocationMap()[ptr] = da;
return ptr;
}
void deallocate(T *p, std::size_t /*n*/) noexcept {
if (!p)
return;
std::lock_guard<std::mutex> lock(GetMutex());
auto &map = GetAllocationMap();
auto it = map.find(p);
if (it != map.end()) {
delete it->second;
map.erase(it);
}
}
static DataAllocator<T> *GetDataAllocator(T *p) {
if (!p)
return nullptr;
std::lock_guard<std::mutex> lock(GetMutex());
auto &map = GetAllocationMap();
auto it = map.find(p);
if (it != map.end()) {
return it->second;
}
return nullptr;
}
private:
static std::map<T *, DataAllocator<T> *> &GetAllocationMap() {
static std::map<T *, DataAllocator<T> *> allocMap;
return allocMap;
}
static std::mutex &GetMutex() {
static std::mutex mtx;
return mtx;
}
};
template <class T, class U>
bool operator==(const MetaAllocator<T> &, const MetaAllocator<U> &) {
return true;
}
template <class T, class U>
bool operator!=(const MetaAllocator<T> &, const MetaAllocator<U> &) {
return false;
}
// Vector Implemetation ... wraps std::vector
template <typename T>
class Vector : public std::vector<T, std::allocator<T> >
{
typedef std::vector< T,std::allocator<T> > BaseClass;
typedef std::allocator<T> Allocator;
template <typename T> class Vector : public std::vector<T, MetaAllocator<T>> {
typedef std::vector<T, MetaAllocator<T>> BaseClass;
typedef MetaAllocator<T> Allocator;
public:
typedef T TypeData;
typedef __gnu_cxx::__normal_iterator<T *, BaseClass> Iterator;
typedef __gnu_cxx::__normal_iterator<const T *, BaseClass> ConstIterator;
typedef CommaInitializer<Vector<T>, T> VectorCommaInit;
typedef typename BaseClass::iterator iterator;
typedef typename BaseClass::const_iterator const_iterator;
typedef typename BaseClass::size_type size_type;
typedef typename BaseClass::reference reference;
Vector(unsigned int size) : BaseClass(size) {}
Vector(unsigned int size, T &value) : BaseClass(size, value) {}
Vector() : BaseClass(0) {}
Vector(std::initializer_list<T> init) : BaseClass(init) {}
inline VectorCommaInit operator<<(T scalar) {
return VectorCommaInit(this, scalar);
}
void MoveToVRAM() {
if (auto alloc = MetaAllocator<T>::GetDataAllocator(BaseClass::data())) {
alloc->MoveToVRAM();
}
}
void MoveToRAM() {
if (auto alloc = MetaAllocator<T>::GetDataAllocator(BaseClass::data())) {
alloc->MoveToRAM();
}
}
T *GetVRAMData() {
if (auto alloc = MetaAllocator<T>::GetDataAllocator(BaseClass::data())) {
return alloc->GetVRAMData();
}
return nullptr;
}
const T *GetVRAMData() const {
if (auto alloc = MetaAllocator<T>::GetDataAllocator(
const_cast<T *>(BaseClass::data()))) {
return alloc->GetVRAMData();
}
return nullptr;
}
inline void PrintSelf(std::ostream &o);
// Overrides for auto-sync //
T &operator[](size_t i) {
this->MoveToRAM();
return BaseClass::operator[](i);
}
const T &operator[](size_t i) const {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::operator[](i);
}
T &at(size_t i) {
this->MoveToRAM();
return BaseClass::at(i);
}
const T &at(size_t i) const {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::at(i);
}
T &front() {
this->MoveToRAM();
return BaseClass::front();
}
const T &front() const {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::front();
}
T &back() {
this->MoveToRAM();
return BaseClass::back();
}
const T &back() const {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::back();
}
T *data() noexcept {
this->MoveToRAM();
return BaseClass::data();
}
const T *data() const noexcept {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::data();
}
Iterator begin() noexcept {
this->MoveToRAM();
return BaseClass::begin();
}
ConstIterator begin() const noexcept {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::begin();
}
Iterator end() noexcept {
this->MoveToRAM();
return BaseClass::end();
}
ConstIterator end() const noexcept {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::end();
}
auto rbegin() noexcept {
this->MoveToRAM();
return BaseClass::rbegin();
}
auto rbegin() const noexcept {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::rbegin();
}
auto rend() noexcept {
this->MoveToRAM();
return BaseClass::rend();
}
auto rend() const noexcept {
const_cast<Vector *>(this)->MoveToRAM();
return BaseClass::rend();
}
void push_back(const T &x) {
this->MoveToRAM();
BaseClass::push_back(x);
}
void push_back(T &&x) {
this->MoveToRAM();
BaseClass::push_back(std::move(x));
}
template <typename... Args> reference emplace_back(Args &&...args) {
this->MoveToRAM();
return BaseClass::emplace_back(std::forward<Args>(args)...);
}
void pop_back() {
this->MoveToRAM();
BaseClass::pop_back();
}
template <typename... Args>
iterator emplace(const_iterator pos, Args &&...args) {
this->MoveToRAM();
return BaseClass::emplace(pos, std::forward<Args>(args)...);
}
iterator insert(const_iterator pos, const T &x) {
this->MoveToRAM();
return BaseClass::insert(pos, x);
}
iterator insert(const_iterator pos, T &&x) {
this->MoveToRAM();
return BaseClass::insert(pos, std::move(x));
}
template <typename InputIt>
iterator insert(const_iterator pos, InputIt first, InputIt last) {
this->MoveToRAM();
return BaseClass::insert(pos, first, last);
}
iterator erase(const_iterator pos) {
this->MoveToRAM();
return BaseClass::erase(pos);
}
iterator erase(const_iterator first, const_iterator last) {
this->MoveToRAM();
return BaseClass::erase(first, last);
}
void resize(size_t n) {
this->MoveToRAM();
BaseClass::resize(n);
}
void resize(size_t n, const T &x) {
this->MoveToRAM();
BaseClass::resize(n, x);
}
void reserve(size_t n) {
this->MoveToRAM();
BaseClass::reserve(n);
}
void clear() noexcept {
this->MoveToRAM();
BaseClass::clear();
}
template <typename InputIt> void assign(InputIt first, InputIt last) {
this->MoveToRAM();
BaseClass::assign(first, last);
}
void assign(size_type count, const T &value) {
this->MoveToRAM();
BaseClass::assign(count, value);
}
void remove_element(unsigned int index) {
this->MoveToRAM();
std::swap(this->at(index), this->back());
this->pop_back();
}
void remove_element(T &t) {
this->MoveToRAM();
std::swap(t, this->back());
this->pop_back();
}
};
template<typename T>
void Vector<T>::PrintSelf(std::ostream &o)
{
template <typename T> void Vector<T>::PrintSelf(std::ostream &o) {
o << " *** uLib Vector *** \n";
o << " n. of items = " << this->size() << "\n";
for (int i = 0; i < this->size(); ++i)
@@ -98,36 +354,30 @@ std::ofstream & operator << (std::ofstream &o, const Vector<T> &v) {
return o;
}
template < typename T >
std::istream & operator >> (std::istream &is, Vector<T> &v) {
template <typename T> std::istream &operator>>(std::istream &is, Vector<T> &v) {
T value;
while (is >> value) {
if(is.fail()) v.push_back(0);
else v.push_back( value );
if (is.fail())
v.push_back(0);
else
v.push_back(value);
}
return is;
}
// Smart pointer Vector Implementation //
template <typename T>
class SmartVector : public SmartPointer< Vector<T> > {
template <typename T> class SmartVector : public SmartPointer<Vector<T>> {
typedef SmartPointer<Vector<T>> Base;
public:
public:
SmartVector() : Base(new Vector<T>()) {}
SmartVector(const SmartVector &copy) : Base(copy) {}
SmartVector(unsigned int size) : Base(new Vector<T>((int)size)) {}
virtual ~SmartVector() {}
T& operator[](int p) {
return Base::get()->at(p);
}
T &operator[](int p) { return Base::get()->at(p); }
void swap_elements(unsigned int first, unsigned int second) {
std::swap(Base::get()->at(first), Base::get()->at(second));
@@ -144,35 +394,25 @@ public:
}
};
// ------ Utils ------------------------------------------------------------- //
// RIFARE con iteratore !
template <typename _Tp, class _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
inline unsigned long VectorSplice(const _Tp &_it, const _Tp &_end,
const float value, _CmpT _comp) {
_Tp it = _it;
_Tp end = _end - 1;
for(it; it != end;)
{
if (_comp(*it,value)) ++it;
else if(_comp(*end,value)) std::swap(*it,*end--);
else --end;
for (; it != end;) {
if (_comp(*it, value))
++it;
else if (_comp(*end, value))
std::swap(*it, *end--);
else
--end;
}
return it - _it;
}
} // uLib
} // namespace uLib
#endif // VECTOR_H

View File

@@ -8,7 +8,7 @@ set( TESTS
ObjectCopyTest
StaticInterfaceTest
CommaInitTest
DebugTTreeDumpTest
# DebugTTreeDumpTest
BoostTest
BoostAccumulatorTest
PropertiesTest
@@ -16,18 +16,18 @@ set( TESTS
SerializeTest
SerializeDreadDiamondTest
DreadDiamondParameters
ObjectPropableTest
UuidTest
TypeIntrospectionTraversal
OptionsTest
PingPongTest
VectorMetaAllocatorTest
)
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
Boost::serialization
Boost::program_options
${ROOT_LIBRARIES}
)
uLib_add_tests(${uLib-module})
uLib_add_tests(Core)

View File

@@ -19,7 +19,6 @@ TESTS = SmartPointerTest \
SerializeTest \
SerializeDreadDiamondTest \
DreadDiamondParameters \
ObjectPropableTest \
TypeIntrospectionTraversal \
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 <typeinfo>
#include <iostream>
#include <string>
#include <typeinfo>
#include "Core/Object.h"
@@ -37,37 +34,24 @@
using namespace uLib;
struct A : Object {
uLibTypeMacro(A,Object)
A() : numa(5552368) {}
uLibTypeMacro(A, Object) A() : numa(5552368) {}
int numa;
};
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) {
ar & AR(numa);
}
ULIB_SERIALIZE_OBJECT(A, Object) { ar &AR(numa); }
struct B : virtual Object {
uLibTypeMacro(B,Object)
B() : numb(5552369) {}
uLibTypeMacro(B, Object) B() : numb(5552369) {}
int numb;
};
ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B, Object) { ar &AR(numb); }
struct C : B {
uLibTypeMacro(C,B)
C() : numc(5552370) {}
uLibTypeMacro(C, B) C() : numc(5552370) {}
int numc;
};
@@ -77,38 +61,16 @@ ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
struct D : A, B {
uLibTypeMacro(D, A, B)
D() : numd(5552371) {}
D()
: numd(5552371) {}
int numd;
};
ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D, A, B) { ar &AR(numd); }
main() {
A o; o.init_properties();
int main() {
A o;
Archive::xml_oarchive(std::cout) << NVP(o);
}

View File

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

View File

@@ -23,73 +23,45 @@
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h"
#include "Core/Signal.h"
#include "Core/Types.h"
#include "testing-prototype.h"
using namespace uLib;
class Ob1 : public Object {
public:
signals:
void V0();
int V1(int a);
void V1(int a);
};
// should be done by moc //
void Ob1::V0() {
ULIB_SIGNAL_EMIT(Ob1::V0);
}
int Ob1::V1(int a) {
ULIB_SIGNAL_EMIT(Ob1::V1,a);
}
void Ob1::V0() { ULIB_SIGNAL_EMIT(Ob1::V0); }
void Ob1::V1(int a) { ULIB_SIGNAL_EMIT(Ob1::V1, a); }
class Ob2 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob2 prints V0\n" << std::flush;
}
void PrintV0() { std::cout << "Ob2 prints V0\n" << std::flush; }
};
class Ob3 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob3 prints V0\n" << std::flush;
}
void PrintV0() { std::cout << "Ob3 prints V0\n" << std::flush; }
void PrintNumber(int n) {
std::cout << "Ob3 is printing number: " << n << "\n";
}
};
int main() {
BEGIN_TESTING(Signals);
@@ -111,5 +83,3 @@ int main() {
END_TESTING;
}

View File

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

View File

@@ -0,0 +1,71 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include <Core/Vector.h>
int main() {
BEGIN_TESTING(VectorMetaAllocator);
uLib::Vector<int> v;
std::cout << "Pushing elements...\n";
v << 1, 2, 3, 4, 5;
std::cout << "Initial RAM contents: ";
for (size_t i = 0; i < v.size(); ++i) {
std::cout << v[i] << " ";
if (v[i] != (int)(i + 1)) {
std::cout << "\nError: Value mismatch at index " << i << "\n";
exit(1);
}
}
std::cout << "\n";
#ifdef USE_CUDA
std::cout << "Moving to VRAM...\n";
v.MoveToVRAM();
int *vram_ptr = v.GetVRAMData();
if (vram_ptr) {
std::cout << "Successfully obtained VRAM pointer: " << vram_ptr << "\n";
} else {
std::cout << "Error: Failed to obtain VRAM pointer!\n";
exit(1);
}
std::cout << "Moving back to RAM...\n";
v.MoveToRAM();
std::cout << "RAM contents after VRAM trip: ";
for (size_t i = 0; i < v.size(); ++i) {
std::cout << v[i] << " ";
if (v[i] != (int)(i + 1)) {
std::cout << "\nError: Data corrupted after RAM->VRAM->RAM trip at index "
<< i << "\n";
exit(1);
}
}
std::cout << "\n";
#else
std::cout << "USE_CUDA not defined, skipping VRAM tests.\n";
#endif
std::cout << "Scaling vector...\n";
for (size_t i = 0; i < v.size(); ++i)
v[i] *= 10;
std::cout << "Final contents: ";
for (size_t i = 0; i < v.size(); ++i)
std::cout << v[i] << " ";
std::cout << "\n";
END_TESTING;
}

View File

@@ -23,53 +23,40 @@
//////////////////////////////////////////////////////////////////////////////*/
#include <Core/Vector.h>
#include "testing-prototype.h"
#include <Core/Vector.h>
#include <algorithm>
template < typename T >
struct __Cmp {
bool operator()(const T &data, const float value) {
return data <= value;
}
template <typename T> struct __Cmp {
bool operator()(const T &data, const float value) { return data <= value; }
};
template <typename _Tp, typename _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
inline const unsigned long VectorSplice(const _Tp &_it, const _Tp &_end,
const float value, _CmpT _comp) {
_Tp it = _it;
_Tp end = _end - 1;
for(it; it != end; )
{
if ( _comp(*it, value) ) it++;
else if( _comp(*end, value) )
{
for (it; it != end;) {
if (_comp(*it, value))
it++;
else if (_comp(*end, value)) {
std::swap(*it, *end--);
}
else --end;
} else
--end;
}
return it - _it;
}
int main()
{
int main() {
BEGIN_TESTING(Vector);
uLib::Vector<float> v;
v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3;
v << 5, 4, 3, 2, 6, 1, 2, 3, 65, 7, 32, 23, 4, 3, 45, 4, 34, 3, 4, 4, 3, 3, 4,
2, 2, 3;
int id = VectorSplice(v.begin(),v.end(),3,__Cmp<float>());
int id = ::VectorSplice(v.begin(), v.end(), 3, __Cmp<float>());
std::cout << "id: " << id << "\n";
std::cout << "vector: ";
@@ -78,7 +65,5 @@ int main()
std::cout << std::endl;
// std::sort(v.begin(),v.end(),LT<float>());
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)
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
set( TESTS
GDMLSolidTest
# GDMLSolidTest
HierarchicalEncodingTest
)
#set(LIBRARIES
# ${PACKAGE_LIBPREFIX}Core
# ${PACKAGE_LIBPREFIX}Math
# ${PACKAGE_LIBPREFIX}Detectors
# ${Boost_SERIALIZATION_LIBRARY}
# ${Boost_SIGNALS_LIBRARY}
# ${Boost_PROGRAM_OPTIONS_LIBRARY}
# ${Eigen_LIBRARY}
# ${Geant4_LIBRARIES}
# ${ROOT_LIBRARIES}
#)
uLib_add_tests(${uLib-module})
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
Boost::serialization
Boost::program_options
Eigen3::Eigen
${ROOT_LIBRARIES}
)
uLib_add_tests(Detectors)

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

View File

@@ -1,3 +1,4 @@
set(HEADERS ContainerBox.h
Dense.h
Geometry.h
@@ -31,8 +32,9 @@ set(SOURCES VoxRaytracer.cpp
Structured2DGrid.cpp
Structured4DGrid.cpp)
set(LIBRARIES ${Eigen_LIBRARY}
${ROOT_LIBRARIES})
set(LIBRARIES Eigen3::Eigen
${ROOT_LIBRARIES}
${VTK_LIBRARIES})
set(libname ${PACKAGE_LIBPREFIX}Math)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -41,13 +43,25 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Math PARENT_SCOPE)
add_library(${libname} SHARED ${SOURCES})
set_target_properties(${libname} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION})
SOVERSION ${PROJECT_SOVERSION}
CXX_STANDARD 17
CUDA_STANDARD 17)
target_link_libraries(${libname} ${LIBRARIES})
if(USE_CUDA)
set_source_files_properties(VoxRaytracer.cpp VoxImage.cpp PROPERTIES LANGUAGE CUDA)
endif()
install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
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()

View File

@@ -23,9 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2012 Andrea Rigoni Garola <andrea@pcimg05>
@@ -47,35 +44,37 @@
*
*/
#ifndef ULIB_DENSEMATRIX_H
#define ULIB_DENSEMATRIX_H
// #include <Eigen/src/Core/Matrix.h>
#include <stdlib.h>
#include <Eigen/Dense>
//// BOOST SERIALIZATION ///////////////////////////////////////////////////////
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/string.hpp>
namespace boost {
namespace serialization {
template<class Archive, class Scalar, int RowsAtCompileTime, int ColsAtCompileTime>
void serialize(Archive & ar, ::Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> & m, const unsigned int /*version*/) {
ar & boost::serialization::make_array(m.data(), RowsAtCompileTime * ColsAtCompileTime);
template <class Archive, class Scalar, int RowsAtCompileTime,
int 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
} // boost
} // namespace serialization
} // namespace boost
////////////////////////////////////////////////////////////////////////////////
@@ -89,21 +88,22 @@ std::istream & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) {
for (unsigned int i = 0; i < size; i++) {
is >> std::skipws;
is >> str;
if(is.fail()) vec(i) = 0;
else vec(i) = boost::lexical_cast<T>(str);
if (is.fail())
vec(i) = 0;
else
vec(i) = boost::lexical_cast<T>(str);
}
return is;
}
template <typename T, int size>
std::ostream & operator << (std::ostream &os, const Eigen::Matrix<T,size,1> &vec) {
std::ostream &operator<<(std::ostream &os,
const Eigen::Matrix<T, size, 1> &vec) {
os << vec.transpose();
return os;
}
} // Eigen
} // namespace Eigen
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
typedef id_t Id_t;
@@ -115,7 +115,20 @@ typedef unsigned long Scalarul;
typedef float Scalarf;
typedef double Scalard;
typedef Eigen::Matrix<int, 1, 1> Vector1i;
typedef Eigen::Vector2i Vector2i;
typedef Eigen::Vector3i Vector3i;
typedef Eigen::Vector4i Vector4i;
typedef Eigen::Matrix<float, 1, 1> Vector1f;
typedef Eigen::Vector2f Vector2f;
typedef Eigen::Vector3f Vector3f;
typedef Eigen::Vector4f Vector4f;
typedef Eigen::Matrix<double, 1, 1> Vector1d;
typedef Eigen::Vector2d Vector2d;
typedef Eigen::Vector3d Vector3d;
typedef Eigen::Vector4d Vector4d;
typedef Eigen::Matrix<int, 1, 1> Matrix1i;
typedef Eigen::Matrix2i Matrix2i;
@@ -127,17 +140,14 @@ typedef Eigen::Matrix2f Matrix2f;
typedef Eigen::Matrix3f Matrix3f;
typedef Eigen::Matrix4f Matrix4f;
typedef Eigen::Matrix<int,1,1> Vector1i;
typedef Eigen::Vector2i Vector2i;
typedef Eigen::Vector3i Vector3i;
typedef Eigen::Vector4i Vector4i;
typedef Eigen::Matrix<float,1,1> Vector1f;
typedef Eigen::Vector2f Vector2f;
typedef Eigen::Vector3f Vector3f;
typedef Eigen::Vector4f Vector4f;
typedef Eigen::Matrix<double, 1, 1> Matrix1d;
typedef Eigen::Matrix2d Matrix2d;
typedef Eigen::Matrix3d Matrix3d;
typedef Eigen::Matrix4d Matrix4d;
typedef Eigen::MatrixXi MatrixXi;
typedef Eigen::MatrixXf MatrixXf;
typedef Eigen::MatrixXd MatrixXd;
////////////////////////////////////////////////////////////////////////////////
@@ -150,15 +160,18 @@ typedef Eigen::Vector4f Vector4f;
*
* \param vec A double vector to be populated with the results
* \param str A string to be parsed as a series of doubles.
* \param delim Delimiters of the text (a typical default is " ," for comma and space-delimited text
* \param delim Delimiters of the text (a typical default is " ," for comma and
* space-delimited text
*
*/
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,
const char *delim = " ,;\t\n") {
std::vector<std::string> strvec;
boost::algorithm::trim_if(str, boost::algorithm::is_any_of(delim));
boost::algorithm::split(strvec,str,boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
boost::algorithm::split(strvec, str, boost::algorithm::is_any_of(delim),
boost::algorithm::token_compress_on);
for (unsigned int i = 0; i < size; i++) {
vec(i) = boost::lexical_cast<T>(strvec[i]);
@@ -172,9 +185,9 @@ std::string VectorxT_ToString(const Eigen::Matrix<T,size,1> &vec) {
return sst.str();
}
// template <typename T, int size>
//Eigen::Matrix<T,size,1> & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) {
// Eigen::Matrix<T,size,1> & operator >> (std::istream &is,
// Eigen::Matrix<T,size,1> &vec) {
// }
template <typename T, int size>
@@ -182,80 +195,69 @@ void operator>> (std::string& str, Eigen::Matrix<T,size,1> &vec){
VectorxT_StringTo(vec, str);
}
////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS VECTORS //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
template <bool p>
class _HPoint3f : public Eigen::Matrix< Scalarf,4,1 > {
template <bool p> class _HPoint3f : public Eigen::Matrix<Scalarf, 4, 1> {
public:
typedef Eigen::Matrix<Scalarf, 4, 1> BaseClass;
_HPoint3f<p>() : BaseClass(0,0,0,p) {}
_HPoint3f<p>(float x,float y,float z) : BaseClass(x,y,z,p) {}
_HPoint3f<p>(Vector3f &in) : BaseClass(in.homogeneous()) { this->operator()(3) = p; }
_HPoint3f() : BaseClass(0, 0, 0, p) {}
_HPoint3f(int rows, int cols) : BaseClass() {
this->operator()(3) = p;
}
_HPoint3f(float x, float y, float z) : BaseClass(x, y, z, p) {}
_HPoint3f(Vector3f &in) : BaseClass(in.homogeneous()) {
this->operator()(3) = p;
}
void operator delete(void *_p, size_t _s) {}
// This constructor allows to construct MyVectorType from Eigen expressions
template <typename OtherDerived>
inline _HPoint3f<p>(const Eigen::MatrixBase<OtherDerived>& other)
: BaseClass(other)
{ }
inline _HPoint3f(const Eigen::MatrixBase<OtherDerived> &other)
: BaseClass(other) {}
// This method allows to assign Eigen expressions to Vector3H
template <typename OtherDerived>
inline _HPoint3f<p> & operator= (const Eigen::MatrixBase <OtherDerived>& other)
{
inline _HPoint3f &operator=(const Eigen::MatrixBase<OtherDerived> &other) {
this->BaseClass::operator=(other);
return *this;
}
};
typedef _HPoint3f<false> HVector3f;
typedef _HPoint3f<true> HPoint3f;
////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS LINE //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
struct _HLine3f
{
struct _HLine3f {
HPoint3f origin;
HVector3f direction;
};
typedef struct _HLine3f HLine3f;
inline std::ostream&
operator<< (std::ostream& stream, const HLine3f &line) {
stream << "HLine3f(" << "pt[" << line.origin.transpose() <<"] , dr[" << line.direction.transpose() << "]) ";
inline std::ostream &operator<<(std::ostream &stream, const HLine3f &line) {
stream << "HLine3f(" << "pt[" << line.origin.transpose() << "] , dr["
<< line.direction.transpose() << "]) ";
return stream;
}
struct _HError3f
{
struct _HError3f {
HVector3f position_error;
HVector3f direction_error;
};
typedef struct _HError3f HError3f;
inline std::ostream&
operator<< (std::ostream& stream, const HError3f &err) {
stream << "HError3f(" << "ept[" << err.position_error.transpose() <<"] , edr[" << err.direction_error.transpose() << "]) ";
inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) {
stream << "HError3f(" << "ept[" << err.position_error.transpose()
<< "] , edr[" << err.direction_error.transpose() << "]) ";
return stream;
}
}
} // namespace uLib
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -269,13 +271,9 @@ ULIB_SERIALIZABLE(uLib::HPoint3f)
ULIB_SERIALIZABLE(uLib::HVector3f)
ULIB_SERIALIZABLE(uLib::HLine3f)
ULIB_SERIALIZABLE(uLib::HError3f)
#endif // ULIB_SERIALIZATION_ON
#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 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); }

View File

@@ -30,6 +30,13 @@
#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 {
@@ -83,7 +90,103 @@ void Abstract::VoxImage::ExportToVtk (const char *file, bool density_type)
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");
if (!vtk_file) return false;
@@ -115,14 +218,18 @@ int Abstract::VoxImage::ImportFromVtk(const char *file)
this->SetSpacing(Vector3f(sx,sy,sz));
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 j = 0; j < dy; ++j) {
for (int i = 0; i < dx; ++i) {
Vector3i idx(i, j, k);
float tmp_val;
fscanf(vtk_file, "%f", &tmp_val);
//this->SetValue(idx,fabs(tmp_val)*1E-6);
this->SetValue(idx,tmp_val*1E-6);
this->SetValue(idx,tmp_val / norm);
}
}
}

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MATH_VOXIMAGE_H
#define U_MATH_VOXIMAGE_H
@@ -36,6 +34,8 @@
#include <stdlib.h>
#include <vector>
#include <Core/DataAllocator.h>
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
@@ -56,16 +56,26 @@ public:
virtual void SetDims(const Vector3i &size) = 0;
void ExportToVtk(const char *file, bool density_type = 0);
void ExportToVtkXml(const char *file, bool density_type = 0);
int ImportFromVtk(const char *file);
protected:
// 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);
virtual ~VoxImage() {}
protected:
VoxImage(const Vector3i &size) : BaseClass(size) {}
};
}
} // namespace Abstract
////////////////////////////////////////////////////////////////////////////////
// VOXEL ////////////////////////////////////////////////////////////////////
@@ -77,20 +87,18 @@ struct Voxel {
uLibCheckMember(Self, Value, Scalarf);
}
};
}
} // namespace Interface
struct Voxel {
Scalarf Value;
Scalarf Value = 0.0f;
Scalari Count = 0;
};
////////////////////////////////////////////////////////////////////////////////
// VOX IMAGE /////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
template< typename T >
class VoxImage : public Abstract::VoxImage {
template <typename T> class VoxImage : public Abstract::VoxImage {
public:
typedef Abstract::VoxImage BaseClass;
@@ -98,14 +106,12 @@ public:
VoxImage(const Vector3i &size);
VoxImage(const VoxImage<T> &copy) :
BaseClass(copy)
{
VoxImage(const VoxImage<T> &copy) : BaseClass(copy) {
this->m_Data = copy.m_Data;
}
inline std::vector<T> & Data() { return this->m_Data; }
inline const std::vector<T>& ConstData() const { return 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)); }
@@ -116,9 +122,7 @@ public:
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 Scalarf GetValue(const int id) const { return this->At(id).Value; }
inline void SetValue(const Vector3i &id, Scalarf value) {
this->operator[](id).Value = value;
@@ -129,19 +133,26 @@ public:
inline void SetDims(const Vector3i &size) {
this->m_Data.resize(size.prod());
BaseClass::BaseClass::SetDims(size); // FIX horrible coding style !
StructuredGrid::SetDims(size);
}
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> 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> 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 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;
@@ -168,8 +179,7 @@ public:
}
// MATH VoxImage Operators //
template <typename S>
void operator +=(VoxImage<S> &sibling) {
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;
@@ -179,8 +189,7 @@ public:
}
}
template <typename S>
void operator -=(VoxImage<S> &sibling) {
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;
@@ -190,8 +199,7 @@ public:
}
}
template <typename S>
void operator *=(VoxImage<S> &sibling) {
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;
@@ -201,8 +209,7 @@ public:
}
}
template <typename S>
void operator /=(VoxImage<S> &sibling) {
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;
@@ -213,35 +220,32 @@ public:
}
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() :
m_Data(0),
BaseClass(Vector3i(0,0,0))
{ Interface::IsA <T,Interface::Voxel>(); /* structural check for 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>
VoxImage<T>::VoxImage(const Vector3i &size) :
m_Data(size.prod()),
BaseClass(size)
{ Interface::IsA <T,Interface::Voxel>(); /* structural check for T */ }
template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const Vector3i begin, const Vector3i end) const
{
VoxImage<T> VoxImage<T>::clipImage(const Vector3i begin,
const Vector3i end) const {
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>()) );
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 )
{
for (uint z = 0; z < dim(2); ++z) {
Vector3i id = Vector3i(x, y, z);
out[id] = this->At(begin + id);
}
@@ -249,16 +253,15 @@ VoxImage<T> VoxImage<T>::clipImage(const Vector3i begin, const Vector3i end) con
}
template <typename T>
VoxImage<T> VoxImage<T>::clipImage(const HPoint3f begin, const HPoint3f end) const
{
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
{
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) {
@@ -272,8 +275,8 @@ VoxImage<T> VoxImage<T>::clipImage(const float density) const
}
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 v2 = Vector3i(0, 0, 0);
for (uint i = 0; i < this->m_Data.size(); ++i) {
@@ -287,8 +290,8 @@ VoxImage<T> VoxImage<T>::clipImage(const float densityMin, const float densityMa
}
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);
out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition());
@@ -309,9 +312,10 @@ VoxImage<T> VoxImage<T>::maskImage(const HPoint3f begin, const HPoint3f end, flo
}
template <typename T>
VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue, float aboveValue) const
{
std::cout << "VoxImage: maskImage, fixing voxels under threshold " << threshold;
VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue,
float aboveValue) const {
std::cout << "VoxImage: maskImage, fixing voxels under threshold "
<< threshold;
if (belowValue)
std::cout << " at value " << belowValue;
else
@@ -322,7 +326,6 @@ VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue, floa
else
std::cout << "found";
VoxImage<T> out(*this);
out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition());
@@ -333,10 +336,11 @@ VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue, floa
// voxels under threshold
if (this->GetValue(i) <= threshold * 1.E-6) {
if (belowValue) {
// std::cout << "vox " << i << ", " << this->GetValue(i);
// std::cout << " ----> set to " << -1.*belowValue*1.E-6 << std::endl;
out.SetValue(i,-1.*belowValue*1.E-6);}
else
// std::cout << "vox " << i << ", " <<
// this->GetValue(i); std::cout << " ----> set to " <<
// -1.*belowValue*1.E-6 << std::endl;
out.SetValue(i, -1. * belowValue * 1.E-6);
} else
out.SetValue(i, -1. * this->GetValue(i));
}
// voxels over threshold
@@ -352,8 +356,8 @@ VoxImage<T> VoxImage<T>::maskImage(const float threshold, float belowValue, floa
}
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;
VoxImage<T> out(*this);
@@ -364,16 +368,15 @@ VoxImage<T> VoxImage<T>::fixVoxels(const float threshold, float tolerance) const
// 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;
// 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
{
template <typename T> VoxImage<T> VoxImage<T>::Abs() const {
std::cout << "VoxImage: set abs voxels value " << std::endl;
VoxImage<T> out(*this);
@@ -387,8 +390,9 @@ VoxImage<T> VoxImage<T>::Abs() const
}
template <typename T>
VoxImage<T> VoxImage<T>::fixVoxels( const float threshold, float tolerance, const HPoint3f begin, const HPoint3f end) const
{
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());
@@ -412,8 +416,8 @@ VoxImage<T> VoxImage<T>::fixVoxels( const float threshold, float tolerance, cons
}
template <typename T>
VoxImage<T> VoxImage<T>::fixVoxels(const HPoint3f begin, const HPoint3f end) const
{
VoxImage<T> VoxImage<T>::fixVoxels(const HPoint3f begin,
const HPoint3f end) const {
VoxImage<T> out(*this);
out.SetDims(this->GetDims());
out.SetPosition(this->GetPosition());
@@ -433,10 +437,11 @@ VoxImage<T> VoxImage<T>::fixVoxels(const HPoint3f begin, const HPoint3f end) con
return out;
}
template <typename T>
VoxImage<T> VoxImage<T>::fixVoxelsAroundPlane( const float threshold, float tolerance, const HPoint3f B, const HPoint3f E, bool aboveAir) const
{
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);
@@ -452,27 +457,30 @@ VoxImage<T> VoxImage<T>::fixVoxelsAroundPlane( const float threshold, float tole
// B, E voxel position
Vector3i iv(ix, iy, iz);
Vector3f v = Vector3f(iv.cast<float>().cwiseProduct(this->GetSpacing()));
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
// 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 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;
// std::cout << "voxel " << iv << ", line " << dist << ", tolerance "
// << tolerance << std::endl;
out.SetValue(ID, threshold * 1.E-6);
}
else
} else
out.SetValue(ID, this->GetValue(ID));
if ((distSign > 0 && aboveAir) || (distSign < 0 && !aboveAir))
@@ -481,13 +489,10 @@ VoxImage<T> VoxImage<T>::fixVoxelsAroundPlane( const float threshold, float tole
return out;
}
template<typename T>
void VoxImage<T>::InitVoxels(T t)
{
template <typename T> void VoxImage<T>::InitVoxels(T t) {
std::fill(m_Data.begin(), m_Data.end(), t); // warning... stl function //
}
}
} // namespace uLib
#endif // VOXIMAGE_H

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTER_H
#define VOXIMAGEFILTER_H
@@ -33,10 +31,8 @@
#include "Math/VoxImage.h"
namespace uLib {
namespace Interface {
struct VoxImageFilterShape {
template <class Self> void check_structural() {
@@ -44,11 +40,10 @@ struct VoxImageFilterShape {
uLibCheckFunction(Self, operator(), float, const Vector3f &);
}
};
}
} // namespace Interface
template <typename VoxelT> class Kernel;
namespace Abstract {
class VoxImageFilter {
public:
@@ -59,12 +54,10 @@ public:
protected:
virtual ~VoxImageFilter() {}
};
}
} // namespace Abstract
template <typename VoxelT, typename AlgorithmT>
class VoxImageFilter : public Abstract::VoxImageFilter
{
class VoxImageFilter : public Abstract::VoxImageFilter {
public:
VoxImageFilter(const Vector3i &size);
@@ -75,22 +68,22 @@ public:
void SetKernelSpherical(float (*shape)(float));
template < class ShapeT >
void SetKernelSpherical( ShapeT shape );
template <class ShapeT> void SetKernelSpherical(ShapeT shape);
void SetKernelWeightFunction(float (*shape)(const Vector3f &));
template < class ShapeT >
void SetKernelWeightFunction( ShapeT shape );
template <class ShapeT> 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; }
void SetImage(Abstract::VoxImage *image);
protected:
float Convolve(const VoxImage<VoxelT> &buffer, int index); // remove //
void SetKernelOffset();
@@ -103,26 +96,18 @@ protected:
private:
AlgorithmT *t_Algoritm;
};
}
} // namespace uLib
#endif // VOXIMAGEFILTER_H
#include "VoxImageFilter.hpp"
#include "VoxImageFilterLinear.hpp"
#include "VoxImageFilterThreshold.hpp"
#include "VoxImageFilterMedian.hpp"
#include "VoxImageFilter2ndStat.hpp"
#include "VoxImageFilterABTrim.hpp"
#include "VoxImageFilterBilateral.hpp"
#include "VoxImageFilter2ndStat.hpp"
#include "VoxImageFilterCustom.hpp"
#include "VoxImageFilterLinear.hpp"
#include "VoxImageFilterMedian.hpp"
#include "VoxImageFilterThreshold.hpp"

View File

@@ -23,24 +23,21 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTER_HPP
#define VOXIMAGEFILTER_HPP
#include <Math/Dense.h>
#include "Math/StructuredData.h"
#include "Math/VoxImage.h"
#include "VoxImageFilter.h"
#include <Math/Dense.h>
namespace uLib {
// KERNEL //////////////////////////////////////////////////////////////////////
template < typename T >
class Kernel : public StructuredData {
template <typename T> class Kernel : public StructuredData {
typedef StructuredData BaseClass;
public:
Kernel(const Vector3i &size);
@@ -48,34 +45,27 @@ public:
inline T &operator[](const int &id) { return m_Data[id]; }
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;
private:
std::vector<T> m_Data;
DataAllocator<T> m_Data;
};
template <typename T>
Kernel<T>::Kernel(const Vector3i &size) :
BaseClass(size),
m_Data(size.prod())
{
Kernel<T>::Kernel(const Vector3i &size) : BaseClass(size), m_Data(size.prod()) {
Interface::IsA<T, Interface::Voxel>();
}
template < typename T >
inline int Kernel<T>::GetCenterData() const
{
template <typename T> inline int Kernel<T>::GetCenterData() const {
static int center = Map(this->GetDims() / 2);
return center;
}
template < typename T >
void Kernel<T>::PrintSelf(std::ostream &o) const
{
template <typename T> void Kernel<T>::PrintSelf(std::ostream &o) const {
o << " Filter Kernel Dump [XZ_Y]: \n";
Vector3i index;
o << "\n Value: \n\n"
@@ -86,8 +76,10 @@ void Kernel<T>::PrintSelf(std::ostream &o) const
for (int x = 0; x < this->GetDims()(0); ++x) {
index << x, y, z;
o << m_Data[Map(index)].Value << " ";
} o << "\n";
} o << " --------------------------------------------------- \n";
}
o << "\n";
}
o << " --------------------------------------------------- \n";
}
o << "\n Offset: \n"
<< "------------------------------------------------- \n";
@@ -97,36 +89,24 @@ void Kernel<T>::PrintSelf(std::ostream &o) const
for (int x = 0; x < this->GetDims()(0); ++x) {
index << x, y, z;
o << m_Data[Map(index)].Count << " ";
} o << "\n";
} o << " --------------------------------------------------- \n";
}
o << "\n";
}
o << " --------------------------------------------------- \n";
}
}
////////////////////////////////////////////////////////////////////////////////
#define _TPL_ template <typename VoxelT, typename AlgorithmT>
#define _TPLT_ VoxelT, AlgorithmT
_TPL_
VoxImageFilter<_TPLT_>::VoxImageFilter(const Vector3i &size)
: m_KernelData(size), t_Algoritm(static_cast<AlgorithmT *>(this)) {}
_TPL_
VoxImageFilter<_TPLT_>::VoxImageFilter(const Vector3i &size) :
m_KernelData(size),
t_Algoritm(static_cast<AlgorithmT *>(this))
{
}
_TPL_
void VoxImageFilter<_TPLT_>::Run()
{
void VoxImageFilter<_TPLT_>::Run() {
VoxImage<VoxelT> buffer = *m_Image;
#pragma omp parallel for
for (int i = 0; i < m_Image->Data().size(); ++i)
@@ -135,8 +115,7 @@ void VoxImageFilter<_TPLT_>::Run()
}
_TPL_
void VoxImageFilter<_TPLT_>::SetKernelOffset()
{
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) {
@@ -149,22 +128,21 @@ void VoxImageFilter<_TPLT_>::SetKernelOffset()
}
_TPL_
float VoxImageFilter<_TPLT_>::Distance2(const Vector3i &v)
{
float VoxImageFilter<_TPLT_>::Distance2(const Vector3i &v) {
Vector3i tmp = v;
const Vector3i &dim = this->m_KernelData.GetDims();
Vector3i center = dim / 2;
tmp = tmp - center;
center = center.cwiseProduct(center);
tmp = tmp.cwiseProduct(tmp);
return (float)(tmp.sum()) / (float)( center.sum() + 0.25 *
(3 - (dim(0) % 2) - (dim(1) % 2) - (dim(2) % 2)));
return (float)(tmp.sum()) /
(float)(center.sum() +
0.25 * (3 - (dim(0) % 2) - (dim(1) % 2) - (dim(2) % 2)));
}
_TPL_
void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(const std::vector<float> &numeric)
{
void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(
const std::vector<float> &numeric) {
// set data order //
StructuredData::Order order = m_KernelData.GetDataOrder();
// m_KernelData.SetDataOrder(StructuredData::XZY);
@@ -182,8 +160,7 @@ void VoxImageFilter<_TPLT_>::SetKernelNumericXZY(const std::vector<float> &numer
}
_TPL_
void VoxImageFilter<_TPLT_>::SetKernelSpherical(float(* shape)(float))
{
void VoxImageFilter<_TPLT_>::SetKernelSpherical(float (*shape)(float)) {
Vector3i id;
for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
for (int z = 0; z < m_KernelData.GetDims()(2); ++z) {
@@ -195,10 +172,8 @@ void VoxImageFilter<_TPLT_>::SetKernelSpherical(float(* shape)(float))
}
}
_TPL_ template <class ShapeT>
void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape)
{
void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape) {
Interface::IsA<ShapeT, Interface::VoxImageFilterShape>();
Vector3i id;
for (int y = 0; y < m_KernelData.GetDims()(1); ++y) {
@@ -212,8 +187,8 @@ void VoxImageFilter<_TPLT_>::SetKernelSpherical(ShapeT shape)
}
_TPL_
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(float (*shape)(const Vector3f &))
{
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(
float (*shape)(const Vector3f &)) {
const Vector3i &dim = m_KernelData.GetDims();
Vector3i id;
Vector3f pt;
@@ -233,8 +208,7 @@ void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(float (*shape)(const Vector
}
_TPL_ template <class ShapeT>
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape)
{
void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape) {
Interface::IsA<ShapeT, Interface::VoxImageFilterShape>();
const Vector3i &dim = m_KernelData.GetDims();
Vector3i id;
@@ -254,22 +228,17 @@ void VoxImageFilter<_TPLT_>::SetKernelWeightFunction(ShapeT shape)
}
}
_TPL_
void VoxImageFilter<_TPLT_>::SetImage(Abstract::VoxImage *image)
{
void VoxImageFilter<_TPLT_>::SetImage(Abstract::VoxImage *image) {
this->m_Image = reinterpret_cast<VoxImage<VoxelT> *>(image);
this->SetKernelOffset();
}
_TPL_
float VoxImageFilter<_TPLT_>::Convolve(const VoxImage<VoxelT> &buffer, int index)
{
const std::vector<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vker = m_KernelData.ConstData();
float VoxImageFilter<_TPLT_>::Convolve(const VoxImage<VoxelT> &buffer,
int index) {
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
const DataAllocator<VoxelT> &vker = m_KernelData.ConstData();
int vox_size = vbuf.size();
int ker_size = vker.size();
int pos;
@@ -283,20 +252,9 @@ float VoxImageFilter<_TPLT_>::Convolve(const VoxImage<VoxelT> &buffer, int index
return conv / ksum;
}
#undef _TPLT_
#undef _TPL_
}
} // namespace uLib
#endif // VOXIMAGEFILTER_HPP

View File

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

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERABTRIM_HPP
#define VOXIMAGEFILTERABTRIM_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h"
#include "VoxImageFilter.h"
#include <Math/Dense.h>
////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER ABTRIM /////////////////////////////////////////////////
@@ -38,29 +36,115 @@
namespace uLib {
#if defined(USE_CUDA) && defined(__CUDACC__)
template <typename VoxelT>
class VoxFilterAlgorithmAbtrim :
public VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT> > {
__global__ void ABTrimFilterKernel(const VoxelT *in, VoxelT *out,
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
{
bool operator()(const VoxelT& e1, const VoxelT& e2)
{ return e1.Value < e2.Value; }
for (int i = 0; i < ker_size; ++i) {
mfh[i].Count = i;
}
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:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmAbtrim<VoxelT>> BaseClass;
VoxFilterAlgorithmAbtrim(const Vector3i &size) :
BaseClass(size)
{
VoxFilterAlgorithmAbtrim(const Vector3i &size) : BaseClass(size) {
mAtrim = 0;
mBtrim = 0;
}
float Evaluate(const VoxImage<VoxelT> &buffer, int index)
{
const std::vector<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData();
#if defined(USE_CUDA) && defined(__CUDACC__)
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;
@@ -69,7 +153,8 @@ public:
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 = index + vker[ik].Count -
vker[this->m_KernelData.GetCenterData()].Count;
pos = (pos + vox_size) % vox_size;
mfh[ik].Value = vbuf[pos].Value;
}
@@ -89,45 +174,75 @@ public:
return fconv / ker_sum;
}
inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; }
inline void SetABTrim(int a, int b) {
mAtrim = a;
mBtrim = b;
}
private:
int mAtrim;
int mBtrim;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Roberspierre Filter //
template <typename VoxelT>
class VoxFilterAlgorithmSPR :
public VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT> > {
class VoxFilterAlgorithmSPR
: public VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT>> {
struct KernelSortAscending
{
bool operator()(const VoxelT& e1, const VoxelT& e2)
{ return e1.Value < e2.Value; }
struct KernelSortAscending {
bool operator()(const VoxelT &e1, const VoxelT &e2) {
return e1.Value < e2.Value;
}
};
public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmSPR<VoxelT>> BaseClass;
VoxFilterAlgorithmSPR(const Vector3i &size) :
BaseClass(size)
{
VoxFilterAlgorithmSPR(const Vector3i &size) : BaseClass(size) {
mAtrim = 0;
mBtrim = 0;
}
float Evaluate(const VoxImage<VoxelT> &buffer, int index)
{
const std::vector<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData();
#if defined(USE_CUDA) && defined(__CUDACC__)
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;
@@ -145,8 +260,7 @@ public:
std::sort(mfh.begin(), mfh.end(), KernelSortAscending());
float spr = vbuf[index].Value;
if ((mAtrim > 0 && spr <= mfh[mAtrim - 1].Value) ||
(mBtrim > 0 && spr >= mfh[ker_size - mBtrim].Value) )
{
(mBtrim > 0 && spr >= mfh[ker_size - mBtrim].Value)) {
float ker_sum = 0;
float fconv = 0;
for (int ik = 0; ik < mAtrim; ik++)
@@ -159,21 +273,20 @@ public:
ker_sum += vker[mfh[ik].Count].Value;
return fconv / ker_sum;
}
else
} else
return spr;
}
inline void SetABTrim(int a, int b) { mAtrim = a; mBtrim = b; }
inline void SetABTrim(int a, int b) {
mAtrim = a;
mBtrim = b;
}
private:
int mAtrim;
int mBtrim;
};
}
} // namespace uLib
#endif // VOXIMAGEFILTERABTRIM_HPP

View File

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

View File

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

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXIMAGEFILTERLINEAR_HPP
#define VOXIMAGEFILTERLINEAR_HPP
#include <Math/Dense.h>
#include "Math/VoxImage.h"
#include "VoxImageFilter.h"
#include <Math/Dense.h>
////////////////////////////////////////////////////////////////////////////////
///// VOXIMAGE FILTER LINEAR /////////////////////////////////////////////////
@@ -38,24 +36,78 @@
namespace uLib {
#if defined(USE_CUDA) && defined(__CUDACC__)
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>
class VoxFilterAlgorithmLinear :
public VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT> > {
class VoxFilterAlgorithmLinear
: public VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT>> {
public:
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmLinear<VoxelT>> BaseClass;
VoxFilterAlgorithmLinear(const Vector3i &size) : BaseClass(size) {}
float Evaluate(const VoxImage<VoxelT> &buffer, int index)
{
const std::vector<VoxelT> &vbuf = buffer.ConstData();
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData();
#if defined(USE_CUDA) && defined(__CUDACC__)
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;
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 = 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;
@@ -64,6 +116,6 @@ public:
}
};
}
} // namespace uLib
#endif // VOXIMAGEFILTERLINEAR_HPP

View File

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

View File

@@ -23,11 +23,10 @@
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "VoxRaytracer.h"
#include "Utils.h"
#include "VoxRaytracer.h"
#define unlikely(expr) __builtin_expect(!!(expr), 0)
@@ -39,62 +38,56 @@ namespace uLib {
///// RAY DATA /////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void VoxRaytracer::RayData::AddElement(Id_t id, float L)
{
void VoxRaytracer::RayData::AddElement(Id_t id, float L) {
if (m_Count >= m_Data.size()) {
size_t new_size = m_Data.size() == 0 ? 128 : m_Data.size() * 2;
m_Data.resize(new_size);
}
Element el = {id, L};
m_Data.push_back(el);
m_Data[m_Count] = el;
m_Count++;
m_TotalLength += L;
}
void VoxRaytracer::RayData::AppendRay(const VoxRaytracer::RayData &in)
{
if (unlikely(!in.m_Data.size())) {
void VoxRaytracer::RayData::AppendRay(const VoxRaytracer::RayData &in) {
if (unlikely(in.m_Count == 0)) {
std::cout << "Warinig: PoCA on exit border!\n";
return;
} else if (unlikely(m_Count == 0)) {
m_Data.resize(in.m_Count);
for (size_t i = 0; i < in.m_Count; ++i) {
m_Data[i] = in.m_Data[i];
}
else if (unlikely(!m_Data.size())) {
m_Data = in.m_Data;
m_Count = in.m_Count;
m_TotalLength = in.m_TotalLength;
std::cout << "Warinig: PoCA on entrance border!\n";
return;
}
else {
} 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());
// }
if (in.m_Count > 0) {
if (m_Count + in.m_Count > m_Data.size()) {
m_Data.resize(m_Count + in.m_Count);
}
for (size_t i = 0; i < in.m_Count; ++i) {
m_Data[m_Count + i] = in.m_Data[i];
}
m_Count += in.m_Count;
}
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";
std::vector<Element>::iterator it;
for(it = m_Data.begin(); it < m_Data.end(); ++it)
o << "[ " << (*it).vox_id << ", " << (*it).L << "] \n";
for (size_t i = 0; i < m_Count; ++i)
o << "[ " << m_Data[i].vox_id << ", " << m_Data[i].L << "] \n";
}
////////////////////////////////////////////////////////////////////////////////
//// RAY TRACER ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt)
{
bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt) {
Vector4f s = m_Image->GetLocalPoint(line.direction);
pt = m_Image->GetLocalPoint(line.origin);
@@ -111,9 +104,9 @@ bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt)
offset(i) = (s(i) > 0) - (pt(i) - floor(pt(i)));
offset = offset.cwiseProduct(L).cwiseAbs();
int id; float d;
for(int loop=0; loop<8; loop++)
{
int id;
float d;
for (int loop = 0; loop < 8; loop++) {
int check_border = 0;
for (int i = 0; i < 3; ++i) {
check_border += pt(i) > 1;
@@ -132,7 +125,6 @@ bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt)
pt(id) = rintf(pt(id));
offset.array() -= d;
offset(id) = fabs(L(id));
}
@@ -142,33 +134,38 @@ bool VoxRaytracer::GetEntryPoint(const HLine3f &line, HPoint3f &pt)
return false;
}
bool VoxRaytracer::GetExitPoint(const HLine3f &line, HPoint3f &pt)
{
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
{
VoxRaytracer::RayData
VoxRaytracer::TraceBetweenPoints(const HPoint3f &in,
const HPoint3f &out) const {
RayData ray;
// get the local points and the direction vector
// local to image means in the normalized voxel space where the size
// of the voxel is 1 in all dimensions
Vector4f pt1 = m_Image->GetLocalPoint(in);
Vector4f pt2 = m_Image->GetLocalPoint(out);
Vector4f s = pt2 - pt1;
// l is the total length of the ray in normalized voxel space
float l = s.head(3).norm();
// L is the length of the ray between two grid lines in grid
Vector3f L(l / s(0), l / s(1), l / s(2));
// Vector3f scale; // FIXXX
// Vector3f scale; // TODO: FIX Scaling
// 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))) ;
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();
@@ -180,24 +177,27 @@ const
}
//---- Otherwise, loop until ray is finished
int id; float d;
int id;
float d;
while (l > 0) {
// find which is the minimum of the offsets to the next grid line
// it will be also the actual normalized voxel ray length
d = offset.minCoeff(&id);
// see if the voxel is inside the grid (we are still inside image)
if (m_Image->IsInsideGrid(vid)) {
// add the voxel to the ray with mapping id and length scaled
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);
// }
// move to the next voxel
vid(id) += (int)fast_sign(s(id));
// update the remaining length
l -= d;
// update the offsets
offset.array() -= d;
offset(id) = fmin(L(id), l);
}
@@ -205,8 +205,7 @@ const
}
// 20150528 SV for absorbed muons
VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const
{
VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const {
RayData ray;
Vector4f pt = m_Image->GetLocalPoint(line.origin);
@@ -222,18 +221,18 @@ VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const
// (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(),
// (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm();
// offset is the fraction of the segment between grid lines when origin is insiede voxel
// cwiseAbs for having positive distances
// offset is the fraction of the segment between grid lines when origin is
// insiede voxel cwiseAbs for having positive distances
Vector3f offset;
for (int i = 0; i < 3; ++i)
offset(i) = (s(i) >= 0) - (pt(i) - floor(pt(i)));
offset = offset.cwiseProduct(L).cwiseAbs();
L = L.cwiseAbs();
int id; float d;
int id;
float d;
Vector3i vid = m_Image->Find(line.origin);
while(m_Image->IsInsideGrid(vid))
{
while (m_Image->IsInsideGrid(vid)) {
// minimun coefficient of offset: id is the coordinate, d is the value
// dependig on which grid line horizontal or vertical it is first intercept
d = offset.minCoeff(&id);
@@ -250,4 +249,4 @@ VoxRaytracer::RayData VoxRaytracer::TraceLine(const HLine3f &line) const
return ray;
}
}
} // namespace uLib

View File

@@ -23,15 +23,20 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VOXRAYTRACER_H
#define VOXRAYTRACER_H
#include <Core/DataAllocator.h>
#include <Core/Vector.h>
#include <math.h>
#include <vector>
#include "Math/StructuredGrid.h"
#include "Math/VoxImage.h"
#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif
namespace uLib {
@@ -40,33 +45,41 @@ class VoxRaytracer {
public:
class RayData {
public:
RayData() : m_TotalLength(0) {}
RayData() : m_TotalLength(0), m_Count(0) {}
typedef struct {
struct Element {
Id_t vox_id;
Scalarf L;
} Element;
~Element() {}
};
inline void AddElement(Id_t id, float L);
void AppendRay(const RayData &in);
inline const std::vector<Element>& Data() const { return this->m_Data; }
inline uLib::Vector<Element> &Data() { return this->m_Data; }
inline const uLib::Vector<Element> &Data() const { return this->m_Data; }
inline size_t Count() const { return this->m_Count; }
inline const Scalarf &TotalLength() const { return this->m_TotalLength; }
inline void SetCount(size_t c) { this->m_Count = c; }
inline void SetTotalLength(Scalarf tl) { this->m_TotalLength = tl; }
void PrintSelf(std::ostream &o);
private:
std::vector<Element> m_Data;
uLib::Vector<Element> m_Data;
Scalarf m_TotalLength;
size_t m_Count;
};
public:
VoxRaytracer(StructuredGrid &image) : m_Image(&image) {
m_scale <<
(m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(),
m_scale << (m_Image->GetWorldMatrix() * Vector4f(1, 0, 0, 0)).norm(),
(m_Image->GetWorldMatrix() * Vector4f(0, 1, 0, 0)).norm(),
(m_Image->GetWorldMatrix() * Vector4f(0, 0, 1, 0)).norm();
}
@@ -81,13 +94,30 @@ public:
inline StructuredGrid *GetImage() const { return this->m_Image; }
#ifdef USE_CUDA
template <typename VoxelT>
void AccumulateLinesCUDA(const HLine3f *lines, size_t num_lines,
VoxImage<VoxelT> &image);
void TraceLineCUDA(const HLine3f *lines, size_t num_lines, RayData *out_rays,
int max_elements_per_ray = 128,
float *kernel_time_ms = nullptr);
void TraceBetweenPointsCUDA(const HPoint3f *in_pts, const HPoint3f *out_pts,
size_t num_lines, RayData *out_rays,
int max_elements_per_ray = 128,
float *kernel_time_ms = nullptr);
#endif
private:
StructuredGrid *m_Image;
Vector3f m_scale;
};
}
} // namespace uLib
#ifdef USE_CUDA
#include "Math/VoxRaytracerCUDA.hpp"
#endif
#endif // VOXRAYTRACER_H

View File

@@ -0,0 +1,548 @@
#ifndef VOXRAYTRACERCUDA_H
#define VOXRAYTRACERCUDA_H
#ifdef USE_CUDA
#include "Math/VoxImage.h"
#include "Math/VoxRaytracer.h"
#include <cuda_runtime.h>
namespace uLib {
#ifdef __CUDACC__
template <typename VoxelT>
__global__ void
RaytraceAccumulateKernel(const float *lines_data, int num_lines,
VoxelT *d_image, int dim0, int dim1, int dim2,
const float *inv_world_matrix_data, float scale0,
float scale1, float scale2) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= num_lines)
return;
const float *line_ptr = &lines_data[idx * 8];
float o_vec[4] = {line_ptr[0], line_ptr[1], line_ptr[2], line_ptr[3]};
float d_vec[4] = {line_ptr[4], line_ptr[5], line_ptr[6], line_ptr[7]};
float pt[4] = {0, 0, 0, 0};
float s[4] = {0, 0, 0, 0};
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
float m_val = inv_world_matrix_data[i + j * 4];
pt[i] += m_val * o_vec[j];
s[i] += m_val * d_vec[j];
}
}
float l = sqrtf(s[0] * s[0] + s[1] * s[1] + s[2] * s[2]);
if (l == 0)
return;
float L[3];
L[0] = l / s[0];
L[1] = l / s[1];
L[2] = l / s[2];
float offset[3];
for (int i = 0; i < 3; ++i) {
float fpt_i = floorf(pt[i]);
offset[i] = (s[i] >= 0) ? (1.0f - (pt[i] - fpt_i)) : (pt[i] - fpt_i);
offset[i] = fabsf(offset[i] * L[i]);
L[i] = fabsf(L[i]);
}
int id;
float d;
int vid[3] = {(int)floorf(pt[0]), (int)floorf(pt[1]), (int)floorf(pt[2])};
float scale_arr[3] = {scale0, scale1, scale2};
while (vid[0] >= 0 && vid[0] < dim0 && vid[1] >= 0 && vid[1] < dim1 &&
vid[2] >= 0 && vid[2] < dim2) {
d = offset[0];
id = 0;
if (offset[1] < d) {
d = offset[1];
id = 1;
}
if (offset[2] < d) {
d = offset[2];
id = 2;
}
float L_intersect = d * scale_arr[id];
size_t vox_index = vid[0] * dim1 * dim2 + vid[1] * dim2 + vid[2];
atomicAdd(&(d_image[vox_index].Value), L_intersect);
float sign_s = (s[id] >= 0) ? 1.0f : -1.0f;
vid[id] += (int)sign_s;
offset[0] -= d;
offset[1] -= d;
offset[2] -= d;
offset[id] = L[id];
}
}
#endif
template <typename VoxelT>
void VoxRaytracer::AccumulateLinesCUDA(const HLine3f *lines, size_t num_lines,
VoxImage<VoxelT> &image) {
if (num_lines == 0)
return;
image.Data().MoveToVRAM();
float *d_lines = nullptr;
size_t lines_size = num_lines * sizeof(HLine3f);
cudaMalloc(&d_lines, lines_size);
cudaMemcpy(d_lines, lines, lines_size, cudaMemcpyHostToDevice);
int threadsPerBlock = 256;
int blocksPerGrid = (num_lines + threadsPerBlock - 1) / threadsPerBlock;
Vector3i dims = image.GetDims();
Matrix4f inv_world_matrix = image.GetWorldMatrix().inverse();
float *d_inv_world;
cudaMalloc(&d_inv_world, 16 * sizeof(float));
cudaMemcpy(d_inv_world, inv_world_matrix.data(), 16 * sizeof(float),
cudaMemcpyHostToDevice);
#ifdef __CUDACC__
RaytraceAccumulateKernel<<<blocksPerGrid, threadsPerBlock>>>(
d_lines, num_lines, image.Data().GetVRAMData(), dims(0), dims(1), dims(2),
d_inv_world, m_scale(0), m_scale(1), m_scale(2));
cudaDeviceSynchronize();
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
std::cerr << "CUDA Error in AccumulateLinesCUDA: "
<< cudaGetErrorString(err) << std::endl;
}
#else
std::cerr << "RaytraceAccumulateKernel requires NVCC!" << std::endl;
#endif
cudaFree(d_lines);
cudaFree(d_inv_world);
}
#ifdef __CUDACC__
__global__ void TraceBetweenPointsKernel(
const float *in_pts_data, const float *out_pts_data, int num_lines,
VoxRaytracer::RayData::Element **d_out_elements, size_t *d_out_counts,
float *d_out_lengths, int max_elements, int dim0, int dim1, int dim2,
const float *inv_world_matrix_data, float scale0, float scale1,
float scale2, int inc0, int inc1, int inc2) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= num_lines)
return;
VoxRaytracer::RayData::Element *ray_out = d_out_elements[idx];
size_t count = 0;
float tot_len = 0.0f;
const float *in_ptr = &in_pts_data[idx * 4];
const float *out_ptr = &out_pts_data[idx * 4];
float pt1[4] = {0, 0, 0, 0}, pt2[4] = {0, 0, 0, 0};
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
float m_val = inv_world_matrix_data[i + j * 4];
pt1[i] += m_val * in_ptr[j];
pt2[i] += m_val * out_ptr[j];
}
}
float s[4];
for (int i = 0; i < 4; ++i)
s[i] = pt2[i] - pt1[i];
float l = sqrtf(s[0] * s[0] + s[1] * s[1] + s[2] * s[2]);
if (l == 0) {
d_out_counts[idx] = count;
d_out_lengths[idx] = tot_len;
return;
}
float L[3];
L[0] = fabsf(l / s[0]);
L[1] = fabsf(l / s[1]);
L[2] = fabsf(l / s[2]);
float offset[3];
for (int i = 0; i < 3; ++i) {
float fpt_i = floorf(pt1[i]);
offset[i] = (s[i] >= 0) ? (1.0f - (pt1[i] - fpt_i)) : (pt1[i] - fpt_i);
offset[i] = fabsf(offset[i] * L[i]);
}
int vid[3] = {(int)floorf(pt1[0]), (int)floorf(pt1[1]), (int)floorf(pt1[2])};
int vid_out[3] = {(int)floorf(pt2[0]), (int)floorf(pt2[1]),
(int)floorf(pt2[2])};
float scale_arr[3] = {scale0, scale1, scale2};
if (vid[0] == vid_out[0] && vid[1] == vid_out[1] && vid[2] == vid_out[2]) {
if (vid[0] >= 0 && vid[0] < dim0 && vid[1] >= 0 && vid[1] < dim1 &&
vid[2] >= 0 && vid[2] < dim2) {
if (count < max_elements) {
int map_id = vid[0] * inc0 + vid[1] * inc1 + vid[2] * inc2;
ray_out[count].vox_id = map_id;
ray_out[count].L = l;
tot_len += l;
count++;
}
}
d_out_counts[idx] = count;
d_out_lengths[idx] = tot_len;
return;
}
int id;
float d;
while (l > 0) {
d = offset[0];
id = 0;
if (offset[1] < d) {
d = offset[1];
id = 1;
}
if (offset[2] < d) {
d = offset[2];
id = 2;
}
if (vid[0] >= 0 && vid[0] < dim0 && vid[1] >= 0 && vid[1] < dim1 &&
vid[2] >= 0 && vid[2] < dim2) {
if (count < max_elements) {
int map_id = vid[0] * inc0 + vid[1] * inc1 + vid[2] * inc2;
ray_out[count].vox_id = map_id;
ray_out[count].L = d * scale_arr[id];
tot_len += d * scale_arr[id];
count++;
}
}
float sign_s = (s[id] >= 0) ? 1.0f : -1.0f;
vid[id] += (int)sign_s;
l -= d;
offset[0] -= d;
offset[1] -= d;
offset[2] -= d;
offset[id] = fminf(L[id], l);
}
d_out_counts[idx] = count;
d_out_lengths[idx] = tot_len;
}
__global__ void TraceLineKernel(const float *lines_data, int num_lines,
VoxRaytracer::RayData::Element **d_out_elements,
size_t *d_out_counts, float *d_out_lengths,
int max_elements, int dim0, int dim1, int dim2,
const float *inv_world_matrix_data,
float scale0, float scale1, float scale2,
int inc0, int inc1, int inc2) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= num_lines)
return;
VoxRaytracer::RayData::Element *ray_out = d_out_elements[idx];
size_t count = 0;
float tot_len = 0.0f;
const float *line_ptr = &lines_data[idx * 8];
float o_vec[4] = {line_ptr[0], line_ptr[1], line_ptr[2], line_ptr[3]};
float d_vec[4] = {line_ptr[4], line_ptr[5], line_ptr[6], line_ptr[7]};
float pt[4] = {0, 0, 0, 0}, s[4] = {0, 0, 0, 0};
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
float m_val = inv_world_matrix_data[i + j * 4];
pt[i] += m_val * o_vec[j];
s[i] += m_val * d_vec[j];
}
}
float l = sqrtf(s[0] * s[0] + s[1] * s[1] + s[2] * s[2]);
if (l == 0) {
d_out_counts[idx] = count;
d_out_lengths[idx] = tot_len;
return;
}
float L[3];
L[0] = fabsf(l / s[0]);
L[1] = fabsf(l / s[1]);
L[2] = fabsf(l / s[2]);
float offset[3];
for (int i = 0; i < 3; ++i) {
float fpt_i = floorf(pt[i]);
offset[i] = (s[i] >= 0) ? (1.0f - (pt[i] - fpt_i)) : (pt[i] - fpt_i);
offset[i] = fabsf(offset[i] * L[i]);
}
int id;
float d;
int vid[3] = {(int)floorf(pt[0]), (int)floorf(pt[1]), (int)floorf(pt[2])};
float scale_arr[3] = {scale0, scale1, scale2};
while (vid[0] >= 0 && vid[0] < dim0 && vid[1] >= 0 && vid[1] < dim1 &&
vid[2] >= 0 && vid[2] < dim2) {
d = offset[0];
id = 0;
if (offset[1] < d) {
d = offset[1];
id = 1;
}
if (offset[2] < d) {
d = offset[2];
id = 2;
}
if (count < max_elements) {
int map_id = vid[0] * inc0 + vid[1] * inc1 + vid[2] * inc2;
ray_out[count].vox_id = map_id;
ray_out[count].L = d * scale_arr[id];
tot_len += d * scale_arr[id];
count++;
}
float sign_s = (s[id] >= 0) ? 1.0f : -1.0f;
vid[id] += (int)sign_s;
offset[0] -= d;
offset[1] -= d;
offset[2] -= d;
offset[id] = L[id];
}
d_out_counts[idx] = count;
d_out_lengths[idx] = tot_len;
}
#endif // __CUDACC__
inline void VoxRaytracer::TraceLineCUDA(const HLine3f *lines, size_t num_lines,
RayData *out_rays,
int max_elements_per_ray,
float *kernel_time_ms) {
if (num_lines == 0)
return;
float *d_lines = nullptr;
bool alloc_lines = false;
cudaPointerAttributes ptr_attr;
cudaPointerGetAttributes(&ptr_attr, lines);
if (ptr_attr.type == cudaMemoryTypeDevice) {
d_lines = (float *)lines;
} else {
alloc_lines = true;
size_t lines_size = num_lines * sizeof(HLine3f);
cudaMalloc(&d_lines, lines_size);
cudaMemcpy(d_lines, lines, lines_size, cudaMemcpyHostToDevice);
}
std::vector<RayData::Element *> h_out_elements(num_lines);
for (size_t i = 0; i < num_lines; ++i) {
out_rays[i].Data().resize(max_elements_per_ray);
out_rays[i].Data().MoveToVRAM();
h_out_elements[i] = out_rays[i].Data().GetVRAMData();
}
RayData::Element **d_out_elements;
cudaMalloc(&d_out_elements, num_lines * sizeof(RayData::Element *));
cudaMemcpy(d_out_elements, h_out_elements.data(),
num_lines * sizeof(RayData::Element *), cudaMemcpyHostToDevice);
size_t *d_out_counts;
float *d_out_lengths;
cudaMalloc(&d_out_counts, num_lines * sizeof(size_t));
cudaMalloc(&d_out_lengths, num_lines * sizeof(float));
int threadsPerBlock = 256;
int blocksPerGrid = (num_lines + threadsPerBlock - 1) / threadsPerBlock;
Vector3i dims = m_Image->GetDims();
Vector3i incs = m_Image->GetIncrements();
Matrix4f inv_world_matrix = m_Image->GetWorldMatrix().inverse();
float *d_inv_world;
cudaMalloc(&d_inv_world, 16 * sizeof(float));
cudaMemcpy(d_inv_world, inv_world_matrix.data(), 16 * sizeof(float),
cudaMemcpyHostToDevice);
#ifdef __CUDACC__
cudaEvent_t start, stop;
if (kernel_time_ms) {
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start);
}
TraceLineKernel<<<blocksPerGrid, threadsPerBlock>>>(
d_lines, num_lines, d_out_elements, d_out_counts, d_out_lengths,
max_elements_per_ray, dims(0), dims(1), dims(2), d_inv_world, m_scale(0),
m_scale(1), m_scale(2), incs(0), incs(1), incs(2));
if (kernel_time_ms) {
cudaEventRecord(stop);
cudaEventSynchronize(stop);
cudaEventElapsedTime(kernel_time_ms, start, stop);
cudaEventDestroy(start);
cudaEventDestroy(stop);
} else {
cudaDeviceSynchronize();
}
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
std::cerr << "CUDA Error in TraceLineCUDA: " << cudaGetErrorString(err)
<< std::endl;
}
#else
std::cerr << "TraceLineKernel requires NVCC!" << std::endl;
#endif
std::vector<size_t> h_out_counts(num_lines);
std::vector<float> h_out_lengths(num_lines);
cudaMemcpy(h_out_counts.data(), d_out_counts, num_lines * sizeof(size_t),
cudaMemcpyDeviceToHost);
cudaMemcpy(h_out_lengths.data(), d_out_lengths, num_lines * sizeof(float),
cudaMemcpyDeviceToHost);
for (size_t i = 0; i < num_lines; ++i) {
out_rays[i].SetCount(h_out_counts[i]);
out_rays[i].SetTotalLength(h_out_lengths[i]);
}
if (alloc_lines) {
cudaFree(d_lines);
}
cudaFree(d_out_elements);
cudaFree(d_out_counts);
cudaFree(d_out_lengths);
cudaFree(d_inv_world);
}
inline void VoxRaytracer::TraceBetweenPointsCUDA(
const HPoint3f *in_pts, const HPoint3f *out_pts, size_t num_lines,
RayData *out_rays, int max_elements_per_ray, float *kernel_time_ms) {
if (num_lines == 0)
return;
float *d_in_pts = nullptr;
float *d_out_pts = nullptr;
bool alloc_pts = false;
cudaPointerAttributes ptr_attr;
cudaPointerGetAttributes(&ptr_attr, in_pts);
if (ptr_attr.type == cudaMemoryTypeDevice) {
d_in_pts = (float *)in_pts;
d_out_pts = (float *)out_pts;
} else {
alloc_pts = true;
size_t pts_size = num_lines * sizeof(HPoint3f);
cudaMalloc(&d_in_pts, pts_size);
cudaMalloc(&d_out_pts, pts_size);
cudaMemcpy(d_in_pts, in_pts, pts_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_out_pts, out_pts, pts_size, cudaMemcpyHostToDevice);
}
std::vector<RayData::Element *> h_out_elements(num_lines);
for (size_t i = 0; i < num_lines; ++i) {
out_rays[i].Data().resize(max_elements_per_ray);
out_rays[i].Data().MoveToVRAM();
h_out_elements[i] = out_rays[i].Data().GetVRAMData();
}
RayData::Element **d_out_elements;
cudaMalloc(&d_out_elements, num_lines * sizeof(RayData::Element *));
cudaMemcpy(d_out_elements, h_out_elements.data(),
num_lines * sizeof(RayData::Element *), cudaMemcpyHostToDevice);
size_t *d_out_counts;
float *d_out_lengths;
cudaMalloc(&d_out_counts, num_lines * sizeof(size_t));
cudaMalloc(&d_out_lengths, num_lines * sizeof(float));
int threadsPerBlock = 256;
int blocksPerGrid = (num_lines + threadsPerBlock - 1) / threadsPerBlock;
Vector3i dims = m_Image->GetDims();
Vector3i incs = m_Image->GetIncrements();
Matrix4f inv_world_matrix = m_Image->GetWorldMatrix().inverse();
float *d_inv_world;
cudaMalloc(&d_inv_world, 16 * sizeof(float));
cudaMemcpy(d_inv_world, inv_world_matrix.data(), 16 * sizeof(float),
cudaMemcpyHostToDevice);
#ifdef __CUDACC__
cudaEvent_t start, stop;
if (kernel_time_ms) {
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start);
}
TraceBetweenPointsKernel<<<blocksPerGrid, threadsPerBlock>>>(
d_in_pts, d_out_pts, num_lines, d_out_elements, d_out_counts,
d_out_lengths, max_elements_per_ray, dims(0), dims(1), dims(2),
d_inv_world, m_scale(0), m_scale(1), m_scale(2), incs(0), incs(1),
incs(2));
if (kernel_time_ms) {
cudaEventRecord(stop);
cudaEventSynchronize(stop);
cudaEventElapsedTime(kernel_time_ms, start, stop);
cudaEventDestroy(start);
cudaEventDestroy(stop);
} else {
cudaDeviceSynchronize();
}
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
std::cerr << "CUDA Error in TraceBetweenPointsCUDA: "
<< cudaGetErrorString(err) << std::endl;
}
#else
std::cerr << "TraceBetweenPointsKernel requires NVCC!" << std::endl;
#endif
std::vector<size_t> h_out_counts(num_lines);
std::vector<float> h_out_lengths(num_lines);
cudaMemcpy(h_out_counts.data(), d_out_counts, num_lines * sizeof(size_t),
cudaMemcpyDeviceToHost);
cudaMemcpy(h_out_lengths.data(), d_out_lengths, num_lines * sizeof(float),
cudaMemcpyDeviceToHost);
for (size_t i = 0; i < num_lines; ++i) {
out_rays[i].SetCount(h_out_counts[i]);
out_rays[i].SetTotalLength(h_out_lengths[i]);
}
if (alloc_pts) {
cudaFree(d_in_pts);
cudaFree(d_out_pts);
}
cudaFree(d_out_elements);
cudaFree(d_out_counts);
cudaFree(d_out_lengths);
cudaFree(d_inv_world);
}
} // namespace uLib
#endif // USE_CUDA
#endif // VOXRAYTRACERCUDA_H

View File

@@ -23,14 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/Accumulator.h"
#include "testing-prototype.h"
#include <TRandom.h>
#include <iostream>
#include <vector>
// #include <boost/accumulators/framework/accumulator_set.hpp>
// #include <boost/accumulators/statistics/count.hpp>
@@ -45,7 +43,8 @@ int test_ABTrim() {
acc.SetABTrim(1, 1);
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.push_back(tmpf);
// v << 1,5,5,5,300;
for (std::vector<float>::iterator itr = v.begin(); itr < v.end(); itr++)
@@ -56,50 +55,53 @@ int test_ABTrim() {
// << v << " ... out = " << acc() << "\n";
return (acc() == 15.0);
}
int test_Mean() {
Accumulator_Mean<float> mean;
TRandom rnd;
const int c = 10000000;
std::vector<float> v;
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];
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]);
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]);
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]);
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]);
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]);
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]);
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]);
for (int i = 0; i < c; ++i)
mean(v[i]);
std::cout << "mean pass: " << mean() << "\n";
return 1;
}
int main(void) {
BEGIN_TESTING(Accumulator);

View File

@@ -5,6 +5,7 @@ set(TESTS
ContainerBoxTest
VoxImageTest
VoxRaytracerTest
VoxRaytracerTestExtended
StructuredDataTest
VoxImageFilterTest
PolicyTest
@@ -17,6 +18,13 @@ set(TESTS
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
Boost::serialization
Eigen3::Eigen
)
uLib_add_tests(${uLib-module})
uLib_add_tests(Math)
if(USE_CUDA)
set_source_files_properties(VoxImageTest.cpp VoxImageCopyTest.cpp VoxImageFilterTest.cpp VoxRaytracerTest.cpp VoxRaytracerTestExtended.cpp PROPERTIES LANGUAGE CUDA)
set_source_files_properties(VoxRaytracerTest.cpp VoxRaytracerTestExtended.cpp PROPERTIES CXX_STANDARD 17 CUDA_STANDARD 17)
endif()

View File

@@ -23,18 +23,14 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/TriangleMesh.h"
#include <iostream>
using namespace uLib;
int main()
{
int main() {
BEGIN_TESTING(Triangle Mesh);
TriangleMesh mesh;
@@ -45,7 +41,6 @@ int main()
mesh.AddTriangle(Vector3i(0, 1, 2));
mesh.PrintSelf(std::cout);
END_TESTING;

View File

@@ -23,15 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/VoxImage.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
@@ -42,14 +39,13 @@ int main() {
{
VoxImage<TestVoxel> img(Vector3i(10, 10, 10));
TestVoxel zero = {0,0};
TestVoxel zero = {0.f, 0};
img.InitVoxels(zero);
TestVoxel nonzero = {5.552368, 0};
TestVoxel nonzero = {5.552368f, 0};
img[Vector3i(5, 1, 7)] = nonzero;
img[img.Find(HPoint3f(3, 3, 3))].Value = 5.552369;
TEST1(img.GetValue(Vector3i(5, 1, 7)) == 5.552368f);
img.SetOrigin(Vector3f(4, 5, 6));
std::cout << "\n";
@@ -63,15 +59,8 @@ int main() {
TEST1(img.GetSpacing() == img2.GetSpacing());
img2 = img;
}
std::cout << "returns " << _fail << "\n";
END_TESTING;
}

View File

@@ -23,17 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/StructuredGrid.h"
#include "testing-prototype.h"
#include "Math/VoxImage.h"
#include "Math/VoxImageFilter.h"
using namespace uLib;
struct TestVoxel {
@@ -41,39 +36,30 @@ struct TestVoxel {
unsigned int Count;
};
float GaussianShape(float d)
{
float GaussianShape(float d) {
// normalized manually .. fix //
return 4.5 * exp(-d * 4.5);
}
class GaussianShapeClass : public Interface::VoxImageFilterShape {
public:
GaussianShapeClass(float sigma) :
m_sigma(sigma)
{}
GaussianShapeClass(float sigma) : m_sigma(sigma) {}
float operator ()(float d) {
return (1/m_sigma) * exp(-d/m_sigma);
}
float operator()(float d) { return (1 / m_sigma) * exp(-d / m_sigma); }
private:
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)
if(v.at(i) > max) max = v.at(i);
if (v.at(i) > max)
max = v.at(i);
return max;
}
int main()
{
int main() {
BEGIN_TESTING(VoxImageFilters);
VoxImage<TestVoxel> image(Vector3i(20, 30, 40));
@@ -81,8 +67,6 @@ int main()
// image[Vector3i(10,10,8)].Value = 1;
image.ExportToVtk("test_filter_original.vtk", 0);
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@@ -113,10 +97,6 @@ int main()
filtered.ExportToVtk("filter_RPS_out.vtk", 0);
}
{
VoxImage<TestVoxel> image(Vector3i(20, 30, 40));
@@ -124,8 +104,6 @@ int main()
image[Vector3i(9, 10, 8)].Value = 2;
image.ExportToVtk("test_filter_max_original.vtk", 0);
VoxFilterAlgorithmCustom<TestVoxel> filter(Vector3i(3, 3, 4));
std::vector<float> values;
@@ -144,7 +122,92 @@ int main()
image.ExportToVtk("test_filter_max.vtk", 0);
}
////////////////////////////////////////////////////////////////////////////
// CUDA Allocator Transfer Test //
{
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;
for (int i = 0; i < filter.GetKernelData().GetDims().prod(); ++i) {
values.push_back(1.0f);
}
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();
// 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

@@ -23,16 +23,12 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/StructuredGrid.h"
#include "Math/VoxImage.h"
#include "Math/StructuredGrid.h"
#include "testing-prototype.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
@@ -64,12 +60,11 @@ int main() {
TEST1(img.GetWorldPoint(1, 1, 1) == HPoint3f(3, 5, 3));
}
{
VoxImage<TestVoxel> img(Vector3i(10, 10, 10));
TestVoxel zero = {0,0};
TestVoxel zero = {0.f, 0};
img.InitVoxels(zero);
TestVoxel nonzero = {5.552368, 0};
TestVoxel nonzero = {5.552368f, 0};
img[Vector3i(5, 1, 7)] = nonzero;
img[img.Find(HPoint3f(3, 3, 3))].Value = 5.552369;
img.ExportToVtk("./test_vox_image.vtk", 0);
@@ -79,11 +74,12 @@ int main() {
{
VoxImage<TestVoxel> img(Vector3i(4, 4, 4));
TestVoxel zero = {0,0};
TestVoxel zero = {0.f, 0};
img.InitVoxels(zero);
img.SetSpacing(Vector3f(2, 2, 2));
img.SetPosition(Vector3f(-4, -4, -4));
TEST1( img.GetWorldPoint(img.GetLocalPoint(HPoint3f(5,5,5))) == HPoint3f(5,5,5));
TEST1(img.GetWorldPoint(img.GetLocalPoint(HPoint3f(5, 5, 5))) ==
HPoint3f(5, 5, 5));
}
{
@@ -92,6 +88,19 @@ int main() {
imgR.ExportToVtk("./read_and_saved.vtk");
}
{
VoxImage<TestVoxel> img(Vector3i(4, 4, 4));
img.InitVoxels({0.f, 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)] = {static_cast<float>(i + j + k), 0};
}
}
}
img.ExportToVti("./vti_saved.vti", 0, 1);
// img.ImportFromVtkXml("./test_vox_image.vti");
}
{
VoxImage<TestVoxel> img1(Vector3i(5, 5, 5));
@@ -100,8 +109,5 @@ int main() {
TEST1(img1.GetDims() == img2.GetDims());
}
END_TESTING
}

View File

@@ -23,18 +23,14 @@
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Math/VoxRaytracer.h"
#include "Math/StructuredGrid.h"
#include "testing-prototype.h"
#include <iostream>
using namespace uLib;
int Vector4f0(Vector4f c)
{
int Vector4f0(Vector4f c) {
c(3) = 0;
if (fabs(c(0)) < 0.001 && fabs(c(1)) < 0.001 && fabs(c(2)) < 0.001)
return 0;
@@ -50,11 +46,14 @@ int Vector4f0(Vector4f c)
// return out == 0;
// }
typedef VoxRaytracer Raytracer;
int main()
{
struct TestVoxel {
float Value;
int Count;
};
int main() {
BEGIN_TESTING(Math VoxRaytracer);
StructuredGrid img(Vector3i(2, 2, 2));
@@ -93,21 +92,21 @@ int main()
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())
{
Raytracer::RayData rdata =
ray.TraceBetweenPoints(HPoint3f(-3, -3, -3), HPoint3f(3, 3, 3));
for (size_t i = 0; i < rdata.Count(); ++i) {
const Raytracer::RayData::Element &el = rdata.Data()[i];
std::cout << " " << el.vox_id << " , " << el.L << "\n";
}
}
{
HPoint3f pt1(1, -0.5, 1);
HPoint3f pt2(1, 4.5, 1);
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2);
TEST1( ray.Data().size() == 2 );
TEST1(ray.Count() == 2);
TEST1(ray.Data().at(0).vox_id == 6);
TEST1(ray.Data().at(1).vox_id == 7);
ray.PrintSelf(std::cout);
@@ -119,7 +118,7 @@ int main()
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2);
TEST1( ray.Data().size() == 2 );
TEST1(ray.Count() == 2);
TEST1(ray.Data().at(0).vox_id == 6);
TEST1(ray.Data().at(1).vox_id == 4);
ray.PrintSelf(std::cout);
@@ -131,7 +130,7 @@ int main()
Raytracer rt(img);
Raytracer::RayData ray = rt.TraceBetweenPoints(pt1, pt2);
TEST1( ray.Data().size() == 4 );
TEST1(ray.Count() == 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);
@@ -139,13 +138,81 @@ int main()
ray.PrintSelf(std::cout);
}
END_TESTING
#ifdef USE_CUDA
{
std::cout << "\n--- Testing CUDA Raytracer Accumulator ---\n";
Raytracer rt(img);
{
HPoint3f pt1(1, -0.5, 1);
HPoint3f pt2(1, 4.5, 1);
HPoint3f pts1[1] = {pt1};
HPoint3f pts2[1] = {pt2};
Raytracer::RayData ray_cuda[1];
rt.TraceBetweenPointsCUDA(pts1, pts2, 1, ray_cuda);
TEST1(ray_cuda[0].Count() == 2);
TEST1(ray_cuda[0].Data().at(0).vox_id == 6);
TEST1(ray_cuda[0].Data().at(1).vox_id == 7);
}
{
HPoint3f pt1(5, 1, 1);
HPoint3f pt2(-3, 1, 1);
HPoint3f pts1[1] = {pt1};
HPoint3f pts2[1] = {pt2};
Raytracer::RayData ray_cuda[1];
rt.TraceBetweenPointsCUDA(pts1, pts2, 1, ray_cuda);
TEST1(ray_cuda[0].Count() == 2);
TEST1(ray_cuda[0].Data().at(0).vox_id == 6);
TEST1(ray_cuda[0].Data().at(1).vox_id == 4);
}
{
HPoint3f pt1(1, 1, 1);
HPoint3f pt2(-1, 3, -1);
HPoint3f pts1[1] = {pt1};
HPoint3f pts2[1] = {pt2};
Raytracer::RayData ray_cuda[1];
rt.TraceBetweenPointsCUDA(pts1, pts2, 1, ray_cuda);
TEST1(ray_cuda[0].Count() == 4);
TEST1(ray_cuda[0].Data().at(0).vox_id == 6);
TEST1(ray_cuda[0].Data().at(1).vox_id == 4);
TEST1(ray_cuda[0].Data().at(2).vox_id == 5);
TEST1(ray_cuda[0].Data().at(3).vox_id == 1);
}
VoxImage<TestVoxel> img_cuda(Vector3i(4, 4, 4));
img_cuda.SetSpacing(Vector3f(2, 2, 2));
img_cuda.SetPosition(Vector3f(-4, -4, -4));
Raytracer ray(img_cuda);
HLine3f line1;
line1.origin << -3, -3, -3, 1;
line1.direction << 1, 1, 1, 0;
HLine3f line2;
line2.origin << -3, -3, 1, 1;
line2.direction << 1, 1, -1, 0;
HLine3f lines[2] = {line1, line2};
// Execute CUDA kernel wrapper over target VoxImage mapped internally into
// VRAM
ray.AccumulateLinesCUDA(lines, 2, img_cuda);
// Validate device synchronization returned data correctly pulling back to
// host
TEST1(img_cuda.Data().GetDevice() !=
MemoryDevice::RAM); // Confirms VRAM executed
// Pull down checking values
float l_val = img_cuda[img_cuda.Find(Vector4f(-3, -3, -3, 1))].Value;
std::cout << "Accumulated Voxel test trace point length returned: " << l_val
<< "\n";
TEST1(l_val > 0.1f);
}
#endif
END_TESTING
}

View File

@@ -0,0 +1,211 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Math/VoxRaytracer.h"
#include "testing-prototype.h"
#include <chrono>
#include <iostream>
#include <random>
using namespace uLib;
typedef VoxRaytracer Raytracer;
int main() {
BEGIN_TESTING(Math VoxRaytracer Extended Benchmark);
std::cout << "\n=============================================\n";
std::cout << " VoxRaytracer CPU vs CUDA Benchmark Test\n";
std::cout << "=============================================\n\n";
// Create a 100x100x100 grid (1 million voxels)
StructuredGrid img(Vector3i(100, 100, 100));
img.SetSpacing(Vector3f(1.0f, 1.0f, 1.0f));
img.SetPosition(Vector3f(-50.0f, -50.0f, -50.0f));
Raytracer rt(img);
const size_t NUM_RAYS = 1000000;
std::cout << "Generating " << NUM_RAYS
<< " random ray pairs across a 100x100x100 grid...\n";
std::vector<HPoint3f> in_pts(NUM_RAYS);
std::vector<HPoint3f> out_pts(NUM_RAYS);
// Use a fixed seed for reproducible tests
std::random_device rd;
std::mt19937 gen(rd());
// The grid spans from -50 to 50 on each axis
std::uniform_real_distribution<float> dist(-49.9f, 49.9f);
// Pick a random face for in/out to ensure rays cross the volume
std::uniform_int_distribution<int> face_dist(0, 5);
for (size_t i = 0; i < NUM_RAYS; ++i) {
HPoint3f p1, p2;
// Generate point 1 on a random face
int f1 = face_dist(gen);
p1(0) = (f1 == 0) ? -50.0f : (f1 == 1) ? 50.0f : dist(gen);
p1(1) = (f1 == 2) ? -50.0f : (f1 == 3) ? 50.0f : dist(gen);
p1(2) = (f1 == 4) ? -50.0f : (f1 == 5) ? 50.0f : dist(gen);
p1(3) = 1.0f;
// Generate point 2 on a different face
int f2;
do {
f2 = face_dist(gen);
} while (
f1 == f2 ||
f1 / 2 ==
f2 / 2); // Avoid same face or opposite face trivially if desired
p2(0) = (f2 == 0) ? -50.0f : (f2 == 1) ? 50.0f : dist(gen);
p2(1) = (f2 == 2) ? -50.0f : (f2 == 3) ? 50.0f : dist(gen);
p2(2) = (f2 == 4) ? -50.0f : (f2 == 5) ? 50.0f : dist(gen);
p2(3) = 1.0f;
in_pts[i] = p1;
out_pts[i] = p2;
}
std::vector<Raytracer::RayData> cpu_results(NUM_RAYS);
std::cout << "\nRunning CPU Raytracing...\n";
auto start_cpu = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < NUM_RAYS; ++i) {
cpu_results[i] = rt.TraceBetweenPoints(in_pts[i], out_pts[i]);
}
auto end_cpu = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> cpu_ms = end_cpu - start_cpu;
std::cout << "CPU Execution Time: " << cpu_ms.count() << " ms\n";
#ifdef USE_CUDA
std::vector<Raytracer::RayData> cuda_results(NUM_RAYS);
int max_elements_per_ray =
400; // 100x100x100 grid max trace length usually ~300 items
std::cout << "\nPre-Allocating Data to VRAM...\n";
// Pre-allocate input and output points to VRAM
HPoint3f *d_in_pts;
HPoint3f *d_out_pts;
size_t pts_size = NUM_RAYS * sizeof(HPoint3f);
cudaMalloc(&d_in_pts, pts_size);
cudaMalloc(&d_out_pts, pts_size);
cudaMemcpy(d_in_pts, in_pts.data(), pts_size, cudaMemcpyHostToDevice);
cudaMemcpy(d_out_pts, out_pts.data(), pts_size, cudaMemcpyHostToDevice);
// Pre-allocate elements output arrays in VRAM via DataAllocator
for (size_t i = 0; i < NUM_RAYS; ++i) {
cuda_results[i].Data().resize(max_elements_per_ray);
cuda_results[i].Data().MoveToVRAM();
}
std::cout << "Running CUDA Raytracing...\n";
auto start_cuda = std::chrono::high_resolution_clock::now();
float kernel_time_ms = 0.0f;
rt.TraceBetweenPointsCUDA(d_in_pts, d_out_pts, NUM_RAYS, cuda_results.data(),
max_elements_per_ray, &kernel_time_ms);
auto end_cuda = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> cuda_ms = end_cuda - start_cuda;
// Free explicit input pointers
cudaFree(d_in_pts);
cudaFree(d_out_pts);
// Also query memory usage info
size_t free_byte;
size_t total_byte;
cudaMemGetInfo(&free_byte, &total_byte);
double free_db = (double)free_byte / (1024.0 * 1024.0);
double total_db = (double)total_byte / (1024.0 * 1024.0);
double used_db = total_db - free_db;
std::cout << "CUDA Kernel Exec Time: " << kernel_time_ms << " ms\n";
std::cout << "CUDA Total Time (API): " << cuda_ms.count() << " ms\n";
std::cout << "CUDA Total Time Spdup: " << (cpu_ms.count() / cuda_ms.count())
<< "x\n";
if (kernel_time_ms > 0.0f) {
std::cout << "CUDA Kernel Speedup : " << (cpu_ms.count() / kernel_time_ms)
<< "x\n";
}
std::cout << "CUDA VRAM Usage Est. : " << used_db << " MB out of " << total_db
<< " MB total\n";
std::cout << "\nVerifying CUDA results against CPU...\n";
size_t mismatches = 0;
for (size_t i = 0; i < NUM_RAYS; ++i) {
const auto &cpu_ray = cpu_results[i];
const auto &cuda_ray = cuda_results[i];
if (cpu_ray.Count() != cuda_ray.Count() ||
std::abs(cpu_ray.TotalLength() - cuda_ray.TotalLength()) > 1e-3) {
if (mismatches < 5) {
std::cout << "Mismatch at ray " << i
<< ": CPU count=" << cpu_ray.Count()
<< ", len=" << cpu_ray.TotalLength()
<< " vs CUDA count=" << cuda_ray.Count()
<< ", len=" << cuda_ray.TotalLength() << "\n";
}
mismatches++;
continue;
}
// Check elements
for (size_t j = 0; j < cpu_ray.Count(); ++j) {
if (cpu_ray.Data()[j].vox_id != cuda_ray.Data()[j].vox_id ||
std::abs(cpu_ray.Data()[j].L - cuda_ray.Data()[j].L) > 1e-3) {
if (mismatches < 5) {
std::cout << "Mismatch at ray " << i << ", element " << j
<< ": CPU id=" << cpu_ray.Data()[j].vox_id
<< ", L=" << cpu_ray.Data()[j].L
<< " vs CUDA id=" << cuda_ray.Data()[j].vox_id
<< ", L=" << cuda_ray.Data()[j].L << "\n";
}
mismatches++;
break;
}
}
}
if (mismatches == 0) {
std::cout << "SUCCESS! All " << NUM_RAYS
<< " rays perfectly match between CPU and CUDA.\n";
} else {
std::cout << "FAILED! " << mismatches << " rays contain mismatched data.\n";
}
TEST1(mismatches == 0);
#else
std::cout << "\nUSE_CUDA is not defined. Skipping CUDA benchmarking.\n";
#endif
std::cout << "=============================================\n";
END_TESTING
}

58
src/Python/CMakeLists.txt Normal file
View File

@@ -0,0 +1,58 @@
set(HEADERS "")
set(SOURCES
module.cpp
core_bindings.cpp
math_bindings.cpp
math_filters_bindings.cpp
)
# Use pybind11 to add the python module
pybind11_add_module(uLib_python module.cpp core_bindings.cpp math_bindings.cpp math_filters_bindings.cpp)
# Link against our C++ libraries
target_link_libraries(uLib_python PRIVATE
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
)
# Include directories from Core and Math are automatically handled if target_include_directories were set appropriately,
# but we might need to manually include them if they aren't INTERFACE includes.
target_include_directories(uLib_python PRIVATE
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}
)
# Install uLib_python within the uLib install target
install(TARGETS uLib_python
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
)
# --- Python Tests ---------------------------------------------------------- #
if(BUILD_TESTING)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_test(NAME pybind_general
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testing/pybind_test.py)
set_tests_properties(pybind_general PROPERTIES
ENVIRONMENT "PYTHONPATH=$<TARGET_FILE_DIR:uLib_python>:${PROJECT_SOURCE_DIR}/src/Python")
add_test(NAME pybind_core
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testing/core_pybind_test.py)
set_tests_properties(pybind_core PROPERTIES
ENVIRONMENT "PYTHONPATH=$<TARGET_FILE_DIR:uLib_python>:${PROJECT_SOURCE_DIR}/src/Python")
add_test(NAME pybind_math
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testing/math_pybind_test.py)
set_tests_properties(pybind_math PROPERTIES
ENVIRONMENT "PYTHONPATH=$<TARGET_FILE_DIR:uLib_python>:${PROJECT_SOURCE_DIR}/src/Python")
add_test(NAME pybind_math_filters
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testing/math_filters_test.py)
set_tests_properties(pybind_math_filters PROPERTIES
ENVIRONMENT "PYTHONPATH=$<TARGET_FILE_DIR:uLib_python>:${PROJECT_SOURCE_DIR}/src/Python")
endif()

View File

@@ -0,0 +1,30 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "Core/Object.h"
#include "Core/Timer.h"
#include "Core/Options.h"
#include "Core/Uuid.h"
namespace py = pybind11;
using namespace uLib;
void init_core(py::module_ &m) {
py::class_<Object, std::shared_ptr<Object>>(m, "Object")
.def(py::init<>())
.def("DeepCopy", &Object::DeepCopy);
py::class_<Timer>(m, "Timer")
.def(py::init<>())
.def("Start", &Timer::Start)
.def("StopWatch", &Timer::StopWatch);
py::class_<Options>(m, "Options")
.def(py::init<const char*>(), py::arg("str") = "Program options")
.def("parse_config_file", py::overload_cast<const char*>(&Options::parse_config_file))
.def("save_config_file", &Options::save_config_file)
.def("count", &Options::count);
py::class_<TypeRegister>(m, "TypeRegister")
.def_static("Controller", &TypeRegister::Controller, py::return_value_policy::reference_internal);
}

View File

@@ -0,0 +1,385 @@
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/numpy.h>
#include "Math/Dense.h"
#include "Math/Transform.h"
#include "Math/Geometry.h"
#include "Math/ContainerBox.h"
#include "Math/StructuredData.h"
#include "Math/StructuredGrid.h"
#include "Math/Structured2DGrid.h"
#include "Math/Structured4DGrid.h"
#include "Math/TriangleMesh.h"
#include "Math/VoxRaytracer.h"
#include "Math/Accumulator.h"
#include "Math/VoxImage.h"
namespace py = pybind11;
using namespace uLib;
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalari>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalarui>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalarl>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalarul>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalarf>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Scalard>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector3f>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector3i>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector4f>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector4i>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector3d>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Vector4d>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<Voxel>);
PYBIND11_MAKE_OPAQUE(uLib::Vector<VoxRaytracer::RayData::Element>);
template <typename MatrixType>
void bind_eigen_type(py::module_ &m, const char *name) {
using Scalar = typename MatrixType::Scalar;
constexpr bool is_vector = MatrixType::IsVectorAtCompileTime;
// Default constructor (zeros)
m.def(name, []() -> MatrixType {
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic || MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
return MatrixType(); // Empty dynamic matrix
} else {
return MatrixType::Zero(); // Zero static matrix
}
});
// Specialized constructor for dynamic matrices
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic || MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
m.def(name, [](int rows, int cols) -> MatrixType {
MatrixType mat;
mat.setZero(rows, cols);
return mat;
});
}
// Initialize from list
m.def(name, [](py::list l) -> MatrixType {
MatrixType mat;
if constexpr (is_vector) {
mat.setZero(l.size());
for (size_t i = 0; i < l.size(); ++i) {
mat(i) = l[i].cast<Scalar>();
}
} else {
int rows = MatrixType::RowsAtCompileTime == Eigen::Dynamic ? (int)std::sqrt(l.size()) : MatrixType::RowsAtCompileTime;
int cols = MatrixType::ColsAtCompileTime == Eigen::Dynamic ? (int)std::sqrt(l.size()) : MatrixType::ColsAtCompileTime;
mat.setZero(rows, cols);
for (size_t i = 0; i < (size_t)l.size(); ++i) {
mat(i / cols, i % cols) = l[i].cast<Scalar>();
}
}
return mat;
});
// Initialize from py::array
m.def(name, [](py::array_t<Scalar, py::array::c_style | py::array::forcecast> arr) -> MatrixType {
auto buf = arr.request();
MatrixType mat;
if constexpr (is_vector) {
mat.setZero(buf.size);
Scalar* ptr = static_cast<Scalar*>(buf.ptr);
for (ssize_t i = 0; i < buf.size; ++i) mat(i) = ptr[i];
} else {
int rows = buf.shape.size() > 0 ? (int)buf.shape[0] : 1;
int cols = buf.shape.size() > 1 ? (int)buf.shape[1] : 1;
mat.setZero(rows, cols);
Scalar* ptr = static_cast<Scalar*>(buf.ptr);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
mat(i, j) = ptr[i * cols + j];
}
}
}
return mat;
});
}
void init_math(py::module_ &m) {
// 1. Basic Eigen Types (Vectors and Matrices)
bind_eigen_type<Vector1f>(m, "Vector1f");
bind_eigen_type<Vector2f>(m, "Vector2f");
bind_eigen_type<Vector3f>(m, "Vector3f");
bind_eigen_type<Vector4f>(m, "Vector4f");
bind_eigen_type<Vector1i>(m, "Vector1i");
bind_eigen_type<Vector2i>(m, "Vector2i");
bind_eigen_type<Vector3i>(m, "Vector3i");
bind_eigen_type<Vector4i>(m, "Vector4i");
bind_eigen_type<Vector1d>(m, "Vector1d");
bind_eigen_type<Vector2d>(m, "Vector2d");
bind_eigen_type<Vector3d>(m, "Vector3d");
bind_eigen_type<Vector4d>(m, "Vector4d");
bind_eigen_type<Matrix2f>(m, "Matrix2f");
bind_eigen_type<Matrix3f>(m, "Matrix3f");
bind_eigen_type<Matrix4f>(m, "Matrix4f");
bind_eigen_type<Matrix2i>(m, "Matrix2i");
bind_eigen_type<Matrix3i>(m, "Matrix3i");
bind_eigen_type<Matrix4i>(m, "Matrix4i");
bind_eigen_type<Matrix2d>(m, "Matrix2d");
bind_eigen_type<Matrix3d>(m, "Matrix3d");
bind_eigen_type<Matrix4d>(m, "Matrix4d");
bind_eigen_type<MatrixXi>(m, "MatrixXi");
bind_eigen_type<MatrixXf>(m, "MatrixXf");
bind_eigen_type<MatrixXd>(m, "MatrixXd");
// 2. Homogeneous types
py::class_<HPoint3f>(m, "HPoint3f")
.def(py::init<>())
.def(py::init<float, float, float>())
.def(py::init<Vector3f &>());
py::class_<HVector3f>(m, "HVector3f")
.def(py::init<>())
.def(py::init<float, float, float>())
.def(py::init<Vector3f &>());
py::class_<HLine3f>(m, "HLine3f")
.def(py::init<>())
.def_readwrite("origin", &HLine3f::origin)
.def_readwrite("direction", &HLine3f::direction);
py::class_<HError3f>(m, "HError3f")
.def(py::init<>())
.def_readwrite("position_error", &HError3f::position_error)
.def_readwrite("direction_error", &HError3f::direction_error);
// 3. Dynamic Vectors (uLib::Vector)
py::bind_vector<uLib::Vector<Scalari>>(m, "Vector_i")
.def("MoveToVRAM", &uLib::Vector<Scalari>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalari>::MoveToRAM);
py::bind_vector<uLib::Vector<Scalarui>>(m, "Vector_ui")
.def("MoveToVRAM", &uLib::Vector<Scalarui>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalarui>::MoveToRAM);
py::bind_vector<uLib::Vector<Scalarl>>(m, "Vector_l")
.def("MoveToVRAM", &uLib::Vector<Scalarl>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalarl>::MoveToRAM);
py::bind_vector<uLib::Vector<Scalarul>>(m, "Vector_ul")
.def("MoveToVRAM", &uLib::Vector<Scalarul>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalarul>::MoveToRAM);
py::bind_vector<uLib::Vector<Scalarf>>(m, "Vector_f")
.def("MoveToVRAM", &uLib::Vector<Scalarf>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalarf>::MoveToRAM);
py::bind_vector<uLib::Vector<Scalard>>(m, "Vector_d")
.def("MoveToVRAM", &uLib::Vector<Scalard>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Scalard>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector3f>>(m, "Vector_Vector3f")
.def("MoveToVRAM", &uLib::Vector<Vector3f>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector3f>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector3i>>(m, "Vector_Vector3i")
.def("MoveToVRAM", &uLib::Vector<Vector3i>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector3i>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector4f>>(m, "Vector_Vector4f")
.def("MoveToVRAM", &uLib::Vector<Vector4f>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector4f>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector4i>>(m, "Vector_Vector4i")
.def("MoveToVRAM", &uLib::Vector<Vector4i>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector4i>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector3d>>(m, "Vector_Vector3d")
.def("MoveToVRAM", &uLib::Vector<Vector3d>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector3d>::MoveToRAM);
py::bind_vector<uLib::Vector<Vector4d>>(m, "Vector_Vector4d")
.def("MoveToVRAM", &uLib::Vector<Vector4d>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Vector4d>::MoveToRAM);
py::bind_vector<uLib::Vector<Voxel>>(m, "Vector_Voxel")
.def("MoveToVRAM", &uLib::Vector<Voxel>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<Voxel>::MoveToRAM);
py::bind_vector<uLib::Vector<VoxRaytracer::RayData::Element>>(m, "Vector_VoxRaytracerRayDataElement")
.def("MoveToVRAM", &uLib::Vector<VoxRaytracer::RayData::Element>::MoveToVRAM)
.def("MoveToRAM", &uLib::Vector<VoxRaytracer::RayData::Element>::MoveToRAM);
// 4. Accumulators
py::class_<Accumulator_Mean<float>>(m, "Accumulator_Mean_f")
.def(py::init<>())
.def("AddPass", &Accumulator_Mean<float>::AddPass)
.def("__call__", py::overload_cast<const float>(&Accumulator_Mean<float>::operator()))
.def("__call__", py::overload_cast<>(&Accumulator_Mean<float>::operator(), py::const_));
py::class_<Accumulator_Mean<double>>(m, "Accumulator_Mean_d")
.def(py::init<>())
.def("AddPass", &Accumulator_Mean<double>::AddPass)
.def("__call__", py::overload_cast<const double>(&Accumulator_Mean<double>::operator()))
.def("__call__", py::overload_cast<>(&Accumulator_Mean<double>::operator(), py::const_));
py::class_<Accumulator_ABTrim<float>>(m, "Accumulator_ABTrim_f")
.def(py::init<>())
.def("SetABTrim", &Accumulator_ABTrim<float>::SetABTrim)
.def("__iadd__", [](Accumulator_ABTrim<float> &self, float val) { self += val; return &self; })
.def("__call__", &Accumulator_ABTrim<float>::operator());
py::class_<Accumulator_ABTrim<double>>(m, "Accumulator_ABTrim_d")
.def(py::init<>())
.def("SetABTrim", &Accumulator_ABTrim<double>::SetABTrim)
.def("__iadd__", [](Accumulator_ABTrim<double> &self, double val) { self += val; return &self; })
.def("__call__", &Accumulator_ABTrim<double>::operator());
py::class_<Accumulator_ABClip<float>>(m, "Accumulator_ABClip_f")
.def(py::init<>())
.def("SetABTrim", &Accumulator_ABClip<float>::SetABTrim)
.def("__iadd__", [](Accumulator_ABClip<float> &self, float val) { self += val; return &self; })
.def("__call__", &Accumulator_ABClip<float>::operator());
py::class_<Accumulator_ABClip<double>>(m, "Accumulator_ABClip_d")
.def(py::init<>())
.def("SetABTrim", &Accumulator_ABClip<double>::SetABTrim)
.def("__iadd__", [](Accumulator_ABClip<double> &self, double val) { self += val; return &self; })
.def("__call__", &Accumulator_ABClip<double>::operator());
// 5. Core Math Structures
py::class_<AffineTransform>(m, "AffineTransform")
.def(py::init<>())
.def("GetWorldMatrix", &AffineTransform::GetWorldMatrix)
.def("SetPosition", &AffineTransform::SetPosition)
.def("GetPosition", &AffineTransform::GetPosition)
.def("Translate", &AffineTransform::Translate)
.def("Scale", &AffineTransform::Scale)
.def("SetRotation", &AffineTransform::SetRotation)
.def("GetRotation", &AffineTransform::GetRotation)
.def("Rotate", py::overload_cast<const Matrix3f &>(&AffineTransform::Rotate))
.def("Rotate", py::overload_cast<const Vector3f>(&AffineTransform::Rotate))
.def("EulerYZYRotate", &AffineTransform::EulerYZYRotate)
.def("FlipAxes", &AffineTransform::FlipAxes);
py::class_<Geometry, AffineTransform>(m, "Geometry")
.def(py::init<>())
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&Geometry::GetWorldPoint, py::const_))
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&Geometry::GetLocalPoint, py::const_));
py::class_<ContainerBox, AffineTransform>(m, "ContainerBox")
.def(py::init<>())
.def("SetOrigin", &ContainerBox::SetOrigin)
.def("GetOrigin", &ContainerBox::GetOrigin)
.def("SetSize", &ContainerBox::SetSize)
.def("GetSize", &ContainerBox::GetSize)
.def("GetWorldMatrix", &ContainerBox::GetWorldMatrix)
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetWorldPoint, py::const_))
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetLocalPoint, py::const_));
py::enum_<StructuredData::_Order>(m, "StructuredDataOrder")
.value("CustomOrder", StructuredData::CustomOrder)
.value("XYZ", StructuredData::XYZ)
.value("XZY", StructuredData::XZY)
.value("YXZ", StructuredData::YXZ)
.value("YZX", StructuredData::YZX)
.value("ZXY", StructuredData::ZXY)
.value("ZYX", StructuredData::ZYX)
.export_values();
py::class_<StructuredData>(m, "StructuredData")
.def(py::init<const Vector3i &>())
.def("GetDims", &StructuredData::GetDims)
.def("SetDims", &StructuredData::SetDims)
.def("GetIncrements", &StructuredData::GetIncrements)
.def("SetIncrements", &StructuredData::SetIncrements)
.def("SetDataOrder", &StructuredData::SetDataOrder)
.def("GetDataOrder", &StructuredData::GetDataOrder)
.def("IsInsideGrid", &StructuredData::IsInsideGrid)
.def("Map", &StructuredData::Map)
.def("UnMap", &StructuredData::UnMap);
py::class_<StructuredGrid, ContainerBox, StructuredData>(m, "StructuredGrid")
.def(py::init<const Vector3i &>())
.def("SetSpacing", &StructuredGrid::SetSpacing)
.def("GetSpacing", &StructuredGrid::GetSpacing)
.def("IsInsideBounds", &StructuredGrid::IsInsideBounds)
.def("Find", [](StructuredGrid &self, Vector3f pt) {
return self.Find(HPoint3f(pt));
});
py::class_<Structured2DGrid>(m, "Structured2DGrid")
.def(py::init<>())
.def("SetDims", &Structured2DGrid::SetDims)
.def("GetDims", &Structured2DGrid::GetDims)
.def("IsInsideGrid", &Structured2DGrid::IsInsideGrid)
.def("Map", &Structured2DGrid::Map)
.def("UnMap", &Structured2DGrid::UnMap)
.def("SetPhysicalSpace", &Structured2DGrid::SetPhysicalSpace)
.def("GetSpacing", &Structured2DGrid::GetSpacing)
.def("GetOrigin", &Structured2DGrid::GetOrigin)
.def("IsInsideBounds", &Structured2DGrid::IsInsideBounds)
.def("PhysicsToUnitSpace", &Structured2DGrid::PhysicsToUnitSpace)
.def("UnitToPhysicsSpace", &Structured2DGrid::UnitToPhysicsSpace)
.def("SetDebug", &Structured2DGrid::SetDebug);
py::class_<Structured4DGrid>(m, "Structured4DGrid")
.def(py::init<>())
.def("SetDims", &Structured4DGrid::SetDims)
.def("GetDims", &Structured4DGrid::GetDims)
.def("IsInsideGrid", &Structured4DGrid::IsInsideGrid)
.def("Map", &Structured4DGrid::Map)
.def("UnMap", &Structured4DGrid::UnMap)
.def("SetPhysicalSpace", &Structured4DGrid::SetPhysicalSpace)
.def("GetSpacing", &Structured4DGrid::GetSpacing)
.def("GetOrigin", &Structured4DGrid::GetOrigin)
.def("IsInsideBounds", &Structured4DGrid::IsInsideBounds)
.def("PhysicsToUnitSpace", &Structured4DGrid::PhysicsToUnitSpace)
.def("UnitToPhysicsSpace", &Structured4DGrid::UnitToPhysicsSpace)
.def("SetDebug", &Structured4DGrid::SetDebug);
// 6. High-level Structures
py::class_<Voxel>(m, "Voxel")
.def(py::init<>())
.def_readwrite("Value", &Voxel::Value)
.def_readwrite("Count", &Voxel::Count);
py::class_<Abstract::VoxImage, StructuredGrid>(m, "AbstractVoxImage")
.def("GetValue", py::overload_cast<const Vector3i &>(&Abstract::VoxImage::GetValue, py::const_))
.def("GetValue", py::overload_cast<const int>(&Abstract::VoxImage::GetValue, py::const_))
.def("SetValue", py::overload_cast<const Vector3i &, float>(&Abstract::VoxImage::SetValue))
.def("SetValue", py::overload_cast<const int, float>(&Abstract::VoxImage::SetValue))
.def("ExportToVtk", &Abstract::VoxImage::ExportToVtk)
.def("ExportToVti", &Abstract::VoxImage::ExportToVti)
.def("ImportFromVtk", &Abstract::VoxImage::ImportFromVtk)
.def("ImportFromVti", &Abstract::VoxImage::ImportFromVti);
py::class_<VoxImage<Voxel>, Abstract::VoxImage>(m, "VoxImage")
.def(py::init<>())
.def(py::init<const Vector3i &>())
.def("Data", &VoxImage<Voxel>::Data, py::return_value_policy::reference_internal)
.def("InitVoxels", &VoxImage<Voxel>::InitVoxels)
.def("Abs", &VoxImage<Voxel>::Abs)
.def("clipImage", py::overload_cast<const Vector3i, const Vector3i>(&VoxImage<Voxel>::clipImage, py::const_))
.def("clipImage", py::overload_cast<const HPoint3f, const HPoint3f>(&VoxImage<Voxel>::clipImage, py::const_))
.def("clipImage", py::overload_cast<const float>(&VoxImage<Voxel>::clipImage, py::const_))
.def("maskImage", py::overload_cast<const HPoint3f, const HPoint3f, float>(&VoxImage<Voxel>::maskImage, py::const_))
.def("maskImage", py::overload_cast<const float, float, float>(&VoxImage<Voxel>::maskImage, py::const_), py::arg("threshold"), py::arg("belowValue") = 0, py::arg("aboveValue") = 0)
.def("fixVoxels", py::overload_cast<const float, float>(&VoxImage<Voxel>::fixVoxels, py::const_))
.def("__getitem__", py::overload_cast<unsigned int>(&VoxImage<Voxel>::operator[]))
.def("__getitem__", py::overload_cast<const Vector3i &>(&VoxImage<Voxel>::operator[]));
py::class_<TriangleMesh>(m, "TriangleMesh")
.def(py::init<>())
.def("AddPoint", &TriangleMesh::AddPoint)
.def("AddTriangle", py::overload_cast<const Vector3i &>(&TriangleMesh::AddTriangle))
.def("Points", &TriangleMesh::Points, py::return_value_policy::reference_internal)
.def("Triangles", &TriangleMesh::Triangles, py::return_value_policy::reference_internal);
py::class_<VoxRaytracer::RayData::Element>(m, "VoxRaytracerRayDataElement")
.def(py::init<>())
.def_readwrite("vox_id", &VoxRaytracer::RayData::Element::vox_id)
.def_readwrite("L", &VoxRaytracer::RayData::Element::L);
py::class_<VoxRaytracer::RayData>(m, "VoxRaytracerRayData")
.def(py::init<>())
.def("AppendRay", &VoxRaytracer::RayData::AppendRay)
.def("Data", py::overload_cast<>(&VoxRaytracer::RayData::Data), py::return_value_policy::reference_internal)
.def("Count", &VoxRaytracer::RayData::Count)
.def("TotalLength", &VoxRaytracer::RayData::TotalLength)
.def("SetCount", &VoxRaytracer::RayData::SetCount)
.def("SetTotalLength", &VoxRaytracer::RayData::SetTotalLength);
py::class_<VoxRaytracer>(m, "VoxRaytracer")
.def(py::init<StructuredGrid &>(), py::keep_alive<1, 2>())
.def("GetImage", &VoxRaytracer::GetImage, py::return_value_policy::reference_internal)
.def("TraceLine", &VoxRaytracer::TraceLine)
.def("TraceBetweenPoints", &VoxRaytracer::TraceBetweenPoints);
}

View File

@@ -0,0 +1,100 @@
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include "Math/VoxImage.h"
#include "Math/VoxImageFilter.h"
#include "Math/VoxImageFilterLinear.hpp"
#include "Math/VoxImageFilterABTrim.hpp"
#include "Math/VoxImageFilterBilateral.hpp"
#include "Math/VoxImageFilterThreshold.hpp"
#include "Math/VoxImageFilterMedian.hpp"
#include "Math/VoxImageFilter2ndStat.hpp"
#include "Math/VoxImageFilterCustom.hpp"
namespace py = pybind11;
using namespace uLib;
template <typename Algorithm>
void bind_common_filter(py::class_<Algorithm, Abstract::VoxImageFilter> &cls) {
cls.def(py::init<const Vector3i &>())
.def("Run", &Algorithm::Run)
.def("SetKernelNumericXZY", &Algorithm::SetKernelNumericXZY)
.def("GetImage", &Algorithm::GetImage, py::return_value_policy::reference_internal)
.def("SetImage", &Algorithm::SetImage);
}
void init_math_filters(py::module_ &m) {
// Abstract::VoxImageFilter
py::class_<Abstract::VoxImageFilter, std::unique_ptr<Abstract::VoxImageFilter, py::nodelete>>(m, "AbstractVoxImageFilter")
.def("Run", &Abstract::VoxImageFilter::Run)
.def("SetImage", &Abstract::VoxImageFilter::SetImage);
// Helper macro to define standard bindings for a filter
#define BIND_FILTER(ClassName) \
{ \
auto cls = py::class_<ClassName<Voxel>, Abstract::VoxImageFilter>(m, #ClassName); \
bind_common_filter(cls); \
}
// VoxFilterAlgorithmLinear
{
auto cls = py::class_<VoxFilterAlgorithmLinear<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmLinear");
bind_common_filter(cls);
}
// VoxFilterAlgorithmAbtrim
{
auto cls = py::class_<VoxFilterAlgorithmAbtrim<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmAbtrim");
bind_common_filter(cls);
cls.def("SetABTrim", &VoxFilterAlgorithmAbtrim<Voxel>::SetABTrim);
}
// VoxFilterAlgorithmSPR
{
auto cls = py::class_<VoxFilterAlgorithmSPR<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmSPR");
bind_common_filter(cls);
cls.def("SetABTrim", &VoxFilterAlgorithmSPR<Voxel>::SetABTrim);
}
// VoxFilterAlgorithmBilateral
{
auto cls = py::class_<VoxFilterAlgorithmBilateral<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmBilateral");
bind_common_filter(cls);
cls.def("SetIntensitySigma", &VoxFilterAlgorithmBilateral<Voxel>::SetIntensitySigma);
}
// VoxFilterAlgorithmBilateralTrim
{
auto cls = py::class_<VoxFilterAlgorithmBilateralTrim<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmBilateralTrim");
bind_common_filter(cls);
cls.def("SetIntensitySigma", &VoxFilterAlgorithmBilateralTrim<Voxel>::SetIntensitySigma);
cls.def("SetABTrim", &VoxFilterAlgorithmBilateralTrim<Voxel>::SetABTrim);
}
// VoxFilterAlgorithmThreshold
{
auto cls = py::class_<VoxFilterAlgorithmThreshold<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmThreshold");
bind_common_filter(cls);
cls.def("SetThreshold", &VoxFilterAlgorithmThreshold<Voxel>::SetThreshold);
}
// VoxFilterAlgorithmMedian
{
auto cls = py::class_<VoxFilterAlgorithmMedian<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmMedian");
bind_common_filter(cls);
}
// VoxFilterAlgorithm2ndStat
{
auto cls = py::class_<VoxFilterAlgorithm2ndStat<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithm2ndStat");
bind_common_filter(cls);
}
// VoxFilterAlgorithmCustom (Omit CustomEvaluate since it uses static function ptrs)
{
auto cls = py::class_<VoxFilterAlgorithmCustom<Voxel>, Abstract::VoxImageFilter>(m, "VoxFilterAlgorithmCustom");
bind_common_filter(cls);
}
}

20
src/Python/module.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <pybind11/pybind11.h>
namespace py = pybind11;
void init_core(py::module_ &m);
void init_math(py::module_ &m);
void init_math_filters(py::module_ &m);
PYBIND11_MODULE(uLib_python, m) {
m.doc() = "Python bindings for uLib Core and Math libraries";
// Core submodule
py::module_ core = m.def_submodule("Core", "Core library bindings");
init_core(core);
// Math submodule
py::module_ math = m.def_submodule("Math", "Math library bindings");
init_math(math);
init_math_filters(math);
}

View File

@@ -0,0 +1,33 @@
import sys
import os
import unittest
import time
import uLib
class TestCoreOptions(unittest.TestCase):
def test_options(self):
opt = uLib.Core.Options("Test Options")
# Test basic config file parsing
with open("test_configuration.ini", "w") as f:
f.write("[Section]\n")
opt.parse_config_file("test_configuration.ini")
os.remove("test_configuration.ini")
class TestCoreObject(unittest.TestCase):
def test_object(self):
obj = uLib.Core.Object()
self.assertIsNotNone(obj)
class TestCoreTimer(unittest.TestCase):
def test_timer(self):
timer = uLib.Core.Timer()
timer.Start()
time.sleep(0.1)
val = timer.StopWatch()
self.assertGreater(val, 0.09)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,151 @@
import unittest
import numpy as np
import os
import sys
# Ensure PYTHONPATH is correct if run from root
sys.path.append(os.path.join(os.getcwd(), 'src', 'Python'))
import uLib
class TestMathFilters(unittest.TestCase):
def test_filter_creation(self):
# 1. Linear Filter
dims = [10, 10, 10]
v_dims = uLib.Math.Vector3i(dims)
linear_filter = uLib.Math.VoxFilterAlgorithmLinear(v_dims)
self.assertIsNotNone(linear_filter)
# 2. ABTrim Filter
abtrim_filter = uLib.Math.VoxFilterAlgorithmAbtrim(v_dims)
self.assertIsNotNone(abtrim_filter)
abtrim_filter.SetABTrim(1, 1)
# 3. Bilateral Filter
bilat_filter = uLib.Math.VoxFilterAlgorithmBilateral(v_dims)
self.assertIsNotNone(bilat_filter)
bilat_filter.SetIntensitySigma(0.5)
# 4. Threshold Filter
threshold_filter = uLib.Math.VoxFilterAlgorithmThreshold(v_dims)
self.assertIsNotNone(threshold_filter)
threshold_filter.SetThreshold(0.5)
# 5. Median Filter
median_filter = uLib.Math.VoxFilterAlgorithmMedian(v_dims)
self.assertIsNotNone(median_filter)
def test_filter_run(self):
# Create image
dims = [10, 10, 10]
vox_img = uLib.Math.VoxImage(dims)
for i in range(10*10*10):
vox_img.SetValue(i, 1.0)
# Linear filter
linear_filter = uLib.Math.VoxFilterAlgorithmLinear([3, 3, 3])
linear_filter.SetImage(vox_img)
# Set kernel (simple 3x3x3 all ones)
# Weights are usually normalized in linear filter logic?
# Let's just test it runs.
linear_filter.SetKernelNumericXZY([1.0] * 27)
# Run filter
linear_filter.Run()
# Value should be 1.0 (mean of all 1.0 is 1.0)
self.assertAlmostEqual(vox_img.GetValue(0), 1.0)
def test_filter_run_abtrim(self):
# Create image
dims = [10, 10, 10]
vox_img = uLib.Math.VoxImage(dims)
for i in range(10*10*10):
vox_img.SetValue(i, 1.0)
# ABTrim filter
abtrim_filter = uLib.Math.VoxFilterAlgorithmAbtrim([3, 3, 3])
abtrim_filter.SetImage(vox_img)
# Set kernel (simple 3x3x3 all ones)
# Weights are usually normalized in linear filter logic?
# Let's just test it runs.
abtrim_filter.SetKernelNumericXZY([1.0] * 27)
# Run filter
abtrim_filter.Run()
# Value should be 1.0 (mean of all 1.0 is 1.0)
self.assertAlmostEqual(vox_img.GetValue(0), 1.0)
def test_filter_run_bilateral(self):
# Create image
dims = [10, 10, 10]
vox_img = uLib.Math.VoxImage(dims)
for i in range(10*10*10):
vox_img.SetValue(i, 1.0)
# Bilateral filter
bilat_filter = uLib.Math.VoxFilterAlgorithmBilateral([3, 3, 3])
bilat_filter.SetImage(vox_img)
# Set kernel (simple 3x3x3 all ones)
# Weights are usually normalized in linear filter logic?
# Let's just test it runs.
bilat_filter.SetKernelNumericXZY([1.0] * 27)
# Run filter
bilat_filter.Run()
# Value should be 1.0 (mean of all 1.0 is 1.0)
self.assertAlmostEqual(vox_img.GetValue(0), 1.0)
def test_filter_run_threshold(self):
# Create image
dims = [10, 10, 10]
vox_img = uLib.Math.VoxImage(dims)
for i in range(10*10*10):
vox_img.SetValue(i, 1.0)
# Threshold filter
threshold_filter = uLib.Math.VoxFilterAlgorithmThreshold([3, 3, 3])
threshold_filter.SetImage(vox_img)
# Set kernel (simple 3x3x3 all ones)
# Weights are usually normalized in linear filter logic?
# Let's just test it runs.
threshold_filter.SetKernelNumericXZY([1.0] * 27)
# Run filter
threshold_filter.Run()
# Value should be 1.0 (mean of all 1.0 is 1.0)
self.assertAlmostEqual(vox_img.GetValue(0), 1.0)
def test_filter_run_median(self):
# Create image
dims = [10, 10, 10]
vox_img = uLib.Math.VoxImage(dims)
for i in range(10*10*10):
vox_img.SetValue(i, 1.0)
# Median filter
median_filter = uLib.Math.VoxFilterAlgorithmMedian([3, 3, 3])
median_filter.SetImage(vox_img)
# Set kernel (simple 3x3x3 all ones)
# Weights are usually normalized in linear filter logic?
# Let's just test it runs.
median_filter.SetKernelNumericXZY([1.0] * 27)
# Run filter
median_filter.Run()
# Value should be 1.0 (mean of all 1.0 is 1.0)
self.assertAlmostEqual(vox_img.GetValue(0), 1.0)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,189 @@
import sys
import os
import unittest
import numpy as np
import uLib
def vector4f0(v, target):
diff = np.array(v) - np.array(target)
diff[3] = 0 # ignoring w
return np.all(np.abs(diff) < 0.001)
class TestMathMatrix(unittest.TestCase):
def test_matrix(self):
def check_1234(m2f):
self.assertEqual(m2f[0, 0], 1)
self.assertEqual(m2f[0, 1], 2)
self.assertEqual(m2f[1, 0], 3)
self.assertEqual(m2f[1, 1], 4)
m2f = uLib.Math.Matrix2f()
m2f[0, 0] = 1
m2f[0, 1] = 2
m2f[1, 0] = 3
m2f[1, 1] = 4
check_1234(m2f)
m2f = uLib.Math.Matrix2f([1, 2, 3, 4])
check_1234(m2f)
# m2f = uLib.Math.Matrix2f([[1, 2], [3, 4]])
# check_1234(m2f)
m2f = uLib.Math.Matrix2f(np.array([[1, 2], [3, 4]]))
check_1234(m2f)
def test_vector2(self):
v2f = uLib.Math.Vector2f()
v2f[0] = 1
v2f[1] = 2
self.assertEqual(v2f[0], 1)
self.assertEqual(v2f[1], 2)
v2f = uLib.Math.Vector2f([1, 2])
self.assertEqual(v2f[0], 1)
self.assertEqual(v2f[1], 2)
v2f = uLib.Math.Vector2f(np.array([1, 2]))
self.assertEqual(v2f[0], 1)
self.assertEqual(v2f[1], 2)
def test_vector3(self):
v3f = uLib.Math.Vector3f()
v3f[0] = 1
v3f[1] = 2
v3f[2] = 3
self.assertEqual(v3f[0], 1)
self.assertEqual(v3f[1], 2)
self.assertEqual(v3f[2], 3)
v3f = uLib.Math.Vector3f([1, 2, 3])
self.assertEqual(v3f[0], 1)
self.assertEqual(v3f[1], 2)
self.assertEqual(v3f[2], 3)
v3f = uLib.Math.Vector3f(np.array([1, 2, 3]))
self.assertEqual(v3f[0], 1)
self.assertEqual(v3f[1], 2)
self.assertEqual(v3f[2], 3)
class TestMathGeometry(unittest.TestCase):
def test_geometry(self):
Geo = uLib.Math.Geometry()
Geo.SetPosition([1, 1, 1])
pt = Geo.GetLocalPoint([2, 3, 2, 1])
wp = Geo.GetWorldPoint(pt)
self.assertTrue(vector4f0(wp, [2, 3, 2, 1]))
Geo.Scale([2, 2, 2])
wp = Geo.GetWorldPoint([1, 1, 1, 1])
self.assertTrue(vector4f0(wp, [3, 3, 3, 1]))
class TestMathContainerBox(unittest.TestCase):
def test_container_box_local(self):
Cnt = uLib.Math.ContainerBox()
Cnt.SetOrigin([-1, -1, -1])
Cnt.SetSize([2, 2, 2])
size = Cnt.GetSize()
self.assertTrue(np.allclose(size, [2, 2, 2]))
def test_container_box_global(self):
Box = uLib.Math.ContainerBox()
Box.SetPosition([1, 1, 1])
Box.SetSize([2, 2, 2])
pt = Box.GetLocalPoint([2, 3, 2, 1])
wp = Box.GetWorldPoint(pt)
self.assertTrue(vector4f0(wp, [2, 3, 2, 1]))
class TestMathStructuredGrid(unittest.TestCase):
def test_structured_grid(self):
grid = uLib.Math.StructuredGrid([10, 10, 10])
grid.SetSpacing([1, 1, 1])
spacing = grid.GetSpacing()
self.assertTrue(np.allclose(spacing, [1, 1, 1]))
class TestMathAccumulator(unittest.TestCase):
def test_accumulator_mean(self):
acc = uLib.Math.Accumulator_Mean_f()
acc(10.0)
acc(20.0)
self.assertAlmostEqual(acc(), 15.0)
class TestMathNewTypes(unittest.TestCase):
def test_eigen_vectors(self):
v1f = uLib.Math.Vector1f()
v3d = uLib.Math.Vector3d()
m4f = uLib.Math.Matrix4f()
self.assertIsNotNone(v1f)
self.assertIsNotNone(v3d)
self.assertIsNotNone(m4f)
def test_ulib_vectors(self):
vi = uLib.Math.Vector_i()
vi.append(1)
vi.append(2)
self.assertEqual(len(vi), 2)
self.assertEqual(vi[0], 1)
self.assertEqual(vi[1], 2)
vf = uLib.Math.Vector_f()
vf.append(1.5)
self.assertAlmostEqual(vf[0], 1.5)
def test_homogeneous(self):
p = uLib.Math.HPoint3f(1.0, 2.0, 3.0)
v = uLib.Math.HVector3f(0.0, 1.0, 0.0)
self.assertIsNotNone(p)
self.assertIsNotNone(v)
def test_vox_image(self):
img = uLib.Math.VoxImage([2, 2, 2])
self.assertEqual(img.GetDims()[0], 2)
img.SetValue([0, 0, 0], 10.5)
# Note: GetValue returns float, and there might be internal scaling (1.E-6 observed in code)
# Actually in VoxImage.h: GetValue(id) returns At(id).Value
# SetValue(id, value) sets At(id).Value = value
self.assertAlmostEqual(img.GetValue([0, 0, 0]), 10.5)
class TestMathVoxRaytracer(unittest.TestCase):
def test_raytracer(self):
grid = uLib.Math.StructuredGrid([10, 10, 10])
grid.SetSpacing([1, 1, 1])
grid.SetOrigin([0, 0, 0])
rt = uLib.Math.VoxRaytracer(grid)
self.assertIsNotNone(rt)
# Test TraceBetweenPoints
p1 = np.array([0.5, 0.5, -1.0, 1.0], dtype=np.float32)
p2 = np.array([0.5, 0.5, 11.0, 1.0], dtype=np.float32)
data = rt.TraceBetweenPoints(p1, p2)
self.assertGreater(data.Count(), 0)
self.assertAlmostEqual(data.TotalLength(), 10.0)
# Check elements
elements = data.Data()
for i in range(data.Count()):
self.assertGreaterEqual(elements[i].vox_id, 0)
self.assertGreater(elements[i].L, 0)
def test_ray_data(self):
data = uLib.Math.VoxRaytracerRayData()
data.SetCount(10)
data.SetTotalLength(5.5)
self.assertEqual(data.Count(), 10)
self.assertAlmostEqual(data.TotalLength(), 5.5)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,46 @@
import sys
import os
import uLib
def test_core():
print("Testing Core module...")
obj = uLib.Core.Object()
print("Core Object created:", obj)
timer = uLib.Core.Timer()
timer.Start()
print("Core Timer started")
options = uLib.Core.Options("Test Options")
print("Core Options created:", options)
def test_math():
print("Testing Math module...")
# Test AffineTransform
transform = uLib.Math.AffineTransform()
print("AffineTransform created")
# Test Geometry
geom = uLib.Math.Geometry()
print("Geometry created")
# Test StructuredData
data = uLib.Math.StructuredData([10, 10, 10])
print("StructuredData created with dims:", data.GetDims())
# Test Structured2DGrid
grid2d = uLib.Math.Structured2DGrid()
grid2d.SetDims([100, 100])
print("Structured2DGrid created with dims:", grid2d.GetDims())
# Test TriangleMesh
mesh = uLib.Math.TriangleMesh()
print("TriangleMesh created")
print("All tests passed successfully!")
if __name__ == "__main__":
test_core()
test_math()

View File

@@ -0,0 +1,7 @@
try:
from .uLib_python import Core, Math
except ImportError:
# Handle cases where the binary extension is not yet built
pass
__all__ = ["Core", "Math"]

View File

@@ -1,30 +1,30 @@
set(HEADERS TestTObject.h
RootMathDense.h
set(HEADERS RootMathDense.h
RootMuonScatter.h
RootHitRaw.h
muBlastHit.h
muBlastMCTrack.h
muCastorMCTrack.h
muCastorHit.h
muCastorInfo.h)
muCastorInfo.h
muCastorSkinHit.h
muCastorPrimaryVertex.h
muCastorMuDetDIGI.h
SkinDetectorWriter.h)
set(DICTIONARY_HEADERS TestTObject.h
RootMathDense.h
RootMuonScatter.h
RootHitRaw.h
muBlastHit.h
muBlastMCTrack.h
muCastorMCTrack.h
muCastorHit.h
muCastorInfo.h)
set(SOURCES TestTObject.cpp
RootMuonScatter.cpp
muBlastHit.cpp
muBlastMCTrack.cpp
set(SOURCES ${HEADERS} RootMuonScatter.cpp
muCastorMCTrack.cpp
muCastorHit.cpp
muCastorInfo.cpp)
muCastorInfo.cpp
muCastorSkinHit.cpp
muCastorPrimaryVertex.cpp
muCastorMuDetDIGI.cpp
SkinDetectorWriter.cpp)
set(DICTIONARY_HEADERS muCastorMCTrack.h
muCastorHit.h
muCastorInfo.h
muCastorSkinHit.h
muCastorPrimaryVertex.h
muCastorMuDetDIGI.h
SkinDetectorWriter.h)
set(LIBRARIES ${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Math)
@@ -42,7 +42,7 @@ list(APPEND SOURCES ${rDictName}.cxx)
set(R_ARTIFACTS ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}_rdict.pcm
${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}.rootmap)
install(FILES ${R_ARTIFACTS}
DESTINATION ${PACKAGE_INSTALL_LIB_DIR})
DESTINATION ${INSTALL_LIB_DIR})
set(libname ${PACKAGE_LIBPREFIX}Root)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
@@ -51,14 +51,18 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Root PARENT_SCOPE)
add_library(${libname} SHARED ${SOURCES})
set_target_properties(${libname} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION})
SOVERSION ${PROJECT_SOVERSION}
CXX_STANDARD 17)
target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Root)
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
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
#define U_ROOT_LINKDEF_H
@@ -35,50 +33,21 @@
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ class TestTObject+;
using namespace ROOT::Mutom;
#pragma link C++ class ROOT::Math::Cartesian2D<int>+;
#pragma link C++ class ROOT::Math::Cartesian2D<float>+;
#pragma link C++ class ROOT::Math::Cartesian2D<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 HitRaw+;
#pragma link C++ function HitRaw::Chm() const;
#pragma link C++ function HitRaw::Rob() const;
#pragma link C++ function HitRaw::Tdc() const;
#pragma link C++ function HitRaw::Ch() const;
#pragma link C++ class muBlastMCTrack+;
#pragma link C++ class muBlastHit+;
#pragma link C++ class muCastorMCTrack + ;
#pragma link C++ class muCastorHit + ;
#pragma link C++ class muCastorInfo + ;
#pragma link C++ class muCastorSkinHit + ;
#pragma link C++ class muCastorPrimaryVertex + ;
#pragma link C++ class muCastorMuDetDIGI + ;
#pragma link C++ class SkinDetectorWriter + ;
#endif // __CINT__

View File

@@ -0,0 +1,47 @@
#include "SkinDetectorWriter.h"
#include "muCastorSkinHit.h"
#include "TVector3.h"
SkinDetectorWriter::SkinDetectorWriter(string filename) :
t_file(nullptr),
t_tree(nullptr),
t_buffer(nullptr),
i_status(0)
{
t_file = new TFile(filename.c_str(), "RECREATE");
t_tree = new TTree("muCastorMC", "muCastorMC");
t_buffer = new TClonesArray("muCastorSkinHit");
t_tree->Branch("CastorSkinHits", "TClonesArray", t_buffer, 32000, 99);
if (t_file->IsZombie()) i_status = 1;
}
SkinDetectorWriter::~SkinDetectorWriter()
{}
void SkinDetectorWriter::add(int detID, float p_x, float p_y, float p_z,
float m_x, float m_y, float m_z)
{
TClonesArray& ref = *t_buffer;
int size = ref.GetEntriesFast();
muCastorSkinHit* new_hit = new(ref[size]) muCastorSkinHit();
new_hit->SetDetID(detID);
new_hit->SetPdgCode(13);
new_hit->SetMotherID(-1);
new_hit->SetPos (TVector3(p_x, p_y, p_z));
new_hit->SetMom (TVector3(m_x, m_y, m_z));
}
void SkinDetectorWriter::write()
{
if (t_tree->Fill() < 0) i_status = 2;
t_buffer->Delete(); // or t_buffer->Clear() ??
}
void SkinDetectorWriter::close()
{
if (t_tree->Write() == 0) i_status = 3;
t_file->Close();
}

View File

@@ -0,0 +1,32 @@
#ifndef SkinDetectorWriter_h
#define SkinDetectorWriter_h
#include <string>
#include "TFile.h"
#include "TTree.h"
#include "TClonesArray.h"
using std::string;
class SkinDetectorWriter
{
public:
SkinDetectorWriter(string filename);
virtual ~SkinDetectorWriter();
void add(int detID, float p_x, float p_y, float p_z, float m_x, float m_y, float m_z);
int status() { return i_status; }
void write();
void close();
private:
TFile* t_file;
TTree* t_tree;
TClonesArray* t_buffer;
int i_status;
};
#endif //SkinDetectorWriter_h

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

@@ -0,0 +1,43 @@
//----------------------------------------------------------
// Class : CastorSkinHit
// Date: October 2020
// Author: Germano Bonomi germano.bonomi@unibs.it
//----------------------------------------------------------
#include <iostream>
#include "muCastorSkinHit.h"
/// \cond CLASSIMP
ClassImp(muCastorSkinHit)
/// \endcond
using namespace std;
//_____________________________________________________________________________
muCastorSkinHit::muCastorSkinHit() :
fDetID(-1),
fPdgCode(-1),
fMotherID(-1),
fMomX(0.),
fMomY(0.),
fMomZ(0.),
fPosX(0.),
fPosY(0.),
fPosZ(0.)
{}
//_____________________________________________________________________________
muCastorSkinHit::~muCastorSkinHit()
{}
//_____________________________________________________________________________
void muCastorSkinHit::Print(const Option_t* /*opt*/) const
{
cout << " detID: " << fDetID
<< " position (cm): ("
<< fPosX << ", " << fPosY << ", " << fPosZ << ")"
<< " momentum (MeV/c): ("
<< fMomX << ", " << fMomY << ", " << fMomZ << ")"
<< endl;
}

View File

@@ -0,0 +1,52 @@
//----------------------------------------------------------
// Class : CastorSkinHit
// Date: October 2020
// Author: Germano Bonomi germano.bonomi@unibs.it
//----------------------------------------------------------
#ifndef muCastor_SKINHIT_H
#define muCastor_SKINHIT_H
#include <TObject.h>
#include <TVector3.h>
class muCastorSkinHit : public TObject
{
public:
muCastorSkinHit();
virtual ~muCastorSkinHit();
// methods
virtual void Print(const Option_t* option = "") const;
// set methods
void SetDetID(Int_t id) { fDetID = id; };
void SetPdgCode(Int_t pdg) { fPdgCode = pdg; };
void SetMotherID(Int_t mid) { fMotherID = mid; };
void SetMom(TVector3 xyz) { fMomX = xyz.X(); fMomY = xyz.Y(); fMomZ = xyz.Z(); };
void SetPos(TVector3 xyz) { fPosX = xyz.X(); fPosY = xyz.Y(); fPosZ = xyz.Z(); };
Int_t GetDetID() { return fDetID; }
Int_t GetPdgCode() { return fPdgCode; }
Int_t GetMotherID() { return fMotherID; }
TVector3 GetMom() { return TVector3(fMomX, fMomY, fMomZ); }
TVector3 GetPos() { return TVector3(fPosX, fPosY, fPosZ); }
private:
Int_t fDetID; // Detector module ID
Int_t fPdgCode; // Particle PDG Code
Int_t fMotherID; // Particle mother ID (-1 = primary, 0 = secondary, etc..)
Double_t fMomX; // Track momentum when releasing the hit (X)
Double_t fMomY; // Track momentum when releasing the hit (Y)
Double_t fMomZ; // Track momentum when releasing the hit (Z)
Double_t fPosX; // Hit coordinates (at the entrance of the detector) (X)
Double_t fPosY; // Hit coordinates (at the entrance of the detector) (Y)
Double_t fPosZ; // Hit coordinates (at the entrance of the detector) (Z)
ClassDef(muCastorSkinHit,1) //muCastorSkinHit
};
#endif //muCastort_SKINHIT_H

View File

@@ -1,16 +1,15 @@
# TESTS
set( TESTS
RootDebugTest
muBlastMCTrackTest
# RootDebugTest
# muBlastMCTrackTest
)
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
${PACKAGE_LIBPREFIX}Root
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
Boost::serialization
Boost::program_options
${ROOT_LIBRARIES}
)
uLib_add_tests(${uLib-module})
uLib_add_tests(Root)

View File

@@ -14,11 +14,16 @@ set(SOURCES uLibVtkInterface.cxx
vtkVoxRaytracerRepresentation.cpp
vtkVoxImage.cpp)
set(LIBRARIES ${Eigen_LIBRARY}
set(LIBRARIES Eigen3::Eigen
${ROOT_LIBRARIES}
${VTK_LIBRARIES}
${PACKAGE_LIBPREFIX}Math)
if(USE_CUDA)
find_package(CUDAToolkit REQUIRED)
list(APPEND LIBRARIES CUDA::cudart)
endif()
set(libname ${PACKAGE_LIBPREFIX}Vtk)
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Vtk PARENT_SCOPE)
@@ -31,8 +36,12 @@ target_link_libraries(${libname} ${LIBRARIES})
install(TARGETS ${libname}
EXPORT "${PROJECT_NAME}Targets"
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
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

@@ -5,7 +5,7 @@ set( TESTS
vtkMuonScatter
vtkStructuredGridTest
vtkVoxRaytracerTest
vtkVoxImageTest
# vtkVoxImageTest
# vtkTriangleMeshTest
)
@@ -14,5 +14,5 @@ set(LIBRARIES
${PACKAGE_LIBPREFIX}Vtk
)
include(${VTK_USE_FILE})
uLib_add_tests(${uLib-module})
# include(${VTK_USE_FILE})
uLib_add_tests(Vtk)

View File

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

View File

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

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