vcg/wrap/import_out.h uses easyexif lib, small typo corrected in alnParser

This commit is contained in:
alemuntoni 2020-09-23 13:07:03 +02:00
parent f38172157a
commit dd8c26474d
2 changed files with 190 additions and 169 deletions

View File

@ -36,7 +36,7 @@ struct RangeMap
} }
std::string filename; std::string filename;
Matrix44m trasformation; Matrix44m transformation;
float quality; float quality;
}; };
@ -66,7 +66,7 @@ public:
{ {
(*rm).filename = (*it); (*rm).filename = (*it);
(*rm).quality = 1.0f; (*rm).quality = 1.0f;
(*rm).trasformation.SetIdentity(); (*rm).transformation.SetIdentity();
} }
files.clear(); files.clear();
return NoError; return NoError;
@ -106,10 +106,10 @@ public:
rm.quality = (float) atof(occurrence+2); rm.quality = (float) atof(occurrence+2);
assert(rm.quality>0); assert(rm.quality>0);
fscanf(stream,"%f %f %f %f \n",&(rm.trasformation[0][0]),&(rm.trasformation[0][1]),&(rm.trasformation[0][2]),&(rm.trasformation[0][3])); fscanf(stream,"%f %f %f %f \n",&(rm.transformation[0][0]),&(rm.transformation[0][1]),&(rm.transformation[0][2]),&(rm.transformation[0][3]));
fscanf(stream,"%f %f %f %f \n",&(rm.trasformation[1][0]),&(rm.trasformation[1][1]),&(rm.trasformation[1][2]),&(rm.trasformation[1][3])); fscanf(stream,"%f %f %f %f \n",&(rm.transformation[1][0]),&(rm.transformation[1][1]),&(rm.transformation[1][2]),&(rm.transformation[1][3]));
fscanf(stream,"%f %f %f %f \n",&(rm.trasformation[2][0]),&(rm.trasformation[2][1]),&(rm.trasformation[2][2]),&(rm.trasformation[2][3])); fscanf(stream,"%f %f %f %f \n",&(rm.transformation[2][0]),&(rm.transformation[2][1]),&(rm.transformation[2][2]),&(rm.transformation[2][3]));
fscanf(stream,"%f %f %f %f \n",&(rm.trasformation[3][0]),&(rm.trasformation[3][1]),&(rm.trasformation[3][2]),&(rm.trasformation[3][3])); fscanf(stream,"%f %f %f %f \n",&(rm.transformation[3][0]),&(rm.transformation[3][1]),&(rm.transformation[3][2]),&(rm.transformation[3][3]));
rangemaps.push_back(rm); rangemaps.push_back(rm);
} }

View File

