Commit 66af095d authored by Sylvain Thery's avatar Sylvain Thery

testing Utils

parent 2e16f9c5
...@@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 2.6) ...@@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 2.6)
project(testing) project(testing)
add_subdirectory(Geometry)
add_subdirectory(Algo) add_subdirectory(Algo)
add_subdirectory(Geometry)
add_subdirectory(Utils)
#define exec to compile #define exec to compile
......
cmake_minimum_required(VERSION 2.6)
project(testing_utils)
add_executable( test_utils
test_utils.cpp
colorMaps.cpp
colourConverter.cpp
qem.cpp
quadricRGBfunctions.cpp
quantization.cpp
# shared_mem.cpp
sphericalHarmonics.cpp
textures.cpp )
target_link_libraries( test_utils
${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
//
// TODO template<REAL> instead of float
#include "Utils/colourConverter.h"
template class CGoGN::Utils::ColourConverter<float>;
template class CGoGN::Utils::ColourConverter<double>;
int test_colourConverter()
{
return 0;
}
#include "Utils/qem.h"
template class CGoGN::Utils::Quadric<float>;
template class CGoGN::Utils::Quadric<double>;
template class CGoGN::Utils::QuadricNd<float,5>;
template class CGoGN::Utils::QuadricNd<double,6>;
template class CGoGN::Utils::QuadricHF<float>;
template class CGoGN::Utils::QuadricHF<double>;
int test_qem()
{
return 0;
}
#include "Utils/quadricRGBfunctions.h"
template class CGoGN::Utils::QuadricRGBfunctions<float>;
template class CGoGN::Utils::QuadricRGBfunctions<double>;
int test_quadricRGBfunctions()
{
return 0;
}
\ No newline at end of file
#include "Utils/quantization.h"
#include "Geometry/vector_gen.h"
using namespace CGoGN;
template struct Utils::CodeVector<Geom::Vec3f>;
template struct Utils::CodeVector<Geom::Vec3d>;
template struct Utils::CodeVector<Geom::Vec4d>;
template class Utils::Quantization<Geom::Vec3f>;
template class Utils::Quantization<Geom::Vec3d>;
template class Utils::Quantization<Geom::Vec4d>;
int test_quantization()
{
return 0;
}
#include "Utils/shared_mem.h"
#include "Geometry/vector_gen.h"
template class CGoGN::Utils::SharedMemSeg<int>;
template class CGoGN::Utils::SharedMemSeg<float>;
template class CGoGN::Utils::SharedMemSeg<double>;
template class CGoGN::Utils::SharedMemSeg<CGoGN::Geom::Vec4f>;
int test_shared_mem()
{
return 0;
}
#include "Utils/sphericalHarmonics.h"
template class CGoGN::Utils::SphericalHarmonics<float, float>;
template class CGoGN::Utils::SphericalHarmonics<double, double>;
template class CGoGN::Utils::SphericalHarmonics<float, double>;
template class CGoGN::Utils::SphericalHarmonics<double, float>;
int test_sphericalHarmonics()
{
return 0;
}
#include <iostream>
// no header files test function names from cpp files
//extern int test_colorMaps();
extern int test_colourConverter();
extern int test_qem();
extern int test_quadricRGBfunctions();
extern int test_quantization();
//extern int test_shared_mem();
extern int test_sphericalHarmonics();
extern int test_texture();
int main()
{
//test_colorMaps();
test_colourConverter();
test_qem();
test_quadricRGBfunctions();
test_quantization();
// test_shared_mem();
test_sphericalHarmonics();
test_texture();
return 0;
}
#include "Utils/textures.h"
template class CGoGN::Utils::Filter<2>;
template class CGoGN::Utils::Filter<3>;
template class CGoGN::Utils::ImageData<2, unsigned char>;
template class CGoGN::Utils::Image<2, unsigned char>;
template class CGoGN::Utils::Texture<2, unsigned char>;
template class CGoGN::Utils::ImageData<2, int>;
template class CGoGN::Utils::Image<2, int>;
template class CGoGN::Utils::Texture<2, int>;
template class CGoGN::Utils::ImageData<2, double>;
template class CGoGN::Utils::Image<2, double>;
template class CGoGN::Utils::Texture<2, double>;
int test_texture()
{
return 0;
}
\ No newline at end of file
...@@ -218,7 +218,7 @@ private : // private constants ...@@ -218,7 +218,7 @@ private : // private constants
//static const REAL Zy = -0.685222 ; //static const REAL Zy = -0.685222 ;
//static const REAL Zz = 0.339219 ; //static const REAL Zz = 0.339219 ;
// only integral static const cana be init inline in standard C++ (float init is gcc extension) // only integral static const can be init inline in standard C++ (float init is gcc extension)
static const REAL Xx; static const REAL Xx;
static const REAL Xy; static const REAL Xy;
static const REAL Xz; static const REAL Xz;
......
...@@ -167,13 +167,21 @@ private: // private members ...@@ -167,13 +167,21 @@ private: // private members
private: // private constants private: // private constants
// D65 reference white // D65 reference white
static constexpr REAL Xn = 0.950456 ; //static constexpr REAL Xn = 0.950456 ;
static constexpr REAL Yn = 1.0 ; //static constexpr REAL Yn = 1.0 ;
static constexpr REAL Zn = 1.088754 ; //static constexpr REAL Zn = 1.088754 ;
static constexpr REAL un = 0.197832 ; //static constexpr REAL un = 0.197832 ;
static constexpr REAL vn = 0.468340 ; //static constexpr REAL vn = 0.468340 ;
// constexpr not supported in VS2013
static const REAL Xn;
static const REAL Yn;
static const REAL Zn;
static const REAL un;
static const REAL vn;
} ; } ;
} // namespace Utils } // namespace Utils
......
...@@ -22,12 +22,29 @@ ...@@ -22,12 +22,29 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <algorithm>
namespace CGoGN namespace CGoGN
{ {
namespace Utils namespace Utils
{ {
template<typename REAL>
const REAL ColourConverter<REAL>::Xn = REAL(0.950456);
template<typename REAL>
const REAL ColourConverter<REAL>::Yn = REAL(1.0);
template<typename REAL>
const REAL ColourConverter<REAL>::Zn = REAL(1.088754);
template<typename REAL>
const REAL ColourConverter<REAL>::un = REAL(0.197832);
template<typename REAL>
const REAL ColourConverter<REAL>::vn = REAL(0.468340);
template<typename REAL> template<typename REAL>
ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) : ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) :
RGB(NULL), RGB(NULL),
...@@ -209,17 +226,17 @@ ColourConverter<REAL>::convertRGBtoXYZ() ...@@ -209,17 +226,17 @@ ColourConverter<REAL>::convertRGBtoXYZ()
{ {
Geom::Matrix<3,3,REAL> M ; Geom::Matrix<3,3,REAL> M ;
M(0,0) = 0.412453 ; M(0,0) = REAL(0.412453);
M(0,1) = 0.357580 ; M(0, 1) = REAL(0.357580);
M(0,2) = 0.180423 ; M(0, 2) = REAL(0.180423);
M(1,0) = 0.212671 ; M(1, 0) = REAL(0.212671);
M(1,1) = 0.715160 ; M(1, 1) = REAL(0.715160);
M(1,2) = 0.072169 ; M(1, 2) = REAL(0.072169);
M(2,0) = 0.019334 ; M(2, 0) = REAL(0.019334);
M(2,1) = 0.119193 ; M(2, 1) = REAL(0.119193);
M(2,2) = 0.950227 ; M(2, 2) = REAL(0.950227);
VEC3 c = M * (*RGB) ; VEC3 c = M * (*RGB) ;
...@@ -235,17 +252,17 @@ ColourConverter<REAL>::convertXYZtoRGB() ...@@ -235,17 +252,17 @@ ColourConverter<REAL>::convertXYZtoRGB()
{ {
Geom::Matrix<3,3,REAL> M ; Geom::Matrix<3,3,REAL> M ;
M(0,0) = 3.240479 ; M(0, 0) = REAL(3.240479);
M(0,1) = -1.537150 ; M(0, 1) = REAL(-1.537150);
M(0,2) = -0.498535 ; M(0, 2) = REAL(-0.498535);
M(1,0) = -0.969256 ; M(1, 0) = REAL(-0.969256);
M(1,1) = 1.875992 ; M(1, 1) = REAL(1.875992);
M(1,2) = 0.041556 ; M(1, 2) = REAL(0.041556);
M(2,0) = 0.055648 ; M(2, 0) = REAL(0.055648);
M(2,1) = -0.204043 ; M(2, 1) = REAL(-0.204043);
M(2,2) = 1.057311 ; M(2, 2) = REAL(1.057311);
VEC3 c = M * (*XYZ) ; VEC3 c = M * (*XYZ) ;
...@@ -274,7 +291,7 @@ ColourConverter<REAL>::convertRGBtoHSV() ...@@ -274,7 +291,7 @@ ColourConverter<REAL>::convertRGBtoHSV()
const REAL diff = max - min ; const REAL diff = max - min ;
V = max ; V = max ;
S = max == 0. ? 0 : diff / max ; S = max == 0.0f ? 0.0f : diff / max ;
if (max == min) if (max == min)
...@@ -312,7 +329,7 @@ ColourConverter<REAL>::convertHSVtoRGB() ...@@ -312,7 +329,7 @@ ColourConverter<REAL>::convertHSVtoRGB()
const REAL& S = (*HSV)[1] ; const REAL& S = (*HSV)[1] ;
const REAL& V = (*HSV)[2] ; const REAL& V = (*HSV)[2] ;
const int i = std::floor(H * 6); const int i = int(std::floor(H * 6));
const REAL f = H * 6 - i; const REAL f = H * 6 - i;
const REAL p = V * (1 - S); const REAL p = V * (1 - S);
const REAL q = V * (1 - f * S); const REAL q = V * (1 - f * S);
...@@ -355,7 +372,7 @@ ColourConverter<REAL>::convertRGBtoHSL() ...@@ -355,7 +372,7 @@ ColourConverter<REAL>::convertRGBtoHSL()
REAL& L = c[2] ; REAL& L = c[2] ;
const REAL sum = max + min ; const REAL sum = max + min ;
L = sum / 2. ; L = sum / 2.0f ;
if (max == min) if (max == min)
{ {
...@@ -365,7 +382,7 @@ ColourConverter<REAL>::convertRGBtoHSL() ...@@ -365,7 +382,7 @@ ColourConverter<REAL>::convertRGBtoHSL()
else else
{ {
const REAL diff = max - min ; const REAL diff = max - min ;
S = L > 0.5 ? diff / (2 - sum) : diff / sum ; S = L > 0.5f ? diff / (2 - sum) : diff / sum ;
if (max == r) if (max == r)
{ {
...@@ -401,7 +418,7 @@ ColourConverter<REAL>::hue2rgb(const REAL& p, const REAL& q, REAL t) ...@@ -401,7 +418,7 @@ ColourConverter<REAL>::hue2rgb(const REAL& p, const REAL& q, REAL t)
if(t < 1/2.) if(t < 1/2.)
return q ; return q ;
if(t < 2/3.) if(t < 2/3.)
return p + (q - p) * (2/3. - t) * 6 ; return p + (q - p) * (REAL(2.0/3.0) - t) * 6.0f ;
return p ; return p ;
} }
...@@ -429,9 +446,9 @@ ColourConverter<REAL>::convertHSLtoRGB() ...@@ -429,9 +446,9 @@ ColourConverter<REAL>::convertHSLtoRGB()
{ {
const REAL q = L < 0.5 ? L * (1 + S) : L + S - L * S; const REAL q = L < 0.5 ? L * (1 + S) : L + S - L * S;
const REAL p = 2 * L - q ; const REAL p = 2 * L - q ;
r = hue2rgb(p, q, H + 1/3.) ; r = hue2rgb(p, q, H + REAL(1./3.));
g = hue2rgb(p, q, H) ; g = hue2rgb(p, q, H) ;
b = hue2rgb(p, q, H - 1/3.) ; b = hue2rgb(p, q, H - REAL(1./3.)) ;
} }
if (RGB != NULL) if (RGB != NULL)
...@@ -452,13 +469,13 @@ ColourConverter<REAL>::convertXYZtoLuv() ...@@ -452,13 +469,13 @@ ColourConverter<REAL>::convertXYZtoLuv()
REAL Ydiv = Y/Yn ; REAL Ydiv = Y/Yn ;
if (Ydiv > 0.008856) if (Ydiv > 0.008856)
L = 116.0 * pow(Ydiv,1.0/3.0) - 16.0 ; L = 116.0f* pow(Ydiv,1.0f/3.0f) - 16.0f ;
else // near black else // near black
L = 903.3 * Ydiv ; L = 903.3f * Ydiv ;
REAL den = X + 15.0 * Y + 3 * Z ; REAL den = X + 15.0f * Y + 3 * Z ;
REAL u1 = (4.0 * X) / den ; REAL u1 = (4.0f * X) / den ;
REAL v1 = (9.0 * Y) / den ; REAL v1 = (9.0f * Y) / den ;
u = 13*L * (u1 - un) ; u = 13*L * (u1 - un) ;
v = 13*L * (v1 - vn) ; v = 13*L * (v1 - vn) ;
...@@ -479,16 +496,16 @@ ColourConverter<REAL>::convertLuvToXYZ() ...@@ -479,16 +496,16 @@ ColourConverter<REAL>::convertLuvToXYZ()
REAL &v = (*Luv)[2] ; REAL &v = (*Luv)[2] ;
if (L > 8.0) if (L > 8.0)
Y = pow(((L+16.0) / 116.0),3) ; Y = pow(((L+16.0f) / 116.0f),3) ;
else // near black else // near black
Y = Yn * L / 903.3 ; Y = Yn * L / 903.3f ;
REAL den = 13.0 * L ; REAL den = 13.0f * L ;
REAL u1 = u/den + un ; REAL u1 = u/den + un ;
REAL v1 = v/den + vn ; REAL v1 = v/den + vn ;
den = 4.0*v1 ; den = 4.0f*v1 ;
X = Y * 9.0 * u1 / den ; X = Y * 9.0f * u1 / den ;
Z = Y * (12.0 - 3.0*u1 - 20.0*v1) / den ; Z = Y * (12.0f - 3.0f*u1 - 20.0f*v1) / den ;
if (XYZ != NULL) if (XYZ != NULL)
*XYZ = VEC3(X,Y,Z) ; *XYZ = VEC3(X,Y,Z) ;
...@@ -511,19 +528,19 @@ ColourConverter<REAL>::convertXYZtoLab() ...@@ -511,19 +528,19 @@ ColourConverter<REAL>::convertXYZtoLab()
static REAL f(REAL x) static REAL f(REAL x)
{ {
if (x > 0.008856) if (x > 0.008856)
return pow(x,1.0/3.0) ; return pow(x,1.0f/3.0f) ;
else else
return 7.787 * x + 16.0/116.0 ; return 7.787f * x + 16.0f/116.0f ;
} }
} ; } ;
if (Y > 0.008856) if (Y > 0.008856)
L = 116.0f * pow(Y,1.0f/3.0) - 16 ; L = 116.0f * pow(Y,1.0f/3.0f) - 16 ;
else // near black else // near black
L = 903.3 * Y ; L = 903.3f * Y ;
a = 500.0 * (Local::f(X/Xn) - Local::f(Y/Yn)) ; a = 500.0f * (Local::f(X/Xn) - Local::f(Y/Yn)) ;
b = 200.0 * (Local::f(Y/Yn) - Local::f(Z/Zn)) ; b = 200.0f * (Local::f(Y/Yn) - Local::f(Z/Zn)) ;
if (Lab != NULL) if (Lab != NULL)
*Lab = VEC3(L,a,b) ; *Lab = VEC3(L,a,b) ;
...@@ -545,21 +562,21 @@ ColourConverter<REAL>::convertLabToXYZ() ...@@ -545,21 +562,21 @@ ColourConverter<REAL>::convertLabToXYZ()
{ {
static REAL f(REAL x) static REAL f(REAL x)
{ {
if (x > 0.206893) if (x > 0.206893f)
return pow(x,3.0) ; return pow(x,3.0f) ;
else else
return x / 7.787 - 16.0/903.3 ; return x / 7.787f - REAL(16.0/903.3) ;
} }
} ; } ;
if (L > 8.0) if (L > 8.0f)
Y = pow(((L+16.0) / 116.0),3) ; Y = pow(((L+16.0f) / 116.0f),3) ;
else // near black else // near black
Y = L / 903.3 ; Y = L / 903.3f ;
REAL nom = (L+16.0) / 116.0 ; REAL nom = (L+16.0f) / 116.0f ;
X = Xn * Local::f( nom + a/500.0) ; X = Xn * Local::f( nom + a/500.0f) ;
Z = Zn * Local::f( nom - b/200.0) ; Z = Zn * Local::f( nom - b/200.0f) ;
if (XYZ != NULL) if (XYZ != NULL)
*XYZ = VEC3(X,Y,Z) ; *XYZ = VEC3(X,Y,Z) ;
......
...@@ -263,7 +263,7 @@ QuadricNd<REAL,N>::operator() (const VECNp& v) const ...@@ -263,7 +263,7 @@ QuadricNd<REAL,N>::operator() (const VECNp& v) const
for (unsigned int i = 0 ; i < N ; ++i) for (unsigned int i = 0 ; i < N ; ++i)
hv[i] = v[i] ; hv[i] = v[i] ;
return evaluate(v) ; return evaluate(hv) ; // v instead of hv !!!
} }
template <typename REAL, unsigned int N> template <typename REAL, unsigned int N>
...@@ -340,7 +340,7 @@ template <typename REAL> ...@@ -340,7 +340,7 @@ template <typename REAL>
QuadricHF<REAL>::QuadricHF(const Geom::Tensor3d* T, const REAL& gamma, const REAL& alpha): QuadricHF<REAL>::QuadricHF(const Geom::Tensor3d* T, const REAL& gamma, const REAL& alpha):
m_noAlphaRot(fabs(alpha) < 1e-13) m_noAlphaRot(fabs(alpha) < 1e-13)
{ {
const unsigned int nbcoefs = ((T[0].order() + 1) * (T[0].order() + 2)) / 2. ; const unsigned int nbcoefs = int(((T[0].order() + 1) * (T[0].order() + 2)) / 2.0f );
// 2D rotation // 2D rotation
const Geom::Matrix33d R = buildRotateMatrix(gamma) ; const Geom::Matrix33d R = buildRotateMatrix(gamma) ;
...@@ -469,7 +469,7 @@ QuadricHF<REAL>& ...@@ -469,7 +469,7 @@ QuadricHF<REAL>&
QuadricHF<REAL>::operator /= (const REAL& v) QuadricHF<REAL>::operator /= (const REAL& v)
{ {
std::cout << "Warning: QuadricHF<REAL>::operator /= should not be used !" << std::endl ; std::cout << "Warning: QuadricHF<REAL>::operator /= should not be used !" << std::endl ;
const REAL& inv = 1. / v ; const REAL& inv = 1.0f / v ;
(*this) *= inv ; (*this) *= inv ;
...@@ -538,7 +538,7 @@ QuadricHF<REAL>::evalR3(const std::vector<VEC3>& coefs) const ...@@ -538,7 +538,7 @@ QuadricHF<REAL>::evalR3(const std::vector<VEC3>& coefs) const
for (unsigned int i = 0 ; i < coefs.size() ; ++i) for (unsigned int i = 0 ; i < coefs.size() ; ++i)
tmp[i] = coefs[i][c] ; tmp[i] = coefs[i][c] ;
res[c] = tmp.transpose() * m_A * tmp ; // A res[c] = tmp.transpose() * m_A * tmp ; // A
res[c] -= 2. * (m_b[c]).transpose() * tmp ; // - 2b res[c] -= 2.0f * (m_b[c]).transpose() * tmp ; // - 2b
res[c] += m_c[c] ; // + c res[c] += m_c[c] ; // + c
} }
...@@ -1192,8 +1192,8 @@ template <typename REAL> ...@@ -1192,8 +1192,8 @@ template <typename REAL>
Geom::Tensor3d* Geom::Tensor3d*
QuadricHF<REAL>::tensorsFromCoefs(const std::vector<VEC3>& coefs) QuadricHF<REAL>::tensorsFromCoefs(const std::vector<VEC3>& coefs)
{