Commit d4159fab authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~thery/CGoGN

Conflicts:
	include/Topology/generic/genericmap.h
parents 85cd31be 9ea67fa3
This diff is collapsed.
......@@ -90,22 +90,22 @@ class MyQT: public Utils::QT::SimpleQT
bool m_showTopo;
unsigned int m_val_combo1;
unsigned int m_val_combo2;
unsigned int m_val_combo3;
unsigned int m_val_combo4;
unsigned int m_val_combo5;
unsigned int m_val_combo6;
unsigned int m_first3;
unsigned int m_ajd_or_inci3;
unsigned int m_second3;
unsigned int m_first2;
unsigned int m_ajd_or_inci2;
unsigned int m_second2;
public:
MyQT():
m_render_topo(NULL),
m_showTopo(true),
m_val_combo1(1),
m_val_combo2(1),
m_val_combo3(2),
m_val_combo4(1),
m_val_combo5(1),
m_val_combo6(2),
m_first3(0),
m_ajd_or_inci3(0),
m_second3(1),
m_first2(0),
m_ajd_or_inci2(0),
m_second2(1),
m_selected(NIL)
{}
......
......@@ -33,6 +33,31 @@ namespace Algo
{
namespace Render
{
/**
* add a cell to a drawer
* @param the cell (VERTEX,EDGE,...)
* * @param dr the drawer to use
* @param map the map
* @param d the dart
* @param positions attribute of positions
* @param k shrinking factor
*/
template<typename PFP>
void drawerCells(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const typename PFP::TVEC3& positions);
/**
* add a set of volumes to a drawer
* @param the cell (VERTEX,EDGE,...)
* @param dr the drawer to use
* @param map the map
* @param vd the darts
* @param positions attribute of positions
* @param k shrinking factor
*/
template<typename PFP>
void drawerCell(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& positions);
/**
* add a set of vertices to a drawer
......@@ -87,7 +112,6 @@ void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>&
* @param map the map
* @param d the dart
* @param positions attribute of positions
* @param k shrinking factor
*/
template<typename PFP>
void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& positions);
......
......@@ -145,6 +145,51 @@ void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const typen
drawerAddVolume<PFP>(dr,map,d,positions,k);
dr.end();
}
template<typename PFP>
void drawerCells(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const typename PFP::TVEC3& positions, float k)
{
switch(cell)
{
case VERTEX:
drawerVertices<PFP>(dr, map, vd, positions);
break;
case EDGE:
drawerEdges<PFP>(dr, map, vd, positions,k);
break;
case FACE:
drawerFaces<PFP>(dr, map, vd, positions,k);
break;
case VOLUME:
drawerVolumes<PFP>(dr, map, vd, positions,k);
break;
default:
break;
}
}
template<typename PFP>
void drawerCell(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& positions, float k)
{
switch(cell)
{
case VERTEX:
drawerVertex<PFP>(dr, map, d, positions);
break;
case EDGE:
drawerEdge<PFP>(dr, map, d, positions,k);
break;
case FACE:
drawerFace<PFP>(dr, map, d, positions,k);
break;
case VOLUME:
drawerVolume<PFP>(dr, map, d, positions,k);
break;
default:
break;
}
}
}
}
......
......@@ -112,13 +112,29 @@ protected:
static const bool m_isMultiRes = false ;
#endif
/**
* container for mr-darts that store indices in attribs[DART] for each level
*/
AttributeContainer m_mrattribs ;
/**
* pointer to indices mvectors (one for each level)
*/
std::vector< AttributeMultiVector<unsigned int>* > m_mrDarts ;
/**
* pointers to mvector of levels
*/
AttributeMultiVector<unsigned char>* m_mrLevels ;
/**
* current level of multiresoltion
*/
unsigned int m_mrCurrentLevel ;
/**
* stack for current level temporary storage
*/
std::vector<unsigned int> m_mrLevelStack ;
public:
......@@ -147,18 +163,39 @@ public:
* MULTIRES *
****************************************/
/**
* get the current level of multi-resolution (use only in MRMaps)
*/
unsigned int getCurrentLevel() ;
/**
* set the current level of multi-resolution (use only in MRMaps)
*/
void setCurrentLevel(unsigned int l) ;
/**
* store current level of multi-resolution on a stack (use only in MRMaps)
*/
void pushLevel() ;
/**
* get back level of multi-resolution of the stack in current (use only in MRMaps)
*/
void popLevel() ;
/**
* get the max level of multi-resolution (use only in MRMaps)
*/
unsigned int getMaxLevel() ;
/**
* add a level of multi-resolution (use only in MRMaps)
*/
void addLevel() ;
/**
* get the insertion level of a dart (use only in MRMaps)
*/
unsigned int getDartLevel(Dart d) ;
/****************************************
......
......@@ -65,19 +65,6 @@ inline unsigned int GenericMap::getMaxLevel()
return m_mrDarts.size() - 1 ;
}
inline void GenericMap::addLevel()
{
unsigned int level = m_mrDarts.size() ;
std::stringstream ss ;
ss << "MRdart_"<< level ;
AttributeMultiVector<unsigned int>* amvMR = m_mrattribs.addAttribute<unsigned int>(ss.str()) ;
m_mrDarts.push_back(amvMR) ;
// copy the darts pointers of the previous level
if(m_mrDarts.size() > 1)
m_mrattribs.copyAttribute(amvMR->getIndex(), m_mrDarts[m_mrDarts.size() - 2]->getIndex()) ;
}
inline unsigned int GenericMap::getDartLevel(Dart d)
{
return m_mrLevels->operator [](d.index) ;
......@@ -310,4 +297,42 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ;
}
/******************************************
* TOPOLOGICAL MULTIRESOLUTION MANAGEMENT*
******************************************/
inline unsigned int GenericMap::getCurrentLevel()
{
return m_mrCurrentLevel ;
}
inline void GenericMap::setCurrentLevel(unsigned int l)
{
if (l < m_mrDarts.size())
m_mrCurrentLevel = l ;
else
CGoGNout << "try to access inexisting resolution level" << CGoGNendl ;
}
inline void GenericMap::pushLevel()
{
m_mrLevelStack.push_back(m_mrCurrentLevel) ;
}
inline void GenericMap::popLevel()
{
m_mrCurrentLevel = m_mrLevelStack.back() ;
m_mrLevelStack.pop_back() ;
}
inline unsigned int GenericMap::getMaxLevel()
{
return m_mrDarts.size() - 1 ;
}
} //namespace CGoGN
......@@ -29,14 +29,32 @@
namespace CGoGN
{
/*******************************************************************************
GENERIC TRAVERSALS FACTORY
*******************************************************************************/
template <typename MAP>
class Traversor2
{
public:
virtual ~Traversor2() {}
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
class Traversor2VE : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -53,7 +71,7 @@ public:
// Traverse the faces incident to a given vertex
template <typename MAP>
class Traversor2VF
class Traversor2VF : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -70,7 +88,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
class Traversor2VVaE
class Traversor2VVaE : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -87,7 +105,7 @@ public:
// Traverse the vertices adjacent to a given vertex through sharing a common face
template <typename MAP>
class Traversor2VVaF
class Traversor2VVaF : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -110,7 +128,7 @@ public:
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor2EV
class Traversor2EV : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -127,7 +145,7 @@ public:
// Traverse the faces incident to a given edge
template <typename MAP>
class Traversor2EF
class Traversor2EF : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -144,7 +162,7 @@ public:
// Traverse the edges adjacent to a given edge through sharing a common vertex
template <typename MAP>
class Traversor2EEaV
class Traversor2EEaV : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -163,7 +181,7 @@ public:
// Traverse the edges adjacent to a given edge through sharing a common face
template <typename MAP>
class Traversor2EEaF
class Traversor2EEaF : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -186,7 +204,7 @@ public:
// Traverse the vertices incident to a given face
template <typename MAP>
class Traversor2FV
class Traversor2FV : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -204,7 +222,7 @@ public:
// Traverse the edges incident to a given face (equivalent to vertices)
template <typename MAP>
class Traversor2FE : public Traversor2FV<MAP>
class Traversor2FE: public Traversor2FV<MAP>
{
public:
Traversor2FE(MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
......@@ -213,7 +231,7 @@ public:
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV
class Traversor2FFaV : public Traversor2<MAP>
{
private:
MAP& m ;
......@@ -232,7 +250,7 @@ public:
// Traverse the faces adjacent to a given face through sharing a common edge
template <typename MAP>
class Traversor2FFaE
class Traversor2FFaE : public Traversor2<MAP>
{
private:
MAP& m ;
......
......@@ -453,4 +453,75 @@ Dart Traversor2FFaE<MAP>::next()
return current ;
}
template<typename MAP>
Traversor2<MAP>* Traversor2<MAP>::createIncident(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
{
int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
switch(code)
{
case 0x0001:
return new Traversor2VE<MAP>(map,dart);
break;
case 0x0002:
return new Traversor2VF<MAP>(map,dart);
break;
case 0x0100:
return new Traversor2EV<MAP>(map,dart);
break;
case 0x0102:
break;
case 0x0200:
return new Traversor2FV<MAP>(map,dart);
break;
case 0x0201:
return new Traversor2FE<MAP>(map,dart);
break;
default:
return NULL;
break;
}
return NULL;
}
template<typename MAP>
Traversor2<MAP>* Traversor2<MAP>::createAdjacent(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY)
{
int code = 0x100*(orbX-VERTEX) + orbY-VERTEX;
switch(code)
{
case 0x0001:
return new Traversor2VVaE<MAP>(map,dart);
break;
case 0x0002:
return new Traversor2VVaF<MAP>(map,dart);
break;
case 0x0100:
return new Traversor2EEaV<MAP>(map,dart);
break;
case 0x0102:
return new Traversor2EEaF<MAP>(map,dart);
break;
case 0x0200:
return new Traversor2FFaV<MAP>(map,dart);
break;
case 0x0201:
return new Traversor2FFaE<MAP>(map,dart);
break;
default:
return NULL;
break;
}
return NULL;
}
} // namespace CGoGN
......@@ -101,7 +101,6 @@ DartMarkerStore* MarkerForTraversor<MAP>::dmark()
template <typename MAP>
Traversor3XY<MAP>::Traversor3XY(MAP& map, Dart dart, unsigned int orbX, unsigned int orbY, bool forceDartMarker, unsigned int thread) :
// Traversor3MarkOnly<MAP,ORBIT_Y>(map, forceDartMarker, thread, true),
m_map(map),
m_dmark(NULL),
m_cmark(NULL),
......
......@@ -73,7 +73,7 @@ public:
/// start the chrono
inline void start() { gettimeofday(&m_start, NULL) ; }
/// return elapsed time since start (cumulative if several calls)
/// return elapsed time since start in ms (cumulative if several calls)
inline int elapsed()
{
gettimeofday(&m_end, NULL) ;
......
......@@ -152,6 +152,34 @@ void GenericMap::clear(bool removeAttrib)
m_attribs[i].clear(false) ;
}
}
if (m_isMultiRes)
{
m_mrattribs.clear(true);
m_mrLevels = NULL;
unsigned int nb = m_mrDarts.size();
for (unsigned int i = 0; i<nb; ++i)
m_mrDarts[i]=NULL;
m_mrCurrentLevel=0;
m_mrLevelStack.clear();
}
}
/****************************************
* MULTIRES *
****************************************/
void GenericMap::addLevel()
{
unsigned int level = m_mrDarts.size() ;
std::stringstream ss ;
ss << "MRdart_"<< level ;
AttributeMultiVector<unsigned int>* amvMR = m_mrattribs.addAttribute<unsigned int>(ss.str()) ;
m_mrDarts.push_back(amvMR) ;
// copy the darts pointers of the previous level
if(m_mrDarts.size() > 1)
m_mrattribs.copyAttribute(amvMR->getIndex(), m_mrDarts[m_mrDarts.size() - 2]->getIndex()) ;
}
/****************************************
......@@ -332,8 +360,16 @@ bool GenericMap::saveMapBin(const std::string& filename)
char* buff = new char[256];
for (int i = 0; i < 256; ++i)
buff[i] = char(255);
const char* cgogn = "CGoGN_Map";
memcpy(buff, cgogn, 10);
if (m_isMultiRes)
{
const char* cgogn = "CGoGN_MRMap";
memcpy(buff, cgogn, 12);
}
else
{
const char* cgogn = "CGoGN_Map";
memcpy(buff, cgogn, 10);
}
std::string mt = mapTypeName();
const char* mtc = mt.c_str();
memcpy(buff+32, mtc, mt.size()+1);
......@@ -346,6 +382,9 @@ bool GenericMap::saveMapBin(const std::string& filename)
for (unsigned int i = 0; i < NB_ORBITS; ++i)
m_attribs[i].saveBin(fs, i);
if (m_isMultiRes)
m_mrattribs.saveBin(fs, 00);
return true;
}
......@@ -367,12 +406,34 @@ bool GenericMap::loadMapBin(const std::string& filename)
std::string buff_str(buff);
// Check file type
if (buff_str != "CGoGN_Map")
if (m_isMultiRes)
{
CGoGNerr<< "Wrong binary file format"<< CGoGNendl;
return false;
if (buff_str == "CGoGN_Map")
{
CGoGNerr<< "Wrong binary file format, file is not a MR-Map"<< CGoGNendl;
return false;
}
if (buff_str != "CGoGN_MRMap")
{
CGoGNerr<< "Wrong binary file format"<< CGoGNendl;
return false;
}
}
else
{
if (buff_str == "CGoGN_MRMap")
{
CGoGNerr<< "Wrong binary file format, file is a MR-Map"<< CGoGNendl;
return false;
}
if (buff_str != "CGoGN_Map")
{
CGoGNerr<< "Wrong binary file format"<< CGoGNendl;
return false;
}
}
// Check map type
buff_str = std::string(buff + 32);
......@@ -402,11 +463,17 @@ bool GenericMap::loadMapBin(const std::string& filename)
m_attribs[id].loadBin(fs);
}
// retrieve m_embeddings (from m_attribs[DART]
if (m_isMultiRes)
m_mrattribs.loadBin(fs);
// retrieve m_embeddings (from m_attribs)
update_m_emb_afterLoad();
// recursive call from real type of map (for topo relation attributes pointers) down to GenericMap (for Marker_cleaning & pointers)
update_topo_shortcuts();
return true;
}
......@@ -470,6 +537,41 @@ void GenericMap::update_topo_shortcuts()
}
}
}
if (m_isMultiRes)
{
std::vector<std::string> names;
m_mrattribs.getAttributesNames(names);
m_mrDarts.resize(names.size()-1);
for (unsigned int i=0; i<m_mrDarts.size(); ++i)
m_mrDarts[i] = NULL;
for (unsigned int i = 0; i < names.size(); ++i)
{
std::string sub = names[i].substr(0, 7);
if (sub=="MRLevel")
m_mrLevels = m_mrattribs.getDataVector<unsigned char>(i);
if (sub=="MRdart_")
{
sub = names[i].substr(7); // compute number following MT_Dart_
unsigned int idx=0;
for (unsigned int j=0; j < sub.length(); j++)
idx = 10*idx+(sub[j]-'0');
if (idx < names.size()-1)
m_mrDarts[idx] = m_mrattribs.getDataVector<unsigned int>(i);
else
CGoGNerr<<"Warning problem updating MR_DARTS" << CGoGNendl;
}
}
// check if all pointers are != NULL
for (unsigned int i=0; i<m_mrDarts.size(); ++i)
{
if (m_mrDarts[i] == NULL)