mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 07:21:31 +01:00
add version 0.6 - make external build possible
This commit is contained in:
@@ -15,16 +15,16 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "build path for
|
|||||||
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
|
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
|
||||||
|
|
||||||
## Install directories ##
|
## Install directories ##
|
||||||
set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
|
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
|
||||||
set(PACKAGE_INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
|
set(INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
|
||||||
set(PACKAGE_INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
|
set(INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
|
||||||
set(PACKAGE_INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
|
set(INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
|
||||||
if(WIN32 AND NOT CYGWIN)
|
if(WIN32 AND NOT CYGWIN)
|
||||||
set(DEF_INSTALL_CMAKE_DIR CMake)
|
set(DEF_INSTALL_CMAKE_DIR CMake)
|
||||||
else()
|
else()
|
||||||
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
|
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
|
||||||
endif()
|
endif()
|
||||||
set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
|
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
|
||||||
|
|
||||||
# Make relative paths absolute (needed later on)
|
# Make relative paths absolute (needed later on)
|
||||||
foreach(p LIB BIN INC DATA CMAKE)
|
foreach(p LIB BIN INC DATA CMAKE)
|
||||||
|
|||||||
@@ -41,15 +41,15 @@ macro(uLib_add_shared_library name)
|
|||||||
|
|
||||||
install(TARGETS ${mname}
|
install(TARGETS ${mname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
|
||||||
# PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev
|
# PUBLIC_HEADER DESTINATION ${INSTALL_INC_DIR} COMPONENT dev
|
||||||
)
|
)
|
||||||
endif(SOURCES)
|
endif(SOURCES)
|
||||||
|
|
||||||
if(HEADERS)
|
if(HEADERS)
|
||||||
foreach(header ${HEADERS})
|
foreach(header ${HEADERS})
|
||||||
install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name})
|
install(FILES ${header} DESTINATION ${INSTALL_INC_DIR}/${name})
|
||||||
endforeach(header)
|
endforeach(header)
|
||||||
endif(HEADERS)
|
endif(HEADERS)
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ macro(uLib_add_target name)
|
|||||||
|
|
||||||
install(TARGETS ${name}
|
install(TARGETS ${name}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
)
|
)
|
||||||
ENDMACRO(uLib_add_target)
|
ENDMACRO(uLib_add_target)
|
||||||
|
|
||||||
|
|||||||
@@ -33,31 +33,20 @@ message(STATUS "Module path = ${CMAKE_MODULE_PATH}")
|
|||||||
|
|
||||||
## GLOBALS ------------------------------------------------------------------ ##
|
## 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
|
# -- move to GnuInstallDirs
|
||||||
# ref: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
|
# ref: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
set(PACKAGE_INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
|
set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
|
||||||
CACHE PATH "Location of header files (.../include)" )
|
CACHE PATH "Location of header files (.../include)" )
|
||||||
set(PACKAGE_INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR}/${PACKAGE_NAME}
|
set(INSTALL_ETC_DIR ${CMAKE_INSTALL_SYSCONFDIR}/${PACKAGE_NAME}
|
||||||
CACHE PATH "Location of configuration files (.../etc)" )
|
CACHE PATH "Location of configuration files (.../etc)" )
|
||||||
set(PACKAGE_INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR}/${PACKAGE_NAME}
|
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR}/${PACKAGE_NAME}
|
||||||
CACHE PATH "Location of executable files (.../bin)" )
|
CACHE PATH "Location of executable files (.../bin)" )
|
||||||
set(PACKAGE_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}
|
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}
|
||||||
CACHE PATH "Location of library files (.../lib)" )
|
CACHE PATH "Location of library files (.../lib)" )
|
||||||
set(PACKAGE_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
|
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
|
||||||
CACHE PATH "Location of cmake files (.../lib/cmake)" )
|
CACHE PATH "Location of cmake files (.../lib/cmake)" )
|
||||||
set(PACKAGE_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}/${PACKAGE_NAME}
|
set(INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}/${PACKAGE_NAME}
|
||||||
CACHE PATH "Location of data files (.../share)" )
|
CACHE PATH "Location of data files (.../share)" )
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +56,7 @@ set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
|
|||||||
|
|
||||||
# this is used to be exported in build target
|
# this is used to be exported in build target
|
||||||
# ( to compile against build directory instead of install )
|
# ( to compile against build directory instead of install )
|
||||||
set(ULIB_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
|
set(ULIB_SOURCE_DIR ${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
message(STATUS "Setting build type to 'Release' as none was specified.")
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
||||||
@@ -105,7 +94,7 @@ find_package(ROOT CONFIG REQUIRED)
|
|||||||
include(${ROOT_USE_FILE})
|
include(${ROOT_USE_FILE})
|
||||||
|
|
||||||
find_package(VTK REQUIRED)
|
find_package(VTK REQUIRED)
|
||||||
include(${VTK_USE_FILE})
|
# include(${VTK_USE_FILE})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -172,7 +161,7 @@ configure_file("${PROJECT_SOURCE_DIR}/CMakeConfig.in.h"
|
|||||||
"${PROJECT_BINARY_DIR}/config.h")
|
"${PROJECT_BINARY_DIR}/config.h")
|
||||||
|
|
||||||
install(FILES "${PROJECT_BINARY_DIR}/config.h"
|
install(FILES "${PROJECT_BINARY_DIR}/config.h"
|
||||||
DESTINATION ${PACKAGE_INSTALL_INC_DIR})
|
DESTINATION ${INSTALL_INC_DIR})
|
||||||
|
|
||||||
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
|
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
|
||||||
|
|
||||||
@@ -217,8 +206,8 @@ add_subdirectory(${SRC_DIR}/Vtk)
|
|||||||
|
|
||||||
|
|
||||||
# Create the FooBarConfig.cmake and FooBarConfigVersion files
|
# Create the FooBarConfig.cmake and FooBarConfigVersion files
|
||||||
# file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
|
# file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
|
||||||
# "${PACKAGE_INSTALL_INC_DIR}")
|
# "${INSTALL_INC_DIR}")
|
||||||
|
|
||||||
# ... for the build tree
|
# ... for the build tree
|
||||||
#set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
|
#set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
|
||||||
@@ -237,21 +226,20 @@ configure_file(uLibConfigVersion.cmake.in
|
|||||||
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
|
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
|
||||||
|
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
|
|
||||||
# from CMake 3.x configure file shall be created using a dedicated function
|
# from CMake 3.x configure file shall be created using a dedicated function
|
||||||
# see: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html
|
# see: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html
|
||||||
#
|
#
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
configure_package_config_file(uLibConfig.cmake.in
|
configure_package_config_file(uLibConfig.cmake.in
|
||||||
"${PROJECT_BINARY_DIR}/uLibConfig.cmake"
|
"${PROJECT_BINARY_DIR}/uLibConfig.cmake"
|
||||||
INSTALL_DESTINATION ${PACKAGE_INSTALL_CMAKE_DIR}
|
INSTALL_DESTINATION ${INSTALL_CMAKE_DIR}
|
||||||
PATH_VARS
|
PATH_VARS
|
||||||
PACKAGE_INSTALL_LIB_DIR
|
INSTALL_LIB_DIR
|
||||||
PACKAGE_INSTALL_INC_DIR
|
INSTALL_INC_DIR
|
||||||
PACKAGE_INSTALL_BIN_DIR
|
INSTALL_BIN_DIR
|
||||||
PACKAGE_INSTALL_CMAKE_DIR
|
INSTALL_CMAKE_DIR
|
||||||
PACKAGE_INSTALL_ETC_DIR
|
INSTALL_ETC_DIR
|
||||||
PACKAGE_INSTALL_DATA_DIR
|
INSTALL_DATA_DIR
|
||||||
ULIB_SOURCE_DIR
|
ULIB_SOURCE_DIR
|
||||||
ULIB_SHARED_LIBRARIES
|
ULIB_SHARED_LIBRARIES
|
||||||
# NO_SET_AND_CHECK_MACRO
|
# NO_SET_AND_CHECK_MACRO
|
||||||
@@ -260,7 +248,7 @@ configure_package_config_file(uLibConfig.cmake.in
|
|||||||
|
|
||||||
install(FILES "${PROJECT_BINARY_DIR}/uLibConfig.cmake"
|
install(FILES "${PROJECT_BINARY_DIR}/uLibConfig.cmake"
|
||||||
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake"
|
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake"
|
||||||
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}"
|
DESTINATION "${INSTALL_CMAKE_DIR}"
|
||||||
COMPONENT dev)
|
COMPONENT dev)
|
||||||
|
|
||||||
|
|
||||||
@@ -275,6 +263,6 @@ export (TARGETS ${ULIB_SHARED_LIBRARIES}
|
|||||||
# Install the export set for use with the install-tree
|
# Install the export set for use with the install-tree
|
||||||
install(EXPORT "uLibTargets"
|
install(EXPORT "uLibTargets"
|
||||||
FILE "uLibTargets.cmake"
|
FILE "uLibTargets.cmake"
|
||||||
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}"
|
DESTINATION "${INSTALL_CMAKE_DIR}"
|
||||||
COMPONENT dev)
|
COMPONENT dev)
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ target_link_libraries(${libname} ${LIBRARIES})
|
|||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Core)
|
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
|
|
||||||
|
|
||||||
//class boost::program_options::error_with_option_name;
|
//class boost::program_options::error_with_option_name;
|
||||||
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
|
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
|
||||||
@@ -74,6 +77,23 @@ void Options::parse_config_file(const char *fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Options::save_config_file(const char *fname) {
|
||||||
|
std::ofstream os;
|
||||||
|
os.open(fname);
|
||||||
|
|
||||||
|
using boost::property_tree::ptree;
|
||||||
|
|
||||||
|
ptree root;
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << m_configuration << "\n";
|
||||||
|
std::cout << m_global << "\n";
|
||||||
|
|
||||||
|
write_ini( std::cout, root );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Options::count(const char *str) const
|
bool Options::count(const char *str) const
|
||||||
{
|
{
|
||||||
return (m_vm.count(str));
|
return (m_vm.count(str));
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ public:
|
|||||||
|
|
||||||
void parse_config_file(const char *fname);
|
void parse_config_file(const char *fname);
|
||||||
|
|
||||||
|
void save_config_file(const char *fname);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
|
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
|
||||||
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
|
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
|
|||||||
|
|
||||||
|
|
||||||
install(FILES ${HEADERS}
|
install(FILES ${HEADERS}
|
||||||
DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Detectors)
|
DESTINATION ${INSTALL_INC_DIR}/Detectors)
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ target_link_libraries(${libname} ${LIBRARIES})
|
|||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Math)
|
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math)
|
||||||
|
|
||||||
# TESTING
|
# TESTING
|
||||||
# include(uLibTargetMacros)
|
# include(uLibTargetMacros)
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ typedef Eigen::Vector4f Vector4f;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Vector String interaction ///////////////////////////////////////////////////
|
// Vector String interaction ///////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -32,9 +32,11 @@
|
|||||||
|
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkImageData.h>
|
#include <vtkImageData.h>
|
||||||
|
#include <vtkXMLImageDataReader.h>
|
||||||
#include <vtkXMLImageDataWriter.h>
|
#include <vtkXMLImageDataWriter.h>
|
||||||
#include <vtkStringArray.h>
|
#include <vtkStringArray.h>
|
||||||
|
#include <vtkInformation.h>
|
||||||
|
#include <vtkInformationStringKey.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
@@ -116,14 +118,23 @@ void Abstract::VoxImage::ExportToVti (const char *file, bool density_type, bool
|
|||||||
scalar[i] = static_cast<float>(voxels->GetValue(i) * norm);
|
scalar[i] = static_cast<float>(voxels->GetValue(i) * norm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Create a custom string key
|
// Create a custom string key
|
||||||
// static vtkInformationStringKey* ConfigNote =
|
static vtkInformationStringKey* ConfigNote =
|
||||||
// vtkInformationStringKey::MakeKey("ConfigNote", "MyNotes");
|
vtkInformationStringKey::MakeKey("cmt.config", "Config");
|
||||||
|
|
||||||
// // Attach metadata
|
// Attach metadata
|
||||||
// image->GetInformation()->Set(ConfigNote, "This image was generated with method X, threshold=0.5");
|
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();
|
vtkSmartPointer<vtkXMLImageDataWriter> writer = vtkSmartPointer<vtkXMLImageDataWriter>::New();
|
||||||
writer->SetFileName(file);
|
writer->SetFileName(file);
|
||||||
writer->SetInputData(image);
|
writer->SetInputData(image);
|
||||||
@@ -135,11 +146,40 @@ void Abstract::VoxImage::ExportToVti (const char *file, bool density_type, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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->SetOrigin(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());
|
||||||
|
for (size_t i = 0; i < npoints; i++) {
|
||||||
|
voxels->SetValue(i, scalar[i] / norm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int Abstract::VoxImage::ImportFromVtk(const char *file, bool density_type)
|
||||||
int Abstract::VoxImage::ImportFromVtk(const char *file)
|
|
||||||
{
|
{
|
||||||
FILE * vtk_file = fopen(file, "r");
|
FILE * vtk_file = fopen(file, "r");
|
||||||
if (!vtk_file) return false;
|
if (!vtk_file) return false;
|
||||||
@@ -171,14 +211,18 @@ int Abstract::VoxImage::ImportFromVtk(const char *file)
|
|||||||
this->SetSpacing(Vector3f(sx,sy,sz));
|
this->SetSpacing(Vector3f(sx,sy,sz));
|
||||||
this->SetPosition(Vector3f(ox,oy,oz));
|
this->SetPosition(Vector3f(ox,oy,oz));
|
||||||
|
|
||||||
|
float norm;
|
||||||
|
if (density_type) {
|
||||||
|
norm = 1;
|
||||||
|
} else norm = 1.E6;
|
||||||
|
|
||||||
for (int k = 0; k < dz; ++k) {
|
for (int k = 0; k < dz; ++k) {
|
||||||
for (int j = 0; j < dy; ++j) {
|
for (int j = 0; j < dy; ++j) {
|
||||||
for (int i = 0; i < dx; ++i) {
|
for (int i = 0; i < dx; ++i) {
|
||||||
Vector3i idx(i, j, k);
|
Vector3i idx(i, j, k);
|
||||||
float tmp_val;
|
float tmp_val;
|
||||||
fscanf(vtk_file, "%f", &tmp_val);
|
fscanf(vtk_file, "%f", &tmp_val);
|
||||||
//this->SetValue(idx,fabs(tmp_val)*1E-6);
|
this->SetValue(idx,tmp_val / norm);
|
||||||
this->SetValue(idx,tmp_val*1E-6);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,18 @@ public:
|
|||||||
virtual void SetDims(const Vector3i &size) = 0;
|
virtual void SetDims(const Vector3i &size) = 0;
|
||||||
|
|
||||||
void ExportToVtk(const char *file, bool density_type = 0);
|
void ExportToVtk(const char *file, bool density_type = 0);
|
||||||
|
|
||||||
|
// use this function to export to VTK binary format
|
||||||
void ExportToVti (const char *file, bool density_type = 0, bool compressed = 0);
|
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);
|
void ExportToVtkXml(const char *file, bool density_type = 0);
|
||||||
int ImportFromVtk(const char *file);
|
|
||||||
|
int ImportFromVtk(const char *file, bool density_type = 0);
|
||||||
|
|
||||||
|
int ImportFromVti(const char *file, bool density_type = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ list(APPEND SOURCES ${rDictName}.cxx)
|
|||||||
set(R_ARTIFACTS ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}_rdict.pcm
|
set(R_ARTIFACTS ${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}_rdict.pcm
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}.rootmap)
|
${CMAKE_CURRENT_BINARY_DIR}/lib${rDictName}.rootmap)
|
||||||
install(FILES ${R_ARTIFACTS}
|
install(FILES ${R_ARTIFACTS}
|
||||||
DESTINATION ${PACKAGE_INSTALL_LIB_DIR})
|
DESTINATION ${INSTALL_LIB_DIR})
|
||||||
|
|
||||||
set(libname ${PACKAGE_LIBPREFIX}Root)
|
set(libname ${PACKAGE_LIBPREFIX}Root)
|
||||||
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
|
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
|
||||||
@@ -57,9 +57,9 @@ target_link_libraries(${libname} ${LIBRARIES})
|
|||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Root)
|
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ target_link_libraries(${libname} ${LIBRARIES})
|
|||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
install(FILES ${HEADERS} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Vtk)
|
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk)
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ set(ULIB_VERSION @PROJECT_VERSION@)
|
|||||||
|
|
||||||
@PACKAGE_INIT@
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
# Definisce le directory per l'inclusione dei file header
|
# Defines the include directories for the header files
|
||||||
# PACKAGE_INCLUDE_INSTALL_DIR è sostituito da configure_package_config_file
|
# PACKAGE_INCLUDE_INSTALL_DIR is replaced by configure_package_config_file
|
||||||
# con il percorso corretto per l'installazione.
|
# with the correct path for the installation.
|
||||||
set(ULIB_INCLUDE_DIRS "${PACKAGE_INCLUDE_INSTALL_DIR}")
|
set(ULIB_INCLUDE_DIRS "${PACKAGE_INCLUDE_INSTALL_DIR}")
|
||||||
|
|
||||||
get_filename_component(ULIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
get_filename_component(ULIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||||
@@ -29,38 +29,64 @@ set(uLib_INSTALL_TARGETS_FILE
|
|||||||
# We use a logic based on the presence of the build target file
|
# We use a logic based on the presence of the build target file
|
||||||
# to determine if we are in a local build.
|
# to determine if we are in a local build.
|
||||||
if(EXISTS "${uLib_BUILD_TARGETS_FILE}")
|
if(EXISTS "${uLib_BUILD_TARGETS_FILE}")
|
||||||
message(WARNING " ++ Using uLib build targets")
|
message(STATUS " ++ Using uLib build targets")
|
||||||
|
|
||||||
include("${uLib_BUILD_TARGETS_FILE}")
|
include("${uLib_BUILD_TARGETS_FILE}")
|
||||||
set_and_check(ULIB_INCLUDE_DIRS "@ULIB_SOURCE_DIR@")
|
set_and_check(ULIB_INCLUDE_DIRS "@ULIB_SOURCE_DIR@/src")
|
||||||
set_and_check(ULIB_LIBRARY_DIRS "${ULIB_CMAKE_DIR}")
|
set_and_check(ULIB_LIBRARY_DIRS "${ULIB_CMAKE_DIR}")
|
||||||
|
set(ULIB_BUILD_DIR ${ULIB_CMAKE_DIR})
|
||||||
|
|
||||||
|
# Target that builds uLib inside its build directory
|
||||||
|
add_custom_target(uLib_dependency_target
|
||||||
|
COMMAND echo " --------------------------------- "
|
||||||
|
COMMAND echo " - Building uLib as a dependency - "
|
||||||
|
COMMAND echo " --------------------------------- "
|
||||||
|
COMMAND echo ""
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build ${ULIB_BUILD_DIR}
|
||||||
|
COMMAND echo ""
|
||||||
|
WORKING_DIRECTORY ${ULIB_BUILD_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(uLib_dependency INTERFACE)
|
||||||
|
add_dependencies(uLib_dependency uLib_dependency_target)
|
||||||
|
link_libraries(uLib_dependency)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
message(STATUS " ++ UsingLib install targets")
|
message(STATUS " ++ Using uLib installed targets")
|
||||||
|
|
||||||
include("${uLib_INSTALL_TARGETS_FILE}")
|
include("${uLib_INSTALL_TARGETS_FILE}")
|
||||||
set_and_check(ULIB_INCLUDE_DIRS "@PACKAGE_PACKAGE_INSTALL_INC_DIR@")
|
set_and_check(ULIB_INCLUDE_DIRS "@PACKAGE_INSTALL_INC_DIR@")
|
||||||
set(ULIB_SYSCONFIG_DIR "@PACKAGE_PACKAGE_INSTALL_ETC_DIR@")
|
set(ULIB_SYSCONFIG_DIR "@PACKAGE_INSTALL_ETC_DIR@")
|
||||||
set_and_check(ULIB_CMAKE_DIR "@PACKAGE_PACKAGE_INSTALL_CMAKE_DIR@")
|
set_and_check(ULIB_CMAKE_DIR "@PACKAGE_INSTALL_CMAKE_DIR@")
|
||||||
set_and_check(ULIB_LIBRARY_DIRS "@PACKAGE_PACKAGE_INSTALL_LIB_DIR@")
|
set_and_check(ULIB_LIBRARY_DIRS "@PACKAGE_INSTALL_LIB_DIR@")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# --- Add required packages from uLib ---
|
||||||
|
# TODO: this should be selected if components are active
|
||||||
|
#
|
||||||
|
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 filesystem REQUIRED)
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
link_libraries(${Boost_LIBRARIES})
|
||||||
|
|
||||||
|
find_package(Eigen3 CONFIG REQUIRED)
|
||||||
|
include(${EIGEN3_USE_FILE})
|
||||||
|
|
||||||
|
find_package(ROOT CONFIG REQUIRED)
|
||||||
|
include(${ROOT_USE_FILE})
|
||||||
|
|
||||||
|
find_package(VTK REQUIRED)
|
||||||
|
# include(${VTK_USE_FILE})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
link_directories("${ULIB_LIBRARY_DIRS}")
|
link_directories("${ULIB_LIBRARY_DIRS}")
|
||||||
set(ULIB_LIBRARIES "@ULIB_SHARED_LIBRARIES@")
|
set(ULIB_LIBRARIES "@ULIB_SHARED_LIBRARIES@")
|
||||||
|
|
||||||
# include("${ULIB_CMAKE_DIR}/uLibTargets.cmake")
|
|
||||||
check_required_components(uLib)
|
check_required_components(uLib)
|
||||||
|
|
||||||
# Imposta la variabile per indicare che il pacchetto è stato trovato.
|
# Set the variable to indicate that the package has been found.
|
||||||
set(uLib_FOUND TRUE)
|
set(uLib_FOUND TRUE)
|
||||||
|
|
||||||
|
|
||||||
# # Compute paths
|
|
||||||
# get_filename_component(ULIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
||||||
# set(ULIB_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@")
|
|
||||||
|
|
||||||
# # Our library dependencies (contains definitions for IMPORTED targets)
|
|
||||||
# include("${ULIB_CMAKE_DIR}/uLibTargets.cmake")
|
|
||||||
|
|
||||||
# # These are IMPORTED targets created by ULibTargets.cmake
|
|
||||||
# set(ULIB_LIBRARIES @ULIB_SHARED_LIBRARIES@)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user