- debugged importer from Bundler format

This commit is contained in:
Paolo Cignoni 2012-01-15 19:38:58 +00:00
parent 653866c814
commit 880fca974f
1 changed files with 49 additions and 52 deletions

View File

@ -61,24 +61,21 @@ typedef typename OpenMeshType::VertexIterator VertexIterator;
typedef typename OpenMeshType::FaceIterator FaceIterator; typedef typename OpenMeshType::FaceIterator FaceIterator;
typedef typename OpenMeshType::EdgeIterator EdgeIterator; typedef typename OpenMeshType::EdgeIterator EdgeIterator;
static char *readline(FILE *fp, int max=100){ static void readline(FILE *fp, char *line, int max=100){
int i=0; int i=0;
char c, *str = new char[max]; char c;
fscanf(fp, "%c", &c); fscanf(fp, "%c", &c);
while( (c!=10) && (c!=13) && (i<max) ){ while( (c!=10) && (c!=13) && (i<max-1) ){
str[i++] = c; line[i++] = c;
fscanf(fp, "%c", &c); fscanf(fp, "%c", &c);
} }
str[i] = '\0'; //end of string line[i] = '\0'; //end of string
return str;
} }
;
static bool ReadHeader(FILE *fp,unsigned int &num_cams, unsigned int &num_points){ static bool ReadHeader(FILE *fp,unsigned int &num_cams, unsigned int &num_points){
char *line; char line[100];
line = readline(fp); if( (!line) || (0!=strcmp("# Bundle file v0.3", line)) ) return false; readline(fp, line); if( (line[0]=='\0') || (0!=strcmp("# Bundle file v0.3", line)) ) return false;
line = readline(fp); if(!line) return false; readline(fp, line); if(line[0]=='\0') return false;
sscanf(line, "%d %d", &num_cams, &num_points); sscanf(line, "%d %d", &num_cams, &num_points);
return true; return true;
} }
@ -101,7 +98,7 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
FILE *fp = fopen(filename,"r"); FILE *fp = fopen(filename,"r");
if(!fp) return false; if(!fp) return false;
ReadHeader(fp, num_cams, num_points); ReadHeader(fp, num_cams, num_points);
char *line; char line[100];
ReadImagesFilenames(filename_images, image_filenames); ReadImagesFilenames(filename_images, image_filenames);
@ -112,13 +109,13 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
float R[16]={0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1}; float R[16]={0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1};
vcg::Point3f t; vcg::Point3f t;
line = readline(fp); if(!line) return false; sscanf(line, "%f %f %f", &f, &k1, &k2); readline(fp, line); if(line[0]=='\0') return false; sscanf(line, "%f %f %f", &f, &k1, &k2);
line = readline(fp); if(!line) return false; sscanf(line, "%f %f %f", &(R[0]), &(R[1]), &(R[2])); R[3] = 0; readline(fp, line); if(line[0]=='\0') return false; sscanf(line, "%f %f %f", &(R[0]), &(R[1]), &(R[2])); R[3] = 0;
line = readline(fp); if(!line) return false; sscanf(line, "%f %f %f", &(R[4]), &(R[5]), &(R[6])); R[7] = 0; readline(fp, line); if(line[0]=='\0') return false; sscanf(line, "%f %f %f", &(R[4]), &(R[5]), &(R[6])); R[7] = 0;
line = readline(fp); if(!line) return false; sscanf(line, "%f %f %f", &(R[8]), &(R[9]), &(R[10])); R[11] = 0; readline(fp, line); if(line[0]=='\0') return false; sscanf(line, "%f %f %f", &(R[8]), &(R[9]), &(R[10])); R[11] = 0;
line = readline(fp); if(!line) return false; sscanf(line, "%f %f %f", &(t[0]), &(t[1]), &(t[2])); readline(fp, line); if(line[0]=='\0') return false; sscanf(line, "%f %f %f", &(t[0]), &(t[1]), &(t[2]));
vcg::Matrix44f mat = vcg::Matrix44<vcg::Shotf::ScalarType>::Construct<float>(R); vcg::Matrix44f mat = vcg::Matrix44<vcg::Shotf::ScalarType>::Construct<float>(R);
@ -173,20 +170,20 @@ static int Open( OpenMeshType &m, std::vector<Shot<typename OpenMeshType::Scalar
static bool ReadImagesFilenames(const char * filename,std::vector<std::string> &image_filenames) static bool ReadImagesFilenames(const char * filename,std::vector<std::string> &image_filenames)
{ {
char line[1000],name[1000]; FILE * fp = fopen(filename,"r");
if (!fp) return false;
FILE * fi = fopen(filename,"r");
if (!fi) return false;
else else
{ {
while(!feof(fi)){ char line[1000], name[1000];
fgets (line , 1000, fi); while(!feof(fp)){
sscanf(line,"%s",&name[0]); readline(fp, line, 1000);
if(line[0] == '\0') continue; //ignore empty lines (in theory, might happen only at end of file)
sscanf(line, "%s", name);
std::string n(name); std::string n(name);
image_filenames.push_back(n); image_filenames.push_back(n);
} }
} }
fclose(fi); fclose(fp);
return true; return true;
} }