Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sauvage
CGoGN
Commits
e44709ec
Commit
e44709ec
authored
Jun 12, 2012
by
Sylvain Thery
Browse files
update histogram & qt..
colorMap cleaning moving qtinputs.cpp in right place (warning cmake needed)
parent
1a799638
Changes
9
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/tuto_histo.cpp
View file @
e44709ec
...
...
@@ -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:
\n
Load mesh & compute histogram & quantilles
\n
+/- increase/decrease \
number of classes
\n
o/p increase/decrease number of quantilles
\n
w/x change \
min/max
\n
c center the histogram on 0
\n
h show/hide histogram
\n
q show/hide quantilles "
);
sqt
.
setHelpMsg
(
"Tuto Histogram:
\n
Load mesh & compute histogram & quantiles
\n
+/- increase/decrease \
number of classes
\n
o/p increase/decrease number of quantiles
\n
w/x change \
min/max
\n
c center the histogram on 0
\n
h show/hide histogram
\n
q 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 quantil
l
es
//compute the quantiles
l_nbq
=
10
;
l_histo
->
populateQuantil
l
es
(
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
->
setQuantil
l
esDraw
(
true
);
l_histodraw
->
setQuantilesDraw
(
true
);
l_histodraw
->
setHistoPosition
(
true
);
l_histodraw
->
setOpacity
(
0.6
f
);
...
...
@@ -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 quantil
l
es
l_histodraw
->
setQuantil
l
esColors
(
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
->
populateQuantil
l
es
(
l_nbq
);
l_histo
->
populateQuantiles
(
l_nbq
);
l_histodraw
->
repaint
();
break
;
case
'o'
:
if
(
l_nbq
>
0
)
l_nbq
--
;
l_histo
->
populateQuantil
l
es
(
l_nbq
);
l_histo
->
populateQuantiles
(
l_nbq
);
l_histodraw
->
repaint
();
break
;
case
'q'
:
l_histodraw
->
setQuantil
l
esDraw
(
!
l_histodraw
->
getQuantil
l
esDraw
());
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
<<
" / Quantil
l
es: "
<<
j
<<
std
::
endl
;
std
::
cout
<<
"CLICK on column Histo: "
<<
i
<<
" / Quantiles: "
<<
j
<<
std
::
endl
;
}
...
...
include/Algo/Histogram/histogram.h
View file @
e44709ec
...
...
@@ -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 quantil
l
es
/// vector of intervals of quantiles
std
::
vector
<
double
>
m_interv
;
/// vector of population for quantil
l
es
std
::
vector
<
double
>
m_pop_quantil
l
es
;
/// 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 sortForQuantil
l
es 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 quantil
l
es
* 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
populateQuantil
l
es
(
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
quantil
l
esColorize
(
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 quantil
l
es
* get the vector of height of quantiles
*/
const
std
::
vector
<
double
>&
getQuantil
l
esHeights
()
const
;
const
std
::
vector
<
double
>&
getQuantilesHeights
()
const
;
/**
* get the vector of intervals bounaries for quantil
l
es
* 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
...
...
include/Algo/Histogram/histogram.hpp
View file @
e44709ec
...
...
@@ -46,13 +46,13 @@ inline const std::vector<unsigned int>& Histogram::getPopulation() const
return
m_populations
;
}
inline
const
std
::
vector
<
double
>&
Histogram
::
getQuantil
l
esHeights
()
const
inline
const
std
::
vector
<
double
>&
Histogram
::
getQuantilesHeights
()
const
{
return
m_pop_quantil
l
es
;
return
m_pop_quantiles
;
}
inline
const
std
::
vector
<
double
>&
Histogram
::
getQuantil
l
esIntervals
()
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
::
quantil
l
esColorize
(
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
();
...
...
include/Utils/Qt/qthistodraw.h
View file @
e44709ec
...
...
@@ -62,7 +62,7 @@ class RenderHistogram : public QWidget
int
m_axl_nbd
;
bool
m_drawHisto
;
bool
m_drawQuantil
l
es
;
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 quantil
l
es drawing
* set color table for quantiles drawing
* @param colors vector of colors
*/
void
setQuantil
l
esColors
(
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
setQuantil
l
esDraw
(
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
getQuantil
l
esDraw
();
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
drawQuantil
l
es
(
QPainter
&
painter
);
void
drawQuantiles
(
QPainter
&
painter
);
/// functinn calles when widget need to be redraw
void
paintEvent
(
QPaintEvent
*
event
);
...
...
include/Utils/colorMaps.h
View file @
e44709ec
...
...
@@ -31,149 +31,89 @@ namespace CGoGN
namespace
Utils
{
inline
Geom
::
Vec3f
color_map_blue_green_red
(
float
x
)
{
Geom
::
Vec3f
r
(
0.0
f
)
;
if
(
x
<
0.0
f
)
r
[
2
]
=
1.0
f
;
else
if
(
x
<
0.5
f
)
{
r
[
1
]
=
2.0
f
*
x
;
r
[
2
]
=
1.0
f
-
2.0
f
*
x
;
}
else
if
(
x
<
1.0
f
)
{
r
[
0
]
=
2.0
f
*
x
-
1.0
f
;
r
[
1
]
=
2.0
f
-
2.0
f
*
x
;
}
else
r
[
0
]
=
1.0
f
;
return
r
;
}
inline
Geom
::
Vec3f
color_map_BCGYR
(
float
x
)
{
Geom
::
Vec3f
r
(
0.0
f
)
;
if
(
x
<
0.0
f
)
r
[
2
]
=
1.0
f
;
else
if
(
x
<
0.25
f
)
{
r
[
0
]
=
0.0
f
;
r
[
1
]
=
4.0
f
*
x
;
r
[
2
]
=
1.0
f
;
}
else
if
(
x
<
0.5
f
)
{
r
[
0
]
=
0.0
f
;
r
[
1
]
=
1.0
f
;
r
[
2
]
=
2.0
f
-
4.0
f
*
x
;
}
else
if
(
x
<
0.75
f
)
{
r
[
0
]
=
4.0
f
*
x
-
2.0
f
;
r
[
1
]
=
1.0
f
;
r
[
2
]
=
0.0
f
;
}
else
if
(
x
<
1.0
f
)
{
r
[
0
]
=
1.0
f
;
r
[
1
]
=
4.0
f
-
4.0
f
*
x
;
r
[
2
]
=
0.0
f
;
}
else
r
[
0
]
=
1.0
f
;
return
r
;
}
inline
Geom
::
Vec3f
color_map_blue_white_red
(
float
x
)
{
Geom
::
Vec3f
r
(
0.0
f
);
if
(
x
<
0.0
f
)
r
[
2
]
=
1.0
f
;
else
if
(
x
<
0.5
f
)
{
r
[
0
]
=
2.0
f
*
x
;
r
[
1
]
=
2.0
f
*
x
;
r
[
2
]
=
1.0
f
;
}
else
if
(
x
<
1.0
f
)
{
r
[
0
]
=
1.0
f
;
r
[
1
]
=
2.0
f
-
2.0
f
*
x
;
r
[
2
]
=
2.0
f
-
2.0
f
*
x
;
}
else
r
[
0
]
=
1.0
f
;
return
r
;
}
inline
Geom
::
Vec3f
color_map_cyan_white_red
(
float
x
)
{
Geom
::
Vec3f
r
(
0.0
f
);
if
(
x
<
0.0
f
)
r
[
2
]
=
1.0
f
;
else
if
(
x
<
0.5
f
)
{
r
[
0
]
=
2.0
f
*
x
;
r
[
1
]
=
1.0
f
;
r
[
2
]
=
1.0
f
;
}
else
if
(
x
<
1.0
f
)
{
r
[
0
]
=
1.0
f
;
r
[
1
]
=
2.0
f
-
2.0
f
*
x
;
r
[
2
]
=
2.0
f
-
2.0
f
*
x
;
}
else
r
[
0
]
=
1.0
f
;
return
r
;
}
inline
float
scale_expand_within_0_1
(
float
x
,
int
n
)
{
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
x
=
(
1.0
f
-
cos
(
M_PI
*
x
))
/
2.0
f
;
for
(
int
i
=
-
1
;
i
>=
n
;
i
--
)
x
=
acos
(
1.0
f
-
2.0
f
*
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.0
f
);
for
(
int
i
=
-
1
;
i
>=
n
;
i
--
)
x
=
asin
(
x
)
*
2.0
f
/
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.0
f
?
0.0
f
:
(
v
>
1.0
f
?
1.0
f
:
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"
include/Utils/colorMaps.hpp
0 → 100644
View file @
e44709ec
/*******************************************************************************
* 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.0
f
)
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
1.0
f
)
;
if
(
x
<
0.5
f
)
return
Geom
::
Vec3f
(
0.0
f
,
2.0
f
*
x
,
1.0
f
-
2.0
f
*
x
);
if
(
x
<
1.0
f
)
return
Geom
::
Vec3f
(
2.0
f
*
x
-
1.0
f
,
2.0
f
-
2.0
f
*
x
,
0.0
f
);
return
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
0.0
f
)
;
}
inline
Geom
::
Vec3f
color_map_BCGYR
(
float
x
)
{
if
(
x
<
0.0
f
)
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
1.0
f
)
;
if
(
x
<
0.25
f
)
return
Geom
::
Vec3f
(
0.0
f
,
4.0
f
*
x
,
1.0
f
);
if
(
x
<
0.5
f
)
return
Geom
::
Vec3f
(
0.0
f
,
1.0
,
2.0
f
-
4.0
f
*
x
);
if
(
x
<
0.75
f
)
return
Geom
::
Vec3f
(
4.0
f
*
x
-
2.0
f
,
1.0
f
,
0.0
f
);
if
(
x
<
1.0
f
)
return
Geom
::
Vec3f
(
1.0
f
,
4.0
f
-
4.0
f
*
x
,
0.0
f
);
return
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
0.0
f
)
;
}
inline
Geom
::
Vec3f
color_map_blue_white_red
(
float
x
)
{
if
(
x
<
0.0
f
)
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
1.0
f
)
;
if
(
x
<
0.5
f
)
return
Geom
::
Vec3f
(
2.0
f
*
x
,
2.0
f
*
x
,
1.0
f
);
if
(
x
<
1.0
f
)
return
Geom
::
Vec3f
(
1.0
f
,
2.0
f
-
2.0
f
*
x
,
2.0
f
-
2.0
f
*
x
);
return
Geom
::
Vec3f
(
1.0
f
,
0.0
f
,
0.0
f
)
;
}
inline
Geom
::
Vec3f
color_map_cyan_white_red
(
float
x
)
{
if
(
x
<
0.0
f
)
return
Geom
::
Vec3f
(
0.0
f
,
0.0
f
,
1.0
f
)
;
if
(
x
<
0.5
f
)
return
Geom
::
Vec3f
(
2.0
f
*
x
,
1.0
f
,
1.0
f
);