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 @@
Viewer::Viewer() :
m_renderStyle(FLAT),
m_drawTopo(true),
m_drawVertices(false),
m_drawEdges(false),
m_drawFaces(true),
m_drawNormals(false),
m_render(NULL),
m_renderTopo(NULL),
m_phongShader(NULL),
m_flatShader(NULL),
m_vectorShader(NULL),
m_simpleColorShader(NULL),
m_pointSprite(NULL),
m_strings(NULL)
m_pointSprite(NULL)
{
normalScaleFactor = 1.0f ;
vertexScaleFactor = 0.1f ;
......@@ -82,7 +79,6 @@ void Viewer::cb_initGL()
setFocal(5.0f) ;
m_render = new Algo::Render::GL2::MapRender() ;
m_renderTopo = new Algo::Render::GL2::TopoRender();
m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ;
......@@ -114,16 +110,11 @@ void Viewer::cb_initGL()
m_pointSprite = new Utils::PointSprite() ;
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_flatShader) ;
registerShader(m_vectorShader) ;
registerShader(m_simpleColorShader) ;
registerShader(m_pointSprite) ;
registerShader(m_strings);
}
void Viewer::cb_redraw()
......@@ -136,7 +127,6 @@ void Viewer::cb_redraw()
m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
m_pointSprite->postdraw() ;
m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f));
}
if(m_drawEdges)
......@@ -172,8 +162,6 @@ void Viewer::cb_redraw()
glDisable(GL_POLYGON_OFFSET_FILL) ;
}
if(m_drawTopo)
m_renderTopo->drawTopo();
}
void Viewer::cb_Open()
......@@ -189,35 +177,12 @@ void Viewer::cb_Open()
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) ;
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)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
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) ;
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize /5.0f ;
......@@ -264,41 +227,25 @@ void Viewer::importMesh(std::string& filename)
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
storeVerticesInfo();
m_strings->sendToVBO();
setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ;
}
void Viewer::exportMesh(std::string& filename)
{
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
size_t pos = filename.rfind(".") ; // position of "." in filename
std::string extension = filename.substr(pos) ;
if (extension == std::string(".map"))
myMap.saveMapBin(filename);
else
if (extension == std::string(".off"))
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)
{
m_drawVertices = b ;
......@@ -308,7 +255,6 @@ void Viewer::slot_drawVertices(bool b)
void Viewer::slot_verticesSize(int i)
{
vertexScaleFactor = i / 500.0f ;
m_strings->setScale(0.02f*i);
updateGL() ;
}
......@@ -354,10 +300,19 @@ int main(int argc, char **argv)
sqt.setGeometry(0, 0, 1000, 800) ;
sqt.show() ;
if(argc == 2)
if(argc >= 2)
{
std::string filename(argv[1]) ;
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() ;
......
......@@ -86,7 +86,7 @@ public:
float faceShrinkage ;
int m_renderStyle ;
bool m_drawTopo;
// bool m_drawTopo;
bool m_drawVertices ;
bool m_drawEdges ;
bool m_drawFaces ;
......@@ -96,7 +96,6 @@ public:
PFP::TVEC3 normal ;
Algo::Render::GL2::MapRender* m_render ;
Algo::Render::GL2::TopoRender* m_renderTopo ;
Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO ;
......@@ -106,7 +105,6 @@ public:
Utils::ShaderVectorPerVertex* m_vectorShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ;
Utils::PointSprite* m_pointSprite ;
Utils::Strings3D* m_strings;
Viewer() ;
......@@ -117,14 +115,9 @@ public:
void cb_Open() ;
void cb_Save() ;
void cb_mousePress(int button, int x, int y);
void importMesh(std::string& filename) ;
void exportMesh(std::string& filename);
protected:
void storeVerticesInfo();
public slots:
void slot_drawVertices(bool b) ;
......
......@@ -25,26 +25,21 @@
#ifndef __COLOURCONVERTER_H__
#define __COLOURCONVERTER_H__
#include <iostream>
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Utils/cgognStream.h"
// #define DISPLAY
namespace CGoGN {
namespace Utils {
/**
* Supported colour spaces
*/
enum ColourEncoding
{
C_RGB = 0,
C_XYZ = 1,
C_Luv = 2,
C_Lab = 3
} ;
/**
/*!
* \class ColourConverter
* \brief Class for switching between different tri-channel color-spaces
*
* Class for colour conversions between the enumerated colour spaces.
* Usage :
* VEC3 colRGB ; // current colour in RGB for example
......@@ -56,34 +51,45 @@ enum ColourEncoding
template <typename REAL>
class ColourConverter
{
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
/**
* Constructor
* \brief Constructor
* @param col a VEC3 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() ;
/**
* getR
* \brief getR
* @return original value (in its original space)
*/
VEC3 getOriginal() ;
/**
* getR
* @return enc value of provided colour
* \brief getR
* @return value of provided colour
*/
VEC3 getColour(enum ColourEncoding enc) ;
/**
* getR
* \brief getR
* @return RGB value of provided colour
*/
VEC3 getRGB() ;
......@@ -104,10 +110,7 @@ public: // methods
VEC3 getXYZ() ;
public: // members
/**
* Colour space of original (unaltered) data
*/
enum ColourEncoding originalEnc ;
enum ColourEncoding originalEnc ; /*!< Colour space of original (unaltered) data */
private: // private members
VEC3 *RGB ;
......@@ -126,7 +129,6 @@ private: // private members
void convertLabToXYZ() ;
private: // private constants
// D65 reference white
static const REAL Xn = 0.950456 ;
static const REAL Yn = 1.0 ;
......
......@@ -23,10 +23,11 @@
*******************************************************************************/
namespace CGoGN {
namespace Utils {
template<typename REAL>
ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) :
ColourConverter<REAL>::ColourConverter(const VEC3& col, const enum ColourEncoding& enc) :
RGB(NULL),
Luv(NULL),
Lab(NULL),
......@@ -36,26 +37,34 @@ ColourConverter<REAL>::ColourConverter(VEC3 col, enum ColourEncoding enc) :
switch(originalEnc) {
case(C_RGB):
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 ;
#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))
std::cerr << "Warning : an unvalid RGB color was entered in ColourConverter constructor" << std::endl ;
#endif
RGB = new VEC3(col) ;
break ;
case (C_Luv) :
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 ;
#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))
std::cerr << "Warning : an unvalid Luv color was entered in ColourConverter constructor" << std::endl ;
#endif
Luv = new VEC3(col) ;
break ;
case (C_XYZ) :
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 ;
#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))
std::cerr << "Warning : an unvalid XYZ color was entered in ColourConverter constructor" << std::endl ;
#endif
XYZ = new VEC3(col) ;
break ;
case (C_Lab) :
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 ;
#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))
std::cerr << "Warning : an unvalid Lab color was entered in ColourConverter constructor" << std::endl ;
#endif
Lab = new VEC3(col) ;
break ;
}
......@@ -281,8 +290,10 @@ void ColourConverter<REAL>::convertLabToXYZ() {
template<typename REAL>
bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncoding to) {
if (to == from) {
CGoGNerr << "ColourConverter::convert(from,to) : conversion into same colour space" << CGoGNendl ;
return false ;
#ifdef DEBUG
std::cout << "WARNING ColourConverter::convert(from,to) : conversion into same colour space" << std::endl ;
#endif
return true ;
}
switch(from) {
......@@ -305,7 +316,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab() ;
break ;
default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ;
std::cerr << "Colour conversion not supported" << std::endl ;
return false ;
}
break ;
......@@ -333,7 +344,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
}
break ;
default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ;
std::cerr << "Colour conversion not supported" << std::endl ;
return false ;
}
break ;
......@@ -353,7 +364,7 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
convertXYZtoLab() ;
break ;
default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ;
std::cerr << "Colour conversion not supported" << std::endl ;
return false ;
}
break ;
......@@ -381,22 +392,21 @@ bool ColourConverter<REAL>::convert(enum ColourEncoding from, enum ColourEncodin
}
break ;
default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ;
std::cerr << "Colour conversion not supported" << std::endl ;
return false ;
}
break ;
default :
CGoGNerr << "Colour conversion not supported" << CGoGNendl ;
std::cerr << "Colour conversion not supported" << std::endl ;
return false ;
}
return true ;
}
} // namespace Utils
} // namespace CGoGN
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