Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
- block stitching code, aligned to zarr block dimensions, seems to be…
Browse files Browse the repository at this point in the history
… working

- cleanup example2.c according to review
- cleanup tests according to review and fix a bunch of improper memory handling
- add small logging functonality to vesuvius-c.h
- add more thorough logging to chunk grafting and vs_vol_get_chunk
  • Loading branch information
SuperOptimizer committed Nov 15, 2024
1 parent e038914 commit 53f4615
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 177 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
add_executable(vesuvius_example example.c)
add_executable(vesuvius_example2 example2.c)
add_executable(vesuvius_tests runtests.c)
add_executable(vesuvius_tests_sanitizer runtests.c)

include_directories(third-party/json.h)

Expand All @@ -19,11 +20,13 @@ if(UNIX)
target_link_options(vesuvius_example PUBLIC -rdynamic)
target_link_options(vesuvius_example2 PUBLIC -rdynamic)
target_link_options(vesuvius_tests PUBLIC -rdynamic)
target_link_options(vesuvius_tests_sanitizer PUBLIC -rdynamic)
endif()

target_link_libraries(vesuvius_example PUBLIC -lm)
target_link_libraries(vesuvius_example2 PUBLIC -lm)
target_link_libraries(vesuvius_tests PUBLIC -lm)
target_link_libraries(vesuvius_tests_sanitizer PUBLIC -lm)

find_package(Blosc2 REQUIRED)
find_package(CURL REQUIRED)
Expand All @@ -34,7 +37,7 @@ if(Blosc2_FOUND)
target_link_libraries(vesuvius_example PUBLIC Blosc2::Blosc2)
target_link_libraries(vesuvius_example2 PUBLIC Blosc2::Blosc2)
target_link_libraries(vesuvius_tests PUBLIC Blosc2::Blosc2)
add_compile_definitions(VESUVIUS_ZARR_IMPL)
target_link_libraries(vesuvius_tests_sanitizer PUBLIC Blosc2::Blosc2)
else()
message(FATAL_ERROR "Blosc2 not found, please install blosc2")
endif()
Expand All @@ -44,9 +47,10 @@ if(CURL_FOUND)
target_link_libraries(vesuvius_example PUBLIC CURL::libcurl)
target_link_libraries(vesuvius_example2 PUBLIC CURL::libcurl)
target_link_libraries(vesuvius_tests PUBLIC CURL::libcurl)
add_compile_definitions(VESUVIUS_CURL_IMPL)
target_link_libraries(vesuvius_tests_sanitizer PUBLIC CURL::libcurl)
else()
message(FATAL_ERROR "CURL not found, please install curl")
endif()


target_compile_options(vesuvius_tests_sanitizer PUBLIC -fsanitize=address -fno-omit-frame-pointer)
target_link_options(vesuvius_tests_sanitizer PUBLIC -fsanitize=address)
45 changes: 28 additions & 17 deletions example2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@
#include "vesuvius-c.h"

