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.
This commit is contained in:
parent
35e423a642
commit
ed7382539c
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.7 2004/06/11 17:09:41 ganovelli
|
||||||
|
inclusion of vector..minorchanges
|
||||||
|
|
||||||
Revision 1.6 2004/05/28 14:11:13 ganovelli
|
Revision 1.6 2004/05/28 14:11:13 ganovelli
|
||||||
changes to comply io_mask moving in vcg::ply namesp
|
changes to comply io_mask moving in vcg::ply namesp
|
||||||
|
|
||||||
|
@ -228,6 +231,36 @@ static const PropDescriptor &CameraDesc(int i)
|
||||||
};
|
};
|
||||||
return cad[i];
|
return cad[i];
|
||||||
}
|
}
|
||||||
|
/// Standard call for knowing the meaning of an error code
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
|
{
|
||||||
|
const char * ply_error_msg[] =
|
||||||
|
{
|
||||||
|
"No errors",
|
||||||
|
"Can't open file",
|
||||||
|
"Header not found",
|
||||||
|
"Eof in header",
|
||||||
|
"Format not found",
|
||||||
|
"Syntax error on header",
|
||||||
|
"Property without element",
|
||||||
|
"Bad type name",
|
||||||
|
"Element not found",
|
||||||
|
"Property not found",
|
||||||
|
"Bad type on addtoread",
|
||||||
|
"Incompatible type",
|
||||||
|
"Bad cast",
|
||||||
|
"No vertex field found",
|
||||||
|
"No face field found",
|
||||||
|
"Unespected eof",
|
||||||
|
"Face with more than 3 vertices",
|
||||||
|
"Bad vertex index in face",
|
||||||
|
"Face with no 6 texture coordinates",
|
||||||
|
"Number of color differ from vertices"
|
||||||
|
};
|
||||||
|
|
||||||
|
if(error>PlyInfo::E_MAXPLYINFOERRORS || error<0) return "Unknown error";
|
||||||
|
else return ply_error_msg[error];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Standard call for reading a mesh
|
/// Standard call for reading a mesh
|
||||||
|
@ -287,7 +320,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||||
{
|
{
|
||||||
pi.status = pf.GetError();
|
pi.status = pf.GetError();
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
pi.header = pf.GetHeader();
|
pi.header = pf.GetHeader();
|
||||||
|
|
||||||
|
@ -305,13 +338,13 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Descrittori dati standard (vertex coord e faces)
|
// Descrittori dati standard (vertex coord e faces)
|
||||||
if( pf.AddToRead(VertDesc(0))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
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 -1; }
|
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 -1; }
|
if( pf.AddToRead(VertDesc(2))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return pi.status; }
|
||||||
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(0))==-1 ) // Se fallisce si prova anche la sintassi di rapidform con index al posto di indices
|
||||||
if( pf.AddToRead(FaceDesc(9))==-1 )
|
if( pf.AddToRead(FaceDesc(9))==-1 )
|
||||||
if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy.
|
if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy.
|
||||||
{ pi.status = PlyInfo::E_NO_FACE; return -1; }
|
{ pi.status = PlyInfo::E_NO_FACE; return pi.status; }
|
||||||
|
|
||||||
// Descrittori facoltativi dei flags
|
// Descrittori facoltativi dei flags
|
||||||
if( pf.AddToRead(VertDesc(3))!=-1 )
|
if( pf.AddToRead(VertDesc(3))!=-1 )
|
||||||
|
@ -385,12 +418,12 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
VPV[i] = pi.VertexData[i];
|
VPV[i] = pi.VertexData[i];
|
||||||
VPV[i].offset1=offsetof(LoadPly_VertAux<ScalarType>,data)+totsz;
|
VPV[i].offset1=offsetof(LoadPly_VertAux<ScalarType>,data)+totsz;
|
||||||
totsz+=pi.VertexData[i].memtypesize();
|
totsz+=pi.VertexData[i].memtypesize();
|
||||||
if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return -1; }
|
if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return pi.status; }
|
||||||
}
|
}
|
||||||
if(totsz > MAX_USER_DATA)
|
if(totsz > MAX_USER_DATA)
|
||||||
{
|
{
|
||||||
pi.status = vcg::ply::E_BADTYPE;
|
pi.status = vcg::ply::E_BADTYPE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(pi.fdn>0){
|
if(pi.fdn>0){
|
||||||
|
@ -399,12 +432,12 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
FPV[i] = pi.FaceData[i];
|
FPV[i] = pi.FaceData[i];
|
||||||
FPV[i].offset1=offsetof(LoadPly_FaceAux,data)+totsz;
|
FPV[i].offset1=offsetof(LoadPly_FaceAux,data)+totsz;
|
||||||
totsz+=pi.FaceData[i].memtypesize();
|
totsz+=pi.FaceData[i].memtypesize();
|
||||||
if( pf.AddToRead(FPV[i])==-1 ) { pi.status = pf.GetError(); return -1; }
|
if( pf.AddToRead(FPV[i])==-1 ) { pi.status = pf.GetError(); return pi.status; }
|
||||||
}
|
}
|
||||||
if(totsz > MAX_USER_DATA)
|
if(totsz > MAX_USER_DATA)
|
||||||
{
|
{
|
||||||
pi.status = vcg::ply::E_BADTYPE;
|
pi.status = vcg::ply::E_BADTYPE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +460,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Read( (void *)&(ca) )==-1 )
|
if( pf.Read( (void *)&(ca) )==-1 )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
//camera.valid = true;
|
//camera.valid = true;
|
||||||
//camera.view_p[0] = ca.view_px;
|
//camera.view_p[0] = ca.view_px;
|
||||||
|
@ -469,7 +502,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Read( (void *)&(va) )==-1 )
|
if( pf.Read( (void *)&(va) )==-1 )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*vi).P()[0] = va.p[0];
|
(*vi).P()[0] = va.p[0];
|
||||||
|
@ -517,12 +550,12 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Read(&fa)==-1 )
|
if( pf.Read(&fa)==-1 )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
if(fa.size!=3)
|
if(fa.size!=3)
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_NO_3VERTINFACE;
|
pi.status = PlyInfo::E_NO_3VERTINFACE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(k=0;k<3;++k)
|
for(k=0;k<3;++k)
|
||||||
|
@ -530,7 +563,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( fa.v[k]<0 || fa.v[k]>=m.vn )
|
if( fa.v[k]<0 || fa.v[k]>=m.vn )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
(*fi).V(k) = index[ fa.v[k] ];
|
(*fi).V(k) = index[ fa.v[k] ];
|
||||||
}
|
}
|
||||||
|
@ -600,7 +633,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Read(&tsa)==-1 )
|
if( pf.Read(&tsa)==-1 )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
int remainder=0;
|
int remainder=0;
|
||||||
//int startface=m.face.size();
|
//int startface=m.face.size();
|
||||||
|
@ -609,7 +642,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if(pi.cb && (k%1000)==0) pi.cb(50+k*50/tsa.size,"Tristrip Face Loading");
|
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 ) {
|
if(tsa.v[k]<0 || tsa.v[k]>=numvert_tmp ) {
|
||||||
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
if(tsa.v[k+2]==-1)
|
if(tsa.v[k+2]==-1)
|
||||||
{
|
{
|
||||||
|
@ -637,7 +670,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
if( pf.Read(0)==-1)
|
if( pf.Read(0)==-1)
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,7 +738,7 @@ int LoadCamera(const char * filename)
|
||||||
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||||
{
|
{
|
||||||
pi.status = pf.GetError();
|
pi.status = pf.GetError();
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -721,7 +754,7 @@ int LoadCamera(const char * filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found)
|
if(!found)
|
||||||
return -1;
|
return pi.status;
|
||||||
|
|
||||||
for(i=0;i<int(pf.elements.size());i++)
|
for(i=0;i<int(pf.elements.size());i++)
|
||||||
{
|
{
|
||||||
|
@ -738,7 +771,7 @@ int LoadCamera(const char * filename)
|
||||||
if( pf.Read( (void *)&(ca) )==-1 )
|
if( pf.Read( (void *)&(ca) )==-1 )
|
||||||
{
|
{
|
||||||
pi.status = PlyInfo::E_SHORTFILE;
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
return -1;
|
return pi.status;
|
||||||
}
|
}
|
||||||
camera.valid = true;
|
camera.valid = true;
|
||||||
camera.view_p[0] = ca.view_px;
|
camera.view_p[0] = ca.view_px;
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.4 2004/03/18 15:30:57 cignoni
|
||||||
|
Removed float/double warning
|
||||||
|
|
||||||
Revision 1.3 2004/03/12 21:42:52 cignoni
|
Revision 1.3 2004/03/12 21:42:52 cignoni
|
||||||
First working version!
|
First working version!
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ namespace io {
|
||||||
/**
|
/**
|
||||||
This class encapsulate a filter for importing stl (stereolitograpy) meshes.
|
This class encapsulate a filter for importing stl (stereolitograpy) meshes.
|
||||||
The stl format is quite simple and rather un-flexible. It just stores, in ascii or binary the, unindexed, geometry of the faces.
|
The stl format is quite simple and rather un-flexible. It just stores, in ascii or binary the, unindexed, geometry of the faces.
|
||||||
warning this code assume little endian (PC) architecture!!!
|
Warning: this code assume little endian (PC) architecture!!!
|
||||||
*/
|
*/
|
||||||
template <class OpenMeshType>
|
template <class OpenMeshType>
|
||||||
class ImporterSTL
|
class ImporterSTL
|
||||||
|
@ -68,6 +71,26 @@ public:
|
||||||
// short attr;
|
// short attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum STLError {
|
||||||
|
E_NOERROR, // 0
|
||||||
|
// Errori di open
|
||||||
|
E_CANTOPEN, // 1
|
||||||
|
E_UNESPECTEDEOF, // 2
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
|
{
|
||||||
|
static const char * stl_error_msg[] =
|
||||||
|
{
|
||||||
|
"No errors",
|
||||||
|
"Can't open file",
|
||||||
|
"Premature End of file",
|
||||||
|
};
|
||||||
|
|
||||||
|
if(error>2 || error<0) return "Unknown error";
|
||||||
|
else return stl_error_msg[error];
|
||||||
|
};
|
||||||
|
|
||||||
static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -75,7 +98,7 @@ static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if(fp == NULL)
|
if(fp == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return E_CANTOPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find size of file */
|
/* Find size of file */
|
||||||
|
@ -109,7 +132,7 @@ static int OpenBinary( OpenMeshType &m, const char * filename, CallBackPos *cb=0
|
||||||
fp = fopen(filename, "rb");
|
fp = fopen(filename, "rb");
|
||||||
if(fp == NULL)
|
if(fp == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return E_CANTOPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facenum;
|
int facenum;
|
||||||
|
@ -137,7 +160,7 @@ static int OpenBinary( OpenMeshType &m, const char * filename, CallBackPos *cb=0
|
||||||
++fi;
|
++fi;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 1;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,7 +170,7 @@ static int OpenBinary( OpenMeshType &m, const char * filename, CallBackPos *cb=0
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if(fp == NULL)
|
if(fp == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return E_CANTOPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Clear();
|
m.Clear();
|
||||||
|
@ -177,7 +200,7 @@ static int OpenBinary( OpenMeshType &m, const char * filename, CallBackPos *cb=0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 1;
|
return E_NOERROR;
|
||||||
}
|
}
|
||||||
}; // end class
|
}; // end class
|
||||||
} // end Namespace tri
|
} // end Namespace tri
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2004/05/12 10:19:30 ganovelli
|
||||||
|
new line added at the end of file
|
||||||
|
|
||||||
Revision 1.2 2004/03/09 21:26:47 cignoni
|
Revision 1.2 2004/03/09 21:26:47 cignoni
|
||||||
cr lf mismatch
|
cr lf mismatch
|
||||||
|
|
||||||
|
@ -94,13 +97,14 @@ public:
|
||||||
enum Error
|
enum Error
|
||||||
{
|
{
|
||||||
// Funzioni superiori
|
// Funzioni superiori
|
||||||
E_NO_VERTEX, // 14
|
E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 14
|
||||||
E_NO_FACE, // 15
|
E_NO_FACE = ply::E_MAXPLYERRORS+2, // 15
|
||||||
E_SHORTFILE, // 16
|
E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 16
|
||||||
E_NO_3VERTINFACE, // 17
|
E_NO_3VERTINFACE = ply::E_MAXPLYERRORS+4, // 17
|
||||||
E_BAD_VERT_INDEX, // 18
|
E_BAD_VERT_INDEX = ply::E_MAXPLYERRORS+5, // 18
|
||||||
E_NO_6TCOORD, // 19
|
E_NO_6TCOORD = ply::E_MAXPLYERRORS+6, // 19
|
||||||
E_DIFFER_COLORS, // 20
|
E_DIFFER_COLORS = ply::E_MAXPLYERRORS+7,
|
||||||
|
E_MAXPLYINFOERRORS= ply::E_MAXPLYERRORS+8// 20
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // end class
|
}; // end class
|
||||||
|
|
|
@ -31,6 +31,9 @@ of Greg Turk and on the work of Claudio Rocchini
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.5 2004/06/23 00:06:45 ponchio
|
||||||
|
Moved #define LITTLE_MACHINE outside of #ifdef WIN32 (linux on PC is little too).
|
||||||
|
|
||||||
Revision 1.4 2004/05/12 17:21:08 ganovelli
|
Revision 1.4 2004/05/12 17:21:08 ganovelli
|
||||||
inclusion of io.h removed (unnecessary)
|
inclusion of io.h removed (unnecessary)
|
||||||
|
|
||||||
|
@ -120,29 +123,6 @@ const char * cachedir = "vcg_cache";
|
||||||
const char * bboxcacheext = ".bbox_cache";
|
const char * bboxcacheext = ".bbox_cache";
|
||||||
const char * bboxheader = "BBOXCACH";
|
const char * bboxheader = "BBOXCACH";
|
||||||
|
|
||||||
const char * ply_error_msg[] =
|
|
||||||
{
|
|
||||||
"No errors",
|
|
||||||
"Can't open file",
|
|
||||||
"Header not found",
|
|
||||||
"Eof in header",
|
|
||||||
"Format not found",
|
|
||||||
"Syntax error on header",
|
|
||||||
"Property without element",
|
|
||||||
"Bad type name",
|
|
||||||
"Element not found",
|
|
||||||
"Property not found",
|
|
||||||
"Bad type on addtoread",
|
|
||||||
"Incompatible type",
|
|
||||||
"Bad cast",
|
|
||||||
"No vertex field found",
|
|
||||||
"No face field found",
|
|
||||||
"Unespected eof",
|
|
||||||
"Face with more than 3 vertices",
|
|
||||||
"Bad vertex index in face",
|
|
||||||
"Face with no 6 texture coordinates",
|
|
||||||
"Number of color differ from vertices"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue