Commit 708ce60e authored by Sylvain Thery's avatar Sylvain Thery

MR: update of load/save/compact/clear

parent 4797d495
...@@ -112,13 +112,29 @@ protected: ...@@ -112,13 +112,29 @@ protected:
static const bool m_isMultiRes = false ; static const bool m_isMultiRes = false ;
#endif #endif
/**
* container for mr-darts that store indices in attribs[DART] for each level
*/
AttributeContainer m_mrattribs ; AttributeContainer m_mrattribs ;
/**
* pointer to indices mvectors (one for each level)
*/
std::vector< AttributeMultiVector<unsigned int>* > m_mrDarts ; std::vector< AttributeMultiVector<unsigned int>* > m_mrDarts ;
/**
* pointers to mvector of levels
*/
AttributeMultiVector<unsigned char>* m_mrLevels ; AttributeMultiVector<unsigned char>* m_mrLevels ;
/**
* current level of multiresoltion
*/
unsigned int m_mrCurrentLevel ; unsigned int m_mrCurrentLevel ;
/**
* stack for current level temporary storage
*/
std::vector<unsigned int> m_mrLevelStack ; std::vector<unsigned int> m_mrLevelStack ;
public: public:
...@@ -147,34 +163,34 @@ public: ...@@ -147,34 +163,34 @@ public:
* MULTIRES * * MULTIRES *
****************************************/ ****************************************/
unsigned int getCurrentLevel() { return m_mrCurrentLevel ; } /**
* get the current level of multi-resolution (use only in MRMaps)
void setCurrentLevel(unsigned int l) */
{ unsigned int getCurrentLevel() ;
if(l < m_mrDarts.size())
m_mrCurrentLevel = l ;
else
CGoGNout << "try to access inexisting resolution level" << CGoGNendl ;
}
void pushLevel() { m_mrLevelStack.push_back(m_mrCurrentLevel) ; }
void popLevel() { m_mrCurrentLevel = m_mrLevelStack.back() ; m_mrLevelStack.pop_back() ; } /**
* 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() ;
unsigned int getMaxLevel() { return m_mrDarts.size() - 1 ; } /**
* get back level of multi-resolution of the stack in current (use only in MRMaps)
*/
void popLevel() ;
void addLevel() /**
{ * get the max level of multi-resolution (use only in MRMaps)
unsigned int level = m_mrDarts.size() ; */
std::stringstream ss ; unsigned int getMaxLevel() ;
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 * add a level of multi-resolution (use only in MRMaps)
if(m_mrDarts.size() > 1) */
m_mrattribs.copyAttribute(amvMR->getIndex(), m_mrDarts[m_mrDarts.size() - 2]->getIndex()) ; void addLevel() ;
}
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
......
...@@ -259,4 +259,42 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na ...@@ -259,4 +259,42 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ; return amv ;
} }
/******************************************
* TOPOLOGICAL MULTIRESOLUTION MANAGEMENT*
******************************************/
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 } //namespace CGoGN
...@@ -152,6 +152,17 @@ void GenericMap::clear(bool removeAttrib) ...@@ -152,6 +152,17 @@ void GenericMap::clear(bool removeAttrib)
m_attribs[i].clear(false) ; 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();
}
} }
/**************************************** /****************************************
...@@ -332,8 +343,16 @@ bool GenericMap::saveMapBin(const std::string& filename) ...@@ -332,8 +343,16 @@ bool GenericMap::saveMapBin(const std::string& filename)
char* buff = new char[256]; char* buff = new char[256];
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
buff[i] = char(255); buff[i] = char(255);
const char* cgogn = "CGoGN_Map"; if (m_isMultiRes)
memcpy(buff, cgogn, 10); {
const char* cgogn = "CGoGN_MRMap";
memcpy(buff, cgogn, 12);
}
else
{
const char* cgogn = "CGoGN_Map";
memcpy(buff, cgogn, 10);
}
std::string mt = mapTypeName(); std::string mt = mapTypeName();
const char* mtc = mt.c_str(); const char* mtc = mt.c_str();
memcpy(buff+32, mtc, mt.size()+1); memcpy(buff+32, mtc, mt.size()+1);
...@@ -346,6 +365,9 @@ bool GenericMap::saveMapBin(const std::string& filename) ...@@ -346,6 +365,9 @@ bool GenericMap::saveMapBin(const std::string& filename)
for (unsigned int i = 0; i < NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
m_attribs[i].saveBin(fs, i); m_attribs[i].saveBin(fs, i);
if (m_isMultiRes)
m_mrattribs.saveBin(fs, 00);
return true; return true;
} }
...@@ -367,11 +389,33 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -367,11 +389,33 @@ bool GenericMap::loadMapBin(const std::string& filename)
std::string buff_str(buff); std::string buff_str(buff);
// Check file type // Check file type
if (buff_str != "CGoGN_Map") if (m_isMultiRes)
{ {
CGoGNerr<< "Wrong binary file format"<< CGoGNendl; if (buff_str == "CGoGN_Map")
return false; {
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 // Check map type
buff_str = std::string(buff + 32); buff_str = std::string(buff + 32);
...@@ -402,11 +446,17 @@ bool GenericMap::loadMapBin(const std::string& filename) ...@@ -402,11 +446,17 @@ bool GenericMap::loadMapBin(const std::string& filename)
m_attribs[id].loadBin(fs); 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(); 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;
} }
...@@ -470,6 +520,41 @@ void GenericMap::update_topo_shortcuts() ...@@ -470,6 +520,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 char>(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)
CGoGNerr<<"Warning problem MR_DARTS = NULL" << CGoGNendl;
}
}
} }
void GenericMap::dumpAttributesAndMarkers() void GenericMap::dumpAttributesAndMarkers()
...@@ -514,30 +599,82 @@ void GenericMap::dumpAttributesAndMarkers() ...@@ -514,30 +599,82 @@ void GenericMap::dumpAttributesAndMarkers()
void GenericMap::compact() void GenericMap::compact()
{ {
std::vector<unsigned int> oldnew; // if MR compact the MR attrib container
std::vector<unsigned int> oldnewMR;
if (m_isMultiRes)
m_mrattribs.compact(oldnewMR);
// compacting the orbits attributes // compacting the orbits attributes
// for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
// {
// if ((orbit != DART) && (isOrbitEmbedded(orbit)))
// {
// m_attribs[orbit].compact(oldnew);
//
// for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
// {
// unsigned int& idx = m_embeddings[orbit]->operator [](i);
// unsigned int jdx = oldnew[idx];
// if ((jdx != 0xffffffff) && (jdx != idx))
// idx = jdx;
// }
// }
// }
// compact embedding attribs
std::vector< std::vector<unsigned int>* > oldnews;
oldnews.resize(NB_ORBITS);
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
if ((orbit != DART) && (isOrbitEmbedded(orbit))) if ((orbit != DART) && (isOrbitEmbedded(orbit)))
{ {
m_attribs[orbit].compact(oldnew); oldnews[orbit] = new std::vector<unsigned int>;
m_attribs[orbit].compact(*(oldnews[orbit]));
}
}
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) // update embedding indices of topo
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
if ((orbit != DART) && (isOrbitEmbedded(orbit)))
{ {
unsigned int& idx = m_embeddings[orbit]->operator [](i); unsigned int& idx = m_embeddings[orbit]->operator[](i);
unsigned int jdx = oldnew[idx]; unsigned int jdx = oldnews[orbit]->operator[](idx);
if ((jdx != 0xffffffff) && (jdx != idx)) if ((jdx != 0xffffffff) && (jdx != idx))
idx = jdx; idx = jdx;
} }
} }
} }
// delete allocated vectors
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
if ((orbit != DART) && (isOrbitEmbedded(orbit)))
delete[] oldnews[orbit];
//compacting the topo //compacting the topo
std::vector<unsigned int> oldnew;
m_attribs[DART].compact(oldnew); m_attribs[DART].compact(oldnew);
// update topo relations: recurvise call from real map down to generic
compactTopoRelations(oldnew); // update MR indices to attribs[DART]
if (m_isMultiRes)
{
unsigned int nbl = m_mrDarts.size();
for (unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
{
for (unsigned int j=0; j<nbl; ++j)
{
unsigned int d_index = m_mrDarts[j][i];
if (d_index != oldnew[d_index])
m_mrDarts[j][i] = Dart(oldnew[d_index]);
}
}
}
// update topo relations from real map
compactTopoRelations(oldnewMR);
// dumpAttributesAndMarkers(); // dumpAttributesAndMarkers();
} }
...@@ -664,6 +801,30 @@ void GenericMap::boundaryUnmarkAll() ...@@ -664,6 +801,30 @@ void GenericMap::boundaryUnmarkAll()
m_markTables[DART][0]->operator[](i).unsetMark(m_boundaryMarker); m_markTables[DART][0]->operator[](i).unsetMark(m_boundaryMarker);
} }
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()) ;
}
} // namespace CGoGN } // namespace CGoGN
// //
......
...@@ -31,20 +31,27 @@ void Map1::compactTopoRelations(const std::vector<unsigned int>& oldnew) ...@@ -31,20 +31,27 @@ void Map1::compactTopoRelations(const std::vector<unsigned int>& oldnew)
{ {
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{ {
{ unsigned int d_index = dartIndex(m_phi1->operator [](i));
Dart& d = m_phi1->operator [](i); // ??????????????? if (d_index != oldnew[d_index])
unsigned int d_index = dartIndex(d); m_phi1->operator [](i) = Dart(oldnew[d_index]);
Dart e = Dart(oldnew[d_index]);
if (d != e) d_index = dartIndex(m_phi_1->operator [](i));
d = e; if (d_index != oldnew[d_index])
} m_phi_1->operator [](i) = Dart(oldnew[d_index]);
{ // {
Dart& d = m_phi_1->operator [](i); // Dart d = m_phi1->operator [](i);
unsigned int d_index = dartIndex(d); // unsigned int d_index = dartIndex(m_phi1->operator [](i));
Dart e = Dart(oldnew[d_index]); // Dart e = Dart(oldnew[d_index]);
if (d != e) // if (d != e)
d = e; // d = e;
} // }
// {
// Dart& d = m_phi_1->operator [](i);
// unsigned int d_index = dartIndex(d);
// Dart e = Dart(oldnew[d_index]);
// if (d != e)
// d = e;
// }
} }
} }
......
...@@ -71,24 +71,36 @@ void Map2::compactTopoRelations(const std::vector<unsigned int>& oldnew) ...@@ -71,24 +71,36 @@ void Map2::compactTopoRelations(const std::vector<unsigned int>& oldnew)
{ {
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{ {
{ unsigned int d_index = dartIndex(m_phi1->operator[](i));
Dart& d = m_phi1->operator [](i); if (d_index != oldnew[d_index])
Dart e = Dart(oldnew[d.index]); m_phi1->operator[](i) = Dart(oldnew[d_index]);
if (d != e)
d = e; d_index = dartIndex(m_phi_1->operator[](i));
} if (d_index != oldnew[d_index])
{ m_phi_1->operator[](i) = Dart(oldnew[d_index]);
Dart& d = m_phi_1->operator [](i);
Dart e = Dart(oldnew[d.index]); d_index = dartIndex(m_phi2->operator[](i));
if (d != e) if (d_index != oldnew[d_index])
d = e; m_phi2->operator[](i) = Dart(oldnew[d_index]);
}
{ // {
Dart& d = m_phi2->operator [](i); // Dart& d = m_phi1->operator [](i);
Dart e = Dart(oldnew[d.index]); // Dart e = Dart(oldnew[d.index]);
if (d != e) // if (d != e)
d = e; // d = e;
} // }
// {
// Dart& d = m_phi_1->operator [](i);
// Dart e = Dart(oldnew[d.index]);
// if (d != e)
// d = e;
// }
// {
// Dart& d = m_phi2->operator [](i);
// Dart e = Dart(oldnew[d.index]);
// if (d != e)
// d = e;
// }
} }
} }
......
...@@ -31,30 +31,46 @@ void Map3::compactTopoRelations(const std::vector<unsigned int>& oldnew) ...@@ -31,30 +31,46 @@ void Map3::compactTopoRelations(const std::vector<unsigned int>& oldnew)
{ {
for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
{ {
{ unsigned int d_index = dartIndex(m_phi1->operator[](i));
Dart& d = m_phi1->operator [](i); if (d_index != oldnew[d_index])
Dart e = Dart(oldnew[d.index]); m_phi1->operator[](i) = Dart(oldnew[d_index]);
if (d != e)
d = e; d_index = dartIndex(m_phi_1->operator[](i));
} if (d_index != oldnew[d_index])
{ m_phi_1->operator[](i) = Dart(oldnew[d_index]);
Dart& d = m_phi_1->operator [](i);
Dart e = Dart(oldnew[d.index]); d_index = dartIndex(m_phi2->operator[](i));
if (d != e) if (d_index != oldnew[d_index])
d = e; m_phi2->operator[](i) = Dart(oldnew[d_index]);
}
{ d_index = dartIndex(m_phi3->operator[](i));
Dart& d = m_phi2->operator [](i); if (d_index != oldnew[d_index])
Dart e = Dart(oldnew[d.index]); m_phi3->operator[](i) = Dart(oldnew[d_index]);
if (d != e) //
d = e; // {
} // Dart& d = m_phi1->operator [](i);
{ // Dart e = Dart(oldnew[d.index]);
Dart& d = m_phi3->operator [](i); // if (d != e)
Dart e = Dart(oldnew[d.index]); // d = e;
if (d != e) // }
d = e; // {
} // Dart& d = m_phi_1->operator [](i);
// Dart e = Dart(oldnew[d.index]);
// if (d != e)
// d = e;
// }
// {
// Dart& d = m_phi2->operator [](i);
// Dart e = Dart(oldnew[d.index]);
// if (d != e)
// d = e;
// }
// {
// Dart& d = m_phi3->operator [](i);
// Dart e = Dart(oldnew[d.index]);
// if (d != e)
// d = e;
// }
} }
} }
......
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