Commit fdfbd068 authored by Sylvain Thery's avatar Sylvain Thery

introducing MapManipulators

parent da89af54
...@@ -50,7 +50,7 @@ namespace Regular ...@@ -50,7 +50,7 @@ namespace Regular
{ {
template <typename PFP> template <typename PFP>
class Map2MR class Map2MR: public MapManipulator
{ {
public: public:
typedef typename PFP::MAP MAP ; typedef typename PFP::MAP MAP ;
...@@ -65,6 +65,8 @@ protected: ...@@ -65,6 +65,8 @@ protected:
public: public:
Map2MR(MAP& map); Map2MR(MAP& map);
virtual MapManipulator* create(GenericMap *gm);
~Map2MR(); ~Map2MR();
//if true : tri and quad else quad //if true : tri and quad else quad
......
...@@ -44,10 +44,10 @@ namespace Regular ...@@ -44,10 +44,10 @@ namespace Regular
template <typename PFP> template <typename PFP>
Map2MR<PFP>::Map2MR(typename PFP::MAP& map) : Map2MR<PFP>::Map2MR(typename PFP::MAP& map) :
MapManipulator("DualRegular2",&map),
m_map(map), m_map(map),
shareVertexEmbeddings(false) shareVertexEmbeddings(false)
{ {
} }
template <typename PFP> template <typename PFP>
...@@ -63,6 +63,17 @@ Map2MR<PFP>::~Map2MR() ...@@ -63,6 +63,17 @@ Map2MR<PFP>::~Map2MR()
m_map.removeLevelFront(); m_map.removeLevelFront();
} }
template <typename PFP>
MapManipulator* Map2MR<PFP>::create(GenericMap *gm)
{
typename PFP::MAP* map = dynamic_cast<typename PFP::MAP*>(gm);
if (map != NULL)
return (new Map2MR<PFP>(*map));
else
return NULL;
}
template <typename PFP> template <typename PFP>
void Map2MR<PFP>::addNewLevel(bool embedNewVertices) void Map2MR<PFP>::addNewLevel(bool embedNewVertices)
{ {
......
...@@ -73,6 +73,7 @@ inline int getSystemNumberOfCores(bool hyperthreading=false) ...@@ -73,6 +73,7 @@ inline int getSystemNumberOfCores(bool hyperthreading=false)
class AttributeHandlerGen ; class AttributeHandlerGen ;
class DartMarkerGen ; class DartMarkerGen ;
class CellMarkerGen ; class CellMarkerGen ;
class MapManipulator;
class GenericMap class GenericMap
{ {
...@@ -98,11 +99,11 @@ protected: ...@@ -98,11 +99,11 @@ protected:
static std::map<std::string, RegisteredBaseAttribute*>* m_attributes_registry_map; static std::map<std::string, RegisteredBaseAttribute*>* m_attributes_registry_map;
static int m_nbInstances; static int m_nbInstances;
// buffer for less memory allocation /// buffer for less memory allocation
static std::vector< std::vector<Dart>* >* s_vdartsBuffers; static std::vector< std::vector<Dart>* >* s_vdartsBuffers;
static std::vector< std::vector<unsigned int>* >* s_vintsBuffers; static std::vector< std::vector<unsigned int>* >* s_vintsBuffers;
// table of instancied maps for Dart/CellMarker release /// table of instancied maps for Dart/CellMarker release
static std::vector<GenericMap*>* s_instances; static std::vector<GenericMap*>* s_instances;
...@@ -177,6 +178,34 @@ public: ...@@ -177,6 +178,34 @@ public:
virtual void clear(bool removeAttrib) ; virtual void clear(bool removeAttrib) ;
/****************************************
* MANIPULATOR MANAGEMENT *
****************************************/
protected:
/// manipulator pointer to Manipulator object that currently work on map
MapManipulator* m_manipulator;
public:
/**
* @brief ask for associating manipulator to the map
* @param ptr Manipulator ptr
* @return ok or not
*/
bool askManipulate(MapManipulator* ptr);
/**
* @brief release the map from manipulator
* @param ptr manipulator asking for release
* @return ok or not
*/
bool releaseManipulate(MapManipulator* ptr);
/**
* @brief get the manipulator
* @return manipulator ptr
*/
MapManipulator* getManipulator();
/**************************************** /****************************************
* DARTS MANAGEMENT * * DARTS MANAGEMENT *
****************************************/ ****************************************/
...@@ -461,7 +490,7 @@ public: ...@@ -461,7 +490,7 @@ 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; virtual void dumpCSV() const;
public: public:
/** /**
...@@ -472,39 +501,32 @@ public: ...@@ -472,39 +501,32 @@ public:
} ; } ;
/**
* @brief The MapManipulator class
*/
class MapManipulator
{
protected:
std::string m_name;
public:
MapManipulator(const std::string& name, GenericMap *gm):
m_name(name)
{
gm->askManipulate(this);
}
~MapManipulator():
m_name(name)
{
gm->releaseManipulate(this);
}
const std::string& name() { return m_name;}
virtual MapManipulator* create(GenericMap *gm);
};
//
//template <typename MAP>
//bool foreach_dart_of_orbit_in_parent(MAP* ptrMap, unsigned int orbit, Dart d, FunctorType& f, unsigned int thread = 0)
//{
// switch(orbit)
// {
// case DART: return f(d);
// case VERTEX: return ptrMap->MAP::ParentMap::foreach_dart_of_vertex(d, f, thread) ;
// case EDGE: return ptrMap->MAP::ParentMap::foreach_dart_of_edge(d, f, thread) ;
// case ORIENTED_FACE: return ptrMap->MAP::ParentMap::foreach_dart_of_oriented_face(d, f, thread) ;
// case FACE: return ptrMap->MAP::ParentMap::foreach_dart_of_face(d, f, thread) ;
// case VOLUME: return ptrMap->MAP::ParentMap::foreach_dart_of_volume(d, f, thread) ;
// default: assert(!"Cells of this dimension are not handled") ;
// }
// return false ;
//}
//
//template <typename MAP>
//bool foreach_dart_of_orbit_in_parent2(MAP* ptrMap, unsigned int orbit, Dart d, FunctorType& f, unsigned int thread = 0)
//{
// switch(orbit)
// {
// case DART: return f(d);
// case VERTEX: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_vertex(d, f,thread) ;
// case EDGE: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_edge(d, f, thread) ;
// case ORIENTED_FACE: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_oriented_face(d, f, thread) ;
// case FACE: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_face(d, f, thread) ;
// case VOLUME: return ptrMap->MAP::ParentMap::ParentMap::foreach_dart_of_volume(d, f, thread) ;
// default: assert(!"Cells of this dimension are not handled") ;
// }
// return false ;
//}
} //namespace CGoGN } //namespace CGoGN
......
...@@ -306,6 +306,8 @@ public: ...@@ -306,6 +306,8 @@ public:
bool copyFromOtherType(const MapMono& map); bool copyFromOtherType(const MapMono& map);
void restore_topo_shortcuts(); void restore_topo_shortcuts();
virtual void dumpCSV() const;
} ; } ;
} //namespace CGoGN } //namespace CGoGN
......
...@@ -844,8 +844,6 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) ...@@ -844,8 +844,6 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
void AttributeContainer::dumpCSV() const void AttributeContainer::dumpCSV() const
{ {
CGoGNout << "Container of "<<orbitName(this->getOrbit())<< CGoGNendl;
CGoGNout << "Name ; ;"; CGoGNout << "Name ; ;";
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i) for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{ {
...@@ -887,6 +885,7 @@ void AttributeContainer::dumpCSV() const ...@@ -887,6 +885,7 @@ void AttributeContainer::dumpCSV() const
} }
CGoGNout << CGoGNendl; CGoGNout << CGoGNendl;
} }
CGoGNout << CGoGNendl;
} }
void AttributeContainer::dumpByLines() const void AttributeContainer::dumpByLines() const
......
...@@ -55,6 +55,7 @@ std::vector<GenericMap*>* GenericMap::s_instances=NULL; ...@@ -55,6 +55,7 @@ std::vector<GenericMap*>* GenericMap::s_instances=NULL;
GenericMap::GenericMap(): GenericMap::GenericMap():
m_manipulator(NULL),
m_nextMarkerId(0) m_nextMarkerId(0)
{ {
if(m_attributes_registry_map == NULL) if(m_attributes_registry_map == NULL)
...@@ -166,6 +167,36 @@ GenericMap::~GenericMap() ...@@ -166,6 +167,36 @@ GenericMap::~GenericMap()
s_instances->pop_back(); s_instances->pop_back();
} }
bool GenericMap::askManipulate(MapManipulator* ptr)
{
if (m_manipulator == NULL)
{
CGoGNerr << "Map already manipulated by other manipulator" << CGoGNendl;
return false;
}
m_manipulator = ptr;
return true;
}
MapManipulator* GenericMap::getManipulator()
{
return m_manipulator;
}
bool GenericMap::releaseManipulate(MapManipulator* ptr)
{
if (m_manipulator != ptr)
{
CGoGNerr << "Wrong manipulator want to release the map" << CGoGNendl;
return false;
}
m_manipulator = NULL;
return true;
}
void GenericMap::init(bool addBoundaryMarkers) void GenericMap::init(bool addBoundaryMarkers)
{ {
for(unsigned int i = 0; i < NB_ORBITS; ++i) for(unsigned int i = 0; i < NB_ORBITS; ++i)
...@@ -499,6 +530,7 @@ void GenericMap::dumpCSV() const ...@@ -499,6 +530,7 @@ void GenericMap::dumpCSV() const
{ {
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{ {
CGoGNout << "Container of "<<orbitName(orbit)<< CGoGNendl;
m_attribs[orbit].dumpCSV(); m_attribs[orbit].dumpCSV();
} }
CGoGNout << CGoGNendl; CGoGNout << CGoGNendl;
......
...@@ -230,17 +230,25 @@ bool MapMulti::saveMapBin(const std::string& filename) const ...@@ -230,17 +230,25 @@ bool MapMulti::saveMapBin(const std::string& filename) const
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);
// save mr_attrtibs
m_mrattribs.saveBin(fs, 00); m_mrattribs.saveBin(fs, 00);
// save current level
fs.write(reinterpret_cast<const char*>(&m_mrCurrentLevel), sizeof(unsigned int)); fs.write(reinterpret_cast<const char*>(&m_mrCurrentLevel), sizeof(unsigned int));
// save table of nb darts per level
unsigned int nb = m_mrNbDarts.size(); unsigned int nb = m_mrNbDarts.size();
fs.write(reinterpret_cast<const char*>(&nb), sizeof(unsigned int)); fs.write(reinterpret_cast<const char*>(&nb), sizeof(unsigned int));
fs.write(reinterpret_cast<const char*>(&(m_mrNbDarts[0])), nb *sizeof(unsigned int)); fs.write(reinterpret_cast<const char*>(&(m_mrNbDarts[0])), nb *sizeof(unsigned int));
// nb = m_mrLevelStack.size();
// fs.write(reinterpret_cast<const char*>(&nb), sizeof(unsigned int));
// fs.write(reinterpret_cast<const char*>(&(m_mrLevelStack[0])), nb *sizeof(unsigned int));
return true; return true;
} }
bool MapMulti::loadMapBin(const std::string& filename) bool MapMulti::loadMapBin(const std::string& filename)
{ {
CGoGNistream fs(filename.c_str(), std::ios::in|std::ios::binary); CGoGNistream fs(filename.c_str(), std::ios::in|std::ios::binary);
...@@ -250,7 +258,18 @@ bool MapMulti::loadMapBin(const std::string& filename) ...@@ -250,7 +258,18 @@ bool MapMulti::loadMapBin(const std::string& filename)
return false; return false;
} }
GenericMap::clear(true); // clear the map but do not insert boundary markers dart attribute
GenericMap::init(false);
// init MR data without adding the attributes
m_mrattribs.clear(true) ;
m_mrattribs.setRegistry(m_attributes_registry_map) ;
m_mrDarts.clear() ;
m_mrDarts.reserve(16) ;
m_mrNbDarts.clear();
m_mrNbDarts.reserve(16);
m_mrLevelStack.clear() ;
m_mrLevelStack.reserve(16) ;
// read info // read info
char* buff = new char[256]; char* buff = new char[256];
...@@ -298,10 +317,12 @@ bool MapMulti::loadMapBin(const std::string& filename) ...@@ -298,10 +317,12 @@ bool MapMulti::loadMapBin(const std::string& filename)
m_attribs[id].loadBin(fs); m_attribs[id].loadBin(fs);
} }
AttributeContainer::loadBinId(fs); // not used but need to read to skip AttributeContainer::loadBinId(fs); // not used but need to read for skipping data file
m_mrattribs.loadBin(fs); m_mrattribs.loadBin(fs);
// read current level
fs.read(reinterpret_cast<char*>(&m_mrCurrentLevel), sizeof(unsigned int)); fs.read(reinterpret_cast<char*>(&m_mrCurrentLevel), sizeof(unsigned int));
// read table of nb darts per level
unsigned int nb; unsigned int nb;
fs.read(reinterpret_cast<char*>(&nb), sizeof(unsigned int)); fs.read(reinterpret_cast<char*>(&nb), sizeof(unsigned int));
m_mrNbDarts.resize(nb); m_mrNbDarts.resize(nb);
...@@ -508,4 +529,14 @@ void MapMulti::compactTopo() ...@@ -508,4 +529,14 @@ void MapMulti::compactTopo()
} }
void MapMulti::dumpCSV() const
{
CGoGNout << "Container of MR_DART"<< CGoGNendl;
m_mrattribs.dumpCSV();
CGoGNout << CGoGNendl;
GenericMap::dumpCSV();
}
} //namespace CGoGN } //namespace CGoGN
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