Updated the some of the importers to the double/float managmaent. Now by default ascii files are read as double and if necessary downcasted to float.

This commit is contained in:
Paolo Cignoni 2014-06-27 08:51:31 +00:00
parent 87e2599d27
commit c02fd854f7
3 changed files with 456 additions and 450 deletions

View File

@ -57,6 +57,7 @@ public:
typedef typename OpenMeshType::VertexPointer VertexPointer;
typedef typename OpenMeshType::ScalarType ScalarType;
typedef typename OpenMeshType::CoordType CoordType;
typedef typename OpenMeshType::VertexType VertexType;
typedef typename OpenMeshType::FaceType FaceType;
typedef typename OpenMeshType::VertexIterator VertexIterator;
@ -130,9 +131,9 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
//vcg::Matrix44f mat = vcg::Matrix44<vcg::Shotf::ScalarType>::Construct<float>(R);
vcg::Quaternion<float> qfrom; qfrom.Import(R);
vcg::Quaternion<ScalarType> qfrom; qfrom.Import(R);
vcg::Matrix44f mat; qfrom.ToMatrix(mat);
vcg::Matrix44<ScalarType> mat; qfrom.ToMatrix(mat);
/*vcg::Matrix33f Rt = vcg::Matrix33f( vcg::Matrix44f(mat), 3);
Rt.Transpose();
@ -147,13 +148,13 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
mat[2][1]=-mat[2][1];
mat[2][2]=-mat[2][2];
shots[i].Extrinsics.SetTra(vcg::Point3<vcg::Shotf::ScalarType>::Construct<float>(t[0],t[1],t[2]));
shots[i].Extrinsics.SetTra(CoordType(t[0],t[1],t[2]));
shots[i].Extrinsics.SetRot(mat);
shots[i].Intrinsics.FocalMm = f/100.0f;
shots[i].Intrinsics.k[0] = 0.0;//k1; To be uncommented when distortion is taken into account reliably
shots[i].Intrinsics.k[1] = 0.0;//k2;
shots[i].Intrinsics.PixelSizeMm = vcg::Point2f(0.01,0.01);
shots[i].Intrinsics.PixelSizeMm = vcg::Point2<ScalarType>(0.01,0.01);
QImageReader sizeImg(QString::fromStdString(image_filenames[i]));
QSize size=sizeImg.size();
shots[i].Intrinsics.ViewportPx = vcg::Point2i(size.width(),size.height());

View File

@ -62,6 +62,7 @@ public:
typedef typename OpenMeshType::VertexPointer VertexPointer;
typedef typename OpenMeshType::ScalarType ScalarType;
typedef typename OpenMeshType::CoordType CoordType;
typedef typename OpenMeshType::VertexType VertexType;
typedef typename OpenMeshType::FaceType FaceType;
typedef typename OpenMeshType::VertexIterator VertexIterator;
@ -98,7 +99,8 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
const char * filename,const char * filename_images, CallBackPos *cb=0)
{
unsigned int num_cams,num_points;
typedef typename vcg::Matrix44<ScalarType> Matrix44x;
typedef typename vcg::Matrix33<ScalarType> Matrix33x;
FILE *fp = fopen(filename,"r");
if(!fp) return false;
ReadHeader(fp, num_cams, num_points);
@ -123,20 +125,20 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
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);
Matrix44x mat = Matrix44x::Construct(Matrix44f(R));
vcg::Matrix33f Rt = vcg::Matrix33f( vcg::Matrix44f(mat), 3);
Matrix33x Rt = Matrix33x( Matrix44x(mat), 3);
Rt.Transpose();
vcg::Point3f pos = Rt * vcg::Point3f(t[0], t[1], t[2]);
CoordType pos = Rt * CoordType(t[0], t[1], t[2]);
shots[i].Extrinsics.SetTra(vcg::Point3<vcg::Shotf::ScalarType>::Construct<float>(-pos[0],-pos[1],-pos[2]));
shots[i].Extrinsics.SetTra(CoordType(-pos[0],-pos[1],-pos[2]));
shots[i].Extrinsics.SetRot(mat);
shots[i].Intrinsics.FocalMm = f;
shots[i].Intrinsics.k[0] = 0.0;//k1; To be uncommented when distortion is taken into account reliably
shots[i].Intrinsics.k[1] = 0.0;//k2;
shots[i].Intrinsics.PixelSizeMm = vcg::Point2f(1,1);
shots[i].Intrinsics.PixelSizeMm = vcg::Point2<ScalarType>(1,1);
QSize size;
QImageReader sizeImg(QString::fromStdString(image_filenames[i]));
if(sizeImg.size()==QSize(-1,-1))
@ -157,9 +159,9 @@ static int Open( OpenMeshType &m, std::vector<Shot<ScalarType> > & shots,
typename OpenMeshType::VertexIterator vi = vcg::tri::Allocator<OpenMeshType>::AddVertices(m,num_points);
for(uint i = 0; i < num_points;++i,++vi){
float x,y,z;
double x,y,z;
unsigned int r,g,b,i_cam, key_sift,n_corr;
fscanf(fp,"%f %f %f ",&x,&y,&z);
fscanf(fp,"%lf %lf %lf ",&x,&y,&z);
(*vi).P() = vcg::Point3<typename OpenMeshType::ScalarType>(x,y,z);
fscanf(fp,"%d %d %d ",&r,&g,&b);
(*vi).C() = vcg::Color4b(r,g,b,255);

View File

@ -37,6 +37,7 @@ namespace io {
/**
This class encapsulate a filter for importing ptx meshes.
*/
template <class OpenMeshType>
class ImporterPTX
{
@ -47,6 +48,8 @@ namespace io {
typedef typename OpenMeshType::FaceType FaceType;
typedef typename OpenMeshType::VertexIterator VertexIterator;
typedef typename OpenMeshType::FaceIterator FaceIterator;
typedef typename OpenMeshType::CoordType CoordType;
typedef typename vcg::Matrix44<ScalarType> Matrix44x;
class Info //ptx file info
{
@ -170,10 +173,10 @@ namespace io {
int numtokens;
int colnum;
int rownum;
float xx,yy,zz; // position
double xx,yy,zz; // position
float rr,gg,bb; // color
float rf; // reflectance
Matrix44f currtrasf;
Matrix44d currtrasf;
bool hascolor;
bool savecolor = importparams.savecolor && VertexType::HasColor();
@ -188,15 +191,15 @@ namespace io {
if ( ( colnum <=0 ) || ( rownum <=0 ) ) return false;
// initial 4 lines [still don't know what is this :) :)]
if ( !fscanf(fp,"%f %f %f\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%f %f %f\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%f %f %f\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%f %f %f\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%lf %lf %lf\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%lf %lf %lf\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%lf %lf %lf\n", &xx, &yy, &zz) ) return false;
if ( !fscanf(fp,"%lf %lf %lf\n", &xx, &yy, &zz) ) return false;
// now the transformation matrix
if ( !fscanf(fp,"%f %f %f %f\n", &(currtrasf.ElementAt(0,0)), &(currtrasf.ElementAt(0,1)), &(currtrasf.ElementAt(0,2)), &(currtrasf.ElementAt(0,3))) )return false;
if ( !fscanf(fp,"%f %f %f %f\n", &(currtrasf.ElementAt(1,0)), &(currtrasf.ElementAt(1,1)), &(currtrasf.ElementAt(1,2)), &(currtrasf.ElementAt(1,3))) )return false;
if ( !fscanf(fp,"%f %f %f %f\n", &(currtrasf.ElementAt(2,0)), &(currtrasf.ElementAt(2,1)), &(currtrasf.ElementAt(2,2)), &(currtrasf.ElementAt(2,3))) )return false;
if ( !fscanf(fp,"%f %f %f %f\n", &(currtrasf.ElementAt(3,0)), &(currtrasf.ElementAt(3,1)), &(currtrasf.ElementAt(3,2)), &(currtrasf.ElementAt(3,3))) )return false;
if ( !fscanf(fp,"%lf %lf %lf %lf\n", &(currtrasf.ElementAt(0,0)), &(currtrasf.ElementAt(0,1)), &(currtrasf.ElementAt(0,2)), &(currtrasf.ElementAt(0,3))) )return false;
if ( !fscanf(fp,"%lf %lf %lf %lf\n", &(currtrasf.ElementAt(1,0)), &(currtrasf.ElementAt(1,1)), &(currtrasf.ElementAt(1,2)), &(currtrasf.ElementAt(1,3))) )return false;
if ( !fscanf(fp,"%lf %lf %lf %lf\n", &(currtrasf.ElementAt(2,0)), &(currtrasf.ElementAt(2,1)), &(currtrasf.ElementAt(2,2)), &(currtrasf.ElementAt(2,3))) )return false;
if ( !fscanf(fp,"%lf %lf %lf %lf\n", &(currtrasf.ElementAt(3,0)), &(currtrasf.ElementAt(3,1)), &(currtrasf.ElementAt(3,2)), &(currtrasf.ElementAt(3,3))) )return false;
//now the real data begins
// first line, we should know if the format is
@ -227,12 +230,12 @@ namespace io {
if(hascolor)
{
printf("\n hascolor ");
sscanf(linebuf,"%f %f %f %f %f %f %f", &xx, &yy, &zz, &rf, &rr, &gg, &bb);
sscanf(linebuf,"%lf %lf %lf %f %f %f %f", &xx, &yy, &zz, &rf, &rr, &gg, &bb);
}
else
{
printf("\n no color ");
sscanf(linebuf,"%f %f %f %f", &xx, &yy, &zz, &rf);
sscanf(linebuf,"%lf %lf %lf %f", &xx, &yy, &zz, &rf);
}
//addthefirstpoint
@ -340,7 +343,7 @@ namespace io {
if(cb) cb(40,"PTX Mesh Loading - remove invalid vertices");
for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); vi++)
{
if((*vi).P() == Point3f(0.0, 0.0, 0.0))
if((*vi).P() == CoordType(0.0, 0.0, 0.0))
Allocator<OpenMeshType>::DeleteVertex(m,*vi);
}
@ -379,24 +382,24 @@ namespace io {
int vT = (rit ) + ((citT ) * rownum);
int vB = (rit ) + ((citB) * rownum);
Point3f v0p=m.vert[v0].P();
Point3f vLp(0,0,0),vRp(0,0,0),vTp(0,0,0),vBp(0,0,0); // Compute the 4 edges around the vertex.
CoordType v0p=m.vert[v0].P();
CoordType vLp(0,0,0),vRp(0,0,0),vTp(0,0,0),vBp(0,0,0); // Compute the 4 edges around the vertex.
if(!m.vert[vL].IsD()) vLp=(m.vert[vL].P()-v0p).Normalize();
if(!m.vert[vR].IsD()) vRp=(m.vert[vR].P()-v0p).Normalize();
if(!m.vert[vT].IsD()) vTp=(m.vert[vT].P()-v0p).Normalize();
if(!m.vert[vB].IsD()) vBp=(m.vert[vB].P()-v0p).Normalize();
float r=0;
int rc=0; Point3f v0pn = Normalize(v0p);
int rc=0; CoordType v0pn = Normalize(v0p);
// Skip edges that are too steep
// Compute the four normalized vector orthogonal to each pair of consecutive edges.
Point3f vLTn = (vLp ^ vTp).Normalize();
Point3f vTRn = (vTp ^ vRp).Normalize();
Point3f vRBn = (vRp ^ vBp).Normalize();
Point3f vBLn = (vBp ^ vLp).Normalize();
CoordType vLTn = (vLp ^ vTp).Normalize();
CoordType vTRn = (vTp ^ vRp).Normalize();
CoordType vRBn = (vRp ^ vBp).Normalize();
CoordType vBLn = (vBp ^ vLp).Normalize();
// Compute an average Normal skipping null normals and normals that are too steep.
// Compute also the sum of non null edge lenght to compute the radius
Point3f N(0,0,0);
CoordType N(0,0,0);
if((vLTn*v0pn)>limitCos) { N+=vLTn; r += Distance(m.vert[vL].P(),v0p)+Distance(m.vert[vT].P(),v0p); rc++; }
if((vTRn*v0pn)>limitCos) { N+=vTRn; r += Distance(m.vert[vT].P(),v0p)+Distance(m.vert[vR].P(),v0p); rc++; }
if((vRBn*v0pn)>limitCos) { N+=vRBn; r += Distance(m.vert[vR].P(),v0p)+Distance(m.vert[vB].P(),v0p); rc++; }
@ -406,7 +409,7 @@ namespace io {
if(tri::HasPerVertexRadius(m)) m.vert[v0].R() = r/(rc*2.0f);
// Isolated points has null normal. Delete them please.
if(m.vert[v0].N() == Point3f(0,0,0)) Allocator<OpenMeshType>::DeleteVertex(m,m.vert[v0]);
if(m.vert[v0].N() == CoordType(0,0,0)) Allocator<OpenMeshType>::DeleteVertex(m,m.vert[v0]);
}
}
}
@ -422,7 +425,7 @@ namespace io {
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); fi++)
if(!(*fi).IsD())
{
Point3f raggio = -((*fi).P(0) + (*fi).P(1) + (*fi).P(2)) / 3.0;
CoordType raggio = -((*fi).P(0) + (*fi).P(1) + (*fi).P(2)) / 3.0;
raggio.Normalize();
if((raggio.dot((*fi).N())) < limitCos)
Allocator<OpenMeshType>::DeleteFace(m,*fi);
@ -431,11 +434,11 @@ namespace io {
tri::Clean<OpenMeshType>::RemoveUnreferencedVertex(m);
}
}
Matrix44x tr; tr.Import(currtrasf);
tri::UpdatePosition<OpenMeshType>::Matrix(m,currtrasf,true);
tri::Allocator<OpenMeshType>::CompactVertexVector(m);
tri::UpdateBounding<OpenMeshType>::Box(m);
if(cb) cb(100,"PTX Mesh Loading finish!");
if(cb) cb(100,"PTX Mesh Loading finished!");
return true;
}