shot_qt.h
Go to the documentation of this file.
00001 #ifndef SHOT_QT_H
00002 #define SHOT_QT_H
00003 
00004 
00009 template <class ShotType>
00010     bool ReadShotFromQDomNode(
00011         ShotType &shot, 
00012         const QDomNode &node) 
00013 {
00014   typedef typename ShotType::ScalarType ScalarType;
00015   typedef vcg::Point3<typename ShotType::ScalarType> Point3x;
00016   if(QString::compare(node.nodeName(),"VCGCamera")==0)
00017   {
00018     QDomNamedNodeMap attr = node.attributes();
00019     Point3x tra;
00020     tra[0] = attr.namedItem("TranslationVector").nodeValue().section(' ',0,0).toDouble();
00021     tra[1] = attr.namedItem("TranslationVector").nodeValue().section(' ',1,1).toDouble();
00022     tra[2] = attr.namedItem("TranslationVector").nodeValue().section(' ',2,2).toDouble();
00023     shot.Extrinsics.SetTra(-tra);
00024 
00025     vcg::Matrix44<ScalarType> rot;
00026     QStringList values =  attr.namedItem("RotationMatrix").nodeValue().split(" ", QString::SkipEmptyParts);
00027     for(int y = 0; y < 4; y++)
00028       for(int x = 0; x < 4; x++)
00029         rot[y][x] = values[x + 4*y].toDouble();
00030     shot.Extrinsics.SetRot(rot);
00031 
00032     vcg::Camera<ScalarType> &cam = shot.Intrinsics;
00033     cam.FocalMm = attr.namedItem("FocalMm").nodeValue().toDouble();
00034     cam.ViewportPx.X() = attr.namedItem("ViewportPx").nodeValue().section(' ',0,0).toInt();
00035     cam.ViewportPx.Y() = attr.namedItem("ViewportPx").nodeValue().section(' ',1,1).toInt();
00036     cam.CenterPx[0] = attr.namedItem("CenterPx").nodeValue().section(' ',0,0).toInt();
00037     cam.CenterPx[1] = attr.namedItem("CenterPx").nodeValue().section(' ',1,1).toInt();
00038     cam.PixelSizeMm[0] = attr.namedItem("PixelSizeMm").nodeValue().section(' ',0,0).toDouble();
00039     cam.PixelSizeMm[1] = attr.namedItem("PixelSizeMm").nodeValue().section(' ',1,1).toDouble();
00040     cam.k[0] = attr.namedItem("LensDistortion").nodeValue().section(' ',0,0).toDouble();
00041     cam.k[1] = attr.namedItem("LensDistortion").nodeValue().section(' ',1,1).toDouble();
00042 
00043     // scale correction should no more exist !!!
00044     //    float scorr = attr.namedItem("ScaleCorr").nodeValue().toDouble();
00045     //    if(scorr != 0.0) {
00046     //      cam.PixelSizeMm[0] *= scorr;
00047     //      cam.PixelSizeMm[1] *= scorr;
00048     //    }
00049     return true;
00050   }
00051   return false;
00052 }
00053 
00055 template <class ShotType>
00056   bool ReadShotFromOLDXML( ShotType &shot, const QDomNode &node)
00057 {
00058   typedef typename ShotType::ScalarType ScalarType;
00059 
00060   if(QString::compare(node.nodeName(),"CamParam")==0)
00061   {
00062     QDomNamedNodeMap attr = node.attributes();
00063     vcg::Point3<ScalarType> tra;
00064     tra[0] = attr.namedItem("SimTra").nodeValue().section(' ',0,0).toDouble();
00065     tra[1] = attr.namedItem("SimTra").nodeValue().section(' ',1,1).toDouble();
00066     tra[2] = attr.namedItem("SimTra").nodeValue().section(' ',2,2).toDouble();
00067     shot.Extrinsics.SetTra(-tra);
00068 
00069     vcg::Matrix44<ScalarType> rot;
00070     QStringList values =  attr.namedItem("SimRot").nodeValue().split(" ", QString::SkipEmptyParts);
00071     for(int y = 0; y < 4; y++)
00072       for(int x = 0; x < 4; x++)
00073         rot[y][x] = values[x + 4*y].toDouble();
00074     shot.Extrinsics.SetRot(rot);
00075 
00076     vcg::Camera<ScalarType> &cam = shot.Intrinsics;
00077     cam.FocalMm = attr.namedItem("Focal").nodeValue().toDouble();
00078     cam.ViewportPx.X() = attr.namedItem("Viewport").nodeValue().section(' ',0,0).toInt();
00079     cam.ViewportPx.Y() = attr.namedItem("Viewport").nodeValue().section(' ',1,1).toInt();
00080     cam.CenterPx[0] = attr.namedItem("Center").nodeValue().section(' ',0,0).toInt();
00081     cam.CenterPx[1] = attr.namedItem("Center").nodeValue().section(' ',1,1).toInt();
00082     cam.PixelSizeMm[0] = attr.namedItem("ScaleF").nodeValue().section(' ',0,0).toDouble();
00083     cam.PixelSizeMm[1] = attr.namedItem("ScaleF").nodeValue().section(' ',1,1).toDouble();
00084     cam.k[0] = attr.namedItem("LensDist").nodeValue().section(' ',0,0).toDouble();
00085     cam.k[1] = attr.namedItem("LensDist").nodeValue().section(' ',1,1).toDouble();
00086 
00087     // scale correction
00088     float scorr = attr.namedItem("ScaleCorr").nodeValue().toDouble();
00089     if(scorr != 0.0) {
00090       cam.PixelSizeMm[0] *= scorr;
00091       cam.PixelSizeMm[1] *= scorr;
00092     }
00093     return true;
00094   }
00095   return false;
00096 }
00097 
00098 
00099 
00100 template <class ShotType>
00101     QDomElement WriteShotToQDomNode(
00102         const ShotType &shot, 
00103         QDomDocument &doc) 
00104 {
00105   typedef typename ShotType::ScalarType ScalarType;
00106 
00107   QDomElement shotElem = doc.createElement( "VCGCamera" );
00108   vcg::Point3<ScalarType> tra = -(shot.Extrinsics.Tra());
00109   QString str = QString("%1 %2 %3 1").arg(tra[0]).arg(tra[1]).arg(tra[2]);
00110   shotElem.setAttribute("TranslationVector", str);
00111   vcg::Matrix44<ScalarType> rot = shot.Extrinsics.Rot();
00112   str = QString("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 ")
00113     .arg(rot[0][0]).arg(rot[0][1]).arg(rot[0][2]).arg(rot[0][3])
00114     .arg(rot[1][0]).arg(rot[1][1]).arg(rot[1][2]).arg(rot[1][3])
00115     .arg(rot[2][0]).arg(rot[2][1]).arg(rot[2][2]).arg(rot[2][3])
00116     .arg(rot[3][0]).arg(rot[3][1]).arg(rot[3][2]).arg(rot[3][3]);
00117   shotElem.setAttribute( "RotationMatrix", str);
00118 
00119   const vcg::Camera<ScalarType> &cam = shot.Intrinsics;
00120 
00121   shotElem.setAttribute( "FocalMm", cam.FocalMm);
00122 
00123   str = QString("%1 %2").arg(cam.k[0]).arg(cam.k[1]);
00124   shotElem.setAttribute( "LensDistortion", str);
00125 
00126   str = QString("%1 %2").arg(cam.PixelSizeMm[0]).arg(cam.PixelSizeMm[1]);
00127   shotElem.setAttribute( "PixelSizeMm", str);
00128 
00129   str = QString("%1 %2").arg(cam.ViewportPx[0]).arg(cam.ViewportPx[1]);
00130   shotElem.setAttribute( "ViewportPx", str);
00131 
00132   str = QString("%1 %2").arg((int)(cam.CenterPx[0])).arg((int)(cam.CenterPx[1]));
00133   shotElem.setAttribute( "CenterPx", str);
00134 
00135   //scale correction should no more exist !!!
00136   //str = QString("%1").arg((double) 1);
00137   //shotElem.setAttribute( "ScaleCorr", str);
00138   return shotElem;
00139 }
00140 
00141 
00142 #endif // SHOT_QT_H


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:35:23