commit 5d18cd205ba4fb127b1d1b910477fefa08365c26
parent d011c481c4d08e9a7324cd75f4714344fef599ef
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 19 Apr 2016 11:34:35 +0200
Add a test for the Henyey-Greenstein distribution.
Diffstat:
2 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -142,6 +142,7 @@ if(NOT NO_TEST)
new_test(test_ssp_ran_discrete)
new_test(test_ssp_ran_hemisphere ${MATH_LIB})
new_test(test_ssp_ran_sphere ${MATH_LIB})
+ new_test(test_ssp_ran_hg ${MATH_LIB})
new_test(test_ssp_ran_triangle ${MATH_LIB})
new_test(test_ssp_rng_proxy)
endif()
diff --git a/src/test_ssp_ran_hg.c b/src/test_ssp_ran_hg.c
@@ -0,0 +1,75 @@
+/* Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#include "ssp.h"
+#include "test_ssp_utils.h"
+
+#define NG 100
+#define NSAMPS 10000
+
+int
+main(int argc, char** argv)
+{
+ struct ssp_rng* rng;
+ struct mem_allocator allocator;
+int i, j;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
+
+ FOR_EACH(i, 0, NG) {
+ /* for any value of g... */
+ double g = ssp_rng_uniform_double(rng, -1, +1);
+ double sum_cos = 0;
+ double sum_cos_local = 0;
+ float dir[4], up[4] = {0, 0, 1};
+ FOR_EACH(j, 0, NSAMPS) {
+ /* HG relative to the Z axis */
+ ssp_ran_sphere_hg_local(rng, g, dir);
+ sum_cos_local += f3_dot(up, dir);
+ }
+ FOR_EACH(j, 0, NSAMPS) {
+ /* HG relative to a up uniformaly sampled */
+ ssp_ran_hemisphere_uniform_local(rng, up);
+ ssp_ran_sphere_hg(rng, up, g, dir);
+ sum_cos += f3_dot(up, dir);
+ }
+ /* ...on average cos(up, dir) should be g */
+ CHECK(eq_eps(sum_cos_local / NSAMPS, g, 2.5e-2), 1);
+ CHECK(eq_eps(sum_cos / NSAMPS, g, 2.5e-2), 1);
+ }
+
+ ssp_rng_ref_put(rng);
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}