htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

commit 2ecfccbc66376507399baf8e67446d01afa322d9
parent 4b65fff58c05213ba751fb38cdba6eecff732e55
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 27 Sep 2018 16:05:46 +0200

Upd the fov argument and and the '-T optical_thickness' option

The fov is now horizontal.

Diffstat:
Mdoc/cli.txt | 2+-
Msrc/htrdr.c | 5+++--
Msrc/htrdr_args.c | 12++++++++++--
Msrc/htrdr_args.h | 4+++-
Msrc/htrdr_camera.c | 10+++-------
Msrc/htrdr_sky.c | 31+++++++++++++++++++++++--------
Msrc/htrdr_sky.h | 1+
7 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/doc/cli.txt b/doc/cli.txt @@ -9,7 +9,7 @@ <camopt> ::= <target> | <position> | <up> - | <fov> + | <fov> # Vertical field of view, in degrees <target> ::= tgt=<float3> <position> ::= pos=<float3> <up> ::= up=<float3> diff --git a/src/htrdr.c b/src/htrdr.c @@ -260,7 +260,7 @@ htrdr_init (double)args->image.definition[0] / (double)args->image.definition[1]; res = htrdr_camera_create(htrdr, args->camera.pos, args->camera.tgt, - args->camera.up, proj_ratio, MDEG2RAD(args->camera.fov_x), &htrdr->cam); + args->camera.up, proj_ratio, MDEG2RAD(args->camera.fov_y), &htrdr->cam); if(res != RES_OK) goto error; res = htrdr_buffer_create(htrdr, @@ -277,7 +277,8 @@ htrdr_init htrdr_sun_set_direction(htrdr->sun, args->main_dir); res = htrdr_sky_create(htrdr, htrdr->sun, args->filename_les, - args->filename_gas, args->filename_mie, &htrdr->sky); + args->filename_gas, args->filename_mie, args->optical_thickness, + &htrdr->sky); if(res != RES_OK) goto error; htrdr->lifo_allocators = MEM_CALLOC diff --git a/src/htrdr_args.c b/src/htrdr_args.c @@ -58,6 +58,10 @@ print_help(const char* cmd) " -t THREADS hint on the number of threads to use. By default use as\n" " many threads as CPU cores.\n"); printf( +" -T THRESHOLD optical thickness used as threshold during the octree\n" +" building. By default its value is `%g'.\n", + HTRDR_ARGS_DEFAULT.optical_thickness); + printf( " -v make the program more verbose.\n"); printf("\n"); printf( @@ -211,7 +215,7 @@ parse_camera_parameter(struct htrdr_args* args, const char* str) } else if(!strcmp(key, "up")) { PARSE("up vector", parse_doubleX(val, args->camera.up, 3)); } else if(!strcmp(key, "fov")) { - PARSE("field-of-view", parse_fov(val, &args->camera.fov_x)); + PARSE("field-of-view", parse_fov(val, &args->camera.fov_y)); } else { fprintf(stderr, "Invalid camera parameter `%s'.\n", key); res = RES_BAD_ARG; @@ -294,7 +298,7 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) *args = HTRDR_ARGS_DEFAULT; - while((opt = getopt(argc, argv, "a:C:c:D:dfg:hi:m:o:t:v")) != -1) { + while((opt = getopt(argc, argv, "a:C:c:D:dfg:hi:m:o:T:t:v")) != -1) { switch(opt) { case 'a': args->filename_gas = optarg; break; case 'C': @@ -317,6 +321,10 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) break; case 'm': args->filename_mie = optarg; break; case 'o': args->output = optarg; break; + case 'T': + res = cstr_to_double(optarg, &args->optical_thickness); + if(res == RES_OK && args->optical_thickness < 0) res = RES_BAD_ARG; + break; case 't': /* Submit an hint on the number of threads to use */ res = cstr_to_uint(optarg, &args->nthreads); if(res == RES_OK && !args->nthreads) res = RES_BAD_ARG; diff --git a/src/htrdr_args.h b/src/htrdr_args.h @@ -36,7 +36,7 @@ struct htrdr_args { double pos[3]; double tgt[3]; double up[3]; - double fov_x; /* In degrees */ + double fov_y; /* In degrees */ } camera; struct { @@ -45,6 +45,7 @@ struct htrdr_args { } image; double main_dir[3]; + double optical_thickness; /* Threshold used during octree building */ unsigned nthreads; /* Hint on the number of threads to use */ int force_overwriting; @@ -74,6 +75,7 @@ struct htrdr_args { 1 /* #samples per pixel */ \ }, \ {0, 0, 1}, /* Main direction */ \ + 1.0, /* Optical thickness */ \ (unsigned)~0, /* #threads */ \ 0, /* Force overwriting */ \ 0, /* dump VTK */ \ diff --git a/src/htrdr_camera.c b/src/htrdr_camera.c @@ -27,8 +27,6 @@ struct htrdr_camera { double axis_z[3]; double position[3]; - double fov_x; /* Field of view in radians */ - double rcp_proj_ratio; /* height / width */ ref_T ref; struct htrdr* htrdr; @@ -79,14 +77,12 @@ htrdr_camera_create res = RES_BAD_ARG; goto error; } - cam->fov_x = fov; if(proj_ratio <= 0) { htrdr_log_err(htrdr, "invalid projection ratio `%g'\n", proj_ratio); res = RES_BAD_ARG; goto error; } - cam->rcp_proj_ratio = 1.0 / proj_ratio; if(d3_normalize(z, d3_sub(z, target, position)) <= 0 || d3_normalize(x, d3_cross(x, z, up)) <= 0 @@ -101,9 +97,9 @@ htrdr_camera_create goto error; } - img_plane_depth = 1.0/tan(fov); - d3_set(cam->axis_x, x); - d3_muld(cam->axis_y, y, cam->rcp_proj_ratio); + img_plane_depth = 1.0/tan(fov*0.5); + d3_muld(cam->axis_x, x, proj_ratio); + d3_set(cam->axis_y, y); d3_muld(cam->axis_z, z, img_plane_depth); d3_set(cam->position, position); diff --git a/src/htrdr_sky.c b/src/htrdr_sky.c @@ -27,6 +27,7 @@ #include <high_tune/htgop.h> #include <high_tune/htmie.h> +#include <rsys/clock_time.h> #include <rsys/dynamic_array_double.h> #include <rsys/dynamic_array_size_t.h> #include <rsys/hash_table.h> @@ -960,6 +961,7 @@ setup_clouds const char* htcp_filename, const char* htgop_filename, const char* htmie_filename, + const double optical_thickness_threshold, const int force_cache_update) { struct svx_voxel_desc vox_desc = SVX_VOXEL_DESC_NULL; @@ -970,7 +972,7 @@ setup_clouds size_t nbands; size_t i; res_T res = RES_OK; - ASSERT(sky && sky->sw_bands); + ASSERT(sky && sky->sw_bands && optical_thickness_threshold >= 0); res = htcp_get_desc(sky->htcp, &sky->htcp_desc); if(res != RES_OK) { @@ -1032,7 +1034,7 @@ setup_clouds /* Setup the build context */ ctx.sky = sky; - ctx.tau_threshold = 1; + ctx.tau_threshold = optical_thickness_threshold; ctx.vxsz[0] = sky->htcp_desc.upper[0] - sky->htcp_desc.lower[0]; ctx.vxsz[1] = sky->htcp_desc.upper[1] - sky->htcp_desc.lower[1]; ctx.vxsz[2] = sky->htcp_desc.upper[2] - sky->htcp_desc.lower[2]; @@ -1203,7 +1205,8 @@ atmosphere_vox_challenge_merge } static res_T -setup_atmosphere(struct htrdr_sky* sky) +setup_atmosphere + (struct htrdr_sky* sky, const double optical_thickness_threshold) { struct build_tree_context ctx = BUILD_TREE_CONTEXT_NULL; struct htgop_level lvl_low, lvl_upp; @@ -1214,7 +1217,7 @@ setup_atmosphere(struct htrdr_sky* sky) size_t nbands; size_t i; res_T res = RES_OK; - ASSERT(sky); + ASSERT(sky && optical_thickness_threshold >= 0); HTGOP(get_layers_count(sky->htgop, &nlayers)); HTGOP(get_levels_count(sky->htgop, &nlevels)); @@ -1226,7 +1229,7 @@ setup_atmosphere(struct htrdr_sky* sky) /* Setup the build context */ ctx.sky = sky; - ctx.tau_threshold = 1; + ctx.tau_threshold = optical_thickness_threshold; ctx.vxsz[0] = INF; ctx.vxsz[1] = INF; ctx.vxsz[2] = (upp-low)/(double)definition; @@ -1404,15 +1407,19 @@ htrdr_sky_create const char* htcp_filename, const char* htgop_filename, const char* htmie_filename, + const double optical_thickness_threshold, struct htrdr_sky** out_sky) { + struct time t0, t1; struct htrdr_sky* sky = NULL; + char buf[128]; int htcp_upd = 1; int htmie_upd = 1; int htgop_upd = 1; int force_upd = 1; res_T res = RES_OK; ASSERT(htrdr && sun && htcp_filename && htmie_filename && out_sky); + ASSERT(optical_thickness_threshold >= 0); sky = MEM_CALLOC(htrdr->allocator, 1, sizeof(*sky)); if(!sky) { @@ -1479,12 +1486,20 @@ htrdr_sky_create if(res != RES_OK) goto error; force_upd = htcp_upd || htmie_upd || htgop_upd; - res = setup_clouds - (sky, htcp_filename, htgop_filename, htmie_filename, force_upd); + time_current(&t0); + res = setup_clouds(sky, htcp_filename, htgop_filename, htmie_filename, + optical_thickness_threshold, force_upd); if(res != RES_OK) goto error; + time_sub(&t0, time_current(&t1), &t0); + time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf)); + htrdr_log(htrdr, "Setup clouds in %s\n", buf); - res = setup_atmosphere(sky); + time_current(&t0); + res = setup_atmosphere(sky, optical_thickness_threshold); if(res != RES_OK) goto error; + time_sub(&t0, time_current(&t1), &t0); + time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf)); + htrdr_log(htrdr, "Setup atmosphere in %s\n", buf); exit: *out_sky = sky; diff --git a/src/htrdr_sky.h b/src/htrdr_sky.h @@ -63,6 +63,7 @@ htrdr_sky_create const char* htcp_filename, const char* htgop_filename, const char* htmie_filename, + const double optical_thickness, /* Threshold used during octree building */ struct htrdr_sky** sky); extern LOCAL_SYM void