Commit e44709ec authored by Sylvain Thery's avatar Sylvain Thery

update histogram & qt..

colorMap cleaning
moving qtinputs.cpp in right place (warning cmake needed)
parent 1a799638
......@@ -49,9 +49,10 @@ int main(int argc, char **argv)
// example code itself
sqt.createMap(std::string(argv[1]));
// set help message in menu
sqt.setHelpMsg("Tuto Histogram: \nLoad mesh & compute histogram & quantilles\n+/- increase/decrease \
number of classes\no/p increase/decrease number of quantilles\nw/x change \
min/max\nc center the histogram on 0\nh show/hide histogram\nq show/hide quantilles ");
sqt.setHelpMsg("Tuto Histogram: \nLoad mesh & compute histogram & quantiles\n+/- increase/decrease \
number of classes\no/p increase/decrease number of quantiles\nw/x change \
min/max\nc center the histogram on 0\nh show/hide histogram\nq show/hide quantiles\
File/Save for exporting histogram in svg format");
// final show for redraw
sqt.show();
......@@ -106,9 +107,9 @@ void MyQT::createMap(const std::string& filename)
l_nbc = 20;
l_histo->populateHisto(l_nbc);
//compute the quantilles
//compute the quantiles
l_nbq = 10;
l_histo->populateQuantilles(l_nbq);
l_histo->populateQuantiles(l_nbq);
// compute color attribute from histogram (histogram can alsdo directly update a VBO see below)
// l_histo->histoColorize(colorF);
......@@ -121,7 +122,7 @@ void MyQT::createMap(const std::string& filename)
l_histodraw = new Utils::QT::RenderHistogram(l_popup, *l_histo);
// some simple parameters
l_histodraw->setQuantillesDraw(true);
l_histodraw->setQuantilesDraw(true);
l_histodraw->setHistoPosition(true);
l_histodraw->setOpacity(0.6f);
......@@ -129,8 +130,8 @@ void MyQT::createMap(const std::string& filename)
std::vector<Geom::Vec3f> colors;
Utils::createTableColor01(colors,10,Utils::color_map_blue_green_red);
// and us it to color the quantilles
l_histodraw->setQuantillesColors(colors);
// and us it to color the quantiles
l_histodraw->setQuantilesColors(colors);
// add the widget to the popup
l_popup->addWidget(l_histodraw,0,0);
......@@ -182,17 +183,17 @@ void MyQT::cb_keyPress(int keycode)
case 'p' :
l_nbq++;
l_histo->populateQuantilles(l_nbq);
l_histo->populateQuantiles(l_nbq);
l_histodraw->repaint();
break;
case 'o' :
if (l_nbq>0)
l_nbq--;
l_histo->populateQuantilles(l_nbq);
l_histo->populateQuantiles(l_nbq);
l_histodraw->repaint();
break;
case 'q':
l_histodraw->setQuantillesDraw(!l_histodraw->getQuantillesDraw());
l_histodraw->setQuantilesDraw(!l_histodraw->getQuantilesDraw());
l_histodraw->repaint();
break;
case 'h':
......@@ -266,7 +267,7 @@ void MyQT::cb_redraw()
void MyQT::clickHisto(unsigned int i,unsigned int j)
{
std::cout << "CLICK on column Histo: "<< i << " / Quantilles: "<< j <<std::endl;
std::cout << "CLICK on column Histo: "<< i << " / Quantiles: "<< j <<std::endl;
}
......
......@@ -125,7 +125,7 @@ class Histogram
// std::vector<double> m_data;
std::vector< std::pair<double, unsigned int> > m_dataIdx;
mutable std::vector< std::pair<double, unsigned int> > m_dataIdx;
/// number of classes in attribute
unsigned int m_nbclasses;
......@@ -133,11 +133,11 @@ class Histogram
/// vector of population
std::vector<unsigned int> m_populations;
/// vector of intervals of quantilles
/// vector of intervals of quantiles
std::vector<double> m_interv;
/// vector of population for quantilles
std::vector<double> m_pop_quantilles;
/// vector of population for quantiles
std::vector<double> m_pop_quantiles;
/// min value
double m_min;
......@@ -159,7 +159,7 @@ class Histogram
HistoColorMap& m_hcolmap;
bool m_sorted;
mutable bool m_sorted;
/// get data
double data(unsigned int i) const;
......@@ -188,7 +188,7 @@ public:
/**
* init data
* @param attr the attribute to copy from
* @param sortForQuantilles sort data vector for quantille generation
* @param sortForQuantiles sort data vector for quantille generation
*/
template <typename ATTR>
void initData(const ATTR& attr);
......@@ -230,7 +230,7 @@ public:
unsigned int getMaxBar() const;
/**
* get max population value of all bars of quantilles
* get max population value of all bars of quantiles
*/
double getMaxQBar() const;
......@@ -248,7 +248,7 @@ public:
/**
* compute the histogram with given number of classes
*/
void populateQuantilles(unsigned int nbclasses=10);
void populateQuantiles(unsigned int nbclasses=10);
/**
* which class belong a value
......@@ -261,7 +261,7 @@ public:
unsigned int whichQuantille(double val) const;
/**
* fill a color attribute
* fill a color attribute from histo
* @param colors attribute to fill
*/
template <typename ATTC>
......@@ -269,7 +269,7 @@ public:
/**
* colorize the VBO (RGB)
* colorize the VBO (RGB) from histo
* @warning GL context must be accessible
* @param vbo the vbo to fill with colors
*/
......@@ -277,20 +277,20 @@ public:
/**
* fill a color attribute
* fill a color attribute from quantiles
* @param colors attribute to fill
* @param tc table of color
*/
template<typename ATTC>
void quantillesColorize(ATTC& colors, const std::vector<Geom::Vec3f>& tc);
void quantilesColorize(ATTC& colors, const std::vector<Geom::Vec3f>& tc);
/**
* fill a color attribute
* @param colors attribute to fill
* @param func colormap function (Geom::Vec3f func(float x)
* colorize the VBO (RGB) from
* @warning GL context must be accessible
* @param vbo the vbo to fill with colors
* @param tc table of color
*/
template<typename ATTC, typename COLORMAP>
void quantillesColorizeFunc(ATTC& colors, COLORMAP func);
void quantilesColorizeVBO(Utils::VBO& vbo, const std::vector<Geom::Vec3f>& tc);
/**
* get the vector of class population
......@@ -298,14 +298,31 @@ public:
const std::vector<unsigned int>& getPopulation() const;
/**
* get the vector of height of quantilles
* get the vector of height of quantiles
*/
const std::vector<double>& getQuantillesHeights() const;
const std::vector<double>& getQuantilesHeights() const;
/**
* get the vector of intervals bounaries for quantilles
* get the vector of intervals bounaries for quantiles
*/
const std::vector<double>& getQuantillesIntervals() const;
const std::vector<double>& getQuantilesIntervals() const;
/**
* return cells of histogram's column
* @param c column of histogram
* @param vc vector of cells (indices)
* @return true if not empty
*/
bool cellsOfHistogramColumn( unsigned int c, std::vector<unsigned int> vc) const;
/**
* return cells of quantile's column
* @param c column of quantile
* @param vc vector of cells (indices)
* @return true if not empty
*/
bool cellsOfQuauntilesColumn( unsigned int c, std::vector<unsigned int> vc) const;
/**
* get the colorMap
......
......@@ -46,13 +46,13 @@ inline const std::vector<unsigned int>& Histogram::getPopulation() const
return m_populations;
}
inline const std::vector<double>& Histogram::getQuantillesHeights() const
inline const std::vector<double>& Histogram::getQuantilesHeights() const
{
return m_pop_quantilles;
return m_pop_quantiles;
}
inline const std::vector<double>& Histogram::getQuantillesIntervals() const
inline const std::vector<double>& Histogram::getQuantilesIntervals() const
{
return m_interv;
}
......@@ -186,7 +186,7 @@ void Histogram::histoColorize(ATTC& colors)
template<typename ATTC>
void Histogram::quantillesColorize(ATTC& colors, const std::vector<Geom::Vec3f>& tc)
void Histogram::quantilesColorize(ATTC& colors, const std::vector<Geom::Vec3f>& tc)
{
unsigned int nb = m_dataIdx.size();
......
......@@ -62,7 +62,7 @@ class RenderHistogram : public QWidget
int m_axl_nbd;
bool m_drawHisto;
bool m_drawQuantilles;
bool m_drawQuantiles;
bool m_histoFront;
float m_opacity;
bool m_drawAxis;
......@@ -88,10 +88,10 @@ public:
virtual QSize sizeHint() const;
/**
* set color table for quantilles drawing
* set color table for quantiles drawing
* @param colors vector of colors
*/
void setQuantillesColors(const std::vector<Geom::Vec3f>& colors);
void setQuantilesColors(const std::vector<Geom::Vec3f>& colors);
/***
* svg export
......@@ -113,7 +113,7 @@ public:
/**
* define if quantille is drawn
*/
void setQuantillesDraw(bool d);
void setQuantilesDraw(bool d);
/**
* get bool value that indicate drawing of histogram
......@@ -123,7 +123,7 @@ public:
/**
* get bool value that indicate drawing of quantille
*/
bool getQuantillesDraw();
bool getQuantilesDraw();
/**
* get opacity value
......@@ -143,6 +143,8 @@ public:
signals:
/**
* emitted signal when a column of histogram is clicked
* @param i column of histo (0xffffffff if none)
* @param j column of quantileq (0xffffffff if none)
*/
void clicked(unsigned int, unsigned int);
......@@ -154,7 +156,7 @@ protected:
void drawHisto(QPainter& painter);
/// draw the quatilles in painter widget
void drawQuantilles(QPainter& painter);
void drawQuantiles(QPainter& painter);
/// functinn calles when widget need to be redraw
void paintEvent(QPaintEvent *event);
......
......@@ -31,149 +31,89 @@ namespace CGoGN
namespace Utils
{
inline Geom::Vec3f color_map_blue_green_red(float x)
{
Geom::Vec3f r(0.0f) ;
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[1] = 2.0f * x;
r[2] = 1.0f - 2.0f * x;
}
else if (x < 1.0f)
{
r[0] = 2.0f * x - 1.0f;
r[1] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_BCGYR(float x)
{
Geom::Vec3f r(0.0f) ;
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.25f)
{
r[0] = 0.0f;
r[1] = 4.0f * x;
r[2] = 1.0f;
}
else if (x < 0.5f)
{
r[0] = 0.0f;
r[1] = 1.0f;
r[2] = 2.0f - 4.0f * x;
}
else if (x < 0.75f)
{
r[0] = 4.0f * x - 2.0f;
r[1] = 1.0f;
r[2] = 0.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 4.0f - 4.0f * x;
r[2] = 0.0f;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_blue_white_red(float x)
{
Geom::Vec3f r(0.0f);
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[0] = 2.0f * x;
r[1] = 2.0f * x;
r[2] = 1.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 2.0f - 2.0f * x;
r[2] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline Geom::Vec3f color_map_cyan_white_red(float x)
{
Geom::Vec3f r(0.0f);
if (x < 0.0f)
r[2] = 1.0f;
else if (x < 0.5f)
{
r[0] = 2.0f * x;
r[1] = 1.0f;
r[2] = 1.0f;
}
else if (x < 1.0f)
{
r[0] = 1.0f;
r[1] = 2.0f - 2.0f * x;
r[2] = 2.0f - 2.0f * x;
}
else
r[0] = 1.0f;
return r;
}
inline float scale_expand_within_0_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = (1.0f - cos(M_PI * x)) / 2.0f;
for (int i = -1; i >= n; i--)
x = acos(1.0f - 2.0f * x) / M_PI;
return x;
}
inline float scale_expand_towards_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = sin(x * M_PI / 2.0f);
for (int i = -1; i >= n; i--)
x = asin(x) * 2.0f / M_PI;
return x;
}
inline float scale_to_0_1(float x, float min, float max)
{
return (x - min) / (max - min);
}
inline float scale_and_clamp_to_0_1(float x, float min, float max)
{
float v = (x - min) / (max - min);
return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
}
inline void scale_centering_around_0(float& min, float& max)
{
float new_max = std::max(max, -min);
min = std::min(min, -max);
max = new_max;
}
inline float scale_to_0_1_around_one_half(float x, float min, float max)
{
float ma = std::max(max, -min);
float mi = std::min(min, -max);
return (x - mi) / (ma - mi);
}
/**
*
* @param x
*/
Geom::Vec3f color_map_blue_green_red(float x);
/**
*
* @param x
*/
Geom::Vec3f color_map_BCGYR(float x);
/**
*
* @param x
*/
Geom::Vec3f color_map_blue_white_red(float x);
/**
*
* @param x
*/
Geom::Vec3f color_map_cyan_white_red(float x);
/**
* Create a table of color using function (param between 0 & 1
* @param table table of color to fill
* @param nb size of table
* @param f the function (color_map_xxxx)
*/
template <typename FUNC>
void createTableColor01(std::vector<Geom::Vec3f>& table, unsigned int nb, FUNC f);
/**
*
* @param x
* @param n
*/
float scale_expand_within_0_1(float x, int n);
/**
*
* @param x
* @param n
*/
float scale_expand_towards_1(float x, int n);
/**
*
* @param min
* @param max
*/
float scale_to_0_1(float x, float min, float max);
/**
*
* @param x
* @param min
* @param max
*/
float scale_and_clamp_to_0_1(float x, float min, float max);
/**
*
* @param min
* @param max
*/
void scale_centering_around_0(float& min, float& max);
/**
*
* @param x
* @param min
* @param max
*/
float scale_to_0_1_around_one_half(float x, float min, float max);
} // namespace Utils
} // namespace CGoGN
#endif
#include "Utils/colorMaps.hpp"
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Utils
{
template <typename FUNC>
inline void createTableColor01(std::vector<Geom::Vec3f>& table, unsigned int nb, FUNC f)
{
table.reserve(nb);
for (unsigned int i=0; i< nb; ++i)
{
float p = float(i)/float(nb);
table.push_back(f(p));
}
}
inline Geom::Vec3f color_map_blue_green_red(float x)
{
if (x < 0.0f)
return Geom::Vec3f(0.0f, 0.0f, 1.0f) ;
if (x < 0.5f)
return Geom::Vec3f(0.0f, 2.0f * x, 1.0f - 2.0f * x);
if (x < 1.0f)
return Geom::Vec3f(2.0f * x - 1.0f, 2.0f - 2.0f * x, 0.0f);
return Geom::Vec3f(1.0f, 0.0f, 0.0f) ;
}
inline Geom::Vec3f color_map_BCGYR(float x)
{
if (x < 0.0f)
return Geom::Vec3f(0.0f, 0.0f, 1.0f) ;
if (x < 0.25f)
return Geom::Vec3f(0.0f, 4.0f * x, 1.0f);
if (x < 0.5f)
return Geom::Vec3f(0.0f, 1.0 , 2.0f - 4.0f * x);
if (x < 0.75f)
return Geom::Vec3f(4.0f * x - 2.0f, 1.0f, 0.0f);
if (x < 1.0f)
return Geom::Vec3f(1.0f, 4.0f - 4.0f * x, 0.0f);
return Geom::Vec3f(1.0f, 0.0f, 0.0f) ;
}
inline Geom::Vec3f color_map_blue_white_red(float x)
{
if (x < 0.0f)
return Geom::Vec3f(0.0f, 0.0f, 1.0f) ;
if (x < 0.5f)
return Geom::Vec3f(2.0f * x, 2.0f * x, 1.0f);
if (x < 1.0f)
return Geom::Vec3f(1.0f, 2.0f - 2.0f * x, 2.0f - 2.0f * x);
return Geom::Vec3f(1.0f, 0.0f, 0.0f) ;
}
inline Geom::Vec3f color_map_cyan_white_red(float x)
{
if (x < 0.0f)
return Geom::Vec3f(0.0f, 0.0f, 1.0f) ;
if (x < 0.5f)
return Geom::Vec3f(2.0f * x, 1.0f , 1.0f);
if (x < 1.0f)
return Geom::Vec3f(1.0f, 2.0f - 2.0f * x, 2.0f - 2.0f * x);
return Geom::Vec3f(1.0f, 0.0f, 0.0f) ;
}
inline float scale_expand_within_0_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = (1.0f - cos(M_PI * x)) / 2.0f;
for (int i = -1; i >= n; i--)
x = acos(1.0f - 2.0f * x) / M_PI;
return x;
}
inline float scale_expand_towards_1(float x, int n)
{
for (int i = 1; i <= n; i++)
x = sin(x * M_PI / 2.0f);
for (int i = -1; i >= n; i--)
x = asin(x) * 2.0f / M_PI;
return x;
}
inline float scale_to_0_1(float x, float min, float max)
{
return (x - min) / (max - min);
}
inline float scale_and_clamp_to_0_1(float x, float min, float max)
{
float v = (x - min) / (max - min);
return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
}
inline void scale_centering_around_0(float& min, float& max)
{
float new_max = std::max(max, -min);
min = std::min(min, -max);
max = new_max;
}
inline float scale_to_0_1_around_one_half(float x, float min, float max)
{
float ma = std::max(max, -min);
float mi = std::min(min, -max);
return (x - mi) / (ma - mi);
}
} // namespace Utils
} // namespace CGoGN
......@@ -89,7 +89,7 @@ void Histogram::populateHisto(unsigned int nbclasses)
}
}
void Histogram::populateQuantilles(unsigned int nbquantilles)
void Histogram::populateQuantiles(unsigned int nbquantiles)
{
if (!m_sorted)
{
......@@ -99,20 +99,20 @@ void Histogram::populateQuantilles(unsigned int nbquantilles)
// compute exact populations
unsigned int nb = m_dataIdx.size();
double pop = double(nb)/nbquantilles;
m_pop_quantilles.resize(nbquantilles);
double pop = double(nb)/nbquantiles;
m_pop_quantiles.resize(nbquantiles);
for (unsigned int i = 0; i < nbquantilles; ++i)
m_pop_quantilles[i]=pop;
for (unsigned int i = 0; i < nbquantiles; ++i)
m_pop_quantiles[i]=pop;
m_interv.clear();
m_interv.reserve(nbquantilles+1);
// quantilles computation
m_interv.reserve(nbquantiles+1);
// quantiles computation
m_interv.push_back(m_dataIdx.front().first);
double cumul = 0.0;
for (unsigned int i = 0; i < nbquantilles; ++i)
for (unsigned int i = 0; i < nbquantiles; ++i)
{
cumul += m_pop_quantilles[i];
cumul += m_pop_quantiles[i];
unsigned int icum = floor(cumul);
double val = 0.0;
if (icum < m_dataIdx.size()-1)
......@@ -130,12 +130,12 @@ void Histogram::populateQuantilles(unsigned int nbquantilles)
if (m_nbclasses != 0) //for histo superposition
lc = double(m_dataIdx.back().first - m_dataIdx.front().first )/double(m_nbclasses);
for (unsigned int i = 0; i < nbquantilles; ++i)
for (unsigned int i = 0; i < nbquantiles; ++i)
{
double lq = m_interv[i+1] - m_interv[i];
m_pop_quantilles[i] = m_pop_quantilles[i]*lc/lq;
if (m_pop_quantilles[i] > m_maxQBar)
m_maxQBar = m_pop_quantilles[i];
m_pop_quantiles[i] = m_pop_quantiles[i]*lc/lq;
if (m_pop_quantiles[i] > m_maxQBar)
m_maxQBar = m_pop_quantiles[i];
}
}
......@@ -155,6 +155,57 @@ void Histogram::histoColorizeVBO(Utils::VBO& vbo)