Added support of polylines (edges) in PLY support. Used the format suggested in the web description of the ply format ( http://paulbourke.net/dataformats/ply/ )

element edge 5                        { five edges in object }
property int vertex1                  { index to first vertex of edge }
property int vertex2                  { index to second vertex }
This commit is contained in:
Paolo Cignoni 2011-11-07 16:14:46 +00:00
parent 4859aa4d80
commit 010b310cac
3 changed files with 71 additions and 6 deletions

View File

@ -172,6 +172,7 @@ typedef typename SaveMeshType::FaceType FaceType;
typedef typename SaveMeshType::FacePointer FacePointer; typedef typename SaveMeshType::FacePointer FacePointer;
typedef typename SaveMeshType::VertexIterator VertexIterator; typedef typename SaveMeshType::VertexIterator VertexIterator;
typedef typename SaveMeshType::FaceIterator FaceIterator; typedef typename SaveMeshType::FaceIterator FaceIterator;
typedef typename SaveMeshType::EdgeIterator EdgeIterator;
static int Save(SaveMeshType &m, const char * filename, bool binary=true) static int Save(SaveMeshType &m, const char * filename, bool binary=true)
{ {
@ -361,7 +362,14 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p
for(i=0;i<pi.fdn;i++) for(i=0;i<pi.fdn;i++)
fprintf(fpout,"property %s %s\n",pi.FaceData[i].stotypename(),pi.FaceData[i].propname); fprintf(fpout,"property %s %s\n",pi.FaceData[i].stotypename(),pi.FaceData[i].propname);
// Saving of edges
if(m.en>0)
fprintf(fpout,
"element edge %d\n"
"property int vertex1\n"
"property int vertex2\n"
,m.en
);
fprintf(fpout, "end_header\n" ); fprintf(fpout, "end_header\n" );
// Salvataggio camera // Salvataggio camera
@ -706,6 +714,24 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p
} }
} }
assert(fcnt==m.fn); assert(fcnt==m.fn);
int eauxvv[2];
int ecnt=0;
for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei)
{
if( ! ei->IsD() )
{
++ecnt;
if(binary)
{
eauxvv[0]=indices[ei->cV(0)];
eauxvv[1]=indices[ei->cV(1)];
fwrite(vv,sizeof(int),2,fpout);
}
else // ***** ASCII *****
fprintf(fpout,"%d %d \n", indices[ei->cV(0)], indices[ei->cV(1)]);
}
}
assert(ecnt==m.en);
fclose(fpout); fclose(fpout);
return 0; return 0;
} }

View File

