Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hurstel
CGoGN
Commits
1a799638
Commit
1a799638
authored
Jun 12, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tuto for histogram computing & drawing
parent
86ebbbe2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
448 additions
and
1 deletion
+448
-1
Apps/Tuto/CMakeLists.txt
Apps/Tuto/CMakeLists.txt
+7
-1
Apps/Tuto/tuto_histo.cpp
Apps/Tuto/tuto_histo.cpp
+299
-0
Apps/Tuto/tuto_histo.h
Apps/Tuto/tuto_histo.h
+142
-0
No files found.
Apps/Tuto/CMakeLists.txt
View file @
1a799638
...
...
@@ -34,7 +34,7 @@ QT4_WRAP_UI( tuto2_ui tuto2.ui )
QT4_WRAP_CPP
(
tuto2_moc tuto2.h
)
add_executable
(
tuto2 tuto2.cpp tuto2.h
${
tuto2_ui
}
${
tuto2_moc
}
)
target_link_libraries
(
tuto2
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
QtSvg
)
QT4_WRAP_CPP
(
tuto3_moc tuto3.h
)
add_executable
(
tuto3 tuto3.cpp
${
tuto3_moc
}
)
...
...
@@ -86,6 +86,12 @@ add_executable( tp_master tp_master.cpp ${tp_master_moc})
target_link_libraries
(
tp_master
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
QT4_WRAP_CPP
(
tuto_histo_moc tuto_histo.h
)
add_executable
(
tuto_histo tuto_histo.cpp tuto_histo.h
${
tuto_histo_ui
}
${
tuto_histo_moc
}
)
target_link_libraries
(
tuto_histo
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
QtSvg
)
#BOOST_LIBS macro: allow using compiled boost in windows (see readme)
# -first argument variable that will contain the libs
# -second argument list of boost libs separated by ; in " "
...
...
Apps/Tuto/tuto_histo.cpp
0 → 100644
View file @
1a799638
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, 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 *
* *
*******************************************************************************/
#include "tuto_histo.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/area.h"
#include "Topology/generic/traversorCell.h"
#include <cmath>
#include <sstream>
using
namespace
CGoGN
;
int
main
(
int
argc
,
char
**
argv
)
{
// // interface
QApplication
app
(
argc
,
argv
);
MyQT
sqt
;
// copy output tout Qt console of application (shift enter)
CGoGNout
.
toConsole
(
&
sqt
);
// 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 "
);
// final show for redraw
sqt
.
show
();
// and wait for the end
return
app
.
exec
();
}
void
MyQT
::
createMap
(
const
std
::
string
&
filename
)
{
myMap
.
clear
(
true
)
;
size_t
pos
=
filename
.
rfind
(
"."
);
// position of "." in filename
std
::
string
extension
=
filename
.
substr
(
pos
);
std
::
vector
<
std
::
string
>
attrNames
;
if
(
!
Algo
::
Import
::
importMesh
<
PFP
>
(
myMap
,
filename
.
c_str
(),
attrNames
))
{
CGoGNerr
<<
"could not import "
<<
filename
<<
CGoGNendl
;
return
;
}
VertexAttribute
<
VEC3
>
position
=
myMap
.
getAttribute
<
PFP
::
VEC3
,
VERTEX
>
(
attrNames
[
0
])
;
// attribute on which we make the histogram
VertexAttribute
<
float
>
area
=
myMap
.
addAttribute
<
float
,
VERTEX
>
(
"area"
);
// attribute color to generate from histo
VertexAttribute
<
VEC3
>
colorF
=
myMap
.
addAttribute
<
PFP
::
VEC3
,
VERTEX
>
(
"colorF"
);
// compute the area attribute
Algo
::
Geometry
::
computeOneRingAreaVertices
<
PFP
>
(
myMap
,
position
,
area
);
// just some tricks to obtain relatives value
float
amax
=
0
;
for
(
unsigned
int
i
=
area
.
begin
();
i
!=
area
.
end
();
area
.
next
(
i
))
if
(
area
[
i
]
>
amax
)
amax
=
area
[
i
];
for
(
unsigned
int
i
=
area
.
begin
();
i
!=
area
.
end
();
area
.
next
(
i
))
area
[
i
]
-=
amax
/
4
;
// create a colormap class for histogram coloring
l_cm
=
new
ColMap
();
// create the histogram
l_histo
=
new
Algo
::
Histogram
::
Histogram
(
*
l_cm
);
// init data with specific conversion (direction init is: l_histo->initData(area);)
AttConv
ac
(
area
);
l_histo
->
initDataConvert
(
ac
);
// compute the histogram
l_nbc
=
20
;
l_histo
->
populateHisto
(
l_nbc
);
//compute the quantilles
l_nbq
=
10
;
l_histo
->
populateQuantilles
(
l_nbq
);
// compute color attribute from histogram (histogram can alsdo directly update a VBO see below)
// l_histo->histoColorize(colorF);
// create a popup window
l_popup
=
new
Utils
::
QT
::
QtPopUp
(
this
);
// create the widget to view histogram
l_histodraw
=
new
Utils
::
QT
::
RenderHistogram
(
l_popup
,
*
l_histo
);
// some simple parameters
l_histodraw
->
setQuantillesDraw
(
true
);
l_histodraw
->
setHistoPosition
(
true
);
l_histodraw
->
setOpacity
(
0.6
f
);
// create a table of color
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
);
// add the widget to the popup
l_popup
->
addWidget
(
l_histodraw
,
0
,
0
);
l_popup
->
show
();
// connect the clicked signal of histogram widget to a slot
QObject
::
connect
(
l_histodraw
,
SIGNAL
(
clicked
(
unsigned
int
,
unsigned
int
)
),
this
,
SLOT
(
clickHisto
(
unsigned
int
,
unsigned
int
)
)
);
// bounding box of scene
Geom
::
BoundingBox
<
PFP
::
VEC3
>
bb
=
Algo
::
Geometry
::
computeBoundingBox
<
PFP
>
(
myMap
,
position
);
float
lWidthObj
=
std
::
max
<
PFP
::
REAL
>
(
std
::
max
<
PFP
::
REAL
>
(
bb
.
size
(
0
),
bb
.
size
(
1
)),
bb
.
size
(
2
));
Geom
::
Vec3f
lPosObj
=
(
bb
.
min
()
+
bb
.
max
())
/
PFP
::
REAL
(
2
);
// send BB info to interface for centering on GL screen
setParamObject
(
lWidthObj
,
lPosObj
.
data
());
// first show for be sure that GL context is binded
show
();
// update of position VBO (context GL necessary)
m_positionVBO
->
updateData
(
position
);
// m_colorVBO2->updateData(colorF);
// histogram can directly update a VBO (warning GL context must be accessible, after the first show!)
l_histo
->
histoColorizeVBO
(
*
m_colorVBO2
);
// construct rendering primities
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL2
::
TRIANGLES
);
}
void
MyQT
::
cb_keyPress
(
int
keycode
)
{
switch
(
keycode
)
{
case
'+'
:
l_nbc
++
;
l_histo
->
populateHisto
(
l_nbc
);
l_histodraw
->
repaint
();
break
;
case
'-'
:
if
(
l_nbc
>
0
)
l_nbc
--
;
l_histo
->
populateHisto
(
l_nbc
);
l_histodraw
->
repaint
();
break
;
case
'p'
:
l_nbq
++
;
l_histo
->
populateQuantilles
(
l_nbq
);
l_histodraw
->
repaint
();
break
;
case
'o'
:
if
(
l_nbq
>
0
)
l_nbq
--
;
l_histo
->
populateQuantilles
(
l_nbq
);
l_histodraw
->
repaint
();
break
;
case
'q'
:
l_histodraw
->
setQuantillesDraw
(
!
l_histodraw
->
getQuantillesDraw
());
l_histodraw
->
repaint
();
break
;
case
'h'
:
l_histodraw
->
setHistoDraw
(
!
l_histodraw
->
getHistoDraw
());
l_histodraw
->
repaint
();
break
;
case
'c'
:
l_histo
->
centerOnZero
();
l_histo
->
populateHisto
(
l_nbc
);
l_histodraw
->
repaint
();
break
;
case
'w'
:
{
double
av
=
(
l_histo
->
getMin
()
+
l_histo
->
getMax
()
)
/
2.0
;
l_histo
->
setMin
(
av
*
0.1
+
l_histo
->
getMin
()
*
0.9
);
l_histo
->
setMax
(
av
*
0.1
+
l_histo
->
getMax
()
*
0.9
);
l_histo
->
populateHisto
(
l_nbc
);
l_histodraw
->
repaint
();
}
break
;
case
'x'
:
{
double
av
=
(
l_histo
->
getMin
()
+
l_histo
->
getMax
()
)
/
2.0
;
l_histo
->
setMin
(
-
0.1
*
av
+
l_histo
->
getMin
()
*
1.1
);
l_histo
->
setMax
(
-
0.1
*
av
+
l_histo
->
getMax
()
*
1.1
);
l_histo
->
populateHisto
(
l_nbc
);
l_histodraw
->
repaint
();
}
break
;
default:
break
;
}
}
void
MyQT
::
cb_initGL
()
{
// choose to use GL version 2
Utils
::
GLSLShader
::
setCurrentOGLVersion
(
2
);
// create the render
m_render
=
new
Algo
::
Render
::
GL2
::
MapRender
();
// VBOs
m_positionVBO
=
new
Utils
::
VBO
();
m_colorVBO2
=
new
Utils
::
VBO
();
//shader
m_shader2
=
new
Utils
::
ShaderColorPerVertex
();
m_shader2
->
setAttributePosition
(
m_positionVBO
);
registerShader
(
m_shader2
);
}
void
MyQT
::
cb_redraw
()
{
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
// draw faces with pervertex color rendering
m_shader2
->
setAttributeColor
(
m_colorVBO2
);
m_render
->
draw
(
m_shader2
,
Algo
::
Render
::
GL2
::
TRIANGLES
);
glDisable
(
GL_POLYGON_OFFSET_FILL
);
}
void
MyQT
::
clickHisto
(
unsigned
int
i
,
unsigned
int
j
)
{
std
::
cout
<<
"CLICK on column Histo: "
<<
i
<<
" / Quantilles: "
<<
j
<<
std
::
endl
;
}
void
MyQT
::
cb_Save
()
{
std
::
string
filename
=
selectFileSave
(
"export svg"
,
"."
,
"*.svg"
)
;
if
(
filename
.
empty
())
return
;
l_histodraw
->
svgExport
(
filename
);
}
void
MyQT
::
cb_exit
()
{
if
(
m_render
!=
NULL
)
delete
m_render
;
if
(
m_shader2
!=
NULL
)
delete
m_shader2
;
if
(
m_positionVBO
!=
NULL
)
delete
m_positionVBO
;
if
(
l_cm
!=
NULL
)
delete
l_cm
;
if
(
l_histo
!=
NULL
)
delete
l_histo
;
if
(
l_histodraw
!=
NULL
)
delete
l_histodraw
;
if
(
l_popup
!=
NULL
)
delete
l_popup
;
}
Apps/Tuto/tuto_histo.h
0 → 100644
View file @
1a799638
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, 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 *
* *
*******************************************************************************/
#ifndef _TUTO2_
#define _TUTO2_
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Algo/Histogram/histogram.h"
#include "Utils/Qt/qthistodraw.h"
using
namespace
CGoGN
;
struct
PFP
:
public
PFP_STANDARD
{
typedef
EmbeddedMap2
MAP
;
};
typedef
PFP
::
MAP
MAP
;
typedef
PFP
::
VEC3
VEC3
;
/*
* color map class for histogram color
*/
class
ColMap
:
public
Algo
::
Histogram
::
HistoColorMap
{
public:
Geom
::
Vec3f
color
(
double
f
)
const
{
return
Utils
::
color_map_BCGYR
(
float
(
f
));}
};
/*
* Attribute conversion to double
*/
//class AttConv: public Algo::Histogram::AttributeConvert
//{
//// VertexAttribute<float>& m_va;
//public:
// /// constructor with attribute reference
// AttConv(VertexAttribute<float>& va): m_va(va){}
//
// /// just call begin of attribute handler
// unsigned int begin() const { return m_va.begin();}
//
// /// just call end of attribute handler
// unsigned int end() const { return m_va.end();}
//
// /// just call next of attribute handler
// void next(unsigned int& i) const { m_va.next(i);}
// unsigned int nbElements() const { return m_va.nbElements();}
// double operator[](unsigned int i) const { return double(m_va[i])*0.33;}
//};
class
AttConv
:
public
Algo
::
Histogram
::
AttributeConvert
<
VertexAttribute
<
float
>
>
{
public:
/// constructor with attribute reference
AttConv
(
VertexAttribute
<
float
>&
va
)
:
Algo
::
Histogram
::
AttributeConvert
<
VertexAttribute
<
float
>
>
(
va
){}
double
operator
[](
unsigned
int
i
)
const
{
return
double
(
attrib
[
i
])
*
0.33
;}
};
class
MyQT
:
public
Utils
::
QT
::
SimpleQT
{
Q_OBJECT
public:
MyQT
()
:
m_render
(
NULL
),
m_positionVBO
(
NULL
),
m_shader2
(
NULL
),
l_cm
(
NULL
),
l_histo
(
NULL
),
l_popup
(
NULL
),
l_histodraw
(
NULL
)
{}
void
cb_redraw
();
void
cb_initGL
();
protected:
MAP
myMap
;
// render, VBO & shader
Algo
::
Render
::
GL2
::
MapRender
*
m_render
;
Utils
::
VBO
*
m_positionVBO
;
// position 3D
Utils
::
VBO
*
m_colorVBO2
;
// color per vertex for edge drawing
Utils
::
ShaderColorPerVertex
*
m_shader2
;
// some ptr
ColMap
*
l_cm
;
Algo
::
Histogram
::
Histogram
*
l_histo
;
Utils
::
QT
::
QtPopUp
*
l_popup
;
Utils
::
QT
::
RenderHistogram
*
l_histodraw
;
unsigned
int
l_nbc
;
unsigned
int
l_nbq
;
public:
// example of simple map creation
void
createMap
(
const
std
::
string
&
filename
);
void
cb_Save
();
void
cb_exit
();
void
cb_keyPress
(
int
keycode
);
public
slots
:
void
clickHisto
(
unsigned
int
i
,
unsigned
int
j
);
};
#endif
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