diff --git a/wrap/io_trimesh/import_raw.h b/wrap/io_trimesh/import_raw.h index 246cd45c..84c74c93 100644 --- a/wrap/io_trimesh/import_raw.h +++ b/wrap/io_trimesh/import_raw.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2005/05/06 13:58:26 callieri +First working version (callieri) + ****************************************************************************/ @@ -60,11 +63,15 @@ typedef typename MESH_TYPE::FaceIterator FaceIterator; enum RAWError { E_NOERROR, // 0 - // Errori di open + // Error open E_CANTOPEN, // 1 E_UNESPECTEDEOF, // 2 - // errore line descriptor - E_INVALIDLINEDESC // 3 + // error line descriptor + E_INVALIDLINEDESC, // 3 + // error line parsing + E_LINEERROR, // 4 + // wrong number of points + E_WRONGPOINTNUM // 5 }; static const char *ErrorMsg(int error) @@ -75,6 +82,8 @@ static const char *ErrorMsg(int error) "Can't open file", "Premature End of file", "Invalid line Descriptor", + "Error parsing a line", + "Point number different from expected" }; if(error>2 || error<0) return "Unknown error"; @@ -169,6 +178,68 @@ static void Skipline(FILE *fp) fread(&(buf),sizeof(char),1,fp); } +// function to parse the line read from the raw file +// all characters besides numerals,dot,minus,plus +// if e is found between numbers it's ketpt (12e4) +static int Parseline(int tokennumber, int *tokenorder, char *rawline, float *linebuffer) +{ + int linelen; + int ii; + bool change; + int foundtok; + + // length + linelen = strlen(rawline); + + // cleaning the line + for(ii=0;ii<(linelen-1);) + { + change = true; + + if(isdigit(rawline[ii])) // is a number + change = false; + else if(rawline[ii]==' ') // is a space + change = false; + else if((rawline[ii]=='-') || (rawline[ii]=='+') || (rawline[ii]=='-') || (rawline[ii]=='.')) // is + - . + change = false; + else if(rawline[ii]=='e') // is e... is perhaps an exponential ? + { + if((ii>0) || (ii<(linelen-2))) // if it's at the begin or the end of line, it's not an exponential + if(isdigit(rawline[ii-1])) // a number before it + if(isdigit(rawline[ii+1]) || (rawline[ii+1]=='+') || (rawline[ii+1]=='-')) // after it a number a plus or a minus + change = false; + } + + if(change) + rawline[ii++] = ' '; // then change it to ' ' + else + ii++; + + } + rawline[linelen] = '\0'; + + // now parsing the line + foundtok = 0; + ii = 0; + while((foundtok0) // empty line, just skip { - nv.N()[0] = linebuffer[3]; nv.N()[1] = linebuffer[4]; nv.N()[2] = linebuffer[5]; - } - // store the color - if(m.HasPerVertexColor()) - { - nv.C()[0] = linebuffer[6]; nv.C()[1] = linebuffer[7]; nv.C()[2] = linebuffer[8]; - } + ret = Parseline(tokennumber, tokenorder, rawline, linebuffer); + if(ret) + return ret; - // store the reflectance - if(m.HasPerVertexQuality()) - { - nv.Q() = linebuffer[9]; - } + /* + // old code reading directly fom file stream + for(ii=0; ii::AddFaces(m,trinum); + + m.fn = 0; + for(rr=0; rr