Added binary serialization of the Camera data
Binary serialization using Base64 encoding of the data
This commit is contained in:
parent
4cfb4c3744
commit
91b8a61d42
|
|
@ -16,31 +16,55 @@ template <class ShotType>
|
||||||
if(QString::compare(node.nodeName(),"VCGCamera")==0)
|
if(QString::compare(node.nodeName(),"VCGCamera")==0)
|
||||||
{
|
{
|
||||||
QDomNamedNodeMap attr = node.attributes();
|
QDomNamedNodeMap attr = node.attributes();
|
||||||
|
if (attr.contains("BinaryData") && attr.namedItem("BinaryData").nodeValue().toInt() == 1)
|
||||||
|
{
|
||||||
Point3x tra;
|
Point3x tra;
|
||||||
tra[0] = attr.namedItem("TranslationVector").nodeValue().section(' ',0,0).toDouble();
|
QString str = attr.namedItem("TranslationVector").nodeValue();
|
||||||
tra[1] = attr.namedItem("TranslationVector").nodeValue().section(' ',1,1).toDouble();
|
QByteArray value = QByteArray::fromBase64(str.toLocal8Bit());
|
||||||
tra[2] = attr.namedItem("TranslationVector").nodeValue().section(' ',2,2).toDouble();
|
memcpy(tra.V(), value.data(), sizeof(ScalarType) * 3);
|
||||||
|
shot.Extrinsics.SetTra(-tra);
|
||||||
|
|
||||||
|
vcg::Matrix44<ScalarType> rot;
|
||||||
|
str = attr.namedItem("RotationMatrix").nodeValue();
|
||||||
|
value = QByteArray::fromBase64(str.toLocal8Bit());
|
||||||
|
memcpy(rot.V(), value.data(), sizeof(ScalarType) * 16);
|
||||||
|
shot.Extrinsics.SetRot(rot);
|
||||||
|
|
||||||
|
vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
||||||
|
if (attr.contains("CameraType")) cam.cameraType = attr.namedItem("CameraType").nodeValue().toInt();
|
||||||
|
memcpy(&cam.FocalMm, QByteArray::fromBase64(attr.namedItem("FocalMm").nodeValue().toLocal8Bit()).data(), sizeof(ScalarType));
|
||||||
|
memcpy(&cam.ViewportPx, QByteArray::fromBase64(attr.namedItem("ViewportPx").nodeValue().toLocal8Bit()).data(), sizeof(int) * 2);
|
||||||
|
memcpy(&cam.CenterPx, QByteArray::fromBase64(attr.namedItem("CenterPx").nodeValue().toLocal8Bit()).data(), sizeof(ScalarType)*2);
|
||||||
|
memcpy(&cam.PixelSizeMm, QByteArray::fromBase64(attr.namedItem("PixelSizeMm").nodeValue().toLocal8Bit()).data(), sizeof(ScalarType) * 2);
|
||||||
|
memcpy(&cam.k, QByteArray::fromBase64(attr.namedItem("LensDistortion").nodeValue().toLocal8Bit()).data(), sizeof(ScalarType) * 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Point3x tra;
|
||||||
|
tra[0] = attr.namedItem("TranslationVector").nodeValue().section(' ', 0, 0).toDouble();
|
||||||
|
tra[1] = attr.namedItem("TranslationVector").nodeValue().section(' ', 1, 1).toDouble();
|
||||||
|
tra[2] = attr.namedItem("TranslationVector").nodeValue().section(' ', 2, 2).toDouble();
|
||||||
shot.Extrinsics.SetTra(-tra);
|
shot.Extrinsics.SetTra(-tra);
|
||||||
|
|
||||||
vcg::Matrix44<ScalarType> rot;
|
vcg::Matrix44<ScalarType> rot;
|
||||||
QStringList values = attr.namedItem("RotationMatrix").nodeValue().split(" ", QString::SkipEmptyParts);
|
QStringList values = attr.namedItem("RotationMatrix").nodeValue().split(" ", QString::SkipEmptyParts);
|
||||||
for(int y = 0; y < 4; y++)
|
for (int y = 0; y < 4; y++)
|
||||||
for(int x = 0; x < 4; x++)
|
for (int x = 0; x < 4; x++)
|
||||||
rot[y][x] = values[x + 4*y].toDouble();
|
rot[y][x] = values[x + 4 * y].toDouble();
|
||||||
shot.Extrinsics.SetRot(rot);
|
shot.Extrinsics.SetRot(rot);
|
||||||
|
|
||||||
vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
||||||
if(attr.contains("CameraType")) cam.cameraType = attr.namedItem("CameraType").nodeValue().toInt();
|
if (attr.contains("CameraType")) cam.cameraType = attr.namedItem("CameraType").nodeValue().toInt();
|
||||||
cam.FocalMm = attr.namedItem("FocalMm").nodeValue().toDouble();
|
cam.FocalMm = attr.namedItem("FocalMm").nodeValue().toDouble();
|
||||||
cam.ViewportPx.X() = attr.namedItem("ViewportPx").nodeValue().section(' ',0,0).toInt();
|
cam.ViewportPx.X() = attr.namedItem("ViewportPx").nodeValue().section(' ', 0, 0).toInt();
|
||||||
cam.ViewportPx.Y() = attr.namedItem("ViewportPx").nodeValue().section(' ',1,1).toInt();
|
cam.ViewportPx.Y() = attr.namedItem("ViewportPx").nodeValue().section(' ', 1, 1).toInt();
|
||||||
cam.CenterPx[0] = attr.namedItem("CenterPx").nodeValue().section(' ', 0, 0).toDouble();
|
cam.CenterPx[0] = attr.namedItem("CenterPx").nodeValue().section(' ', 0, 0).toDouble();
|
||||||
cam.CenterPx[1] = attr.namedItem("CenterPx").nodeValue().section(' ', 1, 1).toDouble();
|
cam.CenterPx[1] = attr.namedItem("CenterPx").nodeValue().section(' ', 1, 1).toDouble();
|
||||||
cam.PixelSizeMm[0] = attr.namedItem("PixelSizeMm").nodeValue().section(' ',0,0).toDouble();
|
cam.PixelSizeMm[0] = attr.namedItem("PixelSizeMm").nodeValue().section(' ', 0, 0).toDouble();
|
||||||
cam.PixelSizeMm[1] = attr.namedItem("PixelSizeMm").nodeValue().section(' ',1,1).toDouble();
|
cam.PixelSizeMm[1] = attr.namedItem("PixelSizeMm").nodeValue().section(' ', 1, 1).toDouble();
|
||||||
cam.k[0] = attr.namedItem("LensDistortion").nodeValue().section(' ',0,0).toDouble();
|
cam.k[0] = attr.namedItem("LensDistortion").nodeValue().section(' ', 0, 0).toDouble();
|
||||||
cam.k[1] = attr.namedItem("LensDistortion").nodeValue().section(' ',1,1).toDouble();
|
cam.k[1] = attr.namedItem("LensDistortion").nodeValue().section(' ', 1, 1).toDouble();
|
||||||
|
}
|
||||||
// scale correction should no more exist !!!
|
// scale correction should no more exist !!!
|
||||||
// float scorr = attr.namedItem("ScaleCorr").nodeValue().toDouble();
|
// float scorr = attr.namedItem("ScaleCorr").nodeValue().toDouble();
|
||||||
// if(scorr != 0.0) {
|
// if(scorr != 0.0) {
|
||||||
|
|
@ -120,6 +144,7 @@ template <class ShotType>
|
||||||
const vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
const vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
||||||
|
|
||||||
shotElem.setAttribute("CameraType", cam.cameraType);
|
shotElem.setAttribute("CameraType", cam.cameraType);
|
||||||
|
shotElem.setAttribute("BinaryData", 0);
|
||||||
|
|
||||||
shotElem.setAttribute( "FocalMm", cam.FocalMm);
|
shotElem.setAttribute( "FocalMm", cam.FocalMm);
|
||||||
|
|
||||||
|
|
@ -142,4 +167,50 @@ template <class ShotType>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class ShotType>
|
||||||
|
QDomElement WriteShotToQDomNodeBinary(
|
||||||
|
const ShotType &shot, /// the shot to be written node
|
||||||
|
QDomDocument &doc) /// The XML node to be read
|
||||||
|
{
|
||||||
|
typedef typename ShotType::ScalarType ScalarType;
|
||||||
|
|
||||||
|
QDomElement shotElem = doc.createElement("VCGCamera");
|
||||||
|
vcg::Point3<ScalarType> tra = -(shot.Extrinsics.Tra());
|
||||||
|
|
||||||
|
QByteArray value = QByteArray::fromRawData((char *)tra.V(), sizeof(ScalarType) * 3).toBase64();
|
||||||
|
shotElem.setAttribute("TranslationVector", QString(value));
|
||||||
|
|
||||||
|
vcg::Matrix44<ScalarType> rot = shot.Extrinsics.Rot();
|
||||||
|
value = QByteArray::fromRawData((char *)rot.V(), sizeof(ScalarType) * 16).toBase64();
|
||||||
|
shotElem.setAttribute("RotationMatrix", QString(value));
|
||||||
|
|
||||||
|
const vcg::Camera<ScalarType> &cam = shot.Intrinsics;
|
||||||
|
|
||||||
|
shotElem.setAttribute("CameraType", cam.cameraType);
|
||||||
|
|
||||||
|
shotElem.setAttribute("BinaryData", 1);
|
||||||
|
|
||||||
|
value = QByteArray::fromRawData((char *)&cam.FocalMm, sizeof(ScalarType)).toBase64();
|
||||||
|
shotElem.setAttribute("FocalMm", QString(value));
|
||||||
|
|
||||||
|
value = QByteArray::fromRawData((char *)&cam.k, sizeof(ScalarType) * 2).toBase64();
|
||||||
|
shotElem.setAttribute("LensDistortion", QString(value));
|
||||||
|
|
||||||
|
value = QByteArray::fromRawData((char *)&cam.PixelSizeMm, sizeof(ScalarType) * 2).toBase64();
|
||||||
|
shotElem.setAttribute("PixelSizeMm", QString(value));
|
||||||
|
|
||||||
|
value = QByteArray::fromRawData((char *)&cam.ViewportPx, sizeof(int) * 2).toBase64();
|
||||||
|
shotElem.setAttribute("ViewportPx", QString(value));
|
||||||
|
|
||||||
|
//str = QString("%1 %2").arg(cam.CenterPx[0]).arg(cam.CenterPx[1]);
|
||||||
|
value = QByteArray::fromRawData((char *)&cam.CenterPx, sizeof(ScalarType) * 2).toBase64();
|
||||||
|
shotElem.setAttribute("CenterPx", QString(value));
|
||||||
|
|
||||||
|
//scale correction should no more exist !!!
|
||||||
|
//str = QString("%1").arg((double) 1);
|
||||||
|
//shotElem.setAttribute( "ScaleCorr", str);
|
||||||
|
return shotElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // SHOT_QT_H
|
#endif // SHOT_QT_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue