htrdr

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

commit 889ee5f91ada926ea8d69a4f2aea662230608fb7
parent 1ab01d2a16c6e10d9e730fa00a6b67663a6adad5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Dec 2019 14:00:49 +0100

Add the -b option to control the type of ground reflections

Diffstat:
Mcmake/CMakeLists.txt | 7+++----
Mdoc/htrdr.1.txt.in | 14+++++++++++---
Msrc/htrdr.c | 2+-
Msrc/htrdr_args.c | 41++++++++++++++++++++++++++++++++++++++++-
Msrc/htrdr_args.h.in | 4++++
Msrc/htrdr_compute_radiance_sw.c | 26+++++++-------------------
6 files changed, 66 insertions(+), 28 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -52,6 +52,7 @@ include_directories( ${HTCP_INCLUDE_DIR} ${HTGOP_INCLUDE_DIR} ${HTMIE_INCLUDE_DIR} + ${HTRDR_SOURCE_DIR} ${MPI_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}) @@ -67,15 +68,13 @@ set(HTRDR_ARGS_DEFAULT_CAMERA_POS "0,0,0") set(HTRDR_ARGS_DEFAULT_CAMERA_TGT "0,1,0") set(HTRDR_ARGS_DEFAULT_CAMERA_UP "0,0,1") set(HTRDR_ARGS_DEFAULT_CAMERA_FOV "70") +set(HTRDR_ARGS_DEFAULT_GROUND_BSDF "HTRDR_BSDF_DIFFUSE") +set(HTRDR_ARGS_DEFAULT_GROUND_REFLECTIVITY "0.5") set(HTRDR_ARGS_DEFAULT_IMG_WIDTH "320") set(HTRDR_ARGS_DEFAULT_IMG_HEIGHT "240") set(HTRDR_ARGS_DEFAULT_IMG_SPP "1") -set(HTRDR_ARGS_DEFAULT_GROUND_REFLECTIVITY "0.5") set(HTRDR_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD "1") -configure_file(${HTRDR_SOURCE_DIR}/htrdr_version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/htrdr_version.h @ONLY) - configure_file(${HTRDR_SOURCE_DIR}/htrdr_args.h.in ${CMAKE_CURRENT_BINARY_DIR}/htrdr_args.h @ONLY) diff --git a/doc/htrdr.1.txt.in b/doc/htrdr.1.txt.in @@ -72,9 +72,16 @@ OPTIONS Path toward the file containing the gas optical properties of the atmosphere. Data must be formatted according to the fileformat described in [1]. +*-b* <diffuse|specular>:: + Define how light is reflected at the ground surface. When set to diffuse, the + reflections are lambertian while a specular surface simulates a perfect + mirror. By default, the ground surface is diffuse. Note that this option + controls only the directional part of the surface reflections; the amount of + reflected energy is defined by the *-e* option. + *-c* _clouds_:: Submit a *htcp*(5) file describing the properties of the clouds. If not - defined, only the atmopshere properties submitted through the *-a* option + defined, only the atmosphere properties submitted through the *-a* option are taken into account. *-C* <__camera-parameter__:...>:: @@ -107,7 +114,7 @@ OPTIONS {0,0,+1} regardless of _azimuth_ value. *-d*:: - Write in _output_ the space partitionning data structures used to speed up + Write in _output_ the space partitioning data structures used to speed up the radiative transfer computations in the clouds. The written data are octrees saved in the VTK file format [3]. Each octree node stores the minimum and the maximum of the extinction coefficients of the cloud cells overlapped @@ -117,7 +124,8 @@ OPTIONS *-e* _reflectivity_:: Reflectivity of the ground geometry in [0, 1]. By default it is set to @HTRDR_ARGS_DEFAULT_GROUND_REFLECTIVITY@. This parameter is fixed for the - while visible range. + while visible range and defines the amount of reflected energy. Refer to the + *-b* option to control how the light is reflected on the ground surface. *-f*:: Force overwrite of the _output_ file. diff --git a/src/htrdr.c b/src/htrdr.c @@ -513,7 +513,7 @@ htrdr_init goto error; } - res = htrdr_ground_create(htrdr, args->filename_obj, + res = htrdr_ground_create(htrdr, args->filename_obj, args->ground_bsdf_type, args->ground_reflectivity, args->repeat_ground, &htrdr->ground); if(res != RES_OK) goto error; diff --git a/src/htrdr_args.c b/src/htrdr_args.c @@ -27,6 +27,18 @@ /******************************************************************************* * Helper functions ******************************************************************************/ +static const char* +bsdf_type_to_string(const enum htrdr_bsdf_type type) +{ + const char* str = "<none>"; + switch(type) { + case HTRDR_BSDF_DIFFUSE: str = "diffuse"; break; + case HTRDR_BSDF_SPECULAR: str = "specular"; break; + default: FATAL("Unreachable code.\n"); break; + } + return str; +} + static void print_help(const char* cmd) { @@ -38,6 +50,10 @@ print_help(const char* cmd) printf( " -a ATMOSPHERE gas optical properties of the atmosphere.\n"); printf( +" -b <diffuse|specular>\n" +" BSDF of the ground. Default value is %s.\n", + bsdf_type_to_string(HTRDR_ARGS_DEFAULT.ground_bsdf_type)); + printf( " -c CLOUDS properties of the clouds.\n"); printf( " -C <camera> define the rendering point of view.\n"); @@ -354,6 +370,26 @@ error: goto exit; } +static res_T +parse_bsdf_type(struct htrdr_args* args, const char* str) +{ + res_T res = RES_OK; + if(!strcmp(str, "diffuse")) { + args->ground_bsdf_type = HTRDR_BSDF_DIFFUSE; + } else if(!strcmp(str, "specular")) { + args->ground_bsdf_type = HTRDR_BSDF_SPECULAR; + } else { + fprintf(stderr, "Invalid BRDF type `%s'.\n", str); + res = RES_BAD_ARG; + goto error; + } + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * Local functions ******************************************************************************/ @@ -378,9 +414,12 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) } } - while((opt = getopt(argc, argv, "a:C:c:D:de:fGg:hi:m:o:RrT:t:V:v")) != -1) { + while((opt = getopt(argc, argv, "a:b:C:c:D:de:fGg:hi:m:o:RrT:t:V:v")) != -1) { switch(opt) { case 'a': args->filename_gas = optarg; break; + case 'b': + res = parse_bsdf_type(args, optarg); + break; case 'C': res = parse_multiple_parameters (args, optarg, parse_camera_parameter); diff --git a/src/htrdr_args.h.in b/src/htrdr_args.h.in @@ -16,6 +16,8 @@ #ifndef HTRDR_ARGS_H #define HTRDR_ARGS_H +#include "htrdr_ground.h" + #include <limits.h> #include <rsys/rsys.h> @@ -48,6 +50,7 @@ struct htrdr_args { double sun_azimuth; /* In degrees */ double sun_elevation; /* In degrees */ double optical_thickness; /* Threshold used during octree building */ + enum htrdr_bsdf_type ground_bsdf_type; double ground_reflectivity; /* Reflectivity of the ground */ unsigned grid_max_definition[3]; /* Maximum definition of the grid */ @@ -84,6 +87,7 @@ struct htrdr_args { 0, /* Sun azimuth */ \ 90, /* Sun elevation */ \ @HTRDR_ARGS_DEFAULT_OPTICAL_THICKNESS_THRESHOLD@, /* Optical thickness */ \ + @HTRDR_ARGS_DEFAULT_GROUND_BSDF@, \ @HTRDR_ARGS_DEFAULT_GROUND_REFLECTIVITY@, /* Ground reflectivity */ \ {UINT_MAX, UINT_MAX, UINT_MAX}, /* Maximum definition of the grid */ \ (unsigned)~0, /* #threads */ \ diff --git a/src/htrdr_compute_radiance_sw.c b/src/htrdr_compute_radiance_sw.c @@ -283,29 +283,14 @@ htrdr_compute_radiance_sw CHK(RES_OK == ssf_phase_create (&htrdr->lifo_allocators[ithread], &ssf_phase_rayleigh, &phase_rayleigh)); -#if 0 - CHK(RES_OK == ssf_bsdf_create - (&htrdr->lifo_allocators[ithread], &ssf_lambertian_reflection, &bsdf)); - SSF(lambertian_reflection_setup - (bsdf, htrdr_ground_get_reflectivity(htrdr->ground))); -#else - CHK(RES_OK == ssf_bsdf_create - (&htrdr->lifo_allocators[ithread], &ssf_specular_reflection, &bsdf)); - { - struct ssf_fresnel* fresnel; - SSF(fresnel_create - (&htrdr->lifo_allocators[ithread], &ssf_fresnel_dielectric_dielectric, &fresnel)); - SSF(fresnel_dielectric_dielectric_setup(fresnel, 1.0, 1.33)); - SSF(specular_reflection_setup(bsdf, fresnel)); - SSF(fresnel_ref_put(fresnel)); - } -#endif - /* Setup the phase function for this spectral band & quadrature point */ g = htrdr_sky_fetch_particle_phase_function_asymmetry_parameter (htrdr->sky, iband, iquad); SSF(phase_hg_setup(phase_hg, g)); + /* Fetch the ground BSDF */ + bsdf = htrdr_ground_get_bsdf(htrdr->ground); + /* Fetch sun properties. Arbitrarily use the wavelength at the center of the * band to retrieve the sun radiance of the current band. Note that the sun * spectral data are defined by bands that, actually are the same of the SW @@ -410,6 +395,10 @@ htrdr_compute_radiance_sw bounce_reflectivity = ssf_bsdf_sample (bsdf, rng, wo, N, dir_next, &type, &pdf); + if(!(type & SSF_REFLECTION)) { /* Handle only reflections */ + bounce_reflectivity = 0; + } + if(d3_dot(N, sun_dir) < 0) { /* Below the ground */ R = 0; } else { @@ -452,7 +441,6 @@ htrdr_compute_radiance_sw d3_set(pos, pos_next); d3_set(dir, dir_next); } - SSF(bsdf_ref_put(bsdf)); SSF(phase_ref_put(phase_hg)); SSF(phase_ref_put(phase_rayleigh)); return w;