00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 DisplayContext;
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( DisplayContext* context,
00075 Ogre::SceneNode *reference_node,
00076 InteractiveMarker *parent );
00077
00078 virtual ~InteractiveMarkerControl();
00079
00082 void processMessage( const visualization_msgs::InteractiveMarkerControl &message );
00083
00084
00085 virtual void enableInteraction(bool enable);
00086
00087
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
00100 void update();
00101
00102 void setVisible( bool visible );
00103
00104 protected:
00105
00106
00107 virtual void preFindVisibleObjects(Ogre::SceneManager *source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport *v);
00108
00109 void updateControlOrientationForViewFacing( Ogre::Viewport* v );
00110
00113 void rotate(Ogre::Ray &mouse_ray);
00114
00117 void moveRotate( Ogre::Ray &mouse_ray );
00118
00120 void movePlane(Ogre::Ray &mouse_ray);
00121
00122
00123 void moveAxis( const Ogre::Ray& mouse_ray, const ViewportMouseEvent& event );
00124
00126 bool intersectYzPlane( const Ogre::Ray& mouse_ray,
00127 Ogre::Vector3& intersection_3d,
00128 Ogre::Vector2& intersection_2d,
00129 float& ray_t );
00130
00132 bool intersectSomeYzPlane( const Ogre::Ray& mouse_ray,
00133 const Ogre::Vector3& point_in_plane,
00134 const Ogre::Quaternion& plane_orientation,
00135 Ogre::Vector3& intersection_3d,
00136 Ogre::Vector2& intersection_2d,
00137 float& ray_t );
00138
00142 bool findClosestPoint( const Ogre::Ray& target_ray,
00143 const Ogre::Ray& mouse_ray,
00144 Ogre::Vector3& closest_point );
00145
00148 void worldToScreen( const Ogre::Vector3& pos_rel_reference,
00149 const Ogre::Viewport* viewport,
00150 Ogre::Vector2& screen_pos );
00151
00153 void addHighlightPass( S_MaterialPtr materials );
00154
00155
00156 void setHighlight( float a );
00157
00158
00159
00160
00161 void recordDraggingInPlaceEvent( ViewportMouseEvent& event );
00162
00163
00164 void handleMouseMovement( ViewportMouseEvent& event );
00165
00166
00167 Ogre::Vector3 closestPointOnLineToPoint( const Ogre::Vector3& line_start,
00168 const Ogre::Vector3& line_dir,
00169 const Ogre::Vector3& test_point );
00170
00172 void makeMarkers( const visualization_msgs::InteractiveMarkerControl &message );
00173
00174 bool dragging_;
00175 Ogre::Viewport* drag_viewport_;
00176
00177 ViewportMouseEvent dragging_in_place_event_;
00178
00179 DisplayContext* context_;
00180
00181 CollObjectHandle coll_object_handle_;
00182
00185 Ogre::SceneNode *reference_node_;
00186
00193 Ogre::SceneNode *control_frame_node_;
00194
00195
00196 Ogre::SceneNode *markers_node_;
00197
00198
00199 int interaction_mode_;
00200 int orientation_mode_;
00201
00202
00203
00204
00205 bool independent_marker_orientation_;
00206
00211 Ogre::Quaternion control_orientation_;
00212
00213 bool always_visible_;
00214
00215 std::string description_;
00216
00217 std::string name_;
00218
00219 typedef boost::shared_ptr<MarkerBase> MarkerBasePtr;
00220 std::vector< MarkerBasePtr > markers_;
00221
00222 InteractiveMarker *parent_;
00223
00224 std::set<Ogre::Pass*> highlight_passes_;
00225
00226
00227
00228
00229 typedef boost::shared_ptr<PointsMarker> PointsMarkerPtr;
00230 std::vector< PointsMarkerPtr > points_markers_;
00231
00234 Ogre::Radian rotation_;
00235
00239 Ogre::Radian rotation_at_mouse_down_;
00240
00243 Ogre::Vector3 grab_point_;
00244
00245
00246 Ogre::Vector2 grab_pixel_;
00247
00248 Ogre::Vector3 parent_position_at_mouse_down_;
00249
00252 Ogre::Quaternion control_frame_orientation_at_mouse_down_;
00253
00256 Ogre::Quaternion parent_orientation_at_mouse_down_;
00257
00261 Ogre::Vector3 rotation_axis_;
00262
00265 Ogre::Vector3 rotation_center_rel_control_;
00266
00269 Ogre::Vector3 grab_point_rel_control_;
00270
00271 bool has_focus_;
00272 bool interaction_enabled_;
00273
00274 bool visible_;
00275 bool view_facing_;
00276 };
00277
00278 }
00279
00280 #endif