Commit e8b02d62 authored by Laurent Belcour's avatar Laurent Belcour

Got fitting of Phong from MERL BRDFs

parent e255951a
......@@ -5,6 +5,7 @@
#include <string>
#include <fstream>
#ifdef OLD
clustering::clustering(const data* d, const arguments& args)
{
// List of the indices of the clustering
......@@ -113,3 +114,53 @@ vec clustering::max() const
{
return _max;
}
#else
template<class T> void clustering(const T* in_data, int _nY, params::input in_param, params::input out_param, std::vector<vec>& out_data)
{
// Set the dimensions
const int in_nX = params::dimension(in_param);
const int out_nX = params::dimension(out_param);
std::cout << " in dim = " << in_nX << std::endl;
std::cout << "out dim = " << out_nX << std::endl;
for(int i=0; i<in_data->size(); ++i)
{
vec p = in_data->get(i);
vec e (out_nX + _nY);
// Fill the input part of the vector
params::convert(&p[0], in_param, out_param, &e[0]);
// Search for duplicates
bool already_exist = false;
for(unsigned int j=0; j<out_data.size(); ++j)
{
vec test_e = out_data[j];
double dist = 0.0;
for(int k=0; k<out_nX; ++k)
{
const double temp = test_e[k]-e[k];
dist += temp*temp;
}
if(dist < 1.0E-5)
already_exist = true;
}
if(!already_exist)
{
// Fill the output part of the vector
for(int j=0; j<_nY; ++j)
e[out_nX + j] = p[in_nX + j];
std::cout << " in = " << p << std::endl;
std::cout << "out = " << e << std::endl;
out_data.push_back(e);
}
}
}
#endif
#pragma once
#include "data.h"
#include "common.h"
#include "params.h"
#include <vector>
#ifdef OLD
class clustering : public data
{
public: // methods
//! \brief constructor loading a full dimension data and clustering
//! it into a low dimension one.
clustering(const data* d, const arguments& args);
clustering::clustering(const data* d, const arguments& args);
//! \brief the clustering class can save a clustering to a file.
virtual void save(const std::string& filename);
......@@ -46,3 +48,8 @@ class clustering : public data
std::vector<vec> _data;
vec _min, _max;
};
#else
template<class T> void clustering(const T* in_data , int nY, params::input in_param, params::input out_param, std::vector<vec>& out_data);
#endif
#include "clustering.cpp"
......@@ -18,4 +18,4 @@ HEADERS = args.h \
SOURCES = plugins_manager.cpp \
vertical_segment.cpp \
rational_function.cpp \
clustering.cpp
#clustering.cpp
......@@ -2,12 +2,16 @@
#include <string>
#include <utility>
#include <iostream>
#include <limits>
#include <fstream>
#include <QtPlugin>
#include "common.h"
#include "args.h"
#include "params.h"
#include "clustering.h"
/*! \brief A data object. Allows to load data from files.
* \ingroup core
......@@ -20,6 +24,23 @@ class data
virtual void load(const std::string& filename) = 0 ;
virtual void load(const std::string& filename, const arguments& args) = 0 ;
// Save the data to a file
virtual void save(const std::string& filename)
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
file << "#DIM " << _nX << " " << _nY << std::endl;
for(int i=0; i<size(); ++i)
{
vec x = this->get(i);
for(int j=0; j<_nX+_nY; ++j)
{
file << x[j] << "\t";
}
file << std::endl;
}
file.close();
}
// Acces to data
virtual vec get(int i) const = 0 ;
virtual vec operator[](int i) const = 0 ;
......@@ -96,17 +117,18 @@ class data_params : public data
//! \brief contructor requires the definition of a base class that
//! has a parametrization, and a new parametrization.
data_params(const data* d, params::input param,
data_params(const data* d, params::input new_param,
data_params::clustrering method = data_params::NONE) :
_d(d), _param_in(param), _clustering_method(method)
_clustering_method(method)
{
_nX = params::dimension(param);
_nX = params::dimension(new_param);
_nY = d->dimY();
if(_nX < _d->dimX() && method == data_params::NONE)
{
throw("No cluster method provided");
}
std::cout << "<<INFO>> Reparametrization of the data" << std::endl;
clustering<data>(d, _nY, d->parametrization(), new_param, _data);
std::cout << "<<INFO>> clustering left " << _data.size() << "/" << d->size() << " elements" << std::endl;
save(std::string("cluster.gnuplot"));
}
// Load data from a file
......@@ -125,13 +147,7 @@ class data_params : public data
// Acces to data
virtual vec get(int i) const
{
vec res(_nX + _nY);
vec in = _d->get(i);
params::convert(&in[0], _d->parametrization(), _param_in, &res[0]);
memcpy(&res[_nX], &in[_d->dimX()], _nY*sizeof(double));
return res;
return _data[i];
}
virtual vec operator[](int i) const
{
......@@ -141,24 +157,24 @@ class data_params : public data
// Get data size, e.g. the number of samples to fit
virtual int size() const
{
return _d->size();
return _data.size();
}
// Get min and max input space values
virtual vec min() const
{
return _d->min();
return _min;
}
virtual vec max() const
{
return _d->max();
return _max;
}
protected: // data
const data* _d;
params::input _param_in;
data_params::clustrering _clustering_method;
//! \todo Add a cluster object that will duplicate data or store indices.
std::vector<vec> _data;
vec _min, _max;
};
......@@ -85,7 +85,7 @@ class params
if(dim > 0)
{
double* outvec = new double[dim];
double temvec[6]; // Temp CARTESIAN vectors
double temvec[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // Temp CARTESIAN vectors
to_cartesian(invec, intype, temvec);
from_cartesian(temvec, outtype, outvec);
......@@ -103,8 +103,13 @@ class params
static void convert(const double* invec, params::input intype,
params::input outtype, double* outvec)
{
double temvec[6]; // Temp CARTESIAN vectors
double temvec[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // Temp CARTESIAN vectors
to_cartesian(invec, intype, temvec);
#ifdef DEBUG
std::cout << "<<DEBUG>> temp vec = ["
<< temvec[0] << ", " << temvec[1] << ", " << temvec[2] << "] => ["
<< temvec[3] << ", " << temvec[4] << ", " << temvec[5] << "]" << std::endl;
#endif
from_cartesian(temvec, outtype, outvec);
}
......@@ -194,7 +199,7 @@ class params
break;
default:
throw("Transformation not implemented, params::from_cartesian");
assert(false);
break;
}
}
......@@ -211,6 +216,7 @@ class params
// 2D Parametrizations
case params::ISOTROPIC_TD_PD:
case params::RUSIN_TH_TD:
case params::ROMEIRO_TH_TD:
case params::COS_TH_TD:
return 2;
......@@ -235,6 +241,7 @@ class params
break;
default:
assert(false);
return -1;
break;
}
......@@ -258,6 +265,7 @@ class params
break;
default:
assert(false);
return -1;
break;
}
......@@ -278,8 +286,8 @@ class params
out[0] = sin(theta_d)*cos(phi_d);
out[1] = sin(theta_d)*sin(phi_d);
out[2] = cos(theta_d);
rotate_binormal(out, theta_h);
rotate_normal(out, phi_h);
rotate_binormal(out, phi_h);
rotate_normal(out, theta_h);
// Compute the out vector from the in vector and the half
// vector.
......
......@@ -79,12 +79,14 @@ class plugins_manager
std::cout << "<<DEBUG>> no change was made to the parametrization" << std::endl;
}
/*
// Check is the data has to be clusterized
if(args.is_defined("cluster-dim"))
{
clustering* cluster = new clustering(d, args);
d = cluster;
}
*/
}
//! \brief Provide a measure of how much memory there is on the system.
......
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