diff --git a/Apps/Examples/Debug/CMakeLists.txt b/Apps/Examples/Debug/CMakeLists.txt index 1091da64dd0016745251ee36acdd75efaf85ba4f..de0861f8a31aac1909a51f96984dec1865a2c450 100644 --- a/Apps/Examples/Debug/CMakeLists.txt +++ b/Apps/Examples/Debug/CMakeLists.txt @@ -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) + diff --git a/Apps/Tuto/tuto5.cpp b/Apps/Tuto/tuto5.cpp index 616116abe27e4c635cd95ff3d6ceb9cf6164066c..e7d9a5f472fdb98370c0fe8e1c66a4d38825138b 100644 --- a/Apps/Tuto/tuto5.cpp +++ b/Apps/Tuto/tuto5.cpp @@ -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(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(); @@ -380,33 +414,38 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) int main(int argc, char **argv) { - std::vector attrNames ; - Algo::Import::importInESS(myMap, argv[1], attrNames); - position = myMap.getAttribute(VERTEX_ORBIT, attrNames[0]) ; - - //plongement -// Algo::Modelisation::Primitive3D prim(myMap,position); -// dglobal = prim.hexaGrid_topo(3,3,3); -// prim.embedHexaGrid(1.0f,1.0f,1.0f); +// std::vector attrNames ; +// Algo::Import::importInESS(myMap, argv[1], attrNames); +// position = myMap.getAttribute(VERTEX_ORBIT, attrNames[0]) ; + + position = myMap.addAttribute(VERTEX_ORBIT,"position"); + + + Algo::Modelisation::Primitive3D prim(myMap,position); + int nb=3; + if (argc>1) + nb = atoi(argv[1]); + dglobal = prim.hexaGrid_topo(nb,nb,nb); + prim.embedHexaGrid(1.0f,1.0f,1.0f); // Geom::Matrix44f mat; // mat.identity(); // Geom::scale(2.0f, 2.0f,2.0f,mat); // prim.transform(mat); - Dart d = Algo::Modelisation::Polyhedron::createOrientedPolyhedron(myMap,6); - dglobal=d; - - position[d] = PFP::VEC3(0); - position[myMap.phi1(d)] = PFP::VEC3(1,0,0); - position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(1,0,1); - position[myMap.phi_1(d)] = PFP::VEC3(0,0,1); - - d = myMap.phi_1(myMap.phi2(myMap.phi_1(myMap.phi_1(myMap.phi2(myMap.phi_1(d)))))); - position[d] = PFP::VEC3(1,1,0); - position[myMap.phi1(d)] = PFP::VEC3(0,1,0); - position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(0,1,1); - position[myMap.phi_1(d)] = PFP::VEC3(1,1,1); +// Dart d = Algo::Modelisation::Polyhedron::createOrientedPolyhedron(myMap,6); +// dglobal=d; +// +// position[d] = PFP::VEC3(0); +// position[myMap.phi1(d)] = PFP::VEC3(1,0,0); +// position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(1,0,1); +// position[myMap.phi_1(d)] = PFP::VEC3(0,0,1); +// +// d = myMap.phi_1(myMap.phi2(myMap.phi_1(myMap.phi_1(myMap.phi2(myMap.phi_1(d)))))); +// position[d] = PFP::VEC3(1,1,0); +// position[myMap.phi1(d)] = PFP::VEC3(0,1,0); +// position[myMap.phi1(myMap.phi1(d))] = PFP::VEC3(0,1,1); +// position[myMap.phi_1(d)] = PFP::VEC3(1,1,1); // Dart d = Algo::Modelisation::Polyhedron::createOrientedPolyhedron(myMap,4); // dglobal=d; diff --git a/Apps/Tuto/tuto_ogl2.cpp b/Apps/Tuto/tuto_ogl2.cpp index 22c9a13e03b1b6316fa6df24b1e4ac7e4cfa1961..d315abb38c3d00d6ec9be32bfd3dabba91fe0d92 100644 --- a/Apps/Tuto/tuto_ogl2.cpp +++ b/Apps/Tuto/tuto_ogl2.cpp @@ -177,7 +177,6 @@ int main(int argc, char **argv) // mgw.m_render->initPrimitives(myMap, allDarts,Algo::Render::VBO::POINTS); - mgw.mainLoop(); return 0; diff --git a/include/Algo/Render/gl3mapRender.h b/include/Algo/Render/gl3mapRender.h index 5320f84cfe0fdeb91a6cac2f2be8f501bccfa1a3..c815d455362b30ea441b9b568decc99a871b5463 100644 --- a/include/Algo/Render/gl3mapRender.h +++ b/include/Algo/Render/gl3mapRender.h @@ -76,13 +76,25 @@ protected: * vbo buffers */ GLuint m_VBOBuffers[NB_BUFFERS] ; -// bool m_allocatedBuffers[NB_BUFFERS] ; -// bool m_usedBuffers[NB_BUFFERS] ; + + /** + * + */ bool m_allocatedAttributes[NB_BUFFERS] ; + + /** + * + */ bool m_usedAttributes[NB_BUFFERS] ; + /** + * + */ unsigned int m_AttributesDataSize[NB_BUFFERS]; + /** + * + */ std::map m_attributebyName; /** diff --git a/include/Algo/Render/topo3_vboRender.h b/include/Algo/Render/topo3_vboRender.h index 5968b2100954ad57a0b9f71f8f9369932fc4304a..c771cd2bbcd2833b95662b22e9780ff919ea08cf 100644 --- a/include/Algo/Render/topo3_vboRender.h +++ b/include/Algo/Render/topo3_vboRender.h @@ -85,6 +85,9 @@ protected: */ float m_topo_relation_width; + + float *m_color_save; + AttributeHandler 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 + 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 diff --git a/include/Algo/Render/topo3_vboRender.hpp b/include/Algo/Render/topo3_vboRender.hpp index 6f9082a675229026c1b7b20ec0cfd705089cf4bf..7bde19ad69440df173f6d860e22137a9536de5ae 100644 --- a/include/Algo/Render/topo3_vboRender.hpp +++ b/include/Algo/Render/topo3_vboRender.hpp @@ -890,6 +890,50 @@ void topo3_VBORenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect //} + +template +void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) +{ + + glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); + float* colorBuffer = reinterpret_cast(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 diff --git a/include/Topology/generic/dartmarker.h b/include/Topology/generic/dartmarker.h index 5fef7f41010da764c94432ef4d49d8e22e6e1491..88cde50186c60c5a1006b567b46c319a21dc8d22 100644 --- a/include/Topology/generic/dartmarker.h +++ b/include/Topology/generic/dartmarker.h @@ -182,6 +182,20 @@ public: FunctorUnmark fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ; m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ; } + + template + void markOrbitInParent(unsigned int orbit, Dart d) + { + FunctorMark fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT,m_thread)) ; + foreach_dart_of_orbit_in_parent(dynamic_cast(&m_map), orbit, d, fm, m_thread); + } + + template + void unmarkOrbit(unsigned int orbit, Dart d) + { + FunctorUnmark fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ; + foreach_dart_of_orbit_in_parent(m_map, orbit, d, fm, m_thread); + } }; /** diff --git a/include/Topology/generic/genericFunc.h b/include/Topology/generic/genericFunc.h index 00fb67aa3ea371f404f491ee986766e7650f82b0..2cf5a868287cc9a61b64c7610d9749faaef6dec9 100644 --- a/include/Topology/generic/genericFunc.h +++ b/include/Topology/generic/genericFunc.h @@ -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 -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 +//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 +//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 +//void foreach_orbitGen(int dim, FunctorType& fonct, MM* ptr, unsigned int th=0); +// +//template +//void foreach_orbitGen_sel(int dim, FunctorType& fonct, MM* ptr, FunctorType& 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 +//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 -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 -void foreach_orbitGen(int dim, FunctorType& fonct, MM* ptr, unsigned int th=0); - -template -void foreach_orbitGen_sel(int dim, FunctorType& fonct, MM* ptr, FunctorType& 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 -void embedOrbitGen(int dim, typename MM::Dart d, int index, Embedding* em, MM* ptr, unsigned int th=0); +//template +//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 diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 05ecc83df3105c57d9a1425537e4783646982d9f..f672d3056a7ae7e155b509c6d84f28da8cb9a97c 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -404,8 +404,42 @@ public: * @return the number of orbits */ unsigned int getNbOrbits(unsigned int orbit, const FunctorSelect& good = SelectorTrue()); + } ; + + +template +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 +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" diff --git a/src/Algo/Render/topo3_vboRender.cpp b/src/Algo/Render/topo3_vboRender.cpp index f01e0d28630a57eb2b4d32c9119b4c6869052e32..730c5431bf37f5ae75e462f384d4d2dea46983ec 100644 --- a/src/Algo/Render/topo3_vboRender.cpp +++ b/src/Algo/Render/topo3_vboRender.cpp @@ -25,6 +25,7 @@ #include "Algo/Render/topo3_vboRender.h" #include "Topology/generic/dart.h" +#include 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(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 diff --git a/src/Utils/glutwin.cpp b/src/Utils/glutwin.cpp index 6d9bda44593cb385c2eb40935a6e08c1623f9f3a..0aa2e9050df55ea918b22c049eae6fab553dbd36 100644 --- a/src/Utils/glutwin.cpp +++ b/src/Utils/glutwin.cpp @@ -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