This commit is contained in:
T.Alderighi 2017-11-27 15:31:28 +01:00
commit 39c61c7893
5 changed files with 166 additions and 30 deletions

View File

@ -217,6 +217,20 @@ namespace vcg
return res;
}
size_t serialize(std::string& str)
{
for (unsigned int ii = 0; ii < ATT_NAMES_DERIVED_CLASS::enumArity(); ++ii)
str.append(((_atts[ii]) ? "1" : "0"));
return ATT_NAMES_DERIVED_CLASS::enumArity();
}
void deserialize(const std::string& str)
{
std::bitset<ATT_NAMES_DERIVED_CLASS::ATT_ARITY> bset(str);
for (unsigned int ii = 0; ii < ATT_NAMES_DERIVED_CLASS::enumArity(); ++ii)
_atts[ATT_NAMES_DERIVED_CLASS::enumArity() - ii - 1] = bset[ii];
}
//template<typename MESHTYPE>
//static void computeARequestedAttributesSetCompatibleWithMesh(const MESHTYPE& mesh,const PRIMITIVE_MODALITY_MASK,RenderingAtts<ATT_NAMES_DERIVED_CLASS>& rqatt)
//{
@ -330,6 +344,8 @@ namespace vcg
class InternalRendAtts : public RenderingAtts<INT_ATT_NAMES>
{
public:
typedef INT_ATT_NAMES AttName;
InternalRendAtts()
:RenderingAtts<INT_ATT_NAMES>()
{

View File

@ -118,7 +118,6 @@ namespace vcg
return (*this);
}
private:
void copyData(const RenderingModalityGLOptions& opts)
{
@ -156,6 +155,9 @@ namespace vcg
class PerViewData : public GLMeshAttributesInfo
{
public:
typedef GL_OPTIONS_DERIVED_TYPE GLOptionsType;
PerViewData()
:_pmmask(),_intatts(PR_ARITY),_glopts(NULL)
{
@ -260,6 +262,53 @@ namespace vcg
}
}
void serialize(std::string& str)
{
str.append(_pmmask.to_string());
for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it)
{
std::string s;
it->serialize(s);
str.append(s);
}
std::string s;
_glopts->serialize(s);
str.append(s);
}
bool deserialize(const std::string& str)
{
std::string::size_type pos = 0;
std::string token[6];
token[0] = str.substr(pos, _pmmask.size());
if (token[0].length() < _pmmask.size())
return false;
int i = 1;
pos = _pmmask.size();
for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it, i++)
{
token[i] = str.substr(pos, InternalRendAtts::AttName::enumArity());
if (token[i].length() < InternalRendAtts::AttName::enumArity())
return false;
pos = pos + InternalRendAtts::AttName::enumArity();
}
if (_glopts != NULL)
{
int size = _glopts->serialize(std::string());
token[i] = str.substr(pos, size);
if (token[i].length() < size)
return false;
}
_pmmask = PRIMITIVE_MODALITY_MASK(token[0]);
i = 1;
for (typename PerRendModData::iterator it = _intatts.begin(); it != _intatts.end(); ++it, i++)
it->deserialize(token[i]);
if (_glopts != NULL)
_glopts->deserialize(token[i]);
return true;
}
protected:
template<typename MESH_TYPE,typename UNIQUE_VIEW_ID_TYPE, typename XX_GL_OPTIONS_DERIVED_TYPE> friend class NotThreadSafeGLMeshAttributesMultiViewerBOManager;

View File

