added possibility of skipping header
This commit is contained in:
parent
1a4c19c69f
commit
90d7a087bc
|
@ -86,12 +86,13 @@ static const char *ErrorMsg(int error)
|
||||||
* \param lineskip number of lines to be skipped at the begin of the file
|
* \param lineskip number of lines to be skipped at the begin of the file
|
||||||
* \return the operation result
|
* \return the operation result
|
||||||
*/
|
*/
|
||||||
static int Open( MESH_TYPE &m, const char * filename, CallBackPos *cb=0,bool triangulate=false)
|
static int Open( MESH_TYPE &m, const char * filename, CallBackPos *cb=0, bool triangulate=false, int lineskip=0)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if(fp == NULL)
|
if(fp == NULL)
|
||||||
{
|
{
|
||||||
|
qDebug("Failed opening of %s",filename);
|
||||||
return E_CANTOPEN;
|
return E_CANTOPEN;
|
||||||
}
|
}
|
||||||
long currentPos = ftell(fp);
|
long currentPos = ftell(fp);
|
||||||
|
@ -106,6 +107,11 @@ static int Open( MESH_TYPE &m, const char * filename, CallBackPos *cb=0,bool tri
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
int ret;
|
int ret;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
// skip the first <lineskip> lines
|
||||||
|
for(int i=0;i<lineskip;++i)
|
||||||
|
fgets(buf,1024,fp);
|
||||||
|
|
||||||
/* Read a single facet from an ASCII .STL file */
|
/* Read a single facet from an ASCII .STL file */
|
||||||
while(!feof(fp))
|
while(!feof(fp))
|
||||||
{
|
{
|
||||||
|
@ -113,11 +119,13 @@ static int Open( MESH_TYPE &m, const char * filename, CallBackPos *cb=0,bool tri
|
||||||
if(feof(fp)) break;
|
if(feof(fp)) break;
|
||||||
fgets(buf,1024,fp);
|
fgets(buf,1024,fp);
|
||||||
ret=sscanf(buf, "%f, %f, %f, %f\n", &pp.X(), &pp.Y(), &pp.Z(),&q);
|
ret=sscanf(buf, "%f, %f, %f, %f\n", &pp.X(), &pp.Y(), &pp.Z(),&q);
|
||||||
if(ret<3) return E_UNESPECTEDEOF;
|
if(ret>=3)
|
||||||
|
{
|
||||||
VertexIterator vi=Allocator<MESH_TYPE>::AddVertices(m,1);
|
VertexIterator vi=Allocator<MESH_TYPE>::AddVertices(m,1);
|
||||||
(*vi).P().Import(pp);
|
(*vi).P().Import(pp);
|
||||||
if(ret==4) (*vi).Q()=q;
|
if(ret==4) (*vi).Q()=q;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if(!triangulate) return E_NOERROR;
|
if(!triangulate) return E_NOERROR;
|
||||||
|
|
Loading…
Reference in New Issue