commit ca0976b33d65ed0fe9fbc8f3d1cb512532ed18d1
parent f72601ab438d7b0ab11f00c0fa005df54e067d25
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 26 Jan 2021 11:24:34 +0100
Add the atrstm_trace_ray function
Diffstat:
| M | src/atrstm.h | | | 36 | ++++++++++++++++++++++++++++++++++++ |
| M | src/atrstm_svx.c | | | 63 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- |
2 files changed, 95 insertions(+), 4 deletions(-)
diff --git a/src/atrstm.h b/src/atrstm.h
@@ -217,6 +217,35 @@ struct atrstm_dump_svx_octree_args {
static const struct atrstm_dump_svx_octree_args
ATRSTM_DUMP_SVX_OCTREE_ARGS_DEFAULT = ATRSTM_DUMP_SVX_OCTREE_ARGS_DEFAULT__;
+struct atrstm_trace_ray_args {
+ double ray_org[3];
+ double ray_dir[3];
+ double ray_range[2];
+
+ const svx_hit_challenge_T challenge; /* NULL <=> Traversed up to the leaves */
+ const svx_hit_filter_T filter; /* NULL <=> Stop RT at the 1st hit voxel */
+ void* context; /* User data send to the 'challenge' & 'filter' function */
+
+ size_t iband; /* Spectral band id. Not use in shortwave */
+ size_t iquad; /* Quadrature point. Not use in short wave */
+};
+
+#define ATRSTM_TRACE_RAY_ARGS_DEFAULT__ { \
+ {0,0,0}, /* Ray origin */ \
+ {0,0,1}, /* Ray direction */ \
+ {0, DBL_MAX}, /* Ray range */ \
+ \
+ NULL, /* Challenge functor */ \
+ NULL, /* Filter functor */ \
+ NULL, /* User defined data */ \
+ \
+ SIZE_MAX, /* Index of the spectral band */ \
+ SIZE_MAX, /* Index of the quadrature point */ \
+}
+static const struct atrstm_trace_ray_args ATRSTM_TRACE_RAY_ARGS_DEFAULT =
+ ATRSTM_TRACE_RAY_ARGS_DEFAULT__;
+
+/* Types used as syntactic sugar that store the radiative coefficients */
typedef double atrstm_radcoefs_T[ATRSTM_RADCOEFS_COUNT__];
typedef double atrstm_radcoefs_svx_T[ATRSTM_RADCOEFS_COUNT__][ATRSTM_SVX_OPS_COUNT__];
@@ -275,6 +304,13 @@ atrstm_dump_svx_octree
const struct atrstm_dump_svx_octree_args* args,
FILE* stream);
+/* Trace a ray into the SVX octree data structure */
+ATRSTM_API res_T
+atrstm_trace_ray
+ (const struct atrstm* atstm,
+ const struct atrstm_trace_ray_args* args,
+ struct svx_hit* hit);
+
END_DECLS
#endif /* ATRSTM_H */
diff --git a/src/atrstm_svx.c b/src/atrstm_svx.c
@@ -20,6 +20,8 @@
#include <star/svx.h>
+#include <rsys/cstr.h>
+
/*******************************************************************************
* Helper functions
******************************************************************************/
@@ -29,7 +31,7 @@ check_fetch_radcoefs_svx_args
const struct atrstm_fetch_radcoefs_svx_args* args,
const char* func_name)
{
- ASSERT(atrstm && args && func_name);
+ ASSERT(atrstm && func_name);
if(!args
|| !(args->radcoefs_mask & ATRSTM_RADCOEFS_MASK_ALL)
@@ -54,7 +56,7 @@ check_fetch_radcoefs_svx_voxel_args
const struct atrstm_fetch_radcoefs_svx_voxel_args* args,
const char* func_name)
{
- ASSERT(atrstm && args && func_name);
+ ASSERT(atrstm && func_name);
if(!args
|| SVX_VOXEL_NONE(&args->voxel)
@@ -74,6 +76,27 @@ check_fetch_radcoefs_svx_voxel_args
return 1;
}
+static INLINE int
+check_trace_ray_args
+ (const struct atrstm* atrstm,
+ const struct atrstm_trace_ray_args* args,
+ const char* func_name)
+{
+ ASSERT(atrstm && func_name);
+
+ if(!args) return 0;
+
+ if(args->iband != ATRSTM_TRACE_RAY_ARGS_DEFAULT.iband /* Not use */
+ || args->iquad != ATRSTM_TRACE_RAY_ARGS_DEFAULT.iquad /* Not use */
+ || atrstm->spectral_type != ATRSTM_SPECTRAL_SW) {
+ log_err(atrstm, "%s: only shortwave is currently supported.\n",
+ func_name);
+ return 0;
+ }
+
+ return 1;
+}
+
static INLINE void
reset_radcoefs
(double radcoefs[ATRSTM_RADCOEFS_COUNT__][ATRSTM_SVX_OPS_COUNT__])
@@ -90,8 +113,9 @@ res_T
atrstm_fetch_radcoefs_svx
(const struct atrstm* atrstm,
const struct atrstm_fetch_radcoefs_svx_args* args,
- double radcoefs[ATRSTM_RADCOEFS_COUNT__][ATRSTM_SVX_OPS_COUNT__]) /*In m^-1*/
+ atrstm_radcoefs_svx_T radcoefs) /* In m^-1 */
{
+
struct atrstm_fetch_radcoefs_svx_voxel_args voxel_args;
struct svx_voxel voxel = SVX_VOXEL_NULL;
res_T res = RES_OK;
@@ -134,7 +158,7 @@ res_T
atrstm_fetch_radcoefs_svx_voxel
(const struct atrstm* atrstm,
const struct atrstm_fetch_radcoefs_svx_voxel_args* args,
- double radcoefs[ATRSTM_RADCOEFS_COUNT__][ATRSTM_SVX_OPS_COUNT__]) /*In m^-1*/
+ atrstm_radcoefs_svx_T radcoefs) /* In m^-1 */
{
int cpnt, radcoef, op;
res_T res = RES_OK;
@@ -171,3 +195,34 @@ error:
goto exit;
}
+res_T
+atrstm_trace_ray
+ (const struct atrstm* atrstm,
+ const struct atrstm_trace_ray_args* args,
+ struct svx_hit* hit)
+{
+ res_T res = RES_OK;
+ if(!atrstm || !check_trace_ray_args(atrstm, args, FUNC_NAME) || !hit) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ /* Reset the hit */
+ *hit = SVX_HIT_NULL;
+
+ res = svx_tree_trace_ray(atrstm->octree, args->ray_org, args->ray_dir,
+ args->ray_range, args->challenge, args->filter, args->context, hit);
+ if(res != RES_OK) {
+ log_err(atrstm,
+ "%s: error tracing the ray: origin = {%g, %g, %g}; "
+ "direction = {%g, %g, %g}; range = {%g, %g} -- %s.\n",
+ FUNC_NAME, SPLIT3(args->ray_org), SPLIT3(args->ray_dir),
+ SPLIT2(args->ray_range), res_to_cstr(res));
+ goto error;
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}