Loading...
Searching...
No Matches
camera_pose.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Marco Paladini <marco.paladini@ocado.com>
* Date: March 2014
*/
#pragma once
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <fstream>
#include <pcl/memory.h>
/**
* @brief The CameraPoseProcessor class is an interface to extract
* camera pose data generated by the pcl_kinfu_app program.
* Use the CameraPoseWriter implementation if writing the camera
* pose to a file is all you need, or provide an alternative implementation.
*/
class CameraPoseProcessor
{
public:
using Ptr = pcl::shared_ptr<CameraPoseProcessor>;
using ConstPtr = pcl::shared_ptr<const CameraPoseProcessor>;
virtual ~CameraPoseProcessor () = default;
/// process the camera pose, this method is called at every frame.
virtual void
processPose (const Eigen::Affine3f &pose)=0;
};
/**
* @brief CameraPoseWriter writes all camera poses computed by
* the KinfuTracker to a file on disk.
*
*/
class CameraPoseWriter : public CameraPoseProcessor
{
std::string output_filename_;
std::ofstream out_stream_;
public:
/**
* @param output_filename name of file to write
*/
CameraPoseWriter (const std::string &output_filename) :
output_filename_ (output_filename)
{
out_stream_.open (output_filename_.c_str () );
}
~CameraPoseWriter ()
{
if (out_stream_.is_open ())
{
out_stream_.close ();
std::cout << "wrote camera poses to file " << output_filename_ << std::endl;
}
}
void
processPose (const Eigen::Affine3f &pose) override
{
if (out_stream_.good ())
{
// convert 3x4 affine transformation to quaternion and write to file
Eigen::Quaternionf q (pose.rotation ());
Eigen::Vector3f t (pose.translation ());
// write translation , quaternion in a row
out_stream_ << t[0] << "," << t[1] << "," << t[2]
<< "," << q.w () << "," << q.x ()
<< "," << q.y ()<< "," << q.z () << std::endl;
}
}
};
CameraPoseProcessor
The CameraPoseProcessor class is an interface to extract camera pose data generated by the pcl_kinfu_...
Definition camera_pose.h:55
CameraPoseProcessor::ConstPtr
pcl::shared_ptr< const CameraPoseProcessor > ConstPtr
Definition camera_pose.h:58
CameraPoseProcessor::processPose
virtual void processPose(const Eigen::Affine3f &pose)=0
process the camera pose, this method is called at every frame.
CameraPoseProcessor::Ptr
pcl::shared_ptr< CameraPoseProcessor > Ptr
Definition camera_pose.h:57
CameraPoseProcessor::~CameraPoseProcessor
virtual ~CameraPoseProcessor()=default
CameraPoseWriter
CameraPoseWriter writes all camera poses computed by the KinfuTracker to a file on disk.
Definition camera_pose.h:73
CameraPoseWriter::processPose
void processPose(const Eigen::Affine3f &pose) override
process the camera pose, this method is called at every frame.
Definition camera_pose.h:96
CameraPoseWriter::CameraPoseWriter
CameraPoseWriter(const std::string &output_filename)
Definition camera_pose.h:80
CameraPoseWriter::~CameraPoseWriter
~CameraPoseWriter()
Definition camera_pose.h:86
memory.h
Defines functions, macros and traits for allocating and using memory.