solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 937d670760f5ce6c0829c2a4f47b266a76335e13
parent 6dc1e599b6280651fbbceb90c9e682bffdbfb277
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue,  6 Sep 2016 15:36:08 +0200

Rename all the object_instance stuff to instance.

Diffstat:
Mcmake/CMakeLists.txt | 6+++---
Msrc/ssol.h | 36++++++++++++++++++------------------
Asrc/ssol_instance.c | 190+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ssol_instance_c.h | 44++++++++++++++++++++++++++++++++++++++++++++
Dsrc/ssol_object_instance.c | 190-------------------------------------------------------------------------------
Dsrc/ssol_object_instance_c.h | 44--------------------------------------------
Msrc/ssol_scene.c | 28++++++++++++++--------------
Msrc/ssol_scene_c.h | 4++--
Msrc/ssol_solver.c | 10+++++-----
Msrc/ssol_solver_c.h | 4++--
Asrc/test_ssol_instance.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/test_ssol_object_instance.c | 87-------------------------------------------------------------------------------
Msrc/test_ssol_scene.c | 20++++++++++----------
Msrc/test_ssol_solver.c | 34+++++++++++++++++-----------------
14 files changed, 392 insertions(+), 392 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -58,7 +58,7 @@ set(SSOL_FILES_SRC ssol_image.c ssol_material.c ssol_object.c - ssol_object_instance.c + ssol_instance.c ssol_ranst_sun_dir.c ssol_scene.c ssol_shape.c @@ -78,7 +78,7 @@ set(SSOL_FILES_INC ssol_image_c.h ssol_material_c.h ssol_object_c.h - ssol_object_instance_c.h + ssol_instance_c.h ssol_ranst_sun_dir.h ssol_scene_c.h ssol_shape_c.h @@ -144,7 +144,7 @@ if(NOT NO_TEST) new_test(test_ssol_image) new_test(test_ssol_material) new_test(test_ssol_object) - new_test(test_ssol_object_instance) + new_test(test_ssol_instance) new_test(test_ssol_scene) new_test(test_ssol_shape) new_test(test_ssol_spectrum) diff --git a/src/ssol.h b/src/ssol.h @@ -50,7 +50,7 @@ struct ssol_device; struct ssol_image; struct ssol_material; struct ssol_object; -struct ssol_object_instance; +struct ssol_instance; struct ssol_scene; struct ssol_quadric; struct ssol_shape; @@ -281,14 +281,14 @@ ssol_scene_ref_put (struct ssol_scene* scn); SSOL_API res_T -ssol_scene_attach_object_instance +ssol_scene_attach_instance (struct ssol_scene* scn, - struct ssol_object_instance* instance); + struct ssol_instance* instance); SSOL_API res_T -ssol_scene_detach_object_instance +ssol_scene_detach_instance (struct ssol_scene* scn, - struct ssol_object_instance* instance); + struct ssol_instance* instance); /* Detach all the instances from the scene and release the reference that the * scene takes onto them. @@ -402,34 +402,34 @@ ssol_object_ref_put SSOL_API res_T ssol_object_instantiate (struct ssol_object* object, - struct ssol_object_instance** instance); + struct ssol_instance** instance); SSOL_API res_T -ssol_object_instance_ref_get - (struct ssol_object_instance* instance); +ssol_instance_ref_get + (struct ssol_instance* instance); SSOL_API res_T -ssol_object_instance_ref_put - (struct ssol_object_instance* intance); +ssol_instance_ref_put + (struct ssol_instance* intance); SSOL_API res_T -ssol_object_instance_set_transform - (struct ssol_object_instance* instance, +ssol_instance_set_transform + (struct ssol_instance* instance, const double transform[12]); /* 3x4 column major matrix */ SSOL_API res_T -ssol_object_instance_set_receiver - (struct ssol_object_instance* instance, +ssol_instance_set_receiver + (struct ssol_instance* instance, const char* name); /* May be NULL <=> it is no more a receiver */ SSOL_API res_T -ssol_object_instance_set_target_mask - (struct ssol_object_instance* instance, +ssol_instance_set_target_mask + (struct ssol_instance* instance, const uint32_t mask); SSOL_API res_T -ssol_object_instance_is_attached - (struct ssol_object_instance* instance, +ssol_instance_is_attached + (struct ssol_instance* instance, char* is_attached); /******************************************************************************* diff --git a/src/ssol_instance.c b/src/ssol_instance.c @@ -0,0 +1,190 @@ +/* Copyright (C) CNRS 2016 + * + * 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 "ssol.h" +#include "ssol_object_c.h" +#include "ssol_shape_c.h" +#include "ssol_instance_c.h" +#include "ssol_device_c.h" + +#include <rsys/rsys.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/double33.h> + +#include <string.h> + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +instance_release(ref_T* ref) +{ + struct ssol_device* dev; + struct ssol_instance* instance; + ASSERT(ref); + + instance = CONTAINER_OF(ref, struct ssol_instance, ref); + dev = instance->dev; + ASSERT(dev && dev->allocator); + + SSOL(object_ref_put(instance->object)); + if(instance->shape_rt) S3D(shape_ref_put(instance->shape_rt)); + if(instance->shape_samp) S3D(shape_ref_put(instance->shape_samp)); + str_release(&instance->receiver_name); + MEM_RM(dev->allocator, instance); + SSOL(device_ref_put(dev)); +} + +/******************************************************************************* + * Exported ssol_instance functions + ******************************************************************************/ +res_T +ssol_object_instantiate + (struct ssol_object* object, + struct ssol_instance** out_instance) +{ + struct ssol_instance* instance = NULL; + struct ssol_device* dev; + + res_T res = RES_OK; + if (!object || !out_instance) { + res = RES_BAD_ARG; + goto error; + } + + dev = object->dev; + ASSERT(dev && dev->allocator); + instance = (struct ssol_instance*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct ssol_instance)); + if (!instance) { + res = RES_MEM_ERR; + goto error; + } + + instance->dev = dev; + instance->object = object; + d33_set_identity(instance->transform); + d3_splat(instance->transform + 9, 0); + instance->target_mask = 0; + str_init(dev->allocator, &instance->receiver_name); + SSOL(object_ref_get(object)); + SSOL(device_ref_get(dev)); + ref_init(&instance->ref); + + /* Create the Star-3D instance to ray-trace */ + res = s3d_scene_instantiate(object->scn_rt, &instance->shape_rt); + if(res != RES_OK) goto error; + + /* Create the Star-3D instance to sample */ + res = s3d_scene_instantiate(object->scn_samp, &instance->shape_samp); + if(res != RES_OK) goto error; + +exit: + if(out_instance) *out_instance = instance; + return res; +error: + if (instance) { + SSOL(instance_ref_put(instance)); + instance = NULL; + } + goto exit; +} + +res_T +ssol_instance_ref_get(struct ssol_instance* instance) +{ + if(!instance) + return RES_BAD_ARG; + ref_get(&instance->ref); + return RES_OK; +} + +res_T +ssol_instance_ref_put + (struct ssol_instance* instance) +{ + if (!instance) + return RES_BAD_ARG; + ref_put(&instance->ref, instance_release); + return RES_OK; +} + +res_T +ssol_instance_set_transform + (struct ssol_instance* instance, const double transform[12]) +{ + float t[12]; + int i; + res_T res = RES_OK; + + if(!instance || !transform) { + res = RES_BAD_ARG; + goto error; + } + + FOR_EACH(i, 0, 12) t[i] = (float)transform[i]; + + res = s3d_instance_set_transform(instance->shape_rt, t); + if(res != RES_OK) goto error; + + if(instance->shape_rt != instance->shape_samp) { + res = s3d_instance_set_transform(instance->shape_samp, t); + if(res != RES_OK) goto error; + } + +exit: + return res; +error: + goto exit; +} + +res_T +ssol_instance_set_receiver + (struct ssol_instance* instance, + const char* name) +{ + if(!instance) + return RES_BAD_ARG; + + if(name) { + return str_set(&instance->receiver_name, name); + } else { + str_clear(&instance->receiver_name); + return RES_OK; + } +} + +res_T +ssol_instance_set_target_mask + (struct ssol_instance* instance, + const uint32_t mask) +{ + if (!instance) + return RES_BAD_ARG; + + instance->target_mask = mask; + return RES_OK; +} + +res_T +ssol_instance_is_attached + (struct ssol_instance* instance, char* is_attached) +{ + FATAL("Not implemented yet."); + if(!instance || !is_attached) return RES_BAD_ARG; + return RES_OK; +} + diff --git a/src/ssol_instance_c.h b/src/ssol_instance_c.h @@ -0,0 +1,44 @@ +/* Copyright (C) CNRS 2016 + * + * 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 SSOL_INSTANCE_C_H +#define SSOL_INSTANCE_C_H + +#include <rsys/list.h> +#include <rsys/ref_count.h> +#include <rsys/str.h> + +struct ssol_instance +{ + struct ssol_object* object; /* Instantiated object */ + struct s3d_shape* shape_rt; /* Instantiated Star-3D shape to ray-trace */ + struct s3d_shape* shape_samp; /* Instantiated Star-3D shape to sample */ + struct str receiver_name; /* Empty if not a receiver */ + double transform[12]; + uint32_t target_mask; + + struct ssol_device* dev; + ref_T ref; +}; + +static INLINE const char* +instance_get_receiver_name(const struct ssol_instance* instance) +{ + ASSERT(instance); + return str_is_empty(&instance->receiver_name) + ? NULL : str_cget(&instance->receiver_name); +} + +#endif /* SSOL_INSTANCE_C_H */ diff --git a/src/ssol_object_instance.c b/src/ssol_object_instance.c @@ -1,190 +0,0 @@ -/* Copyright (C) CNRS 2016 - * - * 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 "ssol.h" -#include "ssol_object_c.h" -#include "ssol_shape_c.h" -#include "ssol_object_instance_c.h" -#include "ssol_device_c.h" - -#include <rsys/rsys.h> -#include <rsys/mem_allocator.h> -#include <rsys/ref_count.h> -#include <rsys/double33.h> - -#include <string.h> - -/******************************************************************************* - * Helper functions - ******************************************************************************/ -static void -object_instance_release(ref_T* ref) -{ - struct ssol_device* dev; - struct ssol_object_instance* instance; - ASSERT(ref); - - instance = CONTAINER_OF(ref, struct ssol_object_instance, ref); - dev = instance->dev; - ASSERT(dev && dev->allocator); - - SSOL(object_ref_put(instance->object)); - if(instance->shape_rt) S3D(shape_ref_put(instance->shape_rt)); - if(instance->shape_samp) S3D(shape_ref_put(instance->shape_samp)); - str_release(&instance->receiver_name); - MEM_RM(dev->allocator, instance); - SSOL(device_ref_put(dev)); -} - -/******************************************************************************* - * Exported ssol_object_instance functions - ******************************************************************************/ -res_T -ssol_object_instantiate - (struct ssol_object* object, - struct ssol_object_instance** out_instance) -{ - struct ssol_object_instance* instance = NULL; - struct ssol_device* dev; - - res_T res = RES_OK; - if (!object || !out_instance) { - res = RES_BAD_ARG; - goto error; - } - - dev = object->dev; - ASSERT(dev && dev->allocator); - instance = (struct ssol_object_instance*)MEM_CALLOC - (dev->allocator, 1, sizeof(struct ssol_object_instance)); - if (!instance) { - res = RES_MEM_ERR; - goto error; - } - - instance->dev = dev; - instance->object = object; - d33_set_identity(instance->transform); - d3_splat(instance->transform + 9, 0); - instance->target_mask = 0; - str_init(dev->allocator, &instance->receiver_name); - SSOL(object_ref_get(object)); - SSOL(device_ref_get(dev)); - ref_init(&instance->ref); - - /* Create the Star-3D instance to ray-trace */ - res = s3d_scene_instantiate(object->scn_rt, &instance->shape_rt); - if(res != RES_OK) goto error; - - /* Create the Star-3D instance to sample */ - res = s3d_scene_instantiate(object->scn_samp, &instance->shape_samp); - if(res != RES_OK) goto error; - -exit: - if(out_instance) *out_instance = instance; - return res; -error: - if (instance) { - SSOL(object_instance_ref_put(instance)); - instance = NULL; - } - goto exit; -} - -res_T -ssol_object_instance_ref_get(struct ssol_object_instance* instance) -{ - if(!instance) - return RES_BAD_ARG; - ref_get(&instance->ref); - return RES_OK; -} - -res_T -ssol_object_instance_ref_put - (struct ssol_object_instance* instance) -{ - if (!instance) - return RES_BAD_ARG; - ref_put(&instance->ref, object_instance_release); - return RES_OK; -} - -res_T -ssol_object_instance_set_transform - (struct ssol_object_instance* instance, const double transform[12]) -{ - float t[12]; - int i; - res_T res = RES_OK; - - if(!instance || !transform) { - res = RES_BAD_ARG; - goto error; - } - - FOR_EACH(i, 0, 12) t[i] = (float)transform[i]; - - res = s3d_instance_set_transform(instance->shape_rt, t); - if(res != RES_OK) goto error; - - if(instance->shape_rt != instance->shape_samp) { - res = s3d_instance_set_transform(instance->shape_samp, t); - if(res != RES_OK) goto error; - } - -exit: - return res; -error: - goto exit; -} - -res_T -ssol_object_instance_set_receiver - (struct ssol_object_instance* instance, - const char* name) -{ - if(!instance) - return RES_BAD_ARG; - - if(name) { - return str_set(&instance->receiver_name, name); - } else { - str_clear(&instance->receiver_name); - return RES_OK; - } -} - -res_T -ssol_object_instance_set_target_mask - (struct ssol_object_instance* instance, - const uint32_t mask) -{ - if (!instance) - return RES_BAD_ARG; - - instance->target_mask = mask; - return RES_OK; -} - -res_T -ssol_object_instance_is_attached - (struct ssol_object_instance* instance, char* is_attached) -{ - FATAL("Not implemented yet."); - if(!instance || !is_attached) return RES_BAD_ARG; - return RES_OK; -} - diff --git a/src/ssol_object_instance_c.h b/src/ssol_object_instance_c.h @@ -1,44 +0,0 @@ -/* Copyright (C) CNRS 2016 - * - * 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 SSOL_OBJECT_INSTANCE_C_H -#define SSOL_OBJECT_INSTANCE_C_H - -#include <rsys/list.h> -#include <rsys/ref_count.h> -#include <rsys/str.h> - -struct ssol_object_instance -{ - struct ssol_object* object; /* Instantiated object */ - struct s3d_shape* shape_rt; /* Instantiated Star-3D shape to ray-trace */ - struct s3d_shape* shape_samp; /* Instantiated Star-3D shape to sample */ - struct str receiver_name; /* Empty if not a receiver */ - double transform[12]; - uint32_t target_mask; - - struct ssol_device* dev; - ref_T ref; -}; - -static INLINE const char* -object_instance_get_receiver_name(const struct ssol_object_instance* instance) -{ - ASSERT(instance); - return str_is_empty(&instance->receiver_name) - ? NULL : str_cget(&instance->receiver_name); -} - -#endif /* SSOL_OBJECT_INSTANCE_C_H */ diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -21,7 +21,7 @@ #include "ssol_device_c.h" #include "ssol_material_c.h" #include "ssol_object_c.h" -#include "ssol_object_instance_c.h" +#include "ssol_instance_c.h" #include <rsys/list.h> #include <rsys/mem_allocator.h> @@ -108,8 +108,8 @@ ssol_scene_ref_put(struct ssol_scene* scene) } res_T -ssol_scene_attach_object_instance - (struct ssol_scene* scene, struct ssol_object_instance* instance) +ssol_scene_attach_instance + (struct ssol_scene* scene, struct ssol_instance* instance) { unsigned id; res_T res; @@ -128,17 +128,17 @@ ssol_scene_attach_object_instance S3D(scene_detach_shape(scene->scn_rt, instance->shape_rt)); return res; } - SSOL(object_instance_ref_get(instance)); + SSOL(instance_ref_get(instance)); return RES_OK; } res_T -ssol_scene_detach_object_instance +ssol_scene_detach_instance (struct ssol_scene* scene, - struct ssol_object_instance* instance) + struct ssol_instance* instance) { - struct ssol_object_instance** pinst; - struct ssol_object_instance* inst; + struct ssol_instance** pinst; + struct ssol_instance* inst; unsigned id; size_t n; (void)n, (void)inst; @@ -158,7 +158,7 @@ ssol_scene_detach_object_instance n = htable_instance_erase(&scene->instances_rt, &id); ASSERT(n == 1); S3D(scene_detach_shape(scene->scn_rt, instance->shape_rt)); - SSOL(object_instance_ref_put(instance)); + SSOL(instance_ref_put(instance)); return RES_OK; } @@ -172,10 +172,10 @@ ssol_scene_clear(struct ssol_scene* scene) htable_instance_begin(&scene->instances_rt, &it); htable_instance_end(&scene->instances_rt, &it_end); while(!htable_instance_iterator_eq(&it, &it_end)) { - struct ssol_object_instance* inst; + struct ssol_instance* inst; inst = *htable_instance_iterator_data_get(&it); S3D(scene_detach_shape(scene->scn_rt, inst->shape_rt)); - SSOL(object_instance_ref_put(inst)); + SSOL(instance_ref_put(inst)); htable_instance_iterator_next(&it); } htable_instance_clear(&scene->instances_rt); @@ -230,7 +230,7 @@ scene_setup_s3d_sampling_scene(struct ssol_scene* scn) htable_instance_end(&scn->instances_rt, &end); while(!htable_instance_iterator_eq(&it, &end)) { - struct ssol_object_instance* inst = *htable_instance_iterator_data_get(&it); + struct ssol_instance* inst = *htable_instance_iterator_data_get(&it); unsigned id; htable_instance_iterator_next(&it); @@ -271,7 +271,7 @@ hit_filter_function void* realisation, void* filter_data) { - struct ssol_object_instance* inst; + struct ssol_instance* inst; const char* receiver_name; struct realisation* rs = realisation; struct segment* seg; @@ -292,7 +292,7 @@ hit_filter_function inst = *htable_instance_find(&rs->data.scene->instances_rt, &hit->prim.inst_id); /* Check if the hit surface is a receiver that registers hit data */ - receiver_name = object_instance_get_receiver_name(inst); + receiver_name = instance_get_receiver_name(inst); if(receiver_name) { float cos_in; /* check normal orientation */ diff --git a/src/ssol_scene_c.h b/src/ssol_scene_c.h @@ -20,12 +20,12 @@ #include <rsys/ref_count.h> #include <rsys/rsys.h> -struct ssol_object_instance; +struct ssol_instance; /* Define the htable_instance data structure */ #define HTABLE_NAME instance #define HTABLE_KEY unsigned /* S3D object instance identifier */ -#define HTABLE_DATA struct ssol_object_instance* +#define HTABLE_DATA struct ssol_instance* #include <rsys/hash_table.h> /* Forward declarations */ diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -23,7 +23,7 @@ #include "ssol_sun_c.h" #include "ssol_material_c.h" #include "ssol_spectrum_c.h" -#include "ssol_object_instance_c.h" +#include "ssol_instance_c.h" #include "ssol_brdf_composite.h" #include <rsys/mem_allocator.h> @@ -41,14 +41,14 @@ static const char* END_TEXT[] = END_TEXT__; * Helper functions ******************************************************************************/ static INLINE int -is_instance_punched(const struct ssol_object_instance* instance) +is_instance_punched(const struct ssol_instance* instance) { ASSERT(instance); return instance->object->shape->type == SHAPE_PUNCHED; } static INLINE const struct ssol_quadric* -get_quadric(const struct ssol_object_instance* instance) +get_quadric(const struct ssol_instance* instance) { ASSERT(instance && is_instance_punched(instance)); return &instance->object->shape->quadric; @@ -298,7 +298,7 @@ release_realisation(struct realisation* rs) static INLINE struct ssol_material* get_material_from_hit(struct ssol_scene* scene, struct s3d_hit* hit) { - struct ssol_object_instance* inst; + struct ssol_instance* inst; ASSERT(scene && hit); inst = *htable_instance_find(&scene->instances_rt, &hit->prim.inst_id); return inst->object->material; @@ -390,7 +390,7 @@ receive_sunlight(struct realisation* rs) if (!receives) return receives; /* if the sampled instance is a receiver, register the sampled point */ - receiver_name = object_instance_get_receiver_name(rs->start.instance); + receiver_name = instance_get_receiver_name(rs->start.instance); if (receiver_name) { /* normal orientation has already been checked */ fprintf(rs->data.out_stream, diff --git a/src/ssol_solver_c.h b/src/ssol_solver_c.h @@ -65,7 +65,7 @@ struct segment { }; struct starting_point { - struct ssol_object_instance* instance; + struct ssol_instance* instance; struct ssol_material* material; struct s3d_primitive primitive; double sundir[3]; @@ -91,7 +91,7 @@ struct solver_data { struct ssp_ranst_piecewise_linear* sun_spectrum_ran; /* Tmp data used for propagation */ struct brdf_composite* brdfs; - struct ssol_object_instance* instance; + struct ssol_instance* instance; struct surface_fragment fragment; }; diff --git a/src/test_ssol_instance.c b/src/test_ssol_instance.c @@ -0,0 +1,87 @@ +/* Copyright (C) CNRS 2016 + * + * 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 "ssol.h" +#include "test_ssol_utils.h" + +#include <rsys/logger.h> + +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + struct ssol_shape* shape; + struct ssol_material* material; + struct ssol_object* object; + struct ssol_instance* instance; + double transform[12]; + (void) argc, (void) argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(logger_init(&allocator, &logger), RES_OK); + logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); + logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); + logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); + + CHECK(ssol_device_create + (&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + + CHECK(ssol_material_create_virtual(dev, &material), RES_OK); + + CHECK(ssol_shape_create_punched_surface(dev, &shape), RES_OK); + CHECK(ssol_object_create(dev, shape, material, &object), RES_OK); + + CHECK(ssol_object_instantiate(object, &instance), RES_OK); + + CHECK(ssol_instance_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_instance_ref_get(instance), RES_OK); + + CHECK(ssol_instance_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_instance_ref_put(instance), RES_OK); + + CHECK(ssol_instance_set_transform(NULL, transform), RES_BAD_ARG); + CHECK(ssol_instance_set_transform(instance, NULL), RES_BAD_ARG); + CHECK(ssol_instance_set_transform(instance, transform), RES_OK); + + CHECK(ssol_instance_set_receiver(NULL, "receiver 1"), RES_BAD_ARG); + CHECK(ssol_instance_set_receiver(instance, NULL), RES_OK); + CHECK(ssol_instance_set_receiver(instance, "receiver 1"), RES_OK); + CHECK(ssol_instance_set_receiver(instance, "receiver 0"), RES_OK); + CHECK(ssol_instance_set_receiver(instance, NULL), RES_OK); + + CHECK(ssol_instance_set_target_mask(NULL, 1), RES_BAD_ARG); + CHECK(ssol_instance_set_target_mask(instance, 1), RES_OK); + CHECK(ssol_instance_set_target_mask(instance, 0), RES_OK); + CHECK(ssol_instance_set_target_mask(instance, 0x10), RES_OK); + + CHECK(ssol_instance_ref_put(instance), RES_OK); + + CHECK(ssol_object_ref_put(object), RES_OK); + CHECK(ssol_shape_ref_put(shape), RES_OK); + CHECK(ssol_material_ref_put(material), RES_OK); + + CHECK(ssol_device_ref_put(dev), RES_OK); + + logger_release(&logger); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + + return 0; +} diff --git a/src/test_ssol_object_instance.c b/src/test_ssol_object_instance.c @@ -1,87 +0,0 @@ -/* Copyright (C) CNRS 2016 - * - * 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 "ssol.h" -#include "test_ssol_utils.h" - -#include <rsys/logger.h> - -int -main(int argc, char** argv) -{ - struct logger logger; - struct mem_allocator allocator; - struct ssol_device* dev; - struct ssol_shape* shape; - struct ssol_material* material; - struct ssol_object* object; - struct ssol_object_instance* instance; - double transform[12]; - (void) argc, (void) argv; - - mem_init_proxy_allocator(&allocator, &mem_default_allocator); - - CHECK(logger_init(&allocator, &logger), RES_OK); - logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); - logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); - logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); - - CHECK(ssol_device_create - (&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); - - CHECK(ssol_material_create_virtual(dev, &material), RES_OK); - - CHECK(ssol_shape_create_punched_surface(dev, &shape), RES_OK); - CHECK(ssol_object_create(dev, shape, material, &object), RES_OK); - - CHECK(ssol_object_instantiate(object, &instance), RES_OK); - - CHECK(ssol_object_instance_ref_get(NULL), RES_BAD_ARG); - CHECK(ssol_object_instance_ref_get(instance), RES_OK); - - CHECK(ssol_object_instance_ref_put(NULL), RES_BAD_ARG); - CHECK(ssol_object_instance_ref_put(instance), RES_OK); - - CHECK(ssol_object_instance_set_transform(NULL, transform), RES_BAD_ARG); - CHECK(ssol_object_instance_set_transform(instance, NULL), RES_BAD_ARG); - CHECK(ssol_object_instance_set_transform(instance, transform), RES_OK); - - CHECK(ssol_object_instance_set_receiver(NULL, "receiver 1"), RES_BAD_ARG); - CHECK(ssol_object_instance_set_receiver(instance, NULL), RES_OK); - CHECK(ssol_object_instance_set_receiver(instance, "receiver 1"), RES_OK); - CHECK(ssol_object_instance_set_receiver(instance, "receiver 0"), RES_OK); - CHECK(ssol_object_instance_set_receiver(instance, NULL), RES_OK); - - CHECK(ssol_object_instance_set_target_mask(NULL, 1), RES_BAD_ARG); - CHECK(ssol_object_instance_set_target_mask(instance, 1), RES_OK); - CHECK(ssol_object_instance_set_target_mask(instance, 0), RES_OK); - CHECK(ssol_object_instance_set_target_mask(instance, 0x10), RES_OK); - - CHECK(ssol_object_instance_ref_put(instance), RES_OK); - - CHECK(ssol_object_ref_put(object), RES_OK); - CHECK(ssol_shape_ref_put(shape), RES_OK); - CHECK(ssol_material_ref_put(material), RES_OK); - - CHECK(ssol_device_ref_put(dev), RES_OK); - - logger_release(&logger); - - check_memory_allocator(&allocator); - mem_shutdown_proxy_allocator(&allocator); - CHECK(mem_allocated_size(), 0); - - return 0; -} diff --git a/src/test_ssol_scene.c b/src/test_ssol_scene.c @@ -27,7 +27,7 @@ main(int argc, char** argv) struct ssol_shape* shape; struct ssol_material* material; struct ssol_object* object; - struct ssol_object_instance* instance; + struct ssol_instance* instance; struct ssol_sun* sun; struct ssol_sun* sun2; struct ssol_scene* scene; @@ -49,7 +49,7 @@ main(int argc, char** argv) CHECK(ssol_shape_create_punched_surface(dev, &shape), RES_OK); CHECK(ssol_object_create(dev, shape, material, &object), RES_OK); CHECK(ssol_object_instantiate(object, &instance), RES_OK); - CHECK(ssol_object_instance_set_transform(instance, transform), RES_OK); + CHECK(ssol_instance_set_transform(instance, transform), RES_OK); CHECK(ssol_sun_create_directional(dev, &sun), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); @@ -60,15 +60,15 @@ main(int argc, char** argv) CHECK(ssol_scene_ref_put(NULL), RES_BAD_ARG); CHECK(ssol_scene_ref_put(scene), RES_OK); - CHECK(ssol_scene_attach_object_instance(NULL, instance), RES_BAD_ARG); - CHECK(ssol_scene_attach_object_instance(scene, NULL), RES_BAD_ARG); - CHECK(ssol_scene_attach_object_instance(scene, instance), RES_OK); + CHECK(ssol_scene_attach_instance(NULL, instance), RES_BAD_ARG); + CHECK(ssol_scene_attach_instance(scene, NULL), RES_BAD_ARG); + CHECK(ssol_scene_attach_instance(scene, instance), RES_OK); - CHECK(ssol_scene_detach_object_instance(NULL, instance), RES_BAD_ARG); - CHECK(ssol_scene_detach_object_instance(scene, NULL), RES_BAD_ARG); - CHECK(ssol_scene_detach_object_instance(scene, instance), RES_OK); + CHECK(ssol_scene_detach_instance(NULL, instance), RES_BAD_ARG); + CHECK(ssol_scene_detach_instance(scene, NULL), RES_BAD_ARG); + CHECK(ssol_scene_detach_instance(scene, instance), RES_OK); - CHECK(ssol_scene_attach_object_instance(scene, instance), RES_OK); + CHECK(ssol_scene_attach_instance(scene, instance), RES_OK); CHECK(ssol_scene_clear(NULL), RES_BAD_ARG); CHECK(ssol_scene_clear(scene), RES_OK); @@ -88,7 +88,7 @@ main(int argc, char** argv) CHECK(ssol_scene_ref_put(scene), RES_OK); - CHECK(ssol_object_instance_ref_put(instance), RES_OK); + CHECK(ssol_instance_ref_put(instance), RES_OK); CHECK(ssol_object_ref_put(object), RES_OK); CHECK(ssol_shape_ref_put(shape), RES_OK); CHECK(ssol_sun_ref_put(sun), RES_OK); diff --git a/src/test_ssol_solver.c b/src/test_ssol_solver.c @@ -44,9 +44,9 @@ main(int argc, char** argv) struct ssol_mirror_shader shader; struct ssol_object* m_object; struct ssol_object* t_object; - struct ssol_object_instance* heliostat; - struct ssol_object_instance* secondary; - struct ssol_object_instance* target; + struct ssol_instance* heliostat; + struct ssol_instance* secondary; + struct ssol_instance* target; struct ssol_sun* sun; struct ssol_spectrum* spectrum; double dir[3]; @@ -110,30 +110,30 @@ main(int argc, char** argv) CHECK(ssol_object_create(dev, square, m_material, &m_object), RES_OK); CHECK(ssol_object_instantiate(m_object, &heliostat), RES_OK); - CHECK(ssol_object_instance_set_receiver(heliostat, "miroir"), RES_OK); - CHECK(ssol_object_instance_set_target_mask(heliostat, 0x1), RES_OK); - CHECK(ssol_scene_attach_object_instance(scene, heliostat), RES_OK); + CHECK(ssol_instance_set_receiver(heliostat, "miroir"), RES_OK); + CHECK(ssol_instance_set_target_mask(heliostat, 0x1), RES_OK); + CHECK(ssol_scene_attach_instance(scene, heliostat), RES_OK); CHECK(ssol_object_instantiate(m_object, &secondary), RES_OK); - CHECK(ssol_object_instance_set_receiver(secondary, "secondaire"), RES_OK); - CHECK(ssol_object_instance_set_transform(secondary, transform1), RES_OK); - CHECK(ssol_object_instance_set_target_mask(secondary, 0x2), RES_OK); - CHECK(ssol_scene_attach_object_instance(scene, secondary), RES_OK); + CHECK(ssol_instance_set_receiver(secondary, "secondaire"), RES_OK); + CHECK(ssol_instance_set_transform(secondary, transform1), RES_OK); + CHECK(ssol_instance_set_target_mask(secondary, 0x2), RES_OK); + CHECK(ssol_scene_attach_instance(scene, secondary), RES_OK); CHECK(ssol_object_create(dev, square, v_material, &t_object), RES_OK); CHECK(ssol_object_instantiate(t_object, &target), RES_OK); - CHECK(ssol_object_instance_set_transform(target, transform2), RES_OK); - CHECK(ssol_object_instance_set_receiver(target, "cible"), RES_OK); - CHECK(ssol_object_instance_set_target_mask(target, 0x4), RES_OK); - CHECK(ssol_scene_attach_object_instance(scene, target), RES_OK); + CHECK(ssol_instance_set_transform(target, transform2), RES_OK); + CHECK(ssol_instance_set_receiver(target, "cible"), RES_OK); + CHECK(ssol_instance_set_target_mask(target, 0x4), RES_OK); + CHECK(ssol_scene_attach_instance(scene, target), RES_OK); CHECK(ssol_solve(scene, rng, 20, stdout), RES_OK); /* free data */ - CHECK(ssol_object_instance_ref_put(heliostat), RES_OK); - CHECK(ssol_object_instance_ref_put(secondary), RES_OK); - CHECK(ssol_object_instance_ref_put(target), RES_OK); + CHECK(ssol_instance_ref_put(heliostat), RES_OK); + CHECK(ssol_instance_ref_put(secondary), RES_OK); + CHECK(ssol_instance_ref_put(target), RES_OK); CHECK(ssol_object_ref_put(m_object), RES_OK); CHECK(ssol_object_ref_put(t_object), RES_OK); CHECK(ssol_shape_ref_put(square), RES_OK);