Point Cloud Library (PCL)  1.7.2
point_picking_event.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #ifndef PCL_VISUALIZATION_POINT_PICKING_EVENT_H_
40 #define PCL_VISUALIZATION_POINT_PICKING_EVENT_H_
41 
42 #include <pcl/pcl_macros.h>
43 #include <vector>
44 
45 #include <vtkCommand.h>
46 class vtkRenderWindowInteractor;
47 
48 namespace pcl
49 {
50  namespace visualization
51  {
52  class PCL_EXPORTS PointPickingCallback : public vtkCommand
53  {
54  public:
56  {
57  return (new PointPickingCallback);
58  }
59 
60  PointPickingCallback () : x_ (0), y_ (0), z_ (0), idx_ (-1), pick_first_ (false) {}
61 
62  /** \brief Empty destructor */
63  virtual ~PointPickingCallback () {}
64 
65  virtual void
66  Execute (vtkObject *caller, unsigned long eventid, void*);
67 
68  int
69  performSinglePick (vtkRenderWindowInteractor *iren);
70 
71  int
72  performSinglePick (vtkRenderWindowInteractor *iren, float &x, float &y, float &z);
73 
74  int
75  performAreaPick (vtkRenderWindowInteractor *iren, std::vector<int> &indices);
76 
77  private:
78  float x_, y_, z_;
79  int idx_;
80  bool pick_first_;
81  };
82 
83  /** /brief Class representing 3D point picking events. */
84  class PCL_EXPORTS PointPickingEvent
85  {
86  public:
87  PointPickingEvent (int idx) : idx_ (idx), idx2_ (-1), x_ (), y_ (), z_ (), x2_ (), y2_ (), z2_ () {}
88  PointPickingEvent (int idx, float x, float y, float z) : idx_ (idx), idx2_ (-1), x_ (x), y_ (y), z_ (z), x2_ (), y2_ (), z2_ () {}
89 
90  PointPickingEvent (int idx1, int idx2, float x1, float y1, float z1, float x2, float y2, float z2) :
91  idx_ (idx1), idx2_ (idx2), x_ (x1), y_ (y1), z_ (z1), x2_ (x2), y2_ (y2), z2_ (z2)
92  {}
93 
94  /** \brief Obtain the ID of a point that the user just clicked on.
95  * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
96  * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
97  * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
98  * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
99  * visualization/tools/pcd_viewer.cpp
100  */
101  inline int
102  getPointIndex () const
103  {
104  return (idx_);
105  }
106 
107  /** \brief Obtain the XYZ point coordinates of a point that the user just clicked on.
108  * \param[out] x the x coordinate of the point that got selected by the user
109  * \param[out] y the y coordinate of the point that got selected by the user
110  * \param[out] z the z coordinate of the point that got selected by the user
111  */
112  inline void
113  getPoint (float &x, float &y, float &z) const
114  {
115  x = x_; y = y_; z = z_;
116  }
117 
118  /** \brief For situations when multiple points are selected in a sequence, return the point coordinates.
119  * \param[out] x1 the x coordinate of the first point that got selected by the user
120  * \param[out] y1 the y coordinate of the first point that got selected by the user
121  * \param[out] z1 the z coordinate of the firts point that got selected by the user
122  * \param[out] x2 the x coordinate of the second point that got selected by the user
123  * \param[out] y2 the y coordinate of the second point that got selected by the user
124  * \param[out] z2 the z coordinate of the second point that got selected by the user
125  * \return true, if two points are available and have been clicked by the user, false otherwise
126  */
127  inline bool
128  getPoints (float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
129  {
130  if (idx2_ == -1)
131  return (false);
132  x1 = x_; y1 = y_; z1 = z_;
133  x2 = x2_; y2 = y2_; z2 = z2_;
134  return (true);
135  }
136 
137  /** \brief For situations where multiple points are selected in a sequence, return the points indices.
138  * \param[out] index_1 index of the first point selected by user
139  * \param[out] index_2 index of the second point selected by user
140  * \return true, if two points are available and have been clicked by the user, false otherwise
141  * \warning If the cloud contains NaNs the index returned by this function will not correspond to the
142  * original indices. To get the correct index either sanitize the input cloud to remove NaNs or use the
143  * PointPickingEvent::getPoint function to get the x,y,z of the picked point and then search the original
144  * cloud for the correct index. An example of how to do this can be found in the pp_callback function in
145  * visualization/tools/pcd_viewer.cpp
146  */
147  inline bool
148  getPointIndices (int &index_1, int &index_2) const
149  {
150  if (idx2_ == -1)
151  return (false);
152  index_1 = idx_;
153  index_2 = idx2_;
154  return (true);
155  }
156 
157  private:
158  int idx_, idx2_;
159 
160  float x_, y_, z_;
161  float x2_, y2_, z2_;
162  };
163  } //namespace visualization
164 } //namespace pcl
165 
166 #endif /* PCL_VISUALIZATION_POINT_PICKING_EVENT_H_ */
167 
bool getPoints(float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
For situations when multiple points are selected in a sequence, return the point coordinates.
PointPickingEvent(int idx1, int idx2, float x1, float y1, float z1, float x2, float y2, float z2)
/brief Class representing 3D point picking events.
virtual ~PointPickingCallback()
Empty destructor.
static PointPickingCallback * New()
int getPointIndex() const
Obtain the ID of a point that the user just clicked on.
PointPickingEvent(int idx, float x, float y, float z)
bool getPointIndices(int &index_1, int &index_2) const
For situations where multiple points are selected in a sequence, return the points indices...
void getPoint(float &x, float &y, float &z) const
Obtain the XYZ point coordinates of a point that the user just clicked on.