00001 /* 00002 * Copyright (c) 2009, 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 OBJECT_SELECTION_FRAME 00031 #define OBJECT_SELECTION_FRAME 00032 00033 #include "pr2_interactive_manipulation/object_selection_ui.h" 00034 00035 #include <geometric_shapes_msgs/Shape.h> 00036 #include <geometry_msgs/Pose.h> 00037 #include <pr2_interactive_object_detection/GraspableObjectList.h> 00038 00039 #include <ogre_tools/point_cloud.h> 00040 00041 #include <OGRE/OgreRenderable.h> 00042 00043 namespace rviz_interaction_tools { 00044 class MeshObject; 00045 class ImageOverlay; 00046 } 00047 00048 namespace ogre_tools { 00049 //class PointCloud; 00050 } 00051 00052 namespace rviz { 00053 class WindowManagerInterface; 00054 class RenderPanel; 00055 class VisualizationManager; 00056 } 00057 00058 namespace Ogre { 00059 class SceneNode; 00060 class RaySceneQuery; 00061 class SceneManager; 00062 } 00063 00064 namespace pr2_interactive_manipulation { 00065 00066 class ObjectSelectionFrame : public ObjectSelectionFrameBase 00067 { 00068 public: 00069 00070 enum ActionState{ IDLE, ACTIVE, ACCEPTED, CANCELED }; 00071 00072 ObjectSelectionFrame(rviz::VisualizationManager *visualization_manager, wxWindow *parent); 00073 virtual ~ObjectSelectionFrame(); 00074 00075 //callback for wx mouse events 00076 void onRenderWindowMouseEvents( wxMouseEvent& event ); 00077 00078 void setData( pr2_interactive_object_detection::GraspableObjectListConstPtr received_objects ); 00079 00080 //called regularly; updates the display. 00081 void update(); 00082 00083 ActionState getState(){return action_state_;} 00084 00085 void setState( ActionState state ) { action_state_ = state; } 00086 00087 unsigned int getSelectedObject() { return selected_object_; } 00088 00089 protected: 00090 00091 // callbacks for gui buttons 00092 virtual void acceptButtonClicked( wxCommandEvent& ); 00093 virtual void cancelButtonClicked( wxCommandEvent& ); 00094 00095 //cleanup ogre scene, hide window 00096 void cleanupAndHide(); 00097 00098 //create the different red and green ogre materials 00099 void createMaterials(); 00100 00101 //put ogre panel into the window 00102 void createRenderPanel( rviz::VisualizationManager *visualization_manager ); 00103 00104 void addMesh( int object_index, 00105 const geometric_shapes_msgs::Shape &mesh, 00106 const geometry_msgs::Pose &pose ); 00107 00108 void addCluster( int object_index, const sensor_msgs::PointCloud &cluster ); 00109 00110 //ogre stuff 00111 rviz::RenderPanel* render_panel_; 00112 Ogre::SceneManager* scene_manager_; 00113 Ogre::SceneNode* scene_root_; 00114 00115 //used for object selection 00116 Ogre::RaySceneQuery* ray_scene_query_; 00117 00118 //displays the camera image 00119 rviz_interaction_tools::ImageOverlay *image_overlay_; 00120 00121 //displays the model hypothesis meshes 00122 std::map< unsigned, boost::shared_ptr<rviz_interaction_tools::MeshObject> > meshes_; 00123 00124 unsigned int selected_object_; 00125 00126 ActionState action_state_; 00127 }; 00128 00129 } 00130 00131 #endif