sandbox/Antoonvh/tree/realtree.c
A “realistic” tree in Basilisk
Based on in-house laser-scanner data (in collaboration with Adriaan van Natijne) we aim to model a tree using the QSM tree model code. We check how a tree gets represented as an embedded boundary in Basilisk.
A Tree resonstruction with branches color-coded according to their radius. I did not realize TU Delft’s Mekel Park is so ugly:
There is room for improvement.
#include "grid/octree.h"
#include "embed.h"
#include "treegen.h"
#include "view.h"
scalar J[];
int maxlevel = 10;
#define SIZEOFBRANCH (60) //!= sizeof(branch)
int main () {
Branch * branches;
FILE * fp = fopen ("realtree.branches", "rb");
(fp, 0, SEEK_END);
fseek int size = ftell (fp); // get file size
(fp, 0, SEEK_SET);
fseek assert (!(size % SIZEOFBRANCH)); //check filesize
= size/SIZEOFBRANCH;
nb printf ("The tree consists of %d segments\n", nb);
= (Branch*) malloc (sizeof(Branch)*nb);
branches for (int i = 0; i < nb; i++){
Branch branch;
(&branch, SIZEOFBRANCH, 1, fp);
fread = {50, 19, 0};
coord trans foreach_dimension() {
.start.x -= trans.x;
branch.end.x -= trans.x;
branch}
[i] = branch;
branches}
printf ("Read the branch data: 100%%\n");
= 20;
L0 = -5.;
X0 = -10;
Y0 = 0;
Z0 (128);
init_grid printf ("Reconstruction..\nIt.\tCells\tMax. level\n");
for (int i = 0; i <= 5 ; i++) {
tree_interface (branches, cs, fs);
boundary ({cs});
({cs}, (double[]){0.001}, maxlevel);
adapt_wavelet printf ("%d\t%ld\t%d\n", i , grid->n, grid->maxdepth);
}
tree_interface (branches, cs, fs, J);
fractions_cleanup (cs, fs);
printf ("Generating image\n");
foreach()
[] = branches[(int)(J[] + 0.5)].R;
Jview (fov = 24, quat = {0.632164,0.374264,0.346885,0.583067},
= 0.0840115, ty = -0.372052, bg = {0.3,0.4,0.6},
tx = 1600, height = 1600, samples = 2);
width draw_vof ("cs", "fs", color = "J");
box();
save ("tree.png");
free (branches);
}