ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pcl_context_item.cpp
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 #include <vtkBrush.h>
9 #include <vtkContext2D.h>
10 #include <vtkImageData.h>
11 #include <vtkObjectFactory.h>
12 #include <vtkPen.h>
13 #include <vtkSmartPointer.h>
14 #include <vtkTextProperty.h>
15 
16 // clang-format off
18 // clang-format on
19 
20 namespace pcl {
21 namespace visualization {
22 // Standard VTK macro for *New ()
25 namespace context_items {
36 } // namespace context_items
37 } // namespace visualization
38 } // namespace pcl
39 
42  unsigned char g,
43  unsigned char b) {
44  colors[0] = r;
45  colors[1] = g;
46  colors[2] = b;
47 }
48 
51  float _y,
52  vtkImageData* _image) {
53  x = _x;
54  y = _y;
55  image->DeepCopy(_image);
56 }
57 
60  SetOpacity(1.0);
61  painter->DrawImage(x, y, image);
62  return (true);
63 }
64 
67  params.resize(2);
68  params[0] = x;
69  params[1] = y;
70 }
71 
74  float y,
75  float radius) {
76  params.resize(4);
77  params[0] = x;
78  params[1] = y;
79  params[2] = radius;
80  params[3] = radius - 1;
81 }
82 
85  float y,
86  float w,
87  float h) {
88  params.resize(4);
89  params[0] = x;
90  params[1] = y;
91  params[2] = w;
92  params[3] = h;
93 }
94 
97  float start_y,
98  float end_x,
99  float end_y) {
100  params.resize(4);
101  params[0] = start_x;
102  params[1] = start_y;
103  params[2] = end_x;
104  params[3] = end_y;
105 }
106 
109  float y,
110  const std::string& _text) {
111  params.resize(2);
112  params[0] = x;
113  params[1] = y;
114  text = _text;
115 }
116 
119  painter->GetBrush()->SetColor(
120  colors[0], colors[1], colors[2],
121  static_cast<unsigned char>((255.0 * GetOpacity())));
122  painter->GetPen()->SetColor(
123  colors[0], colors[1], colors[2],
124  static_cast<unsigned char>((255.0 * GetOpacity())));
125  painter->DrawWedge(params[0], params[1], params[2], params[3], 0.0, 360.0);
126  return (true);
127 }
128 
131  painter->GetBrush()->SetColor(
132  colors[0], colors[1], colors[2],
133  static_cast<unsigned char>((255.0 * GetOpacity())));
134  painter->GetPen()->SetColor(
135  colors[0], colors[1], colors[2],
136  static_cast<unsigned char>((255.0 * GetOpacity())));
137  painter->DrawEllipse(params[0], params[1], params[2], params[2]);
138  return (true);
139 }
140 
143  vtkContext2D* painter) {
144  painter->GetPen()->SetColor(
145  colors[0], colors[1], colors[2],
146  static_cast<unsigned char>((255.0 * GetOpacity())));
147  float p[] = {params[0], params[1], params[2], params[1], params[2],
148  params[3], params[0], params[3], params[0], params[1]};
149 
150  painter->DrawPoly(p, 5);
151  return (true);
152 }
153 
156  vtkContext2D* painter) {
157  painter->GetBrush()->SetColor(
158  colors[0], colors[1], colors[2],
159  static_cast<unsigned char>((255.0 * GetOpacity())));
160  painter->GetPen()->SetColor(
161  colors[0], colors[1], colors[2],
162  static_cast<unsigned char>((255.0 * GetOpacity())));
163  painter->DrawRect(params[0], params[1], params[2], params[3]);
164  return (true);
165 }
166 
169  painter->GetPen()->SetColor(
170  colors[0], colors[1], colors[2],
171  static_cast<unsigned char>((255.0 * GetOpacity())));
172  painter->DrawLine(params[0], params[1], params[2], params[3]);
173  return (true);
174 }
175 
178  painter->GetBrush()->SetColor(
179  colors[0], colors[1], colors[2],
180  static_cast<unsigned char>((255.0 * GetOpacity())));
181  painter->GetPen()->SetColor(
182  colors[0], colors[1], colors[2],
183  static_cast<unsigned char>((255.0 * GetOpacity())));
184  painter->DrawPolygon(&params[0], static_cast<int>(params.size() / 2));
185  return (true);
186 }
187 
190  painter->GetPen()->SetColor(
191  colors[0], colors[1], colors[2],
192  static_cast<unsigned char>((255.0 * GetOpacity())));
193  painter->DrawPoint(params[0], params[1]);
194  return (true);
195 }
196 
199  painter->GetPen()->SetColor(
200  colors[0], colors[1], colors[2],
201  static_cast<unsigned char>((255.0 * GetOpacity())));
202  painter->DrawPoints(&params[0], static_cast<int>(params.size() / 2));
203  return (true);
204 }
205 
208  vtkTextProperty* text_property = painter->GetTextProp();
209  text_property->SetColor(255.0 * colors[0], 255.0 * colors[1],
210  255.0 * colors[2]);
211  text_property->SetOpacity(GetOpacity());
212  text_property->SetFontFamilyToArial();
213  text_property->SetFontSize(10);
214  text_property->SetJustificationToLeft();
215  text_property->BoldOff();
216  text_property->ShadowOff();
217  painter->DrawString(params[0], params[1], text.c_str());
218  return (true);
219 }
220 
223  unsigned char r, unsigned char g, unsigned char b) {
224  point_colors[0] = r;
225  point_colors[1] = g;
226  point_colors[2] = b;
227 }
228 
231  unsigned char rgb[3]) {
232  memcpy(point_colors, rgb, 3 * sizeof(unsigned char));
233 }
234 
237  int nb_points(params.size() / 2);
238  if (size <= 0) size = 2.3 * painter->GetPen()->GetWidth();
239 
240  painter->GetPen()->SetWidth(size);
241  painter->GetPen()->SetColor(
242  colors[0], colors[1], colors[2],
243  static_cast<unsigned char>((255.0 * GetOpacity())));
244  painter->DrawPointSprites(nullptr, &params[0], nb_points);
245  painter->GetPen()->SetWidth(1);
246  painter->GetPen()->SetColor(
247  point_colors[0], point_colors[1], point_colors[2],
248  static_cast<unsigned char>((255.0 * GetOpacity())));
249  painter->DrawPointSprites(nullptr, &params[0], nb_points);
250  return (true);
251 }
252 
256 }
std::shared_ptr< core::Tensor > image
int size
double colors[3]
normal_z y
normal_z rgb
normal_z x
vtkStandardNewMacro(ImageViewerInteractorStyle)
void set(float _x, float _y, vtkImageData *_image)
bool Paint(vtkContext2D *painter) override
void setColors(unsigned char r, unsigned char g, unsigned char b)
virtual void set(float _x, float _y, float _r)
bool Paint(vtkContext2D *painter) override
bool Paint(vtkContext2D *painter) override
bool Paint(vtkContext2D *painter) override
virtual void set(float _x_1, float _y_1, float _x_2, float _y_2)
bool Paint(vtkContext2D *painter) override
void setPointColors(unsigned char r, unsigned char g, unsigned char b)
bool Paint(vtkContext2D *painter) override
virtual void set(float _x, float _y)
bool Paint(vtkContext2D *painter) override
bool Paint(vtkContext2D *painter) override
bool Paint(vtkContext2D *painter) override
virtual void set(float _x, float _y, float _w, float _h)
bool Paint(vtkContext2D *painter) override
bool Paint(vtkContext2D *painter) override
virtual void set(float x, float y, const std::string &_text)