added support for dump of attributes (see wrap/io_trimesh/[import | export]_VMI.h )

This commit is contained in:
ganovelli 2009-07-29 15:45:56 +00:00
parent 2c26fa34d4
commit fa287ce0ab
1 changed files with 28 additions and 5 deletions

View File

@ -61,6 +61,9 @@ public:
virtual void Resize(const int & sz) = 0; virtual void Resize(const int & sz) = 0;
virtual void Reorder(std::vector<size_t> & newVertIndex)=0; virtual void Reorder(std::vector<size_t> & newVertIndex)=0;
virtual int SizeOf() const = 0; virtual int SizeOf() const = 0;
virtual void * DataBegin() = 0;
//virtual void CopyTo(void * ) = 0;
}; };
template <class TYPE> template <class TYPE>
@ -83,10 +86,10 @@ public:
void resize (const int & sz) { void resize (const int & sz) {
int oldDatasize = datasize; int oldDatasize = datasize;
if(sz <= oldDatasize) return;
if(sz > datareserve)
reserve(sz);
datasize = sz; datasize = sz;
if(datasize <= oldDatasize) return;
if(datasize > datareserve)
reserve(datasize);
memset(&data[oldDatasize],0,datasize-oldDatasize); memset(&data[oldDatasize],0,datasize-oldDatasize);
} }
void push_back(const bool & v) { resize(datasize+1); data[datasize] = v;} void push_back(const bool & v) { resize(datasize+1); data[datasize] = v;}
@ -95,6 +98,10 @@ public:
unsigned int size() const { return datasize;} unsigned int size() const { return datasize;}
bool empty() const {return datasize==0;}
bool * begin() const {return data;}
bool & operator [](const int & i){return data[i];} bool & operator [](const int & i){return data[i];}
private: private:
@ -111,8 +118,9 @@ class SimpleTempData:public SimpleTempDataBase<STL_CONT>{
STL_CONT& c; STL_CONT& c;
VectorNBW<ATTR_TYPE> data; VectorNBW<ATTR_TYPE> data;
int padding;
SimpleTempData(STL_CONT &_c):c(_c){data.reserve(c.capacity());data.resize(c.size());}; SimpleTempData(STL_CONT &_c):c(_c),padding(0){data.reserve(c.capacity());data.resize(c.size());};
SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){ SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val):c(_c){
data.reserve(c.capacity());data.resize(c.size()); data.reserve(c.capacity());data.resize(c.size());
Init(val); Init(val);
@ -152,6 +160,18 @@ class SimpleTempData:public SimpleTempDataBase<STL_CONT>{
} }
int SizeOf() const {return sizeof(ATTR_TYPE);} int SizeOf() const {return sizeof(ATTR_TYPE);}
void * DataBegin() {return data.empty()?NULL:&(*data.begin());}
//template <typename ATTR_TYPE>
//void CopyTo(void * dest) {
// SimpleTempData<STL_CONT,ATTR_TYPE> * destination = (SimpleTempData<STL_CONT,ATTR_TYPE> *)dest;
// destination->Resize(data.size());
// for(int i = 0; i < data.size(); ++i)
// memcpy((void*)(*destination)[i] , (void*) &( ((char*)( (*this)[i] ))[padding]),sizeof(ATTR_TYPE));
//}
}; };
class AttributeBase{ class AttributeBase{
@ -159,6 +179,8 @@ class AttributeBase{
virtual ~AttributeBase() {}; virtual ~AttributeBase() {};
AttributeBase() {}; AttributeBase() {};
virtual int SizeOf()const = 0; virtual int SizeOf()const = 0;
virtual void * DataBegin() = 0;
}; };
template <class ATTR_TYPE> template <class ATTR_TYPE>
@ -169,6 +191,7 @@ AttrType * attribute;
Attribute(){attribute = new ATTR_TYPE();} Attribute(){attribute = new ATTR_TYPE();}
~Attribute(){delete attribute;} ~Attribute(){delete attribute;}
int SizeOf()const {return sizeof(ATTR_TYPE);} int SizeOf()const {return sizeof(ATTR_TYPE);}
void * DataBegin(){return attribute;}
}; };
}; // end namespace vcg }; // end namespace vcg