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
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;
// table of center of volume
......@@ -320,7 +324,9 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go
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;
......
......@@ -251,12 +251,19 @@ public:
unsigned int getAttributeBlocksPointers(unsigned int attrIndex, std::vector<T*>& vect_ptr, unsigned int& byteBlockSize);
/**
* fill a vector with attributes' names
* @param vector of names
* @return number of attribute
* fill a vector with attributes names
* @param names vector of names
* @return number of attributes
*/
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 *
**************************************/
......@@ -470,17 +477,17 @@ protected:
/**
* load xmlpart of container
*/
bool loadXmlBWF(xmlNodePtr node);
// bool loadXmlBWF(xmlNodePtr node);
/**
* load xmlpart of container
*/
bool loadXmlAN(xmlNodePtr node, unsigned int nbb);
// bool loadXmlAN(xmlNodePtr node, unsigned int nbb);
/**
* load xmlpart of container
*/
bool loadXmlDL(xmlNodePtr node);
// bool loadXmlDL(xmlNodePtr node);
public:
/**
......@@ -488,20 +495,20 @@ public:
* @param writer a xmlTextWriterPtr obj
* @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
* @param node the node of container node of xml tree
* @return the value of id of the node
*/
static unsigned int getIdXmlNode(xmlNodePtr node);
// static unsigned int getIdXmlNode(xmlNodePtr node);
/**
* load from xml node
* @param node the node of container node of xml tree
*/
bool loadXml(xmlNodePtr node);
// bool loadXml(xmlNodePtr node);
/**
* save binary file
......
......@@ -407,7 +407,6 @@ void AttributeMultiVector<T>::saveBin(CGoGNostream& fs, unsigned int id)
memcpy(buffer+len1,s2,len2);
fs.write(reinterpret_cast<const char*>(buffer),(len1+len2)*sizeof(char));
nbs[0] = m_tableData.size();
nbs[1] = nbs[0] * _BLOCKSIZE_* sizeof(T);
fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int));
......
......@@ -66,7 +66,12 @@ public:
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:
virtual void clear(bool removeAttrib) ;
/****************************************
* ATTRIBUTES MANAGEMENT *
****************************************/
......
......@@ -300,6 +300,13 @@ protected:
*/
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 *
****************************************/
......@@ -340,19 +347,24 @@ public:
*/
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
* @param filename the file name
* @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
* @param filename the file name
* @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
......@@ -368,6 +380,11 @@ public:
*/
bool loadMapBin(const std::string& filename) ;
/**
* Dump attributes types and names per orbit
*/
void dumpAttributesAndMarkers();
/****************************************
* DARTS TRAVERSALS *
****************************************/
......
......@@ -211,5 +211,13 @@ inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& na
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
......@@ -57,6 +57,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -55,6 +55,15 @@ inline void Map1::clear(bool removeAttrib)
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
* Access and Modification
*************************************************************************/
......
......@@ -63,6 +63,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -54,6 +54,13 @@ inline void Map2::clear(bool removeAttrib)
init() ;
}
inline void Map2::update_topo_shortcuts()
{
Map1::update_topo_shortcuts();
m_phi2 = getRelation("phi2");
}
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -65,6 +65,8 @@ public:
virtual void clear(bool removeAttrib);
virtual void update_topo_shortcuts();
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -57,6 +57,13 @@ inline void Map3::clear(bool removeAttrib)
init() ;
}
inline void Map3::update_topo_shortcuts()
{
Map2::update_topo_shortcuts();
m_phi3 = getRelation("phi3");
}
/*! @name Basic Topological Operators
* Access and Modification
*************************************************************************/
......
......@@ -82,6 +82,11 @@ public:
return (m_bits == 0);
}
inline void invert()
{
m_bits = ~m_bits;
}
//! Set given marks to YES
/*! @param m the marks to set
*/
......
......@@ -103,6 +103,20 @@ unsigned int AttributeContainer::getAttributesNames(std::vector<std::string>& na
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 *
**************************************/
......@@ -338,234 +352,234 @@ void AttributeContainer::removeLine(unsigned int index)
/**************************************
* SAVE & LOAD *
**************************************/
bool AttributeContainer::loadXmlBWF(xmlNodePtr node)
{
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");
//
//bool AttributeContainer::loadXmlBWF(xmlNodePtr node)
//{
// xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
// unsigned int nb = atoi((char*)prop);
prop = xmlGetProp(node, BAD_CAST "sv");
// unsigned int sv = atoi((char*)prop);
// Noooooooo!!!!
// m_tableAttribs.resize(sv);
// for (unsigned int i=0; i< sv; ++i)
// m_tableAttribs[i]=NULL;
// charge et cree les attributs
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)
// 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 << "Pb lecture attributs"<< CGoGNendl;
// CGoGNerr <<"Erreur lecture fichier XML incoherent"<< CGoGNendl;
// return false;
// }
return true;
}
bool AttributeContainer::loadXmlDL(xmlNodePtr node)
{
// charge et cree les attributs
for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
{
// get index
xmlChar* prop = xmlGetProp(x_node, BAD_CAST "id");
unsigned int id = atoi((char*)prop);
// get & set nbref
prop = xmlGetProp(x_node, BAD_CAST "refs");
unsigned int nbr = atoi((char*)prop);
setNbRefs(id, nbr);
if (nbr > 0)
{
// for (MapNameId::iterator it = m_attribNameMap.begin(); it != m_attribNameMap.end(); ++it)
// return true;
//}
//
//bool AttributeContainer::loadXmlAN(xmlNodePtr node, unsigned int nbb)
//{
// xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
//// unsigned int nb = atoi((char*)prop);
// prop = xmlGetProp(node, BAD_CAST "sv");
//// unsigned int sv = atoi((char*)prop);
//
// // Noooooooo!!!!
//// m_tableAttribs.resize(sv);
//// for (unsigned int i=0; i< sv; ++i)
//// m_tableAttribs[i]=NULL;
//
// // charge et cree les attributs
// 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())
// {
// prop = xmlGetProp(x_node, BAD_CAST (it->first).c_str());
// // 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));
// CGoGNout << "Skipping non registred attribute "<< std::string((char*)prop)<<CGoGNendl;
// }
}
}
return true;
}
void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id)
{
if (m_nbAttributes == 0)
return;
// noeud du container
int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Container");
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",id);
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "BlockSize","%u",_BLOCKSIZE_);
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize);
// recuperer le nombre d'attributs
unsigned int nbAtt = m_nbAttributes;
unsigned int sizeVectAtt = m_tableAttribs.size();
// noeud avec la liste de attributs
rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Names");
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "nb","%u",nbAtt);
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "sv","%u",sizeVectAtt);
// recuperer les attributs dans la map et les sauver
// for (std::map<std::string, unsigned int>::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it)
// 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;
//// return false;
//// }
// return true;
//}
//
//bool AttributeContainer::loadXmlDL(xmlNodePtr node)
//{
// // charge et cree les attributs
// for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
// {
// int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attribute");
// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name",BAD_CAST (it->first).c_str());
// const std::string& str_type = m_tableAttribs[it->second]->getTypeName();
// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type",BAD_CAST str_type.c_str());
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",it->second);
// rc = xmlTextWriterEndElement(writer);
// // get index
// xmlChar* prop = xmlGetProp(x_node, BAD_CAST "id");
// unsigned int id = atoi((char*)prop);
// // get & set nbref
// prop = xmlGetProp(x_node, BAD_CAST "refs");
// unsigned int nbr = atoi((char*)prop);
// setNbRefs(id, nbr);
//
// if (nbr > 0)
// {
//// for (MapNameId::iterator it = m_attribNameMap.begin(); it != m_attribNameMap.end(); ++it)
//// {
//// prop = xmlGetProp(x_node, BAD_CAST (it->first).c_str());
//// // 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));
//// }
// }
// }
// fin du noeud
rc = xmlTextWriterEndElement(writer);
// parcourir le container et sauver les lignes
rc = xmlTextWriterStartElement(writer, BAD_CAST "Data_Lines");
// return true;
//}
//
//void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id)
//{
// if (m_nbAttributes == 0)
// return;
//
// // noeud du container
// int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Container");
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",id);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "BlockSize","%u",_BLOCKSIZE_);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize);
for (unsigned int i = 0; i != m_maxSize; ++i)
{
unsigned int nbr = getNbRefs(i);
rc = xmlTextWriterStartElement(writer, BAD_CAST "Line");
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",i);
rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "refs","%u",nbr);
if (nbr > 0)
{
// tous les attributs de la ligne
// for (MapNameId::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it)
// {
// std::string st_att = m_tableAttribs[it->second]->output(i);
// rc = xmlTextWriterWriteAttribute(writer,(xmlChar*)( (it->first).c_str()), (xmlChar*)( st_att.c_str()));
// }
}
// fin du noeud Line
rc = xmlTextWriterEndElement(writer);
}
// fin du noeud Data Lines
rc = xmlTextWriterEndElement(writer);
// fin du noeud Container
rc = xmlTextWriterEndElement(writer);
}
unsigned int AttributeContainer::getIdXmlNode(xmlNodePtr node)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST "id");
unsigned int id = atoi((char*)prop);
return id;
}
bool AttributeContainer::loadXml(xmlNodePtr node)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST "BlockSize");
unsigned int bs = atoi((char*)prop);
if (bs != _BLOCKSIZE_)
{
CGoGNerr << "Chargement impossible, tailles de block differentes: "<<_BLOCKSIZE_<<" / " << bs << CGoGNendl;
return false;
}
// prop = xmlGetProp(node, BAD_CAST "id");
//
// // recuperer le nombre d'attributs
// unsigned int nbAtt = m_nbAttributes;
// unsigned int sizeVectAtt = m_tableAttribs.size();
//
// // noeud avec la liste de attributs
// rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Names");
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "nb","%u",nbAtt);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "sv","%u",sizeVectAtt);
//
// // recuperer les attributs dans la map et les sauver
//// for (std::map<std::string, unsigned int>::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it)
//// {
//// int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attribute");
//// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name",BAD_CAST (it->first).c_str());
//// const std::string& str_type = m_tableAttribs[it->second]->getTypeName();
//// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type",BAD_CAST str_type.c_str());
//// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",it->second);