Commit c41b51f0 authored by Sylvain Thery's avatar Sylvain Thery

marker names & load/save/copy ok

parent 3328e365
......@@ -35,3 +35,10 @@ add_executable( Geom_intersectionD ./Geom_intersection.cpp)
target_link_libraries( Geom_intersectionD
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
add_executable( loadSave ./loadSave.cpp)
target_link_libraries( loadSave
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
add_executable( copyfrom ./copyfrom.cpp)
target_link_libraries( copyfrom
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
......@@ -37,319 +37,6 @@ public:
//template <>
//class AttributeMultiVector<MarkerBool> : public AttributeMultiVectorGen
//{
// /**
// * table of blocks of data pointers: vectors!
// */
// std::vector< unsigned char* > m_tableData;
//public:
// AttributeMultiVector(const std::string& strName, const std::string& strType):
// AttributeMultiVectorGen(strName, strType)
// {
// m_tableData.reserve(1024);
// }
// AttributeMultiVector()
// {
// m_tableData.reserve(1024);
// }
// ~AttributeMultiVector() {}
// AttributeMultiVectorGen* new_obj()
// {
// AttributeMultiVectorGen* ptr = new AttributeMultiVector<MarkerBool>;
// ptr->setTypeName(m_typeName);
// return ptr;
// }
// /**************************************
// * MULTI VECTOR MANAGEMENT *
// **************************************/
// void addBlock()
// {
// unsigned char* ptr = new unsigned char[_BLOCKSIZE_];
// memset(ptr,0,_BLOCKSIZE_);
// m_tableData.push_back(ptr);
// }
// void setNbBlocks(unsigned int nbb)
// {
// if (nbb >= m_tableData.size())
// {
// for (unsigned int i= m_tableData.size(); i <nbb; ++i)
// addBlock();
// }
// else
// {
// for (unsigned int i = m_tableData.size()-1; i>=nbb; --i)
// delete[] m_tableData[i];
// m_tableData.resize(nbb);
// }
// }
// unsigned int getNbBlocks() const
// {
// return m_tableData.size();
// }
//// void addBlocksBefore(unsigned int nbb);
// bool copy(const AttributeMultiVectorGen* atmvg)
// {
// const AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<const AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to copy attributes of different type" << CGoGNendl;
// return false;
// }
//// if (atmv->m_typeName != m_typeName)
//// {
//// CGoGNerr << "trying to copy attributes with different type names" << CGoGNendl;
//// return false;
//// }
// m_tableData.resize( atmv->m_tableData.size() );
// for (unsigned int i = 0; i < atmv->m_tableData.size(); ++i)
// m_tableData[i] = atmv->m_tableData[i];
// return true;
// }
// bool swap(AttributeMultiVectorGen* atmvg)
// {
// AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to swap attributes of different type" << CGoGNendl;
// return false;
// }
// if (atmv->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to swap attributes with different type names" << CGoGNendl;
// return false;
// }
// m_tableData.swap(atmv->m_tableData) ;
// return true;
// }
// bool merge(const AttributeMultiVectorGen& att)
// {
// const AttributeMultiVector<MarkerBool>* attrib = dynamic_cast< const AttributeMultiVector<MarkerBool>* >(&att);
// if (attrib==NULL)
// {
// CGoGNerr << "trying to merge attributes of different type" << CGoGNendl;
// return false;
// }
// if (attrib->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to merge attributes with different type names" << CGoGNendl;
// return false;
// }
// for (auto it = attrib->m_tableData.begin(); it != attrib->m_tableData.end(); ++it)
// m_tableData.push_back(*it);
// return true;
// }
// void clear()
// {
// m_tableData.clear();
// }
// int getSizeOfType() const
// {
// return sizeof(bool); // ?
// }
// void allFalse()
// {
//// std::cout << "Marker "<<this->getName()<<" - allFalse"<< std::endl;
// for (unsigned int i = 0; i < m_tableData.size(); ++i)
// {
// memset(m_tableData[i],0,_BLOCKSIZE_);
// }
// }
// /**************************************
// * DATA ACCESS *
// **************************************/
// void setFalse(unsigned int i)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = 0;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET FALSE: "<< this->operator[](i)<< std::endl;
// }
// void setTrue(unsigned int i)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = 1;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET TRUE: "<< this->operator[](i)<< std::endl;
// }
// void setVal(unsigned int i, bool b)
// {
// m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] = b;
//// std::cout << "Marker "<<this->getName()<<" - ";
//// std::cout << "SET VAL: "<< b << " -> "<< this->operator[](i)<< std::endl;
// }
// /**
// * get a const reference on a elt
// * @param i index of element
// */
// bool operator[](unsigned int i) const
// {
//// std::cout << "BITS="<<std::hex<< m_tableData[jj][x]<< " MASK="<<mask<<" ~MASK="<<~mask<<std::endl;
// return m_tableData[i / _BLOCKSIZE_][i % _BLOCKSIZE_] !=0;
// }
// /**
// * Get the addresses of each block of data
// */
// unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& /*byteBlockSize*/) const
// {
// CGoGNerr << "DO NOT USE getBlocksPointers with bool attribute"<< CGoGNendl;
// return 0;
//// addr.reserve(m_tableData.size());
//// addr.clear();
//// for (auto it = m_tableData.begin(); it != m_tableData.end(); ++it)
//// addr.push_back(NULL );
//// return addr.size();
// }
// /**************************************
// * LINES MANAGEMENT *
// **************************************/
// void initElt(unsigned int id)
// {
//// std::cout << "Marker "<<this->getName()<<" - InitElt"<< std::endl;
// setFalse(id);
// }
// void copyElt(unsigned int dst, unsigned int src)
// {
//// std::cout << "Marker "<<this->getName()<<" - CopyElt"<< std::endl;
// setVal(dst,this->operator [](src));
// }
// void swapElt(unsigned int id1, unsigned int id2)
// {
//// std::cout << "Marker "<<this->getName()<<" - SwapElt"<< std::endl;
// bool data = this->operator [](id1);
// setVal(id1,this->operator [](id2));
// setVal(id2,data);
// }
// /**
// * swap two elements in container (useful for compact function)
// * @param src_b block index of source element
// * @param src_id index in block of source element
// * @param dst_b block index of destination element
// * @param dst_id index in block of destination element
// */
// void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id)
// {
//// std::cout << "Marker "<<this->getName()<<" - overwrite"<< std::endl;
// m_tableData[dst_b][dst_id] = m_tableData[src_b][src_id];
// }
// /**************************************
// * SAVE & LOAD *
// **************************************/
// /**
// * Sauvegarde binaire
// * @param fs filestream
// * @param id id of mv
// */
// void saveBin(CGoGNostream& fs, unsigned int id)
// {
//// unsigned int nbs[3];
//// nbs[0] = id;
//// int len1 = m_attrName.size()+1;
//// int len2 = m_typeName.size()+1;
//// nbs[1] = len1;
//// nbs[2] = len2;
//// fs.write(reinterpret_cast<const char*>(nbs),3*sizeof(unsigned int));
//// // store names
//// char buffer[256];
//// const char* s1 = m_attrName.c_str();
//// memcpy(buffer,s1,len1);
//// const char* s2 = m_typeName.c_str();
//// 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_/32;
//// fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int));
//// for (auto ptrIt = m_tableData.begin(); ptrIt!=m_tableData.end(); ++ptrIt)
//// fs.write(reinterpret_cast<const char*>(*ptrIt),_BLOCKSIZE_/8);
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// bool loadBin(CGoGNistream& fs)
// {
//// unsigned int nbs[2];
//// fs.read(reinterpret_cast<char*>(nbs), 2*sizeof(unsigned int));
//// unsigned int nb = nbs[0];
//// bool *bbuff = new bool[nb*_BLOCKSIZE_];
//// fs.read(reinterpret_cast<char*>(bbuff),nb*_BLOCKSIZE_*sizeof(bool));
//// // load data blocks
//// m_tableData.resize(nb);
//// for(unsigned int i = 0; i < nb; ++i)
//// {
//// m_tableData[i] = new unsigned int[_BLOCKSIZE_/32];
//// for (unsigned int j=0; j<_BLOCKSIZE_;++j)
//// fs.read(reinterpret_cast<char*>(m_tableData[i]),_BLOCKSIZE_/8);
//// }
// return true;
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// virtual void dump(unsigned int i) const
// {
// CGoGNout << this->operator[](i);
// }
//};
template <>
class AttributeMultiVector<MarkerBool> : public AttributeMultiVectorGen
{
......@@ -490,7 +177,6 @@ public:
inline void allFalse()
{
// std::cout << "Marker "<<this->getName()<<" - allFalse"<< std::endl;
for (unsigned int i = 0; i < m_tableData.size(); ++i)
{
unsigned int *ptr =m_tableData[i];
......@@ -513,9 +199,6 @@ public:
unsigned int y = j%32;
unsigned int mask = 1 << y;
m_tableData[jj][x] &= ~mask;
// std::cout << "Marker "<<this->getName()<<" - ";
// std::cout << "SET FALSE: "<< this->operator[](i)<< std::endl;
}
inline void setTrue(unsigned int i)
......@@ -526,9 +209,6 @@ public:
unsigned int y = j%32;
unsigned int mask = 1 << y;
m_tableData[jj][x] |= mask;
// std::cout << "Marker "<<this->getName()<<" - ";
// std::cout << "SET TRUE: "<< this->operator[](i)<< std::endl;
}
inline void setVal(unsigned int i, bool b)
......@@ -543,9 +223,6 @@ public:
m_tableData[jj][x] |= mask;
else
m_tableData[jj][x] &= ~mask;
// std::cout << "Marker "<<this->getName()<<" - ";
// std::cout << "SET VAL: "<< b << " -> "<< this->operator[](i)<< std::endl;
}
/**
......@@ -561,7 +238,6 @@ public:
unsigned int mask = 1 << y;
// std::cout << "BITS="<<std::hex<< m_tableData[jj][x]<< " MASK="<<mask<<" ~MASK="<<~mask<<std::endl;
return (m_tableData[jj][x] & mask) != 0;
}
......@@ -587,20 +263,17 @@ public:
inline void initElt(unsigned int id)
{
// std::cout << "Marker "<<this->getName()<<" - InitElt"<< std::endl;
setFalse(id);
}
inline void copyElt(unsigned int dst, unsigned int src)
{
// std::cout << "Marker "<<this->getName()<<" - CopyElt"<< std::endl;
setVal(dst,this->operator [](src));
}
inline void swapElt(unsigned int id1, unsigned int id2)
{
// std::cout << "Marker "<<this->getName()<<" - SwapElt"<< std::endl;
bool data = this->operator [](id1);
setVal(id1,this->operator [](id2));
setVal(id2,data);
......@@ -615,7 +288,6 @@ public:
*/
void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id)
{
// std::cout << "Marker "<<this->getName()<<" - overwrite"<< std::endl;
bool b = m_tableData[src_b][src_id/32] & (1 << (src_id%32));
unsigned int mask = 1 << (dst_id%32);
......@@ -673,15 +345,12 @@ public:
unsigned int nb = nbs[0];
bool *bbuff = new bool[nb*_BLOCKSIZE_];
fs.read(reinterpret_cast<char*>(bbuff),nb*_BLOCKSIZE_*sizeof(bool));
// load data blocks
m_tableData.resize(nb);
for(unsigned int i = 0; i < nb; ++i)
{
m_tableData[i] = new unsigned int[_BLOCKSIZE_/32];
for (unsigned int j=0; j<_BLOCKSIZE_;++j)
fs.read(reinterpret_cast<char*>(m_tableData[i]),_BLOCKSIZE_/8);
}
......@@ -700,300 +369,5 @@ public:
//template <>
//class AttributeMultiVector<MarkerBool> : public AttributeMultiVectorGen
//{
// /**
// * table of blocks of data pointers: vectors!
// */
// std::vector< std::vector<bool>* > m_tableData;
//public:
// AttributeMultiVector(const std::string& strName, const std::string& strType):
// AttributeMultiVectorGen(strName, strType)
// {
// m_tableData.reserve(1024);
// }
// AttributeMultiVector()
// {
// m_tableData.reserve(1024);
// }
// ~AttributeMultiVector() {}
// AttributeMultiVectorGen* new_obj()
// {
// AttributeMultiVectorGen* ptr = new AttributeMultiVector<MarkerBool>;
// ptr->setTypeName(m_typeName);
// return ptr;
// }
// /**************************************
// * MULTI VECTOR MANAGEMENT *
// **************************************/
// void addBlock()
// {
// std::vector<bool>* vb = new std::vector<bool>(_BLOCKSIZE_,false);
// m_tableData.push_back(vb);
// }
// void setNbBlocks(unsigned int nbb)
// {
// if (nbb >= m_tableData.size())
// {
// for (unsigned int i= m_tableData.size(); i <nbb; ++i)
// addBlock();
// }
// else
// {
// // not really released ?
// m_tableData.resize(nbb);
// }
// }
// unsigned int getNbBlocks() const
// {
// return m_tableData.size();
// }
//// void addBlocksBefore(unsigned int nbb);
// bool copy(const AttributeMultiVectorGen* atmvg)
// {
// const AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<const AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to copy attributes of different type" << CGoGNendl;
// return false;
// }
//// if (atmv->m_typeName != m_typeName)
//// {
//// CGoGNerr << "trying to copy attributes with different type names" << CGoGNendl;
//// return false;
//// }
// for (unsigned int i = 0; i < atmv->m_tableData.size(); ++i)
// *(m_tableData[i]) = *(atmv->m_tableData[i]);
// return true;
// }
// bool swap(AttributeMultiVectorGen* atmvg)
// {
// AttributeMultiVector<MarkerBool>* atmv = dynamic_cast<AttributeMultiVector<MarkerBool>*>(atmvg);
// if (atmv == NULL)
// {
// CGoGNerr << "trying to swap attributes of different type" << CGoGNendl;
// return false;
// }
// if (atmv->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to swap attributes with different type names" << CGoGNendl;
// return false;
// }
// m_tableData.swap(atmv->m_tableData) ;
// return true;
// }
// bool merge(const AttributeMultiVectorGen& att)
// {
// const AttributeMultiVector<MarkerBool>* attrib = dynamic_cast< const AttributeMultiVector<MarkerBool>* >(&att);
// if (attrib==NULL)
// {
// CGoGNerr << "trying to merge attributes of different type" << CGoGNendl;
// return false;
// }
// if (attrib->m_typeName != m_typeName)
// {
// CGoGNerr << "trying to merge attributes with different type names" << CGoGNendl;
// return false;
// }
// for (auto it = attrib->m_tableData.begin(); it != attrib->m_tableData.end(); ++it)
// m_tableData.push_back(*it);
// return true;
// }
// void clear()
// {
// for (auto it=m_tableData.begin(); it !=m_tableData.end(); ++it)
// delete *it;
// m_tableData.clear();
// }
// int getSizeOfType() const
// {
// return sizeof(bool); // ?
// }
// void allFalse()
// {
// for (unsigned int i = 0; i < m_tableData.size(); ++i)
// m_tableData[i]->assign(_BLOCKSIZE_,false);
// }
// /**************************************
// * DATA ACCESS *
// **************************************/
// /**
// * get a reference on a elt
// * @param i index of element
// */
// std::vector<bool>::reference operator[](unsigned int i)
// {
// return m_tableData[i / _BLOCKSIZE_]->operator[](i % _BLOCKSIZE_);
// }
// /**
// * get a const reference on a elt
// * @param i index of element
// */
// bool operator[](unsigned int i) const
// {
// return m_tableData[i / _BLOCKSIZE_]->operator[](i % _BLOCKSIZE_);
// }
// /**
// * Get the addresses of each block of data
// */
// unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& /*byteBlockSize*/) const
// {
// CGoGNerr << "DO NOT USE getBlocksPointers with bool attribute"<< CGoGNendl;
// addr.reserve(m_tableData.size());
// addr.clear();
// for (auto it = m_tableData.begin(); it != m_tableData.end(); ++it)
// addr.push_back(NULL );
// return addr.size();
// }
// /**************************************
// * LINES MANAGEMENT *
// **************************************/
// void initElt(unsigned int id)
// {
// m_tableData[id / _BLOCKSIZE_]->operator[](id % _BLOCKSIZE_) = false; // T(0);
// }
// void copyElt(unsigned int dst, unsigned int src)
// {
// m_tableData[dst / _BLOCKSIZE_]->operator[](dst % _BLOCKSIZE_) = m_tableData[src / _BLOCKSIZE_]->operator[](src % _BLOCKSIZE_);
// }
// void swapElt(unsigned int id1, unsigned int id2)
// {
// bool data = m_tableData[id1 / _BLOCKSIZE_]->operator[](id1 % _BLOCKSIZE_) ;
// m_tableData[id1 / _BLOCKSIZE_]->operator[](id1 % _BLOCKSIZE_) = m_tableData[id2 / _BLOCKSIZE_]->operator[](id2 % _BLOCKSIZE_) ;
// m_tableData[id2 / _BLOCKSIZE_]->operator[](id2 % _BLOCKSIZE_) = data ;
// }
// /**
// * swap two elements in container (useful for compact function)
// * @param src_b block index of source element
// * @param src_id index in block of source element
// * @param dst_b block index of destination element
// * @param dst_id index in block of destination element
// */
// void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id)
// {
// m_tableData[dst_b]->operator[](dst_id) = m_tableData[src_b]->operator[](src_id);
// }
// /**************************************
// * SAVE & LOAD *
// **************************************/
// /**
// * Sauvegarde binaire
// * @param fs filestream
// * @param id id of mv
// */
// void saveBin(CGoGNostream& fs, unsigned int id)
// {
// unsigned int nbs[3];
// nbs[0] = id;
// int len1 = m_attrName.size()+1;
// int len2 = m_typeName.size()+1;
// nbs[1] = len1;
// nbs[2] = len2;
// fs.write(reinterpret_cast<const char*>(nbs),3*sizeof(unsigned int));
// // store names
// char buffer[256];
// const char* s1 = m_attrName.c_str();
// memcpy(buffer,s1,len1);
// const char* s2 = m_typeName.c_str();
// 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_/8;
// fs.write(reinterpret_cast<const char*>(nbs),2*sizeof(unsigned int));
// unsigned int nb = _BLOCKSIZE_*m_tableData.size();
// bool *bbuff = new bool[nb];
// bool *ptr = bbuff;
// for (unsigned int i =0; i<m_tableData.size(); ++i)
// for (unsigned int j=0; j<_BLOCKSIZE_;++j)
// *ptr++ = m_tableData[i]->operator[](j);
// fs.write(reinterpret_cast<const char*>(bbuff),nb*sizeof(bool));
// delete[] bbuff;
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// bool loadBin(CGoGNistream& fs)
// {
// unsigned int nbs[2];
// fs.read(reinterpret_cast<char*>(nbs), 2*sizeof(unsigned int));
// unsigned int nb = nbs[0];
// bool *bbuff = new bool[nb*_BLOCKSIZE_];
// fs.read(reinterpret_cast<char*>(bbuff),nb*_BLOCKSIZE_*sizeof(bool));
// // load data blocks
// m_tableData.resize(nb);
// bool *ptr = bbuff;
// for(unsigned int i = 0; i < nb; ++i)
// {
// m_tableData[i] = new std::vector<bool>(_BLOCKSIZE_);
// for (unsigned int j=0; j<_BLOCKSIZE_;++j)
// m_tableData[i]->operator[](j) = *ptr++;
// }
// delete[] bbuff;
// return true;
// }
// /**
// * lecture binaire
// * @param fs filestream
// */
// virtual void dump(unsigned int i) const
// {
// CGoGNout << this->operator[](i);
// }
//};
} // namespace CGoGN
......@@ -123,6 +123,8 @@ protected:
std::vector< AttributeMultiVector<MarkerBool>* > m_markVectors_free[NB_ORBITS][NB_THREAD] ;
std::mutex m_MarkerStorageMutex[NB_ORBITS];
unsigned int m_nextMarkerId;
/**
* Reserved boundary markers
*/
......@@ -159,7 +161,7 @@ public:
protected: