geometryPosesCreatorGui.cpp
Go to the documentation of this file.
00001 #include "geometryPosesCreatorGui.h"
00002 #include <QString>
00003 #include <QFileDialog>
00004 #include <QTextDocument>
00005 #include <sstream>
00006 #include <iomanip>
00007 #include <QMessageBox>
00008 #include <fstream>
00009 
00010 GeometryPosesCreatorGui::GeometryPosesCreatorGui(const std::string & ff, const std::string & tf) : fixed_frame(ff), target_frame(tf)
00011 {
00012    setupUi(this);
00013 
00014    _statusBar = new QStatusBar(this);
00015    this->layout()->addWidget(_statusBar);
00016 }
00017 
00018 GeometryPosesCreatorGui::~GeometryPosesCreatorGui()
00019 {
00020 }
00021 
00022 
00023 void GeometryPosesCreatorGui::showMessage(QString msg)
00024 {
00025    _statusBar->showMessage(msg, 2000);
00026 }
00027 
00028 void GeometryPosesCreatorGui::on_savePoseBtn_clicked()
00029 {
00030     tf::StampedTransform transform;
00031     try{
00032         tf_listener.lookupTransform(fixed_frame, target_frame,
00033                 ros::Time(0), transform);
00034     }
00035     catch (tf::TransformException ex){
00036         ROS_ERROR("%s", ex.what());
00037         QMessageBox::critical(this, "Error in getting transform", QString(ex.what()));
00038         return;
00039     }
00040     ROS_ASSERT(fixed_frame == transform.frame_id_);
00041 
00042     GeometryPoses::NamedPose np;
00043     std::stringstream ss;
00044     ss << "pose" << std::fixed << std::setfill('0') << std::setw(3) << poses.size();
00045     np.first = ss.str();
00046     np.second.header.stamp = transform.stamp_;
00047     np.second.header.frame_id = transform.frame_id_;
00048     np.second.pose.position.x = transform.getOrigin().x();
00049     np.second.pose.position.y = transform.getOrigin().y();
00050     np.second.pose.position.z = transform.getOrigin().z();
00051     if(writeYawOnlyCk->isChecked()) {
00052         ROS_INFO("Using yaw only");
00053         double yaw = tf::getYaw(transform.getRotation());
00054         tf::Quaternion quat = tf::createQuaternionFromYaw(yaw);
00055         transform.setRotation(quat);
00056     }
00057     np.second.pose.orientation.x = transform.getRotation().x();
00058     np.second.pose.orientation.y = transform.getRotation().y();
00059     np.second.pose.orientation.z = transform.getRotation().z();
00060     np.second.pose.orientation.w = transform.getRotation().w();
00061 
00062     poses.push_back(np);
00063     QMessageBox::information(this, "Pose save", "Saved pose");
00064 }
00065 
00066 void GeometryPosesCreatorGui::on_writeFileBtn_clicked()
00067 {
00068     QString fn = QFileDialog::getSaveFileName(this, "Select poses file");
00069     if(fn.length() < 1)
00070         return;
00071 
00072     std::ofstream of(qPrintable(fn));
00073     if(!of.good())
00074         return;
00075 
00076     for(std::vector<GeometryPoses::NamedPose>::iterator it = poses.begin(); it != poses.end(); it++) {
00077         GeometryPoses::NamedPose & np = *it;
00078         of << np.first << " ";
00079         of << np.second.header.stamp.sec << " " << np.second.header.stamp.nsec << " ";
00080         of << np.second.header.frame_id << " ";
00081         of << np.second.pose.position.x << " ";
00082         of << np.second.pose.position.y << " ";
00083         of << np.second.pose.position.z << " ";
00084         of << np.second.pose.orientation.x << " ";
00085         of << np.second.pose.orientation.y << " ";
00086         of << np.second.pose.orientation.z << " ";
00087         of << np.second.pose.orientation.w << std::endl;
00088     }
00089 
00090     if(of.good()) {
00091         QMessageBox::information(this, "Write file", "File written");
00092     }
00093 
00094     of.close();
00095 }
00096 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


hardcoded_facts
Author(s): Christian Dornhege
autogenerated on Wed Dec 26 2012 15:46:04