ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ImageVis.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // LOCAL
11 #include <Utils/PCLCloud.h>
12 
14 #include "qPCL.h"
15 
16 // CV_DB_LIB
17 #include <ecvColorTypes.h>
18 #include <ecvDrawContext.h>
19 #include <ecvGenericVisualizer2D.h>
20 
21 // PCL
23 // #include <pcl/visualization/image_viewer.h>
24 
25 // VTK
26 #include <vtkSmartPointer.h>
27 
28 // Forward declarations
29 class vtkRenderer;
30 class vtkRenderWindow;
31 class vtkRenderWindowInteractor;
32 #if VTK_MAJOR_VERSION >= 6
33 class vtkImageSlice;
34 class vtkImageSliceMapper;
35 #endif
36 
37 namespace PclUtils {
40  // Q_OBJECT
41 public:
43 
46  ImageVis(const std::string& viewerName, bool autoInit = false);
53  void setupInteractor(vtkSmartPointer<vtkRenderWindowInteractor> interactor,
55  void setRenderWindow(vtkSmartPointer<vtkRenderWindow> win);
56  vtkSmartPointer<vtkRenderWindow> getRenderWindow();
57  vtkSmartPointer<vtkRenderWindowInteractor> getRenderWindowInteractor();
58  void setRenderWindowInteractor(
61  vtkSmartPointer<vtkRenderer> getRender();
62  void setRender(vtkSmartPointer<vtkRenderer> render);
63 
68  bool contains(const std::string& id) const;
69 
70  Layer* getLayer(const std::string& id);
71  void changeOpacity(double opacity, const std::string& viewID);
72  void hideShowActors(bool visibility, const std::string& viewID);
73 
77  void removeLayer(const std::string& layer_id);
78 
87  LayerMap::iterator createLayer(const std::string& layer_id,
88  int x,
89  int y,
90  int width,
91  int height,
92  double opacity = 0.5,
93  bool fill_box = true);
94 
95  void addRGBImage(const QImage& qimage,
96  unsigned x,
97  unsigned y,
98  const std::string& layer_id,
99  double opacity = 1.0);
100 
106  void addQImage(const QImage& qimage,
107  const std::string& layer_id = "image",
108  double opacity = 1.0);
109 
110  bool addText(unsigned int x,
111  unsigned int y,
112  const std::string& text_string,
113  double r,
114  double g,
115  double b,
116  const std::string& layer_id = "line",
117  double opacity = 1.0,
118  int fontSize = 10,
119  bool bold = false);
120 
121 public:
122  void enable2Dviewer(bool state);
123 
124  std::string pickItem(int x, int y);
125 
126 private:
127  void mouseEventProcess(const pcl::visualization::MouseEvent& event,
128  void* args);
129  boost::signals2::connection m_mouseConnection;
130  std::string pickItem(const pcl::visualization::MouseEvent& event);
131 
132  // Window resize callback
133  static void WindowResizeCallback(vtkObject* caller,
134  unsigned long eventId,
135  void* clientData,
136  void* callData);
137  void onWindowResize();
138  void updateImageScales();
139 #if VTK_MAJOR_VERSION >= 6
140  void updateImageSliceTransform(vtkImageSlice* imageSlice,
141  unsigned width,
142  unsigned height);
143 #endif
144 
145  // Set interactor style to image style (pan/drag instead of rotate)
146  // This prevents crashes by saving original style and checking before
147  // setting
148  void setImageInteractorStyle();
149 
151  vtkSmartPointer<vtkCallbackCommand> m_windowResizeCallback;
152 
153  // Store original interactor style to restore when needed
154  // This prevents crashes when getCamera is called on
155  // PCLVisualizerInteractorStyle
156  vtkSmartPointer<vtkInteractorObserver> m_originalInteractorStyle;
157 
158  // Store original camera parameters to restore when exiting image mode
159  struct CameraParams {
160  bool parallelProjection;
161  double focalPoint[3];
162  double position[3];
163  double viewUp[3];
164  double viewAngle;
165  double parallelScale;
166  double clippingRange[2];
167  };
168  CameraParams m_originalCameraParams;
169  bool m_cameraParamsSaved;
170 
171  // Store image slice info for each layer (ParaView-style)
172  struct ImageInfo {
173  unsigned originalWidth;
174  unsigned originalHeight;
175 #if VTK_MAJOR_VERSION >= 6
178 #endif
179  };
180  std::map<std::string, ImageInfo> m_imageInfoMap;
181 };
182 
183 typedef std::shared_ptr<ImageVis> ImageVisPtr;
184 } // namespace PclUtils
MouseEvent event
int width
int height
math::float3 position
Generic visualizer 2D interface.
ImageViewer is a class for 2D image visualization.
Definition: image_viewer.h:83
normal_z y
normal_z x
std::shared_ptr< ImageVis > ImageVisPtr
Definition: ImageVis.h:183
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
Internal structure describing a layer.