00001 // -*- mode: c++ -*- 00002 /********************************************************************* 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2014, JSK Lab 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/o2r other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Willow Garage nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 *********************************************************************/ 00035 00036 00037 #ifndef JSK_RVIZ_PLUGINS_CAMERA_INFO_DISPLAY_H_ 00038 #define JSK_RVIZ_PLUGINS_CAMERA_INFO_DISPLAY_H_ 00039 00040 #include <rviz/display.h> 00041 #include <rviz/message_filter_display.h> 00042 #include <rviz/properties/color_property.h> 00043 #include <rviz/properties/bool_property.h> 00044 #include <rviz/properties/float_property.h> 00045 #include <rviz/ogre_helpers/shape.h> 00046 #include <rviz/ogre_helpers/billboard_line.h> 00047 #include <OGRE/OgreSceneNode.h> 00048 #include <image_geometry/pinhole_camera_model.h> 00049 #include <OGRE/OgreManualObject.h> 00050 #include <OGRE/OgreTextureManager.h> 00051 #include <OGRE/OgreTexture.h> 00052 00053 namespace jsk_rviz_plugin 00054 { 00055 class TrianglePolygon 00056 { 00057 public: 00058 typedef boost::shared_ptr<TrianglePolygon> Ptr; 00059 TrianglePolygon(Ogre::SceneManager* manager, 00060 Ogre::SceneNode* node, 00061 const cv::Point3d& O, 00062 const cv::Point3d& A, 00063 const cv::Point3d& B, 00064 const std::string& name, 00065 const Ogre::ColourValue& color); 00066 virtual ~TrianglePolygon(); 00067 protected: 00068 Ogre::ManualObject* manual_; 00069 Ogre::SceneManager* manager_; 00070 private: 00071 00072 }; 00073 00074 class CameraInfoDisplay: 00075 public rviz::MessageFilterDisplay<sensor_msgs::CameraInfo> 00076 { 00077 Q_OBJECT 00078 public: 00079 typedef boost::shared_ptr<rviz::Shape> ShapePtr; 00080 typedef boost::shared_ptr<rviz::BillboardLine> BillboardLinePtr; 00081 CameraInfoDisplay(); 00082 virtual ~CameraInfoDisplay(); 00083 00084 protected: 00086 // methods required by super virtual class 00088 virtual void onInitialize(); 00089 virtual void reset(); 00090 virtual void processMessage(const sensor_msgs::CameraInfo::ConstPtr& msg); 00092 // methods 00094 virtual bool isSameCameraInfo( 00095 const sensor_msgs::CameraInfo::ConstPtr& camera_info); 00096 virtual void createCameraInfoShapes( 00097 const sensor_msgs::CameraInfo::ConstPtr& camera_info); 00098 virtual void addPointToEdge( 00099 const cv::Point3d& point); 00100 virtual void addPolygon( 00101 const cv::Point3d& O, const cv::Point3d& A, const cv::Point3d& B); 00102 virtual void prepareMaterial(); 00104 // variables 00106 std::vector<TrianglePolygon::Ptr> polygons_; 00107 BillboardLinePtr edges_; 00108 sensor_msgs::CameraInfo::ConstPtr camera_info_; 00109 Ogre::MaterialPtr material_; 00110 Ogre::TexturePtr texture_; 00111 00113 // variables updated by rviz properties 00115 double alpha_; 00116 double far_clip_distance_; 00117 QColor color_; 00118 QColor edge_color_; 00119 bool show_polygons_; 00120 00122 // properties 00124 rviz::FloatProperty* far_clip_distance_property_; 00125 rviz::FloatProperty* alpha_property_; 00126 rviz::ColorProperty* color_property_; 00127 rviz::ColorProperty* edge_color_property_; 00128 rviz::BoolProperty* show_polygons_property_; 00129 protected Q_SLOTS: 00130 void updateFarClipDistance(); 00131 void updateAlpha(); 00132 void updateColor(); 00133 void updateShowPolygons(); 00134 void updateEdgeColor(); 00135 }; 00136 00137 } 00138 00139 #endif