commit a788897837e426dbf092fec27a2ce393e948fbc9
parent 20a554f2151e9f082aa880f4354e8359a34d68d4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 18 Nov 2022 17:02:19 +0100
Add the rnatm_get_temperature function
Diffstat:
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/src/rngrd.h b/src/rngrd.h
@@ -96,8 +96,8 @@ static const struct rngrd_trace_ray_args RNGRD_TRACE_RAY_ARGS_DEFAULT =
RNGRD_TRACE_RAY_ARGS_DEFAULT__;
struct rngrd_create_bsdf_args {
- struct s3d_primitive prim; /* Surfacic primitive to query */
- double barycentric_coords[3]; /* Position into and relative to the cell */
+ struct s3d_primitive prim; /* Surface primitive to query */
+ double barycentric_coords[3]; /* Position into and relative to `prim' */
double wavelength; /* In nanometers */
double r; /* Random number uniformly distributed in [0, 1[ */
};
@@ -105,6 +105,14 @@ struct rngrd_create_bsdf_args {
static const struct rngrd_create_bsdf_args RNGRD_CREATE_BSDF_ARGS_NULL =
RNGRD_CREATE_BSDF_ARGS_NULL__;
+struct rngrd_get_temperature_args {
+ struct s3d_primitive prim; /* Surface primitive to query */
+ double barycentric_coords[3]; /* Position into and relative to `prim' */
+};
+#define RNGRD_GET_TEMPERATURE_ARGS_NULL__ {S3D_PRIMITIVE_NULL__, {0,0,0}}
+static const struct rngrd_get_temperature_args RNGRD_GET_TEMPERATURE_ARGS_NULL =
+ RNGRD_GET_TEMPERATURE_ARGS_NULL__;
+
/* Opaque data types */
struct rngrd;
@@ -146,6 +154,12 @@ rngrd_create_bsdf
const struct rngrd_create_bsdf_args* args,
struct ssf_bsdf** bsdf);
+RNGRD_API res_T
+rngrd_get_temperature
+ (const struct rngrd* ground,
+ const struct rngrd_get_temperature_args* args,
+ double* temperature);
+
END_DECLS
#endif /* RNGRD_H */
diff --git a/src/rngrd_properties.c b/src/rngrd_properties.c
@@ -66,6 +66,31 @@ check_create_bsdf_args
return RES_OK;
}
+static INLINE res_T
+check_get_temperature_args
+ (const struct rngrd* ground,
+ const struct rngrd_get_temperature_args* args)
+{
+ double sum_bcoords;
+ ASSERT(ground);
+
+ if(!args) return RES_BAD_ARG;
+
+ /* Invalid primitive */
+ if(args->prim.prim_id >= ground->ntriangles)
+ return RES_BAD_ARG;
+
+ /* Invalid barycentric_coords */
+ sum_bcoords =
+ args->barycentric_coords[0]
+ + args->barycentric_coords[1]
+ + args->barycentric_coords[2];
+ if(!eq_eps(sum_bcoords, 1, 1.e-6))
+ return RES_BAD_ARG;
+
+ return RES_OK;
+}
+
static res_T
check_sbuf_desc
(const struct rngrd* ground,
@@ -347,6 +372,34 @@ error:
goto exit;
}
+res_T
+rngrd_get_temperature
+ (const struct rngrd* ground,
+ const struct rngrd_get_temperature_args* args,
+ double* temperature)
+{
+ const struct ALIGN(8) { uint32_t mtl_id; float temperature; }* item = NULL;
+ struct sbuf_desc desc;
+ res_T res = RES_OK;
+
+ if(!ground || !temperature) { res = RES_BAD_ARG; goto error; }
+ res = check_get_temperature_args(ground, args);
+ if(res != RES_OK) goto error;
+
+ /* Retrieve the ground temperature */
+ res = sbuf_get_desc(ground->props, &desc);
+ if(res != RES_OK) goto error;
+ item = sbuf_desc_at(&desc, args->prim.prim_id);
+ ASSERT(item->temperature >= 0);
+
+ *temperature = item->temperature;
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
/*******************************************************************************
* Local function
******************************************************************************/