Commit 143a773d authored by Laurent Belcour's avatar Laurent Belcour

[Refactor] Moving ALTA code into its own namespace.

parent f4f77c35
......@@ -20,12 +20,14 @@
#include "common.h"
namespace alta {
/*! \brief A useful class for storing the high-level arguments of a program
* or a function.
* \ingroup core
* \internal
*
* The set of parameters are parsed from the command line using the
* The set of parameters are parsed from the command line using the
* constructor. They are stored as std::string in a std::map.
* \todo add functionalities to provide new parameters values.
*/
......@@ -85,7 +87,7 @@ class arguments
#endif
data.append(next);
}
}//end of if
}//end of if
#ifdef DEBUG_ARGS
std::cout << "]" << std::endl;
#endif
......@@ -93,7 +95,7 @@ class arguments
}//end of if test with "--"
}//end of for-loop
}
~arguments()
{
}
......@@ -140,13 +142,13 @@ class arguments
return std::string() ;
}
}
//! \brief update the value \a val stored under key \a key
void update(const std::string& key, const std::string& val)
{
_map[key] = val;
}
//! \brief acces to the string value associated with the parameter
//! \a key.
//!
......@@ -181,7 +183,7 @@ class arguments
{
//IF C++ 2011 is supported and activated
#if __cplusplus > 199711L
auto search = _map.find(key);
if ( search != _map.end() )
{
......@@ -190,13 +192,13 @@ class arguments
return default_value;
#else
std::map<std::string,std::string>::const_iterator res = _map.find(key);
if ( res != _map.end() )
{
return std::atof( res->second.c_str() );
}
return default_value;
#endif
}
......@@ -212,8 +214,8 @@ class arguments
return atoi(_map.find(key)->second.c_str()) ;
else
return default_value ;
}
}
//! \brief acces to a vector of float of size \a size associated with
//! the parameter \a key.
//!
......@@ -270,8 +272,8 @@ class arguments
{
std::vector<T> res;
//TODO: RP: it is not very efficient to call count + find
// because find is called twice !!!
//TODO: RP: it is not very efficient to call count + find
// because find is called twice !!!
// My advice: find should be called once, check if the key exist
// and if yes use the iterator returned by find
if(_map.count(key) > 0)
......@@ -331,7 +333,7 @@ class arguments
}
return res;
}
//! \brief access a pair of element of type \a T.
//! the string associated with the key \a key should have the form
//! "a b" where a, b are compatible with type \a T.
......@@ -340,8 +342,8 @@ class arguments
std::pair<T, T> res;
//TODO: RP: it is not very efficient to call count + find
// because find is called twice !!!
//TODO: RP: it is not very efficient to call count + find
// because find is called twice !!!
// My advice: find should be called once, check if the key exist
// and if yes use the iterator returned by find
if(_map.count(key) > 0) {
......@@ -480,7 +482,7 @@ class arguments
}
}
// Store the line into the argument
// Store the line into the argument
} else {
while(!linestream.eof() && std::isspace(linestream.peek())) {
linestream.get();
......@@ -491,7 +493,7 @@ class arguments
}
}
}
// The first non-comment line terminates the header.
} else {
break;
......@@ -506,4 +508,5 @@ class arguments
std::map<std::string, std::string> _map ;
} ;
};
}
......@@ -15,6 +15,8 @@
#include <vector>
namespace alta {
#ifdef OLD
class clustering : public data
{
......@@ -62,3 +64,4 @@ class clustering : public data
#endif
#include "clustering.cpp"
}
......@@ -25,6 +25,8 @@
#include <iostream>
#include <cassert>
using namespace alta;
vec product(const vec& a, const vec& b)
{
if (a.size() == 1)
......
......@@ -75,6 +75,8 @@ std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
return out;
}
namespace alta {
//! \brief locate the first index of value v in vector vec. Complexity in
//! O(n) is the worst case.
template<typename T> int is_in(std::vector<T> ve, T v)
......@@ -170,6 +172,13 @@ template<typename T> bool isnan(T x)
#else
#define ALTA_DLL_EXPORT extern "C"
#endif
}
namespace alta {
class timer;
}
std::ostream& operator<<(std::ostream& out, const alta::timer& t);
namespace alta {
/*! \brief The timer class: a cross plateform timing solution
*/
......@@ -197,7 +206,7 @@ class timer
void print(std::ostream& out) const;
//! \brief ostream compliant operator
friend std::ostream& operator<<(std::ostream& out, const timer& t);
friend std::ostream& ::operator<<(std::ostream& out, const timer& t);
private:
......@@ -238,3 +247,4 @@ class timer
<< std::endl; \
exit(EXIT_FAILURE); \
}
}
......@@ -13,6 +13,8 @@
#include "data.h"
#include "data_storage.h"
using namespace alta;
void data::save(const std::string& filename) const
{
std::ofstream file;
......
......@@ -23,6 +23,14 @@
#include "clustering.h"
#include "ptr.h"
namespace alta {
class data;
}
void load_data_from_binary(std::istream& in, const alta::arguments& header, alta::data& data);
namespace alta {
/*! \brief A data object. Allows to load data from files.
* \ingroup core
*/
......@@ -79,8 +87,8 @@ class data : public parametrized
double epsilon =
std::pow(1.0, -int(std::numeric_limits<double>::digits10 - 1)));
friend void load_data_from_binary(std::istream& in, const arguments& header,
data& data);
friend void ::load_data_from_binary(std::istream& in, const alta::arguments& header,
alta::data& data);
protected: // data
} ;
......@@ -177,5 +185,6 @@ class data_params : public data
std::vector<vec> _data;
};
}
/* -*- c++ -*- */
......@@ -21,6 +21,8 @@
# include <endian.h>
#endif
using namespace alta;
void vertical_segment::load_data_from_text(std::istream& input,
const arguments& header,
vertical_segment& result,
......
......@@ -16,11 +16,11 @@
#include "args.h"
// Write DATA to OUT in ALTA's text format.
void save_data_as_text(std::ostream& out, const data &data);
void save_data_as_text(std::ostream& out, const alta::data &data);
// Write DATA to OUT in a compact binary format.
void save_data_as_binary(std::ostream& out, const data& data);
void save_data_as_binary(std::ostream& out, const alta::data& data);
// Initialize DATA from the binary-formatted stream IN.
void load_data_from_binary(std::istream& in, const arguments& header,
data &data);
void load_data_from_binary(std::istream& in, const alta::arguments& header,
alta::data &data);
......@@ -15,6 +15,8 @@
#include "args.h"
#include "common.h"
namespace alta {
/*! \brief Fitting interface for generic fitting algorithms
* \ingroup core
*
......@@ -37,4 +39,5 @@ class fitter
//! multiple call to the fit_data procedure
virtual void set_parameters(const arguments& args) = 0 ;
} ;
};
}
......@@ -15,6 +15,8 @@
#include "params.h"
#include "plugins_manager.h"
using namespace alta;
/*--- Functions implementation ----*/
void function::bootstrap(const ptr<data>, const arguments& args)
......
......@@ -21,6 +21,8 @@
#include "params.h"
#include "data.h"
namespace alta {
/*! \brief A representation of an analytical function.
* \ingroup core
*
......@@ -426,3 +428,4 @@ class cosine_function : public nonlinear_function
return jac;
}
};
}
#include "metrics.h"
using namespace alta;
void errors::compute(const data* in, const data* ref,
const data* mask, metrics& res) {
......
......@@ -18,6 +18,8 @@
// STL includes
#include <map>
namespace alta {
/*!
* \brief Error metrics class
*
......@@ -74,3 +76,4 @@ class errors {
Eigen::VectorXd& mse,
Eigen::VectorXd& rmse);
};
}
......@@ -13,6 +13,8 @@
#include "common.h"
#include <cassert>
using namespace alta;
struct param_info
{
param_info(std::string n, int d, std::string i) :
......
......@@ -23,6 +23,8 @@
#include "common.h"
namespace alta {
/*! \class params
* \ingroup core
* \brief a static class allowing to change from one parametrization
......@@ -564,3 +566,4 @@ class parametrized
int _nX, _nY ;
vec _min, _max ;
};
}
......@@ -22,6 +22,8 @@
#include <stdio.h>
#include <list>
using namespace alta;
//#define DEBUG
......
......@@ -22,6 +22,8 @@
#include "clustering.h"
#include "ptr.h"
namespace alta {
/*! \class plugins_manager
* \brief This class permits to load plugin from shared library files.
* \ingroup core
......@@ -76,4 +78,5 @@ class plugins_manager
typedef function* (*FunctionPrototype)();
typedef fitter* (*FitterPrototype)();
typedef data* (*DataPrototype)(const arguments&);
} ;
};
}
......@@ -18,6 +18,9 @@
*/
#include <memory>
namespace alta {
template<class T> using ptr = std::shared_ptr<T>;
template<class T, class U>
......@@ -25,3 +28,4 @@ inline ptr<U> dynamic_pointer_cast(const ptr<T>& ptr_t)
{
return std::dynamic_pointer_cast<U>(ptr_t);
}
}
......@@ -18,6 +18,8 @@
#include <algorithm>
#include <cmath>
using namespace alta;
rational_function_1d::rational_function_1d()
{
}
......@@ -449,8 +451,10 @@ vec rational_function_1d::value(const vec& x) const
std::ostream& operator<< (std::ostream& out, const rational_function_1d& r)
{
const unsigned int np = r._p_coeffs.size();
const unsigned int nq = r._q_coeffs.size();
const auto p = r.getP();
const auto q = r.getQ();
const unsigned int np = p.size();
const unsigned int nq = q.size();
std::cout << "p = [" ;
for(unsigned int i=0; i<np; ++i)
......@@ -459,7 +463,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function_1d& r)
{
std::cout << ", " ;
}
std::cout << r._p_coeffs[i].a ;
std::cout << p[i];
}
std::cout << "]" << std::endl ;
......@@ -470,7 +474,7 @@ std::ostream& operator<< (std::ostream& out, const rational_function_1d& r)
{
std::cout << ", " ;
}
std::cout << r._q_coeffs[i].a ;
std::cout << q[i];
}
std::cout << "]" << std::endl ;
......@@ -643,7 +647,7 @@ void rational_function::save_call(std::ostream& out, const arguments& args) cons
}
}
std::ostream& operator<< (std::ostream& out, rational_function& r)
std::ostream& operator<< (std::ostream& out, const rational_function& r)
{
for(int i=0; i<r.dimY(); ++i)
{
......
......@@ -23,6 +23,17 @@
#include "common.h"
namespace alta {
class rational_function_1d;
class rational_function;
}
// STL stream ouput
std::ostream& operator<< (std::ostream&, const alta::rational_function_1d&);
std::ostream& operator<< (std::ostream&, const alta::rational_function&);
namespace alta {
/*! \brief A one dimensional rational function class. A rational function has
* the form \f$r(x) = \dfrac{\sum_{i} a_i p_i(x)}{b_i q_i(x)}$\f.
*/
......@@ -116,10 +127,6 @@ class rational_function_1d : public function
}
// STL stream ouput
friend std::ostream& operator<< (std::ostream& out,
const rational_function_1d& r) ;
//! Convert a 1D index into a vector of degree for a
//! multinomial coeffcient. The resulting vector v should
//! be used as prod_k x[k]^v[k] for the monomial basis
......@@ -198,9 +205,6 @@ class rational_function : public function
virtual rational_function_1d* get(int i) ;
virtual rational_function_1d* get(int i) const ;
// STL stream ouput
friend std::ostream& operator<<(std::ostream& out, rational_function& r) ;
//! Set the dimension of the output space of the function. This function
//! will update the size of the rs vector size.
virtual void setDimY(int nY)
......@@ -249,4 +253,5 @@ class rational_function : public function
//! \todo Change it by a more adaptive scheme, with different np, nq per
//! color channel?
int np, nq;
} ;
};
}
......@@ -19,6 +19,8 @@
#include <cmath>
#include <cassert>
using namespace alta;
//#define RELATIVE_ERROR
vertical_segment::vertical_segment(unsigned int dim_X,
......
......@@ -22,6 +22,8 @@
#include "fitter.h"
#include "args.h"
namespace alta {
/*! \ingroup core
* \ingroup datas
*
......@@ -155,6 +157,7 @@ class vertical_segment : public data
// relative or absolute intervals? What is the dt used ?
bool _is_absolute;
double _dt;
} ;
};
}
/* -*- c++ -*- */
......@@ -18,6 +18,8 @@
#include <iomanip>
#include <fstream>
using namespace alta;
vec get_min(const params::input& param) {
vec res(params::dimension(param));
......
......@@ -24,6 +24,8 @@
// Matlab includes
#include <engine.h>
using namespace alta;
mxArray *X, *Y, *x, *y;
#define BUFFER_SIZE 10000
......@@ -222,4 +224,4 @@ class MatlabInterpolant : public data
ALTA_DLL_EXPORT data* provide_data(const arguments&)
{
return new MatlabInterpolant();
}
\ No newline at end of file
}
......@@ -32,6 +32,8 @@ int dD;
#include <flann/flann.hpp>
#endif
using namespace alta;
/*! \ingroup datas
* \ingroup plugins
* \class data_interpolant_rbf
......@@ -240,4 +242,4 @@ class rbf_interpolant : public data
ALTA_DLL_EXPORT data* provide_data(const arguments&)
{
return new rbf_interpolant();
}
\ No newline at end of file
}
......@@ -21,6 +21,8 @@
#include <cstdlib>
#include <cmath>
using namespace alta;
/*! \ingroup datas
* \ingroup plugins
* \class data_astm
......
......@@ -42,6 +42,8 @@
#define GREEN_SCALE (1.15/1500.0)
#define BLUE_SCALE (1.66/1500.0)
using namespace alta;
/*! \ingroup datas
* \class data_merl
......
......@@ -16,6 +16,8 @@
#include "EXR_IO.h"
using namespace alta;
/*! \ingroup datas
* \class data_brdf_slice
* \brief Data interface for the BRDF slice file format.
......
......@@ -28,6 +28,8 @@
#include "EXR_IO.h"
using namespace alta;
/*! \ingroup datas
* \class data_utia
* \brief Data interface for the [UTIA][utia] file format.
......
......@@ -22,6 +22,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT fitter* provide_fitter()
{
return new nonlinear_fitter_ceres();
......
......@@ -24,6 +24,8 @@
// CERES include
#include <ceres/ceres.h>
using namespace alta;
/*! \brief A non-linear fitter using the CERES solver
* \ingroup plugins
* \ingroup fitters
......
......@@ -23,6 +23,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT fitter* provide_fitter()
{
return new nonlinear_fitter_eigen();
......
......@@ -21,6 +21,8 @@
#include <core/args.h>
#include <core/vertical_segment.h>
using namespace alta;
/*! \brief A fitter for non-linear BRDF models that uses Eigen's
* Levenberg-Marquardt solver.
* \ingroup plugins
......
......@@ -25,6 +25,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT fitter* provide_fitter()
{
return new nonlinear_fitter_ipopt();
......
......@@ -20,6 +20,8 @@
#include <core/fitter.h>
#include <core/args.h>
using namespace alta;
/*! \brief A non-linear fitter using the COIN-OR IpOpt solver
* \ingroup plugins
* \ingroup fitters
......
......@@ -21,6 +21,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT fitter* provide_fitter()
{
return new nonlinear_fitter_nlopt();
......
......@@ -21,6 +21,8 @@
#include <core/args.h>
#include <core/vertical_segment.h>
using namespace alta;
/*! \brief A non-linear fitter using the NLOpt solver
* \ingroup plugins
* \ingroup fitters
......
......@@ -19,6 +19,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT function* provide_function()
{
return new schlick();
......
......@@ -21,6 +21,8 @@
#include <core/args.h>
#include <core/common.h>
using namespace alta;
class schlick : public nonlinear_function
{
......
......@@ -19,6 +19,8 @@
#include <core/common.h>
using namespace alta;
ALTA_DLL_EXPORT function* provide_function()
{
return new retro_schlick();
......
......@@ -21,6 +21,8 @@
#include <core/args.h>
#include <core/common.h>
using namespace alta;
class retro_schlick : public nonlinear_function
{
......