Commit 5f038b96 authored by untereiner's avatar untereiner

Merge cgogn:~cgogn/CGoGN

Conflicts:
	Apps/Examples/viewer.cpp
parents a1cda248 8924e290
......@@ -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,10 +177,10 @@ 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)
......@@ -218,8 +206,6 @@ void Viewer::cb_mousePress(int button, int x, int y)
updateGL();
}
void Viewer::importMesh(std::string& filename)
{
myMap.clear(true) ;
......@@ -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::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 ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX, "normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
......@@ -262,41 +247,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 ;
......@@ -306,7 +275,6 @@ void Viewer::slot_drawVertices(bool b)
void Viewer::slot_verticesSize(int i)
{
vertexScaleFactor = i / 500.0f ;
m_strings->setScale(0.02f*i);
updateGL() ;
}
......@@ -352,10 +320,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) ;
......
......@@ -181,6 +181,7 @@ void MyQT::traverse2()
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f);
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);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d);
......
......@@ -255,11 +255,15 @@ public:
Dart picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good=allDarts);
/**
* compute dart from color (for picking)
*/
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
}
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>
void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good)
......@@ -281,7 +268,7 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g
if (nb < m_nbDarts)
{
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
*local++ = r;
......
......@@ -115,18 +115,35 @@ protected:
Utils::ShaderColorPerVertex* m_shader2;
/**
* compute color from dart index (for color picking)
*/
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);
/**
* affect a color to each dart
*/
template<typename PFP>
void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good);
/**
* save colors before picking
*/
void pushColors();
/**
* restore colors after picking
*/
void popColors();
public:
......
......@@ -67,10 +67,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
std::vector<Dart> vecDarts;
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");
}
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
std::vector<Dart> vecDarts;
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");
}
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
}
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>
......@@ -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));
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))
{
if (good(d))
......@@ -389,7 +383,7 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go
if (nb < m_nbDarts)
{
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
*local++ = r;
*local++ = g;
......
......@@ -26,6 +26,7 @@
#define __GENERIC_MAP__
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
......@@ -165,7 +166,7 @@ public:
MarkSet& getMarkerSet(unsigned int orbit, unsigned int thread) { return m_marksets[orbit][thread]; }
/****************************************
* MULTIRES *
* RESOLUTION LEVELS MANAGEMENT *
****************************************/
void printMR() ;
......@@ -234,12 +235,20 @@ protected:
*/
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) ;
unsigned int newCopyOfDartLine(unsigned int index) ;
public:
/**
......
......@@ -44,7 +44,7 @@ inline void GenericMap::setCurrentLevel(unsigned int l)
inline void GenericMap::incCurrentLevel()
{
if(m_mrCurrentLevel < m_mrDarts.size())
if(m_mrCurrentLevel < m_mrDarts.size() - 1)
++m_mrCurrentLevel ;
else
CGoGNout << "incCurrentLevel : already at maximum resolution level" << CGoGNendl ;
......@@ -80,26 +80,24 @@ inline unsigned int GenericMap::getMaxLevel()
inline Dart GenericMap::newDart()
{
unsigned int di = m_attribs[DART].insertLine();
unsigned int di = m_attribs[DART].insertLine(); // insert a new dart line
for(unsigned int i = 0; i < NB_ORBITS; ++i)
{
if (m_embeddings[i])
(*m_embeddings[i])[di] = EMBNULL ;
if (m_embeddings[i]) // set all its embeddings
(*m_embeddings[i])[di] = EMBNULL ; // to EMBNULL
}
if (m_isMultiRes)
{
unsigned int mrdi = m_mrattribs.insertLine() ;
(*m_mrLevels)[mrdi] = m_mrCurrentLevel ;
unsigned int mrdi = m_mrattribs.insertLine() ; // insert a new MRdart line
(*m_mrLevels)[mrdi] = m_mrCurrentLevel ; // set the introduction level of the dart
m_mrNbDarts[m_mrCurrentLevel]++ ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i)
(*m_mrDarts[i])[mrdi] = MRNULL ;
for(unsigned int i = 0; i < m_mrCurrentLevel; ++i) // for all previous levels
(*m_mrDarts[i])[mrdi] = MRNULL ; // this MRdart does not exist
(*m_mrDarts[m_mrCurrentLevel])[mrdi] = di ;
for(unsigned int i = m_mrCurrentLevel + 1; i < m_mrDarts.size(); ++i)
(*m_mrDarts[i])[mrdi] = newCopyOfDartLine(di) ;
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i) // for all levels from current to max
(*m_mrDarts[i])[mrdi] = di ; // make this MRdart points to the new dart line
return Dart::create(mrdi) ;
}
......@@ -114,10 +112,12 @@ inline void GenericMap::deleteDart(Dart d)
// a MRdart can only be deleted on its insertion level
assert(getDartLevel(d) == m_mrCurrentLevel || !"deleteDart : try to delete a dart on a level greater than its insertion level") ;
// all the darts pointed in greater levels are deleted
// and then the MRdart is deleted
for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i)
deleteDartLine((*m_mrDarts[i])[d.index]) ;
{
unsigned int index = (*m_mrDarts[i])[d.index] ;
if(isDartValid(index))
deleteDartLine(index) ;
}
m_mrattribs.removeLine(d.index) ;
m_mrNbDarts[m_mrCurrentLevel]-- ;
}
......@@ -149,18 +149,44 @@ inline void GenericMap::deleteDartLine(unsigned int index)
}
}
inline unsigned int GenericMap::newCopyOfDartLine(unsigned int index)
inline unsigned int GenericMap::copyDartLine(unsigned int index)
{
unsigned int newindex = m_attribs[DART].insertLine() ; // create a new dart line
m_attribs[DART].copyLine(newindex, index) ; // copy the given dart line
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if (m_embeddings[orbit]) // put the embeddings of the
(*m_embeddings[orbit])[newindex] = EMBNULL ; // new line to EMBNULL
if (m_embeddings[orbit])
// (*m_embeddings[orbit])[newindex] = EMBNULL ;
{
unsigned int emb = (*m_embeddings[orbit])[newindex] ; // add a ref to the cells pointed
if(emb != EMBNULL) // by the new dart line
m_attribs[orbit].refLine(emb) ;
}
}
return newindex ;
}
inline void GenericMap::duplicateDart(Dart d)
{
assert(getDartLevel(d) <= getCurrentLevel() || !"duplicateDart : called with a dart inserted after current level") ;
if(getDartLevel(d) == getCurrentLevel()) // no need to duplicate
return ; // a dart from its insertion level
unsigned int oldindex = dartIndex(d) ;
if((*m_mrDarts[m_mrCurrentLevel - 1])[d.index] != oldindex) // no need to duplicate if the dart is already
return ; // duplicated with respect to previous level
unsigned int newindex = copyDartLine(oldindex) ;
for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i) // for all levels from current to max
{
assert((*m_mrDarts[i])[d.index] == oldindex || !"duplicateDart : dart was already duplicated on a greater level") ;
(*m_mrDarts[i])[d.index] = newindex ; // make this MRdart points to the new dart line
}
}
inline unsigned int GenericMap::dartIndex(Dart d)
{
if (m_isMultiRes)
......
......@@ -29,6 +29,7 @@
namespace CGoGN
{
/*******************************************************************************
GENERIC TRAVERSALS FACTORY
*******************************************************************************/
......@@ -38,20 +39,18 @@ class Traversor2
{
public:
virtual ~Traversor2() {}
virtual Dart begin() =0;
virtual Dart end() =0;
virtual Dart next() =0;
virtual Dart begin() = 0;
virtual Dart end() = 0;
virtual Dart next() = 0;
static Traversor2<MAP>* createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY);
static Traversor2<MAP>* createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY);
};
/*******************************************************************************
VERTEX CENTERED TRAVERSALS
*******************************************************************************/
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor2VE : public Traversor2<MAP>
......@@ -228,7 +227,6 @@ public:
Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
} ;
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV : public Traversor2<MAP>
......
......@@ -472,6 +472,7 @@ Traversor2<MAP>* Traversor2<MAP>::createIncident(MAP& map, Dart dart, unsigned i
return new Traversor2EV<MAP>(map,dart);
break;
case 0x0102:
return new Traversor2EF<MAP>(map,dart);
break;
case 0x0200:
return new Traversor2FV<MAP>(map,dart);
......
This diff is collapsed.
......@@ -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
/**