Commit 0ea6813e authored by Pierre Kraemer's avatar Pierre Kraemer

update load & save

parent cb65f5ab
......@@ -68,7 +68,7 @@ AttributeHandler_IHM<T, ORBIT> ImplicitHierarchicalMap3::getAttribute(const std:
inline void ImplicitHierarchicalMap3::update_topo_shortcuts()
{
Map3::update_topo_shortcuts();
// Map3::update_topo_shortcuts();
m_dartLevel = Map3::getAttribute<unsigned int, DART>("dartLevel") ;
m_faceId = Map3::getAttribute<unsigned int, DART>("faceId") ;
m_edgeId = Map3::getAttribute<unsigned int, DART>("edgeId") ;
......
......@@ -344,17 +344,13 @@ public:
/****************************************
* SAVE & LOAD *
****************************************/
/**
* update the pointer of embedding vector after loading
*/
void update_m_emb_afterLoad();
protected:
/**
* update the markTables and recursively from real type the topo shortcut pointers
* restore embedding / markers / quick traversal shortcuts
*/
virtual void update_topo_shortcuts();
void restore_shortcuts();
public:
/**
* Save map in a binary file
* @param filename the file name
......@@ -379,11 +375,13 @@ public:
*/
void dumpAttributesAndMarkers() ;
protected:
/**
* update topo relation after compacting the container:
*/
virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew) = 0 ;
public:
/**
* compact the map
*/
......
......@@ -70,6 +70,9 @@ protected:
inline void addPermutation();
virtual unsigned int getNbInvolutions() const = 0;
virtual unsigned int getNbPermutations() const = 0;
template <int I>
inline Dart getInvolution(Dart d) const;
......@@ -80,16 +83,16 @@ protected:
inline Dart getPermutationInv(Dart d) const;
template <int I>
inline void permutationSew(Dart d, Dart e);
inline void involutionSew(Dart d, Dart e);
template <int I>
inline void permutationUnsew(Dart d);
inline void involutionUnsew(Dart d);
template <int I>
inline void involutionSew(Dart d, Dart e);
inline void permutationSew(Dart d, Dart e);
template <int I>
inline void involutionUnsew(Dart d);
inline void permutationUnsew(Dart d);
inline virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
......@@ -125,6 +128,8 @@ public:
bool loadMapBin(const std::string& filename);
bool copyFrom(const GenericMap& map);
void restore_topo_shortcuts();
} ;
} //namespace CGoGN
......
......@@ -107,6 +107,23 @@ inline Dart MapMono::getPermutationInv(Dart d) const
return (*m_permutation_inv[I])[d.index];
}
template <int I>
inline void MapMono::involutionSew(Dart d, Dart e)
{
assert((*m_involution[I])[d.index] == d) ;
assert((*m_involution[I])[e.index] == e) ;
(*m_involution[I])[d.index] = e ;
(*m_involution[I])[e.index] = d ;
}
template <int I>
inline void MapMono::involutionUnsew(Dart d)
{
Dart e = (*m_involution[I])[d.index] ;
(*m_involution[I])[d.index] = d ;
(*m_involution[I])[e.index] = e ;
}
template <int I>
inline void MapMono::permutationSew(Dart d, Dart e)
{
......@@ -129,23 +146,6 @@ inline void MapMono::permutationUnsew(Dart d)
(*m_permutation_inv[I])[e.index] = e ;
}
template <int I>
inline void MapMono::involutionSew(Dart d, Dart e)
{
assert((*m_involution[I])[d.index] == d) ;
assert((*m_involution[I])[e.index] == e) ;
(*m_involution[I])[d.index] = e ;
(*m_involution[I])[e.index] = d ;
}
template <int I>
inline void MapMono::involutionUnsew(Dart d)
{
Dart e = (*m_involution[I])[d.index] ;
(*m_involution[I])[d.index] = d ;
(*m_involution[I])[e.index] = e ;
}
inline void MapMono::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))
......
......@@ -33,6 +33,7 @@ namespace CGoGN
class MapMulti : public GenericMap
{
template<typename MAP> friend class DartMarkerTmpl ;
template<typename MAP> friend class DartMarkerStore ;
public:
MapMulti()
......@@ -137,6 +138,9 @@ protected:
inline void addPermutation();
virtual unsigned int getNbInvolutions() const = 0;
virtual unsigned int getNbPermutations() const = 0;
template <int I>
inline Dart getInvolution(Dart d) const;
......@@ -147,16 +151,16 @@ protected:
inline Dart getPermutationInv(Dart d) const;
template <int I>
inline void permutationSew(Dart d, Dart e);
inline void involutionSew(Dart d, Dart e);
template <int I>
inline void permutationUnsew(Dart d);
inline void involutionUnsew(Dart d);
template <int I>
inline void involutionSew(Dart d, Dart e);
inline void permutationSew(Dart d, Dart e);
template <int I>
inline void involutionUnsew(Dart d);
inline void permutationUnsew(Dart d);
inline virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);
......@@ -283,6 +287,8 @@ public:
bool loadMapBin(const std::string& filename);
bool copyFrom(const GenericMap& map);
void restore_topo_shortcuts();
} ;
} //namespace CGoGN
......
......@@ -224,6 +224,24 @@ inline Dart MapMulti::getPermutationInv(Dart d) const
return (*m_permutation_inv[I])[dartIndex(d)];
}
template <int I>
inline void MapMulti::involutionSew(Dart d, Dart e)
{
assert((*m_involution[I])[dartIndex(d)] == d) ;
assert((*m_involution[I])[dartIndex(e)] == e) ;
(*m_involution[I])[dartIndex(d)] = e ;
(*m_involution[I])[dartIndex(e)] = d ;
}
template <int I>
inline void MapMulti::involutionUnsew(Dart d)
{
unsigned int d_index = dartIndex(d);
Dart e = (*m_involution[I])[d_index] ;
(*m_involution[I])[d_index] = d ;
(*m_involution[I])[dartIndex(e)] = e ;
}
template <int I>
inline void MapMulti::permutationSew(Dart d, Dart e)
{
......@@ -250,24 +268,6 @@ inline void MapMulti::permutationUnsew(Dart d)
(*m_permutation_inv[I])[e_index] = e ;
}
template <int I>
inline void MapMulti::involutionSew(Dart d, Dart e)
{
assert((*m_involution[I])[dartIndex(d)] == d) ;
assert((*m_involution[I])[dartIndex(e)] == e) ;
(*m_involution[I])[dartIndex(d)] = e ;
(*m_involution[I])[dartIndex(e)] = d ;
}
template <int I>
inline void MapMulti::involutionUnsew(Dart d)
{
unsigned int d_index = dartIndex(d);
Dart e = (*m_involution[I])[d_index] ;
(*m_involution[I])[d_index] = d ;
(*m_involution[I])[dartIndex(e)] = e ;
}
inline void MapMulti::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))
......
......@@ -55,7 +55,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -60,10 +60,15 @@ inline void GMap0<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void GMap0<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int GMap0<MAP_IMPL>::getNbInvolutions() const
{
MAP_IMPL::update_topo_shortcuts();
// m_beta0 = getRelation("beta0");
return 1;
}
template <typename MAP_IMPL>
inline unsigned int GMap0<MAP_IMPL>::getNbPermutations() const
{
return 0;
}
/*! @name Basic Topological Operators
......
......@@ -53,7 +53,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -58,10 +58,15 @@ inline void GMap1<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void GMap1<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int GMap1<MAP_IMPL>::getNbInvolutions() const
{
ParentMap::update_topo_shortcuts();
// m_beta1 = getRelation("beta1");
return 1 + ParentMap::getNbInvolutions();
}
template <typename MAP_IMPL>
inline unsigned int GMap1<MAP_IMPL>::getNbPermutations() const
{
return ParentMap::getNbPermutations();
}
/*! @name Basic Topological Operators
......
......@@ -60,7 +60,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -58,10 +58,15 @@ inline void GMap2<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void GMap2<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int GMap2<MAP_IMPL>::getNbInvolutions() const
{
ParentMap::update_topo_shortcuts();
// m_beta2 = getRelation("beta2");
return 1 + ParentMap::getNbInvolutions();
}
template <typename MAP_IMPL>
inline unsigned int GMap2<MAP_IMPL>::getNbPermutations() const
{
return ParentMap::getNbPermutations();
}
/*! @name Basic Topological Operators
......
......@@ -66,7 +66,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -60,10 +60,15 @@ inline void GMap3<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void GMap3<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int GMap3<MAP_IMPL>::getNbInvolutions() const
{
ParentMap::update_topo_shortcuts();
// m_beta3 = getRelation("beta3");
return 1 + ParentMap::getNbInvolutions();
}
template <typename MAP_IMPL>
inline unsigned int GMap3<MAP_IMPL>::getNbPermutations() const
{
return ParentMap::getNbPermutations();
}
/*! @name Basic Topological Operators
......
......@@ -60,7 +60,7 @@ AttributeHandler_IHM<T, ORBIT> ImplicitHierarchicalMap2::getAttribute(const std:
inline void ImplicitHierarchicalMap2::update_topo_shortcuts()
{
Map2::update_topo_shortcuts();
// Map2::update_topo_shortcuts();
m_dartLevel = Map2::getAttribute<unsigned int, DART>("dartLevel") ;
m_edgeId = Map2::getAttribute<unsigned int, DART>("edgeId") ;
......
......@@ -59,7 +59,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -60,11 +60,15 @@ inline void Map1<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void Map1<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int Map1<MAP_IMPL>::getNbInvolutions() const
{
MAP_IMPL::update_topo_shortcuts();
// m_phi1 = MAP::getRelation("phi1");
// m_phi_1 = MAP::getRelation("phi_1");
return 0;
}
template <typename MAP_IMPL>
inline unsigned int Map1<MAP_IMPL>::getNbPermutations() const
{
return 1;
}
/*! @name Basic Topological Operators
......
......@@ -72,7 +72,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -58,10 +58,15 @@ inline void Map2<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int Map2<MAP_IMPL>::getNbInvolutions() const
{
ParentMap::update_topo_shortcuts();
// m_phi2 = getRelation("phi2");
return 1 + ParentMap::getNbInvolutions();
}
template <typename MAP_IMPL>
inline unsigned int Map2<MAP_IMPL>::getNbPermutations() const
{
return ParentMap::getNbPermutations();
}
/*! @name Basic Topological Operators
......
......@@ -80,7 +80,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
virtual unsigned int getNbInvolutions() const;
virtual unsigned int getNbPermutations() const;
/*! @name Basic Topological Operators
* Access and Modification
......
......@@ -60,10 +60,15 @@ inline void Map3<MAP_IMPL>::clear(bool removeAttrib)
}
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::update_topo_shortcuts()
inline unsigned int Map3<MAP_IMPL>::getNbInvolutions() const
{
ParentMap::update_topo_shortcuts();
// m_phi3 = getRelation("phi3");
return 1 + ParentMap::getNbInvolutions();
}
template <typename MAP_IMPL>
inline unsigned int Map3<MAP_IMPL>::getNbPermutations() const
{
return ParentMap::getNbPermutations();
}
/*! @name Basic Topological Operators
......
......@@ -324,8 +324,10 @@ void GenericMap::removeThreadMarker(unsigned int nb)
* SAVE & LOAD *
****************************************/
void GenericMap::update_m_emb_afterLoad()
void GenericMap::restore_shortcuts()
{
// EMBEDDING
// get container of dart orbit
AttributeContainer& cont = m_attribs[DART] ;
......@@ -344,15 +346,28 @@ void GenericMap::update_m_emb_afterLoad()
m_embeddings[orb] = amv ;
}
}
}
void GenericMap::update_topo_shortcuts()
{
// MARKERS & QUICK TRAVERSAL
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
AttributeContainer& cont = m_attribs[orbit];
// get the list of attributes of orbit container
// QUICK TRAVERSAL
m_quickTraversal[orbit] = cont.getDataVector<Dart>("quick_traversal") ;
for(unsigned int j = 0; j < NB_ORBITS; ++j)
{
std::stringstream ss;
ss << "quickLocalIncidentTraversal_" << j;
m_quickLocalIncidentTraversal[orbit][j] = cont.getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
std::stringstream ss2;
ss2 << "quickLocalAdjacentTraversal" << j;
m_quickLocalAdjacentTraversal[orbit][j] = cont.getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss2.str()) ;
}
// MARKERS
std::vector<std::string> listeNames;
cont.getAttributesNames(listeNames);
......@@ -362,18 +377,16 @@ void GenericMap::update_topo_shortcuts()
if (sub == "Mark_")
{
// get thread number
unsigned int thread = listeNames[i][5]-'0';
unsigned int thread = listeNames[i][5] - '0';
if (listeNames[i].size() > 6) // thread number is >9
thread = 10*thread + (listeNames[i][6]-'0');
thread = 10 * thread + (listeNames[i][6] - '0');
AttributeMultiVector<Mark>* amvMark = cont.getDataVector<Mark>(i);
m_markTables[orbit][thread] = amvMark ;
if ((orbit == DART) && (thread == 0)) // for Marker of dart of thread O keep the boundary marker
{
// TODO Verifier ce qu fait exactement ce unsetMark sur m.invert ??
// Mark m(m_boundaryMarker);
Mark m(m_boundaryMarkers[0]+m_boundaryMarkers[1]);
Mark m(m_boundaryMarkers[0] + m_boundaryMarkers[1]);
m.invert();
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
amvMark->operator[](i).unsetMark(m);
......@@ -387,39 +400,15 @@ 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 int>(i);
// NB THREADS
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)
CGoGNerr << "Warning problem MR_DARTS = NULL" << CGoGNendl;
}
std::vector<std::string> typeMark;
unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark);
m_nbThreads = 0;
for (unsigned int i = 0; i < nbatt0; ++i)
{
if (typeMark[i] == "Mark")
++m_nbThreads;
}
}
......
......@@ -119,36 +119,9 @@ bool MapMono::loadMapBin(const std::string& filename)
m_attribs[id].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();
// restore nbThreads
std::vector<std::string> typeMark;
unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark);
m_nbThreads = 0;
for (unsigned int i = 0; i < nbatt0; ++i)
{
if (typeMark[i] == "Mark")
++m_nbThreads;
}
// restore quick traversals pointers if necessary (containers already ok)
for (unsigned int orb=0; orb<NB_ORBITS; ++orb)
{
m_quickTraversal[orb] = m_attribs[orb].getDataVector<Dart>("quick_traversal") ;
for(unsigned int j = 0; j < NB_ORBITS; ++j)
{
std::stringstream ss;
ss << "quickLocalIncidentTraversal_" << j;
m_quickLocalIncidentTraversal[orb][j] = m_attribs[orb].getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
std::stringstream ss2;
ss2 << "quickLocalAdjacentTraversal" << j;
m_quickLocalAdjacentTraversal[orb][j] = m_attribs[orb].getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss2.str()) ;
}
}
// restore shortcuts
GenericMap::restore_shortcuts();
restore_topo_shortcuts();
return true;
}
......@@ -169,13 +142,48 @@ bool MapMono::copyFrom(const GenericMap& map)
for (unsigned int i = 0; i < NB_ORBITS; ++i)
m_attribs[i].copyFrom(mapM.m_attribs[i]);
// 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();
// restore shortcuts
GenericMap::restore_shortcuts();
restore_topo_shortcuts();
return true;
}
void MapMono::restore_topo_shortcuts()
{
m_involution.clear();
m_permutation.clear();
m_permutation_inv.clear();
m_involution.resize(getNbInvolutions());
m_permutation.resize(getNbPermutations());
m_permutation_inv.resize(getNbPermutations());
std::vector<std::string> listeNames;
m_attribs[DART].getAttributesNames(listeNames);
for (unsigned int i = 0; i < listeNames.size(); ++i)
{
std::string sub = listeNames[i].substr(0, listeNames[i].size() - 1);
if (sub == "involution_")
{
unsigned int relNum = listeNames[i][11] - '0';
AttributeMultiVector<Dart>* rel = getRelation(listeNames[i]);
m_involution[relNum] = rel;
}
else if (sub == "permutation_")
{
unsigned int relNum = listeNames[i][12] - '0';
AttributeMultiVector<Dart>* rel = getRelation(listeNames[i]);
m_permutation[relNum] = rel;
}
else if (sub == "permutation_inv_")
{
unsigned int relNum = listeNames[i][16] - '0';
AttributeMultiVector<Dart>* rel = getRelation(listeNames[i]);
m_permutation_inv[relNum] = rel;
}
}
}
} //namespace CGoGN
......@@ -306,36 +306,9 @@ bool MapMulti::loadMapBin(const std::string& filename)
m_mrNbDarts.resize(nb);
fs.read(reinterpret_cast<char*>(&(m_mrNbDarts[0])), nb *sizeof(unsigned int));
// 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();
// restore nbThreads
std::vector<std::string> typeMark;
unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark);
m_nbThreads = 0;
for (unsigned int i = 0; i < nbatt0; ++i)
{
if (typeMark[i] == "Mark")
++m_nbThreads;
}
// restore quick traversals pointers if necessary (containers already ok)
for (unsigned int orb=0; orb<NB_ORBITS; ++orb)
{
m_quickTraversal[orb] = m_attribs[orb].getDataVector<Dart>("quick_traversal") ;
for(unsigned int j = 0; j < NB_ORBITS; ++j)
{
std::stringstream ss;
ss << "quickLocalIncidentTraversal_" << j;
m_quickLocalIncidentTraversal[orb][j] = m_attribs[orb].getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
std::stringstream ss2;
ss2 << "quickLocalAdjacentTraversal" << j;
m_quickLocalAdjacentTraversal[orb][j] = m_attribs[orb].getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss2.str()) ;
}
}
// restore shortcuts
GenericMap::restore_shortcuts();
restore_topo_shortcuts();
return true;
}
......@@ -364,13 +337,81 @@ bool MapMulti::copyFrom(const GenericMap& map)
for (unsigned int i = 0; i < nb; ++i)
m_mrNbDarts[i] = mapMR.m_mrNbDarts[i];
// 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();