int test_volume_load() {
chunk* mychunk;

const char* zarray_url = "https://dl.ash2txt.org/full-scrolls/Scroll1/PHercParis4.volpkg/volumes_zarr_standardized/54keV_7.91um_Scroll1A.zarr/0/.zarray";
const char* zarr_block_url = "https://dl.ash2txt.org/full-scrolls/Scroll1/PHercParis4.volpkg/volumes_zarr_standardized/54keV_7.91um_Scroll1A.zarr/0/50/30/30";
void* metadata_buf;
char url[1024] = "https://dl.ash2txt.org/full-scrolls/Scroll1/PHercParis4.volpkg/volumes_zarr_standardized/54keV_7.91um_Scroll1A.zarr/0/.zarray";
if (vs_download(url, &metadata_buf) <= 0) {
printf("downloading %s\n",zarray_url);
if (vs_download(zarray_url, &metadata_buf) <= 0) {
return 1;
}

zarr_metadata metadata;
printf("parsing zarr metadata\n");
if (vs_zarr_parse_metadata(metadata_buf, &metadata)) {
return 1;
}

void* compressed_buf;
strncpy(url,"https://dl.ash2txt.org/full-scrolls/Scroll1/PHercParis4.volpkg/volumes_zarr_standardized/54keV_7.91um_Scroll1A.zarr/0/50/30/30",1023);
long compressed_size;
if ((compressed_size = vs_download(url, &compressed_buf)) <= 0) {
printf("downloading %s\n",zarr_block_url);
if ((compressed_size = vs_download(zarr_block_url, &compressed_buf)) <= 0) {
return 1;
}
mychunk = vs_zarr_decompress_chunk(compressed_size, compressed_buf,metadata);
printf("decompressing zarr chunk\n");
chunk* mychunk = vs_zarr_decompress_chunk(compressed_size, compressed_buf,metadata);
if (mychunk == NULL) {
return 1;
}
printf("rescaling zarr chunk\n");
chunk* rescaled = vs_normalize_chunk(mychunk);
s32 vertex_count, index_count;
f32 *vertices;
s32 *indices;

if (vs_march_cubes(mychunk->data,mychunk->dims[0],mychunk->dims[1],mychunk->dims[2],.5f,&vertices,&indices,&vertex_count,&index_count)) {
printf("marching cubes on rescaled chunk\n");
if (vs_march_cubes(rescaled->data,rescaled->dims[0],rescaled->dims[1],rescaled->dims[2],.5f,&vertices,&indices,&vertex_count,&index_count)) {
return 1;
}

printf("writing mesh to out_vol.ply\n");
if (vs_ply_write("out_vol.ply",vertices,NULL,indices,vertex_count,index_count)) {
return 1;
}
Expand All @@ -41,36 +46,42 @@ int test_volume_load() {
}

int test_fiber_load() {
const char* zarray_url = "https://dl.ash2txt.org/community-uploads/bruniss/Fiber-and-Surface-Models/GP-Predictions/updated_zarrs/mask-2ext-surface_ome.zarr/0/.zarray";
const char* zarr_block_url = "https://dl.ash2txt.org/community-uploads/bruniss/Fiber-and-Surface-Models/GP-Predictions/updated_zarrs/mask-2ext-surface_ome.zarr/0/50/30/30";

chunk* mychunk;

void* metadata_buf;
char url[1024] = "https://dl.ash2txt.org/community-uploads/bruniss/Fiber-and-Surface-Models/GP-Predictions/updated_zarrs/mask-2ext-surface_ome.zarr/0/.zarray";
if (vs_download(url, &metadata_buf) <= 0) {
printf("downloading %s\n",zarray_url);
if (vs_download(zarray_url, &metadata_buf) <= 0) {
return 1;
}
zarr_metadata metadata;
printf("parsing zarray metadata\n");
if (vs_zarr_parse_metadata(metadata_buf, &metadata)) {
return 1;
}
void* compressed_buf;
strncpy(url,"https://dl.ash2txt.org/community-uploads/bruniss/Fiber-and-Surface-Models/GP-Predictions/updated_zarrs/mask-2ext-surface_ome.zarr/0/50/30/30",1023);
long compressed_size;
if ((compressed_size = vs_download(url, &compressed_buf)) <= 0) {
printf("downloading %s\n",zarr_block_url);
if ((compressed_size = vs_download(zarr_block_url, &compressed_buf)) <= 0) {
return 1;
}
printf("decompressing zarr chunk\n");
mychunk = vs_zarr_decompress_chunk(compressed_size, compressed_buf,metadata);
if (mychunk == NULL) {
return 1;
}
printf("rescaling zarr chunk\n");
chunk* rescaled = vs_normalize_chunk(mychunk);
s32 vertex_count, index_count;
f32 *vertices;
s32 *indices;

if (vs_march_cubes(mychunk->data,mychunk->dims[0],mychunk->dims[1],mychunk->dims[2],.5f,&vertices,&indices,&vertex_count,&index_count)) {
printf("marching cubes on rescaled chunk\n");
if (vs_march_cubes(rescaled->data,rescaled->dims[0],rescaled->dims[1],rescaled->dims[2],.5f,&vertices,&indices,&vertex_count,&index_count)) {
return 1;
}

printf("writing mesh to out_surface.ply\n");
if (vs_ply_write("out_surface.ply",vertices,NULL,indices,vertex_count,index_count)) {
return 1;
}
Expand Down
Loading

0 comments on commit 53f4615

Please sign in to comment.