Skip to content

Commit 186a4c4

Browse files
author
joeljonsson
committed
merged develop into developPython
2 parents 2e3004a + 62d0171 commit 186a4c4

19 files changed

+2471
-142
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(APR_INSTALL "Install APR library" OFF)
1212
option(APR_BUILD_SHARED_LIB "Builds shared library" ON)
1313
option(APR_BUILD_STATIC_LIB "Builds static library" OFF)
1414
option(APR_BUILD_EXAMPLES "Build APR examples" OFF)
15+
option(APR_USE_LIBTIFF "Use LibTIFF" ON)
1516
option(APR_TESTS "Build APR tests" OFF)
1617
option(APR_PREFER_EXTERNAL_GTEST "When found, use the installed GTEST libs instead of included sources" OFF)
1718
option(APR_PREFER_EXTERNAL_BLOSC "When found, use the installed BLOSC libs instead of included sources" OFF)
@@ -53,7 +54,13 @@ message("Configuring for APR version: " ${APR_VERSION_STRING})
5354
###############################################################################
5455
find_package(HDF5 REQUIRED)
5556
find_package(ZLIB REQUIRED)
56-
find_package(TIFF REQUIRED)
57+
if(APR_USE_LIBTIFF)
58+
find_package(TIFF)
59+
set(CMAKE_C_FLAGS "${CMAKE_CFLAGS} -DHAVE_LIBTIFF")
60+
set(CMAKE_CXX_FLAGS "${CMAKE_CXXFLAGS} -DHAVE_LIBTIFF")
61+
else()
62+
message(WARNING "LibTIFF support disable, this disables TIFF writing functionality.")
63+
endif()
5764

5865
# Handle OpenMP
5966
find_package(OpenMP)
@@ -184,7 +191,11 @@ if(APR_BUILD_SHARED_LIB)
184191
if (APPLE)
185192
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE -Wl,-force_load,$<TARGET_FILE:blosc_static>)
186193
else()
187-
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE -Wl,--whole-archive $<TARGET_FILE:blosc_static> -Wl,--no-whole-archive)
194+
if(WIN32)
195+
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE blosc_static)
196+
else()
197+
target_link_libraries(${SHARED_TARGET_NAME} PRIVATE -Wl,--whole-archive $<TARGET_FILE:blosc_static> -Wl,--no-whole-archive)
198+
endif()
188199
endif()
189200
endif()
190201
endif()

cmake/AddStaticLibs.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Adds staticLib to provided (existing) static target. Useful for merging all dependencies to
22
# one fat static lib.
33
# Use: addStaticLibs(libStatic someStaticLibToMerge [evenMoreStaticLibsIfNeeded])
4+
cmake_policy(SET CMP0026 OLD)
5+
46
function(addStaticLibs outLibTarget)
57
get_target_property(libtype ${outLibTarget} TYPE)
68
if(NOT libtype STREQUAL "STATIC_LIBRARY")
@@ -17,7 +19,8 @@ function(addStaticLibs outLibTarget)
1719
if(NOT libtype STREQUAL "STATIC_LIBRARY")
1820
message(FATAL_ERROR "[${lib}] is not a static lib!")
1921
endif()
20-
list(APPEND filesToMerge $<TARGET_FILE:${lib}>)
22+
get_target_property(myLib ${lib} LOCATION)
23+
set(filesToMerge ${filesTomerge} ${myLib})
2124
endforeach()
2225

2326
set(outLibFile $<TARGET_FILE:${outLibTarget}>)

examples/Example_get_apr.cpp

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Advanced (Direct) Settings:
2626
-rel_error rel_error_value (Reasonable ranges are from .08-.15), Default: 0.1
2727
-normalize_input (flag that will rescale the input from the input data range to 80% of the output data type range, useful for float scaled datasets)
2828
-compress_level (the IO uses BLOSC for lossless compression of the APR, this can be set from 1-9, where higher increases the compression level. Note, this can come at a significant time increase.)
29+
-compress_type (Default: 0, loss-less compression of partilce intensities, (1,2) WNL (Balázs et al. 2017) - approach compression applied to particles (1 = without prediction, 2 = with)
30+
31+
-neighborhood_optimization_off turns off the neighborhood opetimization (This results in boundary Particle Cells also being increased in resolution after the Pulling Scheme step)
32+
-output_steps Writes tiff images of the individual steps (gradient magnitude, local intensity scale, and final level of the APR calculation).
33+
2934
)";
3035

