Commit 3aacf0b2 authored by Sylvain Thery's avatar Sylvain Thery

ajout picking (par couleur) dans topo3_vboRender

ajout foreach orbit of parent
mini modif dans printstring (glutwin)
parent da1fdcc9
......@@ -65,3 +65,9 @@ target_link_libraries( extrusionViewD
add_executable( sceneD ../scene.cpp)
target_link_libraries( sceneD
containerD topologyD utilsD algoD ${COMMON_LIBS} )
#add_executable( VizVolumeD ../VizVolume.cpp)
#target_link_libraries( VizVolumeD
# containerD topologyD utilsD algoD ${COMMON_LIBS} Zinri)
......@@ -43,8 +43,6 @@
#include "Algo/Render/topo3_vboRender.h"
//#include "Algo/Render/topo_vboRender.h"
#include "Topology/generic/cellmarker.h"
//#include "testMaps.h"
......@@ -189,6 +187,42 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
}
break;
case 'x':
{
// push/pop color is only needed for dart coloring conservation
// can bee long long huge meshes
m_render_topo->pushColors();
// setDartsIdColor can be done only once if dart coloring not used
m_render_topo->setDartsIdColor<PFP>(myMap,allDarts);
// transform as in drawing cb
glPushMatrix();
float sc = 50.0f/gWidthObj;
glScalef(sc,sc,sc);
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())
{
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;
}
// in console:
break;
}
case 'Q':
m_render_topo->setAllDartsColor(1.0f,1.0f,1.0f);
glutPostRedisplay();
......
......@@ -85,6 +85,9 @@ protected:
*/
float m_topo_relation_width;
float *m_color_save;
AttributeHandler<unsigned int> m_attIndex;
/**
......@@ -207,10 +210,37 @@ public:
* @param g green !
* @param b blue !
*/
void overdrawDart(Dart d, float width, float r, float g, float b);
/**
* save colors
*/
void pushColors();
/**
* restore colors
*/
void popColors();
/*
* store darts in color for picking
* @param map the map (must be the same than during updating data)
* @param good the selector (must be the same than during updating data)
*/
template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good);
/**
* pick dart with color set bey setDartsIdColor
* Do not forget to apply same transformation to scene before picking than before drawing !
* @param x position of mouse (x)
* @param y position of mouse (pass H-y, classic pb of origin)
* @return the dart or NIL
*/
Dart picking(unsigned int x, unsigned int y);
};
//template<typename MAP>
......
......@@ -890,6 +890,50 @@ void topo3_VBORenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect
//}
template<typename PFP>
void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good)
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
float* colorBuffer = reinterpret_cast<float*>(glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (nb < m_nbDarts)
{
if (good(d))
{
unsigned int lab = d.index + 1; // add one to avoid picking the black of screen
float r = float(lab%256) / 256.0f; lab = lab/256;
float g = float(lab%256) / 256.0f; lab = lab/256;
float b = float(lab%256) / 256.0f; 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;
nb++;
}
}
else
{
std::cerr << "Error buffer too small for color picking (change the good parameter ?)" << std::endl;
d = map.end();
}
}
glUnmapBufferARB(GL_ARRAY_BUFFER);
}
}//end namespace VBO
}//end namespace Algo
......
......@@ -182,6 +182,20 @@ public:
FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
}
template <typename MAP>
void markOrbitInParent(unsigned int orbit, Dart d)
{
FunctorMark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT,m_thread)) ;
foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
}
template <typename MAP>
void unmarkOrbit(unsigned int orbit, Dart d)
{
FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
foreach_dart_of_orbit_in_parent<MAP>(m_map, orbit, d, fm, m_thread);
}
};
/**
......
......@@ -38,27 +38,52 @@
namespace CGoGN
{
/**
* mark darts of a cell with marker m
* Warning: works only if any darts of vertex is already marked
* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
* @param MF type of Map used for traversals
* @param d a dart of the cc
* @param m index of the marker
*/
template <typename MF, typename MM>
void markOrbitGen(int dim, typename MM::Dart d, Marker m, MM *ptr, unsigned int th=0);
///**
//* mark darts of a cell with marker m
//* Warning: works only if any darts of vertex is already marked
//* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
//* @param MF type of Map used for traversals
//* @param d a dart of the cc
//* @param m index of the marker
//*/
//template <typename MF, typename MM>
//void markOrbitGen(int dim, typename MM::Dart d, Marker m, MM *ptr, unsigned int th=0);
//
///**
//* unmark darts of a cell with marker m
//* Warning: works only if any darts of vertex is already marked
//* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
//* @param MF type of Map used for traversals
//* @param d a dart of the cc
//* @param m index of the marker
//*/
//template <typename MF, typename MM>
//void unmarkOrbitGen(int dim, typename MM::Dart d, Marker m, MM* ptr, unsigned int th=0);
//
///**
//* execute functor for each cell
//* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
//* @param MF type of Map used for traversals
//* @param f the functor
//*/
//template <typename MF, typename MM>
//void foreach_orbitGen(int dim, FunctorType<typename MM>& fonct, MM* ptr, unsigned int th=0);
//
//template <typename MF, typename MM>
//void foreach_orbitGen_sel(int dim, FunctorType<typename MM>& fonct, MM* ptr, FunctorType<typename MM>& good, unsigned int th=0);
//
///**
//* Associate an embedding to all darts of a vertex
//* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
//* @param MF type of Map used for traversals
//* @param d a dart of the topological vertex
//* @param index the index of Embedding to use
//* @param em the embedding to associate
//* ptr an ptr on the Map
//*/
//template <typename MF, typename MM>
//void embedOrbitGen(int dim, typename MM::Dart d, int index, Embedding* em, MM* ptr, unsigned int th=0);
/**
* unmark darts of a cell with marker m
* Warning: works only if any darts of vertex is already marked
* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
* @param MF type of Map used for traversals
* @param d a dart of the cc
* @param m index of the marker
*/
template <typename MF, typename MM>
void unmarkOrbitGen(int dim, typename MM::Dart d, Marker m, MM* ptr, unsigned int th=0);
/**
* execute functor for each cell
......@@ -66,26 +91,24 @@ void unmarkOrbitGen(int dim, typename MM::Dart d, Marker m, MM* ptr, unsigned in
* @param MF type of Map used for traversals
* @param f the functor
*/
template <typename MF, typename MM>
void foreach_orbitGen(int dim, FunctorType<typename MM>& fonct, MM* ptr, unsigned int th=0);
template <typename MF, typename MM>
void foreach_orbitGen_sel(int dim, FunctorType<typename MM>& fonct, MM* ptr, FunctorType<typename MM>& good, unsigned int th=0);
/**
* Associate an embedding to all darts of a vertex
* @param dim the dimension of the cell: 0=vertex, 1=edge, 2=face, 3=volume, -1=connected component
* @param MF type of Map used for traversals
* @param d a dart of the topological vertex
* @param index the index of Embedding to use
* @param em the embedding to associate
* ptr an ptr on the Map
*/
template <typename MF, typename MM>
void embedOrbitGen(int dim, typename MM::Dart d, int index, Embedding* em, MM* ptr, unsigned int th=0);
//template <typename MAP, typename TRAV>
//bool foreach_dart_of_orbit_gen(unsigned int orbit, Dart d, FunctorType& f, MAP *ptrMap, unsigned int thread=0)
//{
// switch(orbit)
// {
// case DART_ORBIT: return f(d);
// case VERTEX_ORBIT: return ptrMap->TRAV::foreach_dart_of_vertex(d, f,thread);
// case EDGE_ORBIT: return ptrMap->TRAV::foreach_dart_of_edge(d, f,thread);
// case FACE_ORBIT: return ptrMap->TRAV::foreach_dart_of_face(d, f,thread);
// case VOLUME_ORBIT: return ptrMap->TRAV::foreach_dart_of_volume(d, f, thread);
//// case -1: return foreach_dart_of_cc(d,f,thread);
// default: assert(!"Cells of this dimension are not handled");
// }
// return false;
//}
} //namespace CGoGN
#include "Topology/generic/genericFunc.hpp"
//#include "Topology/generic/genericFunc.hpp"
#endif
......@@ -406,8 +406,42 @@ public:
* @return the number of orbits
*/
unsigned int getNbOrbits(unsigned int orbit, const FunctorSelect& good = SelectorTrue());
} ;
template <typename MAP>
bool foreach_dart_of_orbit_in_parent( MAP* ptrMap, unsigned int orbit, Dart d, FunctorType& f, unsigned int thread=0)
{
switch(orbit)
{
case DART_ORBIT: return f(d);
case VERTEX_ORBIT: return ptrMap->MAP::ParentMap::foreach_dart_of_vertex(d, f,thread);
case EDGE_ORBIT: return ptrMap->MAP::ParentMap::foreach_dart_of_edge(d, f,thread);
case FACE_ORBIT: return ptrMap->MAP::ParentMap::foreach_dart_of_face(d, f,thread);
case VOLUME_ORBIT: return ptrMap->MAP::ParentMap::foreach_dart_of_volume(d, f, thread);
default: assert(!"Cells of this dimension are not handled");
}
return false;
}
template <typename MAP>
bool foreach_dart_of_orbit_in_parent2( MAP* ptrMap, unsigned int orbit, Dart d, FunctorType& f, unsigned int thread=0)
{
switch(orbit)
{
case DART_ORBIT: return f(d);
case VERTEX_ORBIT: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_vertex(d, f,thread);
case EDGE_ORBIT: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_edge(d, f,thread);
case FACE_ORBIT: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_face(d, f,thread);
case VOLUME_ORBIT: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_volume(d, f, thread);
default: assert(!"Cells of this dimension are not handled");
}
return false;
}
} //namespace CGoGN
#include "Topology/generic/genericmap.hpp"
......
......@@ -25,6 +25,7 @@
#include "Algo/Render/topo3_vboRender.h"
#include "Topology/generic/dart.h"
#include <string.h>
namespace CGoGN
{
......@@ -40,7 +41,7 @@ namespace VBO
topo3_VBORender::topo3_VBORender():
m_topo_dart_width(2.0f), m_topo_relation_width(3.0f)
m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL)
{
glGenBuffersARB(5, m_VBOBuffers);
}
......@@ -51,6 +52,11 @@ topo3_VBORender::~topo3_VBORender()
glDeleteBuffersARB(5, m_VBOBuffers);
if (m_attIndex.map() != NULL)
static_cast<AttribMap*>(m_attIndex.map())->removeAttribute(m_attIndex);
if (m_color_save!=NULL)
{
delete[] m_color_save;
}
}
......@@ -184,6 +190,71 @@ void topo3_VBORender::drawTopo()
drawRelation3();
}
void topo3_VBORender::pushColors()
{
m_color_save = new float[6*m_nbDarts];
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float));
glUnmapBuffer(GL_ARRAY_BUFFER);
}
void topo3_VBORender::popColors()
{
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]);
void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE);
memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float));
glUnmapBuffer(GL_ARRAY_BUFFER);
delete[] m_color_save;
m_color_save=0;
}
Dart topo3_VBORender::picking(unsigned int x, unsigned int y)
{
//more easy picking for
unsigned int dw = m_topo_dart_width;
m_topo_dart_width+=2;
// save clear color and set to zero
float cc[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE,cc);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
// draw in back buffer (not shown on screen)
drawDarts();
// restore dart with
m_topo_dart_width = dw;
// read the pixel under the mouse in back buffer
glReadBuffer(GL_BACK);
float color[3];
glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
// compute dart index:
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
}
}//end namespace VBO
......
......@@ -355,6 +355,11 @@ void SimpleGlutWin::printString2D(int x, int y, const std::string& str)
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// not very optimized but not very important here
unsigned char blank[180];
for (unsigned int i=0; i< 180; ++i)
blank[i]=(unsigned char)(0);
// AFFICHAGE EN 2D
int x1 = x;
for (unsigned i=0; i<str.length(); ++i)
......@@ -365,6 +370,9 @@ void SimpleGlutWin::printString2D(int x, int y, const std::string& str)
x1 = x;
y += 14;
}
glRasterPos2i(x1,y+2);
glDrawPixels(12,15,GL_LUMINANCE,GL_UNSIGNED_BYTE, blank);
glRasterPos2i(x1,y);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, c);
x1 += glutBitmapWidth(GLUT_BITMAP_HELVETICA_12,c);
......
......@@ -346,6 +346,10 @@ void GlutWin_ATB::printString2D(int x, int y, const std::string& str)
glDisable(GL_DEPTH_TEST) ;
glDisable(GL_LIGHTING) ;
unsigned char blank[180];
for (unsigned int i=0; i< 180; ++i)
blank[i]=(unsigned char)(0);
// AFFICHAGE EN 2D
int x1 = x ;
for(unsigned int i = 0; i < str.length(); ++i)
......@@ -356,6 +360,9 @@ void GlutWin_ATB::printString2D(int x, int y, const std::string& str)
x1 = x ;
y += 14 ;
}
glRasterPos2i(x1,y+2);
glDrawPixels(12,15,GL_LUMINANCE,GL_UNSIGNED_BYTE, blank);
glRasterPos2i(x1, y) ;
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, c) ;
x1 += glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, c) ;
......
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