Commit 5f038b96 authored by untereiner's avatar untereiner
Browse files

Merge cgogn:~cgogn/CGoGN

Conflicts:
	Apps/Examples/viewer.cpp
parents a1cda248 8924e290
...@@ -26,19 +26,16 @@ ...@@ -26,19 +26,16 @@
Viewer::Viewer() : Viewer::Viewer() :
m_renderStyle(FLAT), m_renderStyle(FLAT),
m_drawTopo(true),
m_drawVertices(false), m_drawVertices(false),
m_drawEdges(false), m_drawEdges(false),
m_drawFaces(true), m_drawFaces(true),
m_drawNormals(false), m_drawNormals(false),
m_render(NULL), m_render(NULL),
m_renderTopo(NULL),
m_phongShader(NULL), m_phongShader(NULL),
m_flatShader(NULL), m_flatShader(NULL),
m_vectorShader(NULL), m_vectorShader(NULL),
m_simpleColorShader(NULL), m_simpleColorShader(NULL),
m_pointSprite(NULL), m_pointSprite(NULL)
m_strings(NULL)
{ {
normalScaleFactor = 1.0f ; normalScaleFactor = 1.0f ;
vertexScaleFactor = 0.1f ; vertexScaleFactor = 0.1f ;
...@@ -82,7 +79,6 @@ void Viewer::cb_initGL() ...@@ -82,7 +79,6 @@ void Viewer::cb_initGL()
setFocal(5.0f) ; setFocal(5.0f) ;
m_render = new Algo::Render::GL2::MapRender() ; m_render = new Algo::Render::GL2::MapRender() ;
m_renderTopo = new Algo::Render::GL2::TopoRender();
m_positionVBO = new Utils::VBO() ; m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ; m_normalVBO = new Utils::VBO() ;
...@@ -114,16 +110,11 @@ void Viewer::cb_initGL() ...@@ -114,16 +110,11 @@ void Viewer::cb_initGL()
m_pointSprite = new Utils::PointSprite() ; m_pointSprite = new Utils::PointSprite() ;
m_pointSprite->setAttributePosition(m_positionVBO) ; m_pointSprite->setAttributePosition(m_positionVBO) ;
m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f));
storeVerticesInfo();
m_strings->sendToVBO();
registerShader(m_phongShader) ; registerShader(m_phongShader) ;
registerShader(m_flatShader) ; registerShader(m_flatShader) ;
registerShader(m_vectorShader) ; registerShader(m_vectorShader) ;
registerShader(m_simpleColorShader) ; registerShader(m_simpleColorShader) ;
registerShader(m_pointSprite) ; registerShader(m_pointSprite) ;
registerShader(m_strings);
} }
void Viewer::cb_redraw() void Viewer::cb_redraw()
...@@ -136,7 +127,6 @@ void Viewer::cb_redraw() ...@@ -136,7 +127,6 @@ void Viewer::cb_redraw()
m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ; m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
m_pointSprite->postdraw() ; m_pointSprite->postdraw() ;
m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f));
} }
if(m_drawEdges) if(m_drawEdges)
...@@ -172,8 +162,6 @@ void Viewer::cb_redraw() ...@@ -172,8 +162,6 @@ void Viewer::cb_redraw()
glDisable(GL_POLYGON_OFFSET_FILL) ; glDisable(GL_POLYGON_OFFSET_FILL) ;
} }
if(m_drawTopo)
m_renderTopo->drawTopo();
} }
void Viewer::cb_Open() void Viewer::cb_Open()
...@@ -189,10 +177,10 @@ void Viewer::cb_Open() ...@@ -189,10 +177,10 @@ void Viewer::cb_Open()
void Viewer::cb_Save() void Viewer::cb_Save()
{ {
std::string filters("off (*.off);; map (*.map)") ; std::string filters("all (*.*);; map (*.map);; off (*.off);; ply (*.ply);; plygen (*.plygen)") ;
std::string filename = selectFileSave("Save Mesh", "", filters) ; std::string filename = selectFileSave("Save Mesh", "", filters) ;
exportMesh(filename); exportMesh(filename) ;
} }
void Viewer::cb_mousePress(int button, int x, int y) void Viewer::cb_mousePress(int button, int x, int y)
...@@ -218,8 +206,6 @@ void Viewer::cb_mousePress(int button, int x, int y) ...@@ -218,8 +206,6 @@ void Viewer::cb_mousePress(int button, int x, int y)
updateGL(); updateGL();
} }
void Viewer::importMesh(std::string& filename) void Viewer::importMesh(std::string& filename)
{ {
myMap.clear(true) ; myMap.clear(true) ;
...@@ -248,12 +234,11 @@ void Viewer::importMesh(std::string& filename) ...@@ -248,12 +234,11 @@ void Viewer::importMesh(std::string& filename)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ; m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ; m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_renderTopo->updateData<PFP>(myMap, position, 0.9, 0.9, allDarts);
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
normalBaseSize = bb.diagSize() / 100.0f ; normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ; // vertexBaseSize = normalBaseSize /5.0f ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX, "normal") ;
if(!normal.isValid()) if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ; normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
...@@ -262,41 +247,25 @@ void Viewer::importMesh(std::string& filename) ...@@ -262,41 +247,25 @@ void Viewer::importMesh(std::string& filename)
m_positionVBO->updateData(position) ; m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ; m_normalVBO->updateData(normal) ;
storeVerticesInfo();
m_strings->sendToVBO();
setParamObject(bb.maxSize(), bb.center().data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ; updateGLMatrices() ;
} }
void Viewer::exportMesh(std::string& filename) void Viewer::exportMesh(std::string& filename)
{ {
size_t pos = filename.rfind("."); // position of "." in filename size_t pos = filename.rfind(".") ; // position of "." in filename
std::string extension = filename.substr(pos); std::string extension = filename.substr(pos) ;
if (extension == std::string(".map")) if (extension == std::string(".off"))
myMap.saveMapBin(filename);
else
Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ; Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0)
Algo::Export::exportPLY<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension == std::string(".map"))
myMap.saveMapBin(filename) ;
else
std::cerr << "Cannot save file " << filename << " : unknown or unhandled extension" << std::endl ;
} }
void Viewer::storeVerticesInfo()
{
CellMarker mv(myMap,VERTEX);
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 Viewer::slot_drawVertices(bool b) void Viewer::slot_drawVertices(bool b)
{ {
m_drawVertices = b ; m_drawVertices = b ;
...@@ -306,7 +275,6 @@ void Viewer::slot_drawVertices(bool b) ...@@ -306,7 +275,6 @@ void Viewer::slot_drawVertices(bool b)
void Viewer::slot_verticesSize(int i) void Viewer::slot_verticesSize(int i)
{ {
vertexScaleFactor = i / 500.0f ; vertexScaleFactor = i / 500.0f ;
m_strings->setScale(0.02f*i);
updateGL() ; updateGL() ;
} }
...@@ -352,10 +320,19 @@ int main(int argc, char **argv) ...@@ -352,10 +320,19 @@ int main(int argc, char **argv)
sqt.setGeometry(0, 0, 1000, 800) ; sqt.setGeometry(0, 0, 1000, 800) ;
sqt.show() ; sqt.show() ;
if(argc == 2) if(argc >= 2)
{ {
std::string filename(argv[1]) ; std::string filename(argv[1]) ;
sqt.importMesh(filename) ; sqt.importMesh(filename) ;
if(argc >= 3)
{
std::string filenameExp(argv[2]) ;
std::cout << "Exporting " << filename << " as " << filenameExp << " ... "<< std::flush ;
sqt.exportMesh(filenameExp) ;
std::cout << "done!" << std::endl ;
return (0) ;
}
} }
sqt.initGUI() ; sqt.initGUI() ;
......
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
float faceShrinkage ; float faceShrinkage ;
int m_renderStyle ; int m_renderStyle ;
bool m_drawTopo; // bool m_drawTopo;
bool m_drawVertices ; bool m_drawVertices ;
bool m_drawEdges ; bool m_drawEdges ;
bool m_drawFaces ; bool m_drawFaces ;
...@@ -96,7 +96,6 @@ public: ...@@ -96,7 +96,6 @@ public:
PFP::TVEC3 normal ; PFP::TVEC3 normal ;
Algo::Render::GL2::MapRender* m_render ; Algo::Render::GL2::MapRender* m_render ;
Algo::Render::GL2::TopoRender* m_renderTopo ;
Utils::VBO* m_positionVBO ; Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO ; Utils::VBO* m_normalVBO ;
...@@ -106,7 +105,6 @@ public: ...@@ -106,7 +105,6 @@ public:
Utils::ShaderVectorPerVertex* m_vectorShader ; Utils::ShaderVectorPerVertex* m_vectorShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ; Utils::ShaderSimpleColor* m_simpleColorShader ;
Utils::PointSprite* m_pointSprite ; Utils::PointSprite* m_pointSprite ;
Utils::Strings3D* m_strings;
Viewer() ; Viewer() ;
...@@ -117,14 +115,9 @@ public: ...@@ -117,14 +115,9 @@ public:
void cb_Open() ; void cb_Open() ;
void cb_Save() ; void cb_Save() ;
void cb_mousePress(int button, int x, int y);
void importMesh(std::string& filename) ; void importMesh(std::string& filename) ;
void exportMesh(std::string& filename); void exportMesh(std::string& filename);
protected:
void storeVerticesInfo();
public slots: public slots:
void slot_drawVertices(bool b) ; void slot_drawVertices(bool b) ;
......
...@@ -181,6 +181,7 @@ void MyQT::traverse2() ...@@ -181,6 +181,7 @@ void MyQT::traverse2()
{ {
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f); Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f);
m_drawer.color3f(1.0f,0.0f,0.0f); m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2); Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d); m_affDarts.push_back(d);
......
...@@ -255,11 +255,15 @@ public: ...@@ -255,11 +255,15 @@ public:
Dart picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good=allDarts); Dart picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good=allDarts);
/**
* compute dart from color (for picking)
*/
Dart colToDart(float* color); Dart colToDart(float* color);
template<typename PFP> /**
void dartToCol(typename PFP::MAP& map, Dart d, float& r, float& g, float& b); * compute color from dart (for picking)
*/
void dartToCol(Dart d, float& r, float& g, float& b);
......
...@@ -253,19 +253,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -253,19 +253,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
} }
template<typename PFP>
void Topo3Render::dartToCol(typename PFP::MAP& map, Dart d, float& r, float& g, float& b)
{
// unsigned int lab = d.index + 1; // add one to avoid picking the black of screen
unsigned int lab =map.dartIndex(d) + 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)
CGoGNerr << "Error picking color, too many darts"<< CGoGNendl;
}
template<typename PFP> template<typename PFP>
void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good)
...@@ -281,7 +268,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g ...@@ -281,7 +268,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
if (nb < m_nbDarts) if (nb < m_nbDarts)
{ {
float r,g,b; float r,g,b;
dartToCol<PFP>(map, d, r,g,b); dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r; *local++ = r;
......
...@@ -115,18 +115,35 @@ protected: ...@@ -115,18 +115,35 @@ protected:
Utils::ShaderColorPerVertex* m_shader2; Utils::ShaderColorPerVertex* m_shader2;
/**
* compute color from dart index (for color picking)
*/
Dart colToDart(float* color); Dart colToDart(float* color);
template<typename PFP> /**
void dartToCol(typename PFP::MAP& map, Dart d, float& r, float& g, float& b); * compute dart from color (for color picking)
*/
void dartToCol(Dart d, float& r, float& g, float& b);
/**
* pick the color in the rendered image
*/
Dart pickColor(unsigned int x, unsigned int y); Dart pickColor(unsigned int x, unsigned int y);
/**
* affect a color to each dart
*/
template<typename PFP> template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good); void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good);
/**
* save colors before picking
*/
void pushColors(); void pushColors();
/**
* restore colors after picking
*/
void popColors(); void popColors();
public: public:
......
...@@ -67,10 +67,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC ...@@ -67,10 +67,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
std::vector<Dart> vecDarts; std::vector<Dart> vecDarts;
vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory
if (m_attIndex.map() != &map) m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
{ if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
}
for(Dart d = map.begin(); d!= map.end(); map.next(d)) for(Dart d = map.begin(); d!= map.end(); map.next(d))
{ {
...@@ -213,10 +212,10 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -213,10 +212,10 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
std::vector<Dart> vecDarts; std::vector<Dart> vecDarts;
vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory
if (m_attIndex.map() != &map) m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
{ if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
}
for(Dart d = map.begin(); d!= map.end(); map.next(d)) for(Dart d = map.begin(); d!= map.end(); map.next(d))
{ {
...@@ -361,18 +360,6 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -361,18 +360,6 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
} }
template<typename PFP>
void TopoRender::dartToCol(typename PFP::MAP& map, Dart d, float& r, float& g, float& b)
{
unsigned int lab = map.dartIndex(d) + 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)
CGoGNerr << "Error picking color, too many darts"<< CGoGNendl;
}
template<typename PFP> template<typename PFP>
...@@ -382,6 +369,13 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go ...@@ -382,6 +369,13 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go
float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); float* colorBuffer = reinterpret_cast<float*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
unsigned int nb=0; unsigned int nb=0;
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid())
{
CGoGNerr << "Error attribute_dartIndex does not exist during TopoRender::picking" << CGoGNendl;
return;
}
for (Dart d = map.begin(); d != map.end(); map.next(d)) for (Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if (good(d)) if (good(d))
...@@ -389,7 +383,7 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go ...@@ -389,7 +383,7 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go
if (nb < m_nbDarts) if (nb < m_nbDarts)
{ {
float r,g,b; float r,g,b;
dartToCol<PFP>(map,d, r,g,b); dartToCol(d, r,g,b);
float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO
*local++ = r; *local++ = r;
*local++ = g; *local++ = g;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define __GENERIC_MAP__ #define __GENERIC_MAP__
#include <iostream> #include <iostream>
#include <string>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
...@@ -165,7 +166,7 @@ public: ...@@ -165,7 +166,7 @@ public:
MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; } MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; }
/**************************************** /****************************************
* MULTIRES * * RESOLUTION LEVELS MANAGEMENT *
****************************************/ ****************************************/
void printMR() ; void printMR() ;
...@@ -234,12 +235,20 @@ protected: ...@@ -234,12 +235,20 @@ protected:
*/ */
void deleteDart(Dart d) ; void deleteDart(Dart d) ;
private:
/** /**
* internal functions * create a copy of a dart (based on its index in m_attribs[DART]) and returns its index
*/
unsigned int copyDartLine(unsigned int index) ;
/**
* duplicate a dart starting from current level
*/
void duplicateDart(Dart d) ;
/**
* Properly deletes a dart in m_attribs[DART]
*/ */
void deleteDartLine(unsigned int index) ; void deleteDartLine(unsigned int index) ;
unsigned int newCopyOfDartLine(unsigned int index) ;
public: public:
/** /**
......
...@@ -44,7 +44,7 @@ inline void GenericMap::setCurrentLevel(unsigned int l) ...@@ -44,7 +44,7 @@ inline void GenericMap::setCurrentLevel(unsigned int l)
inline void GenericMap::incCurrentLevel() inline void GenericMap::incCurrentLevel()
{ {
if(m_mrCurrentLevel < m_mrDarts.size())