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

bugfix copyFrom + dumpCSV + some const

parent b50afe03
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "Algo/Export/export.h" #include "Algo/Export/export.h"
#include "Algo/Modelisation/subdivision.h" #include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -78,6 +79,7 @@ int main(int argc, char **argv) ...@@ -78,6 +79,7 @@ int main(int argc, char **argv)
MAP myMap2; MAP myMap2;
// for copying the initial mesh // for copying the initial mesh
myMap2.copyFrom(myMap); myMap2.copyFrom(myMap);
// AttributeHandler are linked to the map, need a new one // AttributeHandler are linked to the map, need a new one
VertexAttribute<VEC3, MAP_IMPL> position2 = myMap2.getAttribute<VEC3, VERTEX>(attrNames[0]); VertexAttribute<VEC3, MAP_IMPL> position2 = myMap2.getAttribute<VEC3, VERTEX>(attrNames[0]);
...@@ -96,5 +98,6 @@ int main(int argc, char **argv) ...@@ -96,5 +98,6 @@ int main(int argc, char **argv)
Algo::Surface::Export::exportOFF<PFP>(myMap2, position2, "resultCC.off"); Algo::Surface::Export::exportOFF<PFP>(myMap2, position2, "resultCC.off");
return 0; return 0;
} }
...@@ -138,7 +138,8 @@ public: ...@@ -138,7 +138,8 @@ public:
~AttributeContainer(); ~AttributeContainer();
unsigned int getOrbit(); unsigned int getOrbit() const;
void setOrbit(unsigned int orbit); void setOrbit(unsigned int orbit);
void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re); void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re);
...@@ -364,7 +365,7 @@ public: ...@@ -364,7 +365,7 @@ public:
* @param index index of the line * @param index index of the line
* @return number of refs of the line * @return number of refs of the line
*/ */
unsigned int getNbRefs(unsigned int index); unsigned int getNbRefs(unsigned int index) const;
/** /**
* set the number of refs of the given line * set the number of refs of the given line
...@@ -473,6 +474,14 @@ public: ...@@ -473,6 +474,14 @@ public:
*/ */
void copyFrom(const AttributeContainer& cont); void copyFrom(const AttributeContainer& cont);
/**
* dump the container in CSV format (; separated columns)
*/
void dumpCSV() const;
void dumpByLines() const;
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
namespace CGoGN namespace CGoGN
{ {
inline unsigned int AttributeContainer::getOrbit() inline unsigned int AttributeContainer::getOrbit() const
{ {
return m_orbit ; return m_orbit ;
} }
...@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index) ...@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index)
return false; return false;
} }
inline unsigned int AttributeContainer::getNbRefs(unsigned int index) inline unsigned int AttributeContainer::getNbRefs(unsigned int index) const
{ {
unsigned int bi = index / _BLOCKSIZE_; unsigned int bi = index / _BLOCKSIZE_;
unsigned int j = index % _BLOCKSIZE_; unsigned int j = index % _BLOCKSIZE_;
......
...@@ -176,6 +176,12 @@ public: ...@@ -176,6 +176,12 @@ public:
virtual bool loadBin(CGoGNistream& fs) = 0; virtual bool loadBin(CGoGNistream& fs) = 0;
static bool skipLoadBin(CGoGNistream& fs); static bool skipLoadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const = 0;
}; };
...@@ -266,17 +272,17 @@ public: ...@@ -266,17 +272,17 @@ public:
* ARITHMETIC OPERATIONS * * ARITHMETIC OPERATIONS *
**************************************/ **************************************/
void affect(unsigned int i, unsigned int j); // void affect(unsigned int i, unsigned int j);
void add(unsigned int i, unsigned int j); // void add(unsigned int i, unsigned int j);
void sub(unsigned int i, unsigned int j); // void sub(unsigned int i, unsigned int j);
void mult(unsigned int i, double alpha); // void mult(unsigned int i, double alpha);
void div(unsigned int i, double alpha); // void div(unsigned int i, double alpha);
void lerp(unsigned res, unsigned int i, unsigned int j, double alpha); // void lerp(unsigned res, unsigned int i, unsigned int j, double alpha);
/************************************** /**************************************
* SAVE & LOAD * * SAVE & LOAD *
...@@ -294,6 +300,13 @@ public: ...@@ -294,6 +300,13 @@ public:
* @param fs filestream * @param fs filestream
*/ */
bool loadBin(CGoGNistream& fs); bool loadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const;
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs) ...@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs)
return true; return true;
} }
template <typename T>
void AttributeMultiVector<T>::dump(unsigned int i) const
{
CGoGNout << this->operator[](i);
}
} // namespace CGoGN } // namespace CGoGN
...@@ -48,6 +48,13 @@ public: ...@@ -48,6 +48,13 @@ public:
static std::string CGoGNnameOfType() { return ""; } static std::string CGoGNnameOfType() { return ""; }
}; };
template <typename T>
std::ostream& operator<<(std::ostream& out, const NoTypeNameAttribute<T>&)
{
out << "no_output" ;
return out ;
}
} // namespace CGoGN } // namespace CGoGN
#endif /* FAKEATTRIBUTE_H_ */ #endif /* FAKEATTRIBUTE_H_ */
...@@ -127,7 +127,7 @@ protected: ...@@ -127,7 +127,7 @@ protected:
*/ */
Mark m_boundaryMarkers[2] ; // 0 for dim 2 / 1 for dim 3 Mark m_boundaryMarkers[2] ; // 0 for dim 2 / 1 for dim 3
unsigned int m_nbThreads ; unsigned int m_nbThreadMarkers ;
/** /**
* Store links to created AttributeHandlers, DartMarkers and CellMarkers * Store links to created AttributeHandlers, DartMarkers and CellMarkers
...@@ -361,7 +361,7 @@ public: ...@@ -361,7 +361,7 @@ public:
* return allowed threads * return allowed threads
* @return the number of threads (including principal) * @return the number of threads (including principal)
*/ */
unsigned int getNbThreadMarkers() ; unsigned int getNbThreadMarkers() const;
/** /**
* Remove some added threads * Remove some added threads
...@@ -414,6 +414,11 @@ public: ...@@ -414,6 +414,11 @@ public:
* compact the map * compact the map
*/ */
void compact() ; void compact() ;
/**
* @brief dump all attributes of map in CSV format (; separated columns)
*/
void dumpCSV() const;
} ; } ;
......
...@@ -49,7 +49,7 @@ inline void GenericMap::deleteDartLine(unsigned int index) ...@@ -49,7 +49,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{ {
m_attribs[DART].removeLine(index) ; // free the dart line m_attribs[DART].removeLine(index) ; // free the dart line
for (unsigned int t = 0; t < m_nbThreads; ++t) // clear markers of for (unsigned int t = 0; t < m_nbThreadMarkers; ++t) // clear markers of
(*m_markTables[DART][t])[index].clear() ; // the removed dart (*m_markTables[DART][t])[index].clear() ; // the removed dart
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
...@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index) ...@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{ {
if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line if(m_attribs[orbit].unrefLine(emb)) // unref the pointed embedding line
{ {
for (unsigned int t = 0; t < m_nbThreads; ++t) // and clear its markers if it was for (unsigned int t = 0; t < m_nbThreadMarkers; ++t) // and clear its markers if it was
(*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed) (*m_markTables[orbit][t])[emb].clear() ; // its last unref (and was thus freed)
} }
} }
......
...@@ -85,7 +85,7 @@ void MapCommon<MAP_IMPL>::setDartEmbedding(Dart d, unsigned int emb) ...@@ -85,7 +85,7 @@ void MapCommon<MAP_IMPL>::setDartEmbedding(Dart d, unsigned int emb)
{ {
if(this->m_attribs[ORBIT].unrefLine(old)) // then unref the old emb if(this->m_attribs[ORBIT].unrefLine(old)) // then unref the old emb
{ {
for (unsigned int t = 0; t < this->m_nbThreads; ++t) // clear the markers if it was the for (unsigned int t = 0; t < this->m_nbThreadMarkers; ++t) // clear the markers if it was the
(*this->m_markTables[ORBIT][t])[old].clear(); // last unref of the line (*this->m_markTables[ORBIT][t])[old].clear(); // last unref of the line
} }
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <iostream> #include <iostream>
#include "Container/attributeContainer.h" #include "Container/attributeContainer.h"
#include "Topology/generic/dart.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -827,8 +828,13 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) ...@@ -827,8 +828,13 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
} }
else else
{ {
// Mark always the first ! // get id of thread
AttributeMultiVectorGen* ptr = m_tableAttribs[i]; const std::string& str = cont.m_tableAttribs[i]->getName();
unsigned int thId = (unsigned int)(str[5]-'0');
if (str.size()==7)
thId = 10*thId + (unsigned int)(sub[6]-'0');
// Mark always at the begin, because called after clear
AttributeMultiVectorGen* ptr = m_tableAttribs[thId];
ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks()); ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks());
ptr->copy(cont.m_tableAttribs[i]); ptr->copy(cont.m_tableAttribs[i]);
} }
...@@ -836,4 +842,74 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont) ...@@ -836,4 +842,74 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
} }
} }
void AttributeContainer::dumpCSV() const
{
CGoGNout << "Container of "<<orbitName(this->getOrbit())<< CGoGNendl;
CGoGNout << "Name ; ;";
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if (m_tableAttribs[i] != NULL)
{
CGoGNout << m_tableAttribs[i]->getName() << " ; ";
}
}
CGoGNout << CGoGNendl;
CGoGNout << "Type ; ;";
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if (m_tableAttribs[i] != NULL)
{
CGoGNout << m_tableAttribs[i]->getTypeName() << " ; ";
}
}
CGoGNout << CGoGNendl;
CGoGNout << "line ; refs ;";
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if (m_tableAttribs[i] != NULL)
{
CGoGNout << "value;";
}
}
CGoGNout << CGoGNendl;
for (unsigned int l=this->begin(); l!= this->end(); this->next(l))
{
CGoGNout << l << " ; "<< this->getNbRefs(l)<< " ; ";
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if (m_tableAttribs[i] != NULL)
{
m_tableAttribs[i]->dump(l);
CGoGNout << " ; ";
}
}
CGoGNout << CGoGNendl;
}
}
void AttributeContainer::dumpByLines() const
{
CGoGNout << "Container of "<<orbitName(this->getOrbit())<< CGoGNendl;
for (unsigned int i = 0; i < m_tableAttribs.size(); ++i)
{
if (m_tableAttribs[i] != NULL)
{
CGoGNout << "Name: "<< m_tableAttribs[i]->getName();
CGoGNout << " / Type: "<< m_tableAttribs[i]->getTypeName();
for (unsigned int l=this->begin(); l!= this->end(); this->next(l))
{
CGoGNout << l << " ; ";
m_tableAttribs[i]->dump(l);
CGoGNout << CGoGNendl;
}
}
}
}
} }
...@@ -42,7 +42,7 @@ int NumberOfThreads = getSystemNumberOfCores(); ...@@ -42,7 +42,7 @@ int NumberOfThreads = getSystemNumberOfCores();
std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL; std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL;
int GenericMap::m_nbInstances = 0; int GenericMap::m_nbInstances = 0;
GenericMap::GenericMap() : m_nbThreads(1) GenericMap::GenericMap() : m_nbThreadMarkers(1)
{ {
if(m_attributes_registry_map == NULL) if(m_attributes_registry_map == NULL)
{ {
...@@ -160,7 +160,7 @@ void GenericMap::init() ...@@ -160,7 +160,7 @@ void GenericMap::init()
} }
AttributeContainer& cont = m_attribs[i]; AttributeContainer& cont = m_attribs[i];
for (unsigned int t = 0; t < m_nbThreads; ++t) for (unsigned int t = 0; t < m_nbThreadMarkers; ++t)
{ {
std::stringstream ss ; std::stringstream ss ;
ss << "Mark_" << t ; ss << "Mark_" << t ;
...@@ -219,7 +219,7 @@ void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit ...@@ -219,7 +219,7 @@ void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit
m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ; m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ;
for(unsigned int t = 0; t < m_nbThreads; ++t) for(unsigned int t = 0; t < m_nbThreadMarkers; ++t)
{ {
AttributeMultiVector<Mark>* m = m_markTables[orbit1][t] ; AttributeMultiVector<Mark>* m = m_markTables[orbit1][t] ;
m_markTables[orbit1][t] = m_markTables[orbit2][t] ; m_markTables[orbit1][t] = m_markTables[orbit2][t] ;
...@@ -289,8 +289,8 @@ void GenericMap::addThreadMarker(unsigned int nb) ...@@ -289,8 +289,8 @@ void GenericMap::addThreadMarker(unsigned int nb)
for (unsigned int j = 0; j < nb; ++j) for (unsigned int j = 0; j < nb; ++j)
{ {
th = m_nbThreads ; th = m_nbThreadMarkers ;
m_nbThreads++ ; m_nbThreadMarkers++ ;
for (unsigned int i = 0; i < NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
...@@ -303,17 +303,17 @@ void GenericMap::addThreadMarker(unsigned int nb) ...@@ -303,17 +303,17 @@ void GenericMap::addThreadMarker(unsigned int nb)
} }
} }
unsigned int GenericMap::getNbThreadMarkers() unsigned int GenericMap::getNbThreadMarkers() const
{ {
return m_nbThreads; return m_nbThreadMarkers;
} }
void GenericMap::removeThreadMarker(unsigned int nb) void GenericMap::removeThreadMarker(unsigned int nb)
{ {
unsigned int th = 0; unsigned int th = 0;
while ((m_nbThreads > 1) && (nb > 0)) while ((m_nbThreadMarkers > 1) && (nb > 0))
{ {
th = --m_nbThreads ; th = --m_nbThreadMarkers ;
--nb; --nb;
for (unsigned int i = 0; i < NB_ORBITS; ++i) for (unsigned int i = 0; i < NB_ORBITS; ++i)
{ {
...@@ -336,11 +336,11 @@ void GenericMap::restore_shortcuts() ...@@ -336,11 +336,11 @@ void GenericMap::restore_shortcuts()
std::vector<std::string> typeMark; std::vector<std::string> typeMark;
unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark); unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark);
m_nbThreads = 0; m_nbThreadMarkers = 0;
for (unsigned int i = 0; i < nbatt0; ++i) for (unsigned int i = 0; i < nbatt0; ++i)
{ {
if (typeMark[i] == "Mark") if (typeMark[i] == "Mark")
++m_nbThreads; ++m_nbThreadMarkers;
} }
// EMBEDDING // EMBEDDING
...@@ -511,4 +511,13 @@ void GenericMap::compact() ...@@ -511,4 +511,13 @@ void GenericMap::compact()
compactTopo(); compactTopo();
} }
void GenericMap::dumpCSV() const
{
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
m_attribs[orbit].dumpCSV();
}
CGoGNout << CGoGNendl;
}
} // namespace CGoGN } // namespace CGoGN
...@@ -137,8 +137,10 @@ bool MapMono::copyFrom(const GenericMap& map) ...@@ -137,8 +137,10 @@ bool MapMono::copyFrom(const GenericMap& map)
} }
GenericMap::clear(true); GenericMap::clear(true);
// add same thread markers than in map (1 in clear)
addThreadMarker(map.getNbThreadMarkers()-1);
// load attrib container // copy attrib containers
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]);
......
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