commit 673575b0dad37cf21ab42b8b103ab98c74633c4b
parent a582180d1b793317cb648b8c41597f83105ecb1a
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 4 Feb 2021 10:43:53 +0100
Add a file name option for infrared rendering
Diffstat:
5 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/doc/stardis.1.txt.in b/doc/stardis.1.txt.in
@@ -134,12 +134,16 @@ EXCLUSIVE OPTIONS
F_BOUNDARY_FOR_SOLID or SOLID_FLUID_CONNECTION (see *stardis-input*(5)).
*-R* [__sub-option__:...]::
- Render an infrared image of the system through a pinhole camera and write it
- to _standard output_. One can use all-default sub-options by
- simply providing the colon character (*:*) alone as an argument. Please note
- that the camera position must be outside the geometry or in a fluid.
+ Render an infrared image of the system through a pinhole camera. One can use
+ all-default sub-options by simply providing the colon character (*:*) alone
+ as an argument. Please note that the camera position must be outside the
+ geometry or in a fluid.
Available sub-options are:
+ **file=**_output_file_;;
+ File name to use to write the infrared image to. If no file name is
+ provided, the result is written to _standard output_.
+
**fmt=**_image_file_format_;;
Format of the image file in output. Can be *VTK* or *HT*. Default
_image_file_format_ is @STARDIS_ARGS_DEFAULT_RENDERING_OUTPUT_FILE_FMT@.
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -220,7 +220,7 @@ stardis_init
stardis->senc3d_scn = NULL;
stardis->mode = args->mode;
stardis->counts = COUNTS_NULL;
- init_camera(&stardis->camera);
+ init_camera(stardis->allocator, &stardis->camera);
str_init(stardis->allocator, &stardis->solve_name);
str_init(stardis->allocator, &stardis->paths_filename);
str_init(stardis->allocator, &stardis->bin_green_filename);
@@ -430,6 +430,7 @@ stardis_release
SDIS(medium_ref_put(darray_media_ptr_data_get(&stardis->media)[i]));
}
darray_media_ptr_release(&stardis->media);
+ release_camera(&stardis->camera);
}
res_T
diff --git a/src/stardis-app.h b/src/stardis-app.h
@@ -636,10 +636,12 @@ struct camera {
unsigned spp;
unsigned img_width, img_height;
int auto_look_at;
+ struct str file_name;
};
static INLINE void
-init_camera(struct camera* cam) {
+init_camera(struct mem_allocator* alloc, struct camera* cam) {
+ ASSERT(alloc && cam);
d3(cam->pos, STARDIS_DEFAULT_RENDERING_POS);
d3(cam->tgt, STARDIS_DEFAULT_RENDERING_TGT);
d3(cam->up, STARDIS_DEFAULT_RENDERING_UP);
@@ -650,6 +652,13 @@ init_camera(struct camera* cam) {
cam->img_height = STARDIS_DEFAULT_RENDERING_IMG_HEIGHT;
d2(cam->time_range, STARDIS_DEFAULT_RENDERING_TIME);
cam->auto_look_at = 1;
+ str_init(alloc, &cam->file_name);
+}
+
+static INLINE void
+release_camera(struct camera* cam) {
+ ASSERT(cam);
+ str_release(&cam->file_name);
}
static INLINE void
diff --git a/src/stardis-compute.c b/src/stardis-compute.c
@@ -589,6 +589,7 @@ compute_camera(struct stardis* stardis)
struct dump_path_context dump_ctx;
size_t definition[2];
size_t ix, iy;
+ FILE* stream;
ASSERT(stardis
&& !(stardis->mode & (MODE_BIN_GREEN | MODE_GREEN))
@@ -624,11 +625,22 @@ compute_camera(struct stardis* stardis)
ERR(sdis_solve_camera(stardis->sdis_scn, &args, &buf));
/* Write the image */
+ if(str_is_empty(&stardis->camera.file_name))
+ stream = stdout;
+ else {
+ stream = fopen(str_cget(&stardis->camera.file_name), "w");
+ if(!stream) {
+ res = RES_IO_ERR;
+ goto error;
+ }
+ }
ASSERT(stardis->camera.fmt == STARDIS_RENDERING_OUTPUT_FILE_FMT_VTK
|| stardis->camera.fmt == STARDIS_RENDERING_OUTPUT_FILE_FMT_HT);
if(stardis->camera.fmt == STARDIS_RENDERING_OUTPUT_FILE_FMT_VTK)
- ERR(dump_vtk_image(buf, stdout));
- else ERR(dump_ht_image(buf, stdout));
+ ERR(dump_vtk_image(buf, stream));
+ else ERR(dump_ht_image(buf, stream));
+ if(!str_is_empty(&stardis->camera.file_name))
+ fclose(stream);
/* Dump paths recorded according to user settings */
dump_ctx.stardis = stardis;
diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c
@@ -986,6 +986,9 @@ parse_camera
GET_OPTIONAL_TIME_RANGE(opt[1], 0, cam->time_range, logger, "%s",
str_cget(&keep));
}
+ else if(strcmp(opt[0], "FILE") == 0) {
+ ERR(str_set(&cam->file_name, opt[1]));
+ }
else if(strcmp(opt[0], "FMT") == 0) {
_strupr(opt[1]);
if(strcmp(opt[1], "VTK") == 0)