3136
#include <algorithm>
@@ -43,31 +48,31 @@ int main(int argc, char **argv) {
4348
//the apr datastructure
4449
APR<uint16_t> apr;
4550

46-
APRConverter<uint16_t> apr_converter;
47-
4851
//read in the command line options into the parameters file
49-
apr_converter.par.Ip_th = options.Ip_th;
50-
apr_converter.par.rel_error = options.rel_error;
51-
apr_converter.par.lambda = options.lambda;
52-
apr_converter.par.mask_file = options.mask_file;
53-
apr_converter.par.min_signal = options.min_signal;
54-
apr_converter.par.SNR_min = options.SNR_min;
55-
apr_converter.par.normalized_input = options.normalize_input;
52+
apr.parameters.Ip_th = options.Ip_th;
53+
apr.parameters.rel_error = options.rel_error;
54+
apr.parameters.lambda = options.lambda;
55+
apr.parameters.mask_file = options.mask_file;
56+
apr.parameters.min_signal = options.min_signal;
57+
apr.parameters.SNR_min = options.SNR_min;
58+
apr.parameters.normalized_input = options.normalize_input;
59+
apr.parameters.neighborhood_optimization = options.neighborhood_optimization;
60+
apr.parameters.output_steps = options.output_steps;
5661

5762
//where things are
58-
apr_converter.par.input_image_name = options.input;
59-
apr_converter.par.input_dir = options.directory;
60-
apr_converter.par.name = options.output;
61-
apr_converter.par.output_dir = options.output_dir;
63+
apr.parameters.input_image_name = options.input;
64+
apr.parameters.input_dir = options.directory;
65+
apr.parameters.name = options.output;
66+
apr.parameters.output_dir = options.output_dir;
6267

63-
apr_converter.fine_grained_timer.verbose_flag = false;
64-
apr_converter.method_timer.verbose_flag = false;
65-
apr_converter.computation_timer.verbose_flag = false;
66-
apr_converter.allocation_timer.verbose_flag = false;
67-
apr_converter.total_timer.verbose_flag = true;
68+
apr.apr_converter.fine_grained_timer.verbose_flag = false;
69+
apr.apr_converter.method_timer.verbose_flag = false;
70+
apr.apr_converter.computation_timer.verbose_flag = false;
71+
apr.apr_converter.allocation_timer.verbose_flag = false;
72+
apr.apr_converter.total_timer.verbose_flag = true;
6873

6974
//Gets the APR
70-
if(apr_converter.get_apr(apr)){
75+
if(apr.get_apr()){
7176

7277
//Below is IO and outputting of the Implied Resolution Function through the Particle Cell level.
7378

@@ -79,18 +84,6 @@ int main(int argc, char **argv) {
7984

8085
timer.verbose_flag = true;
8186

82-
PixelData<uint16_t> level;
83-
84-
apr.interp_depth_ds(level);
85-
86-
std::cout << std::endl;
87-
88-
std::cout << "Saving down-sampled Particle Cell level as tiff image" << std::endl;
89-
90-
std::string output_path = save_loc + file_name + "_level.tif";
91-
//write output as tiff
92-
TiffUtils::saveMeshAsTiff(output_path, level);
93-
9487
std::cout << std::endl;
9588
float original_pixel_image_size = (2.0f*apr.orginal_dimensions(0)*apr.orginal_dimensions(1)*apr.orginal_dimensions(2))/(1000000.0);
9689
std::cout << "Original image size: " << original_pixel_image_size << " MB" << std::endl;
@@ -104,6 +97,8 @@ int main(int argc, char **argv) {
10497
unsigned int blosc_comp_level = options.compress_level;
10598
unsigned int blosc_shuffle = 1;
10699

100+
apr.apr_compress.set_compression_type(options.compress_type);
101+
107102
//write the APR to hdf5 file
108103
FileSizeInfo fileSizeInfo = apr.write_apr(save_loc,file_name,blosc_comp_type,blosc_comp_level,blosc_shuffle);
109104
float apr_file_size = fileSizeInfo.total_file_size;
@@ -117,6 +112,20 @@ int main(int argc, char **argv) {
117112
std::cout << "Lossy Compression Ratio: " << original_pixel_image_size/apr_file_size << std::endl;
118113
std::cout << std::endl;
119114

115+
if(options.output_steps) {
116+
117+
PixelData<uint16_t> level;
118+
119+
apr.interp_depth_ds(level);
120+
121+
std::cout << std::endl;
122+
123+
std::cout << "Saving down-sampled Particle Cell level as tiff image" << std::endl;
124+
125+
std::string output_path = save_loc + file_name + "_level.tif";
126+
//write output as tiff
127+
TiffUtils::saveMeshAsTiff(output_path, level);
128+
}
120129

121130
} else {
122131
std::cout << "Oops, something went wrong. APR not computed :(." << std::endl;
@@ -220,14 +229,25 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
220229
result.compress_level = (unsigned int)std::stoi(std::string(get_command_option(argv, argv + argc, "-compress_level")));
221230
}
222231

232+
if(command_option_exists(argv, argv + argc, "-compress_type"))
233+
{
234+
result.compress_type = (unsigned int)std::stoi(std::string(get_command_option(argv, argv + argc, "-compress_type")));
235+
}
236+
223237
if(command_option_exists(argv, argv + argc, "-normalize_input"))
224238
{
225239
result.normalize_input = true;
226240
}
227241

228-
if(command_option_exists(argv, argv + argc, "-store_delta"))
242+
if(command_option_exists(argv, argv + argc, "-neighborhood_optimization_off"))
243+
{
244+
result.neighborhood_optimization = false;
245+
246+
}
247+
248+
if(command_option_exists(argv, argv + argc, "-output_steps"))
229249
{
230-
result.store_delta = true;
250+
result.output_steps = true;
231251
}
232252

233253
return result;

examples/Example_get_apr.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "algorithm/APRParameters.hpp"
88
#include "data_structures/Mesh/PixelData.hpp"
9-
#include "algorithm/APRConverter.hpp"
109
#include "data_structures/APR/APR.hpp"
1110

1211

@@ -20,8 +19,10 @@ struct cmdLineOptions{
2019
std::string mask_file = "";
2120
bool stats_file = false;
2221
bool normalize_input = false;
23-
bool store_delta = false;
22+
bool neighborhood_optimization = true;
23+
bool output_steps = false;
2424
unsigned int compress_level = 2;
25+
unsigned int compress_type = 0;
2526

2627
float Ip_th = -1;
2728
float SNR_min = -1;

examples/Example_ray_cast.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef PARTPLAY_RAYCAST_H
22
#define PARTPLAY_RAYCAST_H
33

4-
54
#include "numerics/APRRaycaster.hpp"
65
#include "data_structures/APR/APR.hpp"
76

examples/Example_reconstruct_patch.cpp

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Default: Piece-wise constant reconstruction
3939

4040
#include "data_structures/APR/APR.hpp"
4141
#include "io/TiffUtils.hpp"
42+
#include "numerics/APRTreeNumerics.hpp"
4243

4344

4445
struct cmdLineOptions{
@@ -186,18 +187,25 @@ int main(int argc, char **argv) {
186187
reconPatch.z_begin = options.z_begin;
187188
reconPatch.z_end = options.z_end;
188189

190+
reconPatch.level_delta = options.level_delta;
191+
192+
APRTree<uint16_t> aprTree;
193+
aprTree.init(apr);
194+
189195
// Intentionaly block-scoped since local recon_pc will be destructed when block ends and release memory.
190196
{
191197

192198
if(options.output_pc_recon) {
193199
//create mesh data structure for reconstruction
194200
PixelData<uint16_t> recon_pc;
195201

202+
ExtraParticleData<uint16_t> partsTree;
196203

204+
APRTreeNumerics::fill_tree_from_particles(apr,aprTree,apr.particles_intensities,partsTree,[] (const uint16_t& a,const uint16_t& b) {return std::max(a,b);});
197205

198206
timer.start_timer("pc interp");
199207
//perform piece-wise constant interpolation
200-
aprReconstruction.interp_image_patch(apr,recon_pc, apr.particles_intensities,reconPatch);
208+
aprReconstruction.interp_image_patch(apr,aprTree,recon_pc, apr.particles_intensities,partsTree,reconPatch);
201209
timer.stop_timer();
202210

203211
float elapsed_seconds = timer.t2 - timer.t1;
@@ -210,64 +218,39 @@ int main(int argc, char **argv) {
210218
}
211219
}
212220

213-
//////////////////////////
214-
/// Create a particle dataset with the particle type and pc construct it
215-
////////////////////////////
216-
217-
if(options.output_spatial_properties) {
218-
219-
//initialization of the iteration structures
220-
APRIterator<uint16_t> apr_iterator(apr); //this is required for parallel access
221-
222-
//create particle dataset
223-
ExtraParticleData<uint16_t> type(apr);
224-
ExtraParticleData<uint16_t> level(apr);
225-
226-
ExtraParticleData<uint16_t> x(apr);
227-
ExtraParticleData<uint16_t> y(apr);
228-
ExtraParticleData<uint16_t> z(apr);
229221

230-
timer.start_timer("APR parallel iterator loop");
231-
#ifdef HAVE_OPENMP
232-
#pragma omp parallel for schedule(static) firstprivate(apr_iterator)
233-
#endif
234-
for (uint64_t particle_number = 0; particle_number < apr_iterator.total_number_particles(); ++particle_number) {
235-
//needed step for any parallel loop (update to the next part)
236-
apr_iterator.set_iterator_to_particle_by_number(particle_number);
237-
type[apr_iterator] = apr_iterator.type();
238-
level[apr_iterator] = apr_iterator.level();
222+
{
239223

240-
x[apr_iterator] = apr_iterator.x();
241-
y[apr_iterator] = apr_iterator.y();
242-
z[apr_iterator] = apr_iterator.z();
243-
}
244-
timer.stop_timer();
224+
if(options.output_smooth_recon) {
225+
//create mesh data structure for reconstruction
226+
PixelData<uint16_t> recon_pc;
245227

246-
// Intentionaly block-scoped since local type_recon will be destructed when block ends and release memory.
247-
{
248-
PixelData<uint16_t> type_recon;
228+
ExtraParticleData<uint16_t> partsTree;
249229

250-
aprReconstruction.interp_image_patch(apr,type_recon, type,reconPatch);
251-
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_type.tif", type_recon);
230+
std::vector<float> scale = {1,1,1};
252231

253-
//level
254-
aprReconstruction.interp_image_patch(apr,type_recon, level,reconPatch);
255-
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_level.tif", type_recon);
232+
APRTreeNumerics::fill_tree_from_particles(apr,aprTree,apr.particles_intensities,partsTree,[] (const uint16_t& a,const uint16_t& b) {return std::max(a,b);});
256233

257-
//x
258-
aprReconstruction.interp_image_patch(apr,type_recon, x,reconPatch);
259-
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_x.tif", type_recon);
234+
timer.start_timer("smooth interp");
235+
//perform smooth interpolation
236+
aprReconstruction.interp_parts_smooth_patch(apr,aprTree,recon_pc, apr.particles_intensities,partsTree,reconPatch,scale);
237+
timer.stop_timer();
260238

261-
//y
262-
aprReconstruction.interp_image_patch(apr,type_recon, y,reconPatch);
263-
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_y.tif", type_recon);
239+
float elapsed_seconds = timer.t2 - timer.t1;
240+
std::cout << "Smooth recon "
241+
<< (recon_pc.x_num * recon_pc.y_num * recon_pc.z_num * 2) / (elapsed_seconds * 1000000.0f)
242+
<< " MB per second" << std::endl;
264243

265-
//z
266-
aprReconstruction.interp_image_patch(apr,type_recon, z,reconPatch);
267-
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_z.tif", type_recon);
244+
//write output as tiff
245+
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_smooth.tif", recon_pc);
268246
}
269247
}
270248

249+
//////////////////////////
250+
/// Create a particle dataset with the particle type and pc construct it
251+
////////////////////////////
252+
253+
271254
if(options.output_level) {
272255

273256
//initialization of the iteration structures
@@ -294,7 +277,7 @@ int main(int argc, char **argv) {
294277
PixelData<uint8_t> type_recon;
295278

296279
//level
297-
aprReconstruction.interp_image_patch(apr,type_recon, level,reconPatch);
280+
//aprReconstruction.interp_image_patch(apr,aprTree,type_recon, level,reconPatch);
298281
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_level.tif", type_recon);
299282

300283
}

0 commit comments

Comments
 (0)