ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CustomContextItem.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 
9 
10 #include <vtkBrush.h>
11 #include <vtkContext2D.h>
12 #include <vtkImageData.h>
13 #include <vtkObjectFactory.h>
14 #include <vtkPen.h>
15 #include <vtkSmartPointer.h>
16 #include <vtkTextProperty.h>
17 
18 namespace PclUtils {
19 namespace context_items {
30 } // namespace context_items
31 } // namespace PclUtils
32 
35  params.resize(2);
36  params[0] = x;
37  params[1] = y;
38 }
39 
41 void PclUtils::context_items::Circle::set(float x, float y, float radius) {
42  params.resize(4);
43  params[0] = x;
44  params[1] = y;
45  params[2] = radius;
46  params[3] = radius - 1;
47 }
48 
51  float y,
52  float w,
53  float h) {
54  params.resize(4);
55  params[0] = x;
56  params[1] = y;
57  params[2] = w;
58  params[3] = h;
59 }
60 
63  float start_y,
64  float end_x,
65  float end_y) {
66  params.resize(4);
67  params[0] = start_x;
68  params[1] = start_y;
69  params[2] = end_x;
70  params[3] = end_y;
71 }
72 
75  float y,
76  const std::string &_text) {
77  params.resize(2);
78  params[0] = x;
79  params[1] = y;
80  text = _text;
81 }
82 
84 bool PclUtils::context_items::Circle::Paint(vtkContext2D *painter) {
85  painter->GetBrush()->SetColor(
86  colors[0], colors[1], colors[2],
87  static_cast<unsigned char>((255.0 * GetOpacity())));
88  painter->GetPen()->SetColor(
89  colors[0], colors[1], colors[2],
90  static_cast<unsigned char>((255.0 * GetOpacity())));
91  painter->DrawWedge(params[0], params[1], params[2], params[3], 0.0, 360.0);
92  return (true);
93 }
94 
96 bool PclUtils::context_items::Disk::Paint(vtkContext2D *painter) {
97  painter->GetBrush()->SetColor(
98  colors[0], colors[1], colors[2],
99  static_cast<unsigned char>((255.0 * GetOpacity())));
100  painter->GetPen()->SetColor(
101  colors[0], colors[1], colors[2],
102  static_cast<unsigned char>((255.0 * GetOpacity())));
103  painter->DrawEllipse(params[0], params[1], params[2], params[2]);
104  return (true);
105 }
106 
108 bool PclUtils::context_items::Rectangle::Paint(vtkContext2D *painter) {
109  painter->GetPen()->SetColor(
110  colors[0], colors[1], colors[2],
111  static_cast<unsigned char>((255.0 * GetOpacity())));
112  float p[] = {params[0], params[1], params[2], params[1], params[2],
113  params[3], params[0], params[3], params[0], params[1]};
114 
115  painter->DrawPoly(p, 5);
116  return (true);
117 }
118 
121  painter->GetBrush()->SetColor(
122  colors[0], colors[1], colors[2],
123  static_cast<unsigned char>((255.0 * GetOpacity())));
124  painter->GetPen()->SetColor(
125  colors[0], colors[1], colors[2],
126  static_cast<unsigned char>((255.0 * GetOpacity())));
127  painter->DrawRect(params[0], params[1], params[2], params[3]);
128  return (true);
129 }
130 
132 bool PclUtils::context_items::Line::Paint(vtkContext2D *painter) {
133  painter->GetPen()->SetColor(
134  colors[0], colors[1], colors[2],
135  static_cast<unsigned char>((255.0 * GetOpacity())));
136  painter->DrawLine(params[0], params[1], params[2], params[3]);
137  return (true);
138 }
139 
141 bool PclUtils::context_items::Polygon::Paint(vtkContext2D *painter) {
142  painter->GetBrush()->SetColor(
143  colors[0], colors[1], colors[2],
144  static_cast<unsigned char>((255.0 * GetOpacity())));
145  painter->GetPen()->SetColor(
146  colors[0], colors[1], colors[2],
147  static_cast<unsigned char>((255.0 * GetOpacity())));
148  painter->DrawPolygon(&params[0], static_cast<int>(params.size() / 2));
149  return (true);
150 }
151 
153 bool PclUtils::context_items::Point::Paint(vtkContext2D *painter) {
154  painter->GetPen()->SetColor(
155  colors[0], colors[1], colors[2],
156  static_cast<unsigned char>((255.0 * GetOpacity())));
157  painter->DrawPoint(params[0], params[1]);
158  return (true);
159 }
160 
162 bool PclUtils::context_items::Points::Paint(vtkContext2D *painter) {
163  painter->GetPen()->SetColor(
164  colors[0], colors[1], colors[2],
165  static_cast<unsigned char>((255.0 * GetOpacity())));
166  painter->DrawPoints(&params[0], static_cast<int>(params.size() / 2));
167  return (true);
168 }
169 
171 bool PclUtils::context_items::Text::Paint(vtkContext2D *painter) {
172  vtkTextProperty *text_property = painter->GetTextProp();
173  text_property->SetColor(255.0 * colors[0], 255.0 * colors[1],
174  255.0 * colors[2]);
175  text_property->SetOpacity(GetOpacity());
176  text_property->SetFontFamilyToArial();
177  text_property->SetFontSize(fontSize_);
178  text_property->SetJustificationToLeft();
179  bold_ ? text_property->BoldOn() : text_property->BoldOff();
180  text_property->ShadowOff();
181  painter->DrawString(params[0], params[1], text.c_str());
182  return (true);
183 }
184 
187  unsigned char g,
188  unsigned char b) {
189  point_colors[0] = r;
190  point_colors[1] = g;
191  point_colors[2] = b;
192 }
193 
196  memcpy(point_colors, rgb, 3 * sizeof(unsigned char));
197 }
198 
200 bool PclUtils::context_items::Markers::Paint(vtkContext2D *painter) {
201  int nb_points(params.size() / 2);
202  if (size <= 0) size = 2.3 * painter->GetPen()->GetWidth();
203 
204  painter->GetPen()->SetWidth(size);
205  painter->GetPen()->SetColor(
206  colors[0], colors[1], colors[2],
207  static_cast<unsigned char>((255.0 * GetOpacity())));
208  painter->DrawPointSprites(0, &params[0], nb_points);
209  painter->GetPen()->SetWidth(1);
210  painter->GetPen()->SetColor(
211  point_colors[0], point_colors[1], point_colors[2],
212  static_cast<unsigned char>((255.0 * GetOpacity())));
213  painter->DrawPointSprites(0, &params[0], nb_points);
214  return (true);
215 }
int size
double colors[3]
normal_z y
normal_z rgb
normal_z x
virtual void set(float _x, float _y, float _r)
virtual bool Paint(vtkContext2D *painter) override
virtual bool Paint(vtkContext2D *painter) override
virtual bool Paint(vtkContext2D *painter) override
virtual void set(float _x_1, float _y_1, float _x_2, float _y_2)
virtual bool Paint(vtkContext2D *painter) override
void setPointColors(unsigned char r, unsigned char g, unsigned char b)
virtual bool Paint(vtkContext2D *painter) override
virtual void set(float _x, float _y)
virtual bool Paint(vtkContext2D *painter) override
virtual bool Paint(vtkContext2D *painter) override
virtual bool Paint(vtkContext2D *painter) override
virtual bool Paint(vtkContext2D *painter) override
virtual void set(float _x, float _y, float _w, float _h)
virtual bool Paint(vtkContext2D *painter) override
virtual void set(float x, float y, const std::string &_text)