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
Thomas Pitiot
CGoGN
Commits
53c1e31e
Commit
53c1e31e
authored
Feb 28, 2011
by
Sylvain Thery
Browse files
Bug picking with color
parent
4cd0c557
Changes
4
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/tuto5.cpp
View file @
53c1e31e
...
...
@@ -108,9 +108,26 @@ void myGlutWin::myRedraw(void)
glTranslatef
(
-
gPosObj
[
0
],
-
gPosObj
[
1
],
-
gPosObj
[
2
]);
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glDisable
(
GL_LIGHTING
);
glLineWidth
(
3.0
);
glBegin
(
GL_LINES
);
glColor3f
(
1.
,
0.
,
0.
);
glVertex3f
(
0.0
,
0.0
,
0.0
);
glVertex3f
(
1.0
,
0.0
,
0.0
);
glColor3f
(
0.
,
1.
,
0.
);
glVertex3f
(
0.0
,
0.0
,
0.0
);
glVertex3f
(
0.0
,
1.0
,
0.0
);
glColor3f
(
0.
,
0.
,
1.
);
glVertex3f
(
0.0
,
0.0
,
0.0
);
glVertex3f
(
0.0
,
0.0
,
1.0
);
glEnd
();
glColor3f
(
0.0
f
,
1.0
f
,
.0
f
);
m_render
->
draw
(
Algo
::
Render
::
VBO
::
POINTS
);
...
...
@@ -187,6 +204,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
}
break
;
case
'x'
:
{
// push/pop color is only needed for dart coloring conservation
...
...
@@ -203,22 +221,23 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
glTranslatef
(
-
gPosObj
[
0
],
-
gPosObj
[
1
],
-
gPosObj
[
2
]);
//pick
Dart
d
=
m_render_topo
->
picking
(
x
,
H
-
y
);
glPopMatrix
();
m_render_topo
->
popColors
();
if
(
d
!=
Dart
::
nil
())
if
(
d
!=
Dart
::
nil
())
{
m_render_topo
->
setDartColor
(
d
,
1.0
,
0.0
,
0.0
);
redraw
();
std
::
stringstream
ss
;
ss
<<
"Pick dart:"
<<
d
<<
std
::
endl
<<
"pos="
<<
position
[
d
];
glColor3f
(
1.
,
1.
,
0.
);
printString2D
(
x
+
12
,
y
+
22
,
ss
.
str
());
glutSwapBuffers
();
// std::cout << "Pick dart:" << d << " position= "<< position[d] << std::endl;
std
::
cout
<<
"Pick dart:"
<<
d
<<
std
::
endl
;
std
::
cout
<<
"Pick dart:"
<<
d
<<
" pos= "
<<
position
[
d
]
<<
std
::
endl
;
}
// in console:
break
;
}
...
...
@@ -427,6 +446,8 @@ int main(int argc, char **argv)
nb
=
atoi
(
argv
[
1
]);
dglobal
=
prim
.
hexaGrid_topo
(
nb
,
nb
,
nb
);
prim
.
embedHexaGrid
(
1.0
f
,
1.0
f
,
1.0
f
);
// Geom::Matrix44f mat;
// mat.identity();
// Geom::scale(2.0f, 2.0f,2.0f,mat);
...
...
include/Algo/Render/topo3_vboRender.h
View file @
53c1e31e
...
...
@@ -118,6 +118,11 @@ protected:
public:
Dart
colToDart
(
float
*
color
);
void
dartToCol
(
Dart
d
,
float
&
r
,
float
&
g
,
float
&
b
);
/**
* Constructor
* @param map the map to draw
...
...
include/Algo/Render/topo3_vboRender.hpp
View file @
53c1e31e
...
...
@@ -905,21 +905,15 @@ void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelec
{
if
(
good
(
d
))
{
unsigned
int
lab
=
d
.
index
+
1
;
// add one to avoid picking the black of screen
float
r
=
float
(
lab
%
256
)
/
256.0
f
;
lab
=
lab
/
256
;
float
g
=
float
(
lab
%
256
)
/
256.0
f
;
lab
=
lab
/
256
;
float
b
=
float
(
lab
%
256
)
/
256.0
f
;
lab
=
lab
/
256
;
if
(
lab
!=
0
)
std
::
cerr
<<
"Error picking color, too many darts"
<<
std
::
endl
;
*
colorBuffer
++
=
r
;
*
colorBuffer
++
=
g
;
*
colorBuffer
++
=
b
;
*
colorBuffer
++
=
r
;
*
colorBuffer
++
=
g
;
*
colorBuffer
++
=
b
;
float
r
,
g
,
b
;
dartToCol
(
d
,
r
,
g
,
b
);
float
*
local
=
colorBuffer
+
3
*
m_attIndex
[
d
];
// get the right position in VBO
*
local
++
=
r
;
*
local
++
=
g
;
*
local
++
=
b
;
*
local
++
=
r
;
*
local
++
=
g
;
*
local
++
=
b
;
nb
++
;
}
...
...
src/Algo/Render/topo3_vboRender.cpp
View file @
53c1e31e
...
...
@@ -98,7 +98,7 @@ void topo3_VBORender::setAllDartsColor(float r, float g, float b)
void
topo3_VBORender
::
drawDarts
()
{
glColor3f
(
1.0
f
,
1.0
f
,
1.0
f
);
//
glColor3f(1.0f,1.0f,1.0f);
glLineWidth
(
m_topo_dart_width
);
glPointSize
(
2.0
f
*
m_topo_dart_width
);
...
...
@@ -214,6 +214,32 @@ void topo3_VBORender::popColors()
}
Dart
topo3_VBORender
::
colToDart
(
float
*
color
)
{
unsigned
int
r
=
(
unsigned
int
)(
color
[
0
]
*
255.0
f
);
unsigned
int
g
=
(
unsigned
int
)(
color
[
1
]
*
255.0
f
);
unsigned
int
b
=
(
unsigned
int
)(
color
[
2
]
*
255.0
f
);
unsigned
int
id
=
r
+
255
*
g
+
255
*
255
*
b
;
if
(
id
==
0
)
return
Dart
::
nil
();
return
Dart
(
id
-
1
);
}
void
topo3_VBORender
::
dartToCol
(
Dart
d
,
float
&
r
,
float
&
g
,
float
&
b
)
{
unsigned
int
lab
=
d
.
index
+
1
;
// add one to avoid picking the black of screen
r
=
float
(
lab
%
255
)
/
255.0
f
;
lab
=
lab
/
255
;
g
=
float
(
lab
%
255
)
/
255.0
f
;
lab
=
lab
/
255
;
b
=
float
(
lab
%
255
)
/
255.0
f
;
lab
=
lab
/
255
;
if
(
lab
!=
0
)
std
::
cerr
<<
"Error picking color, too many darts"
<<
std
::
endl
;
}
Dart
topo3_VBORender
::
picking
(
unsigned
int
x
,
unsigned
int
y
)
{
//more easy picking for
...
...
@@ -241,17 +267,7 @@ Dart topo3_VBORender::picking(unsigned int x, unsigned int y)
glClearColor
(
cc
[
0
],
cc
[
1
],
cc
[
2
],
cc
[
3
]);
// compute dart index:
unsigned
int
r
=
(
unsigned
int
)(
color
[
0
]
*
255.0
f
);
unsigned
int
g
=
(
unsigned
int
)(
color
[
1
]
*
255.0
f
);
unsigned
int
b
=
(
unsigned
int
)(
color
[
2
]
*
255.0
f
);
unsigned
int
id
=
r
+
256
*
g
+
256
*
256
*
b
;
if
(
id
==
0
)
return
Dart
::
nil
();
return
Dart
(
id
-
1
);
// -1 because we draw +1
return
colToDart
(
color
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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