commit 2e6152dbb79cd296e20ea4826a972c496a59902f
parent 7aae3e6b609c9f22fca6e8155a2547ac5c3b9965
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 24 Mar 2017 17:10:40 +0100
Merge remote-tracking branch 'origin/develop' into feature_outputs
Diffstat:
7 files changed, 384 insertions(+), 95 deletions(-)
diff --git a/doc/cli b/doc/cli
@@ -6,6 +6,7 @@ solstice
-h # Short help and exit
-g <dump> # Switch in dump geometry
-o OUTPUT # defaulting to stdout if not defined
+ -p <dump-radiative-path> # Switch in dump radiative paths mode
-q # don't print a message if no INPUT is submitted
-n INTEGER # Realisations count
-r <rendering> # Switch in rendering mode
@@ -42,6 +43,18 @@ solstice -g format=obj:split-group=1
<dump> ::=
format=<dump-format>[:split=<split-mode>]
+<dump-radiative-path> ::=
+ <dump-path-option>[:<dump-path-option> ... ]
+
+<dump-path-option> ::=
+ <sun-ray-len> | <inf-ray-len> | default
+
+<sun-ray-len> ::=
+ srlen=REAL
+
+<inf-ray-len> ::= # Length of the rays going to infinite
+ irlen=REAL
+
<dump-format> ::=
obj
diff --git a/src/solstice.c b/src/solstice.c
@@ -599,10 +599,15 @@ solstice_init
goto error;
}
- solstice->nrealisations = args->nrealisations;
+ solstice->nexperiments = args->nexperiments;
solstice->output_hits = args->output_hits;
solstice->dump_format = args->dump_format;
solstice->dump_split_mode = args->dump_split_mode;
+ solstice->dump_paths = args->dump_paths;
+
+ solstice->path_tracker = SSOL_PATH_TRACKER_DEFAULT;
+ solstice->path_tracker.infinite_ray_length = args->infinite_ray_length;
+ solstice->path_tracker.sun_ray_length = args->sun_ray_length;
if(args->rendering) {
res = setup_camera(solstice, args);
diff --git a/src/solstice.h b/src/solstice.h
@@ -111,12 +111,16 @@ struct solstice {
enum solstice_args_dump_format dump_format;
enum solstice_args_dump_split_mode dump_split_mode;
+ /* Dump radiative paths mode */
+ struct ssol_path_tracker path_tracker;
+
struct darray_double sun_dirs; /* List of double3 */
struct darray_double sun_angles;
- size_t nrealisations; /* # realisations */
+ size_t nexperiments; /* # MC experiments */
FILE* output; /* Output stream */
int output_hits; /* Output per receiver hits */
+ int dump_paths;
struct mem_allocator* allocator;
};
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -51,14 +51,16 @@ print_help(const char* program)
printf(
" -h display this help and exit.\n");
printf(
-" -n REALISATIONS number of realisations. Default is %lu.\n",
- SOLSTICE_ARGS_DEFAULT.nrealisations);
+" -n EXPERIMENTS number of Monte Carlo experiments. Default is %lu.\n",
+ SOLSTICE_ARGS_DEFAULT.nexperiments);
printf(
" -g <dump> switch in dump geometry mode and configure it.\n");
printf(
" -o OUTPUT write results to OUTPUT. If not defined, write results to\n"
" standard output.\n");
printf(
+" -p <dump-paths> switch in dump radiative paths mode and configure it.\n");
+ printf(
" -q do not print the helper message when no FILE is submitted.\n");
printf(
" -R RECEIVERS define the file from which the list of receivers are read.\n");
@@ -95,6 +97,37 @@ parse_fov(const char* str, double* out_fov)
return RES_OK;
}
+static res_T
+parse_multiple_options
+ (const char* str,
+ struct solstice_args* args,
+ res_T (*parse_option)(const char* str, struct solstice_args* args))
+{
+ char buf[512];
+ char* tk;
+ char* ctx;
+ res_T res = RES_OK;
+ ASSERT(args && str);
+
+ if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) {
+ fprintf(stderr, "Could not duplicate the option string `%s'.\n", str);
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ strncpy(buf, str, sizeof(buf));
+
+ tk = strtok_r(buf, ":", &ctx);
+ do {
+ res = parse_option(tk, args);
+ if(res != RES_OK) goto error;
+ tk = strtok_r(NULL, ":", &ctx);
+ } while(tk);
+
+exit:
+ return res;
+error:
+ goto exit;
+}
static res_T
parse_sun_dir_list(const char* str, struct solstice_args* args)
@@ -292,41 +325,6 @@ parse_rendering_option(const char* str, struct solstice_args* args)
res = RES_BAD_ARG;
goto error;
}
- args->rendering = 1;
-
-exit:
- return res;
-error:
- goto exit;
-}
-
-static res_T
-parse_rendering_options(const char* str, struct solstice_args* args)
-{
- char buf[512];
- char* tk;
- char* ctx;
- res_T res = RES_OK;
- ASSERT(args && str);
-
- /* Setup default values of the rendering parameters */
- args->camera = SOLSTICE_ARGS_DEFAULT.camera;
- args->img = SOLSTICE_ARGS_DEFAULT.img;
-
- if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) {
- fprintf(stderr,
- "Could not duplicate the rendering options string `%s'.\n", str);
- res = RES_MEM_ERR;
- goto error;
- }
- strncpy(buf, str, sizeof(buf));
-
- tk = strtok_r(buf, ":", &ctx);
- do {
- res = parse_rendering_option(tk, args);
- if(res != RES_OK) goto error;
- tk = strtok_r(NULL, ":", &ctx);
- } while(tk);
exit:
return res;
@@ -415,12 +413,6 @@ parse_dump_option(const char* str, struct solstice_args* args)
}
if(res != RES_OK) goto error;
- if(args->dump_format == SOLSTICE_ARGS_DUMP_NONE) {
- fprintf(stderr, "No dump format is defined.\n");
- res = RES_BAD_ARG;
- goto error;
- }
-
exit:
return res;
error:
@@ -428,27 +420,58 @@ error:
}
static res_T
-parse_dump_options(const char* str, struct solstice_args* args)
+parse_dump_paths_option(const char* str, struct solstice_args* args)
{
- char buf[512];
- char* tk;
+ char buf[128];
+ char* key;
+ char* val;
char* ctx;
res_T res = RES_OK;
- ASSERT(args && str);
- (void)str, (void)args;
+ ASSERT(str && args);
+
+ if(!strcmp(str, "default")) {
+ args->infinite_ray_length = SOLSTICE_ARGS_DEFAULT.infinite_ray_length;
+ args->sun_ray_length = SOLSTICE_ARGS_DEFAULT.sun_ray_length;
+ goto exit;
+ }
if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) {
fprintf(stderr,
- "Could not duplicate the dump geometry options string `%s'.\n", str);
+"Could not duplicate the dump radiative paths option string `%s'.\n", str);
res = RES_MEM_ERR;
goto error;
}
+
strncpy(buf, str, sizeof(buf));
- tk = strtok_r(buf, ":", &ctx);
- do {
- res = parse_dump_option(tk, args);
- tk = strtok_r(NULL, ":", &ctx);
- } while(tk);
+
+ key = strtok_r(buf, "=", &ctx);
+ val = strtok_r(NULL, "", &ctx);
+
+ if(!val) {
+ fprintf(stderr,
+ "Missing a value to the dump radiative paths option `%s'.\n", key);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if(!strcmp(key, "irlen")) {
+ res = cstr_to_double(val, &args->infinite_ray_length);
+ if(res != RES_OK) {
+ fprintf(stderr, "Invalid infinite ray length `%s'.\n", val);
+ goto error;
+ }
+ } else if(!strcmp(key, "srlen")) {
+ res = cstr_to_double(val, &args->sun_ray_length);
+ if(res != RES_OK) {
+ fprintf(stderr, "Invalid sun ray length `%s'.\n", val);
+ goto error;
+ }
+ } else {
+ fprintf(stderr, "Invalid dump radiative paths option `%s'.\n", val);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ if(res != RES_OK) goto error;
exit:
return res;
@@ -469,28 +492,42 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
*args = SOLSTICE_ARGS_DEFAULT;
optind = 0;
- while((opt = getopt(argc, argv, "D:fg:Hhn:o:qR:r:t:")) != -1) {
+ while((opt = getopt(argc, argv, "D:fg:Hhn:o:p:qR:r:t:")) != -1) {
switch(opt) {
- case 'D':
+ case 'D': /* Sun directions */
res = parse_sun_dir_list(optarg, args);
break;
case 'f': args->force_overwriting = 1; break;
case 'H': args->output_hits = 1; break;
- case 'h':
+ case 'h': /* Print short help and exit */
print_help(argv[0]);
solstice_args_release(args);
args->quit = 1;
goto exit;
- case 'n':
- res = cstr_to_ulong(optarg, &args->nrealisations);
- if(res == RES_OK && !args->nrealisations) res = RES_BAD_ARG;
+ case 'n': /* Define the number of experiments */
+ res = cstr_to_ulong(optarg, &args->nexperiments);
+ if(res == RES_OK && !args->nexperiments) res = RES_BAD_ARG;
+ break;
+ case 'g': /* Switch in dump geometry mode and configure it */
+ res = parse_multiple_options(optarg, args, parse_dump_option);
+ if(res == RES_OK && args->dump_format == SOLSTICE_ARGS_DUMP_NONE) {
+ fprintf(stderr, "%s: missing a dump format -- `%s'.\n",
+ argv[0], optarg);
+ res = RES_BAD_ARG;
+ }
break;
- case 'g': res = parse_dump_options(optarg, args); break;
case 'o': args->output_filename = optarg; break;
+ case 'p': /* Switch in dump radiative paths mode and configure it */
+ args->dump_paths = 1;
+ res = parse_multiple_options(optarg, args, parse_dump_paths_option);
+ break;
case 'q': args->quiet = 1; break;
case 'R': args->receivers_filename = optarg; break;
- case 'r': res = parse_rendering_options(optarg, args); break;
- case 't':
+ case 'r': /* Switch in rendering mode and configure it */
+ args->rendering = 1;
+ res = parse_multiple_options(optarg, args, parse_rendering_option);
+ 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;
break;
@@ -514,7 +551,19 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
}
if(args->dump_format != SOLSTICE_ARGS_DUMP_NONE && args->rendering) {
- fprintf(stderr, "The '-g' and '-r' options are exclusive\n");
+ fprintf(stderr, "The '-g' and '-r' options are exclusives.\n");
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if(args->dump_format != SOLSTICE_ARGS_DUMP_NONE && args->dump_paths) {
+ fprintf(stderr, "The '-g' and '-p' options are exclusives.\n");
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ if(args->dump_paths && args->rendering) {
+ fprintf(stderr, "The '-p' and '-r' options are exclusives.\n");
res = RES_BAD_ARG;
goto error;
}
diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in
@@ -44,7 +44,7 @@ struct solstice_args {
const char* output_filename;
const char* input_filename; /* May be NULL <=> read data from stdin */
const char* receivers_filename;
- unsigned long nrealisations; /* #realisations */
+ unsigned long nexperiments; /* #experiments */
unsigned nthreads; /* #threads */
/* List of sun directions */
@@ -67,10 +67,16 @@ struct solstice_args {
enum solstice_args_render_mode render_mode;
+ /* Dump geometry mode */
enum solstice_args_dump_format dump_format;
enum solstice_args_dump_split_mode dump_split_mode;
+ /* Dump radiative paths options. */
+ double sun_ray_length; /* Length of the sun rays. */
+ double infinite_ray_length; /* Length of the rays going to infinity. */
+
int force_overwriting;
+ int dump_paths; /* Dump radiative paths */
int rendering;
int output_hits; /* Output the per receiver hits */
int quiet;
@@ -109,7 +115,11 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__;
SOLSTICE_ARGS_DUMP_NONE, /* Dump format */ \
SOLSTICE_ARGS_DUMP_SPLIT_NONE, /* Dump split mode */ \
\
+ -1, /* Sun ray length */ \
+ -1, /* Infinite ray length */ \
+ \
0, /* Force overwriting */ \
+ 0, /* Dump radiative paths */ \
0, /* Rendering */ \
0, /* Output hits */ \
0, /* Quiet */ \
diff --git a/src/solstice_solve.c b/src/solstice_solve.c
@@ -362,6 +362,105 @@ write_per_receiver_mc_primitive
}
}
+static void
+dump_path_positions(struct solstice* solstice, const struct ssol_path* path)
+{
+ size_t ivert, nverts;
+ ASSERT(solstice && path);
+
+ SSOL(path_get_vertices_count(path, &nverts));
+ FOR_EACH(ivert, 0, nverts) {
+ struct ssol_path_vertex vertex;
+ SSOL(path_get_vertex(path, ivert, &vertex));
+ fprintf(solstice->output, "%f %f %f\n", SPLIT3(vertex.pos));
+ }
+}
+
+static void
+dump_path_segments
+ (struct solstice* solstice,
+ const struct ssol_path* path,
+ const size_t offset)
+{
+ size_t i, nverts;
+ ASSERT(solstice && path);
+
+ SSOL(path_get_vertices_count(path, &nverts));
+ ASSERT(nverts);
+
+ fprintf(solstice->output, "%lu", (unsigned long)nverts);
+ FOR_EACH(i, 0, nverts) {
+ fprintf(solstice->output, " %lu", (unsigned long)i + offset);
+ }
+ fprintf(solstice->output, "\n");
+}
+
+static void
+write_paths(struct solstice* solstice, struct ssol_estimator* estimator)
+{
+ struct ssol_path path;
+ size_t ipath, npaths;
+ size_t nverts, nlines;
+ size_t offset;
+ ASSERT(solstice && estimator);
+
+ /* Write the header */
+ fprintf(solstice->output, "# vtk DataFile Version 2.0\n");
+ fprintf(solstice->output, "Radiative paths\n");
+ fprintf(solstice->output, "ASCII\n");
+ fprintf(solstice->output, "DATASET POLYDATA\n");
+
+ /* Compute the overall number of path vertices & segments */
+ nverts = 0;
+ SSOL(estimator_get_tracked_paths_count(estimator, &npaths));
+ FOR_EACH(ipath, 0, npaths) {
+ size_t n;
+ SSOL(estimator_get_tracked_path(estimator, ipath, &path));
+ SSOL(path_get_vertices_count(&path, &n));
+ nverts += n;
+ nlines += n - 1;
+ }
+
+ /* Write the positions of the tracked paths */
+ fprintf(solstice->output, "POINTS %lu float\n", (unsigned long)nverts);
+ FOR_EACH(ipath, 0, npaths) {
+ SSOL(estimator_get_tracked_path(estimator, ipath, &path));
+ dump_path_positions(solstice, &path);
+ }
+
+ /* Write the segment of the tracked paths */
+ offset = 0;
+ fprintf(solstice->output, "LINES %lu %lu\n",
+ (unsigned long)npaths, (unsigned long)nverts + npaths);
+ FOR_EACH(ipath, 0, npaths) {
+ size_t n;
+ SSOL(estimator_get_tracked_path(estimator, ipath, &path));
+ SSOL(path_get_vertices_count(&path, &n));
+ dump_path_segments(solstice, &path, offset);
+ offset += n;
+ }
+
+ /* Write path type */
+ fprintf(solstice->output, "CELL_DATA %lu\n", (unsigned long)npaths);
+ fprintf(solstice->output, "SCALARS Radiative_path_type float 1\n");
+ fprintf(solstice->output, "LOOKUP_TABLE path_type\n");
+ FOR_EACH(ipath, 0, npaths) {
+ enum ssol_path_type type;
+ SSOL(estimator_get_tracked_path(estimator, ipath, &path));
+ SSOL(path_get_type(&path, &type));
+ switch(type) {
+ case SSOL_PATH_MISSING: fprintf(solstice->output, "1.0\n"); break;
+ case SSOL_PATH_SUCCESS: fprintf(solstice->output, "0.5\n"); break;
+ case SSOL_PATH_SHADOW: fprintf(solstice->output, "0.0\n"); break;
+ default: FATAL("Unreachable code.\n"); break;
+ }
+ }
+ fprintf(solstice->output, "LOOKUP_TABLE path_type 3\n");
+ fprintf(solstice->output, "1.0 0.0 0.0 1.0\n");
+ fprintf(solstice->output, "0.0 0.0 1.0 1.0\n");
+ fprintf(solstice->output, "1.0 1.0 0.0 1.0\n");
+}
+
/*******************************************************************************
* Local functions
******************************************************************************/
@@ -391,33 +490,38 @@ solstice_solve(struct solstice* solstice)
}
}
- res = ssol_solve(solstice->scene, rng, solstice->nrealisations,
- bin_stream, &estimator);
+ res = ssol_solve(solstice->scene, rng, solstice->nexperiments,
+ solstice->dump_paths ? &solstice->path_tracker : NULL, bin_stream,
+ &estimator);
if(res != RES_OK) {
fprintf(stderr, "Error in integrating the solar flux.\n");
goto error;
}
- write_mc_global(solstice, estimator);
- write_per_receiver_mc_primitive(solstice, estimator);
-
- if(solstice->output_hits) {
- sz = (size_t)ftell(bin_stream);
- rewind(bin_stream);
-
- while(sz) {
- const size_t read_sz = MMIN(sz, sizeof(buf));
- if(fread(buf, 1, read_sz, bin_stream) != read_sz) {
- fprintf(stderr, "Could not read the output binary stream.\n");
- res = RES_IO_ERR;
- goto error;
- }
- if(fwrite(buf, 1, read_sz, solstice->output) != read_sz) {
- fprintf(stderr, "Could not write the output binary stream.\n");
- res = RES_IO_ERR;
- goto error;
+ if(solstice->dump_paths) {
+ write_paths(solstice, estimator);
+ } else {
+ write_mc_global(solstice, estimator);
+ write_per_receiver_mc_primitive(solstice, estimator);
+
+ if(solstice->output_hits) {
+ sz = (size_t)ftell(bin_stream);
+ rewind(bin_stream);
+
+ while(sz) {
+ const size_t read_sz = MMIN(sz, sizeof(buf));
+ if(fread(buf, 1, read_sz, bin_stream) != read_sz) {
+ fprintf(stderr, "Could not read the output binary stream.\n");
+ res = RES_IO_ERR;
+ goto error;
+ }
+ if(fwrite(buf, 1, read_sz, solstice->output) != read_sz) {
+ fprintf(stderr, "Could not write the output binary stream.\n");
+ res = RES_IO_ERR;
+ goto error;
+ }
+ sz -= read_sz;
}
- sz -= read_sz;
}
}
diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c
@@ -83,7 +83,7 @@ test_rendering(void)
cmd = cmd_create(0, "test", "-r", "img=1280x720", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
CHECK(args.rendering, 1);
- CHECK(args.nrealisations, SOLSTICE_ARGS_DEFAULT.nrealisations);
+ CHECK(args.nexperiments, SOLSTICE_ARGS_DEFAULT.nexperiments);
CHECK(d3_eq(args.camera.pos, SOLSTICE_ARGS_DEFAULT.camera.pos), 1);
CHECK(d3_eq(args.camera.tgt, SOLSTICE_ARGS_DEFAULT.camera.tgt), 1);
CHECK(d3_eq(args.camera.up, SOLSTICE_ARGS_DEFAULT.camera.up), 1);
@@ -100,7 +100,7 @@ test_rendering(void)
cmd = cmd_create(0, "test", "-q", "-r", "img=640x480:fov=70:pos=1,2,3", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
CHECK(args.rendering, 1);
- CHECK(args.nrealisations, SOLSTICE_ARGS_DEFAULT.nrealisations);
+ CHECK(args.nexperiments, SOLSTICE_ARGS_DEFAULT.nexperiments);
CHECK(d3_eq(args.camera.pos, d3(tmp, 1, 2, 3)), 1);
CHECK(d3_eq(args.camera.tgt, SOLSTICE_ARGS_DEFAULT.camera.tgt), 1);
CHECK(d3_eq(args.camera.up, SOLSTICE_ARGS_DEFAULT.camera.up), 1);
@@ -116,7 +116,7 @@ test_rendering(void)
cmd = cmd_create(0, "test", "-r", "up=0,0,1:tgt=0,-10,0:rmode=draft", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
- CHECK(args.nrealisations, SOLSTICE_ARGS_DEFAULT.nrealisations);
+ CHECK(args.nexperiments, SOLSTICE_ARGS_DEFAULT.nexperiments);
CHECK(d3_eq(args.camera.pos, SOLSTICE_ARGS_DEFAULT.camera.pos), 1);
CHECK(d3_eq(args.camera.tgt, d3(tmp, 0,-10, 0)), 1);
CHECK(d3_eq(args.camera.up, d3(tmp, 0, 0, 1)), 1);
@@ -132,7 +132,7 @@ test_rendering(void)
cmd = cmd_create(0, "test", "-r", "up=0,0,1:rmode=pt:spp=4", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
- CHECK(args.nrealisations, SOLSTICE_ARGS_DEFAULT.nrealisations);
+ CHECK(args.nexperiments, SOLSTICE_ARGS_DEFAULT.nexperiments);
CHECK(d3_eq(args.camera.up, d3(tmp, 0, 0, 1)), 1);
CHECK(args.img.width, SOLSTICE_ARGS_DEFAULT.img.width);
CHECK(args.img.height, SOLSTICE_ARGS_DEFAULT.img.height);
@@ -317,19 +317,19 @@ test_realisations_count(void)
cmd = cmd_create(0, "test", "-D", "0,90", "-n", "1", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
- CHECK(args.nrealisations, 1);
+ CHECK(args.nexperiments, 1);
solstice_args_release(&args);
cmd_delete(cmd);
cmd = cmd_create(0, "test", "-D", "0,90", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
- CHECK(args.nrealisations, SOLSTICE_ARGS_DEFAULT.nrealisations);
+ CHECK(args.nexperiments, SOLSTICE_ARGS_DEFAULT.nexperiments);
solstice_args_release(&args);
cmd_delete(cmd);
cmd = cmd_create(0, "test", "-D", "0,90", "-n", "123", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
- CHECK(args.nrealisations, 123);
+ CHECK(args.nexperiments, 123);
solstice_args_release(&args);
cmd_delete(cmd);
@@ -565,6 +565,109 @@ test_dump(void)
cmd = cmd_create(0, "test", "-g", "format=obj:split", NULL);
CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-g", "format=obj", "-r", "up=0,0,1", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-g", "format=obj", "-p", "default", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+}
+
+static void
+test_dump_paths(void)
+{
+ struct solstice_args args = SOLSTICE_ARGS_NULL;
+ char** cmd = NULL;
+
+ cmd = cmd_create(0, "test", "-D", "0,90", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 0);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.infinite_ray_length, SOLSTICE_ARGS_DEFAULT.infinite_ray_length);
+ CHECK(args.sun_ray_length, SOLSTICE_ARGS_DEFAULT.sun_ray_length);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "irlen=3.14:srlen=1.23", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(eq_eps(args.infinite_ray_length, 3.14, 1.e-6), 1);
+ CHECK(eq_eps(args.sun_ray_length, 1.23, 1.e-6), 1);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "irlen=0", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(eq_eps(args.infinite_ray_length, 0, 1.e-6), 1);
+ CHECK(args.sun_ray_length, SOLSTICE_ARGS_DEFAULT.sun_ray_length);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=-4", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.infinite_ray_length, SOLSTICE_ARGS_DEFAULT.infinite_ray_length);
+ CHECK(eq_eps(args.sun_ray_length, -4, 1.e-6), 1);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=3.14:default", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.infinite_ray_length, SOLSTICE_ARGS_DEFAULT.infinite_ray_length);
+ CHECK(args.sun_ray_length, SOLSTICE_ARGS_DEFAULT.sun_ray_length);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default:srlen=1:irlen=2:", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK);
+ CHECK(args.dump_paths, 1);
+ CHECK(args.sun_ray_length, 1);
+ CHECK(args.infinite_ray_length, 2);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "irlen=", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "srlen=abcd", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "irlen", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "=abcd", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default:srlen=1:irlen=2:",
+ "-r", "up=0,0,1", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-p", "default:srlen=1:irlen=2:",
+ "-g", "format=obj", NULL);
+ CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG);
+ cmd_delete(cmd);
}
int
@@ -581,6 +684,7 @@ main(int argc, char** argv)
test_receivers();
test_input();
test_dump();
+ test_dump_paths();
CHECK(mem_allocated_size(), 0);
return 0;
}