Commit 877cc473 authored by untereiner's avatar untereiner

Merge branch 'master' of cgogn:~thery/CGoGN

parents f348eec9 53c1e31e
...@@ -108,9 +108,26 @@ void myGlutWin::myRedraw(void) ...@@ -108,9 +108,26 @@ void myGlutWin::myRedraw(void)
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glDisable(GL_LIGHTING); 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.0f,1.0f,.0f); glColor3f(0.0f,1.0f,.0f);
m_render->draw(Algo::Render::VBO::POINTS); m_render->draw(Algo::Render::VBO::POINTS);
...@@ -187,6 +204,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) ...@@ -187,6 +204,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
} }
break; break;
case 'x': case 'x':
{ {
// push/pop color is only needed for dart coloring conservation // push/pop color is only needed for dart coloring conservation
...@@ -203,22 +221,23 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) ...@@ -203,22 +221,23 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
//pick //pick
Dart d = m_render_topo->picking(x,H-y); Dart d = m_render_topo->picking(x,H-y);
glPopMatrix(); glPopMatrix();
m_render_topo->popColors(); m_render_topo->popColors();
if (d != Dart::nil()) if (d != Dart::nil())
{ {
m_render_topo->setDartColor(d,1.0,0.0,0.0);
redraw(); redraw();
std::stringstream ss; std::stringstream ss;
ss << "Pick dart:" << d << std::endl<<"pos="<< position[d]; ss << "Pick dart:" << d << std::endl<<"pos="<< position[d];
glColor3f(1.,1.,0.); glColor3f(1.,1.,0.);
printString2D(x+12,y+22,ss.str()); printString2D(x+12,y+22,ss.str());
glutSwapBuffers(); glutSwapBuffers();
// std::cout << "Pick dart:" << d << " position= "<< position[d] << std::endl; std::cout << "Pick dart:" << d << " pos= "<< position[d] << std::endl;
std::cout << "Pick dart:" << d << std::endl;
} }
// in console:
break; break;
} }
...@@ -427,6 +446,8 @@ int main(int argc, char **argv) ...@@ -427,6 +446,8 @@ int main(int argc, char **argv)
nb = atoi(argv[1]); nb = atoi(argv[1]);
dglobal = prim.hexaGrid_topo(nb,nb,nb); dglobal = prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f); prim.embedHexaGrid(1.0f,1.0f,1.0f);
// Geom::Matrix44f mat; // Geom::Matrix44f mat;
// mat.identity(); // mat.identity();
// Geom::scale(2.0f, 2.0f,2.0f,mat); // Geom::scale(2.0f, 2.0f,2.0f,mat);
......
...@@ -118,6 +118,11 @@ protected: ...@@ -118,6 +118,11 @@ protected:
public: public:
Dart colToDart(float* color);
void dartToCol(Dart d, float& r, float& g, float& b);
/** /**
* Constructor * Constructor
* @param map the map to draw * @param map the map to draw
......
...@@ -905,21 +905,15 @@ void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelec ...@@ -905,21 +905,15 @@ void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelec
{ {
if (good(d)) if (good(d))
{ {
unsigned int lab = d.index + 1; // add one to avoid picking the black of screen float r,g,b;
dartToCol(d, r,g,b);
float r = float(lab%256) / 256.0f; lab = lab/256; float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
float g = float(lab%256) / 256.0f; lab = lab/256; *local++ = r;
float b = float(lab%256) / 256.0f; lab = lab/256; *local++ = g;
*local++ = b;
if (lab!=0) *local++ = r;
std::cerr << "Error picking color, too many darts"<< std::endl; *local++ = g;
*local++ = b;
*colorBuffer++ = r;
*colorBuffer++ = g;
*colorBuffer++ = b;
*colorBuffer++ = r;
*colorBuffer++ = g;
*colorBuffer++ = b;
nb++; nb++;
} }
......
...@@ -98,7 +98,7 @@ void topo3_VBORender::setAllDartsColor(float r, float g, float b) ...@@ -98,7 +98,7 @@ void topo3_VBORender::setAllDartsColor(float r, float g, float b)
void topo3_VBORender::drawDarts() void topo3_VBORender::drawDarts()
{ {
glColor3f(1.0f,1.0f,1.0f); // glColor3f(1.0f,1.0f,1.0f);
glLineWidth(m_topo_dart_width); glLineWidth(m_topo_dart_width);
glPointSize(2.0f*m_topo_dart_width); glPointSize(2.0f*m_topo_dart_width);
...@@ -214,6 +214,32 @@ void topo3_VBORender::popColors() ...@@ -214,6 +214,32 @@ void topo3_VBORender::popColors()
} }
Dart topo3_VBORender::colToDart(float* color)
{
unsigned int r = (unsigned int)(color[0]*255.0f);
unsigned int g = (unsigned int)(color[1]*255.0f);
unsigned int b = (unsigned int)(color[2]*255.0f);
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.0f; lab = lab/255;
g = float(lab%255) / 255.0f; lab = lab/255;
b = float(lab%255) / 255.0f; 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) Dart topo3_VBORender::picking(unsigned int x, unsigned int y)
{ {
//more easy picking for //more easy picking for
...@@ -241,17 +267,7 @@ Dart topo3_VBORender::picking(unsigned int x, unsigned int y) ...@@ -241,17 +267,7 @@ Dart topo3_VBORender::picking(unsigned int x, unsigned int y)
glClearColor(cc[0], cc[1], cc[2], cc[3]); glClearColor(cc[0], cc[1], cc[2], cc[3]);
// compute dart index: return colToDart(color);
unsigned int r = (unsigned int)(color[0]*255.0f);
unsigned int g = (unsigned int)(color[1]*255.0f);
unsigned int b = (unsigned int)(color[2]*255.0f);
unsigned int id = r + 256*g +256*256*b;
if (id == 0)
return Dart::nil();
return Dart(id-1); // -1 because we draw +1
} }
......
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