2004-03-09 22:26:47 +01:00
|
|
|
/****************************************************************************
|
2004-03-03 16:00:51 +01:00
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2007-03-12 17:40:17 +01:00
|
|
|
Revision 1.34 2007/03/03 02:28:59 cignoni
|
|
|
|
Removed initialization of a single face in the main parsing loop. Single face cannot exist anymore with OCF. Moved into the tristrip parsing section.
|
|
|
|
|
2007-03-03 03:28:59 +01:00
|
|
|
Revision 1.33 2007/02/14 15:30:13 ganovelli
|
|
|
|
added treatment of HasPerVertexFlags absent
|
|
|
|
|
2007-02-14 16:30:13 +01:00
|
|
|
Revision 1.32 2007/02/02 00:29:33 tarini
|
|
|
|
added a few typecasts to QualityTypefor vertices and faces (avoids warinings when short int or int is used for Quality).
|
|
|
|
|
2007-02-02 01:29:33 +01:00
|
|
|
Revision 1.31 2006/12/18 09:46:39 callieri
|
|
|
|
camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot.
|
|
|
|
|
2006-12-18 10:46:39 +01:00
|
|
|
Revision 1.30 2006/11/27 10:36:13 cignoni
|
|
|
|
Removed flags initialization. no more necessary
|
|
|
|
|
2006-11-27 11:36:13 +01:00
|
|
|
Revision 1.29 2006/10/14 00:18:42 cignoni
|
|
|
|
Allowed the correct loading of meshes with 0 faces
|
|
|
|
|
2006-10-14 02:18:42 +02:00
|
|
|
Revision 1.28 2006/05/16 15:01:30 cignoni
|
|
|
|
Wedge colors are loaded into facecolor only if specified in the incoming pi.mask
|
|
|
|
|
2006-05-16 17:01:30 +02:00
|
|
|
Revision 1.27 2006/05/03 21:21:21 cignoni
|
|
|
|
Corrected bug: mismatch in the index of confidence vertex property (8 instead of 11)
|
|
|
|
Changed HasPerFaceColor to the new syntax (HasPerFaceColor(m) instead of FaceType::HasFaceColor() )
|
|
|
|
|
2006-05-03 23:21:21 +02:00
|
|
|
Revision 1.26 2006/02/03 09:46:24 corsini
|
|
|
|
Remove signed/unsigned warning
|
|
|
|
|
2006-02-03 10:46:24 +01:00
|
|
|
Revision 1.25 2006/01/11 10:37:12 cignoni
|
|
|
|
Removed warning for unused vars
|
|
|
|
|
2006-01-11 11:37:12 +01:00
|
|
|
Revision 1.24 2006/01/10 13:20:42 cignoni
|
|
|
|
Changed ply::PlyMask to io::Mask
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
Revision 1.23 2006/01/04 16:17:03 cignoni
|
|
|
|
Corrected use of mask and callback in function Open(m,filename,mask,callback);
|
|
|
|
|
2006-01-04 17:17:03 +01:00
|
|
|
Revision 1.22 2005/12/30 22:30:43 cignoni
|
|
|
|
Added support for per vertex color stored as 'diffuse_xxx' property
|
|
|
|
|
2005-12-30 23:30:43 +01:00
|
|
|
Revision 1.21 2005/12/02 10:04:18 cignoni
|
|
|
|
forgotten a couple of std::
|
|
|
|
|
2005-12-02 11:04:18 +01:00
|
|
|
Revision 1.20 2005/12/02 00:01:30 cignoni
|
|
|
|
Added loading of texturenames (normalmap still to do)
|
|
|
|
|
2005-12-02 01:01:30 +01:00
|
|
|
Revision 1.19 2005/11/25 10:23:27 cignoni
|
|
|
|
Added safe zero initialization of index of wedge texture
|
|
|
|
|
2005-11-25 11:23:27 +01:00
|
|
|
Revision 1.18 2005/11/23 16:59:55 callieri
|
|
|
|
corrected protected access methods (camera, similarity) of shot
|
|
|
|
|
2005-11-23 17:59:55 +01:00
|
|
|
Revision 1.17 2005/11/12 18:13:30 cignoni
|
|
|
|
Added support for non triangular faces (simple fan triangulation) and removed flags intiailization.
|
|
|
|
|
2005-11-12 19:13:30 +01:00
|
|
|
Revision 1.16 2005/10/14 15:09:56 cignoni
|
|
|
|
Added LoadMask without plyinfo and some comment on the mask usage
|
|
|
|
|
2005-10-14 17:09:56 +02:00
|
|
|
Revision 1.15 2005/06/10 15:05:00 cignoni
|
|
|
|
Made inline PlyType specializations
|
|
|
|
|
2005-06-10 17:05:00 +02:00
|
|
|
Revision 1.14 2005/04/14 15:09:38 ponchio
|
|
|
|
New gcc 3.3.3 (with bugs and features) now compiles.
|
|
|
|
|
2005-04-14 17:09:38 +02:00
|
|
|
Revision 1.13 2005/03/18 00:14:39 cignoni
|
|
|
|
removed small gcc compiling issues
|
|
|
|
|
2005-03-18 01:14:40 +01:00
|
|
|
Revision 1.12 2005/02/08 17:28:22 tarini
|
|
|
|
changed 120 "const static" to "static const", and added missing "format" fields to all PropDescriptor literals, to keep Mingw compiler happy
|
|
|
|
|
2005-02-08 18:28:22 +01:00
|
|
|
Revision 1.11 2005/01/03 10:35:47 cignoni
|
|
|
|
Improved the compatibility for ply format for faces having the list size (e.g. number of vertexes of a face) as a char instead of a uchar.
|
|
|
|
Added a couple of new face descriptors, corrected a bug in error reporting function (and restructured) and translated a few comments.
|
|
|
|
Thanks to Patrick Min for the careful bug reporting
|
|
|
|
|
2005-01-03 11:35:59 +01:00
|
|
|
Revision 1.10 2004/10/07 14:51:10 ganovelli
|
|
|
|
added setidentity della camera
|
|
|
|
|
2004-10-07 16:51:10 +02:00
|
|
|
Revision 1.9 2004/10/07 14:19:06 ganovelli
|
|
|
|
shot/camera io added
|
|
|
|
|
2004-10-07 16:19:06 +02:00
|
|
|
Revision 1.8 2004/06/23 15:36:43 cignoni
|
|
|
|
Restructured management of error, now the standard open for any mesh type return the error code, the default success value is zero
|
|
|
|
Any import class has a method ErrorMsg that give a verbal description of an error code.
|
|
|
|
|
2004-06-23 17:36:57 +02:00
|
|
|
Revision 1.7 2004/06/11 17:09:41 ganovelli
|
|
|
|
inclusion of vector..minorchanges
|
|
|
|
|
2004-06-11 19:09:41 +02:00
|
|
|
Revision 1.6 2004/05/28 14:11:13 ganovelli
|
|
|
|
changes to comply io_mask moving in vcg::ply namesp
|
|
|
|
|
2004-05-28 16:11:13 +02:00
|
|
|
Revision 1.5 2004/05/12 10:19:30 ganovelli
|
|
|
|
new line added at the end of file
|
|
|
|
|
2004-05-12 12:19:30 +02:00
|
|
|
Revision 1.4 2004/05/04 02:36:07 ganovelli
|
|
|
|
#ifndef __VCGLIB_IMPORTERPLY added
|
|
|
|
|
2004-05-04 04:36:07 +02:00
|
|
|
Revision 1.3 2004/04/03 13:30:01 cignoni
|
|
|
|
missing include allocate.h
|
|
|
|
|
2004-04-03 15:30:01 +02:00
|
|
|
Revision 1.2 2004/03/09 21:26:47 cignoni
|
|
|
|
cr lf mismatch
|
|
|
|
|
2004-03-09 22:26:47 +01:00
|
|
|
Revision 1.1 2004/03/03 15:00:51 cignoni
|
|
|
|
Initial commit
|
|
|
|
|
2004-03-03 16:00:51 +01:00
|
|
|
****************************************************************************/
|
2004-05-04 04:36:07 +02:00
|
|
|
#ifndef __VCGLIB_IMPORTERPLY
|
|
|
|
#define __VCGLIB_IMPORTERPLY
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
#include<wrap/callback.h>
|
|
|
|
#include<wrap/ply/plylib.h>
|
2006-01-10 14:20:42 +01:00
|
|
|
#include<wrap/io_trimesh/io_mask.h>
|
2004-03-09 22:26:47 +01:00
|
|
|
#include<wrap/io_trimesh/io_ply.h>
|
2004-04-03 15:30:01 +02:00
|
|
|
#include<vcg/complex/trimesh/allocate.h>
|
2005-03-18 01:14:40 +01:00
|
|
|
#include<vcg/space/color4.h>
|
2004-06-11 19:09:41 +02:00
|
|
|
#include <vector>
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
namespace io {
|
|
|
|
|
|
|
|
template <class TYPE>
|
|
|
|
int PlyType () { return 0;}
|
|
|
|
|
2005-06-10 17:05:00 +02:00
|
|
|
|
|
|
|
// 10/6/05 Cignoni this specialization must be inlined becouse otherwise if we include this
|
|
|
|
// .h in two different cpp we should get a double definition error during linking
|
|
|
|
|
|
|
|
template <> inline int PlyType <float >() { return ply::T_FLOAT; }
|
|
|
|
template <> inline int PlyType <double>() { return ply::T_DOUBLE; }
|
|
|
|
template <> inline int PlyType <int >() { return ply::T_INT; }
|
|
|
|
template <> inline int PlyType <short >() { return ply::T_SHORT; }
|
|
|
|
template <> inline int PlyType <unsigned char >() { return ply::T_UCHAR; }
|
2004-03-09 22:26:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
This class encapsulate a filter for opening ply meshes.
|
|
|
|
The ply file format is quite extensible...
|
|
|
|
*/
|
2004-03-03 16:00:51 +01:00
|
|
|
template <class OpenMeshType>
|
|
|
|
class ImporterPLY
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
|
|
|
typedef typename OpenMeshType::VertexPointer VertexPointer;
|
|
|
|
typedef typename OpenMeshType::ScalarType ScalarType;
|
|
|
|
typedef typename OpenMeshType::VertexType VertexType;
|
|
|
|
typedef typename OpenMeshType::FaceType FaceType;
|
|
|
|
typedef typename OpenMeshType::VertexIterator VertexIterator;
|
|
|
|
typedef typename OpenMeshType::FaceIterator FaceIterator;
|
|
|
|
|
|
|
|
//template <class T> int PlyType () { assert(0); return 0;}
|
|
|
|
|
|
|
|
#define MAX_USER_DATA 256
|
|
|
|
// Struttura ausiliaria per la lettura del file ply
|
|
|
|
struct LoadPly_FaceAux
|
|
|
|
{
|
|
|
|
unsigned char size;
|
|
|
|
int v[512];
|
|
|
|
int flags;
|
|
|
|
float q;
|
2007-03-12 17:40:17 +01:00
|
|
|
float texcoord[32];
|
|
|
|
unsigned char ntexcoord;
|
|
|
|
int texcoordind;
|
2004-03-03 16:00:51 +01:00
|
|
|
float colors[32];
|
|
|
|
unsigned char ncolors;
|
|
|
|
|
|
|
|
unsigned char r;
|
|
|
|
unsigned char g;
|
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
unsigned char data[MAX_USER_DATA];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LoadPly_TristripAux
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
int *v;
|
|
|
|
unsigned char data[MAX_USER_DATA];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Struttura ausiliaria per la lettura del file ply
|
|
|
|
template<class S>
|
|
|
|
struct LoadPly_VertAux
|
|
|
|
{
|
|
|
|
S p[3];
|
|
|
|
int flags;
|
|
|
|
float q;
|
|
|
|
unsigned char r;
|
|
|
|
unsigned char g;
|
|
|
|
unsigned char b;
|
|
|
|
unsigned char data[MAX_USER_DATA];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Struttura ausiliaria caricamento camera
|
|
|
|
struct LoadPly_Camera
|
|
|
|
{
|
|
|
|
float view_px;
|
|
|
|
float view_py;
|
|
|
|
float view_pz;
|
|
|
|
float x_axisx;
|
|
|
|
float x_axisy;
|
|
|
|
float x_axisz;
|
|
|
|
float y_axisx;
|
|
|
|
float y_axisy;
|
|
|
|
float y_axisz;
|
|
|
|
float z_axisx;
|
|
|
|
float z_axisy;
|
|
|
|
float z_axisz;
|
|
|
|
float focal;
|
|
|
|
float scalex;
|
|
|
|
float scaley;
|
|
|
|
float centerx;
|
|
|
|
float centery;
|
|
|
|
int viewportx;
|
|
|
|
int viewporty;
|
|
|
|
float k1;
|
|
|
|
float k2;
|
|
|
|
float k3;
|
|
|
|
float k4;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const PropDescriptor &VertDesc(int i)
|
|
|
|
{
|
2005-12-30 23:30:43 +01:00
|
|
|
static const PropDescriptor pv[12]={
|
|
|
|
/*00*/ {"vertex", "x", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p),0,0,0,0,0 ,0},
|
|
|
|
/*01*/ {"vertex", "y", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p) + sizeof(ScalarType),0,0,0,0,0 ,0},
|
|
|
|
/*02*/ {"vertex", "z", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p) + 2*sizeof(ScalarType),0,0,0,0,0 ,0},
|
|
|
|
/*03*/ {"vertex", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_VertAux<ScalarType>,flags),0,0,0,0,0 ,0},
|
|
|
|
/*04*/ {"vertex", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0 ,0},
|
|
|
|
/*05*/ {"vertex", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,r),0,0,0,0,0 ,0},
|
|
|
|
/*06*/ {"vertex", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,g),0,0,0,0,0 ,0},
|
|
|
|
/*07*/ {"vertex", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,b),0,0,0,0,0 ,0},
|
|
|
|
/*08*/ {"vertex", "diffuse_red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,r),0,0,0,0,0 ,0},
|
|
|
|
/*09*/ {"vertex", "diffuse_green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,g),0,0,0,0,0 ,0},
|
|
|
|
/*10*/ {"vertex", "diffuse_blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,b),0,0,0,0,0 ,0},
|
|
|
|
/*11*/ {"vertex", "confidence",ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0 ,0},
|
2004-03-03 16:00:51 +01:00
|
|
|
};
|
|
|
|
return pv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const PropDescriptor &FaceDesc(int i)
|
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
static const PropDescriptor qf[12]=
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
{"face", "vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,v), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_FaceAux,size) ,0},
|
|
|
|
{"face", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,flags), 0,0,0,0,0 ,0},
|
|
|
|
{"face", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_FaceAux,q), 0,0,0,0,0 ,0},
|
2007-03-12 17:40:17 +01:00
|
|
|
{"face", "texcoord", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_FaceAux,texcoord), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_FaceAux,ntexcoord) ,0},
|
2005-02-08 18:28:22 +01:00
|
|
|
{"face", "color", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_FaceAux,colors), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_FaceAux,ncolors) ,0},
|
2007-03-12 17:40:17 +01:00
|
|
|
{"face", "texnumber", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,texcoordind), 0,0,0,0,0 ,0},
|
2005-02-08 18:28:22 +01:00
|
|
|
{"face", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_FaceAux,r), 0,0,0,0,0 ,0},
|
|
|
|
{"face", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_FaceAux,g), 0,0,0,0,0 ,0},
|
|
|
|
{"face", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_FaceAux,b), 0,0,0,0,0 ,0},
|
|
|
|
{"face", "vertex_index", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,v), 1,0,ply::T_UCHAR,ply::T_CHAR,offsetof(LoadPly_FaceAux,size) ,0},
|
|
|
|
{"face", "vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,v), 1,0,ply::T_CHAR,ply::T_CHAR,offsetof(LoadPly_FaceAux,size) ,0},
|
|
|
|
{"face", "vertex_index", ply::T_INT, ply::T_INT, offsetof(LoadPly_FaceAux,v), 1,0,ply::T_CHAR,ply::T_CHAR,offsetof(LoadPly_FaceAux,size) ,0},
|
2004-03-03 16:00:51 +01:00
|
|
|
};
|
|
|
|
return qf[i];
|
|
|
|
}
|
|
|
|
static const PropDescriptor &TristripDesc(int i)
|
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
static const PropDescriptor qf[1]=
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
{"tristrips","vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TristripAux,v), 1,1,ply::T_INT,ply::T_INT,offsetof(LoadPly_TristripAux,size) ,0},
|
2004-03-03 16:00:51 +01:00
|
|
|
};
|
|
|
|
return qf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const PropDescriptor &CameraDesc(int i)
|
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
static const PropDescriptor cad[23] =
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2005-02-08 18:28:22 +01:00
|
|
|
{"camera","view_px",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_px),0,0,0,0,0 ,0},
|
|
|
|
{"camera","view_py",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_py),0,0,0,0,0 ,0},
|
|
|
|
{"camera","view_pz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_pz),0,0,0,0,0 ,0},
|
|
|
|
{"camera","x_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisx),0,0,0,0,0 ,0},
|
|
|
|
{"camera","x_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisy),0,0,0,0,0 ,0},
|
|
|
|
{"camera","x_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisz),0,0,0,0,0 ,0},
|
|
|
|
{"camera","y_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisx),0,0,0,0,0 ,0},
|
|
|
|
{"camera","y_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisy),0,0,0,0,0 ,0},
|
|
|
|
{"camera","y_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisz),0,0,0,0,0 ,0},
|
|
|
|
{"camera","z_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisx),0,0,0,0,0 ,0},
|
|
|
|
{"camera","z_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisy),0,0,0,0,0 ,0},
|
|
|
|
{"camera","z_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisz),0,0,0,0,0 ,0},
|
|
|
|
{"camera","focal" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,focal ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","scalex" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scalex ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","scaley" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scaley ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","centerx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centerx),0,0,0,0,0 ,0},
|
|
|
|
{"camera","centery",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centery),0,0,0,0,0 ,0},
|
|
|
|
{"camera","viewportx",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewportx),0,0,0,0,0 ,0},
|
|
|
|
{"camera","viewporty",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewporty),0,0,0,0,0 ,0},
|
|
|
|
{"camera","k1" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k1 ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","k2" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k2 ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","k3" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k3 ),0,0,0,0,0 ,0},
|
|
|
|
{"camera","k4" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k4 ),0,0,0,0,0 ,0}
|
2004-03-03 16:00:51 +01:00
|
|
|
};
|
|
|
|
return cad[i];
|
|
|
|
}
|
2004-06-23 17:36:57 +02:00
|
|
|
/// Standard call for knowing the meaning of an error code
|
|
|
|
static const char *ErrorMsg(int error)
|
|
|
|
{
|
2005-01-03 11:35:59 +01:00
|
|
|
static std::vector<std::string> ply_error_msg;
|
|
|
|
if(ply_error_msg.empty())
|
|
|
|
{
|
|
|
|
ply_error_msg.resize(PlyInfo::E_MAXPLYINFOERRORS );
|
|
|
|
ply_error_msg[ply::E_NOERROR ]="No errors";
|
|
|
|
ply_error_msg[ply::E_CANTOPEN ]="Can't open file";
|
|
|
|
ply_error_msg[ply::E_NOTHEADER ]="Header not found";
|
|
|
|
ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header";
|
|
|
|
ply_error_msg[ply::E_NOFORMAT ]="Format not found";
|
|
|
|
ply_error_msg[ply::E_SYNTAX ]="Syntax error on header";
|
|
|
|
ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element";
|
|
|
|
ply_error_msg[ply::E_BADTYPENAME ]="Bad type name";
|
|
|
|
ply_error_msg[ply::E_ELEMNOTFOUND ]="Element not found";
|
|
|
|
ply_error_msg[ply::E_PROPNOTFOUND ]="Property not found";
|
|
|
|
ply_error_msg[ply::E_BADTYPE ]="Bad type on addtoread";
|
|
|
|
ply_error_msg[ply::E_INCOMPATIBLETYPE]="Incompatible type";
|
|
|
|
ply_error_msg[ply::E_BADCAST ]="Bad cast";
|
|
|
|
|
|
|
|
ply_error_msg[PlyInfo::E_NO_VERTEX ]="No vertex field found";
|
|
|
|
ply_error_msg[PlyInfo::E_NO_FACE ]="No face field found";
|
|
|
|
ply_error_msg[PlyInfo::E_SHORTFILE ]="Unespected eof";
|
|
|
|
ply_error_msg[PlyInfo::E_NO_3VERTINFACE ]="Face with more than 3 vertices";
|
|
|
|
ply_error_msg[PlyInfo::E_BAD_VERT_INDEX ]="Bad vertex index in face";
|
|
|
|
ply_error_msg[PlyInfo::E_NO_6TCOORD ]="Face with no 6 texture coordinates";
|
|
|
|
ply_error_msg[PlyInfo::E_DIFFER_COLORS ]="Number of color differ from vertices";
|
|
|
|
}
|
2004-06-23 17:36:57 +02:00
|
|
|
|
|
|
|
if(error>PlyInfo::E_MAXPLYINFOERRORS || error<0) return "Unknown error";
|
2005-01-03 11:35:59 +01:00
|
|
|
else return ply_error_msg[error].c_str();
|
2004-06-23 17:36:57 +02:00
|
|
|
};
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
|
2004-03-09 22:26:47 +01:00
|
|
|
/// Standard call for reading a mesh
|
2004-03-03 16:00:51 +01:00
|
|
|
static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
|
|
|
{
|
|
|
|
PlyInfo pi;
|
|
|
|
pi.cb=cb;
|
|
|
|
return Open(m, filename, pi);
|
|
|
|
}
|
|
|
|
|
2004-03-09 22:26:47 +01:00
|
|
|
/// Read a mesh and store in loadmask the loaded field
|
2005-10-14 17:09:56 +02:00
|
|
|
/// Note that loadmask is not read! just modified. You cannot specify what fields
|
|
|
|
/// have to be read. ALL the data for which your mesh HasSomething and are present
|
|
|
|
/// in the file are read in.
|
2004-03-03 16:00:51 +01:00
|
|
|
static int Open( OpenMeshType &m, const char * filename, int & loadmask, CallBackPos *cb =0)
|
|
|
|
{
|
|
|
|
PlyInfo pi;
|
2006-01-04 17:17:03 +01:00
|
|
|
pi.cb=cb;
|
|
|
|
return Open(m, filename,pi);
|
2004-03-03 16:00:51 +01:00
|
|
|
loadmask=pi.mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-09 22:26:47 +01:00
|
|
|
/// read a mesh with all the possible option specified in the PlyInfo obj.
|
2004-03-03 16:00:51 +01:00
|
|
|
static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
|
|
|
{
|
|
|
|
assert(filename!=0);
|
2004-06-11 19:09:41 +02:00
|
|
|
std::vector<VertexPointer> index;
|
2004-03-03 16:00:51 +01:00
|
|
|
LoadPly_FaceAux fa;
|
|
|
|
LoadPly_TristripAux tsa;
|
|
|
|
LoadPly_VertAux<ScalarType> va;
|
|
|
|
|
|
|
|
pi.mask = 0;
|
|
|
|
bool multit = false; // true if texture has a per face int spec the texture index
|
|
|
|
|
|
|
|
va.flags = 42;
|
|
|
|
|
|
|
|
pi.status = ::vcg::ply::E_NOERROR;
|
|
|
|
|
|
|
|
// init defaults
|
|
|
|
VertexType tv;
|
2005-11-12 19:13:30 +01:00
|
|
|
//tv.ClearFlags();
|
2007-02-02 01:29:33 +01:00
|
|
|
if( VertexType::HasQuality() ) tv.Q()=(typename OpenMeshType::VertexType::QualityType)1.0;
|
2004-03-03 16:00:51 +01:00
|
|
|
if( VertexType::HasColor() ) tv.C()=Color4b(Color4b::White);
|
|
|
|
|
|
|
|
// Descrittori delle strutture
|
|
|
|
|
|
|
|
//bool isvflags = false; // Il file contiene i flags
|
|
|
|
|
|
|
|
|
|
|
|
// The main descriptor of the ply file
|
2004-05-12 12:19:30 +02:00
|
|
|
vcg::ply::PlyFile pf;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
// Open the file and parse the header
|
|
|
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
|
|
|
{
|
|
|
|
pi.status = pf.GetError();
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
pi.header = pf.GetHeader();
|
|
|
|
|
|
|
|
// Descrittori della camera
|
|
|
|
{ // Check that all the camera properties are present.
|
|
|
|
bool found = true;
|
|
|
|
for(int i=0;i<23;++i)
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(CameraDesc(i))==-1 ) {
|
|
|
|
found = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-10 14:20:42 +01:00
|
|
|
if(found) pi.mask |= Mask::IOM_CAMERA;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Descrittori dati standard (vertex coord e faces)
|
2004-06-23 17:36:57 +02:00
|
|
|
if( pf.AddToRead(VertDesc(0))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return pi.status; }
|
|
|
|
if( pf.AddToRead(VertDesc(1))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return pi.status; }
|
|
|
|
if( pf.AddToRead(VertDesc(2))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return pi.status; }
|
2004-03-03 16:00:51 +01:00
|
|
|
if( pf.AddToRead(FaceDesc(0))==-1 ) // Se fallisce si prova anche la sintassi di rapidform con index al posto di indices
|
|
|
|
if( pf.AddToRead(FaceDesc(9))==-1 )
|
2005-01-03 11:35:59 +01:00
|
|
|
if( pf.AddToRead(FaceDesc(10))==-1 )
|
|
|
|
if( pf.AddToRead(FaceDesc(11))==-1 )
|
2004-03-03 16:00:51 +01:00
|
|
|
if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy.
|
2004-06-23 17:36:57 +02:00
|
|
|
{ pi.status = PlyInfo::E_NO_FACE; return pi.status; }
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
// Descrittori facoltativi dei flags
|
2005-11-12 19:13:30 +01:00
|
|
|
|
2007-02-14 16:30:13 +01:00
|
|
|
if(VertexType::HasFlags() && pf.AddToRead(VertDesc(3))!=-1 )
|
|
|
|
pi.mask |= Mask::IOM_VERTFLAGS;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
if( VertexType::HasQuality() )
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(VertDesc(4))!=-1 ||
|
2006-05-03 23:21:21 +02:00
|
|
|
pf.AddToRead(VertDesc(11))!=-1 )
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_VERTQUALITY;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( VertexType::HasColor() )
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(VertDesc(5))!=-1 )
|
|
|
|
{
|
|
|
|
pf.AddToRead(VertDesc(6));
|
|
|
|
pf.AddToRead(VertDesc(7));
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_VERTCOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
2005-12-30 23:30:43 +01:00
|
|
|
if( pf.AddToRead(VertDesc(8))!=-1 )
|
|
|
|
{
|
|
|
|
pf.AddToRead(VertDesc(9));
|
|
|
|
pf.AddToRead(VertDesc(10));
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_VERTCOLOR;
|
2005-12-30 23:30:43 +01:00
|
|
|
}
|
|
|
|
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// se ci sono i flag per vertice ci devono essere anche i flag per faccia
|
|
|
|
if( pf.AddToRead(FaceDesc(1))!=-1 )
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_FACEFLAGS;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
if( FaceType::HasFaceQuality())
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(FaceDesc(2))!=-1 )
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_FACEQUALITY;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( FaceType::HasFaceColor() )
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(FaceDesc(6))!=-1 )
|
|
|
|
{
|
|
|
|
pf.AddToRead(FaceDesc(7));
|
|
|
|
pf.AddToRead(FaceDesc(8));
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_FACECOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-12 17:40:17 +01:00
|
|
|
if( FaceType::HasWedgeTexCoord() )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
if( pf.AddToRead(FaceDesc(3))!=-1 )
|
|
|
|
{
|
|
|
|
if(pf.AddToRead(FaceDesc(5))==0) {
|
|
|
|
multit=true; // try to read also the multi texture indicies
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_WEDGTEXMULTI;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_WEDGTEXCOORD;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( FaceType::HasWedgeColor() || FaceType::HasFaceColor() || VertexType::HasColor())
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(FaceDesc(4))!=-1 )
|
|
|
|
{
|
2006-01-10 14:20:42 +01:00
|
|
|
pi.mask |= Mask::IOM_WEDGCOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Descrittori definiti dall'utente,
|
2004-06-11 19:09:41 +02:00
|
|
|
std::vector<PropDescriptor> VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux
|
|
|
|
std::vector<PropDescriptor> FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux
|
2004-03-03 16:00:51 +01:00
|
|
|
if(pi.vdn>0){
|
|
|
|
// Compute the total size needed to load additional per vertex data.
|
|
|
|
size_t totsz=0;
|
|
|
|
for(int i=0;i<pi.vdn;i++){
|
|
|
|
VPV[i] = pi.VertexData[i];
|
|
|
|
VPV[i].offset1=offsetof(LoadPly_VertAux<ScalarType>,data)+totsz;
|
|
|
|
totsz+=pi.VertexData[i].memtypesize();
|
2004-06-23 17:36:57 +02:00
|
|
|
if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return pi.status; }
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
if(totsz > MAX_USER_DATA)
|
|
|
|
{
|
|
|
|
pi.status = vcg::ply::E_BADTYPE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pi.fdn>0){
|
|
|
|
size_t totsz=0;
|
|
|
|
for(int i=0;i<pi.fdn;i++){
|
|
|
|
FPV[i] = pi.FaceData[i];
|
|
|
|
FPV[i].offset1=offsetof(LoadPly_FaceAux,data)+totsz;
|
|
|
|
totsz+=pi.FaceData[i].memtypesize();
|
2004-06-23 17:36:57 +02:00
|
|
|
if( pf.AddToRead(FPV[i])==-1 ) { pi.status = pf.GetError(); return pi.status; }
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
if(totsz > MAX_USER_DATA)
|
|
|
|
{
|
|
|
|
pi.status = vcg::ply::E_BADTYPE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************/
|
|
|
|
/* Main Reading Loop */
|
|
|
|
/**************************************************************/
|
|
|
|
m.Clear();
|
|
|
|
for(int i=0;i<int(pf.elements.size());i++)
|
|
|
|
{
|
|
|
|
int n = pf.ElemNumber(i);
|
|
|
|
|
|
|
|
if( !strcmp( pf.ElemName(i),"camera" ) )
|
|
|
|
{
|
|
|
|
pf.SetCurElement(i);
|
|
|
|
|
|
|
|
LoadPly_Camera ca;
|
|
|
|
|
|
|
|
for(int j=0;j<n;++j)
|
|
|
|
{
|
|
|
|
if( pf.Read( (void *)&(ca) )==-1 )
|
|
|
|
{
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_SHORTFILE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
//camera.valid = true;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
|
|
|
// extrinsic
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Extrinsics.SetIdentity();
|
2005-11-23 17:59:55 +01:00
|
|
|
// view point
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Extrinsics.tra[0] = -ca.view_px;
|
|
|
|
m.shot.Extrinsics.tra[1] = -ca.view_py;
|
|
|
|
m.shot.Extrinsics.tra[2] = -ca.view_pz;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
|
|
|
// axis (i.e. rotation).
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Extrinsics.rot[0][0] = ca.x_axisx;
|
|
|
|
m.shot.Extrinsics.rot[0][1] = ca.x_axisy;
|
|
|
|
m.shot.Extrinsics.rot[0][2] = ca.x_axisz;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Extrinsics.rot[1][0] = ca.y_axisx;
|
|
|
|
m.shot.Extrinsics.rot[1][1] = ca.y_axisy;
|
|
|
|
m.shot.Extrinsics.rot[1][2] = ca.y_axisz;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Extrinsics.rot[2][0] = ca.z_axisx;
|
|
|
|
m.shot.Extrinsics.rot[2][1] = ca.z_axisy;
|
|
|
|
m.shot.Extrinsics.rot[2][2] = ca.z_axisz;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
|
|
|
//intrinsic
|
2006-12-18 10:46:39 +01:00
|
|
|
m.shot.Intrinsics.FocalMm = ca.focal;
|
|
|
|
m.shot.Intrinsics.PixelSizeMm[0] = ca.scalex;
|
|
|
|
m.shot.Intrinsics.PixelSizeMm[1] = ca.scaley;
|
|
|
|
m.shot.Intrinsics.CenterPx[0] = ca.centerx;
|
|
|
|
m.shot.Intrinsics.CenterPx[1] = ca.centery;
|
|
|
|
m.shot.Intrinsics.ViewportPx[0] = ca.viewportx;
|
|
|
|
m.shot.Intrinsics.ViewportPx[1] = ca.viewporty;
|
|
|
|
m.shot.Intrinsics.k[0] = ca.k1;
|
|
|
|
m.shot.Intrinsics.k[1] = ca.k2;
|
|
|
|
m.shot.Intrinsics.k[2] = ca.k3;
|
|
|
|
m.shot.Intrinsics.k[3] = ca.k4;
|
2004-10-07 16:19:06 +02:00
|
|
|
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !strcmp( pf.ElemName(i),"vertex" ) )
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
pf.SetCurElement(i);
|
|
|
|
VertexIterator vi=Allocator<OpenMeshType>::AddVertices(m,n);
|
|
|
|
|
|
|
|
for(j=0;j<n;++j)
|
|
|
|
{
|
|
|
|
if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading");
|
2005-11-12 19:13:30 +01:00
|
|
|
//(*vi).UberFlags()=0; // No more necessary, since 9/2005 flags are set to zero in the constuctor.
|
2004-03-03 16:00:51 +01:00
|
|
|
if( pf.Read( (void *)&(va) )==-1 )
|
|
|
|
{
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_SHORTFILE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
(*vi).P()[0] = va.p[0];
|
|
|
|
(*vi).P()[1] = va.p[1];
|
|
|
|
(*vi).P()[2] = va.p[2];
|
|
|
|
|
2007-02-14 16:30:13 +01:00
|
|
|
if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS) )
|
2004-03-03 16:00:51 +01:00
|
|
|
(*vi).UberFlags() = va.flags;
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_VERTQUALITY )
|
2007-02-02 01:29:33 +01:00
|
|
|
(*vi).Q() = (typename OpenMeshType::VertexType::QualityType)va.q;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_VERTCOLOR )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
(*vi).C()[0] = va.r;
|
|
|
|
(*vi).C()[1] = va.g;
|
|
|
|
(*vi).C()[2] = va.b;
|
|
|
|
(*vi).C()[3] = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int k=0;k<pi.vdn;k++)
|
|
|
|
memcpy((char *)(&*vi) + pi.VertexData[k].offset1,
|
|
|
|
(char *)(&va) + VPV[k].offset1,
|
|
|
|
VPV[k].memtypesize());
|
|
|
|
++vi;
|
|
|
|
}
|
|
|
|
|
|
|
|
index.resize(n);
|
|
|
|
for(j=0,vi=m.vert.begin();j<n;++j,++vi)
|
|
|
|
index[j] = &*vi;
|
|
|
|
}
|
2006-10-14 02:18:42 +02:00
|
|
|
else if( !strcmp( pf.ElemName(i),"face") && (n>0) )/************************************************************/
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
FaceIterator fi=Allocator<OpenMeshType>::AddFaces(m,n);
|
|
|
|
pf.SetCurElement(i);
|
|
|
|
|
|
|
|
for(j=0;j<n;++j)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
|
|
|
if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Face Loading");
|
|
|
|
if( pf.Read(&fa)==-1 )
|
|
|
|
{
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_SHORTFILE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
if(fa.size!=3)
|
2005-11-12 19:13:30 +01:00
|
|
|
{ // Non triangular face are manageable ONLY if there are no Per Wedge attributes
|
2006-01-10 14:20:42 +01:00
|
|
|
if( ( pi.mask & Mask::IOM_WEDGCOLOR ) || ( pi.mask & Mask::IOM_WEDGTEXCOORD ) )
|
2005-11-12 19:13:30 +01:00
|
|
|
{
|
|
|
|
pi.status = PlyInfo::E_NO_3VERTINFACE;
|
|
|
|
return pi.status;
|
|
|
|
}
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
2007-02-14 16:30:13 +01:00
|
|
|
if(m.HasPerFaceFlags() &&( pi.mask & Mask::IOM_FACEFLAGS) )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
(*fi).UberFlags() = fa.flags;
|
|
|
|
}
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_FACEQUALITY )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2007-02-02 01:29:33 +01:00
|
|
|
(*fi).Q() = (typename OpenMeshType::FaceType::QualityType) fa.q;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_FACECOLOR )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
(*fi).C()[0] = fa.r;
|
|
|
|
(*fi).C()[1] = fa.g;
|
|
|
|
(*fi).C()[2] = fa.b;
|
|
|
|
(*fi).C()[3] = 255;
|
|
|
|
}
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_WEDGTEXCOORD )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
for(int k=0;k<3;++k)
|
|
|
|
{
|
2007-03-12 17:40:17 +01:00
|
|
|
(*fi).WT(k).u() = fa.texcoord[k*2+0];
|
|
|
|
(*fi).WT(k).v() = fa.texcoord[k*2+1];
|
|
|
|
if(multit) (*fi).WT(k).n() = fa.texcoordind;
|
2005-11-25 11:23:27 +01:00
|
|
|
else (*fi).WT(k).n()=0; // safely intialize texture index
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pi.mask & Mask::IOM_WEDGCOLOR )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
if(FaceType::HasWedgeColor()){
|
|
|
|
for(int k=0;k<3;++k)
|
|
|
|
{
|
|
|
|
(*fi).WC(k)[0] = (unsigned char)(fa.colors[k*3+0]*255);
|
|
|
|
(*fi).WC(k)[1] = (unsigned char)(fa.colors[k*3+1]*255);
|
|
|
|
(*fi).WC(k)[2] = (unsigned char)(fa.colors[k*3+2]*255);
|
|
|
|
}
|
|
|
|
}
|
2006-05-16 17:01:30 +02:00
|
|
|
//if(FaceType::HasFaceColor()){
|
|
|
|
if(pi.mask & Mask::IOM_FACECOLOR){
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
(*fi).C()[0] = (unsigned char)((fa.colors[0*3+0]*255+fa.colors[1*3+0]*255+fa.colors[2*3+0]*255)/3.0f);
|
|
|
|
(*fi).C()[1] = (unsigned char)((fa.colors[0*3+1]*255+fa.colors[1*3+1]*255+fa.colors[2*3+1]*255)/3.0f);
|
|
|
|
(*fi).C()[2] = (unsigned char)((fa.colors[0*3+2]*255+fa.colors[1*3+2]*255+fa.colors[2*3+2]*255)/3.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-12 19:13:30 +01:00
|
|
|
/// Now the temporary struct 'fa' is ready to be copied into the real face '*fi'
|
|
|
|
/// This loop
|
|
|
|
for(k=0;k<3;++k)
|
|
|
|
{
|
|
|
|
if( fa.v[k]<0 || fa.v[k]>=m.vn )
|
|
|
|
{
|
|
|
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
|
|
|
return pi.status;
|
|
|
|
}
|
|
|
|
(*fi).V(k) = index[ fa.v[k] ];
|
|
|
|
}
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
for(k=0;k<pi.fdn;k++)
|
|
|
|
memcpy((char *)(&(*fi)) + pi.FaceData[k].offset1,
|
|
|
|
(char *)(&fa) + FPV[k].offset1,
|
|
|
|
FPV[k].memtypesize());
|
2005-11-12 19:13:30 +01:00
|
|
|
++fi;
|
|
|
|
|
|
|
|
// Non Triangular Faces Loop
|
|
|
|
// It performs a simple fan triangulation.
|
|
|
|
if(fa.size>3)
|
|
|
|
{
|
|
|
|
int curpos=int(fi-m.face.begin());
|
|
|
|
Allocator<OpenMeshType>::AddFaces(m,fa.size-3);
|
|
|
|
fi=m.face.begin()+curpos;
|
|
|
|
}
|
|
|
|
for(int qq=0;qq<fa.size-3;++qq)
|
|
|
|
{
|
|
|
|
(*fi).V(0) = index[ fa.v[0] ];
|
|
|
|
for(k=1;k<3;++k)
|
|
|
|
{
|
|
|
|
if( fa.v[2+qq]<0 || fa.v[2+qq]>=m.vn )
|
|
|
|
{
|
|
|
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
|
|
|
return pi.status;
|
|
|
|
}
|
|
|
|
(*fi).V(k) = index[ fa.v[1+qq+k] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
for(k=0;k<pi.fdn;k++)
|
|
|
|
memcpy((char *)(&(*fi)) + pi.FaceData[k].offset1,
|
|
|
|
(char *)(&fa) + FPV[k].offset1, FPV[k].memtypesize());
|
|
|
|
++fi;
|
|
|
|
}
|
|
|
|
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}else if( !strcmp( pf.ElemName(i),"tristrips") )//////////////////// LETTURA TRISTRIP DI STANFORD
|
2007-03-03 03:28:59 +01:00
|
|
|
{
|
|
|
|
// Warning the parsing of tristrips could not work if OCF types are used
|
|
|
|
FaceType tf;
|
|
|
|
if( FaceType::HasFaceQuality() ) tf.Q()=(typename OpenMeshType::FaceType::QualityType)1.0;
|
|
|
|
if( FaceType::HasWedgeColor() ) tf.WC(0)=tf.WC(1)=tf.WC(2)=Color4b(Color4b::White);
|
|
|
|
if( HasPerFaceColor(m) ) tf.C()=Color4b(Color4b::White);
|
|
|
|
|
2004-03-03 16:00:51 +01:00
|
|
|
int j;
|
|
|
|
pf.SetCurElement(i);
|
2005-11-12 19:13:30 +01:00
|
|
|
int numvert_tmp = (int)m.vert.size();
|
2004-03-03 16:00:51 +01:00
|
|
|
for(j=0;j<n;++j)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Tristrip Face Loading");
|
|
|
|
if( pf.Read(&tsa)==-1 )
|
|
|
|
{
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_SHORTFILE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
int remainder=0;
|
2004-04-03 15:30:01 +02:00
|
|
|
//int startface=m.face.size();
|
2004-03-03 16:00:51 +01:00
|
|
|
for(k=0;k<tsa.size-2;++k)
|
|
|
|
{
|
|
|
|
if(pi.cb && (k%1000)==0) pi.cb(50+k*50/tsa.size,"Tristrip Face Loading");
|
|
|
|
if(tsa.v[k]<0 || tsa.v[k]>=numvert_tmp ) {
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
if(tsa.v[k+2]==-1)
|
|
|
|
{
|
|
|
|
k+=2;
|
|
|
|
if(k%2) remainder=0;
|
|
|
|
else remainder=1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tf.V(0) = index[ tsa.v[k+0] ];
|
|
|
|
tf.V(1) = index[ tsa.v[k+1] ];
|
|
|
|
tf.V(2) = index[ tsa.v[k+2] ];
|
2004-06-11 19:09:41 +02:00
|
|
|
if((k+remainder)%2) math::Swap (tf.V(0), tf.V(1) );
|
2004-03-03 16:00:51 +01:00
|
|
|
m.face.push_back( tf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Skippaggio elementi non gestiti
|
|
|
|
int n = pf.ElemNumber(i);
|
|
|
|
pf.SetCurElement(i);
|
|
|
|
|
|
|
|
for(int j=0;j<n;j++)
|
|
|
|
{
|
|
|
|
if( pf.Read(0)==-1)
|
|
|
|
{
|
2004-03-09 22:26:47 +01:00
|
|
|
pi.status = PlyInfo::E_SHORTFILE;
|
2004-06-23 17:36:57 +02:00
|
|
|
return pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-02 01:01:30 +01:00
|
|
|
// Parsing texture names
|
|
|
|
m.textures.clear();
|
|
|
|
m.normalmaps.clear();
|
|
|
|
|
|
|
|
for(int co=0;co<int(pf.comments.size());++co)
|
|
|
|
{
|
2005-12-02 11:04:18 +01:00
|
|
|
std::string TFILE = "TextureFile";
|
|
|
|
std::string NFILE = "TextureNormalFile";
|
|
|
|
std::string &c = pf.comments[co];
|
2006-01-11 11:37:12 +01:00
|
|
|
// char buf[256];
|
2005-12-02 11:04:18 +01:00
|
|
|
std::string bufstr,bufclean;
|
2006-01-11 11:37:12 +01:00
|
|
|
int i,n;
|
2005-12-02 01:01:30 +01:00
|
|
|
|
|
|
|
if( TFILE == c.substr(0,TFILE.length()) )
|
|
|
|
{
|
|
|
|
bufstr = c.substr(TFILE.length()+1);
|
2006-02-03 10:46:24 +01:00
|
|
|
n = static_cast<int>(bufstr.length());
|
2005-12-02 01:01:30 +01:00
|
|
|
for(i=0;i<n;i++)
|
|
|
|
if( bufstr[i]!=' ' && bufstr[i]!='\t' && bufstr[i]>32 && bufstr[i]<125 ) bufclean.push_back(bufstr[i]);
|
|
|
|
|
|
|
|
char buf2[255];
|
|
|
|
ply::interpret_texture_name( bufclean.c_str(),filename,buf2 );
|
2005-12-02 11:04:18 +01:00
|
|
|
m.textures.push_back( std::string(buf2) );
|
2005-12-02 01:01:30 +01:00
|
|
|
}
|
|
|
|
/*if( !strncmp(c,NFILE,strlen(NFILE)) )
|
|
|
|
{
|
|
|
|
strcpy(buf,c+strlen(NFILE)+1);
|
|
|
|
n = strlen(buf);
|
|
|
|
for(i=j=0;i<n;i++)
|
|
|
|
if( buf[i]!=' ' && buf[i]!='\t' && buf[i]>32 && buf[i]<125 ) buf[j++] = buf[i];
|
|
|
|
|
|
|
|
buf[j] = 0;
|
|
|
|
char buf2[255];
|
|
|
|
__interpret_texture_name( buf,filename,buf2 );
|
|
|
|
m.normalmaps.push_back( string(buf2) );
|
|
|
|
}*/
|
|
|
|
}
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
// vn and fn should be correct but if someone wrongly saved some deleted elements they can be wrong.
|
|
|
|
m.vn = 0;
|
|
|
|
VertexIterator vi;
|
|
|
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
|
|
if( ! (*vi).IsD() )
|
|
|
|
++m.vn;
|
|
|
|
|
|
|
|
m.fn = 0;
|
|
|
|
FaceIterator fi;
|
|
|
|
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
|
|
|
if( ! (*fi).IsD() )
|
|
|
|
++m.fn;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Caricamento camera da un ply
|
|
|
|
int LoadCamera(const char * filename)
|
|
|
|
{
|
2004-05-12 12:19:30 +02:00
|
|
|
vcg::ply::PlyFile pf;
|
|
|
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2005-04-14 17:09:38 +02:00
|
|
|
this->pi.status = pf.GetError();
|
|
|
|
return this->pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool found = true;
|
|
|
|
int i;
|
|
|
|
for(i=0;i<23;++i)
|
|
|
|
{
|
|
|
|
if( pf.AddToRead(CameraDesc(i))==-1 )
|
|
|
|
{
|
|
|
|
found = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!found)
|
2005-04-14 17:09:38 +02:00
|
|
|
return this->pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
for(i=0;i<int(pf.elements.size());i++)
|
|
|
|
{
|
|
|
|
int n = pf.ElemNumber(i);
|
|
|
|
|
|
|
|
if( !strcmp( pf.ElemName(i),"camera" ) )
|
|
|
|
{
|
|
|
|
pf.SetCurElement(i);
|
|
|
|
|
|
|
|
LoadPly_Camera ca;
|
|
|
|
|
|
|
|
for(int j=0;j<n;++j)
|
|
|
|
{
|
|
|
|
if( pf.Read( (void *)&(ca) )==-1 )
|
|
|
|
{
|
2005-04-14 17:09:38 +02:00
|
|
|
this->pi.status = PlyInfo::E_SHORTFILE;
|
|
|
|
return this->pi.status;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
2005-04-14 17:09:38 +02:00
|
|
|
this->camera.valid = true;
|
|
|
|
this->camera.view_p[0] = ca.view_px;
|
|
|
|
this->camera.view_p[1] = ca.view_py;
|
|
|
|
this->camera.view_p[2] = ca.view_pz;
|
|
|
|
this->camera.x_axis[0] = ca.x_axisx;
|
|
|
|
this->camera.x_axis[1] = ca.x_axisy;
|
|
|
|
this->camera.x_axis[2] = ca.x_axisz;
|
|
|
|
this->camera.y_axis[0] = ca.y_axisx;
|
|
|
|
this->camera.y_axis[1] = ca.y_axisy;
|
|
|
|
this->camera.y_axis[2] = ca.y_axisz;
|
|
|
|
this->camera.z_axis[0] = ca.z_axisx;
|
|
|
|
this->camera.z_axis[1] = ca.z_axisy;
|
|
|
|
this->camera.z_axis[2] = ca.z_axisz;
|
|
|
|
this->camera.f = ca.focal;
|
|
|
|
this->camera.s[0] = ca.scalex;
|
|
|
|
this->camera.s[1] = ca.scaley;
|
|
|
|
this->camera.c[0] = ca.centerx;
|
|
|
|
this->camera.c[1] = ca.centery;
|
|
|
|
this->camera.viewport[0] = ca.viewportx;
|
|
|
|
this->camera.viewport[1] = ca.viewporty;
|
|
|
|
this->camera.k[0] = ca.k1;
|
|
|
|
this->camera.k[1] = ca.k2;
|
|
|
|
this->camera.k[2] = ca.k3;
|
|
|
|
this->camera.k[3] = ca.k4;
|
2004-03-03 16:00:51 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-14 17:09:56 +02:00
|
|
|
static bool LoadMask(const char * filename, int &mask)
|
|
|
|
{
|
|
|
|
PlyInfo pi;
|
|
|
|
return LoadMask(filename, mask,pi);
|
|
|
|
}
|
|
|
|
static bool LoadMask(const char * filename, int &mask, PlyInfo &pi)
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
|
|
|
mask=0;
|
2004-05-12 12:19:30 +02:00
|
|
|
vcg::ply::PlyFile pf;
|
|
|
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
2004-03-03 16:00:51 +01:00
|
|
|
{
|
2005-10-14 17:09:56 +02:00
|
|
|
pi.status = pf.GetError();
|
2004-03-03 16:00:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pf.AddToRead(VertDesc(0))!=-1 &&
|
|
|
|
pf.AddToRead(VertDesc(1))!=-1 &&
|
2006-01-10 14:20:42 +01:00
|
|
|
pf.AddToRead(VertDesc(2))!=-1 ) mask |= Mask::IOM_VERTCOORD;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pf.AddToRead(VertDesc(3))!=-1 ) mask |= Mask::IOM_VERTFLAGS;
|
|
|
|
if( pf.AddToRead(VertDesc(4))!=-1 ) mask |= Mask::IOM_VERTQUALITY;
|
2006-05-03 23:21:21 +02:00
|
|
|
if( pf.AddToRead(VertDesc(11))!=-1 ) mask |= Mask::IOM_VERTQUALITY;
|
2004-03-03 16:00:51 +01:00
|
|
|
if( ( pf.AddToRead(VertDesc(5))!=-1 ) &&
|
|
|
|
( pf.AddToRead(VertDesc(6))!=-1 ) &&
|
2006-01-10 14:20:42 +01:00
|
|
|
( pf.AddToRead(VertDesc(7))!=-1 ) ) mask |= Mask::IOM_VERTCOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pf.AddToRead(FaceDesc(0))!=-1 ) mask |= Mask::IOM_FACEINDEX;
|
|
|
|
if( pf.AddToRead(FaceDesc(1))!=-1 ) mask |= Mask::IOM_FACEFLAGS;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
2006-01-10 14:20:42 +01:00
|
|
|
if( pf.AddToRead(FaceDesc(2))!=-1 ) mask |= Mask::IOM_FACEQUALITY;
|
|
|
|
if( pf.AddToRead(FaceDesc(3))!=-1 ) mask |= Mask::IOM_WEDGTEXCOORD;
|
|
|
|
if( pf.AddToRead(FaceDesc(5))!=-1 ) mask |= Mask::IOM_WEDGTEXMULTI;
|
|
|
|
if( pf.AddToRead(FaceDesc(4))!=-1 ) mask |= Mask::IOM_WEDGCOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
if( ( pf.AddToRead(FaceDesc(6))!=-1 ) &&
|
|
|
|
( pf.AddToRead(FaceDesc(7))!=-1 ) &&
|
2006-01-10 14:20:42 +01:00
|
|
|
( pf.AddToRead(FaceDesc(8))!=-1 ) ) mask |= Mask::IOM_FACECOLOR;
|
2004-03-03 16:00:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}; // end class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace tri
|
|
|
|
} // end namespace io
|
|
|
|
} // end namespace vcg
|
2004-05-04 04:36:07 +02:00
|
|
|
|
2004-05-12 12:19:30 +02:00
|
|
|
#endif
|