Commit b9dbea54 authored by Sylvain Thery's avatar Sylvain Thery

bugfix copyFrom + dumpCSV + some const

parent b50afe03
......@@ -33,6 +33,7 @@
#include "Algo/Export/export.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ;
......@@ -78,6 +79,7 @@ int main(int argc, char **argv)
MAP myMap2;
// for copying the initial mesh
myMap2.copyFrom(myMap);
// AttributeHandler are linked to the map, need a new one
VertexAttribute<VEC3, MAP_IMPL> position2 = myMap2.getAttribute<VEC3, VERTEX>(attrNames[0]);
......@@ -96,5 +98,6 @@ int main(int argc, char **argv)
Algo::Surface::Export::exportOFF<PFP>(myMap2, position2, "resultCC.off");
return 0;
}
......@@ -138,7 +138,8 @@ public:
~AttributeContainer();
unsigned int getOrbit();
unsigned int getOrbit() const;
void setOrbit(unsigned int orbit);
void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re);
......@@ -364,7 +365,7 @@ public:
* @param index index 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
......@@ -473,6 +474,14 @@ public:
*/
void copyFrom(const AttributeContainer& cont);
/**
* dump the container in CSV format (; separated columns)
*/
void dumpCSV() const;
void dumpByLines() const;
};
} // namespace CGoGN
......
......@@ -30,7 +30,7 @@
namespace CGoGN
{
inline unsigned int AttributeContainer::getOrbit()
inline unsigned int AttributeContainer::getOrbit() const
{
return m_orbit ;
}
......@@ -332,7 +332,7 @@ inline bool AttributeContainer::unrefLine(unsigned int index)
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 j = index % _BLOCKSIZE_;
......
......@@ -176,6 +176,12 @@ public:
virtual bool loadBin(CGoGNistream& fs) = 0;
static bool skipLoadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const = 0;
};
......@@ -266,17 +272,17 @@ public:
* 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 *
......@@ -294,6 +300,13 @@ public:
* @param fs filestream
*/
bool loadBin(CGoGNistream& fs);
/**
* lecture binaire
* @param fs filestream
*/
virtual void dump(unsigned int i) const;
};
} // namespace CGoGN
......
......@@ -407,4 +407,11 @@ inline bool AttributeMultiVectorGen::skipLoadBin(CGoGNistream& fs)
return true;
}
template <typename T>
void AttributeMultiVector<T>::dump(unsigned int i) const
{
CGoGNout << this->operator[](i);
}
} // namespace CGoGN
......@@ -48,6 +48,13 @@ public:
static std::string CGoGNnameOfType() { return ""; }
};
template <typename T>
std::ostream& operator<<(std::ostream& out, const NoTypeNameAttribute<T>&)
{
out << "no_output" ;
return out ;
}
} // namespace CGoGN
#endif /* FAKEATTRIBUTE_H_ */
......@@ -127,7 +127,7 @@ protected:
*/
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
......@@ -361,7 +361,7 @@ public:
* return allowed threads
* @return the number of threads (including principal)
*/
unsigned int getNbThreadMarkers() ;
unsigned int getNbThreadMarkers() const;
/**
* Remove some added threads
......@@ -414,6 +414,11 @@ public:
* compact the map
*/
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)
{
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
for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
......@@ -61,7 +61,7 @@ inline void GenericMap::deleteDartLine(unsigned int index)
{
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)
}
}
......
......@@ -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
{
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
}
}
......
......@@ -30,6 +30,7 @@
#include <iostream>
#include "Container/attributeContainer.h"
#include "Topology/generic/dart.h"
namespace CGoGN
{
......@@ -827,8 +828,13 @@ void AttributeContainer::copyFrom(const AttributeContainer& cont)
}
else
{
// Mark always the first !
AttributeMultiVectorGen* ptr = m_tableAttribs[i];
// get id of thread
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->copy(cont.m_tableAttribs[i]);
}
......@@ -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();
std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL;
int GenericMap::m_nbInstances = 0;
GenericMap::GenericMap() : m_nbThreads(1)
GenericMap::GenericMap() : m_nbThreadMarkers(1)
{
if(m_attributes_registry_map == NULL)
{
......@@ -160,7 +160,7 @@ void GenericMap::init()
}
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 ;
ss << "Mark_" << t ;
......@@ -219,7 +219,7 @@ void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit
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] ;
m_markTables[orbit1][t] = m_markTables[orbit2][t] ;
......@@ -289,8 +289,8 @@ void GenericMap::addThreadMarker(unsigned int nb)
for (unsigned int j = 0; j < nb; ++j)
{
th = m_nbThreads ;
m_nbThreads++ ;
th = m_nbThreadMarkers ;
m_nbThreadMarkers++ ;
for (unsigned int i = 0; i < NB_ORBITS; ++i)
{
......@@ -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)
{
unsigned int th = 0;
while ((m_nbThreads > 1) && (nb > 0))
while ((m_nbThreadMarkers > 1) && (nb > 0))
{
th = --m_nbThreads ;
th = --m_nbThreadMarkers ;
--nb;
for (unsigned int i = 0; i < NB_ORBITS; ++i)
{
......@@ -336,11 +336,11 @@ void GenericMap::restore_shortcuts()
std::vector<std::string> typeMark;
unsigned int nbatt0 = m_attribs[0].getAttributesTypes(typeMark);
m_nbThreads = 0;
m_nbThreadMarkers = 0;
for (unsigned int i = 0; i < nbatt0; ++i)
{
if (typeMark[i] == "Mark")
++m_nbThreads;
++m_nbThreadMarkers;
}
// EMBEDDING
......@@ -511,4 +511,13 @@ void GenericMap::compact()
compactTopo();
}
void GenericMap::dumpCSV() const
{
for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
{
m_attribs[orbit].dumpCSV();
}
CGoGNout << CGoGNendl;
}
} // namespace CGoGN
......@@ -137,8 +137,10 @@ bool MapMono::copyFrom(const GenericMap& map)
}
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)
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