add version 0.6 - make external build possible

This commit is contained in:
AndreaRigoni
2025-09-05 18:04:54 +02:00
parent 2e401f6fc5
commit 591cc9d8bc
14 changed files with 179 additions and 91 deletions

View File

@@ -18,10 +18,10 @@ 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}/Core)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Core)

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

@@ -4,4 +4,4 @@ set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
install(FILES ${HEADERS}
DESTINATION ${PACKAGE_INSTALL_INC_DIR}/Detectors)
DESTINATION ${INSTALL_INC_DIR}/Detectors)

View File

@@ -49,10 +49,10 @@ 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}/Math)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Math)
# TESTING
# include(uLibTargetMacros)

View File

@@ -139,7 +139,6 @@ typedef Eigen::Vector4f Vector4f;
////////////////////////////////////////////////////////////////////////////////
// Vector String interaction ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

View File

@@ -32,9 +32,11 @@
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkXMLImageDataReader.h>
#include <vtkXMLImageDataWriter.h>
#include <vtkStringArray.h>
#include <vtkInformation.h>
#include <vtkInformationStringKey.h>
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);
}
// // Create a custom string key
// static vtkInformationStringKey* ConfigNote =
// vtkInformationStringKey::MakeKey("ConfigNote", "MyNotes");
// Create a custom string key
static vtkInformationStringKey* ConfigNote =
vtkInformationStringKey::MakeKey("cmt.config", "Config");
// // Attach metadata
// image->GetInformation()->Set(ConfigNote, "This image was generated with method X, threshold=0.5");
// 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);
@@ -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)
int Abstract::VoxImage::ImportFromVtk(const char *file, bool density_type)
{
FILE * vtk_file = fopen(file, "r");
if (!vtk_file) return false;
@@ -171,14 +211,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

@@ -56,9 +56,18 @@ public:
virtual void SetDims(const Vector3i &size) = 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);
// 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);
int ImportFromVtk(const char *file, bool density_type = 0);
int ImportFromVti(const char *file, bool density_type = 0);
protected:

View File

@@ -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)
@@ -57,9 +57,9 @@ 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}/Root)
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Root)

View File

@@ -31,8 +31,8 @@ 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)