Commit c146daa8 authored by Sylvain Thery's avatar Sylvain Thery

Map3::moveFrom

parent 785f2c31
...@@ -402,6 +402,14 @@ int main(int argc, char **argv) ...@@ -402,6 +402,14 @@ int main(int argc, char **argv)
else else
{ {
*/ */
if(extension == std::string(".map"))
{
myMap.loadMapBin(filename);
position = myMap.getAttribute<VEC3, VERTEX,MAP>("position") ;
}
else
{
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames)) if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
{ {
std::cerr << "could not import " << filename << std::endl ; std::cerr << "could not import " << filename << std::endl ;
...@@ -409,9 +417,9 @@ int main(int argc, char **argv) ...@@ -409,9 +417,9 @@ int main(int argc, char **argv)
} }
else else
position = myMap.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]) ; position = myMap.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]) ;
// } }
color = myMap.addAttribute<VEC3, VOLUME, MAP>("color"); color = myMap.addAttribute<VEC3, VOLUME, MAP>("colorVol");
TraversorCell<MAP, VOLUME> tra(myMap); TraversorCell<MAP, VOLUME> tra(myMap);
float maxV = 0.0f; float maxV = 0.0f;
......
...@@ -42,3 +42,7 @@ target_link_libraries( loadSave ...@@ -42,3 +42,7 @@ target_link_libraries( loadSave
add_executable( copyfrom ./copyfrom.cpp) add_executable( copyfrom ./copyfrom.cpp)
target_link_libraries( copyfrom target_link_libraries( copyfrom
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS}) ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
add_executable( movefrom ./movefrom.cpp)
target_link_libraries( movefrom
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
...@@ -61,11 +61,6 @@ protected: ...@@ -61,11 +61,6 @@ protected:
*/ */
unsigned int m_index; unsigned int m_index;
/**
* Process or not the attribute in arithmetic operations
*/
bool m_toProcess;
public: public:
AttributeMultiVectorGen(const std::string& strName, const std::string& strType); AttributeMultiVectorGen(const std::string& strName, const std::string& strType);
......
...@@ -26,11 +26,10 @@ namespace CGoGN ...@@ -26,11 +26,10 @@ namespace CGoGN
{ {
inline AttributeMultiVectorGen::AttributeMultiVectorGen(const std::string& strName, const std::string& strType): inline AttributeMultiVectorGen::AttributeMultiVectorGen(const std::string& strName, const std::string& strType):
m_attrName(strName), m_typeName(strType), m_toProcess(true) m_attrName(strName), m_typeName(strType)
{} {}
inline AttributeMultiVectorGen::AttributeMultiVectorGen(): inline AttributeMultiVectorGen::AttributeMultiVectorGen()
m_toProcess(true)
{} {}
inline AttributeMultiVectorGen::~AttributeMultiVectorGen() inline AttributeMultiVectorGen::~AttributeMultiVectorGen()
......
...@@ -133,7 +133,7 @@ protected: ...@@ -133,7 +133,7 @@ protected:
/** /**
* Store links to created AttributeHandlers * Store links to created AttributeHandlers
*/ */
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe!) std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ;
std::mutex attributeHandlersMutex; std::mutex attributeHandlersMutex;
public: public:
...@@ -300,6 +300,17 @@ public: ...@@ -300,6 +300,17 @@ public:
template <unsigned int ORBIT> template <unsigned int ORBIT>
void releaseMarkVector(AttributeMultiVector<MarkerBool>* amv, unsigned int thread=0); void releaseMarkVector(AttributeMultiVector<MarkerBool>* amv, unsigned int thread=0);
protected:
/**
* @brief scan attributes for MarkerBool, clean them and store as free in thread 0
*/
void garbageMarkVectors();
/**
* @brief scan attributes for MarkerBool and remove them
*/
void removeMarkVectors();
public:
/** /**
* return a pointer to the Dart attribute vector that store the embedding of the given orbit * return a pointer to the Dart attribute vector that store the embedding of the given orbit
...@@ -426,6 +437,13 @@ public: ...@@ -426,6 +437,13 @@ public:
* @brief dump all attributes of map in CSV format (; separated columns) * @brief dump all attributes of map in CSV format (; separated columns)
*/ */
void dumpCSV() const; void dumpCSV() const;
public:
/**
* @brief move data (container && shortcuts from a map to this map
* @param mapf map from which data are moved);
*/
void moveData(GenericMap &mapf);
} ; } ;
......
...@@ -73,6 +73,7 @@ public: ...@@ -73,6 +73,7 @@ public:
protected: protected:
inline void addInvolution(); inline void addInvolution();
inline void addPermutation(); inline void addPermutation();
inline void removeLastInvolutionPtr(); // for moveFrom
inline AttributeMultiVector<Dart>* getInvolutionAttribute(unsigned int i); inline AttributeMultiVector<Dart>* getInvolutionAttribute(unsigned int i);
inline AttributeMultiVector<Dart>* getPermutationAttribute(unsigned int i); inline AttributeMultiVector<Dart>* getPermutationAttribute(unsigned int i);
......
...@@ -90,6 +90,11 @@ inline void MapMono::addInvolution() ...@@ -90,6 +90,11 @@ inline void MapMono::addInvolution()
m_involution.push_back(addRelation(sstm.str())); m_involution.push_back(addRelation(sstm.str()));
} }
inline void MapMono::removeLastInvolutionPtr()
{
m_involution.pop_back();
}
inline void MapMono::addPermutation() inline void MapMono::addPermutation()
{ {
std::stringstream sstm; std::stringstream sstm;
......
...@@ -519,6 +519,13 @@ public: ...@@ -519,6 +519,13 @@ public:
void computeDualTest(); void computeDualTest();
//@} //@}
/**
* @brief move all data from a map2 in a map3
* @param mapf the input map2 (which will be empty after)
*/
void moveFrom(Map2<MAP_IMPL>& mapf);
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -1803,7 +1803,20 @@ void Map3<MAP_IMPL>::computeDualTest() ...@@ -1803,7 +1803,20 @@ void Map3<MAP_IMPL>::computeDualTest()
// //deleteVolume(d); // //deleteVolume(d);
// } // }
// } // }
}
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::moveFrom(Map2<MAP_IMPL>& mapf)
{
GenericMap::moveData(mapf);
MAP_IMPL::removeLastInvolutionPtr();
MAP_IMPL::addInvolution() ;
MAP_IMPL::restore_topo_shortcuts() ;
GenericMap::garbageMarkVectors();
closeMap();
} }
} // namespace CGoGN } // namespace CGoGN
...@@ -661,7 +661,22 @@ void AttributeContainer::removeLine(unsigned int index) ...@@ -661,7 +661,22 @@ void AttributeContainer::removeLine(unsigned int index)
void AttributeContainer::saveBin(CGoGNostream& fs, unsigned int id) const void AttributeContainer::saveBin(CGoGNostream& fs, unsigned int id) const
{ {
// en ascii id et taille les tailles std::vector<AttributeMultiVectorGen*> bufferamv;
bufferamv.reserve(m_tableAttribs.size());
for(std::vector<AttributeMultiVectorGen*>::const_iterator it = m_tableAttribs.begin(); it != m_tableAttribs.end(); ++it)
{
if (*it != NULL)
{
const std::string& attName = (*it)->getName();
std::string markName = attName.substr(0,7);
if (markName != "marker_")
bufferamv.push_back(*it);
}
}
// en ascii id et les tailles
std::vector<unsigned int> bufferui; std::vector<unsigned int> bufferui;
bufferui.reserve(10); bufferui.reserve(10);
...@@ -670,20 +685,27 @@ void AttributeContainer::saveBin(CGoGNostream& fs, unsigned int id) const ...@@ -670,20 +685,27 @@ void AttributeContainer::saveBin(CGoGNostream& fs, unsigned int id) const
bufferui.push_back(_BLOCKSIZE_); bufferui.push_back(_BLOCKSIZE_);
bufferui.push_back(m_holesBlocks.size()); bufferui.push_back(m_holesBlocks.size());
bufferui.push_back(m_tableBlocksWithFree.size()); bufferui.push_back(m_tableBlocksWithFree.size());
bufferui.push_back(m_nbAttributes); // bufferui.push_back(m_nbAttributes);
bufferui.push_back(bufferamv.size());
bufferui.push_back(m_size); bufferui.push_back(m_size);
bufferui.push_back(m_maxSize); bufferui.push_back(m_maxSize);
bufferui.push_back(m_orbit); bufferui.push_back(m_orbit);
bufferui.push_back(m_nbUnknown); bufferui.push_back(m_nbUnknown);
fs.write(reinterpret_cast<const char*>(&bufferui[0]), bufferui.size()*sizeof(unsigned int)); fs.write(reinterpret_cast<const char*>(&bufferui[0]), bufferui.size()*sizeof(unsigned int));
unsigned int i = 0; unsigned int i = 0;
for(std::vector<AttributeMultiVectorGen*>::const_iterator it = m_tableAttribs.begin(); it != m_tableAttribs.end(); ++it) for(std::vector<AttributeMultiVectorGen*>::const_iterator it = bufferamv.begin(); it != bufferamv.end(); ++it)
{ {
if (*it != NULL) if (*it != NULL)
{
const std::string& attName = (*it)->getName();
std::string markName = attName.substr(0,7);
if (markName != "marker_")
(*it)->saveBin(fs, i++); (*it)->saveBin(fs, i++);
}
else else
{ {
CGoGNerr << "PB saving, NULL ptr in m_tableAttribs" << CGoGNendl; CGoGNerr << "PB saving, NULL ptr in m_tableAttribs" << CGoGNendl;
......
...@@ -471,4 +471,85 @@ void GenericMap::dumpCSV() const ...@@ -471,4 +471,85 @@ void GenericMap::dumpCSV() const
CGoGNout << CGoGNendl; CGoGNout << CGoGNendl;
} }
void GenericMap::moveData(GenericMap &mapf)
{
GenericMap::init(false);
for (unsigned int i=0; i<NB_ORBITS; ++i)
{
this->m_attribs[i].swap(mapf.m_attribs[i]);
this->m_embeddings[i] = mapf.m_embeddings[i];
this->m_quickTraversal[i] = mapf.m_quickTraversal[i];
mapf.m_embeddings[i] = NULL ;
mapf.m_quickTraversal[i] = NULL;
for (unsigned int j=0; j<NB_ORBITS; ++j)
{
this->m_quickLocalIncidentTraversal[i][j] = mapf.m_quickLocalIncidentTraversal[i][j];
this->m_quickLocalAdjacentTraversal[i][j] = mapf.m_quickLocalAdjacentTraversal[i][j];
mapf.m_quickLocalIncidentTraversal[i][j] = NULL ;
mapf.m_quickLocalAdjacentTraversal[i][j] = NULL ;
}
for (unsigned int j=0; j<NB_THREAD; ++j)
this->m_markVectors_free[i][j].swap(mapf.m_markVectors_free[i][j]);
}
this->m_boundaryMarkers[0] = mapf.m_boundaryMarkers[0];
this->m_boundaryMarkers[1] = mapf.m_boundaryMarkers[1];
this->m_nextMarkerId = mapf.m_nextMarkerId;
for(auto it = mapf.attributeHandlers.begin(); it != mapf.attributeHandlers.end(); ++it)
(*it).second->setInvalid() ;
mapf.attributeHandlers.clear() ;
}
void GenericMap::garbageMarkVectors()
{
unsigned int maxId=0;
for (unsigned int orbit=0; orbit<NB_ORBITS;++orbit)
{
std::vector<std::string> attNames;
m_attribs[orbit].getAttributesNames(attNames);
for (auto sit=attNames.begin(); sit!=attNames.end();++sit)
{
if (sit->substr(0,7) == "marker_")
{
std::string num = sit->substr(sit->length()-3,3);
unsigned int id = 100*(num[0]-'0')+10*(num[1]-'0')+(num[2]-'0');
if (id > maxId)
maxId = id;
AttributeMultiVector<MarkerBool>* amv = m_attribs[orbit].getDataVector<MarkerBool>(*sit);
amv->allFalse();
m_markVectors_free[orbit][0].push_back(amv);
}
}
}
m_nextMarkerId = maxId+1;
}
void GenericMap::removeMarkVectors()
{
for (unsigned int orbit=0; orbit<NB_ORBITS;++orbit)
{
std::vector<std::string> attNames;
m_attribs[orbit].getAttributesNames(attNames);
for (auto sit=attNames.begin(); sit!=attNames.end();++sit)
{
if (sit->substr(0,7) == "marker_")
{
m_attribs[orbit].removeAttribute<MarkerBool>(*sit);
}
}
}
m_nextMarkerId = 0;
}
} // namespace CGoGN } // namespace CGoGN
...@@ -128,6 +128,7 @@ bool MapMono::loadMapBin(const std::string& filename) ...@@ -128,6 +128,7 @@ bool MapMono::loadMapBin(const std::string& filename)
bool MapMono::copyFrom(const GenericMap& map) bool MapMono::copyFrom(const GenericMap& map)
{ {
if (mapTypeName() != map.mapTypeName()) if (mapTypeName() != map.mapTypeName())
{ {
CGoGNerr << "try to copy from incompatible type map" << CGoGNendl; CGoGNerr << "try to copy from incompatible type map" << CGoGNendl;
...@@ -143,6 +144,8 @@ bool MapMono::copyFrom(const GenericMap& map) ...@@ -143,6 +144,8 @@ bool MapMono::copyFrom(const GenericMap& map)
for (unsigned int i = 0; i < NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
m_attribs[i].copyFrom(mapM.m_attribs[i]); m_attribs[i].copyFrom(mapM.m_attribs[i]);
GenericMap::garbageMarkVectors();
// restore shortcuts // restore shortcuts
GenericMap::restore_shortcuts(); GenericMap::restore_shortcuts();
restore_topo_shortcuts(); restore_topo_shortcuts();
......
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