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

testing Utils

parent 2e16f9c5
......@@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 2.6)
project(testing)
add_subdirectory(Geometry)
add_subdirectory(Algo)
add_subdirectory(Geometry)
add_subdirectory(Utils)
#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
//static const REAL Zy = -0.685222 ;
//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 Xy;
static const REAL Xz;
......
......@@ -167,13 +167,21 @@ private: // private members
private: // private constants
// D65 reference white
static constexpr REAL Xn = 0.950456 ;
static constexpr REAL Yn = 1.0 ;
static constexpr REAL Zn = 1.088754 ;
//static constexpr REAL Xn = 0.950456 ;
//static constexpr REAL Yn = 1.0 ;
//static constexpr REAL Zn = 1.088754 ;
static constexpr REAL un = 0.197832 ;
static constexpr REAL vn = 0.468340 ;
//static constexpr REAL un = 0.197832 ;
//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
......
......@@ -22,12 +22,29 @@
* *
*******************************************************************************/
#include <algorithm>
namespace CGoGN
{
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>
ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) :
RGB(NULL),
......@@ -209,17 +226,17 @@ ColourConverter<REAL>::convertRGBtoXYZ()
{
Geom::Matrix<3,3,REAL> M ;
M(0,0) = 0.412453 ;
M(0,1) = 0.357580 ;
M(0,2) = 0.180423 ;
M(0,0) = REAL(0.412453);
M(0, 1) = REAL(0.357580);
M(0, 2) = REAL(0.180423);
M(1,0) = 0.212671 ;
M(1,1) = 0.715160 ;
M(1,2) = 0.072169 ;
M(1, 0) = REAL(0.212671);
M(1, 1) = REAL(0.715160);
M(1, 2) = REAL(0.072169);
M(2,0) = 0.019334 ;
M(2,1) = 0.119193 ;
M(2,2) = 0.950227 ;
M(2, 0) = REAL(0.019334);
M(2, 1) = REAL(0.119193);
M(2, 2) = REAL(0.950227);
VEC3 c = M * (*RGB) ;
......@@ -235,17 +252,17 @@ ColourConverter<REAL>::convertXYZtoRGB()
{
Geom::Matrix<3,3,REAL> M ;
M(0,0) = 3.240479 ;
M(0,1) = -1.537150 ;
M(0,2) = -0.498535 ;
M(0, 0) = REAL(3.240479);
M(0, 1) = REAL(-1.537150);
M(0, 2) = REAL(-0.498535);
M(1,0) = -0.969256 ;
M(1,1) = 1.875992 ;
M(1,2) = 0.041556 ;
M(1, 0) = REAL(-0.969256);
M(1, 1) = REAL(1.875992);
M(1, 2) = REAL(0.041556);
M(2,0) = 0.055648 ;
M(2,1) = -0.204043 ;
M(2,2) = 1.057311 ;
M(2, 0) = REAL(0.055648);
M(2, 1) = REAL(-0.204043);
M(2, 2) = REAL(1.057311);
VEC3 c = M * (*XYZ) ;
......@@ -274,7 +291,7 @@ ColourConverter<REAL>::convertRGBtoHSV()
const REAL diff = max - min ;
V = max ;
S = max == 0. ? 0 : diff / max ;
S = max == 0.0f ? 0.0f : diff / max ;
if (max == min)
......@@ -312,7 +329,7 @@ ColourConverter<REAL>::convertHSVtoRGB()
const REAL& S = (*HSV)[1] ;
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 p = V * (1 - S);
const REAL q = V * (1 - f * S);
......@@ -355,7 +372,7 @@ ColourConverter<REAL>::convertRGBtoHSL()
REAL& L = c[2] ;
const REAL sum = max + min ;
L = sum / 2. ;
L = sum / 2.0f ;
if (max == min)
{
......@@ -365,7 +382,7 @@ ColourConverter<REAL>::convertRGBtoHSL()
else
{
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)
{
......@@ -401,7 +418,7 @@ ColourConverter<REAL>::hue2rgb(const REAL& p, const REAL& q, REAL t)
if(t < 1/2.)
return q ;
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 ;
}
......@@ -429,9 +446,9 @@ ColourConverter<REAL>::convertHSLtoRGB()
{
const REAL q = L < 0.5 ? L * (1 + S) : L + S - L * S;
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) ;
b = hue2rgb(p, q, H - 1/3.) ;
b = hue2rgb(p, q, H - REAL(1./3.)) ;
}
if (RGB != NULL)
......@@ -452,13 +469,13 @@ ColourConverter<REAL>::convertXYZtoLuv()
REAL Ydiv = Y/Yn ;
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
L = 903.3 * Ydiv ;
L = 903.3f * Ydiv ;
REAL den = X + 15.0 * Y + 3 * Z ;
REAL u1 = (4.0 * X) / den ;
REAL v1 = (9.0 * Y) / den ;
REAL den = X + 15.0f * Y + 3 * Z ;
REAL u1 = (4.0f * X) / den ;
REAL v1 = (9.0f * Y) / den ;
u = 13*L * (u1 - un) ;
v = 13*L * (v1 - vn) ;
......@@ -479,16 +496,16 @@ ColourConverter<REAL>::convertLuvToXYZ()
REAL &v = (*Luv)[2] ;
if (L > 8.0)
Y = pow(((L+16.0) / 116.0),3) ;
Y = pow(((L+16.0f) / 116.0f),3) ;
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 v1 = v/den + vn ;
den = 4.0*v1 ;
X = Y * 9.0 * u1 / den ;
Z = Y * (12.0 - 3.0*u1 - 20.0*v1) / den ;
den = 4.0f*v1 ;
X = Y * 9.0f * u1 / den ;
Z = Y * (12.0f - 3.0f*u1 - 20.0f*v1) / den ;
if (XYZ != NULL)
*XYZ = VEC3(X,Y,Z) ;
......@@ -511,19 +528,19 @@ ColourConverter<REAL>::convertXYZtoLab()
static REAL f(REAL x)
{
if (x > 0.008856)
return pow(x,1.0/3.0) ;
return pow(x,1.0f/3.0f) ;
else
return 7.787 * x + 16.0/116.0 ;
return 7.787f * x + 16.0f/116.0f ;
}
} ;
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
L = 903.3 * Y ;
L = 903.3f * Y ;
a = 500.0 * (Local::f(X/Xn) - Local::f(Y/Yn)) ;
b = 200.0 * (Local::f(Y/Yn) - Local::f(Z/Zn)) ;
a = 500.0f * (Local::f(X/Xn) - Local::f(Y/Yn)) ;
b = 200.0f * (Local::f(Y/Yn) - Local::f(Z/Zn)) ;
if (Lab != NULL)
*Lab = VEC3(L,a,b) ;
......@@ -545,21 +562,21 @@ ColourConverter<REAL>::convertLabToXYZ()
{
static REAL f(REAL x)
{
if (x > 0.206893)
return pow(x,3.0) ;
if (x > 0.206893f)
return pow(x,3.0f) ;
else
return x / 7.787 - 16.0/903.3 ;
return x / 7.787f - REAL(16.0/903.3) ;
}
} ;
if (L > 8.0)
Y = pow(((L+16.0) / 116.0),3) ;
if (L > 8.0f)
Y = pow(((L+16.0f) / 116.0f),3) ;
else // near black
Y = L / 903.3 ;
Y = L / 903.3f ;
REAL nom = (L+16.0) / 116.0 ;
X = Xn * Local::f( nom + a/500.0) ;
Z = Zn * Local::f( nom - b/200.0) ;
REAL nom = (L+16.0f) / 116.0f ;
X = Xn * Local::f( nom + a/500.0f) ;
Z = Zn * Local::f( nom - b/200.0f) ;
if (XYZ != NULL)
*XYZ = VEC3(X,Y,Z) ;
......
......@@ -263,7 +263,7 @@ QuadricNd<REAL,N>::operator() (const VECNp& v) const
for (unsigned int i = 0 ; i < N ; ++i)
hv[i] = v[i] ;
return evaluate(v) ;
return evaluate(hv) ; // v instead of hv !!!
}
template <typename REAL, unsigned int N>
......@@ -340,7 +340,7 @@ template <typename REAL>
QuadricHF<REAL>::QuadricHF(const Geom::Tensor3d* T, const REAL& gamma, const REAL& alpha):
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
const Geom::Matrix33d R = buildRotateMatrix(gamma) ;
......@@ -469,7 +469,7 @@ QuadricHF<REAL>&
QuadricHF<REAL>::operator /= (const REAL& v)
{
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 ;
......@@ -538,7 +538,7 @@ QuadricHF<REAL>::evalR3(const std::vector<VEC3>& coefs) const
for (unsigned int i = 0 ; i < coefs.size() ; ++i)
tmp[i] = coefs[i][c] ;
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
}
......@@ -1192,8 +1192,8 @@ template <typename REAL>
Geom::Tensor3d*
QuadricHF<REAL>::tensorsFromCoefs(const std::vector<VEC3>& coefs)
{
const unsigned int& N = coefs.size() ;
const unsigned int& degree = (sqrt(1+8*N) - 3) / REAL(2) ;
unsigned int N = (unsigned int)(coefs.size()) ;
unsigned int degree = (unsigned int)((sqrt(1 + 8 * N) - 3.0) / 2.0);
Geom::Tensor3d *A = new Geom::Tensor3d[3] ;
for (unsigned int col = 0 ; col < 3 ; ++col)
......
......@@ -30,11 +30,16 @@
#include "Geometry/matrix.h"
#include "Utils/cgognStream.h"
using namespace CGoGN;
namespace CGoGN
{
namespace Utils
{
enum channel {RED=0, GREEN, BLUE};
#define COLCHANNELS 3
template <typename REAL>
class QuadricRGBfunctions {
public:
......@@ -92,6 +97,9 @@ private :
};
}
}
#include "quadricRGBfunctions.hpp"
#endif /* QUADRICLF_H_ */
......@@ -25,6 +25,12 @@
#ifndef QUADRICLF_HPP_
#define QUADRICLF_HPP_
namespace CGoGN
{
namespace Utils
{
template <typename REAL>
std::string QuadricRGBfunctions<REAL>::CGoGNnameOfType() {
return std::string("QuadricColFuncs");
......@@ -447,4 +453,7 @@ void QuadricRGBfunctions<REAL>::zero () {
}
}
}
}
#endif /* QUADRICLF_HPP_ */
......@@ -25,6 +25,9 @@
#ifndef __QUANTIZATION_H__
#define __QUANTIZATION_H__
#include <vector>
#include <list>
#define epsSplitVector 0.00001f
#define epsilonDistortion 0.0001f
......@@ -35,10 +38,7 @@
namespace CGoGN
{
namespace Algo
{
namespace PMesh
namespace Utils
{
template <typename VEC>
......@@ -101,9 +101,7 @@ private:
} ;
} //namespace PMesh
} //namespace Algo
} //namespace Utils
} //namespace CGoGN
......
......@@ -22,15 +22,14 @@
* *
*******************************************************************************/
#include "Utils/cgognStream.h"
#include <limits>
namespace CGoGN
{
namespace Algo
{
namespace PMesh
namespace Utils
{
template <typename VEC>
......@@ -378,8 +377,6 @@ float Quantization<VEC>::determinant(float* matrice)
}
}
} //namespace PMesh
} //namespace Algo
} //namespace Utils
} //namespace CGoGN
......@@ -47,14 +47,10 @@ m_size(img.m_size),
m_sizeSub(img.m_sizeSub),
m_localAlloc(true)
{
if (img.m_qimg == NULL)
if (img.m_data_ptr != NULL)
{
if (img.m_data_ptr != NULL)
{
m_data_ptr = new TYPE[m_sizeSub[DIM-1]];
memcpy(m_data_ptr, img.m_data_ptr, sizeof(TYPE)*m_sizeSub[DIM-1]);
this->m_qimg = NULL;
}
m_data_ptr = new TYPE[m_sizeSub[DIM-1]];
memcpy(m_data_ptr, img.m_data_ptr, sizeof(TYPE)*m_sizeSub[DIM-1]);
}
}
......@@ -113,11 +109,6 @@ void ImageData<DIM,TYPE>::computeSub()
template < unsigned int DIM, typename TYPE >
void ImageData<DIM,TYPE>::create(TYPE* data, const COORD& size)
{
// first free old image if exist
if (this->m_qimg != NULL)
{
delete this->m_qmg;
}
else if (m_data_ptr!=NULL)
{
delete[] m_data_ptr;
......@@ -126,7 +117,6 @@ void ImageData<DIM,TYPE>::create(TYPE* data, const COORD& size)
m_size = size;
computeSub();
m_data_ptr = data;
this->m_qimg = NULL;
}
template < unsigned int DIM, typename TYPE >
......@@ -273,20 +263,6 @@ Image<DIM,TYPE>::~Image()
// this->m_data_ptr = NULL;
}
/*
template < unsigned int DIM, typename TYPE >
void Image<DIM,TYPE>::swap(Image<DIM,TYPE>& img)
{
if ((this->m_qimg != NULL) && (img.m_qimg != NULL))
{
QImage* ptr = this->m_qimg;
this->m_qimg = img.m_qimg;
img.m_qimg = ptr;
}
ImageData<DIM,TYPE>::swap(img);
}
*/
template < unsigned int DIM, typename TYPE >
bool Image<DIM,TYPE>::load(const unsigned char *ptr, unsigned int w, unsigned int h, unsigned int bpp)
......
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