htrdr

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

commit ba67b269f7c2c490fad95741928bf266113202a9
parent 162882802f54460443f96134e4be8a49d90b2f2c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 28 Oct 2022 08:59:37 +0200

htrdr-planeto: add image options and configure render buffer

Diffstat:
Msrc/planeto/htrdr_planeto.c | 65++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/planeto/htrdr_planeto_args.c | 7++++++-
Msrc/planeto/htrdr_planeto_args.h | 2++
Msrc/planeto/htrdr_planeto_c.h | 41+++++++++++++++++++++++++++++++++++++++++
4 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/src/planeto/htrdr_planeto.c b/src/planeto/htrdr_planeto.c @@ -212,6 +212,41 @@ error: goto exit; } +static res_T +setup_buffer + (struct htrdr_planeto* cmd, + const struct htrdr_planeto_args* args) +{ + struct htrdr_pixel_format pixfmt = HTRDR_PIXEL_FORMAT_NULL; + res_T res = RES_OK; + ASSERT(cmd && args); + + if(cmd->output != HTRDR_PLANETO_ARGS_OUTPUT_IMAGE) + goto exit; + + planeto_get_pixel_format(cmd, &pixfmt); + + /* Setup buffer layout */ + cmd->buf_layout.width = args->image.definition[0]; + cmd->buf_layout.height = args->image.definition[1]; + cmd->buf_layout.pitch = args->image.definition[0] * pixfmt.size; + cmd->buf_layout.elmt_size = pixfmt.size; + cmd->buf_layout.alignment = pixfmt.alignment; + + /* Create the image buffer only on the master process; Image parts rendered + * by other processes are collected there */ + if(htrdr_get_mpi_rank(cmd->htrdr) != 0) goto exit; + + res = htrdr_buffer_create(cmd->htrdr, &cmd->buf_layout, &cmd->buf); + if(res != RES_OK) goto error; + +exit: + return res; +error: + if(cmd->buf) { htrdr_buffer_ref_put(cmd->buf); cmd->buf = NULL; } + goto exit; +} + static INLINE res_T write_vtk_octrees(const struct htrdr_planeto* cmd) { @@ -246,6 +281,7 @@ planeto_release(ref_T* ref) if(cmd->ground) RNGRD(ref_put(cmd->ground)); if(cmd->octrees_storage) CHK(fclose(cmd->octrees_storage) == 0); if(cmd->output && cmd->output != stdout) CHK(fclose(cmd->output) == 0); + if(cmd->buf) htrdr_buffer_ref_put(cmd->buf); str_release(&cmd->output_name); htrdr = cmd->htrdr; @@ -288,6 +324,8 @@ htrdr_planeto_create if(res != RES_OK) goto error; res = setup_spectral_domain(cmd, args); if(res != RES_OK) goto error; + res = setup_buffer(cmd, args); + if(res != RES_OK) goto error; res = setup_ground(cmd, args); if(res != RES_OK) goto error; res = setup_atmosphere(cmd, args); @@ -331,7 +369,7 @@ htrdr_planeto_run(struct htrdr_planeto* cmd) case HTRDR_PLANETO_ARGS_OUTPUT_OCTREES: res = write_vtk_octrees(cmd); break; - default: FATAL("Unreachable code.\n"); break; + default: FATAL("Unreachable code\n"); break; } if(res != RES_OK) goto error; @@ -340,3 +378,28 @@ exit: error: goto exit; } + +/******************************************************************************* + * Local function + ******************************************************************************/ +void +planeto_get_pixel_format + (const struct htrdr_planeto* cmd, + struct htrdr_pixel_format* fmt) +{ + ASSERT(cmd && fmt && cmd->output_type == HTRDR_PLANETO_ARGS_OUTPUT_IMAGE); + (void)cmd; + + switch(cmd->spectral_domain.spectral_type) { + case HTRDR_SPECTRAL_LW: + case HTRDR_SPECTRAL_SW: + fmt->size = sizeof(struct planeto_pixel_xwave); + fmt->alignment = ALIGNOF(struct planeto_pixel_xwave); + break; + case HTRDR_SPECTRAL_SW_CIE_XYZ: + fmt->size = sizeof(struct planeto_pixel_image); + fmt->alignment = ALIGNOF(struct planeto_pixel_image); + break; + default: FATAL("Unreachable code\n"); break; + } +} diff --git a/src/planeto/htrdr_planeto_args.c b/src/planeto/htrdr_planeto_args.c @@ -125,6 +125,8 @@ print_help(const char* cmd) printf( " -h display this help and exit\n"); printf( +" -i image image to compute\n"); + printf( " -O octrees_storage\n" " file where atmospheric acceleration structures are\n" " stored/loaded\n"); @@ -474,7 +476,7 @@ htrdr_planeto_args_init(struct htrdr_planeto_args* args, int argc, char** argv) *args = HTRDR_PLANETO_ARGS_DEFAULT; - while((opt = getopt(argc, argv, "a:dfG:g:hO:o:S:s:T:t:V:v")) != -1) { + while((opt = getopt(argc, argv, "a:dfG:g:hi:O:o:S:s:T:t:V:v")) != -1) { switch(opt) { case 'a': sa_add(args->aerosols, 1); @@ -508,6 +510,9 @@ htrdr_planeto_args_init(struct htrdr_planeto_args* args, int argc, char** argv) htrdr_planeto_args_release(args); args->quit = 1; goto exit; + case 'i': + res = htrdr_args_image_parse(&args->image, optarg); + break; case 'O': args->octrees_storage = optarg; break; case 'o': args->output = optarg; break; case 'S': diff --git a/src/planeto/htrdr_planeto_args.h b/src/planeto/htrdr_planeto_args.h @@ -69,6 +69,7 @@ struct htrdr_planeto_args { char* output; /* File where the result is written */ struct htrdr_args_spectral spectral_domain; /* Integration spectral domain */ struct htrdr_planeto_source_args source; + struct htrdr_args_image image; /* Miscellaneous arguments */ unsigned nthreads; /* Hint on the nimber of threads to use */ @@ -91,6 +92,7 @@ struct htrdr_planeto_args { NULL, /* Ouput file */ \ HTRDR_ARGS_SPECTRAL_DEFAULT__, /* Spectral domain */ \ HTRDR_PLANETO_SOURCE_ARGS_NULL__, /* Source */ \ + HTRDR_ARGS_IMAGE_DEFAULT__, /* Image */ \ \ UINT_MAX, /* Number of threads */ \ HTRDR_PLANETO_ARGS_OUTPUT_IMAGE, \ diff --git a/src/planeto/htrdr_planeto_c.h b/src/planeto/htrdr_planeto_c.h @@ -20,19 +20,51 @@ #include "planeto/htrdr_planeto_args.h" +#include "core/htrdr_accum.h" #include "core/htrdr_args.h" +#include "core/htrdr_buffer.h" #include <rsys/ref_count.h> #include <rsys/str.h> /* Forward declarations */ struct htrdr; +struct htrdr_pixel_format; struct rnatm; struct rngrd; +struct planeto_pixel_xwave { + struct htrdr_estimate radiance; /* In W/m²/sr */ + struct htrdr_estimate radiance_temperature; /* In W/m²/sr */ + struct htrdr_accum time; /* In µs */ +}; +#define PLANETO_PIXEL_XWAVE_NULL__ { \ + HTRDR_ESTIMATE_NULL__, \ + HTRDR_ESTIMATE_NULL__, \ + HTRDR_ACCUM_NULL__ \ +} +static const struct planeto_pixel_xwave PLANETO_PIXEL_XWAVE_NULL = + PLANETO_PIXEL_XWAVE_NULL__; + +struct planeto_pixel_image { + struct htrdr_estimate X; /* In W/m²/sr */ + struct htrdr_estimate Y; /* In W/m²/sr */ + struct htrdr_estimate Z; /* In W/m²/sr */ + struct htrdr_accum time; /* In µs */ +}; +#define PLANETO_PIXEL_IMAGE_NULL__ { \ + HTRDR_ESTIMATE_NULL__, \ + HTRDR_ESTIMATE_NULL__, \ + HTRDR_ESTIMATE_NULL__, \ + HTRDR_ACCUM_NULL__ \ +} + +struct planeto_pixel_xwave; + struct htrdr_planeto { struct rnatm* atmosphere; struct rngrd* ground; + struct htrdr_planeto_source* source; struct htrdr_args_spectral spectral_domain; @@ -42,8 +74,17 @@ struct htrdr_planeto { struct str output_name; enum htrdr_planeto_args_output_type output_type; + struct htrdr_buffer_layout buf_layout; + struct htrdr_buffer* buf; /* NULL on non master processes */ + size_t spp; /* Samples per pixel */ + ref_T ref; struct htrdr* htrdr; }; +extern LOCAL_SYM void +planeto_get_pixel_format + (const struct htrdr_planeto* cmd, + struct htrdr_pixel_format* fmt); + #endif /* HTRDR_PLANETO_C_H */