fixed string-related bugs in reading file images

This commit is contained in:
ganovelli 2014-04-28 15:37:36 +00:00
parent 115bb8a701
commit d88a1f9772
1 changed files with 7 additions and 10 deletions

View File

@ -69,20 +69,17 @@ typedef typename OpenMeshType::FaceIterator FaceIterator;
typedef typename OpenMeshType::EdgeIterator EdgeIterator;
static void readline(FILE *fp, char *line, int max=100){
int i=0;
char c;
fscanf(fp, "%c", &c);
while( (c!=10) && (c!=13) && (i<max-1) ){
line[i++] = c;
fscanf(fp, "%c", &c);
}
line[i] = '\0'; //end of string
fgets ( line, max, fp);
}
static bool ReadHeader(FILE *fp,unsigned int &num_cams, unsigned int &num_points){
char line[100];
readline(fp, line); if( (line[0]=='\0') || (0!=strcmp("# Bundle file v0.3", line)) ) return false;
readline(fp, line); if(line[0]=='\0') return false;
readline(fp, line);
if( (line[0]=='\0') ) return false;
line[18]='\0';
if(0!=strcmp("# Bundle file v0.3", line)) return false;
readline(fp, line);
if(line[0]=='\0') return false;
sscanf(line, "%d %d", &num_cams, &num_points);
return true;
}