Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 */ 00038 00039 #ifndef PCL_VISUALIZATION_POINT_PICKING_EVENT_H_ 00040 #define PCL_VISUALIZATION_POINT_PICKING_EVENT_H_ 00041 00042 #include <pcl/pcl_macros.h> 00043 #include <vector> 00044 00045 #include <vtkCommand.h> 00046 class vtkRenderWindowInteractor; 00047 00048 namespace pcl 00049 { 00050 namespace visualization 00051 { 00052 class PCL_EXPORTS PointPickingCallback : public vtkCommand 00053 { 00054 public: 00055 static PointPickingCallback *New () 00056 { 00057 return (new PointPickingCallback); 00058 } 00059 00060 PointPickingCallback () : x_ (0), y_ (0), z_ (0), idx_ (-1), pick_first_ (false) {} 00061 00062 /** \brief Empty destructor */ 00063 virtual ~PointPickingCallback () {} 00064 00065 virtual void 00066 Execute (vtkObject *caller, unsigned long eventid, void*); 00067 00068 int 00069 performSinglePick (vtkRenderWindowInteractor *iren); 00070 00071 int 00072 performSinglePick (vtkRenderWindowInteractor *iren, float &x, float &y, float &z); 00073 00074 int 00075 performAreaPick (vtkRenderWindowInteractor *iren, std::vector<int> &indices); 00076 00077 private: 00078 float x_, y_, z_; 00079 int idx_; 00080 bool pick_first_; 00081 }; 00082 00083 /** /brief Class representing 3D point picking events. */ 00084 class PCL_EXPORTS PointPickingEvent 00085 { 00086 public: 00087 PointPickingEvent (int idx) : idx_ (idx), idx2_ (-1), x_ (), y_ (), z_ (), x2_ (), y2_ (), z2_ () {} 00088 PointPickingEvent (int idx, float x, float y, float z) : idx_ (idx), idx2_ (-1), x_ (x), y_ (y), z_ (z), x2_ (), y2_ (), z2_ () {} 00089 00090 PointPickingEvent (int idx1, int idx2, float x1, float y1, float z1, float x2, float y2, float z2) : 00091 idx_ (idx1), idx2_ (idx2), x_ (x1), y_ (y1), z_ (z1), x2_ (x2), y2_ (y2), z2_ (z2) 00092 {} 00093 00094 /** \brief Obtain the ID of a point that the user just clicked on. */ 00095 inline int 00096 getPointIndex () const 00097 { 00098 return (idx_); 00099 } 00100 00101 /** \brief Obtain the XYZ point coordinates of a point that the user just clicked on. 00102 * \param[out] x the x coordinate of the point that got selected by the user 00103 * \param[out] y the y coordinate of the point that got selected by the user 00104 * \param[out] z the z coordinate of the point that got selected by the user 00105 */ 00106 inline void 00107 getPoint (float &x, float &y, float &z) const 00108 { 00109 x = x_; y = y_; z = z_; 00110 } 00111 00112 /** \brief For situations when multiple points are selected in a sequence, return the point coordinates. 00113 * \param[out] x1 the x coordinate of the first point that got selected by the user 00114 * \param[out] y1 the y coordinate of the first point that got selected by the user 00115 * \param[out] z1 the z coordinate of the firts point that got selected by the user 00116 * \param[out] x2 the x coordinate of the second point that got selected by the user 00117 * \param[out] y2 the y coordinate of the second point that got selected by the user 00118 * \param[out] z2 the z coordinate of the second point that got selected by the user 00119 * \return true, if two points are available and have been clicked by the user, false otherwise 00120 */ 00121 inline bool 00122 getPoints (float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const 00123 { 00124 if (idx2_ == -1) 00125 return (false); 00126 x1 = x_; y1 = y_; z1 = z_; 00127 x2 = x2_; y2 = y2_; z2 = z2_; 00128 return (true); 00129 } 00130 00131 /** \brief For situations where multiple points are selected in a sequence, return the points indices. 00132 * \param[out] index_1 index of the first point selected by user 00133 * \param[out] index_2 index of the second point selected by user 00134 * \return true, if two points are available and have been clicked by the user, false otherwise 00135 */ 00136 inline bool 00137 getPointIndices (int &index_1, int &index_2) const 00138 { 00139 if (idx2_ == -1) 00140 return (false); 00141 index_1 = idx_; 00142 index_2 = idx2_; 00143 return (true); 00144 } 00145 00146 private: 00147 int idx_, idx2_; 00148 00149 float x_, y_, z_; 00150 float x2_, y2_, z2_; 00151 }; 00152 } //namespace visualization 00153 } //namespace pcl 00154 00155 #endif /* PCL_VISUALIZATION_POINT_PICKING_EVENT_H_ */ 00156