Commit e2fc1ed9 authored by Sylvain Thery's avatar Sylvain Thery

add copyFrom method in genericmap (testing in progress)

add some const
parent 11ba46af
...@@ -530,6 +530,13 @@ public: ...@@ -530,6 +530,13 @@ public:
* @param id ?? * @param id ??
*/ */
bool loadBin(CGoGNistream& fs); bool loadBin(CGoGNistream& fs);
/**
* copy container
* TODO a version that compact on the fly ?
*/
void copyFrom(const AttributeContainer& cont);
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -126,6 +126,8 @@ public: ...@@ -126,6 +126,8 @@ public:
*/ */
virtual void setNbBlocks(unsigned int nbb) = 0; virtual void setNbBlocks(unsigned int nbb) = 0;
virtual unsigned int getNbBlocks() const = 0;
virtual void addBlocksBefore(unsigned int nbb) = 0; virtual void addBlocksBefore(unsigned int nbb) = 0;
virtual bool copy(const AttributeMultiVectorGen* atmvg) = 0; virtual bool copy(const AttributeMultiVectorGen* atmvg) = 0;
...@@ -244,6 +246,8 @@ public: ...@@ -244,6 +246,8 @@ public:
void setNbBlocks(unsigned int nbb); void setNbBlocks(unsigned int nbb);
unsigned int getNbBlocks() const;
void addBlocksBefore(unsigned int nbb); void addBlocksBefore(unsigned int nbb);
bool copy(const AttributeMultiVectorGen* atmvg); bool copy(const AttributeMultiVectorGen* atmvg);
......
...@@ -132,7 +132,9 @@ AttributeMultiVector<T>::~AttributeMultiVector() ...@@ -132,7 +132,9 @@ AttributeMultiVector<T>::~AttributeMultiVector()
template <typename T> template <typename T>
inline AttributeMultiVectorGen* AttributeMultiVector<T>::new_obj() inline AttributeMultiVectorGen* AttributeMultiVector<T>::new_obj()
{ {
return new AttributeMultiVector<T>; AttributeMultiVectorGen* ptr = new AttributeMultiVector<T>;
ptr->setTypeName(m_typeName);
return ptr;
} }
/************************************** /**************************************
...@@ -166,6 +168,12 @@ void AttributeMultiVector<T>::setNbBlocks(unsigned int nbb) ...@@ -166,6 +168,12 @@ void AttributeMultiVector<T>::setNbBlocks(unsigned int nbb)
} }
} }
template <typename T>
unsigned int AttributeMultiVector<T>::getNbBlocks() const
{
return m_tableData.size();
}
template <typename T> template <typename T>
void AttributeMultiVector<T>::addBlocksBefore(unsigned int nbb) void AttributeMultiVector<T>::addBlocksBefore(unsigned int nbb)
{ {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <assert.h>
#include "Container/sizeblock.h" #include "Container/sizeblock.h"
...@@ -49,7 +50,7 @@ protected: ...@@ -49,7 +50,7 @@ protected:
unsigned int m_nbref; unsigned int m_nbref;
/** /**
* nb element in block * nb elements in block
*/ */
unsigned int m_nb; unsigned int m_nb;
...@@ -59,6 +60,11 @@ public: ...@@ -59,6 +60,11 @@ public:
*/ */
HoleBlockRef(); HoleBlockRef();
/**
* copy constructor
*/
HoleBlockRef(const HoleBlockRef& hb);
/** /**
* destructor * destructor
*/ */
...@@ -149,6 +155,7 @@ public: ...@@ -149,6 +155,7 @@ public:
*/ */
inline bool unref(unsigned int i) inline bool unref(unsigned int i)
{ {
// assert(m_refCount[i] > 1);
m_refCount[i]--; m_refCount[i]--;
if (m_refCount[i] == 1) if (m_refCount[i] == 1)
{ {
...@@ -165,7 +172,7 @@ public: ...@@ -165,7 +172,7 @@ public:
/** /**
* number of references of element i * number of references of element i
* @return the number of references (0 = no elements) * @return the number of references +1 (stored as n+1, 0 = not used, 1 used but not refs, ...)
*/ */
inline unsigned int nbRefs(unsigned int i) { return m_refCount[i]; } inline unsigned int nbRefs(unsigned int i) { return m_refCount[i]; }
......
...@@ -150,7 +150,7 @@ public: ...@@ -150,7 +150,7 @@ public:
~GenericMap() ; ~GenericMap() ;
virtual std::string mapTypeName() = 0 ; virtual std::string mapTypeName() const = 0 ;
/** /**
* Clear the map * Clear the map
...@@ -503,6 +503,11 @@ public: ...@@ -503,6 +503,11 @@ public:
*/ */
bool loadMapBin(const std::string& filename) ; bool loadMapBin(const std::string& filename) ;
/**
* copy from another map (of same type)
*/
bool copyFrom(const GenericMap& map);
/** /**
* Dump attributes types and names per orbit * Dump attributes types and names per orbit
*/ */
......
...@@ -46,7 +46,7 @@ protected: ...@@ -46,7 +46,7 @@ protected:
public: public:
GMap0(); GMap0();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -37,7 +37,7 @@ inline GMap0::GMap0() : AttribMap() ...@@ -37,7 +37,7 @@ inline GMap0::GMap0() : AttribMap()
init() ; init() ;
} }
inline std::string GMap0::mapTypeName() inline std::string GMap0::mapTypeName() const
{ {
return "GMap0"; return "GMap0";
} }
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
GMap1(); GMap1();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -35,7 +35,7 @@ inline GMap1::GMap1() : GMap0() ...@@ -35,7 +35,7 @@ inline GMap1::GMap1() : GMap0()
init() ; init() ;
} }
inline std::string GMap1::mapTypeName() inline std::string GMap1::mapTypeName() const
{ {
return "GMap1"; return "GMap1";
} }
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
GMap2(); GMap2();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -35,7 +35,7 @@ inline GMap2::GMap2() : GMap1() ...@@ -35,7 +35,7 @@ inline GMap2::GMap2() : GMap1()
init() ; init() ;
} }
inline std::string GMap2::mapTypeName() inline std::string GMap2::mapTypeName() const
{ {
return "GMap2"; return "GMap2";
} }
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
GMap3(); GMap3();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -35,7 +35,7 @@ inline GMap3::GMap3() : GMap2() ...@@ -35,7 +35,7 @@ inline GMap3::GMap3() : GMap2()
init() ; init() ;
} }
inline std::string GMap3::mapTypeName() inline std::string GMap3::mapTypeName() const
{ {
return "GMap3"; return "GMap3";
} }
......
...@@ -51,7 +51,7 @@ protected: ...@@ -51,7 +51,7 @@ protected:
public: public:
Map1(); Map1();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -38,7 +38,7 @@ inline Map1::Map1() : AttribMap() ...@@ -38,7 +38,7 @@ inline Map1::Map1() : AttribMap()
init() ; init() ;
} }
inline std::string Map1::mapTypeName() inline std::string Map1::mapTypeName() const
{ {
return "Map1" ; return "Map1" ;
} }
......
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
Map2(); Map2();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -37,7 +37,7 @@ inline Map2::Map2() : Map1() ...@@ -37,7 +37,7 @@ inline Map2::Map2() : Map1()
init() ; init() ;
} }
inline std::string Map2::mapTypeName() inline std::string Map2::mapTypeName() const
{ {
return "Map2" ; return "Map2" ;
} }
......
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
Map3(); Map3();
virtual std::string mapTypeName(); virtual std::string mapTypeName() const;
virtual unsigned int dimension(); virtual unsigned int dimension();
......
...@@ -35,7 +35,7 @@ inline Map3::Map3() : Map2() ...@@ -35,7 +35,7 @@ inline Map3::Map3() : Map2()
init() ; init() ;
} }
inline std::string Map3::mapTypeName() inline std::string Map3::mapTypeName() const
{ {
return "Map3"; return "Map3";
} }
......
...@@ -690,4 +690,57 @@ bool AttributeContainer::loadBin(CGoGNistream& fs) ...@@ -690,4 +690,57 @@ bool AttributeContainer::loadBin(CGoGNistream& fs)
return true; return true;
} }
void AttributeContainer::copyFrom(const AttributeContainer& cont)
{
// clear is done from the map
m_size = cont.m_size;
m_maxSize = cont.m_maxSize;
m_orbit = cont.m_orbit;
m_nbUnknown = cont.m_nbUnknown;
m_nbAttributes = cont.m_nbAttributes;
m_lineCost = cont.m_lineCost;
// blocks
unsigned int sz = cont.m_holesBlocks.size();
m_holesBlocks.resize(sz);
for (unsigned int i = 0; i < sz; ++i)
m_holesBlocks[i] = new HoleBlockRef(*(cont.m_holesBlocks[i]));
// blocks with free
sz = cont.m_tableBlocksWithFree.size();
m_tableBlocksWithFree.resize(sz);
for (unsigned int i = 0; i < sz; ++i)
m_tableBlocksWithFree[i] = cont.m_tableBlocksWithFree[i];
// empty blocks
sz = cont.m_tableBlocksEmpty.size();
m_tableBlocksEmpty.resize(sz);
for (unsigned int i = 0; i < sz; ++i)
m_tableBlocksEmpty[i] = cont.m_tableBlocksEmpty[i];
//attributes (warning attribute can have different numbers than in original)
m_tableAttribs.reserve(m_nbAttributes);
sz = cont.m_tableAttribs.size();
for (unsigned int i = 0; i < sz; ++i)
{
if (cont.m_tableAttribs[i] != NULL)
{
AttributeMultiVectorGen* ptr = cont.m_tableAttribs[i]->new_obj();
ptr->setName(cont.m_tableAttribs[i]->getName());
ptr->setOrbit(cont.m_tableAttribs[i]->getIndex());
ptr->setIndex(m_tableAttribs.size());
ptr->setNbBlocks(cont.m_tableAttribs[i]->getNbBlocks());
ptr->copy(cont.m_tableAttribs[i]);
if (cont.m_tableAttribs[i]->toProcess())
ptr->toggleProcess();
else
ptr->toggleNoProcess();
m_tableAttribs.push_back(ptr);
}
}
}
} }
...@@ -43,10 +43,24 @@ namespace CGoGN ...@@ -43,10 +43,24 @@ namespace CGoGN
HoleBlockRef::HoleBlockRef(): HoleBlockRef::HoleBlockRef():
m_nbfree(0),m_nbref(0),m_nb(0) m_nbfree(0),m_nbref(0),m_nb(0)
{ {
m_tableFree = new unsigned int[_BLOCKSIZE_]; m_tableFree = new unsigned int[_BLOCKSIZE_ + 10];
m_refCount = new unsigned int[_BLOCKSIZE_]; m_refCount = new unsigned int[_BLOCKSIZE_];
} }
HoleBlockRef::HoleBlockRef(const HoleBlockRef& hb)
{
m_nbfree = hb.m_nbfree;
m_nbref = hb.m_nbref;
m_nb = hb.m_nb;
m_tableFree = new unsigned int[_BLOCKSIZE_ +10];
memcpy(m_tableFree, hb.m_tableFree, (_BLOCKSIZE_+ 10) * sizeof(unsigned int));
m_refCount = new unsigned int[_BLOCKSIZE_];
memcpy(m_refCount, hb.m_refCount, _BLOCKSIZE_ * sizeof(unsigned int));
}
HoleBlockRef::~HoleBlockRef() HoleBlockRef::~HoleBlockRef()
{ {
delete[] m_tableFree; delete[] m_tableFree;
......
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