- 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::EdgeIterator EdgeIterator;
static char *readline(FILE *fp, int max=100){
static void readline(FILE *fp, char *line, int max=100){
int i=0;
char c, *str = new char[max];
char c;
fscanf(fp, "%c", &c);
while( (c!=10) && (c!=13) && (i<max) ){
str[i++] = c;
while( (c!=10) && (c!=13) && (i<max-1) ){
line[i++] = c;
fscanf(fp, "%c", &c);
}
str[i] = '\0'; //end of string
return str;
line[i] = '\0'; //end of string
}
;
static bool ReadHeader(FILE *fp,unsigned int &num_cams, unsigned int &num_points){
char *line;
line = readline(fp); if( (!line) || (0!=strcmp("# Bundle file v0.3", line)) ) return false;
line = readline(fp); if(!line) return false;
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;
sscanf(line, "%d %d", &num_cams, &num_points);
return true;
}
@ -101,9 +98,9 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
FILE *fp = fopen(filename,"r");
if(!fp) return false;
ReadHeader(fp, num_cams, num_points);
char *line;
char line[100];
ReadImagesFilenames(filename_images,image_filenames);
ReadImagesFilenames(filename_images, image_filenames);
shots.resize(num_cams);
for(int i = 0; i < num_cams;++i)
@ -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};
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;
line = readline(fp); if(!line) 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[0]), &(R[1]), &(R[2])); R[3] = 0;
readline(fp, line); if(line[0]=='\0') 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[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);
@ -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)
{
char line[1000],name[1000];
FILE * fi = fopen(filename,"r");
if (!fi) return false;
FILE * fp = fopen(filename,"r");
if (!fp) return false;
else
{
while(!feof(fi)){
fgets (line , 1000, fi);
sscanf(line,"%s",&name[0]);
char line[1000], name[1000];
while(!feof(fp)){
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);
image_filenames.push_back(n);
}
}
fclose(fi);
fclose(fp);
return true;
}