@ -31,7 +31,7 @@
#include <igl/cut_mesh_from_singularities.h>
#include <igl/find_cross_field_singularities.h>
#include <igl/compute_frame_field_bisectors.h>
#include <igl/comiso/miq.h>
#include <igl/copyleft/comiso/miq.h>
#include <vcg/complex/algorithms/parametrization/uv_utils.h>
#include <vcg/complex/algorithms/mesh_to_matrix.h>
@ -163,7 +163,7 @@ private:
}
}
igl::miq(V,F,X1,X2,UV,FUV,MiqP.gradient,MiqP.stiffness,MiqP.directRound,
igl::copyleft::comiso::miq(V,F,X1,X2,UV,FUV,MiqP.gradient,MiqP.stiffness,MiqP.directRound,
MiqP.stiffness_iter,MiqP.local_iter,MiqP.doRound,MiqP.round_singularities,
extra_round,hard_features);
@ -287,7 +287,7 @@ private:
// MMatch,isSingularity,singularityIndex,Seams,
// UV,FUV,MiqP.gradient,MiqP.stiffness,MiqP.directRound,
// MiqP.stiffness_iter,MiqP.local_iter,MiqP.doRound,MiqP.round_singularities,extra_round,hard_features);
igl::miq(V,F,X1_combed,X2_combed,
igl::copyleft::comiso::miq(V,F,X1_combed,X2_combed,
UV,FUV,MiqP.gradient,MiqP.stiffness,MiqP.directRound,
MiqP.stiffness_iter,MiqP.local_iter,MiqP.doRound,MiqP.round_singularities,extra_round,hard_features);

View File

@ -476,7 +476,7 @@ namespace nanoply
std::getline(fileStream, line);
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
last = false;
if (line == "end_header")
if (line.find("end_header") != std::string::npos)
last = true;
return true;
}
@ -1139,7 +1139,7 @@ namespace nanoply
token = strtok(tempStr, " \t");
if (strstr(token, "element") == NULL)
return false;
token = strtok(0, " \t\n");
token = strtok(0, " \t\r\n");
name = std::string(token);
plyElem = PlyElemEntity::NNP_UNKNOWN_ELEM;
ElementMapIterator iter = mapElem.begin();
@ -1162,7 +1162,7 @@ namespace nanoply
}
iter++;
}
token = strtok(0, " \t\n");
token = strtok(0, " \t\r\n");
cnt = atoi(token);
for (size_t i = 0; i < propStr.size(); i++)
if (!AddProperty(propStr[i]))
@ -1512,7 +1512,7 @@ namespace nanoply
{
this->filename = filename;
this->errInfo = NNP_OK;
std::ifstream input(filename, std::ios::binary);
std::ifstream input(filename);
if (!input.good())
{
this->errInfo = NNP_UNABLE_TO_OPEN;

View File

@ -16,31 +16,55 @@ template <class ShotType>
if(QString::compare(node.nodeName(),"VCGCamera")==0)
{
QDomNamedNodeMap attr = node.attributes();
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);
if (attr.contains("BinaryData") && attr.namedItem("BinaryData").nodeValue().toInt() == 1)
{
Point3x tra;
QString str = attr.namedItem("TranslationVector").nodeValue();
QByteArray value = QByteArray::fromBase64(str.toLocal8Bit());
memcpy(tra.V(), value.data(), sizeof(ScalarType) * 3);
shot.Extrinsics.SetTra(-tra);
vcg::Matrix44<ScalarType> rot;
QStringList values = attr.namedItem("RotationMatrix").nodeValue().split(" ", QString::SkipEmptyParts);
for(int y = 0; y < 4; y++)
for(int x = 0; x < 4; x++)
rot[y][x] = values[x + 4*y].toDouble();
shot.Extrinsics.SetRot(rot);
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();
cam.FocalMm = attr.namedItem("FocalMm").nodeValue().toDouble();
cam.ViewportPx.X() = attr.namedItem("ViewportPx").nodeValue().section(' ',0,0).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[1] = attr.namedItem("CenterPx").nodeValue().section(' ', 1, 1).toDouble();
cam.PixelSizeMm[0] = attr.namedItem("PixelSizeMm").nodeValue().section(' ',0,0).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[1] = attr.namedItem("LensDistortion").nodeValue().section(' ',1,1).toDouble();
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);
vcg::Matrix44<ScalarType> rot;
QStringList values = attr.namedItem("RotationMatrix").nodeValue().split(" ", QString::SkipEmptyParts);
for (int y = 0; y < 4; y++)
for (int x = 0; x < 4; x++)
rot[y][x] = values[x + 4 * y].toDouble();
shot.Extrinsics.SetRot(rot);
vcg::Camera<ScalarType> &cam = shot.Intrinsics;
if (attr.contains("CameraType")) cam.cameraType = attr.namedItem("CameraType").nodeValue().toInt();
cam.FocalMm = attr.namedItem("FocalMm").nodeValue().toDouble();
cam.ViewportPx.X() = attr.namedItem("ViewportPx").nodeValue().section(' ', 0, 0).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[1] = attr.namedItem("CenterPx").nodeValue().section(' ', 1, 1).toDouble();
cam.PixelSizeMm[0] = attr.namedItem("PixelSizeMm").nodeValue().section(' ', 0, 0).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[1] = attr.namedItem("LensDistortion").nodeValue().section(' ', 1, 1).toDouble();
}
// scale correction should no more exist !!!
// float scorr = attr.namedItem("ScaleCorr").nodeValue().toDouble();
// if(scorr != 0.0) {
@ -120,6 +144,7 @@ template <class ShotType>
const vcg::Camera<ScalarType> &cam = shot.Intrinsics;
shotElem.setAttribute("CameraType", cam.cameraType);
shotElem.setAttribute("BinaryData", 0);
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