| 1 |
/**************************************************************************** |
| 2 |
* NanoPLY * |
| 3 |
* NanoPLY is a C++11 header-only library to read and write PLY file * |
| 4 |
* * |
| 5 |
* Copyright(C) 2014-2015 * |
| 6 |
* Visual Computing Lab * |
| 7 |
* ISTI - Italian National Research Council * |
| 8 |
* * |
| 9 |
* This Source Code Form is subject to the terms of the Mozilla Public * |
| 10 |
* License, v. 2.0. If a copy of the MPL was not distributed with this * |
| 11 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * |
| 12 |
* * |
| 13 |
****************************************************************************/ |
| 14 |
|
| 15 |
#ifndef NANOPLY_WRAPPER_VCG_H |
| 16 |
#define NANOPLY_WRAPPER_VCG_H |
| 17 |
|
| 18 |
#include <wrap/nanoply/include/nanoply.hpp> |
| 19 |
#include <vcg/complex/complex.h> |
| 20 |
#include <vcg/space/point.h> |
| 21 |
#include <map> |
| 22 |
|
| 23 |
#include <typeinfo> |
| 24 |
#include <type_traits> |
| 25 |
|
| 26 |
namespace nanoply |
| 27 |
{ |
| 28 |
|
| 29 |
template <class MeshType> |
| 30 |
class NanoPlyWrapper{ |
| 31 |
|
| 32 |
|
| 33 |
private: |
| 34 |
|
| 35 |
typedef typename MeshType::PointerToAttribute PointerToAttribute; |
| 36 |
typedef typename MeshType::ScalarType ScalarType; |
| 37 |
|
| 38 |
typedef typename MeshType::VertexType VertexType; |
| 39 |
typedef typename MeshType::VertexType::ScalarType VertexCoordScalar; |
| 40 |
typedef typename MeshType::VertexType::NormalType VertexNormalType; |
| 41 |
typedef typename MeshType::VertexType::NormalType::ScalarType VertexNormScalar; |
| 42 |
typedef typename MeshType::VertexType::ColorType VertexColorType; |
| 43 |
typedef typename MeshType::VertexType::ColorType::ScalarType VertexColorScalar; |
| 44 |
typedef typename MeshType::VertexType::QualityType VertexQuality; |
| 45 |
typedef typename MeshType::VertexType::RadiusType VertexRadius; |
| 46 |
typedef typename MeshType::VertexType::FlagType VertexFlag; |
| 47 |
typedef typename MeshType::VertexType::TexCoordType VertexTexCoordType; |
| 48 |
typedef typename MeshType::VertexType::TexCoordType::ScalarType VertexTexScalar; |
| 49 |
typedef typename MeshType::VertexType::CurvatureType VertexCurType; |
| 50 |
typedef typename MeshType::VertexType::CurvatureType::ScalarType VertexCurScalar; |
| 51 |
typedef typename MeshType::VertexType::CurvatureDirType VertexCurDirType; |
| 52 |
typedef typename MeshType::VertexType::CurScalarType VertexDirCurScalar; |
| 53 |
typedef typename MeshType::VertexType::CurVecType::ScalarType VertexDirCurVecScalar; |
| 54 |
|
| 55 |
typedef typename MeshType::EdgeType EdgeType; |
| 56 |
typedef typename MeshType::EdgeType::ColorType::ScalarType EdgeColorScalar; |
| 57 |
typedef typename MeshType::EdgeType::QualityType EdgeQuality; |
| 58 |
typedef typename MeshType::EdgeType::FlagType EdgeFlag; |
| 59 |
|
| 60 |
typedef typename MeshType::FaceType FaceType; |
| 61 |
typedef typename MeshType::FaceType::NormalType FaceNormalType; |
| 62 |
typedef typename MeshType::FaceType::NormalType::ScalarType FaceNormScalar; |
| 63 |
typedef typename MeshType::FaceType::ColorType FaceColorType; |
| 64 |
typedef typename MeshType::FaceType::ColorType::ScalarType FaceColorScalar; |
| 65 |
typedef typename MeshType::FaceType::QualityType FaceQuality; |
| 66 |
typedef typename MeshType::FaceType::FlagType FaceFlag; |
| 67 |
typedef typename vcg::face::vector_ocf<FaceType>::WedgeTexTypePack FaceTexCoordType; |
| 68 |
typedef typename MeshType::FaceType::TexCoordType::ScalarType FaceTexScalar; |
| 69 |
typedef typename MeshType::FaceType::CurvatureDirType FaceCurDirType; |
| 70 |
typedef typename MeshType::FaceType::CurScalarType FaceDirCurScalar; |
| 71 |
typedef typename MeshType::FaceType::CurVecType::ScalarType FaceDirCurVecScalar; |
| 72 |
typedef typename vcg::face::vector_ocf<FaceType>::WedgeColorTypePack WedgeColorType; |
| 73 |
typedef typename MeshType::FaceType::WedgeColorType::ScalarType WedgeColorScalar; |
| 74 |
typedef typename vcg::face::vector_ocf<FaceType>::WedgeNormalTypePack WedgeNormalType; |
| 75 |
typedef typename MeshType::FaceType::WedgeNormalType::ScalarType WedgeNormalScalar; |
| 76 |
|
| 77 |
typedef typename MeshType::FaceIterator FaceIterator; |
| 78 |
|
| 79 |
template<class T> |
| 80 |
static PlyType getEntity() |
| 81 |
{ |
| 82 |
if constexpr (std::is_same<T, unsigned char>::value) { return NNP_UINT8; } |
| 83 |
if constexpr (std::is_same<T, char>::value) { return NNP_INT8; } |
| 84 |
if constexpr (std::is_same<T, unsigned short>::value) { return NNP_UINT16; } |
| 85 |
if constexpr (std::is_same<T, short>::value) { return NNP_INT16; } |
| 86 |
if constexpr (std::is_same<T, unsigned int>::value) { return NNP_UINT32; } |
| 87 |
if constexpr (std::is_same<T, int>::value) { return NNP_INT32; } |
| 88 |
if constexpr (std::is_same<T, float>::value) { return NNP_FLOAT32; } |
| 89 |
if constexpr (std::is_same<T, double>::value) { return NNP_FLOAT64; } |
| 90 |
return NNP_UNKNOWN_TYPE; |
| 91 |
}; |
| 92 |
|
| 93 |
template<class T> |
| 94 |
static PlyType getEntityList() |
| 95 |
{ |
| 96 |
if constexpr (std::is_same<T, unsigned char>::value) { return NNP_LIST_UINT8_UINT8; }; |
| 97 |
if constexpr (std::is_same<T, char>::value) { return NNP_LIST_UINT8_INT8; }; |
| 98 |
if constexpr (std::is_same<T, unsigned short>::value) { return NNP_LIST_UINT8_UINT16; }; |
| 99 |
if constexpr (std::is_same<T, short>::value) { return NNP_LIST_UINT8_INT16; }; |
| 100 |
if constexpr (std::is_same<T, unsigned int>::value) { return NNP_LIST_UINT8_UINT32; }; |
| 101 |
if constexpr (std::is_same<T, int>::value) { return NNP_LIST_UINT8_INT32; }; |
| 102 |
if constexpr (std::is_same<T, float>::value) { return NNP_LIST_UINT8_FLOAT32; }; |
| 103 |
if constexpr (std::is_same<T, double>::value) { return NNP_LIST_UINT8_FLOAT64; }; |
| 104 |
return NNP_UNKNOWN_TYPE; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
template<class Container, class Type, int n> |
| 109 |
inline static void PushDescriport(std::vector<PlyProperty>& prop, ElementDescriptor& elem, PlyEntity entity, void* ptr) |
| 110 |
{ |
| 111 |
prop.push_back(PlyProperty(getEntity<Type>(), entity)); |
| 112 |
DescriptorInterface* di = new DataDescriptor<Container, n, Type>(entity, ptr); |
| 113 |
elem.dataDescriptor.push_back(di); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
template<class Container, class Type, int n> |
| 118 |
inline static void PushDescriportList(std::vector<PlyProperty>& prop, ElementDescriptor& elem, PlyEntity entity, void* ptr) |
| 119 |
{ |
| 120 |
prop.push_back(PlyProperty(getEntityList<Type>(), entity)); |
| 121 |
DescriptorInterface* di = new DataDescriptor<Container, n, Type>(entity, ptr); |
| 122 |
elem.dataDescriptor.push_back(di); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
template<class Container, class Type, int n> |
| 127 |
inline static void PushDescriport(std::vector<PlyProperty>& prop, ElementDescriptor& elem, const std::string& name, void* ptr) |
| 128 |
{ |
| 129 |
prop.push_back(PlyProperty(getEntity<Type>(), name)); |
| 130 |
DescriptorInterface* di = new DataDescriptor<Container, n, Type>(name, ptr); |
| 131 |
elem.dataDescriptor.push_back(di); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
template<class Container, class Type, int n> |
| 136 |
inline static void PushDescriportList(std::vector<PlyProperty>& prop, ElementDescriptor& elem, const std::string& name, void* ptr) |
| 137 |
{ |
| 138 |
prop.push_back(PlyProperty(getEntityList<Type>(), name)); |
| 139 |
DescriptorInterface* di = new DataDescriptor<Container, n, Type>(name, ptr); |
| 140 |
elem.dataDescriptor.push_back(di); |
| 141 |
} |
| 142 |
|
| 143 |
public: |
| 144 |
|
| 145 |
|
| 146 |
typedef enum { |
| 147 |
IO_NONE = 0x00000000, |
| 148 |
|
| 149 |
IO_VERTCOORD = 0x00000001, |
| 150 |
IO_VERTFLAGS = 0x00000002, |
| 151 |
IO_VERTCOLOR = 0x00000004, |
| 152 |
IO_VERTQUALITY = 0x00000008, |
| 153 |
IO_VERTNORMAL = 0x00000010, |
| 154 |
IO_VERTTEXCOORD = 0x00000020, |
| 155 |
IO_VERTRADIUS = 0x00000040, |
| 156 |
IO_VERTCURV = 0x00000080, |
| 157 |
IO_VERTCURVDIR = 0x00000100, |
| 158 |
IO_VERTATTRIB = 0x00000200, |
| 159 |
|
| 160 |
IO_FACEINDEX = 0x00000400, |
| 161 |
IO_FACEFLAGS = 0x00000800, |
| 162 |
IO_FACECOLOR = 0x00001000, |
| 163 |
IO_FACEQUALITY = 0x00002000, |
| 164 |
IO_FACENORMAL = 0x00004000, |
| 165 |
IO_FACECURVDIR = 0x00008000, |
| 166 |
IO_FACEATTRIB = 0x00010000, |
| 167 |
|
| 168 |
IO_EDGEINDEX = 0x00020000, |
| 169 |
IO_EDGEQUALITY = 0x00040000, |
| 170 |
IO_EDGECOLOR = 0x00080000, |
| 171 |
IO_EDGEFLAGS = 0x00100000, |
| 172 |
IO_EDGEATTRIB = 0x00200000, |
| 173 |
|
| 174 |
IO_WEDGCOLOR = 0x00400000, |
| 175 |
IO_WEDGTEXCOORD = 0x00800000, |
| 176 |
IO_WEDGTEXMULTI = 0x01000000, // when texture index is explicit |
| 177 |
IO_WEDGNORMAL = 0x02000000, |
| 178 |
|
| 179 |
IO_ALL_ATTRIB = 0x03FFFFFF, |
| 180 |
|
| 181 |
IO_BITPOLYGONAL = 0x04000000, // loads explicit polygonal mesh |
| 182 |
|
| 183 |
IO_CAMERA = 0x08000000, |
| 184 |
IO_MESHATTRIB = 0x10000000, |
| 185 |
|
| 186 |
IO_FLAGS = IO_VERTFLAGS | IO_FACEFLAGS, |
| 187 |
|
| 188 |
IO_ALL = 0xFFFFFFFF |
| 189 |
}BitMask; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
class CustomAttributeDescriptor |
| 194 |
{ |
| 195 |
public: |
| 196 |
|
| 197 |
typedef std::map<std::string, ElementDescriptor::PropertyDescriptor> MapMeshAttrib; |
| 198 |
typedef std::map<std::string, ElementDescriptor::PropertyDescriptor>::iterator MapMeshAttribIter; |
| 199 |
typedef std::map<std::string, std::vector<PlyProperty>> MapMeshAttribProp; |
| 200 |
typedef std::map<std::string, std::vector<PlyProperty>>::iterator MapMeshAttribPropIter; |
| 201 |
|
| 202 |
ElementDescriptor::PropertyDescriptor vertexAttrib; |
| 203 |
ElementDescriptor::PropertyDescriptor faceAttrib; |
| 204 |
ElementDescriptor::PropertyDescriptor edgeAttrib; |
| 205 |
std::vector<PlyProperty> vertexAttribProp; |
| 206 |
std::vector<PlyProperty> faceAttribProp; |
| 207 |
std::vector<PlyProperty> edgeAttribProp; |
| 208 |
|
| 209 |
MapMeshAttrib meshAttrib; |
| 210 |
MapMeshAttribProp meshAttribProp; |
| 211 |
std::map<std::string, int> meshAttribCnt; |
| 212 |
|
| 213 |
|
| 214 |
~CustomAttributeDescriptor() |
| 215 |
{ |
| 216 |
for (size_t i = 0; i < vertexAttrib.size(); i++) |
| 217 |
delete vertexAttrib[i]; |
| 218 |
for (size_t i = 0; i < edgeAttrib.size(); i++) |
| 219 |
delete edgeAttrib[i]; |
| 220 |
for (size_t i = 0; i < faceAttrib.size(); i++) |
| 221 |
delete faceAttrib[i]; |
| 222 |
CustomAttributeDescriptor::MapMeshAttribIter iter = meshAttrib.begin(); |
| 223 |
for (; iter != meshAttrib.end(); iter++) |
| 224 |
for (size_t i = 0; i < (*iter).second.size(); i++) |
| 225 |
delete (*iter).second[i]; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
template<class Container, class Type, int n> |
| 230 |
void AddVertexAttribDescriptor(const std::string& name, PlyType type, void* ptr) |
| 231 |
{ |
| 232 |
AddAttribDescriptor<Container, Type, n>(name, type, ptr, vertexAttrib, vertexAttribProp); |
| 233 |
} |
| 234 |
|
| 235 |
template<class Container, class Type, int n> |
| 236 |
void AddEdgeAttribDescriptor(const std::string& name, PlyType type, void* ptr) |
| 237 |
{ |
| 238 |
AddAttribDescriptor<Container, Type, n>(name, type, ptr, edgeAttrib, edgeAttribProp); |
| 239 |
} |
| 240 |
|
| 241 |
template<class Container, class Type, int n> |
| 242 |
void AddFaceAttribDescriptor(const std::string& name, PlyType type, void* ptr) |
| 243 |
{ |
| 244 |
AddAttribDescriptor<Container, Type, n>(name, type, ptr, faceAttrib, faceAttribProp); |
| 245 |
} |
| 246 |
|
| 247 |
template<class Container, class Type, int n> |
| 248 |
void AddMeshAttribDescriptor(const std::string& nameAttrib, const std::string& nameProp, PlyType type, void* ptr) |
| 249 |
{ |
| 250 |
meshAttrib[nameAttrib].push_back(new DataDescriptor<Container, n, Type>(nameProp, ptr)); |
| 251 |
meshAttribProp[nameAttrib].push_back(PlyProperty(type, nameProp)); |
| 252 |
} |
| 253 |
|
| 254 |
void AddMeshAttrib(const std::string& name, int cnt) |
| 255 |
{ |
| 256 |
meshAttribCnt[name] = cnt; |
| 257 |
} |
| 258 |
|
| 259 |
void GetMeshAttrib(std::string filename) |
| 260 |
{ |
| 261 |
nanoply::Info info(filename); |
| 262 |
if (info.errInfo == nanoply::NNP_OK) |
| 263 |
{ |
| 264 |
for (size_t i = 0; i < info.elemVec.size(); i++) |
| 265 |
{ |
| 266 |
if (info.elemVec[i].plyElem == NNP_UNKNOWN_ELEM && info.elemVec[i].name != "camera") |
| 267 |
meshAttribCnt[info.elemVec[i].name] = info.elemVec[i].cnt; |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
bool CreateVertexAttribDescriptor(const PointerToAttribute* ptr) |
| 273 |
{ |
| 274 |
return CreateAttribDescriptor(ptr, vertexAttrib, vertexAttribProp); |
| 275 |
} |
| 276 |
|
| 277 |
bool CreateEdgeAttribDescriptor(const PointerToAttribute* ptr) |
| 278 |
{ |
| 279 |
return CreateAttribDescriptor(ptr, edgeAttrib, edgeAttribProp); |
| 280 |
} |
| 281 |
|
| 282 |
bool CreateFaceAttribDescriptor(const PointerToAttribute* ptr) |
| 283 |
{ |
| 284 |
return CreateAttribDescriptor(ptr, faceAttrib, faceAttribProp); |
| 285 |
} |
| 286 |
|
| 287 |
bool AddVertexAttrib(MeshType& m, std::set<PointerToAttribute>& ptrAttrib, PlyElement* elem) |
| 288 |
{ |
| 289 |
return AddCustomAttrib<0>(m, ptrAttrib, elem, vertexAttrib); |
| 290 |
} |
| 291 |
|
| 292 |
bool AddEdgeAttrib(MeshType& m, std::set<PointerToAttribute>& ptrAttrib, PlyElement* elem) |
| 293 |
{ |
| 294 |
return AddCustomAttrib<1>(m, ptrAttrib, elem, edgeAttrib); |
| 295 |
} |
| 296 |
|
| 297 |
bool AddFaceAttrib(MeshType& m, std::set<PointerToAttribute>& ptrAttrib, PlyElement* elem) |
| 298 |
{ |
| 299 |
return AddCustomAttrib<2>(m, ptrAttrib, elem, faceAttrib); |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
private: |
| 305 |
|
| 306 |
const std::vector<std::string> pointSuffix = { "x", "y", "z", "w" }; |
| 307 |
const std::vector<std::string> colorSuffix = { "r", "g", "b", "a" }; |
| 308 |
const std::map<std::string, int> pointSuffixMap = { { "x", 0 },{ "y", 1 },{ "z", 2 },{ "w", 3 } }; |
| 309 |
const std::map<std::string, int> colorSuffixMap = { {"r", 0},{ "g", 1 },{ "b", 2 },{ "a", 3 } }; |
| 310 |
const std::string separator = std::string("@_.#$>"); |
| 311 |
|
| 312 |
template<class Container, class Type, int n> |
| 313 |
void AddAttribDescriptor(const std::string& name, PlyType type, void* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 314 |
{ |
| 315 |
attrib.push_back(new DataDescriptor<Container, n, Type>(name, ptr)); |
| 316 |
attribProp.push_back(PlyProperty(type, name)); |
| 317 |
} |
| 318 |
|
| 319 |
template<class Container> |
| 320 |
void AddScalarAttribDescriptor(const PointerToAttribute* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 321 |
{ |
| 322 |
AddAttribDescriptor<Container, Container, 1>(ptr->_name, getEntity<Container>(), ptr->_handle->DataBegin(), attrib, attribProp); |
| 323 |
} |
| 324 |
|
| 325 |
template<class Container> |
| 326 |
void AddPointAttribDescriptor(const PointerToAttribute* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 327 |
{ |
| 328 |
int size = int(Container::Dimension); |
| 329 |
std::string name(ptr->_name); |
| 330 |
Container* tmpPtr = (Container*)ptr->_handle->DataBegin(); |
| 331 |
for (int i = 0 ; i < size; i++) |
| 332 |
AddAttribDescriptor<Container, typename Container::ScalarType, 1>((name + "." + pointSuffix[i]), getEntity<typename Container::ScalarType>(), &(*tmpPtr)[i], attrib, attribProp); |
| 333 |
} |
| 334 |
|
| 335 |
template<class Container> |
| 336 |
void AddColorAttribDescriptor(const PointerToAttribute* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 337 |
{ |
| 338 |
int size = int(Container::Dimension); |
| 339 |
std::string name(ptr->_name); |
| 340 |
Container* tmpPtr = (Container*)ptr->_handle->DataBegin(); |
| 341 |
for (int i = 0; i < size; i++) |
| 342 |
AddAttribDescriptor<Container, typename Container::ScalarType, 1>((name + "." + colorSuffix[i]), getEntity<typename Container::ScalarType>(), &(*tmpPtr)[i], attrib, attribProp); |
| 343 |
} |
| 344 |
|
| 345 |
template<class Container, class Type> |
| 346 |
void AddListAttribDescriptor(const PointerToAttribute* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 347 |
{ |
| 348 |
AddAttribDescriptor<Container, Type, 0>(ptr->_name, getEntityList<Type>(), ptr->_handle->DataBegin(), attrib, attribProp); |
| 349 |
} |
| 350 |
|
| 351 |
bool CreateAttribDescriptor(const PointerToAttribute* ptr, ElementDescriptor::PropertyDescriptor& attrib, std::vector<PlyProperty>& attribProp) |
| 352 |
{ |
| 353 |
if (ptr->_type == std::type_index(typeid(unsigned char))) |
| 354 |
AddScalarAttribDescriptor<unsigned char >(ptr, attrib, attribProp); |
| 355 |
else if (ptr->_type == std::type_index(typeid(char))) |
| 356 |
AddScalarAttribDescriptor<char>(ptr, attrib, attribProp); |
| 357 |
else if (ptr->_type == std::type_index(typeid(unsigned short))) |
| 358 |
AddScalarAttribDescriptor<unsigned short>(ptr, attrib, attribProp); |
| 359 |
else if (ptr->_type == std::type_index(typeid(short))) |
| 360 |
AddScalarAttribDescriptor<short>(ptr, attrib, attribProp); |
| 361 |
else if (ptr->_type == std::type_index(typeid(unsigned int))) |
| 362 |
AddScalarAttribDescriptor<unsigned int>(ptr, attrib, attribProp); |
| 363 |
else if (ptr->_type == std::type_index(typeid(int))) |
| 364 |
AddScalarAttribDescriptor<int>(ptr, attrib, attribProp); |
| 365 |
else if (ptr->_type == std::type_index(typeid(float))) |
| 366 |
AddScalarAttribDescriptor<float>(ptr, attrib, attribProp); |
| 367 |
else if (ptr->_type == std::type_index(typeid(double))) |
| 368 |
AddScalarAttribDescriptor<double>(ptr, attrib, attribProp); |
| 369 |
else if (ptr->_type == std::type_index(typeid(vcg::Point2s))) |
| 370 |
AddPointAttribDescriptor<vcg::Point2s>(ptr, attrib, attribProp); |
| 371 |
else if (ptr->_type == std::type_index(typeid(vcg::Point2i))) |
| 372 |
AddPointAttribDescriptor<vcg::Point2i>(ptr, attrib, attribProp); |
| 373 |
else if (ptr->_type == std::type_index(typeid(vcg::Point2f))) |
| 374 |
AddPointAttribDescriptor<vcg::Point2f>(ptr, attrib, attribProp); |
| 375 |
else if (ptr->_type == std::type_index(typeid(vcg::Point2d))) |
| 376 |
AddPointAttribDescriptor<vcg::Point2d>(ptr, attrib, attribProp); |
| 377 |
else if (ptr->_type == std::type_index(typeid(vcg::Point3s))) |
| 378 |
AddPointAttribDescriptor<vcg::Point3s>(ptr, attrib, attribProp); |
| 379 |
else if (ptr->_type == std::type_index(typeid(vcg::Point3i))) |
| 380 |
AddPointAttribDescriptor<vcg::Point3i>(ptr, attrib, attribProp); |
| 381 |
else if (ptr->_type == std::type_index(typeid(vcg::Point3f))) |
| 382 |
AddPointAttribDescriptor<vcg::Point3f>(ptr, attrib, attribProp); |
| 383 |
else if (ptr->_type == std::type_index(typeid(vcg::Point3d))) |
| 384 |
AddPointAttribDescriptor<vcg::Point3d>(ptr, attrib, attribProp); |
| 385 |
else if (ptr->_type == std::type_index(typeid(vcg::Point4s))) |
| 386 |
AddPointAttribDescriptor<vcg::Point4s>(ptr, attrib, attribProp); |
| 387 |
else if (ptr->_type == std::type_index(typeid(vcg::Point4i))) |
| 388 |
AddPointAttribDescriptor<vcg::Point4i>(ptr, attrib, attribProp); |
| 389 |
else if (ptr->_type == std::type_index(typeid(vcg::Point4f))) |
| 390 |
AddPointAttribDescriptor<vcg::Point4f>(ptr, attrib, attribProp); |
| 391 |
else if (ptr->_type == std::type_index(typeid(vcg::Point4d))) |
| 392 |
AddPointAttribDescriptor<vcg::Point4d>(ptr, attrib, attribProp); |
| 393 |
else if (ptr->_type == std::type_index(typeid(vcg::Color4b))) |
| 394 |
AddColorAttribDescriptor<vcg::Color4b>(ptr, attrib, attribProp); |
| 395 |
else if (ptr->_type == std::type_index(typeid(vcg::Color4f))) |
| 396 |
AddColorAttribDescriptor<vcg::Color4f>(ptr, attrib, attribProp); |
| 397 |
else if (ptr->_type == std::type_index(typeid(vcg::Color4d))) |
| 398 |
AddColorAttribDescriptor<vcg::Color4d>(ptr, attrib, attribProp); |
| 399 |
else if (ptr->_type == std::type_index(typeid(vcg::Color4d))) |
| 400 |
AddColorAttribDescriptor<vcg::Color4d>(ptr, attrib, attribProp); |
| 401 |
else if (ptr->_type == std::type_index(typeid(std::vector<unsigned char>))) |
| 402 |
AddListAttribDescriptor<std::vector<unsigned char>, unsigned char>(ptr, attrib, attribProp); |
| 403 |
else if (ptr->_type == std::type_index(typeid(std::vector<char>))) |
| 404 |
AddListAttribDescriptor<std::vector<char>,char>(ptr, attrib, attribProp); |
| 405 |
else if (ptr->_type == std::type_index(typeid(std::vector<unsigned short>))) |
| 406 |
AddListAttribDescriptor<std::vector<unsigned short>, unsigned short>(ptr, attrib, attribProp); |
| 407 |
else if (ptr->_type == std::type_index(typeid(std::vector<short>))) |
| 408 |
AddListAttribDescriptor<std::vector<short>, short>(ptr, attrib, attribProp); |
| 409 |
else if (ptr->_type == std::type_index(typeid(std::vector<unsigned int>))) |
| 410 |
AddListAttribDescriptor<std::vector<unsigned int>, unsigned int>(ptr, attrib, attribProp); |
| 411 |
else if (ptr->_type == std::type_index(typeid(std::vector<int>))) |
| 412 |
AddListAttribDescriptor<std::vector<int>, int>(ptr, attrib, attribProp); |
| 413 |
else if (ptr->_type == std::type_index(typeid(std::vector<float>))) |
| 414 |
AddListAttribDescriptor<std::vector<float>, float>(ptr, attrib, attribProp); |
| 415 |
else if (ptr->_type == std::type_index(typeid(std::vector<double>))) |
| 416 |
AddListAttribDescriptor<std::vector<double>, double>(ptr, attrib, attribProp); |
| 417 |
else |
| 418 |
return false; |
| 419 |
return true; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
template <size_t ActionType, class Container> |
| 424 |
void AddScalarAttrib(MeshType& m, const std::string& name, PlyType& type) |
| 425 |
{ |
| 426 |
if (ActionType == 0) //vertex |
| 427 |
{ |
| 428 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<Container>(m, name); |
| 429 |
AddVertexAttribDescriptor<Container, Container, 1>(name, type, h._handle->DataBegin()); |
| 430 |
} |
| 431 |
else if (ActionType == 1) //Edge |
| 432 |
{ |
| 433 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerEdgeAttribute<Container>(m, name); |
| 434 |
AddEdgeAttribDescriptor<Container, Container, 1>(name, type, h._handle->DataBegin()); |
| 435 |
} |
| 436 |
else if (ActionType == 2) //Face |
| 437 |
{ |
| 438 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerFaceAttribute<Container>(m, name); |
| 439 |
AddFaceAttribDescriptor<Container, Container, 1>(name, type, h._handle->DataBegin()); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
template <size_t ActionType, class Container> |
| 444 |
void AddPointAttrib(MeshType& m, const std::string& name, std::vector<PlyProperty>& prop) |
| 445 |
{ |
| 446 |
if (ActionType == 0) //vertex |
| 447 |
{ |
| 448 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<Container>(m, name); |
| 449 |
for (size_t i = 0; i < prop.size(); i++) |
| 450 |
AddVertexAttribDescriptor<Container, typename Container::ScalarType, 1>(prop[i].name, prop[i].type, &h[0][i]); |
| 451 |
} |
| 452 |
else if (ActionType == 1) //Edge |
| 453 |
{ |
| 454 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerEdgeAttribute<Container>(m, name); |
| 455 |
for (size_t i = 0; i < prop.size(); i++) |
| 456 |
AddEdgeAttribDescriptor<Container, typename Container::ScalarType, 1>(prop[i].name, prop[i].type, &h[0][i]); |
| 457 |
} |
| 458 |
else if (ActionType == 2) //Face |
| 459 |
{ |
| 460 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerFaceAttribute<Container>(m, name); |
| 461 |
for (size_t i = 0; i < prop.size(); i++) |
| 462 |
AddFaceAttribDescriptor<Container, typename Container::ScalarType, 1>(prop[i].name, prop[i].type, &h[0][i]); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
template <size_t ActionType, class Container, class Type> |
| 468 |
void AddListAttrib(MeshType& m, const std::string& name, PlyType& type) |
| 469 |
{ |
| 470 |
if (ActionType == 0) //vertex |
| 471 |
{ |
| 472 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<Container>(m, name); |
| 473 |
AddVertexAttribDescriptor<Container, Type, 0>(name, type, h._handle->DataBegin()); |
| 474 |
} |
| 475 |
else if (ActionType == 1) //Edge |
| 476 |
{ |
| 477 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerEdgeAttribute<Container>(m, name); |
| 478 |
AddEdgeAttribDescriptor<Container, Type, 0>(name, type, h._handle->DataBegin()); |
| 479 |
} |
| 480 |
else if (ActionType == 2) //Face |
| 481 |
{ |
| 482 |
auto h = vcg::tri::Allocator<MeshType>::template GetPerFaceAttribute<Container>(m, name); |
| 483 |
AddFaceAttribDescriptor<Container, Type, 0>(name, type, h._handle->DataBegin()); |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
template <size_t ActionType> |
| 489 |
bool AddCustomAttrib(MeshType& m, std::set<PointerToAttribute>& ptrAttrib, PlyElement* elem, ElementDescriptor::PropertyDescriptor& attrib) |
| 490 |
{ |
| 491 |
//Custom attribute with already a data descriptor |
| 492 |
std::set<std::string> validCustomAttrib; |
| 493 |
for (size_t i = 0; i < attrib.size(); i++) |
| 494 |
{ |
| 495 |
if (attrib[i]->base == NULL) |
| 496 |
{ |
| 497 |
typename std::set<PointerToAttribute>::iterator ai; |
| 498 |
for (ai = ptrAttrib.begin(); ai != ptrAttrib.end(); ++ai) |
| 499 |
{ |
| 500 |
if (attrib[i]->name == (*ai)._name) |
| 501 |
{ |
| 502 |
attrib[i]->base = ai->_handle->DataBegin(); |
| 503 |
validCustomAttrib.insert(attrib[i]->name); |
| 504 |
break; |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
else |
| 509 |
validCustomAttrib.insert(attrib[i]->name); |
| 510 |
} |
| 511 |
//Get custom properties without a data descriptor |
| 512 |
std::map<std::string, std::pair<std::vector<PlyProperty>, int>> customAttribName; |
| 513 |
std::vector<std::string> attribName((*elem).propVec.size()); |
| 514 |
for (size_t i = 0; i < (*elem).propVec.size(); i++) |
| 515 |
{ |
| 516 |
if ((*elem).propVec[i].elem == NNP_UNKNOWN_ENTITY) |
| 517 |
{ |
| 518 |
if (validCustomAttrib.find((*elem).propVec[i].name) == validCustomAttrib.end()) |
| 519 |
{ |
| 520 |
std::size_t found = (*elem).propVec[i].name.find_first_of(separator); |
| 521 |
if (found != std::string::npos) |
| 522 |
{ |
| 523 |
attribName[i] = (*elem).propVec[i].name.substr(0, found); |
| 524 |
std::string suffix = (*elem).propVec[i].name.substr(found+1); |
| 525 |
std::map<std::string, int>::const_iterator it1, it2; |
| 526 |
it1 = pointSuffixMap.find(suffix); |
| 527 |
it2 = colorSuffixMap.find(suffix); |
| 528 |
if (it1 != pointSuffixMap.cend()) |
| 529 |
customAttribName[attribName[i]].second |= (1 << (*it1).second); |
| 530 |
else if (it2 != colorSuffixMap.cend()) |
| 531 |
customAttribName[attribName[i]].second |= (1 << ((*it2).second + 4)); |
| 532 |
} |
| 533 |
else |
| 534 |
attribName[i] = (*elem).propVec[i].name; |
| 535 |
customAttribName[attribName[i]].first.push_back((*elem).propVec[i]); |
| 536 |
|
| 537 |
} |
| 538 |
} |
| 539 |
} |
| 540 |
//Create the attribute and the data descriptor |
| 541 |
std::map<std::string, std::pair<std::vector<PlyProperty>, int>>::iterator mapIter; |
| 542 |
for (mapIter = customAttribName.begin(); mapIter != customAttribName.end(); mapIter++) |
| 543 |
{ |
| 544 |
unsigned int bitType = 0; |
| 545 |
std::vector<PlyProperty> tempProp((*mapIter).second.first.size()); |
| 546 |
int checkMask = (1 << (*mapIter).second.first.size()) - 1; |
| 547 |
for (size_t i = 0; i < (*mapIter).second.first.size(); i++) |
| 548 |
{ |
| 549 |
PlyProperty& p = (*mapIter).second.first[i]; |
| 550 |
bitType |= p.type; |
| 551 |
std::size_t found = p.name.find_first_of(separator); |
| 552 |
if (found != std::string::npos) |
| 553 |
{ |
| 554 |
std::string suffix = p.name.substr(found + 1); |
| 555 |
if ((*mapIter).second.second == checkMask) |
| 556 |
tempProp[(*pointSuffixMap.find(suffix)).second] = p; |
| 557 |
else if ((*mapIter).second.second == (checkMask << 4)) |
| 558 |
tempProp[(*colorSuffixMap.find(suffix)).second] = p; |
| 559 |
else |
| 560 |
tempProp[i] = p; |
| 561 |
} |
| 562 |
else |
| 563 |
tempProp[i] = p; |
| 564 |
} |
| 565 |
unsigned int r = (bitType & (~tempProp[0].type)); (void)r; |
| 566 |
if (tempProp.size() > 1 && ((bitType & (~tempProp[0].type)) == 0)) |
| 567 |
{ |
| 568 |
if (tempProp.size() == 2) |
| 569 |
{ |
| 570 |
switch (tempProp[0].type) |
| 571 |
{ |
| 572 |
case NNP_FLOAT32: AddPointAttrib<ActionType, vcg::Point2f>(m, (*mapIter).first, tempProp); break; |
| 573 |
case NNP_FLOAT64: AddPointAttrib<ActionType, vcg::Point2d>(m, (*mapIter).first, tempProp); break; |
| 574 |
case NNP_INT8: AddPointAttrib<ActionType, vcg::Point2<char>>(m, (*mapIter).first, tempProp); break; |
| 575 |
case NNP_INT16: AddPointAttrib<ActionType, vcg::Point2s>(m, (*mapIter).first, tempProp); break; |
| 576 |
case NNP_INT32: AddPointAttrib<ActionType, vcg::Point2i>(m, (*mapIter).first, tempProp); break; |
| 577 |
case NNP_UINT8: AddPointAttrib<ActionType, vcg::Point2<unsigned char>>(m, (*mapIter).first, tempProp); break; |
| 578 |
case NNP_UINT16: AddPointAttrib<ActionType, vcg::Point2<unsigned short>>(m, (*mapIter).first, tempProp); break; |
| 579 |
case NNP_UINT32: AddPointAttrib<ActionType, vcg::Point2<unsigned int>>(m, (*mapIter).first, tempProp); break; |
| 580 |
default: assert(0); |
| 581 |
} |
| 582 |
} |
| 583 |
else if (tempProp.size() == 3) |
| 584 |
{ |
| 585 |
switch (tempProp[0].type) |
| 586 |
{ |
| 587 |
case NNP_FLOAT32: AddPointAttrib<ActionType, vcg::Point3f>(m, (*mapIter).first, tempProp); break; |
| 588 |
case NNP_FLOAT64: AddPointAttrib<ActionType, vcg::Point3d>(m, (*mapIter).first, tempProp); break; |
| 589 |
case NNP_INT8: AddPointAttrib<ActionType, vcg::Point3<char>>(m, (*mapIter).first, tempProp); break; |
| 590 |
case NNP_INT16: AddPointAttrib<ActionType, vcg::Point3s>(m, (*mapIter).first, tempProp); break; |
| 591 |
case NNP_INT32: AddPointAttrib<ActionType, vcg::Point3i>(m, (*mapIter).first, tempProp); break; |
| 592 |
case NNP_UINT8: AddPointAttrib<ActionType, vcg::Point3<unsigned char>>(m, (*mapIter).first, tempProp); break; |
| 593 |
case NNP_UINT16: AddPointAttrib<ActionType, vcg::Point3<unsigned short>>(m, (*mapIter).first, tempProp); break; |
| 594 |
case NNP_UINT32: AddPointAttrib<ActionType, vcg::Point3<unsigned int>>(m, (*mapIter).first, tempProp); break; |
| 595 |
default: assert(0); |
| 596 |
} |
| 597 |
} |
| 598 |
else if (tempProp.size() == 4 && (*mapIter).second.second != (checkMask << 4)) |
| 599 |
{ |
| 600 |
switch (tempProp[0].type) |
| 601 |
{ |
| 602 |
case NNP_FLOAT32: AddPointAttrib<ActionType, vcg::Point4d>(m, (*mapIter).first, tempProp); break; |
| 603 |
case NNP_FLOAT64: AddPointAttrib<ActionType, vcg::Point4d>(m, (*mapIter).first, tempProp); break; |
| 604 |
case NNP_INT8: AddPointAttrib<ActionType, vcg::Point4<char>>(m, (*mapIter).first, tempProp); break; |
| 605 |
case NNP_INT16: AddPointAttrib<ActionType, vcg::Point4s>(m, (*mapIter).first, tempProp); break; |
| 606 |
case NNP_INT32: AddPointAttrib<ActionType, vcg::Point4i>(m, (*mapIter).first, tempProp); break; |
| 607 |
case NNP_UINT8: AddPointAttrib<ActionType, vcg::Point4<unsigned char>>(m, (*mapIter).first, tempProp); break; |
| 608 |
case NNP_UINT16: AddPointAttrib<ActionType, vcg::Point4<unsigned short>>(m, (*mapIter).first, tempProp); break; |
| 609 |
case NNP_UINT32: AddPointAttrib<ActionType, vcg::Point4<unsigned int>>(m, (*mapIter).first, tempProp); break; |
| 610 |
default: assert(0); |
| 611 |
} |
| 612 |
} |
| 613 |
else if (tempProp.size() == 4) |
| 614 |
{ |
| 615 |
switch (tempProp[0].type) |
| 616 |
{ |
| 617 |
case NNP_INT8: |
| 618 |
case NNP_INT16: |
| 619 |
case NNP_INT32: |
| 620 |
case NNP_UINT16: |
| 621 |
case NNP_UINT32: |
| 622 |
case NNP_FLOAT32: AddPointAttrib<ActionType, vcg::Color4f>(m, (*mapIter).first, tempProp); break; |
| 623 |
case NNP_FLOAT64: AddPointAttrib<ActionType, vcg::Color4d>(m, (*mapIter).first, tempProp); break; |
| 624 |
case NNP_UINT8: AddPointAttrib<ActionType, vcg::Color4b>(m, (*mapIter).first, tempProp); break; |
| 625 |
default: assert(0); |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
else |
| 630 |
{ |
| 631 |
for (size_t i = 0; i < tempProp.size(); i++) |
| 632 |
{ |
| 633 |
switch (tempProp[i].type) |
| 634 |
{ |
| 635 |
case NNP_FLOAT32: AddScalarAttrib<ActionType, float>(m, tempProp[i].name, tempProp[i].type); break; |
| 636 |
case NNP_FLOAT64: AddScalarAttrib<ActionType, double>(m, tempProp[i].name, tempProp[i].type); break; |
| 637 |
case NNP_INT8: AddScalarAttrib<ActionType, char>(m, tempProp[i].name, tempProp[i].type); break; |
| 638 |
case NNP_INT16: AddScalarAttrib<ActionType, short>(m, tempProp[i].name, tempProp[i].type); break; |
| 639 |
case NNP_INT32: AddScalarAttrib<ActionType, int>(m, tempProp[i].name, tempProp[i].type); break; |
| 640 |
case NNP_UINT8: AddScalarAttrib<ActionType, unsigned char>(m, tempProp[i].name, tempProp[i].type); break; |
| 641 |
case NNP_UINT16: AddScalarAttrib<ActionType, unsigned short>(m, tempProp[i].name, tempProp[i].type); break; |
| 642 |
case NNP_UINT32: AddScalarAttrib<ActionType, unsigned int>(m, tempProp[i].name, tempProp[i].type); break; |
| 643 |
case NNP_LIST_UINT8_UINT32: |
| 644 |
case NNP_LIST_INT8_UINT32: AddListAttrib<ActionType, std::vector<unsigned int>, unsigned int>(m, tempProp[i].name, tempProp[i].type); break; |
| 645 |
case NNP_LIST_UINT8_INT32: |
| 646 |
case NNP_LIST_INT8_INT32: AddListAttrib<ActionType, std::vector<int>, int>(m, tempProp[i].name, tempProp[i].type); break; |
| 647 |
case NNP_LIST_UINT8_FLOAT32: |
| 648 |
case NNP_LIST_INT8_FLOAT32: AddListAttrib<ActionType, std::vector<float>, float>(m, tempProp[i].name, tempProp[i].type); break; |
| 649 |
case NNP_LIST_UINT8_FLOAT64: |
| 650 |
case NNP_LIST_INT8_FLOAT64: AddListAttrib<ActionType, std::vector<double>, double>(m, tempProp[i].name, tempProp[i].type); break; |
| 651 |
case NNP_LIST_UINT8_UINT8: |
| 652 |
case NNP_LIST_INT8_UINT8: AddListAttrib<ActionType, std::vector<unsigned char>, unsigned char>(m, tempProp[i].name, tempProp[i].type); break; |
| 653 |
case NNP_LIST_UINT8_INT8: |
| 654 |
case NNP_LIST_INT8_INT8: AddListAttrib<ActionType, std::vector<char>, char>(m, tempProp[i].name, tempProp[i].type); break; |
| 655 |
case NNP_LIST_UINT8_UINT16: |
| 656 |
case NNP_LIST_INT8_UINT16: AddListAttrib<ActionType, std::vector<unsigned short>, unsigned short>(m, tempProp[i].name, tempProp[i].type); break; |
| 657 |
case NNP_LIST_UINT8_INT16: |
| 658 |
case NNP_LIST_INT8_INT16: AddListAttrib<ActionType, std::vector<short>, short>(m, tempProp[i].name, tempProp[i].type); break; |
| 659 |
default: assert(0); |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
} |
| 664 |
return true; |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
}; |
| 670 |
|
| 671 |
|
| 672 |
template <class T> |
| 673 |
struct OcfManager |
| 674 |
{ |
| 675 |
typedef typename T::VertexType VType; |
| 676 |
typedef typename T::FaceType FType; |
| 677 |
typedef typename T::EdgeType EType; |
| 678 |
|
| 679 |
|
| 680 |
template <bool f = std::is_same<typename T::VertContainer, vcg::vertex::vector_ocf<VType>>::value> |
| 681 |
static unsigned int EnableVertexOcf(typename T::VertContainer& cont, unsigned int mask) |
| 682 |
{ |
| 683 |
unsigned int enabledMask = 0; |
| 684 |
if constexpr (f) |
| 685 |
{ |
| 686 |
if ((mask & BitMask::IO_VERTNORMAL) && VType::HasNormalOcf() && !cont.IsNormalEnabled()) |
| 687 |
{ |
| 688 |
cont.EnableNormal(); |
| 689 |
enabledMask |= BitMask::IO_VERTNORMAL; |
| 690 |
} |
| 691 |
if ((mask & BitMask::IO_VERTCOLOR) && VType::HasColorOcf() && !cont.IsColorEnabled()) |
| 692 |
{ |
| 693 |
cont.EnableColor(); |
| 694 |
enabledMask |= BitMask::IO_VERTCOLOR; |
| 695 |
} |
| 696 |
if ((mask & BitMask::IO_VERTQUALITY) && VType::HasQualityOcf() && !cont.IsQualityEnabled()) |
| 697 |
{ |
| 698 |
cont.EnableQuality(); |
| 699 |
enabledMask |= BitMask::IO_VERTQUALITY; |
| 700 |
} |
| 701 |
if ((mask & BitMask::IO_VERTCURV) && VType::HasCurvatureOcf() && !cont.IsCurvatureEnabled()) |
| 702 |
{ |
| 703 |
cont.EnableCurvature(); |
| 704 |
enabledMask |= BitMask::IO_VERTCURV; |
| 705 |
} |
| 706 |
if ((mask & BitMask::IO_VERTCURVDIR) && VType::HasCurvatureDirOcf() && !cont.IsCurvatureDirEnabled()) |
| 707 |
{ |
| 708 |
cont.EnableCurvatureDir(); |
| 709 |
enabledMask |= BitMask::IO_VERTCURVDIR; |
| 710 |
} |
| 711 |
if ((mask & BitMask::IO_VERTRADIUS) && VType::HasRadiusOcf() && !cont.IsRadiusEnabled()) |
| 712 |
{ |
| 713 |
cont.EnableRadius(); |
| 714 |
enabledMask |= BitMask::IO_VERTRADIUS; |
| 715 |
} |
| 716 |
if ((mask & BitMask::IO_VERTTEXCOORD) && VType::HasTexCoordOcf() && !cont.IsTexCoordEnabled()) |
| 717 |
{ |
| 718 |
cont.EnableTexCoord(); |
| 719 |
enabledMask |= BitMask::IO_VERTTEXCOORD; |
| 720 |
} |
| 721 |
} |
| 722 |
return enabledMask; |
| 723 |
} |
| 724 |
|
| 725 |
template <bool f = std::is_same<typename T::FaceContainer, vcg::face::vector_ocf<FType>>::value> |
| 726 |
static unsigned int EnableFaceOcf(typename T::FaceContainer& cont, unsigned int mask) |
| 727 |
{ |
| 728 |
unsigned int enabledMask = 0; |
| 729 |
if constexpr (f) |
| 730 |
{ |
| 731 |
if ((mask & BitMask::IO_FACENORMAL) && FType::HasNormalOcf() && !cont.IsNormalEnabled()) |
| 732 |
{ |
| 733 |
cont.EnableNormal(); |
| 734 |
enabledMask |= BitMask::IO_FACENORMAL; |
| 735 |
} |
| 736 |
if ((mask & BitMask::IO_FACECOLOR) && FType::HasColorOcf() && !cont.IsColorEnabled()) |
| 737 |
{ |
| 738 |
cont.EnableColor(); |
| 739 |
enabledMask |= BitMask::IO_FACECOLOR; |
| 740 |
} |
| 741 |
if ((mask & BitMask::IO_FACEQUALITY) && FType::HasQualityOcf() && !cont.IsQualityEnabled()) |
| 742 |
{ |
| 743 |
cont.EnableQuality(); |
| 744 |
enabledMask |= BitMask::IO_FACEQUALITY; |
| 745 |
} |
| 746 |
if ((mask & BitMask::IO_FACECURVDIR) && FType::HasCurvatureDirOcf() && !cont.IsCurvatureDirEnabled()) |
| 747 |
{ |
| 748 |
cont.EnableCurvatureDir(); |
| 749 |
enabledMask |= BitMask::IO_FACECURVDIR; |
| 750 |
} |
| 751 |
if ((mask & BitMask::IO_WEDGCOLOR) && FType::HasWedgeColorOcf() && !cont.IsWedgeColorEnabled()) |
| 752 |
{ |
| 753 |
cont.EnableWedgeColor(); |
| 754 |
enabledMask |= BitMask::IO_WEDGCOLOR; |
| 755 |
} |
| 756 |
if ((mask & BitMask::IO_WEDGNORMAL) && FType::HasWedgeNormalOcf() && !cont.IsWedgeNormalEnabled()) |
| 757 |
{ |
| 758 |
cont.EnableWedgeNormal(); |
| 759 |
enabledMask |= BitMask::IO_WEDGNORMAL; |
| 760 |
} |
| 761 |
if ((mask & BitMask::IO_WEDGTEXCOORD) && FType::HasWedgeTexCoordOcf() && !cont.IsWedgeTexCoordEnabled()) |
| 762 |
{ |
| 763 |
cont.EnableWedgeTexCoord(); |
| 764 |
enabledMask |= BitMask::IO_WEDGTEXCOORD; |
| 765 |
} |
| 766 |
if ((mask & BitMask::IO_WEDGTEXMULTI) && FType::HasWedgeTexCoordOcf()) |
| 767 |
{ |
| 768 |
if (!cont.IsWedgeTexCoordEnabled()) |
| 769 |
cont.EnableWedgeTexCoord(); |
| 770 |
enabledMask |= BitMask::IO_WEDGTEXMULTI; |
| 771 |
} |
| 772 |
} |
| 773 |
return enabledMask; |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
template <bool f = std::is_same<typename T::VertContainer, vcg::vertex::vector_ocf<VType>>::value> |
| 778 |
static unsigned int VertexOcfMask(typename T::VertContainer& cont) |
| 779 |
{ |
| 780 |
unsigned int enabledMask = 0; |
| 781 |
if constexpr(f) |
| 782 |
{ |
| 783 |
if (VType::HasNormalOcf() && cont.IsNormalEnabled()) |
| 784 |
enabledMask |= BitMask::IO_VERTNORMAL; |
| 785 |
if (VType::HasColorOcf() && cont.IsColorEnabled()) |
| 786 |
enabledMask |= BitMask::IO_VERTCOLOR; |
| 787 |
if (VType::HasQualityOcf() && cont.IsQualityEnabled()) |
| 788 |
enabledMask |= BitMask::IO_VERTQUALITY; |
| 789 |
if (VType::HasCurvatureOcf() && cont.IsCurvatureEnabled()) |
| 790 |
enabledMask |= BitMask::IO_VERTCURV; |
| 791 |
if (VType::HasCurvatureDirOcf() && cont.IsCurvatureDirEnabled()) |
| 792 |
enabledMask |= BitMask::IO_VERTCURVDIR; |
| 793 |
if (VType::HasRadiusOcf() && cont.IsRadiusEnabled()) |
| 794 |
enabledMask |= BitMask::IO_VERTRADIUS; |
| 795 |
if (VType::HasTexCoordOcf() && cont.IsTexCoordEnabled()) |
| 796 |
enabledMask |= BitMask::IO_VERTTEXCOORD; |
| 797 |
} |
| 798 |
return enabledMask; |
| 799 |
} |
| 800 |
|
| 801 |
template <bool f = std::is_same<typename T::FaceContainer, vcg::face::vector_ocf<FType>>::value> |
| 802 |
static unsigned int FaceOcfMask(typename T::FaceContainer& cont) |
| 803 |
{ |
| 804 |
unsigned int enabledMask = 0; |
| 805 |
if constexpr (f) |
| 806 |
{ |
| 807 |
if (FType::HasNormalOcf() && cont.IsNormalEnabled()) |
| 808 |
enabledMask |= BitMask::IO_FACENORMAL; |
| 809 |
if (FType::HasColorOcf() && cont.IsColorEnabled()) |
| 810 |
enabledMask |= BitMask::IO_FACECOLOR; |
| 811 |
if (FType::HasQualityOcf() && cont.IsQualityEnabled()) |
| 812 |
enabledMask |= BitMask::IO_FACEQUALITY; |
| 813 |
if (FType::HasCurvatureDirOcf() && cont.IsCurvatureDirEnabled()) |
| 814 |
enabledMask |= BitMask::IO_FACECURVDIR; |
| 815 |
if (FType::HasWedgeColorOcf() && cont.IsWedgeColorEnabled()) |
| 816 |
enabledMask |= BitMask::IO_WEDGCOLOR; |
| 817 |
if (FType::HasWedgeNormalOcf() && cont.IsWedgeNormalEnabled()) |
| 818 |
enabledMask |= BitMask::IO_WEDGNORMAL; |
| 819 |
if (FType::HasWedgeTexCoordOcf() && cont.IsWedgeTexCoordEnabled()) |
| 820 |
{ |
| 821 |
enabledMask |= BitMask::IO_WEDGTEXCOORD; |
| 822 |
enabledMask |= BitMask::IO_WEDGTEXMULTI; |
| 823 |
} |
| 824 |
} |
| 825 |
return enabledMask; |
| 826 |
} |
| 827 |
}; |
| 828 |
|
| 829 |
|
| 830 |
static unsigned int GetFileBitMask(nanoply::Info& info) |
| 831 |
{ |
| 832 |
unsigned int mask = 0; |
| 833 |
for (size_t j = 0; j < info.elemVec.size(); j++) |
| 834 |
{ |
| 835 |
PlyElement& elem = info.elemVec[j]; |
| 836 |
if (elem.plyElem == PlyElemEntity::NNP_VERTEX_ELEM) |
| 837 |
{ |
| 838 |
for (size_t i = 0; i < elem.propVec.size(); i++) |
| 839 |
{ |
| 840 |
switch (elem.propVec[i].elem) |
| 841 |
{ |
| 842 |
case NNP_PXYZ: mask |= BitMask::IO_VERTCOORD; break; |
| 843 |
case NNP_NXYZ: mask |= BitMask::IO_VERTNORMAL; break; |
| 844 |
case NNP_CRGB: |
| 845 |
case NNP_CRGBA: mask |= BitMask::IO_VERTCOLOR; break; |
| 846 |
case NNP_BITFLAG: mask |= BitMask::IO_VERTFLAGS; break; |
| 847 |
case NNP_QUALITY: mask |= BitMask::IO_VERTQUALITY; break; |
| 848 |
case NNP_DENSITY: mask |= BitMask::IO_VERTRADIUS; break; |
| 849 |
case NNP_TEXTURE2D: |
| 850 |
case NNP_TEXTURE3D: mask |= BitMask::IO_VERTTEXCOORD; break; |
| 851 |
// case NNP_KH: |
| 852 |
// case NNP_KG: mask |= BitMask::IO_VERTCURV; break; |
| 853 |
case NNP_K1: |
| 854 |
case NNP_K2: |
| 855 |
case NNP_K1DIR: |
| 856 |
case NNP_K2DIR: mask |= BitMask::IO_VERTCURVDIR; break; |
| 857 |
case NNP_UNKNOWN_ENTITY: mask |= BitMask::IO_VERTATTRIB; break; |
| 858 |
default: assert(0); |
| 859 |
} |
| 860 |
} |
| 861 |
} |
| 862 |
else if (elem.plyElem == PlyElemEntity::NNP_EDGE_ELEM) |
| 863 |
{ |
| 864 |
for (size_t i = 0; i < elem.propVec.size(); i++) |
| 865 |
{ |
| 866 |
switch (elem.propVec[i].elem) |
| 867 |
{ |
| 868 |
case NNP_EDGE_V1: |
| 869 |
case NNP_EDGE_V2: mask |= BitMask::IO_EDGEINDEX; break; |
| 870 |
case NNP_CRGB: |
| 871 |
case NNP_CRGBA: mask |= BitMask::IO_EDGECOLOR; break; |
| 872 |
case NNP_BITFLAG: mask |= BitMask::IO_EDGEFLAGS; break; |
| 873 |
case NNP_QUALITY: mask |= BitMask::IO_EDGEQUALITY; break; |
| 874 |
case NNP_UNKNOWN_ENTITY: mask |= BitMask::IO_EDGEATTRIB; break; |
| 875 |
default: assert(0); |
| 876 |
} |
| 877 |
} |
| 878 |
} |
| 879 |
else if (elem.plyElem == PlyElemEntity::NNP_FACE_ELEM) |
| 880 |
{ |
| 881 |
for (size_t i = 0; i < elem.propVec.size(); i++) |
| 882 |
{ |
| 883 |
switch (elem.propVec[i].elem) |
| 884 |
{ |
| 885 |
case NNP_FACE_VERTEX_LIST: mask |= BitMask::IO_FACEINDEX; break; |
| 886 |
case NNP_NXYZ: mask |= BitMask::IO_FACENORMAL; break; |
| 887 |
case NNP_CRGB: |
| 888 |
case NNP_CRGBA: mask |= BitMask::IO_FACECOLOR; break; |
| 889 |
case NNP_BITFLAG: mask |= BitMask::IO_FACEFLAGS; break; |
| 890 |
case NNP_QUALITY: mask |= BitMask::IO_FACEQUALITY; break; |
| 891 |
case NNP_K1: |
| 892 |
case NNP_K2: |
| 893 |
case NNP_K1DIR: |
| 894 |
case NNP_K2DIR: mask |= BitMask::IO_FACECURVDIR; break; |
| 895 |
case NNP_FACE_WEDGE_COLOR: mask |= BitMask::IO_WEDGCOLOR; break; |
| 896 |
case NNP_FACE_WEDGE_NORMAL: mask |= BitMask::IO_WEDGNORMAL; break; |
| 897 |
case NNP_FACE_WEDGE_TEX: mask |= BitMask::IO_WEDGTEXCOORD; break; |
| 898 |
case NNP_TEXTUREINDEX: mask |= BitMask::IO_WEDGTEXMULTI; break; |
| 899 |
case NNP_UNKNOWN_ENTITY: mask |= BitMask::IO_FACEATTRIB; break; |
| 900 |
default: assert(0); |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
else if (elem.plyElem == PlyElemEntity::NNP_UNKNOWN_ELEM) |
| 905 |
{ |
| 906 |
if (elem.name == "camera") |
| 907 |
mask |= BitMask::IO_CAMERA; |
| 908 |
else |
| 909 |
mask |= BitMask::IO_MESHATTRIB; |
| 910 |
} |
| 911 |
} |
| 912 |
return mask; |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
static int LoadModel(const char* filename, MeshType& mesh, unsigned int bitMask, CustomAttributeDescriptor& custom) |
| 918 |
{ |
| 919 |
nanoply::Info info(filename); |
| 920 |
if (info.errInfo != nanoply::NNP_OK) |
| 921 |
return info.errInfo; |
| 922 |
|
| 923 |
unsigned int headerMask = GetFileBitMask(info); |
| 924 |
bitMask &= headerMask; |
| 925 |
unsigned int ocfVertexMask = OcfManager<MeshType>::EnableVertexOcf(mesh.vert, bitMask); |
| 926 |
unsigned int ocfFaceMask = OcfManager<MeshType>::EnableFaceOcf(mesh.face, bitMask); |
| 927 |
|
| 928 |
//Camera |
| 929 |
ElementDescriptor cameraDescr(std::string("camera")); |
| 930 |
vcg::Point3<ScalarType> tra; |
| 931 |
vcg::Matrix44<ScalarType> rot; |
| 932 |
size_t count = info.GetElementCount(std::string("camera")); |
| 933 |
if (count > 0 && (bitMask & BitMask::IO_CAMERA)) |
| 934 |
{ |
| 935 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_px"), &tra[0])); |
| 936 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_py"), &tra[1])); |
| 937 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_pz"), &tra[2])); |
| 938 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisx"), &rot[0][0])); |
| 939 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisy"), &rot[0][1])); |
| 940 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisz"), &rot[0][2])); |
| 941 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisx"), &rot[1][0])); |
| 942 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisy"), &rot[1][1])); |
| 943 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisz"), &rot[1][2])); |
| 944 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisx"), &rot[2][0])); |
| 945 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisy"), &rot[2][1])); |
| 946 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisz"), &rot[2][2])); |
| 947 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("focal"), &mesh.shot.Intrinsics.FocalMm)); |
| 948 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("scalex"), &mesh.shot.Intrinsics.PixelSizeMm[0])); |
| 949 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("scaley"), &mesh.shot.Intrinsics.PixelSizeMm[1])); |
| 950 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("centerx"), &mesh.shot.Intrinsics.CenterPx[0])); |
| 951 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("centery"), &mesh.shot.Intrinsics.CenterPx[1])); |
| 952 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<int, 1, int>(std::string("viewportx"), &mesh.shot.Intrinsics.ViewportPx[0])); |
| 953 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<int, 1, int>(std::string("viewporty"), &mesh.shot.Intrinsics.ViewportPx[1])); |
| 954 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k1"), &mesh.shot.Intrinsics.k[0])); |
| 955 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k2"), &mesh.shot.Intrinsics.k[1])); |
| 956 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k3"), &mesh.shot.Intrinsics.k[2])); |
| 957 |
cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k4"), &mesh.shot.Intrinsics.k[3])); |
| 958 |
} |
| 959 |
|
| 960 |
//Vertex |
| 961 |
std::vector<std::string> nameList; |
| 962 |
VertexType::Name(nameList); |
| 963 |
ElementDescriptor vertexDescr(NNP_VERTEX_ELEM); |
| 964 |
count = info.GetVertexCount(); |
| 965 |
if (nameList.size() > 0 && count > 0) |
| 966 |
{ |
| 967 |
vcg::tri::Allocator<MeshType>::AddVertices(mesh, count); |
| 968 |
if ((bitMask & BitMask::IO_VERTCOORD) && VertexType::HasCoord()) |
| 969 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexCoordScalar>(NNP_PXYZ, (*mesh.vert.begin()).P().V())); |
| 970 |
if ((bitMask & BitMask::IO_VERTNORMAL) && vcg::tri::HasPerVertexNormal(mesh)) |
| 971 |
{ |
| 972 |
if (ocfVertexMask & BitMask::IO_VERTNORMAL) |
| 973 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexNormalType, 3, VertexNormScalar>(NNP_NXYZ, (*mesh.vert.begin()).N().V())); |
| 974 |
else |
| 975 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexNormScalar>(NNP_NXYZ, (*mesh.vert.begin()).N().V())); |
| 976 |
} |
| 977 |
if ((bitMask & BitMask::IO_VERTCOLOR) && vcg::tri::HasPerVertexColor(mesh)) |
| 978 |
{ |
| 979 |
if (ocfVertexMask & BitMask::IO_VERTCOLOR) |
| 980 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexColorType, 4, VertexColorScalar>(NNP_CRGBA, (*mesh.vert.begin()).C().V())); |
| 981 |
else |
| 982 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 4, VertexColorScalar>(NNP_CRGBA, (*mesh.vert.begin()).C().V())); |
| 983 |
} |
| 984 |
if ((bitMask & BitMask::IO_VERTQUALITY) && vcg::tri::HasPerVertexQuality(mesh)) |
| 985 |
{ |
| 986 |
if (ocfVertexMask & BitMask::IO_VERTQUALITY) |
| 987 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexQuality, 1, VertexQuality>(NNP_QUALITY, &(*mesh.vert.begin()).Q())); |
| 988 |
else |
| 989 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexQuality>(NNP_QUALITY, &(*mesh.vert.begin()).Q())); |
| 990 |
} |
| 991 |
if ((bitMask & BitMask::IO_VERTFLAGS) && vcg::tri::HasPerVertexFlags(mesh)) |
| 992 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexFlag>(NNP_BITFLAG, &(*mesh.vert.begin()).Flags())); |
| 993 |
if ((bitMask & BitMask::IO_VERTRADIUS) && vcg::tri::HasPerVertexRadius(mesh)) |
| 994 |
{ |
| 995 |
if (ocfVertexMask & BitMask::IO_VERTRADIUS) |
| 996 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexRadius, 1, VertexRadius>(NNP_DENSITY, &(*mesh.vert.begin()).R())); |
| 997 |
else |
| 998 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexRadius>(NNP_DENSITY, &(*mesh.vert.begin()).R())); |
| 999 |
} |
| 1000 |
if ((bitMask & BitMask::IO_VERTTEXCOORD) && vcg::tri::HasPerVertexTexCoord(mesh)) |
| 1001 |
{ |
| 1002 |
if (ocfVertexMask & BitMask::IO_VERTTEXCOORD) |
| 1003 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexTexCoordType, 2, VertexTexScalar>(NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V())); |
| 1004 |
else |
| 1005 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 2, VertexTexScalar>(NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V())); |
| 1006 |
} |
| 1007 |
// if ((bitMask & BitMask::IO_VERTCURV) && vcg::tri::HasPerVertexCurvature(mesh)) |
| 1008 |
// { |
| 1009 |
// if (ocfVertexMask & BitMask::IO_VERTCURV) |
| 1010 |
// { |
| 1011 |
// vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurType, 1, VertexCurScalar>(NNP_KG, &(*mesh.vert.begin()).Kg())); |
| 1012 |
// vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurType, 1, VertexCurScalar>(NNP_KH, &(*mesh.vert.begin()).Kh())); |
| 1013 |
// } |
| 1014 |
// else |
| 1015 |
// { |
| 1016 |
// vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexCurScalar>(NNP_KG, &(*mesh.vert.begin()).Kg())); |
| 1017 |
// vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexCurScalar>(NNP_KH, &(*mesh.vert.begin()).Kh())); |
| 1018 |
// } |
| 1019 |
// } |
| 1020 |
if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerVertexCurvatureDir(mesh)) |
| 1021 |
{ |
| 1022 |
if (ocfVertexMask & BitMask::IO_VERTCURVDIR) |
| 1023 |
{ |
| 1024 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurDirType, 1, VertexDirCurScalar>(NNP_K1, &(*mesh.vert.begin()).K1())); |
| 1025 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurDirType, 1, VertexDirCurScalar>(NNP_K2, &(*mesh.vert.begin()).K2())); |
| 1026 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurDirType, 3, VertexDirCurVecScalar>(NNP_K1DIR, (*mesh.vert.begin()).PD1().V())); |
| 1027 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexCurDirType, 3, VertexDirCurVecScalar>(NNP_K2DIR, (*mesh.vert.begin()).PD2().V())); |
| 1028 |
} |
| 1029 |
else |
| 1030 |
{ |
| 1031 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexDirCurScalar>(NNP_K1, &(*mesh.vert.begin()).K1())); |
| 1032 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexDirCurScalar>(NNP_K2, &(*mesh.vert.begin()).K2())); |
| 1033 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexDirCurVecScalar>(NNP_K1DIR, (*mesh.vert.begin()).PD1().V())); |
| 1034 |
vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexDirCurVecScalar>(NNP_K2DIR, (*mesh.vert.begin()).PD2().V())); |
| 1035 |
} |
| 1036 |
} |
| 1037 |
if (bitMask & BitMask::IO_VERTATTRIB) |
| 1038 |
{ |
| 1039 |
custom.AddVertexAttrib(mesh, mesh.vert_attr, info.GetVertexElement()); |
| 1040 |
for (size_t i = 0; i < custom.vertexAttrib.size(); i++) |
| 1041 |
{ |
| 1042 |
if ((*custom.vertexAttrib[i]).base != NULL) |
| 1043 |
vertexDescr.dataDescriptor.push_back(custom.vertexAttrib[i]); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
//Edge |
| 1049 |
nameList.clear(); |
| 1050 |
EdgeType::Name(nameList); |
| 1051 |
ElementDescriptor edgeDescr(NNP_EDGE_ELEM); |
| 1052 |
count = info.GetEdgeCount(); |
| 1053 |
std::vector<vcg::Point2i> edgeIndex; |
| 1054 |
if (nameList.size() > 0 && count > 0) |
| 1055 |
{ |
| 1056 |
vcg::tri::Allocator<MeshType>::AddEdges(mesh, count); |
| 1057 |
if ((bitMask & BitMask::IO_EDGEINDEX) && MeshType::EdgeType::HasVertexRef()) |
| 1058 |
{ |
| 1059 |
edgeIndex.resize(count); |
| 1060 |
edgeDescr.dataDescriptor.push_back(new DataDescriptor<vcg::Point2i, 1, int>(NNP_EDGE_V1, &(*edgeIndex.begin()).V()[0])); |
| 1061 |
edgeDescr.dataDescriptor.push_back(new DataDescriptor<vcg::Point2i, 1, int>(NNP_EDGE_V2, &(*edgeIndex.begin()).V()[1])); |
| 1062 |
} |
| 1063 |
if ((bitMask & BitMask::IO_EDGEQUALITY) && vcg::tri::HasPerEdgeQuality(mesh)) |
| 1064 |
edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 1, EdgeQuality>(NNP_QUALITY, &(*mesh.edge.begin()).Q())); |
| 1065 |
if ((bitMask & BitMask::IO_EDGECOLOR) && vcg::tri::HasPerEdgeColor(mesh)) |
| 1066 |
edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 4, EdgeColorScalar>(NNP_CRGBA, (*mesh.edge.begin()).C().V())); |
| 1067 |
if ((bitMask & BitMask::IO_EDGEFLAGS) && vcg::tri::HasPerEdgeFlags(mesh)) |
| 1068 |
edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 1, EdgeFlag>(NNP_BITFLAG, &(*mesh.edge.begin()).Flags())); |
| 1069 |
if (bitMask & BitMask::IO_EDGEATTRIB) |
| 1070 |
{ |
| 1071 |
custom.AddEdgeAttrib(mesh, mesh.edge_attr, info.GetEdgeElement()); |
| 1072 |
for (size_t i = 0; i < custom.edgeAttrib.size(); i++) |
| 1073 |
{ |
| 1074 |
if ((*custom.edgeAttrib[i]).base != NULL) |
| 1075 |
edgeDescr.dataDescriptor.push_back(custom.edgeAttrib[i]); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
} |
| 1079 |
|
| 1080 |
//Face |
| 1081 |
nameList.clear(); |
| 1082 |
FaceType::Name(nameList); |
| 1083 |
ElementDescriptor faceDescr(NNP_FACE_ELEM); |
| 1084 |
count = info.GetFaceCount(); |
| 1085 |
std::vector<std::vector<unsigned int>> faceIndex; |
| 1086 |
std::vector<vcg::ndim::Point<6, FaceTexScalar>> wedgeTexCoord; |
| 1087 |
if (nameList.size() > 0 && count > 0) |
| 1088 |
{ |
| 1089 |
vcg::tri::Allocator<MeshType>::AddFaces(mesh, count); |
| 1090 |
if ((bitMask & BitMask::IO_FACEINDEX) && FaceType::HasVertexRef()) |
| 1091 |
{ |
| 1092 |
faceIndex.resize(count); |
| 1093 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<std::vector<unsigned int>,0, unsigned int>(NNP_FACE_VERTEX_LIST, &faceIndex[0])); |
| 1094 |
} |
| 1095 |
if ((bitMask & BitMask::IO_FACEFLAGS) && vcg::tri::HasPerFaceFlags(mesh)) |
| 1096 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceFlag>(NNP_BITFLAG, &(*mesh.face.begin()).Flags())); |
| 1097 |
if ((bitMask & BitMask::IO_FACECOLOR) && vcg::tri::HasPerFaceColor(mesh)) |
| 1098 |
{ |
| 1099 |
if (ocfFaceMask & BitMask::IO_FACECOLOR) |
| 1100 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceColorType, 4, FaceColorScalar>(NNP_CRGBA, (*mesh.face.begin()).C().V())); |
| 1101 |
else |
| 1102 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 4, FaceColorScalar>(NNP_CRGBA, (*mesh.face.begin()).C().V())); |
| 1103 |
} |
| 1104 |
if ((bitMask & BitMask::IO_FACEQUALITY) && vcg::tri::HasPerFaceQuality(mesh)) |
| 1105 |
{ |
| 1106 |
if (ocfFaceMask & BitMask::IO_FACEQUALITY) |
| 1107 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceQuality, 1, FaceQuality>(NNP_QUALITY, &(*mesh.face.begin()).Q())); |
| 1108 |
else |
| 1109 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceQuality>(NNP_QUALITY, &(*mesh.face.begin()).Q())); |
| 1110 |
} |
| 1111 |
if ((bitMask & BitMask::IO_FACENORMAL) && vcg::tri::HasPerFaceNormal(mesh)) |
| 1112 |
{ |
| 1113 |
if (ocfFaceMask & BitMask::IO_FACENORMAL) |
| 1114 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceNormalType, 3, FaceNormScalar>(NNP_NXYZ, (*mesh.face.begin()).N().V())); |
| 1115 |
else |
| 1116 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceNormScalar>(NNP_NXYZ, (*mesh.face.begin()).N().V())); |
| 1117 |
} |
| 1118 |
if ((bitMask & BitMask::IO_FACECURVDIR) && vcg::tri::HasPerFaceCurvatureDir(mesh)) |
| 1119 |
{ |
| 1120 |
if (ocfFaceMask & BitMask::IO_FACECURVDIR) |
| 1121 |
{ |
| 1122 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceCurDirType, 1, FaceDirCurScalar>(NNP_K1, &(*mesh.face.begin()).K1())); |
| 1123 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceCurDirType, 1, FaceDirCurScalar>(NNP_K2, &(*mesh.face.begin()).K2())); |
| 1124 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceCurDirType, 3, FaceDirCurVecScalar>(NNP_K1DIR, (*mesh.face.begin()).PD1().V())); |
| 1125 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceCurDirType, 3, FaceDirCurVecScalar>(NNP_K2DIR, (*mesh.face.begin()).PD2().V())); |
| 1126 |
} |
| 1127 |
else |
| 1128 |
{ |
| 1129 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceDirCurScalar>(NNP_K1, &(*mesh.face.begin()).K1())); |
| 1130 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceDirCurScalar>(NNP_K2, &(*mesh.face.begin()).K2())); |
| 1131 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceDirCurVecScalar>(NNP_K1DIR, (*mesh.face.begin()).PD1().V())); |
| 1132 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceDirCurVecScalar>(NNP_K2DIR, (*mesh.face.begin()).PD2().V())); |
| 1133 |
} |
| 1134 |
} |
| 1135 |
if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh)) |
| 1136 |
{ |
| 1137 |
wedgeTexCoord.resize(count); |
| 1138 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<vcg::ndim::Point<6, FaceTexScalar>, 6, FaceTexScalar>(NNP_FACE_WEDGE_TEX, (*wedgeTexCoord.begin()).V())); |
| 1139 |
} |
| 1140 |
if ((bitMask & BitMask::IO_WEDGTEXMULTI) && vcg::tri::HasPerWedgeTexCoord(mesh)) |
| 1141 |
{ |
| 1142 |
if (ocfFaceMask & BitMask::IO_WEDGTEXMULTI) |
| 1143 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceTexCoordType, 1, short>(NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N())); |
| 1144 |
else |
| 1145 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, short>(NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N())); |
| 1146 |
} |
| 1147 |
if ((bitMask & BitMask::IO_WEDGCOLOR) && vcg::tri::HasPerWedgeColor(mesh)) |
| 1148 |
{ |
| 1149 |
if (ocfFaceMask & BitMask::IO_WEDGCOLOR) |
| 1150 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<WedgeColorType, 12, WedgeColorScalar>(NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V())); |
| 1151 |
else |
| 1152 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 12, WedgeColorScalar>(NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V())); |
| 1153 |
} |
| 1154 |
if ((bitMask & BitMask::IO_WEDGNORMAL) && vcg::tri::HasPerWedgeNormal(mesh)) |
| 1155 |
{ |
| 1156 |
if (ocfFaceMask & BitMask::IO_WEDGNORMAL) |
| 1157 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<WedgeNormalType, 9, WedgeNormalScalar>(NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V())); |
| 1158 |
else |
| 1159 |
faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 9, WedgeNormalScalar>(NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V())); |
| 1160 |
} |
| 1161 |
if (bitMask & BitMask::IO_FACEATTRIB) |
| 1162 |
{ |
| 1163 |
custom.AddFaceAttrib(mesh, mesh.face_attr, info.GetFaceElement()); |
| 1164 |
for (size_t i = 0; i < custom.faceAttrib.size(); i++) |
| 1165 |
{ |
| 1166 |
if ((*custom.faceAttrib[i]).base != NULL) |
| 1167 |
faceDescr.dataDescriptor.push_back(custom.faceAttrib[i]); |
| 1168 |
} |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
std::vector<ElementDescriptor*> meshDescr; |
| 1173 |
meshDescr.push_back(&cameraDescr); |
| 1174 |
meshDescr.push_back(&vertexDescr); |
| 1175 |
meshDescr.push_back(&edgeDescr); |
| 1176 |
meshDescr.push_back(&faceDescr); |
| 1177 |
|
| 1178 |
//Mesh attribute |
| 1179 |
if ((bitMask & BitMask::IO_MESHATTRIB)) |
| 1180 |
{ |
| 1181 |
typename CustomAttributeDescriptor::MapMeshAttribIter iter = custom.meshAttrib.begin(); |
| 1182 |
for (; iter != custom.meshAttrib.end(); iter++) |
| 1183 |
{ |
| 1184 |
std::string name((*iter).first); |
| 1185 |
meshDescr.push_back(new ElementDescriptor(name)); |
| 1186 |
count = info.GetElementCount(name); |
| 1187 |
if (count > 0) |
| 1188 |
{ |
| 1189 |
meshDescr.back()->dataDescriptor = (*iter).second; |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
} |
| 1194 |
if (!OpenModel(info, meshDescr)) |
| 1195 |
return info.errInfo; |
| 1196 |
|
| 1197 |
mesh.shot.SetViewPoint(tra); |
| 1198 |
mesh.shot.Extrinsics.SetRot(rot); |
| 1199 |
bool triangleMesh = true; |
| 1200 |
for (size_t i = 0; i < faceIndex.size(); i++) |
| 1201 |
if (faceIndex[i].size() > 3) |
| 1202 |
triangleMesh = false; |
| 1203 |
|
| 1204 |
if (!triangleMesh && !vcg::tri::HasPolyInfo(mesh)) |
| 1205 |
{ |
| 1206 |
bool hasFaceFlags = (bitMask & BitMask::IO_FACEFLAGS) && vcg::tri::HasPerFaceFlags(mesh); |
| 1207 |
bool hasFaceColor = (bitMask & BitMask::IO_FACECOLOR) && vcg::tri::HasPerFaceColor(mesh); |
| 1208 |
bool hasFaceQuality = (bitMask & BitMask::IO_FACEQUALITY) && vcg::tri::HasPerFaceQuality(mesh); |
| 1209 |
bool hasFaceNormal = (bitMask & BitMask::IO_FACENORMAL) && vcg::tri::HasPerFaceNormal(mesh); |
| 1210 |
for (size_t i = 0; i < faceIndex.size(); i++) |
| 1211 |
{ |
| 1212 |
if (faceIndex[i].size() >= 3) |
| 1213 |
{ |
| 1214 |
for (int j = 0; j < 3; j++) |
| 1215 |
mesh.face[i].V(j) = &mesh.vert[faceIndex[i][j]]; |
| 1216 |
if (hasFaceFlags) |
| 1217 |
mesh.face[i].SetF(2); |
| 1218 |
FaceIterator fi = vcg::tri::Allocator<MeshType>::AddFaces(mesh, faceIndex[i].size() - 3); |
| 1219 |
for (size_t j = 3; j < faceIndex[i].size(); j++) |
| 1220 |
{ |
| 1221 |
(*fi).V(0) = &mesh.vert[faceIndex[i][0]]; |
| 1222 |
(*fi).V(1) = &mesh.vert[faceIndex[i][j - 1]]; |
| 1223 |
(*fi).V(2) = &mesh.vert[faceIndex[i][j]]; |
| 1224 |
if (hasFaceFlags) |
| 1225 |
{ |
| 1226 |
(*fi).SetFlags(mesh.face[i].Flags()); |
| 1227 |
(*fi).SetF(0); |
| 1228 |
if (j == faceIndex[i].size() - 1) |
| 1229 |
(*fi).ClearF(2); |
| 1230 |
} |
| 1231 |
if (hasFaceColor) |
| 1232 |
(*fi).C() = mesh.face[i].C(); |
| 1233 |
if (hasFaceQuality) |
| 1234 |
(*fi).Q() = mesh.face[i].Q(); |
| 1235 |
if (hasFaceNormal) |
| 1236 |
(*fi).N() = mesh.face[i].N(); |
| 1237 |
fi++; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
else |
| 1241 |
mesh.face[i].V(0) = mesh.face[i].V(1) = mesh.face[i].V(2) = &mesh.vert[0]; |
| 1242 |
} |
| 1243 |
} |
| 1244 |
else |
| 1245 |
{ |
| 1246 |
for (size_t i = 0; i < faceIndex.size(); i++) |
| 1247 |
{ |
| 1248 |
mesh.face[i].Alloc(faceIndex[i].size()); |
| 1249 |
for (size_t j = 0; j < faceIndex[i].size(); j++) |
| 1250 |
mesh.face[i].V(j) = &mesh.vert[faceIndex[i][j]]; |
| 1251 |
} |
| 1252 |
for (size_t i = 0; i < wedgeTexCoord.size(); i++) |
| 1253 |
{ |
| 1254 |
for (int j = 0; j < 3; j++) |
| 1255 |
{ |
| 1256 |
mesh.face[i].WT(j).U() = wedgeTexCoord[i][j * 2]; |
| 1257 |
mesh.face[i].WT(j).V() = wedgeTexCoord[i][j * 2 + 1]; |
| 1258 |
mesh.face[i].WT(j).N() = mesh.face[i].WT(0).N(); |
| 1259 |
} |
| 1260 |
} |
| 1261 |
} |
| 1262 |
|
| 1263 |
for (size_t i = 0; i < edgeIndex.size(); i++) |
| 1264 |
{ |
| 1265 |
mesh.edge[i].V(0) = &mesh.vert[edgeIndex[i].X()]; |
| 1266 |
mesh.edge[i].V(1) = &mesh.vert[edgeIndex[i].Y()]; |
| 1267 |
} |
| 1268 |
|
| 1269 |
for (size_t i = 0; i < cameraDescr.dataDescriptor.size(); i++) |
| 1270 |
delete cameraDescr.dataDescriptor[i]; |
| 1271 |
for (size_t i = 0; i < vertexDescr.dataDescriptor.size(); i++) |
| 1272 |
if (vertexDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1273 |
delete vertexDescr.dataDescriptor[i]; |
| 1274 |
for (size_t i = 0; i < edgeDescr.dataDescriptor.size(); i++) |
| 1275 |
if (edgeDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1276 |
delete edgeDescr.dataDescriptor[i]; |
| 1277 |
for (size_t i = 0; i < faceDescr.dataDescriptor.size(); i++) |
| 1278 |
if (faceDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1279 |
delete faceDescr.dataDescriptor[i]; |
| 1280 |
mesh.textures = info.textureFile; |
| 1281 |
return info.errInfo; |
| 1282 |
} |
| 1283 |
|
| 1284 |
|
| 1285 |
static int LoadModel(const char* filename, MeshType& mesh, unsigned int bitMask) |
| 1286 |
{ |
| 1287 |
CustomAttributeDescriptor custom; |
| 1288 |
return LoadModel(filename, mesh, bitMask, custom); |
| 1289 |
} |
| 1290 |
|
| 1291 |
|
| 1292 |
static bool SaveModel(const char* filename, MeshType& mesh, unsigned int bitMask, CustomAttributeDescriptor& custom, bool binary) |
| 1293 |
{ |
| 1294 |
unsigned int ocfVertexMask = OcfManager<MeshType>::VertexOcfMask(mesh.vert); |
| 1295 |
unsigned int ocfFaceMask = OcfManager<MeshType>::FaceOcfMask(mesh.face); |
| 1296 |
|
| 1297 |
//Camera |
| 1298 |
std::vector<PlyProperty> cameraProp; |
| 1299 |
ElementDescriptor cameraDescr(std::string("camera")); |
| 1300 |
vcg::Point3<ScalarType> tra = mesh.shot.Extrinsics.Tra(); |
| 1301 |
vcg::Matrix44<ScalarType> rot = mesh.shot.Extrinsics.Rot(); |
| 1302 |
if (bitMask & BitMask::IO_CAMERA) |
| 1303 |
{ |
| 1304 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_px"), &tra[0]); |
| 1305 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_py"), &tra[1]); |
| 1306 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_pz"), &tra[2]); |
| 1307 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisx"), &rot[0][0]); |
| 1308 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisy"), &rot[0][1]); |
| 1309 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisz"), &rot[0][2]); |
| 1310 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisx"), &rot[1][0]); |
| 1311 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisy"), &rot[1][1]); |
| 1312 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisz"), &rot[1][2]); |
| 1313 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisx"), &rot[2][0]); |
| 1314 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisy"), &rot[2][1]); |
| 1315 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisz"), &rot[2][2]); |
| 1316 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("focal"), &mesh.shot.Intrinsics.FocalMm); |
| 1317 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("scalex"), &mesh.shot.Intrinsics.PixelSizeMm[0]); |
| 1318 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("scaley"), &mesh.shot.Intrinsics.PixelSizeMm[1]); |
| 1319 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("centerx"), &mesh.shot.Intrinsics.CenterPx[0]); |
| 1320 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("centery"), &mesh.shot.Intrinsics.CenterPx[1]); |
| 1321 |
PushDescriport<int, int, 1>(cameraProp, cameraDescr, std::string("viewportx"), &mesh.shot.Intrinsics.ViewportPx[0]); |
| 1322 |
PushDescriport<int, int, 1>(cameraProp, cameraDescr, std::string("viewporty"), &mesh.shot.Intrinsics.ViewportPx[1]); |
| 1323 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k1"), &mesh.shot.Intrinsics.k[0]); |
| 1324 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k2"), &mesh.shot.Intrinsics.k[1]); |
| 1325 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k3"), &mesh.shot.Intrinsics.k[2]); |
| 1326 |
PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k4"), &mesh.shot.Intrinsics.k[3]); |
| 1327 |
} |
| 1328 |
|
| 1329 |
//Vertex |
| 1330 |
std::vector<std::string> nameList; |
| 1331 |
VertexType::Name(nameList); |
| 1332 |
std::vector<PlyProperty> vertexProp; |
| 1333 |
ElementDescriptor vertexDescr(NNP_VERTEX_ELEM); |
| 1334 |
if (nameList.size() > 0 && mesh.vert.size() > 0) |
| 1335 |
{ |
| 1336 |
if ((bitMask & BitMask::IO_VERTCOORD) && VertexType::HasCoord()) |
| 1337 |
PushDescriport<VertexType, VertexCoordScalar, 3>(vertexProp, vertexDescr, NNP_PXYZ, (*mesh.vert.begin()).P().V()); |
| 1338 |
if ((bitMask & BitMask::IO_VERTNORMAL) && vcg::tri::HasPerVertexNormal(mesh)) |
| 1339 |
{ |
| 1340 |
if (ocfVertexMask & BitMask::IO_VERTNORMAL) |
| 1341 |
PushDescriport<VertexNormalType, VertexNormScalar, 3>(vertexProp, vertexDescr, NNP_NXYZ, (*mesh.vert.begin()).N().V()); |
| 1342 |
else |
| 1343 |
PushDescriport<VertexType, VertexNormScalar, 3>(vertexProp, vertexDescr, NNP_NXYZ, (*mesh.vert.begin()).N().V()); |
| 1344 |
} |
| 1345 |
if ((bitMask & BitMask::IO_VERTCOLOR) && vcg::tri::HasPerVertexColor(mesh)) |
| 1346 |
{ |
| 1347 |
if (ocfVertexMask & BitMask::IO_VERTCOLOR) |
| 1348 |
PushDescriport<VertexColorType, VertexColorScalar, 4>(vertexProp, vertexDescr, NNP_CRGBA, (*mesh.vert.begin()).C().V()); |
| 1349 |
else |
| 1350 |
PushDescriport<VertexType, VertexColorScalar, 4>(vertexProp, vertexDescr, NNP_CRGBA, (*mesh.vert.begin()).C().V()); |
| 1351 |
} |
| 1352 |
if ((bitMask & BitMask::IO_VERTQUALITY) && vcg::tri::HasPerVertexQuality(mesh)) |
| 1353 |
{ |
| 1354 |
if (ocfVertexMask & BitMask::IO_VERTQUALITY) |
| 1355 |
PushDescriport<VertexQuality, VertexQuality, 1>(vertexProp, vertexDescr, NNP_QUALITY, &(*mesh.vert.begin()).Q()); |
| 1356 |
else |
| 1357 |
PushDescriport<VertexType, VertexQuality, 1>(vertexProp, vertexDescr, NNP_QUALITY, &(*mesh.vert.begin()).Q()); |
| 1358 |
} |
| 1359 |
if ((bitMask & BitMask::IO_VERTFLAGS) && vcg::tri::HasPerVertexFlags(mesh)) |
| 1360 |
PushDescriport<VertexType, VertexFlag, 1>(vertexProp, vertexDescr, NNP_BITFLAG, &(*mesh.vert.begin()).Flags()); |
| 1361 |
if ((bitMask & BitMask::IO_VERTRADIUS) && vcg::tri::HasPerVertexRadius(mesh)) |
| 1362 |
{ |
| 1363 |
if (ocfVertexMask & BitMask::IO_VERTRADIUS) |
| 1364 |
PushDescriport<VertexRadius, VertexRadius, 1>(vertexProp, vertexDescr, NNP_DENSITY, &(*mesh.vert.begin()).R()); |
| 1365 |
else |
| 1366 |
PushDescriport<VertexType, VertexRadius, 1>(vertexProp, vertexDescr, NNP_DENSITY, &(*mesh.vert.begin()).R()); |
| 1367 |
} |
| 1368 |
if ((bitMask & BitMask::IO_VERTTEXCOORD) && vcg::tri::HasPerVertexTexCoord(mesh)) |
| 1369 |
{ |
| 1370 |
if (ocfVertexMask & BitMask::IO_VERTTEXCOORD) |
| 1371 |
PushDescriport<VertexTexCoordType, VertexTexScalar, 2>(vertexProp, vertexDescr, NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V()); |
| 1372 |
else |
| 1373 |
PushDescriport<VertexType, VertexTexScalar, 2>(vertexProp, vertexDescr, NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V()); |
| 1374 |
} |
| 1375 |
// if ((bitMask & BitMask::IO_VERTCURV) && vcg::tri::HasPerVertexCurvature(mesh)) |
| 1376 |
// { |
| 1377 |
// if (ocfVertexMask & BitMask::IO_VERTTEXCOORD) |
| 1378 |
// { |
| 1379 |
// PushDescriport<VertexCurType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KG, &(*mesh.vert.begin()).Kg()); |
| 1380 |
// PushDescriport<VertexCurType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KH, &(*mesh.vert.begin()).Kh()); |
| 1381 |
// } |
| 1382 |
// else |
| 1383 |
// { |
| 1384 |
// PushDescriport<VertexType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KG, &(*mesh.vert.begin()).Kg()); |
| 1385 |
// PushDescriport<VertexType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KH, &(*mesh.vert.begin()).Kh()); |
| 1386 |
// } |
| 1387 |
// } |
| 1388 |
if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerVertexCurvatureDir(mesh)) |
| 1389 |
{ |
| 1390 |
if (ocfVertexMask & BitMask::IO_VERTCURVDIR) |
| 1391 |
{ |
| 1392 |
PushDescriport<VertexCurDirType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K1, &(*mesh.vert.begin()).K1()); |
| 1393 |
PushDescriport<VertexCurDirType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K2, &(*mesh.vert.begin()).K2()); |
| 1394 |
PushDescriportList<VertexCurDirType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K1DIR, (*mesh.vert.begin()).PD1().V()); |
| 1395 |
PushDescriportList<VertexCurDirType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K2DIR, (*mesh.vert.begin()).PD2().V()); |
| 1396 |
} |
| 1397 |
else |
| 1398 |
{ |
| 1399 |
PushDescriport<VertexType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K1, &(*mesh.vert.begin()).K1()); |
| 1400 |
PushDescriport<VertexType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K2, &(*mesh.vert.begin()).K2()); |
| 1401 |
PushDescriportList<VertexType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K1DIR, (*mesh.vert.begin()).PD1().V()); |
| 1402 |
PushDescriportList<VertexType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K2DIR, (*mesh.vert.begin()).PD2().V()); |
| 1403 |
} |
| 1404 |
} |
| 1405 |
if ((bitMask & BitMask::IO_VERTATTRIB)) |
| 1406 |
{ |
| 1407 |
typename std::set<PointerToAttribute>::iterator ai; |
| 1408 |
int userSize = custom.vertexAttrib.size(); |
| 1409 |
for (ai = mesh.vert_attr.begin(); ai != mesh.vert_attr.end(); ++ai) |
| 1410 |
{ |
| 1411 |
bool userDescr = false; |
| 1412 |
for (int i = 0; i < userSize; i++) |
| 1413 |
{ |
| 1414 |
if ((*custom.vertexAttrib[i]).name == (*ai)._name) |
| 1415 |
{ |
| 1416 |
userDescr = true; |
| 1417 |
break; |
| 1418 |
} |
| 1419 |
} |
| 1420 |
if (!userDescr) |
| 1421 |
custom.CreateVertexAttribDescriptor(&(*ai)); |
| 1422 |
} |
| 1423 |
for (size_t i = 0; i < custom.vertexAttrib.size(); i++) |
| 1424 |
{ |
| 1425 |
vertexProp.push_back(custom.vertexAttribProp[i]); |
| 1426 |
vertexDescr.dataDescriptor.push_back(custom.vertexAttrib[i]); |
| 1427 |
} |
| 1428 |
} |
| 1429 |
} |
| 1430 |
|
| 1431 |
//Edge |
| 1432 |
nameList.clear(); |
| 1433 |
EdgeType::Name(nameList); |
| 1434 |
std::vector<PlyProperty> edgeProp; |
| 1435 |
ElementDescriptor edgeDescr(NNP_EDGE_ELEM); |
| 1436 |
std::vector<vcg::Point2i> edgeIndex; |
| 1437 |
for (size_t i = 0; i < mesh.edge.size(); i++) |
| 1438 |
edgeIndex.push_back(vcg::Point2i(vcg::tri::Index(mesh, mesh.edge[i].V(0)), vcg::tri::Index(mesh, mesh.edge[i].V(1)))); |
| 1439 |
if (nameList.size() > 0 && mesh.edge.size() > 0) |
| 1440 |
{ |
| 1441 |
if ((bitMask & BitMask::IO_EDGEINDEX) && EdgeType::HasVertexRef()) |
| 1442 |
{ |
| 1443 |
PushDescriport<vcg::Point2i, int, 1>(edgeProp, edgeDescr, NNP_EDGE_V1, &(*edgeIndex.begin()).V()[0]); |
| 1444 |
PushDescriport<vcg::Point2i, int, 1>(edgeProp, edgeDescr, NNP_EDGE_V2, &(*edgeIndex.begin()).V()[1]); |
| 1445 |
} |
| 1446 |
if ((bitMask & BitMask::IO_EDGEQUALITY) && vcg::tri::HasPerEdgeQuality(mesh)) |
| 1447 |
PushDescriport<EdgeType, EdgeQuality, 1>(edgeProp, edgeDescr, NNP_QUALITY, &(*mesh.edge.begin()).Q()); |
| 1448 |
if ((bitMask & BitMask::IO_EDGECOLOR) && vcg::tri::HasPerEdgeColor(mesh)) |
| 1449 |
PushDescriport<EdgeType, EdgeColorScalar, 4>(edgeProp, edgeDescr, NNP_CRGBA, (*mesh.edge.begin()).C().V()); |
| 1450 |
if ((bitMask & BitMask::IO_EDGEFLAGS) && vcg::tri::HasPerEdgeFlags(mesh)) |
| 1451 |
PushDescriport<EdgeType, EdgeFlag, 1>(edgeProp, edgeDescr, NNP_BITFLAG, &(*mesh.edge.begin()).Flags()); |
| 1452 |
|
| 1453 |
if ((bitMask & BitMask::IO_EDGEATTRIB)) |
| 1454 |
{ |
| 1455 |
typename std::set<PointerToAttribute>::iterator ai; |
| 1456 |
int userSize = custom.edgeAttrib.size(); |
| 1457 |
for (ai = mesh.edge_attr.begin(); ai != mesh.edge_attr.end(); ++ai) |
| 1458 |
{ |
| 1459 |
bool userDescr = false; |
| 1460 |
for (int i = 0; i < userSize; i++) |
| 1461 |
{ |
| 1462 |
if ((*custom.edgeAttrib[i]).name == (*ai)._name) |
| 1463 |
{ |
| 1464 |
userDescr = true; |
| 1465 |
break; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
if (!userDescr) |
| 1469 |
custom.CreateEdgeAttribDescriptor(&(*ai)); |
| 1470 |
} |
| 1471 |
for (size_t i = 0; i < custom.edgeAttrib.size(); i++) |
| 1472 |
{ |
| 1473 |
edgeProp.push_back(custom.edgeAttribProp[i]); |
| 1474 |
edgeDescr.dataDescriptor.push_back(custom.edgeAttrib[i]); |
| 1475 |
} |
| 1476 |
} |
| 1477 |
} |
| 1478 |
|
| 1479 |
//Face |
| 1480 |
nameList.clear(); |
| 1481 |
FaceType::Name(nameList); |
| 1482 |
std::vector<PlyProperty> faceProp; |
| 1483 |
ElementDescriptor faceDescr(NNP_FACE_ELEM); |
| 1484 |
std::vector<std::vector<unsigned int>> faceIndex; |
| 1485 |
std::vector<vcg::ndim::Point<6, FaceTexScalar>> wedgeTexCoord; |
| 1486 |
for (size_t i = 0; i < mesh.face.size(); i++) |
| 1487 |
{ |
| 1488 |
faceIndex.push_back(std::vector<unsigned int>()); |
| 1489 |
for (int j = 0; j < mesh.face[i].VN(); j++) |
| 1490 |
faceIndex.back().push_back(vcg::tri::Index(mesh, mesh.face[i].V(j))); |
| 1491 |
} |
| 1492 |
if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh)) |
| 1493 |
{ |
| 1494 |
for (size_t i = 0; i < mesh.face.size(); i++) |
| 1495 |
{ |
| 1496 |
wedgeTexCoord.push_back(vcg::ndim::Point<6, FaceTexScalar>()); |
| 1497 |
for (int j = 0; j < 3; j++) |
| 1498 |
{ |
| 1499 |
wedgeTexCoord.back()[j * 2] = mesh.face[i].WT(j).U(); |
| 1500 |
wedgeTexCoord.back()[j * 2 + 1] = mesh.face[i].WT(j).V(); |
| 1501 |
} |
| 1502 |
} |
| 1503 |
} |
| 1504 |
if (nameList.size() > 0 && mesh.face.size() > 0) |
| 1505 |
{ |
| 1506 |
if ((bitMask & BitMask::IO_FACEINDEX) && FaceType::HasVertexRef()) |
| 1507 |
PushDescriportList<std::vector<unsigned int>, unsigned int, 0>(faceProp, faceDescr, NNP_FACE_VERTEX_LIST, &faceIndex[0]); |
| 1508 |
if ((bitMask & BitMask::IO_FACEFLAGS) && vcg::tri::HasPerFaceFlags(mesh)) |
| 1509 |
PushDescriport<FaceType, FaceFlag, 1>(faceProp, faceDescr, NNP_BITFLAG, &(*mesh.face.begin()).Flags()); |
| 1510 |
if ((bitMask & BitMask::IO_FACECOLOR) && vcg::tri::HasPerFaceColor(mesh)) |
| 1511 |
{ |
| 1512 |
if (ocfFaceMask & BitMask::IO_FACECOLOR) |
| 1513 |
PushDescriport<FaceColorType, FaceColorScalar, 4>(faceProp, faceDescr, NNP_CRGBA, (*mesh.face.begin()).C().V()); |
| 1514 |
else |
| 1515 |
PushDescriport<FaceType, FaceColorScalar, 4>(faceProp, faceDescr, NNP_CRGBA, (*mesh.face.begin()).C().V()); |
| 1516 |
} |
| 1517 |
if ((bitMask & BitMask::IO_FACEQUALITY) && vcg::tri::HasPerFaceQuality(mesh)) |
| 1518 |
{ |
| 1519 |
if (ocfFaceMask & BitMask::IO_FACEQUALITY) |
| 1520 |
PushDescriport<FaceQuality, FaceQuality, 1>(faceProp, faceDescr, NNP_QUALITY, &(*mesh.face.begin()).Q()); |
| 1521 |
else |
| 1522 |
PushDescriport<FaceType, FaceQuality, 1>(faceProp, faceDescr, NNP_QUALITY, &(*mesh.face.begin()).Q()); |
| 1523 |
} |
| 1524 |
if ((bitMask & BitMask::IO_FACENORMAL) && vcg::tri::HasPerFaceNormal(mesh)) |
| 1525 |
{ |
| 1526 |
if (ocfFaceMask & BitMask::IO_FACENORMAL) |
| 1527 |
PushDescriport<FaceNormalType, FaceNormScalar, 3>(faceProp, faceDescr, NNP_NXYZ, (*mesh.face.begin()).N().V()); |
| 1528 |
else |
| 1529 |
PushDescriport<FaceType, FaceNormScalar, 3>(faceProp, faceDescr, NNP_NXYZ, (*mesh.face.begin()).N().V()); |
| 1530 |
} |
| 1531 |
if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerFaceCurvatureDir(mesh)) |
| 1532 |
{ |
| 1533 |
if (ocfFaceMask & BitMask::IO_VERTCURVDIR) |
| 1534 |
{ |
| 1535 |
PushDescriport<FaceCurDirType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K1, &(*mesh.face.begin()).K1()); |
| 1536 |
PushDescriport<FaceCurDirType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K2, &(*mesh.face.begin()).K2()); |
| 1537 |
PushDescriportList<FaceCurDirType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K1DIR, (*mesh.face.begin()).PD1().V()); |
| 1538 |
PushDescriportList<FaceCurDirType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K2DIR, (*mesh.face.begin()).PD2().V()); |
| 1539 |
} |
| 1540 |
else |
| 1541 |
{ |
| 1542 |
PushDescriport<FaceType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K1, &(*mesh.face.begin()).K1()); |
| 1543 |
PushDescriport<FaceType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K2, &(*mesh.face.begin()).K2()); |
| 1544 |
PushDescriportList<FaceType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K1DIR, (*mesh.face.begin()).PD1().V()); |
| 1545 |
PushDescriportList<FaceType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K2DIR, (*mesh.face.begin()).PD2().V()); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh)) |
| 1549 |
PushDescriportList<vcg::ndim::Point<6, FaceTexScalar>, FaceTexScalar, 6>(faceProp, faceDescr, NNP_FACE_WEDGE_TEX, (*wedgeTexCoord.begin()).V()); |
| 1550 |
if ((bitMask & BitMask::IO_WEDGTEXMULTI) && vcg::tri::HasPerWedgeTexCoord(mesh)) |
| 1551 |
{ |
| 1552 |
if (ocfFaceMask & BitMask::IO_VERTCURVDIR) |
| 1553 |
PushDescriport<FaceTexCoordType, short, 1>(faceProp, faceDescr, NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N()); |
| 1554 |
else |
| 1555 |
PushDescriport<FaceType, short, 1>(faceProp, faceDescr, NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N()); |
| 1556 |
} |
| 1557 |
if ((bitMask & BitMask::IO_WEDGCOLOR) && vcg::tri::HasPerWedgeColor(mesh)) |
| 1558 |
{ |
| 1559 |
if (ocfFaceMask & BitMask::IO_WEDGCOLOR) |
| 1560 |
PushDescriportList<WedgeColorType, WedgeColorScalar, 12>(faceProp, faceDescr, NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V()); |
| 1561 |
else |
| 1562 |
PushDescriportList<FaceType, WedgeColorScalar, 12>(faceProp, faceDescr, NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V()); |
| 1563 |
} |
| 1564 |
if ((bitMask & BitMask::IO_WEDGNORMAL) && vcg::tri::HasPerWedgeNormal(mesh)) |
| 1565 |
{ |
| 1566 |
if (ocfFaceMask & BitMask::IO_WEDGNORMAL) |
| 1567 |
PushDescriportList<WedgeNormalType, WedgeNormalScalar, 9>(faceProp, faceDescr, NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V()); |
| 1568 |
else |
| 1569 |
PushDescriportList<FaceType, WedgeNormalScalar, 9>(faceProp, faceDescr, NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V()); |
| 1570 |
} |
| 1571 |
if ((bitMask & BitMask::IO_FACEATTRIB)) |
| 1572 |
{ |
| 1573 |
typename std::set<PointerToAttribute>::iterator ai; |
| 1574 |
int userSize = custom.faceAttrib.size(); |
| 1575 |
for (ai = mesh.face_attr.begin(); ai != mesh.face_attr.end(); ++ai) |
| 1576 |
{ |
| 1577 |
bool userDescr = false; |
| 1578 |
for (int i = 0; i < userSize; i++) |
| 1579 |
{ |
| 1580 |
if ((*custom.faceAttrib[i]).name == (*ai)._name) |
| 1581 |
{ |
| 1582 |
userDescr = true; |
| 1583 |
break; |
| 1584 |
} |
| 1585 |
} |
| 1586 |
if (!userDescr) |
| 1587 |
custom.CreateFaceAttribDescriptor(&(*ai)); |
| 1588 |
} |
| 1589 |
for (size_t i = 0; i < custom.faceAttrib.size(); i++) |
| 1590 |
{ |
| 1591 |
faceProp.push_back(custom.faceAttribProp[i]); |
| 1592 |
faceDescr.dataDescriptor.push_back(custom.faceAttrib[i]); |
| 1593 |
} |
| 1594 |
} |
| 1595 |
} |
| 1596 |
|
| 1597 |
Info infoSave; |
| 1598 |
infoSave.filename = filename; |
| 1599 |
infoSave.binary = binary; |
| 1600 |
PlyElement cameraElem(std::string("camera"), cameraProp, 1); |
| 1601 |
PlyElement vertexElem(NNP_VERTEX_ELEM, vertexProp, mesh.vert.size()); |
| 1602 |
PlyElement edgeElem(NNP_EDGE_ELEM, edgeProp, mesh.edge.size()); |
| 1603 |
PlyElement faceElem(NNP_FACE_ELEM, faceProp, mesh.face.size()); |
| 1604 |
infoSave.AddPlyElement(cameraElem); |
| 1605 |
infoSave.AddPlyElement(vertexElem); |
| 1606 |
infoSave.AddPlyElement(edgeElem); |
| 1607 |
infoSave.AddPlyElement(faceElem); |
| 1608 |
infoSave.textureFile = mesh.textures; |
| 1609 |
std::vector<ElementDescriptor*> meshDescr; |
| 1610 |
meshDescr.push_back(&cameraDescr); |
| 1611 |
meshDescr.push_back(&vertexDescr); |
| 1612 |
meshDescr.push_back(&edgeDescr); |
| 1613 |
meshDescr.push_back(&faceDescr); |
| 1614 |
|
| 1615 |
//Mesh attribute |
| 1616 |
if ((bitMask & BitMask::IO_MESHATTRIB)) |
| 1617 |
{ |
| 1618 |
typename CustomAttributeDescriptor::MapMeshAttribIter iter = custom.meshAttrib.begin(); |
| 1619 |
typename CustomAttributeDescriptor::MapMeshAttribPropIter iterProp = custom.meshAttribProp.begin(); |
| 1620 |
for (; iter != custom.meshAttrib.end(); iter++, iterProp++) |
| 1621 |
{ |
| 1622 |
std::string name((*iter).first); |
| 1623 |
PlyElement customElem(name, (*iterProp).second, custom.meshAttribCnt[(*iter).first]); |
| 1624 |
infoSave.AddPlyElement(customElem); |
| 1625 |
meshDescr.push_back(new ElementDescriptor(name)); |
| 1626 |
meshDescr.back()->dataDescriptor = (*iter).second; |
| 1627 |
} |
| 1628 |
} |
| 1629 |
|
| 1630 |
bool flag = nanoply::SaveModel(infoSave.filename, meshDescr, infoSave); |
| 1631 |
|
| 1632 |
for (size_t i = 0; i < cameraDescr.dataDescriptor.size(); i++) |
| 1633 |
delete cameraDescr.dataDescriptor[i]; |
| 1634 |
for (size_t i = 0; i < vertexDescr.dataDescriptor.size(); i++) |
| 1635 |
if (vertexDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1636 |
delete vertexDescr.dataDescriptor[i]; |
| 1637 |
for (size_t i = 0; i < edgeDescr.dataDescriptor.size(); i++) |
| 1638 |
if (edgeDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1639 |
delete edgeDescr.dataDescriptor[i]; |
| 1640 |
for (size_t i = 0; i < faceDescr.dataDescriptor.size(); i++) |
| 1641 |
if (faceDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY) |
| 1642 |
delete faceDescr.dataDescriptor[i]; |
| 1643 |
|
| 1644 |
return flag; |
| 1645 |
} |
| 1646 |
|
| 1647 |
|
| 1648 |
static bool SaveModel(const char* filename, MeshType& mesh, unsigned int bitMask, bool binary) |
| 1649 |
{ |
| 1650 |
CustomAttributeDescriptor custom; |
| 1651 |
return SaveModel(filename, mesh, bitMask, custom, binary); |
| 1652 |
} |
| 1653 |
|
| 1654 |
|
| 1655 |
}; |
| 1656 |
|
| 1657 |
} |
| 1658 |
|
| 1659 |
#endif |