Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive debug #181

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
26cf2a6
initialize the first value of ne_counter to 0
joeljonsson Oct 24, 2022
0b1a7b3
indentation
joeljonsson Oct 24, 2022
66a5c0c
inline hdf5 file creation call
joeljonsson Oct 24, 2022
2b38a7b
bump submodule gtest
joeljonsson Oct 24, 2022
afb5261
make protected APR members public
joeljonsson Nov 24, 2022
cf7f7bb
ensure correct GenInfo for linearAccess/gpuAccess
joeljonsson Nov 27, 2022
374c01f
make addition of gaussian noise an option (off by default)
joeljonsson Feb 20, 2023
69a3fe5
Fix unsafe addition of bspline_offset for APRConverter of integer type
joeljonsson Feb 20, 2023
ad3a5b5
set pinned memory to false as cuda pipeline is not functional
joeljonsson Feb 20, 2023
5bc9d8e
Use APRConverter<float> in Example_get_apr.cpp
joeljonsson Feb 20, 2023
3705021
add auto_parameters option and use float converter
joeljonsson Feb 20, 2023
0850611
move compute_bspline_offset method to AutoParameters.hpp
joeljonsson Feb 20, 2023
a3c5365
use compute_bspline_offset method in blocked pipeline
joeljonsson Feb 20, 2023
a2f55eb
move getMinMax function to AutoParameters.hpp
joeljonsson Feb 20, 2023
52f5f9a
bump vcpkg
joeljonsson Feb 20, 2023
e303f19
add brew install pkg-config in macos workflow
joeljonsson Feb 20, 2023
10cb3ea
bump action versions
joeljonsson Feb 20, 2023
01f2f1f
add --output-on-failure flag to ctest command
joeljonsson Feb 20, 2023
ec057d4
fix duplicate option
joeljonsson Feb 20, 2023
c9f508e
bump blosc submodule
joeljonsson Feb 20, 2023
99fd77b
bump gtest submodule
joeljonsson Feb 20, 2023
ad548b2
try downloading gtest in config instead of using submodule
joeljonsson Feb 20, 2023
b86b6f6
bump minimum cmake version to 3.10 -> 3.14
joeljonsson Feb 20, 2023
e6cf415
set cmake policy CMP0135
joeljonsson Feb 20, 2023
10d9f67
set CMAKE_BUILD_TYPE to Release
joeljonsson Feb 20, 2023
0e5916c
revert to old behaviour (not setting APR_PREFER_EXTERNAL_GTEST)
joeljonsson Feb 21, 2023
f3138d6
remove submodule gtest
joeljonsson Feb 21, 2023
98ea8ee
add parameters to copy constructor
joeljonsson Feb 22, 2023
b3f4409
rerun workflow
joeljonsson Mar 23, 2023
10ab24a
empty
joeljonsson Sep 5, 2023
6035900
Merge remote-tracking branch 'origin/patch_178' into joel_tmp
joeljonsson Oct 16, 2023
d960917
bump vcpkg
joeljonsson Oct 16, 2023
d220171
add vcpkg baseline ref
joeljonsson Oct 16, 2023
003270b
Merge pull request #180 from AdaptiveParticles/joel_tmp
joeljonsson Oct 16, 2023
bb90fa3
update hdf5 version in vcpkg manifest
joeljonsson Oct 16, 2023
e9eb89d
update package version
joeljonsson Oct 16, 2023
4dca4f9
update tiff version in vcpkg manifest
joeljonsson Oct 16, 2023
6853443
bump checkout action
joeljonsson Oct 16, 2023
1e27c7a
remove version specification for dependencies
joeljonsson Oct 16, 2023
e31ad7e
make iterator comparison and pipeline_test_u16 more informative
joeljonsson Oct 16, 2023
dd1dfb3
fix error
joeljonsson Oct 16, 2023
f2247d9
increase compareMeshes error threshold for u16 pipeline test
joeljonsson Oct 16, 2023
fba2358
actually check gradient
joeljonsson Oct 16, 2023
fabc9ac
remove duplicate printouts
joeljonsson Oct 16, 2023
c94ed44
make bspline_offset public
joeljonsson Oct 16, 2023
40e807b
reset bspline_offset before computing APR with saved grad and lis
joeljonsson Oct 16, 2023
c6c627e
Interactive debug
cheesema Nov 3, 2023
d8a471e
Update cmake.yml
cheesema Nov 3, 2023
c37416a
Change out to tmate action
cheesema Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ jobs:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true

# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
- uses: lukka/get-cmake@latest
# Restore both vcpkg and its artifacts from the GitHub cache service.
- name: Restore vcpkg and its artifacts.
uses: actions/cache@v2
uses: actions/cache@v3
with:
# The first path is where vcpkg generates artifacts while consuming the vcpkg.json manifest file.
# The second path is the location of vcpkg (it contains the vcpkg executable and data files).
Expand All @@ -64,7 +64,7 @@ jobs:

- name: Install OpenMP dependencies with brew for OSX
if: contains(matrix.os,'macos')
run: brew install libomp #todo caching
run: brew install libomp pkg-config #todo caching

- name: Show content of workspace after cache has been restored
run: find $RUNNER_WORKSPACE
Expand All @@ -75,17 +75,21 @@ jobs:
# Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json.
- name: Install dependencies and generate project files
run: |
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }}
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }}

# Build the whole project with Ninja (which is spawn by CMake).
- name: Build
run: |
cmake --build "${{ env.CMAKE_BUILD_DIR }}" --parallel 4 --config Release


- name: Setup tmate session
uses: mxschmitt/action-tmate@v3

# Run tests
- name: tests
run: |
ctest --test-dir "${{ env.CMAKE_BUILD_DIR }}"
ctest --test-dir "${{ env.CMAKE_BUILD_DIR }}" --output-on-failure

- name: Show content of workspace at its completion
run: find $RUNNER_WORKSPACE
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "external/glm"]
path = external/glm
url = https://github.com/g-truc/glm.git
[submodule "external/gtest"]
path = external/gtest
url = https://github.com/google/googletest
[submodule "external/c-blosc"]
path = external/c-blosc
url = https://github.com/Blosc/c-blosc
Expand Down
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
###############################################################################
# APR - Adaptive Particle Representation
###############################################################################
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.14)
project(APR DESCRIPTION "Adaptive Particle Representation library")

message(STATUS "CMAKE VERSION ${CMAKE_VERSION}")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif(POLICY CMP0135)

