This commit is contained in:
T.Alderighi 2017-12-11 19:13:34 +01:00
commit 65ae2f9939
8 changed files with 1548 additions and 504 deletions

View File

@ -201,7 +201,7 @@ public:
{
VertexPointer v0 = FindVertexSnap(f0,ip0);
VertexPointer v1 = FindVertexSnap(f1,ip1);
assert(v1 != NULL && v1 != NULL && v0 != v1);
assert(v0 != NULL && v1 != NULL && v0 != v1);
FacePointer ff0,ff1;
int e0,e1;
ret &= face::FindSharedFaces<FaceType>(v0,v1,ff0,ff1,e0,e1);

View File

@ -1070,6 +1070,7 @@ public:
h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0;
h._handle = new SimpleTempData<VertContainer,ATTR_TYPE>(m.vert);
h._type = typeid(ATTR_TYPE);
m.attrn++;
h.n_attr = m.attrn;
std::pair < AttrIterator , bool> res = m.vert_attr.insert(h);
@ -1211,6 +1212,7 @@ public:
h._padding = 0;
// h._typename = typeid(ATTR_TYPE).name();
h._handle = new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge);
h._type = typeid(ATTR_TYPE);
m.attrn++;
h.n_attr = m.attrn;
std::pair < AttrIterator , bool> res = m.edge_attr.insert(h);
@ -1334,6 +1336,7 @@ public:
h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0;
h._handle = new SimpleTempData<FaceContainer,ATTR_TYPE>(m.face);
h._type = typeid(ATTR_TYPE);
m.attrn++;
h.n_attr = m.attrn;
std::pair < AttrIterator , bool> res = m.face_attr.insert(h);
@ -1452,6 +1455,7 @@ public:
h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0;
h._handle = new Attribute<ATTR_TYPE>();
h._type = typeid(ATTR_TYPE);
m.attrn++;
h.n_attr = m.attrn;
std::pair < AttrIterator , bool> res = m.mesh_attr.insert(h);

View File

@ -37,10 +37,12 @@ public:
int _padding; // padding (used only with VMI loading)
int n_attr; // unique ID of the attribute
std::type_index _type;
void Resize(size_t sz){((SimpleTempDataBase *)_handle)->Resize(sz);}
void Reorder(std::vector<size_t> & newVertIndex){((SimpleTempDataBase *)_handle)->Reorder(newVertIndex);}
bool operator<(const PointerToAttribute b) const { return(_name.empty()&&b._name.empty())?(_handle < b._handle):( _name < b._name);}
PointerToAttribute(): _type(typeid(void)) { };
};

View File

@ -39,6 +39,7 @@
#include <stdexcept>
#include <limits>
#include <iterator>
#include <typeindex>
#include <wrap/callback.h>
#include <vcg/complex/exception.h>
#include <vcg/container/simple_temporary_data.h>

View File

@ -96,7 +96,7 @@ public:
}
}
typename VALUE_TYPE::ColorType wc[3];
typename VALUE_TYPE::WedgeColorType wc[3];
};
class WedgeNormalTypePack {
@ -111,7 +111,7 @@ public:
}
}
typename VALUE_TYPE::NormalType wn[3];
typename VALUE_TYPE::WedgeNormalType wn[3];
};

View File

@ -108,6 +108,7 @@ public:
T::Dealloc();
}
static bool HasVertexRef() { return true; }
static bool HasFVAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PFVAdj"));T::Name(name);}

View File

@ -246,7 +246,7 @@ namespace nanoply
{ PlyEntity::NNP_K2DIR, NameVector({ "k2dir" }) },
{ PlyEntity::NNP_EDGE_V1, NameVector({ "vertex1", "v1" }) },
{ PlyEntity::NNP_EDGE_V2, NameVector({ "vertex2", "v2" }) },
{ PlyEntity::NNP_FACE_VERTEX_LIST, NameVector({ "vertex_index", "vertex_indices" }) },
{ PlyEntity::NNP_FACE_VERTEX_LIST, NameVector({ "vertex_indices", "vertex_index" }) },
{ PlyEntity::NNP_FACE_WEDGE_COLOR, NameVector({ "color" }) },
{ PlyEntity::NNP_FACE_WEDGE_NORMAL, NameVector({ "normal" }) },
{ PlyEntity::NNP_FACE_WEDGE_TEX, NameVector({ "texcoord" }) }
@ -463,7 +463,7 @@ namespace nanoply
if (fileStream.fail())
return false;
bufferOffset = 0;
//fileStream.setf(std::ios::fixed, std::ios::floatfield);
fileStream.setf(std::ios::fixed, std::ios::floatfield);
//fileStream.precision(7);
return true;
}
@ -583,6 +583,10 @@ namespace nanoply
PlyEntity elem; /**< Property entity. */
bool validToWrite; /**< Property validity (necessary to write the header). */
inline PlyProperty() {}
/**
* Constructor that sets the type and the entity of a standard PLY property.
*
@ -1732,7 +1736,7 @@ namespace nanoply
* @param _s Name of the PlyProperty.
* @param _b Pointer to the memory location that contains the data of the property.
*/
inline DescriptorInterface(std::string& _s, void *_b) :curPos(0), elem(PlyEntity::NNP_UNKNOWN_ENTITY), name(_s), base(_b){};
inline DescriptorInterface(const std::string& _s, void *_b) :curPos(0), elem(PlyEntity::NNP_UNKNOWN_ENTITY), name(_s), base(_b){};
/**
* Restart the descriptor.
@ -1990,18 +1994,336 @@ namespace nanoply
template<class ContainerType, int VectorSize, typename ScalarType>
class DescriptorHelper
{
public:
template<typename C>
static void ReadBinary(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop, bool fixEndian)
{
char * buffer = nullptr;
int size;
int count = prop.CountValue();
int typeSize = prop.TypeSize();
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
file.ReadBinaryData(buffer, sizeof(char));
const int cntList = int(*(reinterpret_cast<unsigned char *>(buffer)));
size = typeSize * cntList;
count = cntList;
}
else
size = typeSize * count;
file.ReadBinaryData(buffer, size);
if (typeSize > 1 && fixEndian)
adjustEndianess(reinterpret_cast<unsigned char *>(buffer), typeSize, count);
unsigned char* baseProp = (unsigned char*)descr.base + descr.curPos * sizeof(ContainerType);
C* temp = (C*)buffer;
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && std::is_same<C, unsigned char>::value)
norm = 1.0f / 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && std::is_same<C, float>::value)
norm = 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i * sizeof(ScalarType))) = ScalarType(temp[i] * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i * sizeof(ScalarType))) = ScalarType(temp[i]);
}
++(descr.curPos);
}
template<typename C>
static void ReadAscii(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop)
{
int count = prop.CountValue();
if (prop.type >= NNP_LIST_UINT8_UINT32)
file.ReadAsciiData(count);
C* temp = new C[count];
for (int i = 0; i < count; i++)
file.ReadAsciiData(temp[i]);
unsigned char* baseProp = (unsigned char*)descr.base + descr.curPos * sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && prop.type == NNP_UINT8)
norm = 1.0f / 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && prop.type == NNP_FLOAT32)
norm = 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i * sizeof(ScalarType))) = ScalarType(temp[i] * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i * sizeof(ScalarType))) = ScalarType(temp[i]);
}
delete[] temp;
++(descr.curPos);
}
template<typename C>
static void WriteBinary(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop, bool fixEndian)
{
(void)fixEndian;
int count = prop.CountValue();
C data[VectorSize];
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
char listSize = (char)VectorSize;
file.WriteBinaryData(&listSize, 1);
count = VectorSize;
}
else
{
unsigned char listSize = (unsigned char)VectorSize;
file.WriteBinaryData(&listSize, 1);
count = VectorSize;
}
}
C temp = 0;
unsigned char* baseProp = (unsigned char*)descr.base + descr.curPos * sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && std::is_same<C, unsigned char>::value)
norm = 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && std::is_same<C, float>::value)
norm = 1.0f / 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i * sizeof(ScalarType))) * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i * sizeof(ScalarType))));
}
if (sizeof(C) > 1 && fixEndian)
adjustEndianess((unsigned char*)data, sizeof(C), std::min(VectorSize, count));
file.WriteBinaryData(data, sizeof(C)*std::min(VectorSize, count));
for (int i = 0; i < (count - VectorSize); i++)
file.WriteBinaryData(&temp, sizeof(C));
++(descr.curPos);
}
template<typename C>
static void WriteAscii(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop)
{
int count = prop.CountValue();
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
int listSize = (int)VectorSize;
file.WriteAsciiData(listSize);
count = VectorSize;
}
else
{
unsigned int listSize = (unsigned int)VectorSize;
file.WriteAsciiData(listSize);
count = VectorSize;
}
file.WriteAsciiData(std::string(" "));
}
C data[VectorSize];
unsigned char* baseProp = (unsigned char*)descr.base + descr.curPos * sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0;
if (std::is_same<ScalarType, float>::value && prop.type == NNP_UINT8)
norm = 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && prop.type == NNP_FLOAT32)
norm = 1.0f / 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i * sizeof(ScalarType))) * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i * sizeof(ScalarType))));
}
for (int i = 0; i < (count - VectorSize); i++)
data[i] = 0;
for (int i = 0; i < count; i++)
{
file.WriteAsciiData(data[i]);
if (i < count - 1)
file.WriteAsciiData(std::string(" "));
}
++(descr.curPos);
}
};
template<class ContainerType, typename ScalarType>
class DescriptorHelper<ContainerType, 0, ScalarType>
{
public:
template<typename C>
static void ReadBinary(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop, bool fixEndian)
{
char * buffer = nullptr;
int size;
int count = prop.CountValue();
int typeSize = prop.TypeSize();
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
file.ReadBinaryData(buffer, sizeof(char));
const int cntList = int(*(reinterpret_cast<unsigned char *>(buffer)));
size = typeSize * cntList;
count = cntList;
}
else
size = typeSize * count;
file.ReadBinaryData(buffer, size);
if (typeSize > 1 && fixEndian)
adjustEndianess(reinterpret_cast<unsigned char *>(buffer), typeSize, count);
C* temp = (C*)buffer;
ContainerType* container = (ContainerType*)((unsigned char*)descr.base + descr.curPos * sizeof(ContainerType));
(*container).resize(count);
for (int i = 0; i < count; i++)
(*container)[i] = (ScalarType)(temp[i]);
++(descr.curPos);
}
template<typename C>
static void ReadAscii(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop)
{
int count = prop.CountValue();
if (prop.type >= NNP_LIST_UINT8_UINT32)
file.ReadAsciiData(count);
C* temp = new C[count];
for (int i = 0; i < count; i++)
file.ReadAsciiData(temp[i]);
ContainerType* container = (ContainerType*)((unsigned char*)descr.base + descr.curPos * sizeof(ContainerType));
(*container).resize(count);
for (int i = 0; i < count; i++)
(*container)[i] = (ScalarType)(temp[i]);
delete[] temp;
++(descr.curPos);
}
template<typename C>
static void WriteBinary(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop, bool fixEndian)
{
size_t count = prop.CountValue();
ContainerType* list = (ContainerType*)((unsigned char*)descr.base + descr.curPos * sizeof(ContainerType));
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
char listSize = (char)list->size();
file.WriteBinaryData(&listSize, 1);
count = list->size();
}
else
{
unsigned char listSize = (unsigned char)list->size();
file.WriteBinaryData(&listSize, 1);
count = list->size();
}
}
std::vector<C> data(count);
for (int i = 0; i < std::min(count, list->size()); i++)
data[i] = (C)((*list)[i]);
if (sizeof(C) > 1 && fixEndian)
adjustEndianess((unsigned char*)data.data(), sizeof(C), std::min(count, list->size()));
file.WriteBinaryData(data.data(), sizeof(C)*std::min(count, list->size()));
C temp = 0;
for (int i = 0; i < (count - list->size()); i++)
file.WriteBinaryData(&temp, sizeof(C));
++(descr.curPos);
}
template<typename C>
static void WriteAscii(DescriptorInterface& descr, PlyFile &file, PlyProperty &prop)
{
size_t count = prop.CountValue();
ContainerType* list = (ContainerType*)((unsigned char*)descr.base + descr.curPos * sizeof(ContainerType));
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
int listSize = (int)list->size();
file.WriteAsciiData(listSize);
count = list->size();
}
else
{
unsigned int listSize = (unsigned int)list->size();
file.WriteAsciiData(listSize);
count = list->size();
}
file.WriteAsciiData(std::string(" "));
}
std::vector<C> data(count);
for (int i = 0; i < std::min(count, list->size()); i++)
data[i] = (C)((*list)[i]);
for (int i = 0; i < (count - list->size()); i++)
data[i] = 0;
for (int i = 0; i < count; i++)
{
file.WriteAsciiData(data[i]);
if (i < count - 1)
file.WriteAsciiData(std::string(" "));
}
++(descr.curPos);
}
};
/** Memory descriptor of a vector of properties.
* The class defines how a vector of PlyProperty is saved in memory.
*
* @tparam CointainerType Type of the container of the property
* @tparam ContainerType Type of the container of the property
* @tparam VectorSize Number of values stored in the property.
* @tparam ScalarType Type of the values stored in the property.
*/
template<class CointainerType, int VectorSize, typename ScalarType>
template<class ContainerType, int VectorSize, typename ScalarType>
class DataDescriptor : public DescriptorInterface
{
public:
DescriptorHelper<ContainerType, VectorSize, ScalarType> helper;
inline DataDescriptor();
/**
@ -2018,7 +2340,7 @@ namespace nanoply
* @param _s Name of the PlyProperty.
* @param _b Pointer to the memory location that contains the data of the property.
*/
inline DataDescriptor(std::string& _s, void *_b) :DescriptorInterface(_s, _b){};
inline DataDescriptor(const std::string& _s, void *_b) :DescriptorInterface(_s, _b){};
inline void Restart();
@ -2029,75 +2351,18 @@ namespace nanoply
inline bool WriteElemBinary(PlyFile &file, PlyProperty &prop, bool fixEndian);
inline bool WriteElemAscii(PlyFile &file, PlyProperty &prop);
private:
template<typename C>
inline void ReadBinary(PlyFile &file, PlyProperty &prop, bool fixEndian);
template<typename C>
inline void ReadAscii(PlyFile &file, PlyProperty &prop);
template<typename C>
inline void WriteBinary(PlyFile &file, PlyProperty &prop, bool fixEndian);
template<typename C>
inline void WriteAscii(PlyFile &file, PlyProperty &prop);
};
template<class CointainerType, int VectorSize, typename ScalarType>
inline void DataDescriptor<CointainerType, VectorSize, ScalarType>::Restart()
template<class ContainerType, int VectorSize, typename ScalarType>
void DataDescriptor<ContainerType, VectorSize, ScalarType>::Restart()
{
this->curPos = 0;
}
template<class ContainerType, int VectorSize, typename ScalarType>
template<typename C>
inline void DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
{
char * buffer = nullptr;
int size;
int count = prop.CountValue();
int typeSize = prop.TypeSize();
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
file.ReadBinaryData(buffer, sizeof(char));
const int cntList = int(*(reinterpret_cast<unsigned char *>(buffer)));
size = typeSize * cntList;
count = cntList;
}
else
size = typeSize * count;
file.ReadBinaryData(buffer, size);
if (typeSize > 1 && fixEndian)
adjustEndianess(reinterpret_cast<unsigned char *>(buffer), typeSize, count);
unsigned char* baseProp = (unsigned char*)base + this->curPos*sizeof(ContainerType);
C* temp = (C*)buffer;
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && std::is_same<C, unsigned char>::value)
norm = 1.0f / 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && std::is_same<C, float>::value)
norm = 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i*sizeof(ScalarType))) = ScalarType(temp[i] * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i*sizeof(ScalarType))) = ScalarType(temp[i]);
}
++(this->curPos);
}
template<class ContainerType, int VectorSize, typename ScalarType>
inline bool DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadElemBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
bool DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadElemBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
{
if (prop.elem != elem)
return false;
@ -2105,70 +2370,35 @@ namespace nanoply
{
case NNP_LIST_INT8_INT8:
case NNP_LIST_UINT8_INT8:
case NNP_INT8: this->ReadBinary<char>(file, prop, fixEndian); break;
case NNP_INT8: helper.ReadBinary<char>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_UINT8:
case NNP_LIST_UINT8_UINT8:
case NNP_UINT8: this->ReadBinary<unsigned char>(file, prop, fixEndian); break;
case NNP_UINT8: helper.ReadBinary<unsigned char>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_INT16:
case NNP_LIST_UINT8_INT16:
case NNP_INT16: this->ReadBinary<short>(file, prop, fixEndian); break;
case NNP_INT16: helper.ReadBinary<short>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_UINT16:
case NNP_LIST_UINT8_UINT16:
case NNP_UINT16: this->ReadBinary<unsigned short>(file, prop, fixEndian); break;
case NNP_UINT16: helper.ReadBinary<unsigned short>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_FLOAT32:
case NNP_LIST_UINT8_FLOAT32:
case NNP_FLOAT32: this->ReadBinary<float>(file, prop, fixEndian); break;
case NNP_FLOAT32: helper.ReadBinary<float>(*this, file, prop, fixEndian); break;
case NNP_LIST_UINT8_INT32:
case NNP_LIST_INT8_INT32:
case NNP_INT32: this->ReadBinary<int>(file, prop, fixEndian); break;
case NNP_INT32: helper.ReadBinary<int>(*this, file, prop, fixEndian); break;
case NNP_LIST_UINT8_UINT32:
case NNP_LIST_INT8_UINT32:
case NNP_UINT32: this->ReadBinary<unsigned int>(file, prop, fixEndian); break;
case NNP_UINT32: helper.ReadBinary<unsigned int>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_FLOAT64:
case NNP_LIST_UINT8_FLOAT64:
case NNP_FLOAT64: this->ReadBinary<double>(file, prop, fixEndian); break;
case NNP_FLOAT64: helper.ReadBinary<double>(*this, file, prop, fixEndian); break;
}
return true;
}
template<class ContainerType, int VectorSize, typename ScalarType>
template<typename C>
inline void DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadAscii(PlyFile &file, PlyProperty &prop)
{
int count = prop.CountValue();
if (prop.type >= NNP_LIST_UINT8_UINT32)
file.ReadAsciiData(count);
C* temp = new C[count];
for (int i = 0; i < count; i++)
file.ReadAsciiData(temp[i]);
unsigned char* baseProp = (unsigned char*)base + this->curPos*sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && prop.type == NNP_UINT8)
norm = 1.0f / 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && prop.type == NNP_FLOAT32)
norm = 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i*sizeof(ScalarType))) = ScalarType(temp[i] * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
*((ScalarType *)(baseProp + i*sizeof(ScalarType))) = ScalarType(temp[i]);
}
delete[] temp;
++(this->curPos);
}
template<class ContainerType, int VectorSize, typename ScalarType>
inline bool DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadElemAscii(PlyFile &file, PlyProperty &prop)
bool DataDescriptor<ContainerType, VectorSize, ScalarType>::ReadElemAscii(PlyFile &file, PlyProperty &prop)
{
if (prop.elem != elem)
return false;
@ -2176,87 +2406,35 @@ namespace nanoply
{
case NNP_LIST_UINT8_INT8:
case NNP_LIST_INT8_INT8:
case NNP_INT8: this->ReadAscii<int>(file, prop); break;
case NNP_INT8: helper.ReadAscii<int>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT8:
case NNP_LIST_INT8_UINT8:
case NNP_UINT8: this->ReadAscii<unsigned int>(file, prop); break;
case NNP_UINT8: helper.ReadAscii<unsigned int>(*this, file, prop); break;
case NNP_LIST_UINT8_INT16:
case NNP_LIST_INT8_INT16:
case NNP_INT16: this->ReadAscii<short>(file, prop); break;
case NNP_INT16: helper.ReadAscii<short>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT16:
case NNP_LIST_INT8_UINT16:
case NNP_UINT16: this->ReadAscii<unsigned short>(file, prop); break;
case NNP_UINT16: helper.ReadAscii<unsigned short>(*this, file, prop); break;
case NNP_LIST_UINT8_FLOAT32:
case NNP_LIST_INT8_FLOAT32:
case NNP_FLOAT32: this->ReadAscii<float>(file, prop); break;
case NNP_FLOAT32: helper.ReadAscii<float>(*this, file, prop); break;
case NNP_LIST_UINT8_INT32:
case NNP_LIST_INT8_INT32:
case NNP_INT32: this->ReadAscii<int>(file, prop); break;
case NNP_INT32: helper.ReadAscii<int>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT32:
case NNP_LIST_INT8_UINT32:
case NNP_UINT32: this->ReadAscii<unsigned int>(file, prop); break;
case NNP_UINT32: helper.ReadAscii<unsigned int>(*this, file, prop); break;
case NNP_LIST_UINT8_FLOAT64:
case NNP_LIST_INT8_FLOAT64:
case NNP_FLOAT64: this->ReadAscii<double>(file, prop); break;
case NNP_FLOAT64: helper.ReadAscii<double>(*this, file, prop); break;
}
return true;
}
template<class ContainerType, int VectorSize, typename ScalarType>
template<typename C>
inline void DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
{
(void)fixEndian;
int count = prop.CountValue();
C data[VectorSize];
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
char listSize = (char)VectorSize;
file.WriteBinaryData(&listSize, 1);
count = VectorSize;
}
else
{
unsigned char listSize = (unsigned char)VectorSize;
file.WriteBinaryData(&listSize, 1);
count = VectorSize;
}
}
C temp = 0;
unsigned char* baseProp = (unsigned char*)base + this->curPos*sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0f;
if (std::is_same<ScalarType, float>::value && std::is_same<C, unsigned char>::value)
norm = 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && std::is_same<C, float>::value)
norm = 1.0f / 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i*sizeof(ScalarType))) * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i*sizeof(ScalarType))));
}
if (sizeof(C) > 1 && fixEndian)
adjustEndianess((unsigned char*)data, sizeof(C), std::min(VectorSize, count));
file.WriteBinaryData(data, sizeof(C)*std::min(VectorSize, count));
for (int i = 0; i < (count - VectorSize); i++)
file.WriteBinaryData(&temp, sizeof(C));
++(this->curPos);
}
template<class ContainerType, int VectorSize, typename ScalarType>
inline bool DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteElemBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
bool DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteElemBinary(PlyFile &file, PlyProperty &prop, bool fixEndian)
{
if (prop.elem != elem)
return false;
@ -2264,89 +2442,35 @@ namespace nanoply
{
case NNP_LIST_INT8_INT8:
case NNP_LIST_UINT8_INT8:
case NNP_INT8: this->WriteBinary<char>(file, prop, fixEndian); break;
case NNP_INT8: helper.WriteBinary<char>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_UINT8:
case NNP_LIST_UINT8_UINT8:
case NNP_UINT8: this->WriteBinary<unsigned char>(file, prop, fixEndian); break;
case NNP_UINT8: helper.WriteBinary<unsigned char>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_INT16:
case NNP_LIST_UINT8_INT16:
case NNP_INT16: this->WriteBinary<short>(file, prop, fixEndian); break;
case NNP_INT16: helper.WriteBinary<short>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_UINT16:
case NNP_LIST_UINT8_UINT16:
case NNP_UINT16: this->WriteBinary<unsigned short>(file, prop, fixEndian); break;
case NNP_UINT16: helper.WriteBinary<unsigned short>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_FLOAT32:
case NNP_LIST_UINT8_FLOAT32:
case NNP_FLOAT32: this->WriteBinary<float>(file, prop, fixEndian); break;
case NNP_FLOAT32: helper.WriteBinary<float>(*this, file, prop, fixEndian); break;
case NNP_LIST_UINT8_INT32:
case NNP_LIST_INT8_INT32:
case NNP_INT32: this->WriteBinary<int>(file, prop, fixEndian); break;
case NNP_INT32: helper.WriteBinary<int>(*this, file, prop, fixEndian); break;
case NNP_LIST_UINT8_UINT32:
case NNP_LIST_INT8_UINT32:
case NNP_UINT32: this->WriteBinary<unsigned int>(file, prop, fixEndian); break;
case NNP_UINT32: helper.WriteBinary<unsigned int>(*this, file, prop, fixEndian); break;
case NNP_LIST_INT8_FLOAT64:
case NNP_LIST_UINT8_FLOAT64:
case NNP_FLOAT64: this->WriteBinary<double>(file, prop, fixEndian); break;
case NNP_FLOAT64: helper.WriteBinary<double>(*this, file, prop, fixEndian); break;
}
return true;
}
template<class ContainerType, int VectorSize, typename ScalarType>
template<typename C>
inline void DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteAscii(PlyFile &file, PlyProperty &prop)
{
int count = prop.CountValue();
if (prop.type >= NNP_LIST_UINT8_UINT32)
{
if (prop.IsSigned())
{
int listSize = (int)VectorSize;
file.WriteAsciiData(listSize);
count = VectorSize;
}
else
{
unsigned int listSize = (unsigned int)VectorSize;
file.WriteAsciiData(listSize);
count = VectorSize;
}
file.WriteAsciiData(std::string(" "));
}
C data[VectorSize];
unsigned char* baseProp = (unsigned char*)base + this->curPos*sizeof(ContainerType);
if ((prop.elem == NNP_CRGB || prop.elem == NNP_CRGBA))
{
float norm = 1.0;
if (std::is_same<ScalarType, float>::value && prop.type == NNP_UINT8)
norm = 255.0f;
else if (std::is_same<ScalarType, unsigned char>::value && prop.type == NNP_FLOAT32)
norm = 1.0f / 255.0f;
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i*sizeof(ScalarType))) * norm);
}
else
{
for (int i = 0; i < std::min(VectorSize, count); i++)
data[i] = (C)((*(ScalarType*)(baseProp + i*sizeof(ScalarType))));
}
for (int i = 0; i < (count - VectorSize); i++)
data[i] = 0;
for (int i = 0; i < count; i++)
{
file.WriteAsciiData(data[i]);
if (i < count - 1)
file.WriteAsciiData(std::string(" "));
}
++(this->curPos);
}
template<class ContainerType, int VectorSize, typename ScalarType>
inline bool DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteElemAscii(PlyFile &file, PlyProperty& prop)
bool DataDescriptor<ContainerType, VectorSize, ScalarType>::WriteElemAscii(PlyFile &file, PlyProperty& prop)
{
if (prop.elem != elem)
return false;
@ -2356,28 +2480,28 @@ namespace nanoply
{
case NNP_LIST_UINT8_INT8:
case NNP_LIST_INT8_INT8:
case NNP_INT8: this->WriteAscii<int>(file, prop); break;
case NNP_INT8: helper.WriteAscii<int>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT8:
case NNP_LIST_INT8_UINT8:
case NNP_UINT8: this->WriteAscii<unsigned int>(file, prop); break;
case NNP_UINT8: helper.WriteAscii<unsigned int>(*this, file, prop); break;
case NNP_LIST_UINT8_INT16:
case NNP_LIST_INT8_INT16:
case NNP_INT16: this->WriteAscii<short>(file, prop); break;
case NNP_INT16: helper.WriteAscii<short>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT16:
case NNP_LIST_INT8_UINT16:
case NNP_UINT16: this->WriteAscii<unsigned short>(file, prop); break;
case NNP_UINT16: helper.WriteAscii<unsigned short>(*this, file, prop); break;
case NNP_LIST_UINT8_FLOAT32:
case NNP_LIST_INT8_FLOAT32:
case NNP_FLOAT32: this->WriteAscii<float>(file, prop); break;
case NNP_FLOAT32: helper.WriteAscii<float>(*this, file, prop); break;
case NNP_LIST_UINT8_INT32:
case NNP_LIST_INT8_INT32:
case NNP_INT32: this->WriteAscii<int>(file, prop); break;
case NNP_INT32: helper.WriteAscii<int>(*this, file, prop); break;
case NNP_LIST_UINT8_UINT32:
case NNP_LIST_INT8_UINT32:
case NNP_UINT32: this->WriteAscii<unsigned int>(file, prop); break;
case NNP_UINT32: helper.WriteAscii<unsigned int>(*this, file, prop); break;
case NNP_LIST_UINT8_FLOAT64:
case NNP_LIST_INT8_FLOAT64:
case NNP_FLOAT64: this->WriteAscii<double>(file, prop); break;
case NNP_FLOAT64: helper.WriteAscii<double>(*this, file, prop); break;
}
return true;
}

File diff suppressed because it is too large Load Diff