|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: histogram_visualizer.hpp 6161 2012-07-05 17:37:29Z rusu $ 00037 * 00038 */ 00039 00040 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_ 00041 #define PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_ 00042 00044 template <typename PointT> bool 00045 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram ( 00046 const pcl::PointCloud<PointT> &cloud, int hsize, 00047 const std::string &id, int win_width, int win_height) 00048 { 00049 RenWinInteractMap::iterator am_it = wins_.find (id); 00050 if (am_it != wins_.end ()) 00051 { 00052 PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ()); 00053 return (false); 00054 } 00055 00056 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New (); 00057 xy_array->SetNumberOfComponents (2); 00058 xy_array->SetNumberOfTuples (hsize); 00059 00060 // Parse the cloud data and store it in the array 00061 double xy[2]; 00062 for (int d = 0; d < hsize; ++d) 00063 { 00064 xy[0] = d; 00065 xy[1] = cloud.points[0].histogram[d]; 00066 xy_array->SetTuple (d, xy); 00067 } 00068 RenWinInteract renwinint; 00069 createActor (xy_array, renwinint, id, win_width, win_height); 00070 00071 // Save the pointer/ID pair to the global window map 00072 wins_[id] = renwinint; 00073 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) 00074 resetStoppedFlag (); 00075 #endif 00076 return (true); 00077 } 00078 00080 template <typename PointT> bool 00081 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram ( 00082 const pcl::PointCloud<PointT> &cloud, 00083 const std::string &field_name, 00084 const int index, 00085 const std::string &id, int win_width, int win_height) 00086 { 00087 if (index < 0 || index >= cloud.points.size ()) 00088 { 00089 PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index); 00090 return (false); 00091 } 00092 00093 // Get the fields present in this cloud 00094 std::vector<sensor_msgs::PointField> fields; 00095 // Check if our field exists 00096 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields); 00097 if (field_idx == -1) 00098 { 00099 PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ()); 00100 return (false); 00101 } 00102 00103 RenWinInteractMap::iterator am_it = wins_.find (id); 00104 if (am_it != wins_.end ()) 00105 { 00106 PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ()); 00107 return (false); 00108 } 00109 00110 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New (); 00111 xy_array->SetNumberOfComponents (2); 00112 xy_array->SetNumberOfTuples (fields[field_idx].count); 00113 00114 // Parse the cloud data and store it in the array 00115 double xy[2]; 00116 for (int d = 0; d < fields[field_idx].count; ++d) 00117 { 00118 xy[0] = d; 00119 //xy[1] = cloud.points[index].histogram[d]; 00120 float data; 00121 memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + d * sizeof (float), sizeof (float)); 00122 xy[1] = data; 00123 xy_array->SetTuple (d, xy); 00124 } 00125 RenWinInteract renwinint; 00126 createActor (xy_array, renwinint, id, win_width, win_height); 00127 00128 // Save the pointer/ID pair to the global window map 00129 wins_[id] = renwinint; 00130 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4)) 00131 resetStoppedFlag (); 00132 #endif 00133 return (true); 00134 } 00135 00137 template <typename PointT> bool 00138 pcl::visualization::PCLHistogramVisualizer::updateFeatureHistogram ( 00139 const pcl::PointCloud<PointT> &cloud, int hsize, 00140 const std::string &id) 00141 { 00142 RenWinInteractMap::iterator am_it = wins_.find (id); 00143 if (am_it == wins_.end ()) 00144 { 00145 PCL_WARN ("[updateFeatureHistogram] A window with id <%s> does not exists!.\n", id.c_str ()); 00146 return (false); 00147 } 00148 RenWinInteract* renwinupd = &wins_[id]; 00149 00150 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New (); 00151 xy_array->SetNumberOfComponents (2); 00152 xy_array->SetNumberOfTuples (hsize); 00153 00154 // Parse the cloud data and store it in the array 00155 double xy[2]; 00156 for (int d = 0; d < hsize; ++d) 00157 { 00158 xy[0] = d; 00159 xy[1] = cloud.points[0].histogram[d]; 00160 xy_array->SetTuple (d, xy); 00161 } 00162 reCreateActor (xy_array, renwinupd, hsize); 00163 return (true); 00164 } 00165 00167 template <typename PointT> bool 00168 pcl::visualization::PCLHistogramVisualizer::updateFeatureHistogram ( 00169 const pcl::PointCloud<PointT> &cloud, const std::string &field_name, const int index, 00170 const std::string &id) 00171 { 00172 if (index < 0 || index >= cloud.points.size ()) 00173 { 00174 PCL_ERROR ("[updateFeatureHistogram] Invalid point index (%d) given!\n", index); 00175 return (false); 00176 } 00177 00178 // Get the fields present in this cloud 00179 std::vector<sensor_msgs::PointField> fields; 00180 // Check if our field exists 00181 int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields); 00182 if (field_idx == -1) 00183 { 00184 PCL_ERROR ("[updateFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ()); 00185 return (false); 00186 } 00187 00188 RenWinInteractMap::iterator am_it = wins_.find (id); 00189 if (am_it == wins_.end ()) 00190 { 00191 PCL_WARN ("[updateFeatureHistogram] A window with id <%s> does not exists!.\n", id.c_str ()); 00192 return (false); 00193 } 00194 RenWinInteract* renwinupd = &wins_[id]; 00195 00196 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New (); 00197 xy_array->SetNumberOfComponents (2); 00198 xy_array->SetNumberOfTuples (fields[field_idx].count); 00199 00200 // Parse the cloud data and store it in the array 00201 double xy[2]; 00202 for (int d = 0; d < fields[field_idx].count; ++d) 00203 { 00204 xy[0] = d; 00205 //xy[1] = cloud.points[index].histogram[d]; 00206 float data; 00207 memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + d * sizeof (float), sizeof (float)); 00208 xy[1] = data; 00209 xy_array->SetTuple (d, xy); 00210 } 00211 00212 reCreateActor (xy_array, renwinupd, cloud.fields[field_idx].count - 1); 00213 return (true); 00214 } 00215 00216 #endif 00217
1.7.6.1