@ -31,26 +31,21 @@
#include <wrap/callback.h> #include <wrap/callback.h>
#include <wrap/io_trimesh/io_mask.h> #include <wrap/io_trimesh/io_mask.h>
#include <QImageReader> #include <QImageReader>
#include <QFileInfo>
extern "C" #include <exif.h> //external easyexif lib
{
#include <jhead.h>
int ReadJpegSections (FILE * infile, ReadMode_t ReadMode);
void ResetJpgfile(void);
}
namespace vcg { namespace vcg {
namespace tri { namespace tri {
namespace io { namespace io {
struct Correspondence{ struct Correspondence{
Correspondence(unsigned int id_img_,unsigned int key_,float x_,float y_):id_img(id_img_),key(key_),x(x_),y(y_){} Correspondence(unsigned int id_img_,unsigned int key_,float x_,float y_):id_img(id_img_),key(key_),x(x_),y(y_){}
unsigned int id_img,key; unsigned int id_img,key;
float x; float x;
float y; float y;
}; };
typedef std::vector<Correspondence> CorrVec; typedef std::vector<Correspondence> CorrVec;
/** /**
This class encapsulate a filter for opening bundler file This class encapsulate a filter for opening bundler file
@ -60,20 +55,20 @@ class ImporterOUT
{ {
public: public:
typedef typename OpenMeshType::VertexPointer VertexPointer; typedef typename OpenMeshType::VertexPointer VertexPointer;
typedef typename OpenMeshType::ScalarType ScalarType; typedef typename OpenMeshType::ScalarType ScalarType;
typedef typename OpenMeshType::CoordType CoordType; typedef typename OpenMeshType::CoordType CoordType;
typedef typename OpenMeshType::VertexType VertexType; typedef typename OpenMeshType::VertexType VertexType;
typedef typename OpenMeshType::FaceType FaceType; typedef typename OpenMeshType::FaceType FaceType;
typedef typename OpenMeshType::VertexIterator VertexIterator; 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 void readline(FILE *fp, char *line, int max=100){ static void readline(FILE *fp, char *line, int max=100){
fgets ( line, max, fp); fgets ( line, max, fp);
} }
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[100]; char line[100];
readline(fp, line); readline(fp, line);
if( line[0]=='\0' ) return false; if( line[0]=='\0' ) return false;
@ -83,12 +78,16 @@ static bool ReadHeader(FILE *fp,unsigned int &num_cams, unsigned int &num_points
if(line[0]=='\0') return false; if(line[0]=='\0') return false;
if (sscanf(line, "%d %d", &num_cams, &num_points) != 2) return false; if (sscanf(line, "%d %d", &num_cams, &num_points) != 2) return false;
return true; return true;
} }
static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots, static int Open(
OpenMeshType &m,
std::vector<Shot<ScalarType> > & shots,
std::vector<std::string > & image_filenames, std::vector<std::string > & image_filenames,
const char * filename,const char * filename_images, CallBackPos *cb=0) const char * filename,
{ const char * filename_images,
CallBackPos *cb=0)
{
unsigned int num_cams,num_points; unsigned int num_cams,num_points;
typedef typename vcg::Matrix44<ScalarType> Matrix44x; typedef typename vcg::Matrix44<ScalarType> Matrix44x;
typedef typename vcg::Matrix33<ScalarType> Matrix33x; typedef typename vcg::Matrix33<ScalarType> Matrix33x;
@ -167,11 +166,11 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
fclose(fp); fclose(fp);
return (shots.size() == 0); return (shots.size() == 0);
} }
static bool ReadImagesFilenames(const char * filename,std::vector<std::string> &image_filenames) static bool ReadImagesFilenames(const char * filename,std::vector<std::string> &image_filenames)
{ {
FILE * fp = fopen(filename,"r"); FILE * fp = fopen(filename,"r");
if (!fp) return false; if (!fp) return false;
else else
@ -187,20 +186,42 @@ static bool ReadImagesFilenames(const char * filename,std::vector<std::string>
} }
fclose(fp); fclose(fp);
return true; return true;
} }
static bool AddIntrinsics(vcg::Shotf &shot, const char * image_file) static bool AddIntrinsics(vcg::Shotf &shot, const char * image_file)
{ {
::ResetJpgfile(); // Read the JPEG file into a buffer
FILE * pFile = fopen(image_file, "rb"); FILE *fp = fopen(qUtf8Printable(image_file), "rb");
int ret = ::ReadJpegSections (pFile, READ_METADATA); if (!fp) {
fclose(pFile); std::cerr << "Exif Parsing: Unable to open file:\n\"%1\"\n\nError details: file %1 is not readable.";
if(ret==0) return false; return false;
shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.Width, ImageInfo.Height); }
shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.Width/2.0), float(ImageInfo.Height/2.0)); fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
rewind(fp);
unsigned char *buf = new unsigned char[fsize];
if (fread(buf, 1, fsize, fp) != fsize) {
std::cerr << "Exif Parsing: Unable to read the content of the opened file:\n\"%1\"\n\nError details: file %1 is not readable.";
delete[] buf;
fclose(fp);
return false;
}
fclose(fp);
// Parse EXIF
easyexif::EXIFInfo ImageInfo;
int ret = ImageInfo.parseFrom(buf, fsize);
delete[] buf;
if (ret == 0) {
std::cerr << "Warning unable to parse exif for file %s" << qPrintable(image_file);
return false;
}
shot.Intrinsics.ViewportPx = vcg::Point2i(ImageInfo.ImageWidth, ImageInfo.ImageHeight);
shot.Intrinsics.CenterPx = vcg::Point2f(float(ImageInfo.ImageWidth/2.0), float(ImageInfo.ImageHeight/2.0));
return true; return true;
} }
}; // end class }; // end class