39 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
40 #define PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
42 #include <vtkDoubleArray.h>
48 namespace visualization
51 template <
typename Po
intT>
bool
54 const std::string &
id,
int win_width,
int win_height)
56 auto am_it = wins_.find (
id);
57 if (am_it != wins_.end ())
59 PCL_WARN (
"[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n",
id.c_str ());
64 xy_array->SetNumberOfComponents (2);
65 xy_array->SetNumberOfTuples (hsize);
69 for (
int d = 0; d < hsize; ++d)
72 xy[1] = cloud[0].histogram[d];
73 xy_array->SetTuple (d, xy);
76 createActor (xy_array, renwinint,
id, win_width, win_height);
79 wins_[id] = renwinint;
85 template <
typename Po
intT>
bool
88 const std::string &field_name,
90 const std::string &
id,
int win_width,
int win_height)
92 if (index < 0 || index >= cloud.
size ())
94 PCL_ERROR (
"[addFeatureHistogram] Invalid point index (%d) given!\n", index);
99 std::vector<pcl::PCLPointField> fields;
101 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
104 PCL_ERROR (
"[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
108 auto am_it = wins_.find (
id);
109 if (am_it != wins_.end ())
111 PCL_WARN (
"[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n",
id.c_str ());
116 xy_array->SetNumberOfComponents (2);
117 xy_array->SetNumberOfTuples (fields[field_idx].count);
121 for (
uindex_t d = 0; d < fields[field_idx].count; ++d)
126 memcpy (&data,
reinterpret_cast<const char*
> (&cloud[index]) + fields[field_idx].offset + d *
sizeof (
float),
sizeof (
float));
128 xy_array->SetTuple (d, xy);
131 createActor (xy_array, renwinint,
id, win_width, win_height);
134 wins_[id] = renwinint;
139 template <
typename Po
intT>
bool
142 const std::string &
id)
144 auto am_it = wins_.find (
id);
145 if (am_it == wins_.end ())
147 PCL_WARN (
"[updateFeatureHistogram] A window with id <%s> does not exists!.\n",
id.c_str ());
153 xy_array->SetNumberOfComponents (2);
154 xy_array->SetNumberOfTuples (hsize);
158 for (
int d = 0; d < hsize; ++d)
161 xy[1] = cloud[0].histogram[d];
162 xy_array->SetTuple (d, xy);
169 template <
typename Po
intT>
bool
172 const std::string &
id)
174 if (index < 0 || index >= cloud.
size ())
176 PCL_ERROR (
"[updateFeatureHistogram] Invalid point index (%d) given!\n", index);
181 std::vector<pcl::PCLPointField> fields;
183 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
186 PCL_ERROR (
"[updateFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
190 auto am_it = wins_.find (
id);
191 if (am_it == wins_.end ())
193 PCL_WARN (
"[updateFeatureHistogram] A window with id <%s> does not exists!.\n",
id.c_str ());
199 xy_array->SetNumberOfComponents (2);
200 xy_array->SetNumberOfTuples (fields[field_idx].count);
204 for (std::uint32_t d = 0; d < fields[field_idx].count; ++d)
209 memcpy (&data,
reinterpret_cast<const char*
> (&cloud[index]) + fields[field_idx].offset + d *
sizeof (
float),
sizeof (
float));
211 xy_array->SetTuple (d, xy);
214 reCreateActor (xy_array, renwinupd, cloud.fields[field_idx].count - 1);
PointCloud represents the base class in PCL for storing collections of 3D points.
bool addFeatureHistogram(const pcl::PointCloud< PointT > &cloud, int hsize, const std::string &id="cloud", int win_width=640, int win_height=200)
Add a histogram feature to screen as a separate window, from a cloud containing a single histogram.
bool updateFeatureHistogram(const pcl::PointCloud< PointT > &cloud, int hsize, const std::string &id="cloud")
Update a histogram feature that is already on screen, with a cloud containing a single histogram.
void createActor(const vtkSmartPointer< vtkDoubleArray > &xy_array, RenWinInteract &renwinint, const std::string &id, const int win_width, const int win_height)
Create a 2D actor from the given vtkDoubleArray histogram and add it to the screen.
void reCreateActor(const vtkSmartPointer< vtkDoubleArray > &xy_array, RenWinInteract *renwinupd, const int hsize)
Remove the current 2d actor and create a new 2D actor from the given vtkDoubleArray histogram and add...
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.