rational_function.h 3.23 KB
Newer Older
1 2
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions

3
   Copyright (C) 2014, 2016 Inria
4 5 6 7 8 9 10

   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/.  */

11 12 13 14 15 16 17 18 19 20 21 22 23 24
#pragma once

// Include STL
#include <vector>
#include <string>

// Interface
#include <core/function.h>
#include <core/rational_function.h>
#include <core/data.h>
#include <core/fitter.h>
#include <core/args.h>
#include <core/common.h>

25 26
using namespace alta;

27 28 29 30
class rational_function_legendre_1d : public rational_function_1d
{
	public: // methods

31 32
    rational_function_legendre_1d(const parameters& params, int np, int nq);

33
		rational_function_legendre_1d() ;
34
		rational_function_legendre_1d(int nX, int np, int nq, params::input params) ;
35 36 37 38 39 40 41 42 43 44 45 46
		virtual ~rational_function_legendre_1d() {}

		// Get the p_i and q_j function
		virtual double p(const vec& x, int i) const ;
		virtual double q(const vec& x, int j) const ;

	protected:  // methods

		// Legendre polynomial evaluation
		double legendre(double x, int i) const;
} ;

47
/*! \ingroup functions
48 49 50 51
 *  \class rational_function_cosine
 *  \brief Rational function using 
 *  [Legendre polynomials](https://en.wikipedia.org/wiki/Legendre_polynomials),
 *  with a cosine factor.
52 53 54
 *
 *  \details 
 *
55 56 57
 *  This class uses the implementation of the \ref rational_function_legendre
 *  plugin as a basis. The resulting value is multiplied by the product of the
 *  elevation of the light and view directions.
58
 *
59
 *  \author Laurent Belcour \<laurent.belcour@umontreal.ca\>
60
 */
61 62 63 64
class rational_function_legendre : public rational_function
{
	public: // methods

65 66
    rational_function_legendre(const parameters& params);
		rational_function_legendre() ALTA_DEPRECATED;
67 68 69 70 71 72 73
		virtual ~rational_function_legendre() ;

		//! Get the 1D function associated with color channel i. If no one exist, 
		//! this function allocates a new element. If i > nY, it returns NULL.
		virtual rational_function_1d* get(int i)
		{
			// Check for consistency in the index of color channel
74
			if(i < _parameters.dimY())
75 76 77
			{
				if(rs[i] == NULL)
				{
78 79
					rs[i] = new rational_function_legendre_1d(_parameters.dimX(), np, nq,
                                                    _parameters.input_parametrization());
80 81 82
					
					vec _min = min();
					vec _max = max();
83
					for(int k=0; k<_parameters.dimX(); ++k)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
					{
						if(_min[k] == _max[k])
						{
							_min[k] -= 1.0;
							_max[k] += 1.0;
						}
					}

					rs[i]->setMin(_min) ;
					rs[i]->setMax(_max) ;
				}
				return rs[i];
			}
			else
			{
				std::cout << "<<ERROR>> tried to access out of bound 1D RF" 
				          << std::endl;
				return NULL;
			}
		}

		//! Update the y-1D function for the ith dimension.
		//! \note It will test if the 1D function provided is of the dynamic type
		//! \name rational_function_legendre_1d
		virtual void update(int i, rational_function_1d* r)
		{
			if(dynamic_cast<rational_function_legendre_1d*>(r) != NULL)
			{
				rational_function::update(i, r);
			}
			else
			{
#ifdef DEBUG
				std::cerr << "<<ERROR>> the function provided is not of type \"rational_function_legendre\"" << std::endl;
#endif
			}
		}
} ;