MetaFormatFactory.cpp
Go to the documentation of this file.
2 
3 namespace lvr2
4 {
5 
6 void saveMetaInformation(const std::string &outfile, const YAML::Node &node)
7 {
8  boost::filesystem::path p(outfile);
9 
10  if (p.extension() == ".yaml")
11  {
12  std::cout << timestamp << "SaveMetaInformation(YAML): " << outfile << std::endl;
13  std::ofstream out(outfile.c_str());
14  out << node;
15  out.close();
16  }
17  else if (p.extension() == ".slam6d")
18  {
19  // Try to get pose estimation from yaml node
20  // and write it to pose file in the directory
21  // encoded in the pseudo meta path
22  if (node["pose_estimate"])
23  {
24  Transformf transform = node["pose_estimate"].as<Transformf>();
25  BaseVector<float> position;
26  BaseVector<float> angles;
27  getPoseFromMatrix(position, angles, transform);
28 
29  //Construct .pose file path and save
30  boost::filesystem::path outfilePath(outfile);
31  boost::filesystem::path dir = outfilePath.parent_path();
32  boost::filesystem::path posePath(outfilePath.stem().string() + ".pose");
33  boost::filesystem::path poseOutPath = p.parent_path() / posePath;
34 
35  std::cout << timestamp << "SaveMetaInformation(SLAM6D): " << poseOutPath << std::endl;
36  writePose(position, angles, poseOutPath);
37  }
38 
39  // Same for registration. If present, write frames file
40  if (node["registration"])
41  {
42  Transformf transform = node["registration"].as<Transformf>();
43  //Construct .pose file path and save
44  boost::filesystem::path outfilePath(outfile);
45  boost::filesystem::path dir = outfilePath.parent_path();
46  boost::filesystem::path framesPath(outfilePath.stem().string() + ".frames");
47  boost::filesystem::path framesOutPath = p.parent_path() / framesPath;
48  std::cout << timestamp << "SaveMetaInformation(SLAM6D): " << framesOutPath << std::endl;
49  writeFrame(transform, framesOutPath);
50  }
51  }
52 }
53 
54 YAML::Node loadMetaInformation(const std::string &in)
55 {
56  boost::filesystem::path inPath(in);
57  if (inPath.extension() == ".yaml")
58  {
59  YAML::Node n;
60  if (boost::filesystem::exists(inPath))
61  {
62  std::cout << timestamp
63  << "LoadMetaInformation(YAML): Loading " << inPath << std::endl;
64  n = YAML::LoadFile(inPath.string());
65  }
66  else
67  {
68  std::cout << timestamp
69  << "LoadMetaInformation(YAML): Unable to find yaml file: " << inPath << std::endl;
70  }
71  return n;
72  }
73  else if (inPath.extension() == ".slam6d")
74  {
75  YAML::Node node;
76 
77  boost::filesystem::path dir = inPath.parent_path();
78  boost::filesystem::path posePath(inPath.stem().string() + ".pose");
79  boost::filesystem::path poseInPath = inPath.parent_path() / posePath;
80  std::ifstream in_str(poseInPath.c_str());
81  if (in_str.good())
82  {
83  std::cout << timestamp
84  << "LoadMetaInformation(SLAM6D): Loading " << poseInPath << std::endl;
85 
86  double x, y, z, r, t, p;
87  in_str >> x >> y >> z >> r >> t >> p;
88  Vector3d pose(x, y, z);
89  Vector3d angles(r, t, p);
90 
91  Transformd poseEstimate = poseToMatrix(pose, angles);
92  node["pose_estimate"] = poseEstimate;
93  }
94  else
95  {
96  std::cout << timestamp
97  << "LoadMetaInformation(SLAM6D): Warning: No pose file found." << std::endl;
98  }
99 
100  boost::filesystem::path framesPath(inPath.stem().string() + ".frames");
101  boost::filesystem::path framesInPath = inPath.parent_path() / framesPath;
102  if (boost::filesystem::exists(framesInPath))
103  {
104  std::cout << timestamp
105  << "LoadMetaInformation(SLAM6D): Loading " << framesInPath << std::endl;
106  Transformd registration = getTransformationFromFrames<double>(framesInPath);
107  node["registration"] = registration;
108  }
109  else
110  {
111  std::cout << timestamp
112  << "LoadMetaInformation(SLAM6D): Warning: No pose file found." << std::endl;
113  }
114  return node;
115  }
116 }
117 
118 } // namespace lvr2
lvr2::BaseVector< float >
transform
Definition: src/tools/lvr2_transform/Options.cpp:44
lvr2::loadMetaInformation
YAML::Node loadMetaInformation(const std::string &in)
Definition: MetaFormatFactory.cpp:54
lvr2::Transformd
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
lvr2::writeFrame
void writeFrame(const Transform< T > &transform, const boost::filesystem::path &framesOut)
Writes a Eigen transformation into a .frames file.
p
SharedPointer p
Definition: ConvertShared.hpp:42
lvr2::getPoseFromMatrix
void getPoseFromMatrix(BaseVector< T > &position, BaseVector< T > &angles, const Transform< T > &mat)
Computes a Euler representation from the given transformation matrix.
lvr2::saveMetaInformation
void saveMetaInformation(const std::string &outfile, const YAML::Node &node)
Definition: MetaFormatFactory.cpp:6
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::Vector3d
Eigen::Vector3d Vector3d
Eigen 3D vector, double precision.
Definition: MatrixTypes.hpp:121
MetaFormatFactory.hpp
lvr2::Transformf
Transform< float > Transformf
4x4 single precision transformation matrix
Definition: MatrixTypes.hpp:68
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::writePose
void writePose(const BaseVector< float > &position, const BaseVector< float > &angles, const boost::filesystem::path &out)
Writes pose information in Euler representation to the given file.
Definition: IOUtils.cpp:154
lvr2::poseToMatrix
Transform< T > poseToMatrix(const Vector3< T > &position, const Vector3< T > &rotation)
Converts a Pose to a Matrix.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:24