Commit 8924e290 authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor

Merge branch 'master' of /home/vanhoey/CGoGN

* 'master' of /home/vanhoey/CGoGN:
  Added utility in viewer to export a mesh into all available exported types. Added utility in viewer to do this in command-line using 2 arguments : for example "./viewer input.off output.ply" A set of data is btw available here : http://canaris.u-strasbg.fr/~kenneth/share/DataGeometry/
  Added utility in viewer to export a mesh into all available exported types. Added utility in viewer to do this in command-line using 2 arguments : for example "./viewer input.off output.ply" A set of data is btw available here : http://canaris.u-strasbg.fr/~kenneth/share/DataGeometry/
  Added utility in viewer to export a mesh into all available exported types. Added utility in viewer to do this in command-line using 2 arguments : for example "./viewer input.off output.ply"
  updated comments

Conflicts:
	Apps/Examples/viewer.cpp
	Apps/Examples/viewer.h
parents 1ed2022c cff4e860
...@@ -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,35 +177,12 @@ void Viewer::cb_Open() ...@@ -189,35 +177,12 @@ 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)
{
if (Shift())
{
std::cout << "shift" << std::endl;
m_renderTopo->updateData<PFP>(myMap, position, 0.9, 0.9, allDarts);
Dart d = m_renderTopo->picking<PFP>(myMap, x, y, allDarts);
if (d != Dart::nil())
{
//statusMsg("dart picked");
myMap.mergeFaces(d);
}
else
{
statusMsg("No dart was picked");
}
}
updateGL();
}
...@@ -249,8 +214,6 @@ void Viewer::importMesh(std::string& filename) ...@@ -249,8 +214,6 @@ 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 ;
...@@ -264,41 +227,25 @@ void Viewer::importMesh(std::string& filename) ...@@ -264,41 +227,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 ;
...@@ -308,7 +255,6 @@ void Viewer::slot_drawVertices(bool b) ...@@ -308,7 +255,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() ;
} }
...@@ -354,10 +300,19 @@ int main(int argc, char **argv) ...@@ -354,10 +300,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) ;
......
...@@ -25,26 +25,21 @@ ...@@ -25,26 +25,21 @@
#ifndef __COLOURCONVERTER_H__ #ifndef __COLOURCONVERTER_H__
#define __COLOURCONVERTER_H__ #define __COLOURCONVERTER_H__
#include <iostream>
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Geometry/matrix.h" #include "Geometry/matrix.h"
#include "Utils/cgognStream.h"
// #define DISPLAY
namespace CGoGN { namespace CGoGN {
namespace Utils { namespace Utils {
/** /*!
* Supported colour spaces * \class ColourConverter
*/ * \brief Class for switching between different tri-channel color-spaces
enum ColourEncoding *
{
C_RGB = 0,
C_XYZ = 1,
C_Luv = 2,
C_Lab = 3
} ;
/**
* Class for colour conversions between the enumerated colour spaces. * Class for colour conversions between the enumerated colour spaces.
* Usage : * Usage :
* VEC3 colRGB ; // current colour in RGB for example * VEC3 colRGB ; // current colour in RGB for example
...@@ -56,34 +51,45 @@ enum ColourEncoding ...@@ -56,34 +51,45 @@ enum ColourEncoding
template <typename REAL> template <typename REAL>
class ColourConverter class ColourConverter
{ {
public: // types public: // types
typedef Geom::Vector<3,REAL> VEC3 ; /**
* \enum ColourEncoding
* Supported colour spaces
*/
enum ColourEncoding
{
C_RGB = 0,
C_XYZ = 1,
C_Luv = 2,
C_Lab = 3
} ;
typedef Geom::Vector<3,REAL> VEC3 ; /*!< Triplet for color encoding */
public: // methods public: // methods
/** /**
* Constructor * \brief Constructor
* @param col a VEC3 colour * @param col a VEC3 colour
* @param enc the colour space of provided colour * @param enc the colour space of provided colour
*/ */
ColourConverter(VEC3 col, enum ColourEncoding enc) ; ColourConverter(const VEC3& col, const enum ColourEncoding& enc) ;
/** /**
* Destructor * \brief Destructor
*/ */
~ColourConverter() ; ~ColourConverter() ;
/** /**
* getR * \brief getR
* @return original value (in its original space) * @return original value (in its original space)
*/ */
VEC3 getOriginal() ; VEC3 getOriginal() ;
/** /**
* getR * \brief getR
* @return enc value of provided colour * @return value of provided colour
*/ */
VEC3 getColour(enum ColourEncoding enc) ; VEC3 getColour(enum ColourEncoding enc) ;
/** /**
* getR * \brief getR
* @return RGB value of provided colour * @return RGB value of provided colour
*/ */
VEC3 getRGB() ; VEC3 getRGB() ;
...@@ -104,10 +110,7 @@ public: // methods ...@@ -104,10 +110,7 @@ public: // methods
VEC3 getXYZ() ; VEC3 getXYZ() ;
public: // members public: // members
/** enum ColourEncoding originalEnc ; /*!< Colour space of original (unaltered) data */
* Colour space of original (unaltered) data
*/
enum ColourEncoding originalEnc ;
private: // private members private: // private members
VEC3 *RGB ; VEC3 *RGB ;
...@@ -126,7 +129,6 @@ private: // private members ...@@ -126,7 +129,6 @@ private: // private members
void convertLabToXYZ() ; void convertLabToXYZ() ;
private: // private constants private: // private constants
// D65 reference white // D65 reference white
static const REAL Xn = 0.950456 ; static const REAL Xn = 0.950456 ;
static const REAL Yn = 1.0 ; static const REAL Yn = 1.0 ;
......
...@@ -23,10 +23,11 @@ ...@@ -23,10 +23,11 @@
*******************************************************************************/ *******************************************************************************/
namespace CGoGN { namespace CGoGN {
namespace Utils { namespace Utils {
template<typename REAL> template<typename REAL>
ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) : ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) :
RGB(NULL), RGB(NULL),
Luv(NULL), Luv(NULL),
Lab(NULL), Lab(NULL),
...@@ -36,26 +37,34 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) : ...@@ -36,26 +37,34 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) :
switch(originalEnc) { switch(originalEnc) {
case(C_RGB): case(C_RGB):
#ifdef DEBUG
if (!(-0.001 < col[0] && col[0] < 1.001 && -0.001 < col[1] && col[1] < 1.001 && -0.001 < col[2] && col[2] < 1.001)) if (!(-0.001 < col[0] && col[0] < 1.001 && -0.001 < col[1] && col[1] < 1.001 && -0.001 < col[2] && col[2] < 1.001))
CGoGNerr << "Warning : an unvalid RGB color was entered in ColourConverter constructor" << CGoGNendl ; std::cerr << "Warning : an unvalid RGB color was entered in ColourConverter constructor" << std::endl ;
#endif
RGB = new VEC3(col) ; RGB = new VEC3(col) ;
break ; break ;
case (C_Luv) : case (C_Luv) :
#ifdef DEBUG
if (!(-0.001 < col[0] && col[0] < 100.001 && -83.001 < col[1] && col[1] < 175.001 && -134.001 < col[2] && col[2] < 108.001)) if (!(-0.001 < col[0] && col[0] < 100.001 && -83.001 < col[1] && col[1] < 175.001 && -134.001 < col[2] && col[2] < 108.001))
CGoGNerr << "Warning : an unvalid Luv color was entered in ColourConverter constructor" << CGoGNendl ; std::cerr << "Warning : an unvalid Luv color was entered in ColourConverter constructor" << std::endl ;
#endif
Luv = new VEC3(col) ; Luv = new VEC3(col) ;
break ; break ;
case (C_XYZ) : case (C_XYZ) :
#ifdef DEBUG
if (!(-0.001 < col[0] && col[0] < 1.001 && -0.001 < col[1] && col[1] < 1.001 && -0.001 < col[2] && col[2] < 1.001)) if (!(-0.001 < col[0] && col[0] < 1.001 && -0.001 < col[1] && col[1] < 1.001 && -0.001 < col[2] && col[2] < 1.001))
CGoGNerr << "Warning : an unvalid XYZ color was entered in ColourConverter constructor" << CGoGNendl ; std::cerr << "Warning : an unvalid XYZ color was entered in ColourConverter constructor" << std::endl ;
#endif
XYZ = new VEC3(col) ; XYZ = new VEC3(col) ;
break ; break ;
case (C_Lab) : case (C_Lab) :
#ifdef DEBUG
if (!(-0.001 < col[0] && col[0] < 100.001 && -86.001 < col[1] && col[1] < 98.001 && -108.001 < col[2] && col[2] < 95.001)) if (!(-0.001 < col[0] && col[0] < 100.001 && -86.001 < col[1] && col[1] < 98.001 && -108.001 < col[2] && col[2] < 95.001))
CGoGNerr << "Warning : an unvalid Lab color was entered in ColourConverter constructor" << CGoGNendl ; std::cerr << "Warning : an unvalid Lab color was entered in ColourConverter constructor" << std::endl ;
#endif
Lab = new VEC3(col) ; Lab = new VEC3(col) ;
break ; break ;
} }
...@@ -281,8 +290,10 @@ void ColourConverter<REAL>::convertLabToXYZ() { ...@@ -281,8 +290,10 @@ void ColourConverter<REAL>::convertLabToXYZ() {
template<typename REAL> template<typename REAL>
bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncoding to) { bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncoding to) {
if (to == from) { if (to == from) {
CGoGNerr << "ColourConverter::convert(from,to) : conversion into same colour space" << CGoGNendl ; #ifdef DEBUG
return false ; std::cout << "WARNING ColourConverter::convert(from,to) : conversion into same colour space" << std::endl ;
#endif
return true ;
} }
switch(from) { switch(from) {
...@@ -305,7 +316,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin ...@@ -305,7 +316,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab() ; convertXYZtoLab() ;
break ; break ;
default : default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ; std::cerr << "Colour conversion not supported" << std::endl ;
return false ; return false ;
} }
break ; break ;
...@@ -333,7 +344,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin ...@@ -333,7 +344,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
} }
break ; break ;
default : default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ; std::cerr << "Colour conversion not supported" << std::endl ;
return false ; return false ;
} }
break ; break ;
...@@ -353,7 +364,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin ...@@ -353,7 +364,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab() ; convertXYZtoLab() ;
break ; break ;
default : default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ; std::cerr << "Colour conversion not supported" << std::endl ;
return false ; return false ;
} }
break ; break ;
...@@ -381,22 +392,21 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin ...@@ -381,22 +392,21 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
} }
break ; break ;
default : default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ; std::cerr << "Colour conversion not supported" << std::endl ;
return false ; return false ;
} }
break ; break ;
default : default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ; std::cerr << "Colour conversion not supported" << std::endl ;
return false ; return false ;
} }