# APR build options:
option(APR_INSTALL "Install APR library" OFF)
option(APR_BUILD_SHARED_LIB "Builds shared library" OFF)
Expand Down Expand Up @@ -360,12 +364,22 @@ if(APR_TESTS)
if(GTEST_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
else(GTEST_FOUND)
message(STATUS "APR: GTest not found, it will be downloaded and built")

include(FetchContent)
FetchContent_Declare(
googletest
# Specify the commit you depend on and update it regularly.
URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(BUILD_GTEST ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
message(STATUS "APR: GTest not found, using internal gtest")
add_subdirectory("external/gtest")
set(GTEST_LIBRARIES gtest)
FetchContent_MakeAvailable(googletest)

set(GTEST_LIBRARIES GTest::gtest_main)
endif(GTEST_FOUND)

enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion examples/Example_get_apr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int runAPR(cmdLineOptions options) {
//the apr datastructure
APR apr;

APRConverter<uint16_t> aprConverter;
APRConverter<float> aprConverter;

//read in the command line options into the parameters file
aprConverter.par.Ip_th = options.Ip_th;
Expand Down
9 changes: 7 additions & 2 deletions examples/Example_get_apr_by_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ must be used. The exact influence of this has not yet been studied.
int runAPR(cmdLineOptions options) {

APR apr;
APRConverterBatch<uint16_t> aprConverter;
APRConverterBatch<float> aprConverter;

//read in the command line options into the parameters file
aprConverter.par.Ip_th = options.Ip_th;
Expand All @@ -55,6 +55,7 @@ int runAPR(cmdLineOptions options) {
aprConverter.par.neighborhood_optimization = options.neighborhood_optimization;
aprConverter.par.output_steps = options.output_steps;
aprConverter.par.grad_th = options.grad_th;
aprConverter.par.auto_parameters = options.auto_parameters;

//where things are
aprConverter.par.input_image_name = options.input;
Expand Down Expand Up @@ -234,7 +235,6 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
if(command_option_exists(argv, argv + argc, "-neighborhood_optimization_off"))
{
result.neighborhood_optimization = false;

}

if(command_option_exists(argv, argv + argc, "-output_steps"))
Expand All @@ -247,5 +247,10 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
result.store_tree = true;
}

if(command_option_exists(argv, argv + argc, "-auto_parameters"))
{
result.auto_parameters = true;
}

return result;
}
2 changes: 2 additions & 0 deletions examples/Example_get_apr_by_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct cmdLineOptions{
float rel_error = 0.1;
float grad_th = 1;

bool auto_parameters = false;

int z_block_size = 128;
int z_ghost = 16; // number of "ghost slices" to use in the APR pipeline
int z_ghost_sampling = 64; // number of "ghost slices" to use when sampling intensities
Expand Down
46 changes: 22 additions & 24 deletions examples/Example_reconstruct_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct cmdLineOptions{
bool output_spatial_properties = false;
bool output_pc_recon = false;
bool output_smooth_recon = false;

float gaussian_noise_sigma = 0.0f;
};

static bool command_option_exists(char **begin, char **end, const std::string &option) {
Expand Down Expand Up @@ -99,6 +99,10 @@ static cmdLineOptions read_command_line_options(int argc, char **argv) {
result.output_spatial_properties = true;
}

if(command_option_exists(argv, argv + argc, "-noise")) {
result.gaussian_noise_sigma = std::stof(std::string(get_command_option(argv, argv + argc, "-noise")));
}

if(!(result.output_pc_recon || result.output_smooth_recon || result.output_spatial_properties)){
//default is pc recon
result.output_pc_recon = true;
Expand All @@ -107,7 +111,7 @@ static cmdLineOptions read_command_line_options(int argc, char **argv) {
return result;
}
template<typename T>
void add_random_to_img(PixelData<T>& img,float sd){
void add_random_to_img(PixelData<T>& img, float sd){

std::default_random_engine generator;
std::normal_distribution<float> distribution(0.0,sd);
Expand Down Expand Up @@ -149,32 +153,26 @@ int main(int argc, char **argv) {
apr.name = options.output;
timer.stop_timer();

// Intentionaly block-scoped since local recon_pc will be destructed when block ends and release memory.
{

if(options.output_pc_recon) {
//create mesh data structure for reconstruction
bool add_random_gitter = true;

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

timer.start_timer("pc interp");
//perform piece-wise constant interpolation
APRReconstruction::reconstruct_constant(apr,recon_pc, parts);
timer.stop_timer();
timer.start_timer("pc interp");
//perform piece-wise constant interpolation
APRReconstruction::reconstruct_constant(apr, recon_pc, parts);
timer.stop_timer();

if(add_random_gitter){
add_random_to_img(recon_pc,1.0f);
}
if(options.gaussian_noise_sigma > 0.0f) {
add_random_to_img(recon_pc, options.gaussian_noise_sigma);
}

float elapsed_seconds = timer.t2 - timer.t1;
std::cout << "PC recon "
<< (recon_pc.x_num * recon_pc.y_num * recon_pc.z_num * 2) / (elapsed_seconds * 1000000.0f)
<< " MB per second" << std::endl;
float elapsed_seconds = timer.t2 - timer.t1;
std::cout << "PC recon "
<< (recon_pc.x_num * recon_pc.y_num * recon_pc.z_num * 2) / (elapsed_seconds * 1000000.0f)
<< " MB per second" << std::endl;

// write output as tiff
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_pc.tif", recon_pc);
}
// write output as tiff
TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_pc.tif", recon_pc);
}

//////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion external/c-blosc
Submodule c-blosc updated 438 files
1 change: 0 additions & 1 deletion external/gtest
Submodule gtest deleted from 6b74da
39 changes: 7 additions & 32 deletions src/algorithm/APRConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class APRConverter {
return true;
}

float bspline_offset = 0;

protected:

template<typename T>
Expand All @@ -108,8 +110,6 @@ class APRConverter {

//get apr without setting parameters, and with an already loaded image.

float bspline_offset = 0;

//DATA (so it can be re-used)

PixelData<ImageType> grad_temp; // should be a down-sampled image
Expand All @@ -133,26 +133,6 @@ class APRConverter {
};


template <typename T>
struct MinMax{T min; T max; };

template <typename T>
static MinMax<T> getMinMax(const PixelData<T>& input_image) {
T minVal = std::numeric_limits<T>::max();
T maxVal = std::numeric_limits<T>::min();

#ifdef HAVE_OPENMP
#pragma omp parallel for default(shared) reduction(max:maxVal) reduction(min:minVal)
#endif
for (size_t i = 0; i < input_image.mesh.size(); ++i) {
T val = input_image.mesh[i];
if (val > maxVal) maxVal = val;
if (val < minVal) minVal = val;
}

return MinMax<T>{minVal, maxVal};
}

template<typename ImageType>
void APRConverter<ImageType>::initPipelineMemory(int y_num,int x_num,int z_num){
//initializes the internal memory to be used in the pipeline.
Expand Down Expand Up @@ -224,7 +204,7 @@ void APRConverter<ImageType>::computeL(APR& aAPR,PixelData<T>& input_image){
//assuming uint16, the total memory cost shoudl be approximately (1 + 1 + 1/8 + 2/8 + 2/8) = 2 5/8 original image size in u16bit
//storage of the particle cell tree for computing the pulling scheme
allocation_timer.start_timer("init and copy image");
PixelData<ImageType> image_temp(input_image, false /* don't copy */, true /* pinned memory */); // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image)
PixelData<ImageType> image_temp(input_image, false /* don't copy */, false /* pinned memory */); // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image)

allocation_timer.stop_timer();

Expand All @@ -233,17 +213,12 @@ void APRConverter<ImageType>::computeL(APR& aAPR,PixelData<T>& input_image){
////////////////////////

fine_grained_timer.start_timer("offset image");
//offset image by factor (this is required if there are zero areas in the background with uint16_t and uint8_t images, as the Bspline co-efficients otherwise may be negative!)
// Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set image_type = "", i.e. uncomment the following line)

if (std::is_same<uint16_t, ImageType>::value) {
bspline_offset = 100;
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
} else if (std::is_same<uint8_t, ImageType>::value){
bspline_offset = 5;
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
} else {
if (std::is_floating_point<ImageType>::value) {
image_temp.copyFromMesh(input_image);
} else {
bspline_offset = compute_bspline_offset<ImageType>(input_image, par.lambda);
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
}

fine_grained_timer.stop_timer();
Expand Down
15 changes: 6 additions & 9 deletions src/algorithm/APRConverterBatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,14 @@ bool APRConverterBatch<ImageType>::get_apr_method_patch(APR &aAPR, PixelData<T>&
computation_timer.start_timer("Calculations");

fine_grained_timer.start_timer("offset image");
//offset image by factor (this is required if there are zero areas in the background with uint16_t and uint8_t images, as the Bspline co-efficients otherwise may be negative!)
// Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set image_type = "", i.e. uncomment the following line)
if (std::is_same<uint16_t, ImageType>::value) {
bspline_offset = 100;
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
} else if (std::is_same<uint8_t, ImageType>::value){
bspline_offset = 5;
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
} else {

if (std::is_floating_point<ImageType>::value) {
image_temp.copyFromMesh(input_image);
} else {
bspline_offset = compute_bspline_offset<ImageType>(input_image, par.lambda);
image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); });
}

fine_grained_timer.stop_timer();

method_timer.start_timer("compute_gradient_magnitude_using_bsplines");
Expand Down
39 changes: 39 additions & 0 deletions src/algorithm/AutoParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,43 @@ void autoParametersLiEntropy(APRParameters& par,
}
}



template <typename T>
struct MinMax{T min; T max; };

template <typename T>
static MinMax<T> getMinMax(const PixelData<T>& input_image) {
T minVal = std::numeric_limits<T>::max();
T maxVal = std::numeric_limits<T>::min();

#ifdef HAVE_OPENMP
#pragma omp parallel for default(shared) reduction(max:maxVal) reduction(min:minVal)
#endif
for (size_t i = 0; i < input_image.mesh.size(); ++i) {
const T val = input_image.mesh[i];
if (val > maxVal) maxVal = val;
if (val < minVal) minVal = val;
}

return MinMax<T>{minVal, maxVal};
}

/**
* Compute bspline offset for APRConverter of integer type ImageType
*/
template<typename ImageType, typename T>
float compute_bspline_offset(PixelData<T>& input_image, float lambda) {
// if bspline smoothing is disabled, there is no need for an offset
if(lambda <= 0) return 0;

// compute offset to center the intensities in the ImageType range (can be negative)
auto img_range = getMinMax(input_image);
float offset = (std::numeric_limits<ImageType>::max() - (img_range.max - img_range.min)) / 2 - img_range.min;

// clamp the offset to [-100, 100]
return std::max(std::min(offset, 100.f), -100.f);
}


#endif //APR_AUTOPARAMETERS_HPP
Loading
Loading