htrdr

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

commit 3b41b51414d6c35391566df8b2473fbd83b7bd25
parent 422896aee475f12df5f234d5f6008690b578c71a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 14 Oct 2020 13:22:43 +0200

Implement the htrdr_ground_closest_point function

Diffstat:
Msrc/htrdr_ground.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/htrdr_ground.h | 7+++++++
2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/src/htrdr_ground.c b/src/htrdr_ground.c @@ -672,3 +672,61 @@ error: goto exit; } +res_T +htrdr_ground_find_closest_point + (struct htrdr_ground* ground, + const double pos[3], + const double radius, + struct s3d_hit* hit) +{ + float query_pos[3]; + float query_radius; + float ground_sz[3]; + res_T res = RES_OK; + ASSERT(ground && pos && hit); + + if(!ground->view) { /* No ground geometry */ + *hit = S3D_HIT_NULL; + goto exit; + } + + query_radius = (float)radius; + f3_set_d3(query_pos, pos); + + if(ground->repeat) { + float translation[2] = {0, 0}; + int64_t xy[2]; + ground_sz[0] = ground->upper[0] - ground->lower[0]; + ground_sz[1] = ground->upper[1] - ground->lower[1]; + ground_sz[2] = ground->upper[2] - ground->lower[2]; + + /* Define the 2D index of the current ground instance. (0,0) is the index + * of the non instantiated ground */ + xy[0] = (int64_t)floor((query_pos[0] - ground->lower[0]) / ground_sz[0]); + xy[1] = (int64_t)floor((query_pos[1] - ground->lower[1]) / ground_sz[1]); + + /* Define the translation along the X and Y axis from world space to local + * ground geometry space */ + translation[0] = -(float)xy[0] * ground_sz[0]; + translation[1] = -(float)xy[1] * ground_sz[1]; + + /* Transform the query pos in local ground geometry space */ + query_pos[0] += translation[0]; + query_pos[1] += translation[1]; + } + + /* Closest point query */ + res = s3d_scene_view_closest_point + (ground->view, query_pos, query_radius, NULL, hit); + if(res != RES_OK) { + htrdr_log_err(ground->htrdr, + "%s: could not query the closest point to the ground geometry -- %s.\n", + FUNC_NAME, res_to_cstr(res)); + goto error; + } + +exit: + return res; +error: + goto exit; +} diff --git a/src/htrdr_ground.h b/src/htrdr_ground.h @@ -67,5 +67,12 @@ htrdr_ground_trace_ray const struct s3d_hit* prev_hit,/* Previous hit. Avoid self hit. May be NULL*/ struct s3d_hit* hit); +extern LOCAL_SYM res_T +htrdr_ground_find_closest_point + (struct htrdr_ground* ground, + const double position[3], + const double radius, + struct s3d_hit* hit); + #endif /* HTRDR_GROUND_H */