1 /// 2 /// Copyright (c) 2012, Texas A&M University 3 /// All rights reserved. 4 /// 5 /// Redistribution and use in source and binary forms, with or without 6 /// modification, are permitted provided that the following conditions 7 /// are met: 8 /// 9 /// * Redistributions of source code must retain the above copyright 10 /// notice, this list of conditions and the following disclaimer. 11 /// * Redistributions in binary form must reproduce the above 12 /// copyright notice, this list of conditions and the following 13 /// disclaimer in the documentation and/or other materials provided 14 /// with the distribution. 15 /// * Neither the name of Texas A&M University nor the names of its 16 /// contributors may be used to endorse or promote products derived 17 /// from this software without specific prior written permission. 18 /// 19 /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 /// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 /// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 /// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 /// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 /// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 /// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 /// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 /// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 /// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 /// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 /// POSSIBILITY OF SUCH DAMAGE. 31 /// 32 /// The following software was written as part of a collaboration with the 33 /// University of South Carolina, Interdisciplinary Mathematics Institute. 34 /// 35 36 /// @file cloudTransformTool.h 37 /// @details Provides a tool for changing the view of cloud through a simple 38 /// transformation matrix using inputs from the mouse. 39 /// @author Yue Li and Matthew Hielsberg 40 41 #pragma once 42 43 #include <pcl/apps/point_cloud_editor/toolInterface.h> 44 #include <pcl/apps/point_cloud_editor/localTypes.h> 45 #include <pcl/apps/point_cloud_editor/trackball.h> 46 47 /// @brief The cloud transform tool computes the transform matrix from user's 48 /// mouse operation. It then updates the cloud with the new transform matrices 49 /// to make the cloud be rendered appropriately. 50 class CloudTransformTool : public ToolInterface 51 { 52 public: 53 /// @brief Constructor 54 /// @param cloud_ptr a shared pointer pointing to the cloud object. 55 CloudTransformTool (CloudPtr cloud_ptr); 56 57 /// @brief Destructor 58 ~CloudTransformTool (); 59 60 /// @brief Initialize the current transform with mouse screen coordinates 61 /// and key modifiers. 62 /// @param x the x value of the mouse screen coordinates. 63 /// @param y the y value of the mouse screen coordinates. 64 /// @param modifiers The keyboard modifiers. This function does not make 65 /// use of this parameter. 66 /// @param buttons The state of the mouse buttons. This function does not 67 /// make use of this parameter. 68 void 69 start (int x, int y, BitMask modifiers, BitMask buttons) override; 70 71 /// @brief Updates the transform matrix of this object with mouse screen 72 /// coordinates and key modifiers. 73 /// @details When the LEFT mouse button is down the motion of the mouse is 74 /// used to compute various transforms for the cloud display. Depending on 75 /// the modifiers, the transformation matrix is computed correspondingly. 76 /// When shift is pressed, the motion of mouse indicates a scale. If 77 /// no key modifiers is pressed, the mouse move indicates a rotation. The 78 /// control key pans the display, and the alt key translates along the 79 /// z-axis. 80 /// @param x The x value of the mouse screen coordinates. 81 /// @param y The y value of the mouse screen coordinates. 82 /// @param modifiers the key modifier. SHIFT scales the point cloud 83 /// display. CONTROL pans the point cloud parallel to the view plane. ALT 84 /// moves the point cloud in/out along the z-axis (perpendicular to the 85 /// view plane). If no modifier is pressed then the cloud display is 86 /// rotated. 87 /// @param buttons The LEFT mouse button must be pressed for any transform 88 /// to be generated. All other buttons are ignored. 89 void 90 update (int x, int y, BitMask modifiers, BitMask buttons) override; 91 92 /// @brief Updates the transform matrix of this object with mouse screen 93 /// coordinates and key modifiers. Then right multiplies the cloud_matrix_ 94 /// matrix of the cloud object with the transform matrix of this object. 95 /// @details This function is not required by this tool 96 void end(int,int,BitMask,BitMask)97 end (int, int, BitMask, BitMask) override 98 { 99 } 100 101 /// @brief This function does nothing for this cloud transform tool. 102 void draw()103 draw() const override 104 { 105 } 106 107 private: 108 109 /// generate translate matrix for the xy plane 110 void 111 getTranslateMatrix (int dx, int dy, float* matrix); 112 113 /// generate translate matrix for the z direction 114 void 115 getZTranslateMatrix (int dy, float* matrix); 116 117 /// generate scale matrix 118 void 119 getScaleMatrix (int dy, float* matrix) const; 120 121 /// the transform matrix to be used for updating the coordinates of all 122 /// the points in the cloud 123 float transform_matrix_[MATRIX_SIZE]; 124 125 /// a shared pointer pointing to the cloud object. 126 CloudPtr cloud_ptr_; 127 128 /// the trackball associated with this transform 129 TrackBall trackball_; 130 131 /// last recorded mouse positions 132 int x_, y_; 133 134 /// scaling factor used to control the speed which the display scales the 135 /// point cloud 136 float scale_factor_; 137 138 /// scaling factor used to control the speed which the display translates 139 /// the point cloud 140 float translate_factor_; 141 142 /// default scaling factor 143 static const float DEFAULT_SCALE_FACTOR_; 144 145 /// default translation factor 146 static const float DEFAULT_TRANSLATE_FACTOR_; 147 }; 148