Point Cloud Library (PCL)  1.3.1
histogram_visualizer.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: histogram_visualizer.hpp 3000 2011-10-31 22:57:26Z rusu $
00035  *
00036  */
00037 
00038 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
00039 #define PCL_PCL_HISTOGRAM_VISUALIZER_IMPL_H_
00040 
00042 template <typename PointT> bool
00043 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
00044     const pcl::PointCloud<PointT> &cloud, int hsize, 
00045     const std::string &id, int win_width, int win_height)
00046 {
00047   RenWinInteractMap::iterator am_it = wins_.find (id);
00048   if (am_it != wins_.end ())
00049   {
00050     PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
00051     return (false);
00052   }
00053 
00054   vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00055   xy_array->SetNumberOfComponents (2);
00056   xy_array->SetNumberOfTuples (hsize);
00057 
00058   // Parse the cloud data and store it in the array
00059   double xy[2];
00060   for (int d = 0; d < hsize; ++d)
00061   {
00062     xy[0] = d;
00063     xy[1] = cloud.points[0].histogram[d];
00064     xy_array->SetTuple (d, xy);
00065   }
00066   RenWinInteract renwinint;
00067   createActor (xy_array, renwinint, id, win_width, win_height);
00068 
00069   // Save the pointer/ID pair to the global window map
00070   wins_[id] = renwinint;
00071 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00072   resetStoppedFlag ();
00073 #endif
00074   return (true);
00075 }
00076 
00078 template <typename PointT> bool
00079 pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
00080     const pcl::PointCloud<PointT> &cloud, 
00081     const std::string &field_name,
00082     const int index, 
00083     const std::string &id, int win_width, int win_height)
00084 {
00085   if (index < 0 || index >= cloud.points.size ())
00086   {
00087     PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
00088     return (false);
00089   }
00090 
00091   // Get the fields present in this cloud
00092   std::vector<sensor_msgs::PointField> fields;
00093   // Check if our field exists
00094   int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
00095   if (field_idx == -1)
00096   {
00097     PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
00098     return (false);
00099   }
00100 
00101   RenWinInteractMap::iterator am_it = wins_.find (id);
00102   if (am_it != wins_.end ())
00103   {
00104     PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
00105     return (false);
00106   }
00107 
00108   vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00109   xy_array->SetNumberOfComponents (2);
00110   xy_array->SetNumberOfTuples (fields[field_idx].count);
00111 
00112   // Parse the cloud data and store it in the array
00113   double xy[2];
00114   for (int d = 0; d < fields[field_idx].count; ++d)
00115   {
00116     xy[0] = d;
00117     //xy[1] = cloud.points[index].histogram[d];
00118     float data;
00119     memcpy (&data, (const char*)&cloud.points[index] + fields[field_idx].offset + d * sizeof (float), sizeof (float));
00120     xy[1] = data;
00121     xy_array->SetTuple (d, xy);
00122   }
00123   RenWinInteract renwinint;
00124   createActor (xy_array, renwinint, id, win_width, win_height);
00125 
00126   // Save the pointer/ID pair to the global window map
00127   wins_[id] = renwinint;
00128 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00129   resetStoppedFlag ();
00130 #endif
00131   return (true);
00132 }
00133 
00134 #endif
00135 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines