htrdr

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

commit d2c338c4ff5ee08ad98e741697a83d6aef409bae
parent 25358506f9851f165da5c80298d62c696e974aa8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  8 Sep 2020 12:38:52 +0200

Begin the implementation of the flux map sensor

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/htrdr.c | 34+++++++++++++++++++++++++++++-----
Msrc/htrdr.h | 3++-
Msrc/htrdr_args.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/htrdr_args.h.in | 3+++
Asrc/htrdr_sensor.h | 32++++++++++++++++++++++++++++++++
6 files changed, 133 insertions(+), 8 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -117,6 +117,7 @@ set(HTRDR_FILES_INC htrdr_mtl.h htrdr_ran_wlen.h htrdr_rectangle.h + htrdr_sensor.h htrdr_slab.h htrdr_spectral.h htrdr_sun.h diff --git a/src/htrdr.c b/src/htrdr.c @@ -389,6 +389,34 @@ error: goto exit; } +static res_T +setup_sensor(struct htrdr* htrdr, const struct htrdr_args* args) +{ + double proj_ratio; + res_T res = RES_OK; + ASSERT(htrdr && args); + + htrdr->sensor.type = args->sensor_type; + + switch(args->sensor_type) { + case HTRDR_SENSOR_CAMERA: + proj_ratio = + (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_y), + &htrdr->sensor.camera); + break; + case HTRDR_SENSOR_RECTANGLE: + res = htrdr_rectangle_create(htrdr, args->rectangle.sz, + args->rectangle.pos, args->rectangle.tgt, args->rectangle.up, + &htrdr->sensor.rectangle); + break; + default: FATAL("Unreachable code.\n"); break; + } + return res; +} + /******************************************************************************* * Local functions ******************************************************************************/ @@ -475,11 +503,7 @@ htrdr_init &htrdr->ground); if(res != RES_OK) goto error; - proj_ratio = - (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_y), &htrdr->cam); + res = setup_sensor(htrdr, args); if(res != RES_OK) goto error; res = htrdr_sun_create(htrdr, &htrdr->sun); diff --git a/src/htrdr.h b/src/htrdr.h @@ -17,6 +17,7 @@ #ifndef HTRDR_H #define HTRDR_H +#include "htrdr_sensor.h" #include "htrdr_spectral.h" #include <rsys/logger.h> @@ -54,7 +55,7 @@ struct htrdr { struct htrdr_cie_xyz* cie; struct htrdr_ran_wlen* ran_wlen; - struct htrdr_camera* cam; + struct htrdr_sensor sensor; struct htrdr_buffer* buf; struct htsky* sky; diff --git a/src/htrdr_args.c b/src/htrdr_args.c @@ -71,6 +71,8 @@ print_help(const char* cmd) " -o OUTPUT file where data are written. If not defined, data are\n" " written to standard output.\n"); printf( +" -p <plane> define a plane sensor.\n"); + printf( " -R infinitely repeat the ground along the X and Y axis.\n"); printf( " -r infinitely repeat the clouds along the X and Y axis.\n"); @@ -261,6 +263,62 @@ error: } static res_T +parse_rectangle_parameter(struct htrdr_args* args, const char* str) +{ + char buf[128]; + char* key; + char* val; + char* ctx; + res_T res = RES_OK; + ASSERT(args); + + if(strlen(str) >= sizeof(buf) -1/*NULL char*/) { + fprintf(stderr, + "Could not duplicate the rectangle option string `%s'.\n", str); + res = RES_MEM_ERR; + goto error; + } + strncpy(buf, str, sizeof(buf)); + + /* pos=0,0,10.1; key <- pos, val <- 0,0,10 */ + key = strtok_r(buf, "=", &ctx); + val = strtok_r(NULL, "", &ctx); + + if(!val) { + fprintf(stderr, "Missing value to the rectangle option `%s'.\n", key); + res = RES_BAD_ARG; + goto error; + } + + #define PARSE(Name, Func) { \ + if(RES_OK != (res = Func)) { \ + fprintf(stderr, "Invalid rectangle "Name" `%s'.\n", val); \ + goto error; \ + } \ + } (void)0 + if(!strcmp(key, "pos")) { + PARSE("position", parse_doubleX(val, args->rectangle.pos, 3)); + } else if(!strcmp(key, "tgt")) { + PARSE("target", parse_doubleX(val, args->rectangle.tgt, 3)); + } else if(!strcmp(key, "up")) { + PARSE("up vector", parse_doubleX(val, args->rectangle.up, 3)); + } else if(!strcmp(key, "sz")) { + PARSE("size", parse_doubleX(val, args->rectangle.sz, 2)); + } else { + fprintf(stderr, "Invalid rectangle parameter `%s'.\n", key); + res = RES_BAD_ARG; + goto error; + } + #undef PARSE +exit: + return res; +error: + goto exit; +} + + + +static res_T parse_spectral_range(const char* str, double wlen_range[2]) { double range[2]; @@ -471,10 +529,11 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) } } - while((opt = getopt(argc, argv, "a:C:c:D:dfg:hi:M:m:O:o:Rrs:T:t:V:v")) != -1) { + while((opt = getopt(argc, argv, "a:C:c:D:dfg:hi:M:m:O:o:p:Rrs:T:t:V:v")) != -1) { switch(opt) { case 'a': args->filename_gas = optarg; break; case 'C': + args->sensor_type = HTRDR_SENSOR_CAMERA; res = parse_multiple_parameters (args, optarg, parse_camera_parameter); break; @@ -496,6 +555,11 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) case 'm': args->filename_mie = optarg; break; case 'O': args->cache = optarg; break; case 'o': args->output = optarg; break; + case 'p': + args->sensor_type = HTRDR_SENSOR_RECTANGLE; + res = parse_multiple_parameters + (args, optarg, parse_rectangle_parameter); + break; case 'r': args->repeat_clouds = 1; break; case 'R': args->repeat_ground = 1; break; case 's': @@ -544,7 +608,7 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) /* Setup default ref temperature if necessary */ if(args->ref_temperature <= 0) { switch(args->spectral_type) { - case HTRDR_SPECTRAL_LW: + case HTRDR_SPECTRAL_LW: args->ref_temperature = HTRDR_DEFAULT_LW_REF_TEMPERATURE; break; case HTRDR_SPECTRAL_SW: diff --git a/src/htrdr_args.h.in b/src/htrdr_args.h.in @@ -16,6 +16,7 @@ #ifndef HTRDR_ARGS_H #define HTRDR_ARGS_H +#include "htrdr_sensor.h" #include "htrdr_spectral.h" #include "htrdr_cie_xyz.h" @@ -60,6 +61,7 @@ struct htrdr_args { double wlen_range[2]; /* Spectral range of integration in nm */ double ref_temperature; /* Planck reference temperature in Kelvin */ + enum htrdr_sensor_type sensor_type; unsigned nthreads; /* Hint on the number of threads to use */ int force_overwriting; int dump_vtk; /* Dump the loaded cloud properties in a VTK file */ @@ -98,6 +100,7 @@ struct htrdr_args { HTRDR_SPECTRAL_SW_CIE_XYZ, /* Spectral type */ \ HTRDR_CIE_XYZ_RANGE_DEFAULT__, /* Spectral range */ \ -1, /* Reference temperature */ \ + HTRDR_SENSOR_CAMERA, /* sensor type */ \ (unsigned)~0, /* #threads */ \ 0, /* Force overwriting */ \ 0, /* dump VTK */ \ diff --git a/src/htrdr_sensor.h b/src/htrdr_sensor.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2018, 2019, 2020 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2018, 2019 CNRS, Université Paul Sabatier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef HTRDR_SENSOR_H +#define HTRDR_SENSOR_H + +enum htrdr_sensor_type { + HTRDR_SENSOR_CAMERA, + HTRDR_SENSOR_RECTANGLE +}; + +struct htrdr_sensor { + struct htrdr_camera* camera; + struct htrdr_rectangle* rectangle; + enum htrdr_sensor_type type; +}; + +#endif /* HTRDR_SENSOR_H */ +