00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
00040 #define PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
00041
00042 #include <vtkDoubleArray.h>
00043
00045 template <typename PointT> bool
00046 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
00047 const pcl::PointCloud<PointT> &cloud, int hsize,
00048 const std::string &id, int win_width, int win_height)
00049 {
00050 RenWinInteractMap::iterator am_it = wins_.find (id);
00051 if (am_it != wins_.end ())
00052 {
00053 PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
00054 return (false);
00055 }
00056
00057 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00058 xy_array->SetNumberOfComponents (2);
00059 xy_array->SetNumberOfTuples (hsize);
00060
00061
00062 double xy[2];
00063 for (int d = 0; d < hsize; ++d)
00064 {
00065 xy[0] = d;
00066 xy[1] = cloud.points[0].histogram[d];
00067 xy_array->SetTuple (d, xy);
00068 }
00069 RenWinInteract renwinint;
00070 createActor (xy_array, renwinint, id, win_width, win_height);
00071
00072
00073 wins_[id] = renwinint;
00074 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00075 resetStoppedFlag ();
00076 #endif
00077 return (true);
00078 }
00079
00081 template <typename PointT> bool
00082 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
00083 const pcl::PointCloud<PointT> &cloud,
00084 const std::string &field_name,
00085 const int index,
00086 const std::string &id, int win_width, int win_height)
00087 {
00088 if (index < 0 || index >= cloud.points.size ())
00089 {
00090 PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
00091 return (false);
00092 }
00093
00094
00095 std::vector<pcl::PCLPointField> fields;
00096
00097 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
00098 if (field_idx == -1)
00099 {
00100 PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
00101 return (false);
00102 }
00103
00104 RenWinInteractMap::iterator am_it = wins_.find (id);
00105 if (am_it != wins_.end ())
00106 {
00107 PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
00108 return (false);
00109 }
00110
00111 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00112 xy_array->SetNumberOfComponents (2);
00113 xy_array->SetNumberOfTuples (fields[field_idx].count);
00114
00115
00116 double xy[2];
00117 for (int d = 0; d < fields[field_idx].count; ++d)
00118 {
00119 xy[0] = d;
00120
00121 float data;
00122 memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + d * sizeof (float), sizeof (float));
00123 xy[1] = data;
00124 xy_array->SetTuple (d, xy);
00125 }
00126 RenWinInteract renwinint;
00127 createActor (xy_array, renwinint, id, win_width, win_height);
00128
00129
00130 wins_[id] = renwinint;
00131 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00132 resetStoppedFlag ();
00133 #endif
00134 return (true);
00135 }
00136
00138 template <typename PointT> bool
00139 pcl::visualization::PCLHistogramVisualizer::updateFeatureHistogram (
00140 const pcl::PointCloud<PointT> &cloud, int hsize,
00141 const std::string &id)
00142 {
00143 RenWinInteractMap::iterator am_it = wins_.find (id);
00144 if (am_it == wins_.end ())
00145 {
00146 PCL_WARN ("[updateFeatureHistogram] A window with id <%s> does not exists!.\n", id.c_str ());
00147 return (false);
00148 }
00149 RenWinInteract* renwinupd = &wins_[id];
00150
00151 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00152 xy_array->SetNumberOfComponents (2);
00153 xy_array->SetNumberOfTuples (hsize);
00154
00155
00156 double xy[2];
00157 for (int d = 0; d < hsize; ++d)
00158 {
00159 xy[0] = d;
00160 xy[1] = cloud.points[0].histogram[d];
00161 xy_array->SetTuple (d, xy);
00162 }
00163 reCreateActor (xy_array, renwinupd, hsize);
00164 return (true);
00165 }
00166
00168 template <typename PointT> bool
00169 pcl::visualization::PCLHistogramVisualizer::updateFeatureHistogram (
00170 const pcl::PointCloud<PointT> &cloud, const std::string &field_name, const int index,
00171 const std::string &id)
00172 {
00173 if (index < 0 || index >= cloud.points.size ())
00174 {
00175 PCL_ERROR ("[updateFeatureHistogram] Invalid point index (%d) given!\n", index);
00176 return (false);
00177 }
00178
00179
00180 std::vector<pcl::PCLPointField> fields;
00181
00182 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
00183 if (field_idx == -1)
00184 {
00185 PCL_ERROR ("[updateFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
00186 return (false);
00187 }
00188
00189 RenWinInteractMap::iterator am_it = wins_.find (id);
00190 if (am_it == wins_.end ())
00191 {
00192 PCL_WARN ("[updateFeatureHistogram] A window with id <%s> does not exists!.\n", id.c_str ());
00193 return (false);
00194 }
00195 RenWinInteract* renwinupd = &wins_[id];
00196
00197 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00198 xy_array->SetNumberOfComponents (2);
00199 xy_array->SetNumberOfTuples (fields[field_idx].count);
00200
00201
00202 double xy[2];
00203 for (int d = 0; d < fields[field_idx].count; ++d)
00204 {
00205 xy[0] = d;
00206
00207 float data;
00208 memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + d * sizeof (float), sizeof (float));
00209 xy[1] = data;
00210 xy_array->SetTuple (d, xy);
00211 }
00212
00213 reCreateActor (xy_array, renwinupd, cloud.fields[field_idx].count - 1);
00214 return (true);
00215 }
00216
00217 #endif
00218