primitive.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id: Primitive.h 676 2012-04-19 18:32:07Z xlokaj03 $
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by Robo@FIT group.
00009  *
00010  * Author: Tomas Lokaj (xlokaj03@stud.fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: 24/11/2011
00013  * 
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  * 
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #pragma once
00029 #ifndef PRIMITIVE_H_
00030 #define PRIMITIVE_H_
00031 
00032 #include <ros/ros.h>
00033 #include <interactive_markers/interactive_marker_server.h>
00034 #include <interactive_markers/tools.h>
00035 #include <interactive_markers/menu_handler.h>
00036 #include <geometry_msgs/Point.h>
00037 #include <geometry_msgs/Polygon.h>
00038 #include <std_msgs/ColorRGBA.h>
00039 #include <OGRE/OgreVector3.h>
00040 #include <arm_navigation_msgs/Shape.h>
00041 
00042 #include <tf/tf.h>
00043 #include <tf/transform_listener.h>
00044 
00045 #include <srs_interaction_primitives/parameters_list.h>
00046 #include <srs_interaction_primitives/PrimitiveType.h>
00047 #include <srs_interaction_primitives/PoseType.h>
00048 #include "update_publisher.h"
00049 
00050 #define MEASURE_TEXT_SCALE 0.2
00051 #define MEASURE_TEXT_MAX_SIZE 0.3
00052 #define MEASURE_TEXT_MIN_SIZE 0.1
00053 
00054 #define GRASP_ARROW_LENGTH 0.25
00055 #define GRASP_ARROW_WIDTH 0.2
00056 #define GRASP_TEXT_OFFSET 0.1
00057 #define GRASP_TEXT_SIZE 0.1
00058 #define GRASP_POINT_SCALE 0.05
00059 #define GRASP_TRANSPARENCY 0.3
00060 
00061 namespace srs_interaction_primitives
00062 {
00063 
00064 typedef boost::shared_ptr<interactive_markers::InteractiveMarkerServer> InteractiveMarkerServerPtr;
00065 typedef geometry_msgs::Vector3 Scale;
00066 
00071 float maxScale(geometry_msgs::Vector3 scale);
00072 
00077 float minScale(geometry_msgs::Vector3 scale);
00078 
00079 const float SCALE_COEFF = 1.0;
00080 
00086 class Primitive
00087 {
00088 public:
00095   Primitive(InteractiveMarkerServerPtr server, std::string frame_id, std::string name, int type);
00096 
00100   Primitive()
00101   {
00102   }
00103 
00107   virtual ~Primitive()
00108   {
00109     this->erase();
00110     server_->applyChanges();
00111   }
00112 
00116   virtual void insert();
00117 
00121   virtual void erase();
00122 
00127   void changeColor(std_msgs::ColorRGBA color);
00128 
00133   void setPoseType(int type)
00134   {
00135     if (type == PoseType::POSE_CENTER || type == PoseType::POSE_BASE)
00136     {
00137       pose_type_ = type;
00138     }
00139   }
00140 
00145   int getPoseType()
00146   {
00147     return pose_type_;
00148   }
00149 
00154   void setPrimitiveType(int type)
00155   {
00156     primitive_type_ = type;
00157     delete updatePublisher_;
00158     updatePublisher_ = new UpdatePublisher(name_, primitive_type_);
00159   }
00160 
00165   int getPrimitiveType()
00166   {
00167     return primitive_type_;
00168   }
00169 
00174   std::string getUpdateTopic(int update_type)
00175   {
00176     return updatePublisher_->getUpdateTopic(update_type);
00177   }
00178 
00183   std::string getName()
00184   {
00185     return name_;
00186   }
00187 
00192   void setColor(std_msgs::ColorRGBA color)
00193   {
00194     color_ = color;
00195   }
00196 
00201   std_msgs::ColorRGBA getColor()
00202   {
00203     return color_;
00204   }
00205 
00210   void setPose(geometry_msgs::Pose pose)
00211   {
00212     if (pose_type_ == PoseType::POSE_BASE)
00213     {
00214       pose.position.z += scale_.z * 0.5;
00215     }
00216 
00217     geometry_msgs::Pose pose_change;
00218     pose_change.position.x = pose.position.x - pose_.position.x;
00219     pose_change.position.y = pose.position.y - pose_.position.y;
00220     pose_change.position.z = pose.position.z - pose_.position.z;
00221     pose_change.orientation.x = pose.orientation.x - pose_.orientation.x;
00222     pose_change.orientation.y = pose.orientation.y - pose_.orientation.y;
00223     pose_change.orientation.z = pose.orientation.z - pose_.orientation.z;
00224     pose_change.orientation.w = pose.orientation.w - pose_.orientation.w;
00225     pose_ = pose;
00226     object_.pose = pose_;
00227     updatePublisher_->publishPoseChanged(pose_, pose_change);
00228   }
00229 
00234   geometry_msgs::Pose getPose()
00235   {
00236     return pose_;
00237   }
00238 
00243   void setScale(geometry_msgs::Vector3 scale)
00244   {
00245     if (pose_type_ == PoseType::POSE_BASE)
00246     {
00247       pose_.position.z -= scale_.z * 0.5;
00248       pose_.position.z += scale.z * 0.5;
00249     }
00250 
00251     geometry_msgs::Vector3 scale_change;
00252     scale_change.x = scale.x - scale_.x;
00253     scale_change.y = scale.y - scale_.y;
00254     scale_change.z = scale.z - scale_.z;
00255     scale_ = scale;
00256     object_.scale = SCALE_COEFF * srs_interaction_primitives::maxScale(scale_);
00257     updatePublisher_->publishScaleChanged(scale_, scale_change);
00258   }
00259 
00264   geometry_msgs::Vector3 getScale()
00265   {
00266     return scale_;
00267   }
00268 
00273   void setDescription(std::string description)
00274   {
00275     description_ = description;
00276   }
00277 
00282   std::string getDescription()
00283   {
00284     return description_;
00285   }
00286 
00291   void setFrameID(std::string frame_id)
00292   {
00293     frame_id_ = frame_id;
00294   }
00295 
00300   std::string getFrameID()
00301   {
00302     return frame_id_;
00303   }
00304 
00308   void updateControls();
00309 
00314   visualization_msgs::InteractiveMarkerControl * getControl(std::string name);
00315 
00319   virtual void defaultCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00320 
00321 protected:
00325   virtual void create()
00326   {
00327   }
00328 
00332   virtual void createMenu()
00333   {
00334   }
00335 
00339   void addDescriptionControl();
00340 
00344   void addMeasureControl();
00345 
00350   void addMovementControls();
00351 
00355   void addRotationControls();
00356 
00360   void removeMovementControls();
00361 
00365   void removeRotationControls();
00366 
00370   void removeMeasureControl();
00371 
00375   void removeDescriptionControl();
00376 
00381   void removeControl(std::string name);
00382 
00386   void clearObject();
00387 
00391   void addScaleControls();
00392 
00396   virtual void updateScaleControls();
00397 
00401   void removeScaleControls();
00402 
00406   void scaleFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00407 
00408   geometry_msgs::Vector3 min_size_, max_size_;
00409   int primitive_type_;
00410   visualization_msgs::InteractiveMarker object_;
00411   visualization_msgs::InteractiveMarkerControl control_, descriptionControl_, measureControl_, scaleControl_,
00412                                                trajectoryControl_;
00413   visualization_msgs::InteractiveMarkerControl moveXControl_, moveYControl_, moveZControl_, rotateXControl_,
00414                                                rotateYControl, rotateZControl_;
00415   interactive_markers::MenuHandler menu_handler_;
00416 
00417 // Transform listener
00418   tf::TransformListener *tfListener;
00419 
00420 // Transformer
00421   tf::Transformer transformer;
00422 
00423 // Transformations
00424   tf::StampedTransform feedbackToDefaultTransform;
00425 
00426 // Common attributes
00427   std::string name_, description_, frame_id_;
00428   InteractiveMarkerServerPtr server_;
00429   geometry_msgs::Pose pose_;
00430   geometry_msgs::Vector3 scale_;
00431   std_msgs::ColorRGBA color_, color_green_a01_;
00432   int pose_type_;
00433   geometry_msgs::Pose pose_change;
00434 
00435   UpdatePublisher *updatePublisher_;
00436 
00437   bool show_movement_control_, show_scale_control_, show_rotation_control_, show_measure_control_,
00438        show_description_control_,  show_trajectory_control_;
00439   bool menu_created_;
00440 
00441   geometry_msgs::Vector3 scale_prev_;
00442   int scale_saved_;
00443 };
00444 
00445 
00446 }
00447 #endif /* PRIMITIVE_H_ */


srs_interaction_primitives
Author(s): Tomas Lokaj, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Mon Oct 6 2014 07:55:11