interactive_marker_control.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef INTERACTIVE_MARKER_CONTROL_H_
00031 #define INTERACTIVE_MARKER_CONTROL_H_
00032 
00033 #include <boost/shared_ptr.hpp>
00034 #include <boost/enable_shared_from_this.hpp>
00035 
00036 #include <visualization_msgs/InteractiveMarkerControl.h>
00037 
00038 #include "rviz/default_plugin/markers/marker_base.h"
00039 #include "rviz/selection/forwards.h"
00040 #include "rviz/viewport_mouse_event.h"
00041 #include "rviz/interactive_object.h"
00042 
00043 #include <OGRE/OgreRay.h>
00044 #include <OGRE/OgreVector3.h>
00045 #include <OGRE/OgreQuaternion.h>
00046 #include <OGRE/OgreSceneManager.h>
00047 
00048 namespace Ogre
00049 {
00050   class SceneNode;
00051 }
00052 
00053 namespace rviz
00054 {
00055 class VisualizationManager;
00056 class InteractiveMarker;
00057 class PointsMarker;
00058 
00062 class InteractiveMarkerControl: public Ogre::SceneManager::Listener,
00063                                 public InteractiveObject,
00064                                 public boost::enable_shared_from_this<InteractiveMarkerControl>
00065 {
00066 public:
00074   InteractiveMarkerControl(VisualizationManager* vis_manager,
00075                            Ogre::SceneNode *reference_node,
00076                            InteractiveMarker *parent );
00077 
00078   virtual ~InteractiveMarkerControl();
00079 
00082   void processMessage( const visualization_msgs::InteractiveMarkerControl &message );
00083 
00084   // called when interactive mode is globally switched on/off
00085   virtual void enableInteraction(bool enable);
00086 
00087   // will receive all mouse events while the handler has focus
00088   virtual void handleMouseEvent(ViewportMouseEvent& event);
00089 
00095   void interactiveMarkerPoseChanged( Ogre::Vector3 int_marker_position, Ogre::Quaternion int_marker_orientation );
00096 
00097   bool isInteractive() { return interaction_mode_ != visualization_msgs::InteractiveMarkerControl::NONE; }
00098 
00099   // Called every frame by parent's update() function.
00100   void update();
00101 
00102   void setVisible( bool visible );
00103 
00104   void hideVisible();
00105 
00106   void restoreVisible();
00107 
00108 protected:
00109 
00110   // when this is called, we will face the camera
00111   virtual void preFindVisibleObjects(Ogre::SceneManager *source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport *v);
00112 
00113   void updateControlOrientationForViewFacing( Ogre::Viewport* v );
00114 
00117   void rotate(Ogre::Ray &mouse_ray);
00118 
00121   void moveRotate( Ogre::Ray &mouse_ray );
00122 
00124   void movePlane(Ogre::Ray &mouse_ray);
00125 
00126   // Move the position along the control ray given the latest mouse ray.
00127   void moveAxis( const Ogre::Ray& mouse_ray, const ViewportMouseEvent& event );
00128 
00130   bool intersectYzPlane( const Ogre::Ray& mouse_ray,
00131                          Ogre::Vector3& intersection_3d,
00132                          Ogre::Vector2& intersection_2d,
00133                          float& ray_t );
00134 
00136   bool intersectSomeYzPlane( const Ogre::Ray& mouse_ray,
00137                              const Ogre::Vector3& point_in_plane,
00138                              const Ogre::Quaternion& plane_orientation,
00139                              Ogre::Vector3& intersection_3d,
00140                              Ogre::Vector2& intersection_2d,
00141                              float& ray_t );
00142 
00146   bool findClosestPoint( const Ogre::Ray& target_ray,
00147                          const Ogre::Ray& mouse_ray,
00148                          Ogre::Vector3& closest_point );
00149 
00152   void worldToScreen( const Ogre::Vector3& pos_rel_reference,
00153                       const Ogre::Viewport* viewport,
00154                       Ogre::Vector2& screen_pos );
00155 
00157   void addHighlightPass( S_MaterialPtr materials );
00158 
00159   // set the highlight color to (a,a,a)
00160   void setHighlight( float a );
00161 
00162   // Save a copy of the latest mouse event with the event type set to
00163   // QEvent::MouseMove, so that update() can resend the mouse event during
00164   // drag actions to maintain consistent behavior.
00165   void recordDraggingInPlaceEvent( ViewportMouseEvent& event );
00166 
00167   // Motion part of mouse event handling.
00168   void handleMouseMovement( ViewportMouseEvent& event );
00169 
00170   // Return closest point on a line to a test point.
00171   Ogre::Vector3 closestPointOnLineToPoint( const Ogre::Vector3& line_start,
00172                                            const Ogre::Vector3& line_dir,
00173                                            const Ogre::Vector3& test_point );
00174 
00176   void makeMarkers( const visualization_msgs::InteractiveMarkerControl &message );
00177 
00178   bool dragging_;
00179   Ogre::Viewport* drag_viewport_;
00180 
00181   ViewportMouseEvent dragging_in_place_event_;
00182 
00183   VisualizationManager* vis_manager_;
00184 
00185   CollObjectHandle coll_object_handle_;
00186 
00189   Ogre::SceneNode *reference_node_;
00190 
00197   Ogre::SceneNode *control_frame_node_;
00198 
00199   // this is a child of scene_node, but might be oriented differently
00200   Ogre::SceneNode *markers_node_;
00201 
00202   // interaction mode
00203   int interaction_mode_;
00204   int orientation_mode_;
00205 
00206   // if in view facing mode, the markers should be
00207   // view facing as well
00208   // if set to false, they will follow the parent's transformations
00209   bool independent_marker_orientation_;
00210 
00215   Ogre::Quaternion control_orientation_;
00216 
00217   bool always_visible_;
00218 
00219   std::string description_;
00220 
00221   std::string name_;
00222 
00223   typedef boost::shared_ptr<MarkerBase> MarkerBasePtr;
00224   std::vector< MarkerBasePtr > markers_;
00225 
00226   InteractiveMarker *parent_;
00227 
00228   std::set<Ogre::Pass*> highlight_passes_;
00229 
00230   // PointsMarkers are rendered by special shader programs, so the
00231   // regular highlighting method does not work for them.  Keep a
00232   // vector of them so we can call their setHighlightColor() function.
00233   typedef boost::shared_ptr<PointsMarker> PointsMarkerPtr;
00234   std::vector< PointsMarkerPtr > points_markers_;
00235 
00238   Ogre::Radian rotation_;
00239 
00243   Ogre::Radian rotation_at_mouse_down_;
00244 
00247   Ogre::Vector3 grab_point_;
00248 
00249   // The 2D position in pixel coordinates of the mouse-down location.
00250   Ogre::Vector2 grab_pixel_;
00251   // The position of the parent when the mouse button is pressed.
00252   Ogre::Vector3 parent_position_at_mouse_down_;
00253 
00256   Ogre::Quaternion control_frame_orientation_at_mouse_down_;
00257 
00260   Ogre::Quaternion parent_orientation_at_mouse_down_;
00261 
00265   Ogre::Vector3 rotation_axis_;
00266 
00269   Ogre::Vector3 rotation_center_rel_control_;
00270 
00273   Ogre::Vector3 grab_point_rel_control_;
00274 
00275   bool has_focus_;
00276   bool interaction_enabled_;
00277 
00278   bool visible_;
00279   bool saved_visibility_state_;
00280   bool view_facing_;
00281 };
00282 
00283 }
00284 
00285 #endif /* INTERACTIVE_MARKER_CONTROL_H_ */


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:32