Commit eade1e0b authored by Romain Pacanowski's avatar Romain Pacanowski

Added two static functions to test whether or not a geometrical configuration...

 Added two static functions to test whether or not a geometrical configuration is above the hemisphere
 Added a new unit test for the params::is_above_hemisphere static function
parent e5dccfc7
......@@ -831,3 +831,21 @@ void params::print_input_params()
std::cout << it->second.info << std::endl;
}
}
bool
params::is_above_hemisphere( double* const invec, params::input in_param_type )
{
vec input_in_cartesian(6);
params::convert(invec, in_param_type, params::CARTESIAN, &input_in_cartesian[0]);
return input_in_cartesian[2] >= 0.0 && input_in_cartesian[5] >= 0.0;
}
......@@ -415,6 +415,17 @@ class params
static void print_input_params();
//! \brief Check whether or not a (light,view) configuration is above the hemisphere
//! \return true if both vectors (light and view) are above and false otherwise
//! \remark the function returns true also for grazing, tangential configuration
//! (i.e., where light dot normal == 0 or view dot normal == 0)
static bool is_above_hemisphere( double* invec, params::input intype );
static bool inline is_below_hemisphere( double* invec, params::input intype )
{
return ! is_above_hemisphere(invec, intype);
}
};
/*! \brief A parameters object. Allow to define function object (either data
......
......@@ -177,6 +177,7 @@ CXX_TESTS = [ 'core/half-test-1.cpp',
'core/half-test-3.cpp',
'core/half-test-4.cpp',
'core/params-test-1.cpp',
'core/params-test-2.cpp',
'core/data-io.cpp',
'core/nonlinear-fit.cpp' ]
......
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2016 CNRS, romain.pacanowski@institutoptique.fr
This file is part of ALTA.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// ALTA includes
#include <core/params.h>
#include <tests.h>
using namespace alta;
using namespace alta::tests;
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <random>
typedef std::mt19937_64 GENERATOR_TYPE;
/* Test different configurations for the Half / Cartesian parametrization. */
int main(int argc, char** argv)
{
unsigned int const NB_TESTS = 1000;
unsigned int nb_pass = 0;
// Number of failed tests
unsigned int nb_fail = 0;
// Testing is Above with Cartesians Configurations
std::uniform_real_distribution<> distribution(-1.0, 1.0);
GENERATOR_TYPE generator( time(NULL) );
vec input_lv(6);
for (unsigned int i = 0; i < NB_TESTS; ++i)
{
double const l_x = distribution( generator );
double const l_y = distribution( generator );
double const l_z = std::sqrt(std::max( 1.0 - l_x*l_x - l_y*l_y, 0.0) );
double const v_x = distribution( generator );
double const v_y = distribution( generator );
double const v_z = std::sqrt( std::max( 1.0 - v_x*v_x - v_y*v_y, 0.0) );
input_lv(0) = l_x; input_lv(1) = l_y; input_lv(2) = l_z;
input_lv(3) = v_x; input_lv(4) = v_y; input_lv(5) = v_z;
if( params::is_above_hemisphere( &input_lv[0], params::CARTESIAN ) )
{
nb_pass++;
}
else
{
nb_fail++;
}
}
if(nb_fail > 0) {
std::cerr << "<<ERROR>> " << nb_fail << " out of " << NB_TESTS
<< " configurations fail the test is_above_hemisphere "
<< std::endl;
}
return nb_fail > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment