4 #include <opencv/cv.hpp> 9 #include <boost/archive/xml_iarchive.hpp> 10 #include <boost/archive/xml_oarchive.hpp> 16 #define GRAPH_INFO_NAME "graphInfo" 17 #define TREE_INFO_NAME "treeInfo" 18 #define DATA_NAME "graphData" 20 Serializer::Serializer()
25 std::size_t Serializer::getHash(
const std::vector<signed char> &_map, Eigen::Vector2d _origin,
float _resolution)
29 boost::hash_combine(seed, _origin[0]);
30 boost::hash_combine(seed, _origin[1]);
31 boost::hash_combine(seed, _resolution);
33 for(
const signed char & val : _map)
35 boost::hash_combine(seed, val);
42 bool Serializer::load(
const std::string &_mapPath, std::vector<Segment> &_segs, Eigen::Vector2d &_origin,
float &_resolution)
47 boost::filesystem::path data(_mapPath +
DATA_NAME);
49 if(!boost::filesystem::exists(graf) | !boost::filesystem::exists(tree) | !boost::filesystem::exists(data))
59 boost::archive::xml_iarchive xml(ifs);
60 xml >> boost::serialization::make_nvp(
"GraphInfo", g);
68 boost::archive::xml_iarchive xmlti(ifti);
69 xmlti >> boost::serialization::make_nvp(
"TreeInfo", t);
75 std::vector<SegmentSerializer> segs;
81 for(
int i = 0; i < t.
Length; i++)
84 segs.emplace_back(pred[i], succ[i], pts[i]);
88 std::ifstream ifsDist(_mapPath +
DATA_NAME);
89 boost::archive::xml_iarchive iaDist(ifsDist);
90 iaDist >> boost::serialization::make_nvp(
"graph",graph);
95 for(
int i = 0; i < graph.
Length; i++)
97 std::vector<Eigen::Vector2d> pts;
102 pts.emplace_back(ptPtr[j].
x, ptPtr[j].
y);
111 for(
int i = 0; i < graph.
Length; i++)
113 std::vector<uint32_t> predecessors;
114 std::vector<uint32_t> successors;
120 if(!_segs[i].containsPredecessor(predPtr[j]))
121 _segs[i].addPredecessor(predPtr[j]);
128 if(!_segs[i].containsSuccessor(succPtr[j]))
129 _segs[i].addSuccessor(succPtr[j]);
142 void Serializer::save(
const std::string &_mapPath,
const std::vector<Segment> &_segs,
const Eigen::Vector2d &_origin,
const float &_resolution)
144 if(!boost::filesystem::exists(_mapPath))
145 boost::filesystem::create_directories(_mapPath);
149 GraphInfo info(_origin, _resolution, _segs.size());
152 boost::archive::xml_oarchive oa(ofs);
153 oa << boost::serialization::make_nvp(
"GraphInfo", info);
159 assert(ofsTree.good());
160 boost::archive::xml_oarchive ot(ofsTree);
161 ot << boost::serialization::make_nvp(
"TreeInfo", tInfo);
165 std::vector<SegmentSerializer> segs;
167 for(
const auto & seg : _segs)
169 segs.emplace_back(seg);
174 std::ofstream ofsGraph(_mapPath +
DATA_NAME);
175 boost::archive::xml_oarchive oaGraph(ofsGraph);
176 oaGraph << boost::serialization::make_nvp(
"graph", graph);
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::unique_ptr< int > Predecessors
std::unique_ptr< int > predecessors
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::unique_ptr< PointSerializer > points
std::unique_ptr< int > successors
std::unique_ptr< int > Successors
std::unique_ptr< int > Points
SegmentSerializer * segments_