Point Cloud Library (PCL)  1.9.1-dev
camera_pose.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2014-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Author: Marco Paladini <marco.paladini@ocado.com>
37  * Date: March 2014
38  */
39 
40 #pragma once
41 
42 #include <Eigen/Core>
43 #include <Eigen/Geometry>
44 #include <fstream>
45 
46 /**
47  * @brief The CameraPoseProcessor class is an interface to extract
48  * camera pose data generated by the pcl_kinfu_app program.
49  * Use the CameraPoseWriter implementation if writing the camera
50  * pose to a file is all you need, or provide an alternative implementation.
51  */
53 {
54  public:
55  virtual ~CameraPoseProcessor () {}
56 
57  /// process the camera pose, this method is called at every frame.
58  virtual void
59  processPose (const Eigen::Affine3f &pose)=0;
60 };
61 
62 /**
63  * @brief CameraPoseWriter writes all camera poses computed by
64  * the KinfuTracker to a file on disk.
65  *
66  */
68 {
69  std::string output_filename_;
70  std::ofstream out_stream_;
71  public:
72  /**
73  * @param output_filename name of file to write
74  */
75  CameraPoseWriter (const std::string &output_filename) :
76  output_filename_ (output_filename)
77  {
78  out_stream_.open (output_filename_.c_str () );
79  }
80 
82  {
83  if (out_stream_.is_open ())
84  {
85  out_stream_.close ();
86  std::cout << "wrote camera poses to file " << output_filename_ << std::endl;
87  }
88  }
89 
90  void
91  processPose (const Eigen::Affine3f &pose) override
92  {
93  if (out_stream_.good ())
94  {
95  // convert 3x4 affine transformation to quaternion and write to file
96  Eigen::Quaternionf q (pose.rotation ());
97  Eigen::Vector3f t (pose.translation ());
98  // write translation , quaternion in a row
99  out_stream_ << t[0] << "," << t[1] << "," << t[2]
100  << "," << q.w () << "," << q.x ()
101  << "," << q.y ()<< "," << q.z () << std::endl;
102  }
103  }
104 
105 };
CameraPoseWriter writes all camera poses computed by the KinfuTracker to a file on disk...
Definition: camera_pose.h:67
virtual void processPose(const Eigen::Affine3f &pose)=0
process the camera pose, this method is called at every frame.
void processPose(const Eigen::Affine3f &pose) override
process the camera pose, this method is called at every frame.
Definition: camera_pose.h:91
CameraPoseWriter(const std::string &output_filename)
Definition: camera_pose.h:75
virtual ~CameraPoseProcessor()
Definition: camera_pose.h:55
The CameraPoseProcessor class is an interface to extract camera pose data generated by the pcl_kinfu_...
Definition: camera_pose.h:52