Commit 6a6f5c35 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~thery/CGoGN

parents 6fc984cb bcbfbd82
...@@ -255,6 +255,7 @@ void Viewer::importMesh(std::string& filename) ...@@ -255,6 +255,7 @@ void Viewer::importMesh(std::string& filename)
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") ;
......
...@@ -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>
......
...@@ -42,6 +42,8 @@ protected: ...@@ -42,6 +42,8 @@ protected:
public: public:
Map2MR_Primal() ; Map2MR_Primal() ;
std::string mapTypeName() { return "Map2MR_Primal";}
/*************************************************** /***************************************************
* CELLS INFORMATION * * CELLS INFORMATION *
***************************************************/ ***************************************************/
......
...@@ -322,6 +322,21 @@ Dart Topo3Render::colToDart(float* color) ...@@ -322,6 +322,21 @@ Dart Topo3Render::colToDart(float* color)
} }
void Topo3Render::dartToCol(Dart d, float& r, float& g, float& b)
{
// here use dart.index beacause it is what we want (and not map.dartIndex(d) !!)
unsigned int lab = d.index + 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;
}
Dart Topo3Render::pickColor(unsigned int x, unsigned int y) Dart Topo3Render::pickColor(unsigned int x, unsigned int y)
{ {
//more easy picking for //more easy picking for
......
...@@ -215,6 +215,19 @@ Dart TopoRender::colToDart(float* color) ...@@ -215,6 +215,19 @@ Dart TopoRender::colToDart(float* color)
} }
void TopoRender::dartToCol(Dart d, float& r, float& g, float& b)
{
// here use d.index beacause it is what we want (and not map.dartIndex(d) !!)
unsigned int lab = d.index + 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;
}
Dart TopoRender::pickColor(unsigned int x, unsigned int y) Dart TopoRender::pickColor(unsigned int x, unsigned int y)
{ {
......
...@@ -173,6 +173,8 @@ void GenericMap::initMR() ...@@ -173,6 +173,8 @@ void GenericMap::initMR()
#endif #endif
m_mrattribs.clear(true) ; m_mrattribs.clear(true) ;
m_mrattribs.setRegistry(m_attributes_registry_map) ;
m_mrDarts.clear() ; m_mrDarts.clear() ;
m_mrDarts.reserve(16) ; m_mrDarts.reserve(16) ;
m_mrNbDarts.clear(); m_mrNbDarts.clear();
...@@ -457,8 +459,16 @@ bool GenericMap::saveMapBin(const std::string& filename) ...@@ -457,8 +459,16 @@ bool GenericMap::saveMapBin(const std::string& filename)
m_attribs[i].saveBin(fs, i); m_attribs[i].saveBin(fs, i);
if (m_isMultiRes) if (m_isMultiRes)
{
m_mrattribs.saveBin(fs, 00); m_mrattribs.saveBin(fs, 00);
fs.write(reinterpret_cast<const char*>(&m_mrCurrentLevel), sizeof(unsigned int));
unsigned int nb = m_mrNbDarts.size();
fs.write(reinterpret_cast<const char*>(&nb), sizeof(unsigned int));
fs.write(reinterpret_cast<const char*>(&(m_mrNbDarts[0])), nb *sizeof(unsigned int));
}
return true; return true;
} }
...@@ -538,16 +548,24 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -538,16 +548,24 @@ bool GenericMap::loadMapBin(const std::string& filename)
} }
if (m_isMultiRes) if (m_isMultiRes)
{
AttributeContainer::loadBinId(fs); // not used but need to read to skip
m_mrattribs.loadBin(fs); m_mrattribs.loadBin(fs);
fs.read(reinterpret_cast<char*>(&m_mrCurrentLevel), sizeof(unsigned int));
unsigned int nb;
fs.read(reinterpret_cast<char*>(&nb), sizeof(unsigned int));
m_mrNbDarts.resize(nb);
fs.read(reinterpret_cast<char*>(&(m_mrNbDarts[0])), nb *sizeof(unsigned int));
}
// retrieve m_embeddings (from m_attribs) // retrieve m_embeddings (from m_attribs)
update_m_emb_afterLoad(); update_m_emb_afterLoad();
// recursive call from real type of map (for topo relation attributes pointers) down to GenericMap (for Marker_cleaning & pointers) // recursive call from real type of map (for topo relation attributes pointers) down to GenericMap (for Marker_cleaning & pointers)
update_topo_shortcuts(); update_topo_shortcuts();
return true; return true;
} }
......
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