1 // ---------------------------------------------------------------------------- 2 // - Open3D: www.open3d.org - 3 // ---------------------------------------------------------------------------- 4 // The MIT License (MIT) 5 // 6 // Copyright (c) 2018 www.open3d.org 7 // 8 // Permission is hereby granted, free of charge, to any person obtaining a copy 9 // of this software and associated documentation files (the "Software"), to deal 10 // in the Software without restriction, including without limitation the rights 11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 // copies of the Software, and to permit persons to whom the Software is 13 // furnished to do so, subject to the following conditions: 14 // 15 // The above copyright notice and this permission notice shall be included in 16 // all copies or substantial portions of the Software. 17 // 18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 24 // IN THE SOFTWARE. 25 // ---------------------------------------------------------------------------- 26 27 #pragma once 28 29 #include <Visualization/Visualizer/Visualizer.h> 30 31 namespace three { 32 33 class SelectionPolygon; 34 class PointCloudPicker; 35 36 class VisualizerWithEditing : public Visualizer 37 { 38 public: 39 enum class SelectionMode { 40 None = 0, 41 Rectangle = 1, 42 Polygon = 2, 43 }; 44 45 public: 46 VisualizerWithEditing(double voxel_size = -1.0, bool use_dialog = true, voxel_size_(voxel_size)47 const std::string &directory = "") : voxel_size_(voxel_size), 48 use_dialog_(use_dialog), default_directory_(directory) {} ~VisualizerWithEditing()49 ~VisualizerWithEditing() override {} 50 VisualizerWithEditing(const VisualizerWithEditing &) = delete; 51 VisualizerWithEditing &operator=(const VisualizerWithEditing &) = delete; 52 53 public: 54 bool AddGeometry(std::shared_ptr<const Geometry> geometry_ptr) override; 55 void PrintVisualizerHelp() override; 56 void UpdateWindowTitle() override; 57 void BuildUtilities() override; 58 int PickPoint(double x, double y); 59 std::vector<size_t> &GetPickedPoints(); 60 61 protected: 62 bool InitViewControl() override; 63 bool InitRenderOption() override; 64 void WindowResizeCallback(GLFWwindow *window, int w, int h) override; 65 void MouseMoveCallback(GLFWwindow* window, double x, double y) override; 66 void MouseScrollCallback(GLFWwindow* window, double x, double y) override; 67 void MouseButtonCallback(GLFWwindow* window, 68 int button, int action, int mods) override; 69 void KeyPressCallback(GLFWwindow *window, 70 int key, int scancode, int action, int mods) override; 71 void InvalidateSelectionPolygon(); 72 void InvalidatePicking(); 73 void SaveCroppingResult(const std::string &filename = ""); 74 75 protected: 76 std::shared_ptr<SelectionPolygon> selection_polygon_ptr_; 77 std::shared_ptr<glsl::SelectionPolygonRenderer> 78 selection_polygon_renderer_ptr_; 79 SelectionMode selection_mode_ = SelectionMode::None; 80 81 std::shared_ptr<PointCloudPicker> pointcloud_picker_ptr_; 82 std::shared_ptr<glsl::PointCloudPickerRenderer> 83 pointcloud_picker_renderer_ptr_; 84 85 std::shared_ptr<const Geometry> original_geometry_ptr_; 86 std::shared_ptr<Geometry> editing_geometry_ptr_; 87 std::shared_ptr<glsl::GeometryRenderer> editing_geometry_renderer_ptr_; 88 89 double voxel_size_ = -1.0; 90 bool use_dialog_ = true; 91 std::string default_directory_; 92 }; 93 94 } // namespace three 95