我最近问到关于反序列化的问题,我在这里得到了一个答案:反序列化一个STL映射类成员我现在面临的问题是,我得到了一些point
对象值的nan
值。 下面是一个序列化字符串示例:
22 serialization::archive 16 0 0 47 uploads/guest/another_project/90.step_1/90.step 0 0 1 0 0 0 1 0 0 0 0 1 9.00000000000000000e+01 1 0 0 -2.400000000000000000000e+01 1.000000000000000000000e+00 -2.500000000000000000000e+01 -2.400000000000000000000e+01 1.000000000000000000000e+00 2.500000000000000000000e+01
我决定在序列化和反序列化期间打印值,并显示正确的值。
...
class Point
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const Point &p);
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// save/load base class information
ar & X & Y & Z;
std::cout << "(" << X << ", " << Y << ", " << Z << ")" << std::endl; // OK
}
...
};
对point
对象的操作返回INF/NAN/不正确的结果,因此我决定在另一个函数中打印point
对象,而不是获取(-24,1,-25)&; (-24,1,25)
我正在获取(-nan,-nan,-nan)&; (-nan,-nan,nan)
我在bend
类中有两个点对象startp和endp,序列化如下:
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// save/load base class information
ar & boost::serialization::base_object<MFace>(*this);
ar & mBendAngle & mBendDirection & startp & endp;
}
还有一个名为bendline的对象,我必须使用2个point
对象创建它:这是我打印点的函数
void ModelBend::makeBendLine(){
gp_Pnt endPoint(
startp.X,
startp.Y,
startp.Z
);
gp_Pnt dirVertex(
startp.X - endp.X,
startp.Y - endp.Y,
startp.Z - endp.Z
);
bendLine_ = gp_Lin(endPoint, gp_Dir(dirVertex.X(), dirVertex.Y(), dirVertex.Z()));
std::cout << "===========================================" << std::endl;
std::cout << "(" << startp.X << ", " << startp.Y << ", " << startp.Z << ")" << " ==== ";
std::cout << "(" << endp.X << ", " << endp.Y << ", " << endp.Z << ")" << std::endl;
std::cout << "===========================================" << std::endl;
}
此函数从ModelBend构造函数调用。 这就是我得到某些点值的nan值的地方。
我更改了代码,从序列化函数中调用makeBendLine(),而不是在构造函数ModelBend()中调用,如下所示,现在一切都很完美:
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// save/load base class information
ar & boost::serialization::base_object<MFace>(*this);
ar & mBendAngle & mBendDirection & startp & endp;
makeBendLine(); // LIKE THIS
}