Commit 1fd88af9 authored by Sylvain Thery's avatar Sylvain Thery

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

parents fb95e191 735a68f9
......@@ -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,9 +43,8 @@
#include "Algo/Render/topo3_vboRender.h"
//#include "Algo/Render/topo_vboRender.h"
#include "Topology/generic/cellmarker.h"
#include "Utils/text3d.h"
//#include "testMaps.h"
......@@ -68,6 +67,10 @@ Dart dglobal;
unsigned int idNorm;
unsigned int idCol;
class myGlutWin: public Utils::SimpleGlutWin
{
public:
......@@ -85,8 +88,12 @@ public:
Algo::Render::VBO::MapRender_VBO* m_render;
Algo::Render::VBO::topo3_VBORenderMapD* m_render_topo;
Utils::Strings3D m_strings;
void updateVBO();
void storeVerticesInfo();
myGlutWin( int* argc, char **argv, int winX, int winY):SimpleGlutWin(argc,argv,winX,winY)
{
aff_help = false;
......@@ -99,6 +106,22 @@ public:
void myKeyboard(unsigned char keycode, int x, int y);
};
void myGlutWin::storeVerticesInfo()
{
CellMarker mv(myMap,VERTEX_CELL);
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{
if (!mv.isMarked(d))
{
mv.mark(d);
std::stringstream ss;
ss << d << " : "<< position[d];
m_strings.addString(ss.str(),position[d]);
}
}
}
void myGlutWin::myRedraw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -110,9 +133,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.0f,1.0f,.0f);
m_render->draw(Algo::Render::VBO::POINTS);
......@@ -146,6 +186,15 @@ void myGlutWin::myRedraw(void)
}
// m_strings.predraw(Geom::Vec3f(0.0,1.0,1.0));
// m_strings.draw(0,Geom::Vec3f(0.5,0.5,0.5));
// m_strings.draw(1,Geom::Vec3f(-0.5,0.5,0.5));
// m_strings.draw(2,Geom::Vec3f(-0.5,-0.5,0.5));
// m_strings.postdraw();
m_strings.drawAll(Geom::Vec3f(0.0,1.0,1.0));
//affichage de l'aide
if (aff_help) {
glColor3f(1.0f,1.0f,1.0f);
......@@ -189,6 +238,44 @@ 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())
{
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 << " pos= "<< position[d] << std::endl;
}
break;
}
case 'Q':
m_render_topo->setAllDartsColor(1.0f,1.0f,1.0f);
glutPostRedisplay();
......@@ -380,33 +467,40 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
int main(int argc, char **argv)
{
std::vector<std::string> attrNames ;
Algo::Import::importInESS<PFP>(myMap, argv[1], attrNames);
position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;
//plongement
// Algo::Modelisation::Primitive3D<PFP> prim(myMap,position);
// dglobal = prim.hexaGrid_topo(3,3,3);
// prim.embedHexaGrid(1.0f,1.0f,1.0f);
// std::vector<std::string> attrNames ;
// Algo::Import::importInESS<PFP>(myMap, argv[1], attrNames);
// position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;
position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT,"position");
Algo::Modelisation::Primitive3D<PFP> 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<PFP>::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<PFP>::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<PFP>::createOrientedPolyhedron(myMap,4);
// dglobal=d;
......@@ -443,10 +537,11 @@ int main(int argc, char **argv)
mgw.m_render = new Algo::Render::VBO::MapRender_VBO();
mgw.m_render_topo = new Algo::Render::VBO::topo3_VBORenderMapD();
mgw.updateVBO();
mgw.m_strings.init();
mgw.storeVerticesInfo();
mgw.m_strings.sendToVBO();
mgw.mainLoop();
......
......@@ -177,7 +177,6 @@ int main(int argc, char **argv)
// mgw.m_render->initPrimitives<PFP>(myMap, allDarts,Algo::Render::VBO::POINTS);
mgw.mainLoop();
return 0;
......
......@@ -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<std::string,GLuint> m_attributebyName;
/**
......
......@@ -85,6 +85,9 @@ protected:
*/
float m_topo_relation_width;
float *m_color_save;
AttributeHandler<unsigned int> m_attIndex;
/**
......@@ -115,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
......@@ -207,10 +215,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,44 @@ 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))
{
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++;
}
}
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
......@@ -404,8 +404,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"
......
......@@ -39,6 +39,7 @@
#include <map>
#include <stdlib.h>
#include <string>
#include <vector>
namespace CGoGN
{
......@@ -128,10 +129,7 @@ protected:
*/
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES);
/*
* search file in different path
*/
std::string findFile(const std::string filename);
/**
* get log after compiling
......@@ -141,6 +139,8 @@ protected:
char* getInfoLog( GLhandleARB obj );
static std::vector<std::string> m_pathes;
public:
/**
* constructor
......@@ -153,6 +153,11 @@ public:
*/
virtual ~GLSLShader();
/*
* search file in different path
*/
static std::string findFile(const std::string filename);
/**
* test support of shader
......@@ -210,6 +215,9 @@ public:
virtual void unbind();
/**
*
*/
GLuint getAttribIndex( char* attribName );
......@@ -225,20 +233,49 @@ public:
void bindAttrib(unsigned int att, const char* name) const;
/**
* check shader validity width official GLSL syntax
*/
bool validateProgram();
/**
* check program link status
*/
bool checkProgram();
/**
* check shader compile status
*/
bool checkShader(int shaderType);
public:
/**
* set uniform shader float variable
* @warning practical but less efficient that storing id (get with glGetUniformLocation) and use glUniform*fvARB
* @param NB template size of variable to set
* @param name name in shader
* @param pointer on data to copy
*/
template<unsigned int NB>
void setuniformf( const char* name , float* val);
/**
* set uniform shader int variable
* @warning practical but less efficient that storing id (get with glGetUniformLocation) and use glUniform*ivARB
* @param NB template size of variable to set
* @param name name in shader
* @param pointer on data to copy
*/
template<unsigned int NB>
void setuniformi( const char* name , int* val);
/**
* add search path for file