@ -63,6 +63,7 @@ typedef typename OpenMeshType::VertexType VertexType;
typedef typename OpenMeshType::FaceType FaceType; typedef typename OpenMeshType::FaceType FaceType;
typedef typename OpenMeshType::VertexIterator VertexIterator; typedef typename OpenMeshType::VertexIterator VertexIterator;
typedef typename OpenMeshType::FaceIterator FaceIterator; typedef typename OpenMeshType::FaceIterator FaceIterator;
typedef typename OpenMeshType::EdgeIterator EdgeIterator;
//template <class T> int PlyType () { assert(0); return 0;} //template <class T> int PlyType () { assert(0); return 0;}
@ -94,6 +95,11 @@ struct LoadPly_TristripAux
unsigned char data[MAX_USER_DATA]; unsigned char data[MAX_USER_DATA];
}; };
struct LoadPly_EdgeAux
{
int v1,v2;
unsigned char data[MAX_USER_DATA];
};
// Yet another auxiliary data structure for loading some strange ply files // Yet another auxiliary data structure for loading some strange ply files
// the original stanford range data... // the original stanford range data...
@ -228,6 +234,16 @@ static const PropDescriptor &TristripDesc(int i)
return qf[i]; return qf[i];
} }
static const PropDescriptor &EdgeDesc(int i)
{
static const PropDescriptor qf[2]=
{
{"edge","vertex1", ply::T_INT, ply::T_INT, offsetof(LoadPly_EdgeAux,v1), 0,0,0,0,0 ,0},
{"edge","vertex2", ply::T_INT, ply::T_INT, offsetof(LoadPly_EdgeAux,v2), 0,0,0,0,0 ,0},
};
return qf[i];
}
// Descriptor for the Stanford Data Repository Range Maps. // Descriptor for the Stanford Data Repository Range Maps.
// In practice a grid with some invalid elements. Coords are saved only for good elements // In practice a grid with some invalid elements. Coords are saved only for good elements
static const PropDescriptor &RangeDesc(int i) static const PropDescriptor &RangeDesc(int i)
@ -279,7 +295,7 @@ static const char *ErrorMsg(int error)
ply_error_msg[ply::E_NOERROR ]="No errors"; ply_error_msg[ply::E_NOERROR ]="No errors";
ply_error_msg[ply::E_CANTOPEN ]="Can't open file"; ply_error_msg[ply::E_CANTOPEN ]="Can't open file";
ply_error_msg[ply::E_NOTHEADER ]="Header not found"; ply_error_msg[ply::E_NOTHEADER ]="Header not found";
ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header"; ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header";
ply_error_msg[ply::E_NOFORMAT ]="Format not found"; ply_error_msg[ply::E_NOFORMAT ]="Format not found";
ply_error_msg[ply::E_SYNTAX ]="Syntax error on header"; ply_error_msg[ply::E_SYNTAX ]="Syntax error on header";
ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element"; ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element";
@ -339,6 +355,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
assert(filename!=0); assert(filename!=0);
std::vector<VertexPointer> index; std::vector<VertexPointer> index;
LoadPly_FaceAux fa; LoadPly_FaceAux fa;
LoadPly_EdgeAux ea;
LoadPly_TristripAux tsa; LoadPly_TristripAux tsa;
LoadPly_VertAux<ScalarType> va; LoadPly_VertAux<ScalarType> va;
@ -416,9 +433,11 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
} }
// Descrittori facoltativi dei flags // Descrittori facoltativi dei flags
if(pf.AddToRead(EdgeDesc(0) )!= -1 && pf.AddToRead(EdgeDesc(1)) != -1 )
pi.mask |= Mask::IOM_EDGEINDEX;
if(VertexType::HasFlags() && pf.AddToRead(VertDesc(3))!=-1 ) if(VertexType::HasFlags() && pf.AddToRead(VertDesc(3))!=-1 )
pi.mask |= Mask::IOM_VERTFLAGS; pi.mask |= Mask::IOM_VERTFLAGS;
if( VertexType::HasNormal() ) if( VertexType::HasNormal() )
{ {
@ -677,7 +696,25 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
for(j=0,vi=m.vert.begin();j<n;++j,++vi) for(j=0,vi=m.vert.begin();j<n;++j,++vi)
index[j] = &*vi; index[j] = &*vi;
} }
else if( !strcmp( pf.ElemName(i),"face") && (n>0) )/************************************************************/ else if( !strcmp( pf.ElemName(i),"edge") && (n>0) )/******************** EDGE READING *******************************/
{
assert( pi.mask & Mask::IOM_EDGEINDEX );
EdgeIterator ei=Allocator<OpenMeshType>::AddEdges(m,n);
pf.SetCurElement(i);
for(int j=0;j<n;++j)
{
if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Edge Loading");
if( pf.Read(&ea)==-1 )
{
pi.status = PlyInfo::E_SHORTFILE;
return pi.status;
}
(*ei).V(0) = index[ ea.v1 ];
(*ei).V(1) = index[ ea.v2 ];
++ei;
}
}
else if( !strcmp( pf.ElemName(i),"face") && (n>0) )/******************** FACE READING ****************************************/
{ {
int j; int j;

View File

@ -72,7 +72,9 @@ enum {
IOM_VERTQUALITY = 0x00008, IOM_VERTQUALITY = 0x00008,
IOM_VERTNORMAL = 0x00010, IOM_VERTNORMAL = 0x00010,
IOM_VERTTEXCOORD = 0x00020, IOM_VERTTEXCOORD = 0x00020,
IOM_VERTRADIUS = 0x10000, IOM_VERTRADIUS = 0x10000,
IOM_EDGEINDEX = 0x80000,
IOM_FACEINDEX = 0x00040, IOM_FACEINDEX = 0x00040,
IOM_FACEFLAGS = 0x00080, IOM_FACEFLAGS = 0x00080,