htrdr

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

commit 415219a3c1e70f8df43ec19bffaefe4b4f5d1f6c
parent 1428fc52dbc781ae5f698e4cc25fb688a4438011
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 16 Apr 2021 13:59:03 +0200

Ray filter function for the combustion chamber geometry

Implement 2 ray filter functions that ignore the first or last
intersected surface. The first function will be used to allow the rays
of the camera to enter the combustion chamber while the second will be
used to reach the laser surface emission during the backward ray tracing,
i.e. to let the laser sheet enter the combustion chamber.

Diffstat:
Mcmake/combustion/CMakeLists.txt | 2++
Asrc/combustion/htrdr_combustion_geometry_ray_filter.c | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/combustion/htrdr_combustion_geometry_ray_filter.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/cmake/combustion/CMakeLists.txt b/cmake/combustion/CMakeLists.txt @@ -51,6 +51,7 @@ set(HTRDR_COMBUSTION_FILES_SRC htrdr_combustion_args.c htrdr_combustion_draw_map.c htrdr_combustion_compute_radiance_sw.c + htrdr_combustion_geometry_ray_filter.c htrdr_combustion_laser.c htrdr_combustion_main.c) @@ -58,6 +59,7 @@ set(HTRDR_COMBUSTION_FILES_INC htrdr_combustion.h htrdr_combustion_c.h htrdr_combustion_args.h + htrdr_combustion_geometry_ray_filter.h htrdr_combustion_laser.h) # Prepend each file in the `HTRDR_FILES_<SRC|INC>' list by `HTRDR_SOURCE_DIR' diff --git a/src/combustion/htrdr_combustion_geometry_ray_filter.c b/src/combustion/htrdr_combustion_geometry_ray_filter.c @@ -0,0 +1,109 @@ +/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2018, 2019, 2021 CNRS + * Copyright (C) 2018, 2019, Université Paul Sabatier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "combustion/htrdr_combustion_geometry_ray_filter.h" + + +/******************************************************************************* + * Local functions + ******************************************************************************/ +int +geometry_ray_filter_discard_first_hit + (const struct s3d_hit* hit, + const float ray_org[3], + const float ray_dir[3], + void* ray_data, + void* filter_data) +{ + struct geometry_ray_filter_context* ctx = ray_data; + int discard = 0; + ASSERT(hit && ray_org && ray_dir && ray_data && !S3D_HIT_NONE(hit)); + (void)ray_org, (void)ray_dir, (void)filter_data; + + /* Note that the surfaces are not intersected in order. In this filter + * function, we save in ctx->hit_tmp__ the current "first intersection" and + * in ctx->hit the second one that is the candidate intersection. */ + + if(hit->distance > ctx->hit_tmp__.distance) { + /* An intersection was already registered as the first hit. Accept the + * input hit and update the ctx->hit if necessary */ + discard = 0; + if(hit->distance < ctx->hit.distance) { + ctx->hit = *hit; + } + } else { + /* No intersection has been stored or the submitted intersection is closer + * than the one recorded as "first intersection". This new intersection + * becomes the new first hit and is therefore rejected while the previous + * become the candidate intersection. */ + discard = 1; + ASSERT(ctx->hit.distance >= ctx->hit_tmp__.distance); + ctx->hit = ctx->hit_tmp__; + ctx->hit_tmp__ = *hit; + } + return discard; +} + +int +geometry_ray_filter_discard_last_hit + (const struct s3d_hit* hit, + const float ray_org[3], + const float ray_dir[3], + void* ray_data, + void* filter_data) +{ + struct geometry_ray_filter_context* ctx = ray_data; + int discard = 0; + ASSERT(hit && ray_org && ray_dir && ray_data && !S3D_HIT_NONE(hit)); + (void)ray_org, (void)ray_dir, (void)filter_data; + + /* Note that the surfaces are not intersected in order. In this filter + * function, we save in ctx->hit_tmp__ the current "last intersection" and + * in ctx->hit the closest one exepted this last intersection. */ + + if(S3D_HIT_NONE(&ctx->hit_tmp__)) { + /* No intersection was registered. The submitted hit would be the last one. + * So discard it and register the hit as the last intersect */ + discard = 1; + ctx->hit_tmp__ = *hit; + + } else if(hit->distance > ctx->hit_tmp__.distance) { + /* A "last intersection" has already been stored but is closer than the + * submitted intersection. This new intersection could be the real “last + * intersection”. So we save this intersection and reject it */ + discard = 1; + ASSERT(S3D_HIT_NONE(&ctx->hit) + || ctx->hit_tmp__.distance >= ctx->hit.distance); + + /* Also, if the nearest intersection was not already defined, we set it to + * the last previously saved intersection; if it was already defined, it + * would necessarily be the closest. */ + if(S3D_HIT_NONE(&ctx->hit)) { + ctx->hit = ctx->hit_tmp__; + } + + ctx->hit_tmp__ = *hit; /* Save last intersection */ + + } else if(hit->distance < ctx->hit.distance) { + /* A closest intersection that is not the last one is found. Keep and + * register this intersection */ + discard = 0; + ctx->hit = *hit; + } + + return discard; +} diff --git a/src/combustion/htrdr_combustion_geometry_ray_filter.h b/src/combustion/htrdr_combustion_geometry_ray_filter.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2018, 2019, 2021 CNRS + * Copyright (C) 2018, 2019, Université Paul Sabatier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef HTRDR_COMBUSTION_GEOMETRY_RAY_FILTER_H +#define HTRDR_COMBUSTION_GEOMETRY_RAY_FILTER_H + +#include <star/s3d.h> +#include <rsys/rsys.h> + +struct geometry_ray_filter_context { + /* This is the real hit to use. The one returned by the trace ray function is + * only used as a "early stop" of the tray tracing process */ + struct s3d_hit hit; + + struct s3d_hit hit_tmp__; /* Temporary internal data */ +}; + +#define GEOMETRY_RAY_FILTER_CONTEXT_NULL__ {S3D_HIT_NULL__, S3D_HIT_NULL__} +static const struct geometry_ray_filter_context +GEOMETRY_RAY_FILTER_CONTEXT_NULL = GEOMETRY_RAY_FILTER_CONTEXT_NULL__; + +/* Filter function used to ignore the first intersection along the ray. Note + * that the intersection to use is output in the 'hit' member variable of the + * 'struct geometry_filter_context' data structure pointed to by the 'ray_data' + * input argument. The intersection returned by the ray tracing procedure + * itself is actually just a temporary variable used to prematurely stop ray + * tracing. */ +extern LOCAL_SYM int +geometry_ray_filter_discard_first_hit + (const struct s3d_hit* hit, + const float ray_org[3], + const float ray_dir[3], + void* ray_data, /* Must point to a struct geometry_filter_context */ + void* filter_data); + +/* Quite similar filtering function to the previous one, but this time it + * filters the last intersection along the ray, not the first. This means that + * if the ray intersects only one surface, it is assumed that the ray does not + * intersect anything. */ +extern LOCAL_SYM int +geometry_ray_filter_discard_last_hit + (const struct s3d_hit* hit, + const float ray_org[3], + const float ray_dir[3], + void* ray_data, /* Must point to a struct geometry_filter_context */ + void* filter_data); + +#endif /* HTRDR_COMBUSTION_GEOMETRY_RAY_FILTER_H */