solstice-solver

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

commit 5fb2c34804f535e78b41405f4c5a5de67765013c
parent b794fca287b2c2103af70a29972e0db1f3281407
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue, 28 Jun 2016 18:48:27 +0200

First try to objects.

Diffstat:
Mcmake/CMakeLists.txt | 3+++
Msrc/ssol.h | 12++----------
Asrc/ssol_object.c | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ssol_object_c.h | 29+++++++++++++++++++++++++++++
Asrc/test_ssol_object.c | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 294 insertions(+), 10 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -49,6 +49,7 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(SSOL_FILES_SRC ssol_device.c ssol_material.c + ssol_object.c ssol_shape.c) set(SSOL_FILES_INC_API @@ -57,6 +58,7 @@ set(SSOL_FILES_INC_API set(SSOL_FILES_INC ssol_device_c.h ssol_material_c.h + ssol_object_c.h ssol_shape_c.h) set(SSOL_FILES_DOC COPYING README.md) @@ -108,6 +110,7 @@ if(NOT NO_TEST) new_test(test_ssol_device) new_test(test_ssol_material) + new_test(test_ssol_object) new_test(test_ssol_shape) endif(NOT NO_TEST) diff --git a/src/ssol.h b/src/ssol.h @@ -369,6 +369,8 @@ ssol_mirror_set_shader SSOL_API res_T ssol_object_create (struct ssol_device* dev, + struct ssol_shape* shape, + struct ssol_material* mtl, struct ssol_object** obj); SSOL_API res_T @@ -379,16 +381,6 @@ SSOL_API res_T ssol_object_ref_put (struct ssol_object* obj); -SSOL_API res_T /* Geometric shape of the object */ -ssol_object_set_shape - (struct ssol_object* obj, - struct ssol_shape* shape); - -SSOL_API res_T /* Properties of the object */ -ssol_object_set_material - (struct ssol_object* obj, - struct ssol_material* mtl); - /******************************************************************************* * Object Instance API - Clone of an object with a set of per instance data as * world transformation, material parameters, etc. Note that the object diff --git a/src/ssol_object.c b/src/ssol_object.c @@ -0,0 +1,117 @@ +/* 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_device_c.h" + +#include <rsys\rsys.h> +#include <rsys\mem_allocator.h> +#include <rsys\ref_count.h> + +/******************************************************************************* +* Helper functions +******************************************************************************/ + +static void +object_release(ref_T* ref) +{ + struct ssol_object* object; + ASSERT(ref); + object = CONTAINER_OF(ref, struct ssol_object, ref); + + ASSERT(object->dev && object->dev->allocator); + + SSOL(shape_ref_put(object->shape)); + SSOL(material_ref_put(object->material)); + SSOL(device_ref_put(object->dev)); + MEM_RM(object->dev->allocator, object); +} + +static INLINE res_T +object_ok(const struct ssol_object* object) { + if (!object + || !object->shape + || !object->material) + return RES_BAD_ARG; + return RES_OK; +} + +/******************************************************************************* +* Local functions +******************************************************************************/ + +/******************************************************************************* +* Exported ssol_material functions +******************************************************************************/ + +res_T +ssol_object_create + (struct ssol_device* dev, + struct ssol_shape* shape, + struct ssol_material* material, + struct ssol_object** out_object) +{ + struct ssol_object* object = NULL; + res_T res = RES_OK; + if (!dev || !shape || !material || !out_object) { + return RES_BAD_ARG; + } + + object = (struct ssol_object*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct ssol_object)); + if (!object) { + res = RES_MEM_ERR; + goto error; + } + + SSOL(shape_ref_get(shape)); + SSOL(material_ref_get(material)); + SSOL(device_ref_get(dev)); + object->dev = dev; + object->shape = shape; + object->material = material; + ref_init(&object->ref); + +exit: + if (out_object) *out_object = object; + return res; +error: + if (object) { + SSOL(object_ref_put(object)); + object = NULL; + } + goto exit; +} + +res_T +ssol_object_ref_get + (struct ssol_object* object) +{ + if (!object) + return RES_BAD_ARG; + ref_get(&object->ref); + return RES_OK; +} + +res_T +ssol_object_ref_put + (struct ssol_object* object) +{ + if (!object) + return RES_BAD_ARG; + ref_put(&object->ref, object_release); + return RES_OK; +} diff --git a/src/ssol_object_c.h b/src/ssol_object_c.h @@ -0,0 +1,29 @@ +/* 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_C_H +#define SSOL_OBJECT_C_H + +#include <rsys/ref_count.h> + +struct ssol_object { + struct ssol_shape* shape; + struct ssol_material* material; + + struct ssol_device* dev; + ref_T ref; +}; + +#endif /* SSOL_OBJECT_C_H */ diff --git a/src/test_ssol_object.c b/src/test_ssol_object.c @@ -0,0 +1,142 @@ +/* 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> + +static void +get_shading_normal +(struct ssol_device* dev, + const double wavelength, + const double P[3], + const double Ng[3], + const double uv[2], + const double wo[3], + double* val) +{ + int i; + (void) dev; (void) wavelength; (void) P; (void) uv; (void) wo; + for (i = 0; i < 3; i++) val[i] = Ng[i]; +} + +static void +get_reflectivity +(struct ssol_device* dev, + const double wavelength, + const double P[3], + const double Ng[3], + const double uv[2], + const double wo[3], + double* val) +{ + (void) dev; (void) wavelength; (void) P; (void) Ng; (void) uv; (void) wo; + *val = 1; +} + +static void +get_diffuse_specular_ratio +(struct ssol_device* dev, + const double wavelength, + const double P[3], + const double Ng[3], + const double uv[2], + const double wo[3], + double* val) +{ + (void) dev; (void) wavelength; (void) P; (void) Ng; (void) uv; (void) wo; + *val = 0; +} + +static void +get_roughness +(struct ssol_device* dev, + const double wavelength, + const double P[3], + const double Ng[3], + const double uv[2], + const double wo[3], + double* val) +{ + (void) dev; (void) wavelength; (void) P; (void) Ng; (void) uv; (void) wo; + *val = 0; +} + +/******************************************************************************* +* test main program +******************************************************************************/ +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + struct ssol_carving carving; + struct ssol_quadric quadric; + struct ssol_shape* shape; + struct ssol_punched_surface punched_surface; + struct ssol_material* material; + struct ssol_object* object; + (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); + + carving.type = SSOL_CARVING_CIRCLE; + carving.internal = 0; + carving.data.circle.center[0] = 0; + carving.data.circle.center[1] = 0; + carving.data.circle.radius = 1; + quadric.type = SSOL_QUADRIC_PLANE; + punched_surface.nb_carvings = 1; + punched_surface.quadric = &quadric; + punched_surface.carvings = &carving; + CHECK(ssol_shape_create_punched_surface(dev, &shape), RES_OK); + + CHECK(ssol_object_create(NULL, shape, material, &object), RES_BAD_ARG); + CHECK(ssol_object_create(dev, NULL, material, &object), RES_BAD_ARG); + CHECK(ssol_object_create(dev, shape, NULL, &object), RES_BAD_ARG); + CHECK(ssol_object_create(dev, shape, material, NULL), RES_BAD_ARG); + CHECK(ssol_object_create(dev, shape, material, &object), RES_OK); + + CHECK(ssol_object_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_object_ref_get(object), RES_OK); + + CHECK(ssol_object_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_object_ref_put(object), 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; +} +\ No newline at end of file