This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.c
121 lines (102 loc) · 5.09 KB
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#define VESUVIUS_IMPL
#include "vesuvius-c.h"
#include <stdio.h>
int main() {
// Initialize the library
const char *scroll_id = "1";
const int energy = 54;
const double resolution = 7.91;
init_vesuvius(scroll_id, energy, resolution);
// Read a single value from the scroll volume
unsigned char value;
int x = 3693, y = 2881, z = 6777;
if (get_volume_voxel(x, y, z, &value) == 0) {
printf("Voxel value at (%d, %d, %d): %u\n", x, y, z, value);
}
// value <- 83
// Define a region of interest in the scroll volume
RegionOfInterest roi = {
.x_start = 3456, .y_start = 3256, .z_start = 6521,
.x_width = 256, .y_height = 256, .z_depth = 256,
};
// Fetch this region of interest into a local 3D volume
unsigned char *volume = (unsigned char *)malloc(roi.x_width * roi.y_height * roi.z_depth);
if (get_volume_roi(roi, volume) == 0) {
printf("Filled volume ROI: %d+%d, %d+%d, %d+%d\n", roi.x_start, roi.x_width, roi.y_start, roi.y_height, roi.z_start, roi.z_depth);
}
// Fetch the same region again (will come from the cache this time)
unsigned char *volume2 = (unsigned char *)malloc(roi.x_width * roi.y_height * roi.z_depth);
if (get_volume_roi(roi, volume2) == 0) {
printf("Filled volume ROI from cache: %d+%d, %d+%d, %d+%d\n", roi.x_start, roi.x_width, roi.y_start, roi.y_height, roi.z_start, roi.z_depth);
}
free(volume2);
// Write the three orthogonal slice planes from the region of interest
unsigned char *xy_slice = (unsigned char *)malloc(roi.x_width * roi.y_height);
int middle_z = roi.z_depth / 2;
for (int y = 0; y < roi.y_height; y++) {
for (int x = 0; x < roi.x_width; x++) {
xy_slice[y * roi.x_width + x] = volume[middle_z * roi.x_width * roi.y_height + y * roi.x_width + x];
}
}
write_bmp("xy_slice.bmp", xy_slice, roi.x_width, roi.y_height);
free(xy_slice);
unsigned char *xz_slice = (unsigned char *)malloc(roi.x_width * roi.z_depth);
int middle_y = roi.y_height / 2;
for (int z = 0; z < roi.z_depth; z++) {
for (int x = 0; x < roi.x_width; x++) {
xz_slice[z * roi.x_width + x] = volume[z * roi.y_height * roi.x_width + middle_y * roi.x_width + x];
}
}
write_bmp("xz_slice.bmp", xz_slice, roi.x_width, roi.z_depth);
free(xz_slice);
unsigned char *yz_slice = (unsigned char *)malloc(roi.y_height * roi.z_depth);
int middle_x = roi.x_width / 2;
for (int z = 0; z < roi.z_depth; z++) {
for (int y = 0; y < roi.y_height; y++) {
yz_slice[z * roi.y_height + y] = volume[z * roi.y_height * roi.x_width + y * roi.x_width + middle_x];
}
}
write_bmp("yz_slice.bmp", yz_slice, roi.y_height, roi.z_depth);
free(yz_slice);
// Fetch a slice plane from the volume (region of interest with a depth of 1)
// This is identical to the xy_slice taken from the above region of interest
unsigned char *slice = (unsigned char *)malloc(roi.x_width * roi.y_height);
roi.z_start = roi.z_start + middle_z;
roi.z_depth = 1;
if (get_volume_slice(roi, slice) == 0) {
printf("Filled volume slice: %d+%d, %d+%d, %d\n", roi.x_start, roi.x_width, roi.y_start, roi.y_height, roi.z_start);
}
write_bmp("slice.bmp", slice, roi.x_width, roi.y_height);
free(slice);
free(volume);
//////////////////////////////////////////////////////////////////////////////////
// The below are examples of in-progress functionality that is not yet complete //
//////////////////////////////////////////////////////////////////////////////////
// Fetch an .obj
TriangleMesh mesh;
const char *segment_id = "20231016151002";
if (get_triangle_mesh(segment_id, &mesh) == 0) {
printf("Fetched triangle mesh with %zu vertices and %zu triangles\n", mesh.vertex_count, mesh.triangle_count);
}
// Write the triangle mesh to an .obj file
char filename[256];
snprintf(filename, sizeof(filename), "%s.obj", segment_id);
if (write_trianglemesh_to_obj(filename, &mesh) == 0) {
printf("Wrote triangle mesh to: %s\n", filename);
}
// Calculate the bounding box of the triangle mesh
RegionOfInterest mesh_bbox = get_mesh_bounding_box(&mesh);
printf("Bounding box of the triangle mesh: %d+%d, %d+%d, %d+%d\n", mesh_bbox.x_start, mesh_bbox.x_width, mesh_bbox.y_start, mesh_bbox.y_height, mesh_bbox.z_start, mesh_bbox.z_depth);
// Get a 256x256x256 volume centered around 2900, 4970, 12900
RegionOfInterest mesh_roi = {
.x_start = 2900 - 128, .y_start = 4970 - 128, .z_start = 12900 - 128,
.x_width = 256, .y_height = 256, .z_depth = 256,
};
unsigned char *mesh_volume = (unsigned char *)malloc(mesh_roi.x_width * mesh_roi.y_height * mesh_roi.z_depth);
if (get_volume_roi(mesh_roi, mesh_volume) == 0) {
printf("Filled volume ROI around triangle mesh: %d+%d, %d+%d, %d+%d\n", mesh_roi.x_start, mesh_roi.x_width, mesh_roi.y_start, mesh_roi.y_height, mesh_roi.z_start, mesh_roi.z_depth);
}
// Reset mesh origin to the ROI
reset_mesh_origin_to_roi(&mesh, &mesh_roi);
return 0;
}