Point Cloud Library (PCL)  1.7.1
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  inline int
96  getPointIndex () const
97  {
98  return (idx_);
99  }
100 
101  /** \brief Obtain the XYZ point coordinates of a point that the user just clicked on.
102  * \param[out] x the x coordinate of the point that got selected by the user
103  * \param[out] y the y coordinate of the point that got selected by the user
104  * \param[out] z the z coordinate of the point that got selected by the user
105  */
106  inline void
107  getPoint (float &x, float &y, float &z) const
108  {
109  x = x_; y = y_; z = z_;
110  }
111 
112  /** \brief For situations when multiple points are selected in a sequence, return the point coordinates.
113  * \param[out] x1 the x coordinate of the first point that got selected by the user
114  * \param[out] y1 the y coordinate of the first point that got selected by the user
115  * \param[out] z1 the z coordinate of the firts point that got selected by the user
116  * \param[out] x2 the x coordinate of the second point that got selected by the user
117  * \param[out] y2 the y coordinate of the second point that got selected by the user
118  * \param[out] z2 the z coordinate of the second point that got selected by the user
119  * \return true, if two points are available and have been clicked by the user, false otherwise
120  */
121  inline bool
122  getPoints (float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
123  {
124  if (idx2_ == -1)
125  return (false);
126  x1 = x_; y1 = y_; z1 = z_;
127  x2 = x2_; y2 = y2_; z2 = z2_;
128  return (true);
129  }
130 
131  /** \brief For situations where multiple points are selected in a sequence, return the points indices.
132  * \param[out] index_1 index of the first point selected by user
133  * \param[out] index_2 index of the second point selected by user
134  * \return true, if two points are available and have been clicked by the user, false otherwise
135  */
136  inline bool
137  getPointIndices (int &index_1, int &index_2) const
138  {
139  if (idx2_ == -1)
140  return (false);
141  index_1 = idx_;
142  index_2 = idx2_;
143  return (true);
144  }
145 
146  private:
147  int idx_, idx2_;
148 
149  float x_, y_, z_;
150  float x2_, y2_, z2_;
151  };
152  } //namespace visualization
153 } //namespace pcl
154 
155 #endif /* PCL_VISUALIZATION_POINT_PICKING_EVENT_H_ */
156