Commit adb3b266 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

MAJ saveMapBin et loadMapBin

parent 8d0fb6f4
...@@ -52,9 +52,13 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -52,9 +52,13 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go
if (m_attIndex.map() != &map) if (m_attIndex.map() != &map)
{ {
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
} }
m_nbDarts = 0; m_nbDarts = 0;
// table of center of volume // table of center of volume
...@@ -320,7 +324,9 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go ...@@ -320,7 +324,9 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go
if (m_attIndex.map() != &map) if (m_attIndex.map() != &map)
{ {
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
} }
m_nbDarts = 0; m_nbDarts = 0;
......
...@@ -251,12 +251,19 @@ public: ...@@ -251,12 +251,19 @@ public:
unsigned int getAttributeBlocksPointers(unsigned int attrIndex, std::vector<T*>& vect_ptr, unsigned int& byteBlockSize); unsigned int getAttributeBlocksPointers(unsigned int attrIndex, std::vector<T*>& vect_ptr, unsigned int& byteBlockSize);
/** /**
* fill a vector with attributes' names * fill a vector with attributes names
* @param vector of names * @param names vector of names
* @return number of attribute * @return number of attributes
*/ */
unsigned int getAttributesNames(std::vector<std::string>& names); unsigned int getAttributesNames(std::vector<std::string>& names);
/**
* fill a vector with attribute type names
* @param types vector of type names
* @return number of attributes
*/
unsigned int getAttributesTypes(std::vector<std::string>& types);
/************************************** /**************************************
* CONTAINER MANAGEMENT * * CONTAINER MANAGEMENT *
**************************************/ **************************************/
...@@ -470,17 +477,17 @@ protected: ...@@ -470,17 +477,17 @@ protected:
/** /**
* load xmlpart of container * load xmlpart of container
*/ */
bool loadXmlBWF(xmlNodePtr node); // bool loadXmlBWF(xmlNodePtr node);
/** /**
* load xmlpart of container * load xmlpart of container
*/ */
bool loadXmlAN(xmlNodePtr node, unsigned int nbb); // bool loadXmlAN(xmlNodePtr node, unsigned int nbb);
/** /**
* load xmlpart of container * load xmlpart of container
*/ */
bool loadXmlDL(xmlNodePtr node); // bool loadXmlDL(xmlNodePtr node);
public: public:
/** /**
...@@ -488,20 +495,20 @@ public: ...@@ -488,20 +495,20 @@ public:
* @param writer a xmlTextWriterPtr obj * @param writer a xmlTextWriterPtr obj
* @param id the id to save * @param id the id to save
*/ */
void saveXml(xmlTextWriterPtr writer, unsigned int id); // void saveXml(xmlTextWriterPtr writer, unsigned int id);
/** /**
* get id from xml node * get id from xml node
* @param node the node of container node of xml tree * @param node the node of container node of xml tree
* @return the value of id of the node * @return the value of id of the node
*/ */
static unsigned int getIdXmlNode(xmlNodePtr node); // static unsigned int getIdXmlNode(xmlNodePtr node);
/** /**
* load from xml node * load from xml node
* @param node the node of container node of xml tree * @param node the node of container node of xml tree
*/ */
bool loadXml(xmlNodePtr node); // bool loadXml(xmlNodePtr node);
/** /**
* save binary file * save binary file
......
...@@ -407,7 +407,6 @@ void AttributeMultiVector<T>::saveBin(CGoGNostream& fs, unsigned int id) ...@@ -407,7 +407,6 @@ void AttributeMultiVector<T>::saveBin(CGoGNostream& fs, unsigned int id)
memcpy(buffer+len1,s2,len2); memcpy(buffer+len1,s2,len2);
fs.write(reinterpret_cast<const char*>(buffer),(len1+len2)*sizeof(char)); fs.write(reinterpret_cast<const char*>(buffer),(len1+len2)*sizeof(char));
nbs[0] = m_tableData.size(); nbs[0] = m_tableData.size();
nbs[1] = nbs[0] * _BLOCKSIZE_* sizeof(T); nbs[1] = nbs[0] * _BLOCKSIZE_* sizeof(T);
fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int)); fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int));
......
...@@ -66,7 +66,12 @@ public: ...@@ -66,7 +66,12 @@ public:
AttributeMultiVectorGen* addAttribute(AttributeContainer& container, const std::string& attribName) AttributeMultiVectorGen* addAttribute(AttributeContainer& container, const std::string& attribName)
{ {
return container.addAttribute<T>(attribName); unsigned int id = container.getAttributeIndex(attribName);
// new attribute
if (id == AttributeContainer::UNKNOWN)
return container.addAttribute<T>(attribName);
// or existing one
return container.getDataVector<T>(id);
} }
}; };
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
virtual void clear(bool removeAttrib) ; virtual void clear(bool removeAttrib) ;
/**************************************** /****************************************
* ATTRIBUTES MANAGEMENT * * ATTRIBUTES MANAGEMENT *
****************************************/ ****************************************/
......
...@@ -300,6 +300,13 @@ protected: ...@@ -300,6 +300,13 @@ protected:
*/ */
AttributeMultiVector<Dart>* addRelation(const std::string& name) ; AttributeMultiVector<Dart>* addRelation(const std::string& name) ;
/**
* Get attributeMultivector pointer of a relation attribute
* @param anem name of relation
* @return the attribute multi-vector pointer
*/
AttributeMultiVector<Dart>* getRelation(const std::string& name);
/**************************************** /****************************************
* THREAD MANAGEMENT * * THREAD MANAGEMENT *
****************************************/ ****************************************/
...@@ -340,19 +347,24 @@ public: ...@@ -340,19 +347,24 @@ public:
*/ */
void update_m_emb_afterLoad(); void update_m_emb_afterLoad();
/**
* update the markTables and recursively from real type the topo shortcut pointers
*/
virtual void update_topo_shortcuts();
/** /**
* Save map in a XML file * Save map in a XML file
* @param filename the file name * @param filename the file name
* @return true if OK * @return true if OK
*/ */
bool saveMapXml(const std::string& filename, bool compress = false) ; // bool saveMapXml(const std::string& filename, bool compress = false) ;
/** /**
* Load map from a XML file * Load map from a XML file
* @param filename the file name * @param filename the file name
* @return true if OK * @return true if OK
*/ */
bool loadMapXml(const std::string& filename, bool compress = false) ; // bool loadMapXml(const std::string& filename, bool compress = false) ;
/** /**
* Save map in a binary file * Save map in a binary file
...@@ -368,6 +380,11 @@ public: ...@@ -368,6 +380,11 @@ public:
*/ */
bool loadMapBin(const std::string& filename) ; bool loadMapBin(const std::string& filename) ;
/**
* Dump attributes types and names per orbit
*/
void dumpAttributesAndMarkers();
/**************************************** /****************************************
* DARTS TRAVERSALS * * DARTS TRAVERSALS *
****************************************/ ****************************************/
......
...@@ -211,5 +211,13 @@ inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& na ...@@ -211,5 +211,13 @@ inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& na
return amv ; return amv ;
} }
inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& name)
{
AttributeContainer& cont = m_attribs[DART] ;
AttributeMultiVector<Dart>* amv = cont.getDataVector<Dart>(cont.getAttributeIndex(name)) ;
return amv ;
}
} //namespace CGoGN } //namespace CGoGN
...@@ -57,6 +57,8 @@ public: ...@@ -57,6 +57,8 @@ public:
virtual void clear(bool removeAttrib); virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -55,6 +55,15 @@ inline void Map1::clear(bool removeAttrib) ...@@ -55,6 +55,15 @@ inline void Map1::clear(bool removeAttrib)
init() ; init() ;
} }
inline void Map1::update_topo_shortcuts()
{
GenericMap::update_topo_shortcuts();
m_phi1 = getRelation("phi1");
m_phi_1 = getRelation("phi_1");
}
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -63,6 +63,8 @@ public: ...@@ -63,6 +63,8 @@ public:
virtual void clear(bool removeAttrib); virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -54,6 +54,13 @@ inline void Map2::clear(bool removeAttrib) ...@@ -54,6 +54,13 @@ inline void Map2::clear(bool removeAttrib)
init() ; init() ;
} }
inline void Map2::update_topo_shortcuts()
{
Map1::update_topo_shortcuts();
m_phi2 = getRelation("phi2");
}
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -65,6 +65,8 @@ public: ...@@ -65,6 +65,8 @@ public:
virtual void clear(bool removeAttrib); virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -57,6 +57,13 @@ inline void Map3::clear(bool removeAttrib) ...@@ -57,6 +57,13 @@ inline void Map3::clear(bool removeAttrib)
init() ; init() ;
} }
inline void Map3::update_topo_shortcuts()
{
Map2::update_topo_shortcuts();
m_phi3 = getRelation("phi3");
}
/*! @name Basic Topological Operators /*! @name Basic Topological Operators
* Access and Modification * Access and Modification
*************************************************************************/ *************************************************************************/
......
...@@ -82,6 +82,11 @@ public: ...@@ -82,6 +82,11 @@ public:
return (m_bits == 0); return (m_bits == 0);
} }
inline void invert()
{
m_bits = ~m_bits;
}
//! Set given marks to YES //! Set given marks to YES
/*! @param m the marks to set /*! @param m the marks to set
*/ */
......
...@@ -103,6 +103,20 @@ unsigned int AttributeContainer::getAttributesNames(std::vector<std::string>& na ...@@ -103,6 +103,20 @@ unsigned int AttributeContainer::getAttributesNames(std::vector<std::string>& na
return m_nbAttributes ; return m_nbAttributes ;
} }
unsigned int AttributeContainer::getAttributesTypes(std::vector<std::string>& types)
{
types.clear() ;
types.reserve(m_nbAttributes) ;
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if(m_tableAttribs[i] != NULL)
types.push_back(m_tableAttribs[i]->getTypeName()) ;
}
return m_nbAttributes ;
}
/************************************** /**************************************
* CONTAINER MANAGEMENT * * CONTAINER MANAGEMENT *
**************************************/ **************************************/
...@@ -338,234 +352,234 @@ void AttributeContainer::removeLine(unsigned int index) ...@@ -338,234 +352,234 @@ void AttributeContainer::removeLine(unsigned int index)
/************************************** /**************************************
* SAVE & LOAD * * SAVE & LOAD *
**************************************/ **************************************/
//
bool AttributeContainer::loadXmlBWF(xmlNodePtr node) //bool AttributeContainer::loadXmlBWF(xmlNodePtr node)
{ //{
xmlChar* prop = xmlGetProp(node, BAD_CAST "nb"); // xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
unsigned int nb = atoi((char*)prop);
m_tableBlocksWithFree.clear();
// charge et cree les attributs
for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
{
unsigned int ind = atoi((char*)(xmlNodeGetContent(x_node)));
m_tableBlocksWithFree.push_back(ind);
}
if (m_tableBlocksWithFree.size() != nb)
{
CGoGNerr <<"Erreur lecture fichier XML incoherent"<< CGoGNendl;
return false;
}
return true;
}
bool AttributeContainer::loadXmlAN(xmlNodePtr node, unsigned int nbb)
{
xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
// unsigned int nb = atoi((char*)prop); // unsigned int nb = atoi((char*)prop);
prop = xmlGetProp(node, BAD_CAST "sv"); // m_tableBlocksWithFree.clear();
// unsigned int sv = atoi((char*)prop); //
// // charge et cree les attributs
// Noooooooo!!!! // for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
// m_tableAttribs.resize(sv); // {
// for (unsigned int i=0; i< sv; ++i) // unsigned int ind = atoi((char*)(xmlNodeGetContent(x_node)));
// m_tableAttribs[i]=NULL; // m_tableBlocksWithFree.push_back(ind);
// }
// charge et cree les attributs // if (m_tableBlocksWithFree.size() != nb)
for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
{
prop = xmlGetProp(x_node, BAD_CAST "id");
// unsigned int id = unsigned int(atoi((char*)prop);
prop = xmlGetProp(x_node, BAD_CAST "type");
// recupere l'attribut enregistrer par son type
if (m_attributes_registry_map !=NULL)
{
std::map<std::string, RegisteredBaseAttribute*>::iterator itAtt = m_attributes_registry_map->find(std::string((char*)prop));
if (itAtt == m_attributes_registry_map->end())
{
CGoGNout << "Skipping non registred attribute "<< std::string((char*)prop)<<CGoGNendl;
}
else
{
RegisteredBaseAttribute* ra = itAtt->second;
prop = xmlGetProp(x_node, BAD_CAST "name");
// ra->addAttribute(*this, std::string((char*)prop), id);
AttributeMultiVectorGen* amvg = ra->addAttribute(*this, std::string((char*)prop));
amvg->setNbBlocks(nbb);
}
}
else
{
CGoGNerr << "Attribute Registry non initialized"<< CGoGNendl;
return false;
}
}
// if (m_attribNameMap.size() != nb)
// { // {
// CGoGNerr << "Pb lecture attributs"<< CGoGNendl; // CGoGNerr <<"Erreur lecture fichier XML incoherent"<< CGoGNendl;
// return false; // return false;
// } // }
return true; // return true;
} //}
//
bool AttributeContainer::loadXmlDL(xmlNodePtr node) //bool AttributeContainer::loadXmlAN(xmlNodePtr node, unsigned int nbb)
{ //{
// charge et cree les attributs // xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next) //// unsigned int nb = atoi((char*)prop);
{ // prop = xmlGetProp(node, BAD_CAST "sv");
// get index //// unsigned int sv = atoi((char*)prop);
xmlChar* prop = xmlGetProp(x_node, BAD_CAST "id"); //
unsigned int id = atoi((char*)prop); // // Noooooooo!!!!
// get & set nbref //// m_tableAttribs.resize(sv);
prop = xmlGetProp(x_node, BAD_CAST "refs"); //// for (unsigned int i=0; i< sv; ++i)
unsigned int nbr = atoi((char*)prop); //// m_tableAttribs[i]=NULL;
setNbRefs(id, nbr); //
// // charge et cree les attributs
if (nbr > 0) // for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
{ // {
// for (MapNameId::iterator it = m_attribNameMap.begin(); it != m_attribNameMap.end(); ++it) // prop = xmlGetProp(x_node, BAD_CAST "id");
//// unsigned int id = unsigned int(atoi((char*)prop);
//
// prop = xmlGetProp(x_node, BAD_CAST "type");
// // recupere l'attribut enregistrer par son type
// if (m_attributes_registry_map !=NULL)
// {
// std::map<std::string, RegisteredBaseAttribute*>::iterator itAtt = m_attributes_registry_map->find(std::string((char*)prop));
// if (itAtt == m_attributes_registry_map->end())
// { // {
// prop = xmlGetProp(x_node, BAD_CAST (it->first).c_str()); // CGoGNout << "Skipping non registred attribute "<< std::string((char*)prop)<<CGoGNendl;
// // if name of data unkwown then error
// if (prop == NULL)
// {
// CGoGNerr << "inconsistent xml file"<<CGoGNendl;
// return false;
// }
// m_tableAttribs[it->second]->input(id, std::string((char*)prop));
// } // }
} // else
} // {
return true; // RegisteredBaseAttribute* ra = itAtt->second;
} // prop = xmlGetProp(x_node, BAD_CAST "name");
//// ra->addAttribute(*this, std::string((char*)prop), id);
void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id) // AttributeMultiVectorGen* amvg = ra->addAttribute(*this, std::string((char*)prop));
{ // amvg->setNbBlocks(nbb);
if (m_nbAttributes == 0) // }
return; // }
// else
// noeud du container // {
int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Container"); // CGoGNerr << "Attribute Registry non initialized"<< CGoGNendl;
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",id); // return false;
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "BlockSize","%u",_BLOCKSIZE_); // }
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize); // }
//// if (m_attribNameMap.size() != nb)
// recuperer le nombre d'attributs //// {
unsigned int nbAtt = m_nbAttributes; //// CGoGNerr << "Pb lecture attributs"<< CGoGNendl;
unsigned int sizeVectAtt = m_tableAttribs.size(); //// return false;
//// }
// noeud avec la liste de attributs // return true;
rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Names"); //}
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "nb","%u",nbAtt); //
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "sv","%u",sizeVectAtt); //bool AttributeContainer::loadXmlDL(xmlNodePtr node)