Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
alta
alta
Commits
e8b02d62
Commit
e8b02d62
authored
May 23, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Got fitting of Phong from MERL BRDFs
parent
e255951a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
28 deletions
+112
-28
sources/core/clustering.cpp
sources/core/clustering.cpp
+51
-0
sources/core/clustering.h
sources/core/clustering.h
+9
-2
sources/core/core.pro
sources/core/core.pro
+1
-1
sources/core/data.h
sources/core/data.h
+36
-20
sources/core/params.h
sources/core/params.h
+13
-5
sources/core/plugins_manager.h
sources/core/plugins_manager.h
+2
-0
No files found.
sources/core/clustering.cpp
View file @
e8b02d62
...
...
@@ -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
sources/core/clustering.h
View file @
e8b02d62
#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"
sources/core/core.pro
View file @
e8b02d62
...
...
@@ -18,4 +18,4 @@ HEADERS = args.h \
SOURCES
=
plugins_manager
.
cpp
\
vertical_segment
.
cpp
\
rational_function
.
cpp
\
clustering
.
cpp
#
clustering
.
cpp
sources/core/data.h
View file @
e8b02d62
...
...
@@ -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
_d
ata
.
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
;
};
sources/core/params.h
View file @
e8b02d62
...
...
@@ -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.
...
...
sources/core/plugins_manager.h
View file @
e8b02d62
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment