handling non trivially copyable types in the attribute copy when appending meshes.
https://en.cppreference.com/w/cpp/types/is_trivially_copyable
This commit is contained in:
parent
c28ee8c5b4
commit
a78a51e650
|
|
@ -426,8 +426,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
|
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
|
||||||
if( !(*vi).IsD() && (!selected || (*vi).IsS()))
|
if( !(*vi).IsD() && (!selected || (*vi).IsS()))
|
||||||
memcpy((*al)._handle->At(remap.vert[Index(mr,*vi)]),(*ar)._handle->At(id_r),
|
(*al)._handle->CopyValue(remap.vert[Index(mr,*vi)], id_r, (*ar)._handle);
|
||||||
(*al)._handle->SizeOf());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,8 +438,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
|
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
|
||||||
if( !(*ei).IsD() && (!selected || (*ei).IsS()))
|
if( !(*ei).IsD() && (!selected || (*ei).IsS()))
|
||||||
memcpy((*al)._handle->At(remap.edge[Index(mr,*ei)]),(*ar)._handle->At(id_r),
|
(*al)._handle->CopyValue(remap.edge[Index(mr,*ei)], id_r, (*ar)._handle);
|
||||||
(*al)._handle->SizeOf());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -452,8 +450,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
|
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
|
||||||
if( !(*fi).IsD() && (!selected || (*fi).IsS()))
|
if( !(*fi).IsD() && (!selected || (*fi).IsS()))
|
||||||
memcpy((*al)._handle->At(remap.face[Index(mr,*fi)]),(*ar)._handle->At(id_r),
|
(*al)._handle->CopyValue(remap.face[Index(mr,*fi)], id_r, (*ar)._handle);
|
||||||
(*al)._handle->SizeOf());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,8 +462,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
|
||||||
id_r = 0;
|
id_r = 0;
|
||||||
for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti, ++id_r)
|
for(TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti, ++id_r)
|
||||||
if( !(*ti).IsD() && (!selected || (*ti).IsS()))
|
if( !(*ti).IsD() && (!selected || (*ti).IsS()))
|
||||||
memcpy((*al)._handle->At(remap.tetra[Index(mr, *ti)]),(*ar)._handle->At(id_r),
|
(*al)._handle->CopyValue(remap.tetra[Index(mr, *ti)], id_r, (*ar)._handle);
|
||||||
(*al)._handle->SizeOf());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// per mesh attributes
|
// per mesh attributes
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,11 @@
|
||||||
#ifndef __VCGLIB_SIMPLE__
|
#ifndef __VCGLIB_SIMPLE__
|
||||||
#define __VCGLIB_SIMPLE__
|
#define __VCGLIB_SIMPLE__
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg
|
||||||
|
{
|
||||||
|
|
||||||
class SimpleTempDataBase{
|
class SimpleTempDataBase
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~SimpleTempDataBase() {}
|
virtual ~SimpleTempDataBase() {}
|
||||||
SimpleTempDataBase() {}
|
SimpleTempDataBase() {}
|
||||||
|
|
@ -34,42 +36,59 @@ public:
|
||||||
virtual void Reorder(std::vector<size_t> &newVertIndex) = 0;
|
virtual void Reorder(std::vector<size_t> &newVertIndex) = 0;
|
||||||
virtual size_t SizeOf() const = 0;
|
virtual size_t SizeOf() const = 0;
|
||||||
virtual void *DataBegin() = 0;
|
virtual void *DataBegin() = 0;
|
||||||
|
|
||||||
virtual void *At(size_t i) = 0;
|
virtual void *At(size_t i) = 0;
|
||||||
|
virtual const void *At(size_t i) const = 0;
|
||||||
|
virtual void CopyValue(const size_t to, const size_t from, const SimpleTempDataBase *other) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class TYPE>
|
template <class TYPE>
|
||||||
class VectorNBW: public std::vector<TYPE> {};
|
class VectorNBW : public std::vector<TYPE>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class VectorNBW<bool>{
|
class VectorNBW<bool>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
VectorNBW() : data(0), datasize(0), datareserve(0) {}
|
VectorNBW() : data(0), datasize(0), datareserve(0) {}
|
||||||
|
|
||||||
~VectorNBW() {
|
~VectorNBW()
|
||||||
|
{
|
||||||
if (data)
|
if (data)
|
||||||
delete[] data;
|
delete[] data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool *data;
|
bool *data;
|
||||||
|
|
||||||
void reserve (const int & sz) {
|
void reserve(const int &sz)
|
||||||
if(sz<=datareserve) return;
|
{
|
||||||
|
if (sz <= datareserve)
|
||||||
|
return;
|
||||||
bool *newdataLoc = new bool[sz];
|
bool *newdataLoc = new bool[sz];
|
||||||
if(datasize!=0) memcpy(newdataLoc,data,sizeof(datasize));
|
if (datasize != 0)
|
||||||
|
memcpy(newdataLoc, data, sizeof(datasize));
|
||||||
std::swap(data, newdataLoc);
|
std::swap(data, newdataLoc);
|
||||||
if(newdataLoc != 0) delete[] newdataLoc;
|
if (newdataLoc != 0)
|
||||||
|
delete[] newdataLoc;
|
||||||
datareserve = sz;
|
datareserve = sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize (const int & sz) {
|
void resize(const int &sz)
|
||||||
|
{
|
||||||
int oldDatasize = datasize;
|
int oldDatasize = datasize;
|
||||||
if(sz <= oldDatasize) return;
|
if (sz <= oldDatasize)
|
||||||
|
return;
|
||||||
if (sz > datareserve)
|
if (sz > datareserve)
|
||||||
reserve(sz);
|
reserve(sz);
|
||||||
datasize = sz;
|
datasize = sz;
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
void clear() { datasize = 0; }
|
void clear() { datasize = 0; }
|
||||||
|
|
||||||
|
|
@ -80,6 +99,7 @@ public:
|
||||||
bool *begin() const { return data; }
|
bool *begin() const { return data; }
|
||||||
|
|
||||||
bool &operator[](const int &i) { return data[i]; }
|
bool &operator[](const int &i) { return data[i]; }
|
||||||
|
const bool &operator[](const int &i) const { return data[i]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int datasize;
|
int datasize;
|
||||||
|
|
@ -87,7 +107,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class STL_CONT, class ATTR_TYPE>
|
template <class STL_CONT, class ATTR_TYPE>
|
||||||
class SimpleTempData:public SimpleTempDataBase{
|
class SimpleTempData : public SimpleTempDataBase
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef SimpleTempData<STL_CONT, ATTR_TYPE> SimpTempDataType;
|
typedef SimpleTempData<STL_CONT, ATTR_TYPE> SimpTempDataType;
|
||||||
|
|
@ -97,9 +118,15 @@ class SimpleTempData:public SimpleTempDataBase{
|
||||||
VectorNBW<ATTR_TYPE> data;
|
VectorNBW<ATTR_TYPE> data;
|
||||||
int padding;
|
int padding;
|
||||||
|
|
||||||
SimpleTempData(STL_CONT &_c):c(_c),padding(0){data.reserve(c.capacity());data.resize(c.size());};
|
SimpleTempData(STL_CONT &_c) : c(_c), padding(0)
|
||||||
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());
|
||||||
|
};
|
||||||
|
SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val) : c(_c)
|
||||||
|
{
|
||||||
|
data.reserve(c.capacity());
|
||||||
|
data.resize(c.size());
|
||||||
Init(val);
|
Init(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -118,10 +145,23 @@ class SimpleTempData:public SimpleTempDataBase{
|
||||||
ATTR_TYPE &operator[](const typename STL_CONT::iterator &cont) { return data[&(*cont) - &*c.begin()]; }
|
ATTR_TYPE &operator[](const typename STL_CONT::iterator &cont) { return data[&(*cont) - &*c.begin()]; }
|
||||||
ATTR_TYPE &operator[](size_t i) { return data[i]; }
|
ATTR_TYPE &operator[](size_t i) { return data[i]; }
|
||||||
|
|
||||||
void * At(size_t i ) {return &(*this)[i];};
|
const ATTR_TYPE &operator[](const typename STL_CONT::value_type &v) const { return data[&v - &*c.begin()]; }
|
||||||
|
const ATTR_TYPE &operator[](const typename STL_CONT::value_type *v) const { return data[v - &*c.begin()]; }
|
||||||
|
const ATTR_TYPE &operator[](const typename STL_CONT::iterator &cont) const { return data[&(*cont) - &*c.begin()]; }
|
||||||
|
const ATTR_TYPE &operator[](size_t i) const { return data[i]; }
|
||||||
|
|
||||||
|
void *At(size_t i) { return &(*this)[i]; }
|
||||||
|
const void *At(size_t i) const { return &(*this)[i]; }
|
||||||
|
|
||||||
|
void CopyValue(const size_t to, const size_t from, const SimpleTempDataBase *other)
|
||||||
|
{
|
||||||
|
assert(other != nullptr);
|
||||||
|
data[to] = *(static_cast<const ATTR_TYPE *>(other->At(from)));
|
||||||
|
}
|
||||||
|
|
||||||
// update temporary data size
|
// update temporary data size
|
||||||
bool UpdateSize(){
|
bool UpdateSize()
|
||||||
|
{
|
||||||
if (data.size() != c.size())
|
if (data.size() != c.size())
|
||||||
{
|
{
|
||||||
data.resize(c.size());
|
data.resize(c.size());
|
||||||
|
|
@ -130,12 +170,15 @@ class SimpleTempData:public SimpleTempDataBase{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(size_t sz){
|
void Resize(size_t sz)
|
||||||
|
{
|
||||||
data.resize(sz);
|
data.resize(sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reorder(std::vector<size_t> & newVertIndex){
|
void Reorder(std::vector<size_t> &newVertIndex)
|
||||||
for(unsigned int i = 0 ; i < data.size(); ++i){
|
{
|
||||||
|
for (unsigned int i = 0; i < data.size(); ++i)
|
||||||
|
{
|
||||||
if (newVertIndex[i] != (std::numeric_limits<size_t>::max)())
|
if (newVertIndex[i] != (std::numeric_limits<size_t>::max)())
|
||||||
data[newVertIndex[i]] = data[i];
|
data[newVertIndex[i]] = data[i];
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +189,8 @@ class SimpleTempData:public SimpleTempDataBase{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ATTR_TYPE>
|
template <class ATTR_TYPE>
|
||||||
class Attribute: public SimpleTempDataBase {
|
class Attribute : public SimpleTempDataBase
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
typedef ATTR_TYPE AttrType;
|
typedef ATTR_TYPE AttrType;
|
||||||
AttrType *attribute;
|
AttrType *attribute;
|
||||||
|
|
@ -157,7 +201,18 @@ public:
|
||||||
|
|
||||||
void Resize(size_t) { assert(0); }
|
void Resize(size_t) { assert(0); }
|
||||||
void Reorder(std::vector<size_t> &) { assert(0); }
|
void Reorder(std::vector<size_t> &) { assert(0); }
|
||||||
void * At(size_t ) {assert(0);return (void*)0;}
|
|
||||||
|
void *At(size_t)
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
return (void *)0;
|
||||||
|
}
|
||||||
|
const void *At(size_t) const
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
return (void *)0;
|
||||||
|
}
|
||||||
|
void CopyValue(const size_t, const size_t, const SimpleTempDataBase *) { assert(0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace vcg
|
} // end namespace vcg
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue