Point Cloud Library (PCL)
1.7.0
|
00001 #ifndef PCL_VISUALIZATION_SIMPLE_BUFF_H 00002 #define PCL_VISUALIZATION_SIMPLE_BUFF_H 00003 00004 #include <pcl/visualization/histogram_visualizer.h> 00005 00006 //#include <pcl/visualization/impl/simple_buffer_visualizer.hpp> 00007 00008 00009 namespace pcl 00010 { 00011 namespace visualization 00012 { 00013 /** \brief PCL simple buffer visualizer main class. 00014 * \note The idea is to offer a simple visualizer that stores and display the last X values as a curve. 00015 * \note The class is based on PCLHistogramVisualizer and pcl::VFHSignature308 for display. 00016 * \note Therefore, the number of values is limited to [2-308]. 00017 * \author Raphael Favier 00018 * \ingroup visualization 00019 */ 00020 class PCL_EXPORTS PCLSimpleBufferVisualizer 00021 { 00022 public: 00023 /** \brief PCL simple buffer visualizer visualizer default constructor. */ 00024 PCLSimpleBufferVisualizer () 00025 { 00026 histo_ = new PCLHistogramVisualizer (); 00027 nb_values_ = 308; 00028 00029 // init values buffer 00030 initValuesAndVisualization(); 00031 } 00032 00033 /** \brief PCL simple buffer visualizer visualizer constructor. 00034 * \param[in] nb_values the number of values stored in the buffer [2 - 308] 00035 */ 00036 PCLSimpleBufferVisualizer (const int nb_values) 00037 { 00038 histo_ = new PCLHistogramVisualizer (); 00039 nb_values_ = nb_values; 00040 00041 if(nb_values_ > 308) 00042 { 00043 PCL_WARN("Maximum number of values can only be 308 (%d given). Setting back to 308. \n"); 00044 nb_values_ = 308; 00045 } 00046 00047 if(nb_values_ <= 1) 00048 { 00049 PCL_WARN("Number of values must be at least 2 (%d given). Setting it to default (308). \n"); 00050 nb_values_ = 308; 00051 } 00052 00053 // init values buffer 00054 initValuesAndVisualization(); 00055 } 00056 00057 /** \brief force display of values. 00058 * \param[in] time - How long (in ms) should the visualization loop be allowed to run 00059 */ 00060 void 00061 displayValues (const int time = 1) 00062 { 00063 // load values into cloud 00064 updateValuesToDisplay(); 00065 00066 // check if we need to automatically handle the backgroud color 00067 if(control_background_color_) 00068 { 00069 if(values_.back() < lowest_threshold_) 00070 { 00071 histo_->setBackgroundColor(255.0, 140.0, 0.0); 00072 } 00073 else 00074 { 00075 histo_->setBackgroundColor(255.0, 255.0, 255.0); 00076 } 00077 } 00078 00079 // add cloud to the visualizer 00080 histo_->updateFeatureHistogram(cloud_, nb_values_); 00081 00082 // check if we need to handle the Y scale ourselves 00083 if (handle_y_scale_) 00084 { 00085 histo_->setGlobalYRange(min_, max_); 00086 } 00087 00088 // spin once 00089 spinOnce(time); 00090 } 00091 00092 /** \brief add a new value at the end of the buffer. 00093 * \param[in] val the float value to add. 00094 */ 00095 void 00096 addValue (const float val) 00097 { 00098 // remove front value 00099 values_.pop_front(); 00100 00101 // push new value in the back 00102 values_.push_back(val); 00103 00104 // udapte min_ and max_ values 00105 if (val > max_) 00106 max_ = val; 00107 00108 if (val < min_) 00109 min_ = val; 00110 } 00111 00112 /** \brief spinOnce method. 00113 * \param[in] time - How long (in ms) should the visualization loop be allowed to run 00114 */ 00115 void 00116 spinOnce (const int time = 1) 00117 { 00118 histo_->spinOnce(time); 00119 } 00120 00121 /** \brief spin method. */ 00122 void 00123 spin () 00124 { 00125 histo_->spin(); 00126 } 00127 00128 /** \brief set background color handling mode. 00129 * \note The point here is to change the background to orange when the latest value is under a threshold. 00130 * \param[in] value if true, automatic mode is enabled. Else, background will be white 00131 * \param[in] threshold value that triggers the background to turn orange if the latest value is lower 00132 * \note This functionality does not work yet at time of commit (see http://dev.pointclouds.org/issues/829) 00133 */ 00134 void 00135 setAutomaticBackgroundColorControl (const bool value = true, const float threshold = 0.0f) 00136 { 00137 control_background_color_ = value; 00138 00139 // if the user sets it back to false, we make sure to reset the bckgrd color to white 00140 if(value == false) 00141 histo_->setBackgroundColor(255.0, 255.0, 255.0); 00142 00143 lowest_threshold_ = threshold; 00144 } 00145 00146 /** \brief set Y scale policy. 00147 * \note If set to true, the minimal and maximal Y values are kept forever. 00148 * \note If set to false, the Y scale is automatically adjusted to the current values (default). 00149 * \param[in] value boolean that enable or disable this policy 00150 */ 00151 void 00152 setManuallyManageYScale (const bool value = false) 00153 { 00154 handle_y_scale_ = value; 00155 } 00156 00157 private: 00158 /** \brief initialize ther buffer that stores the values to zero. 00159 * \note The size is set by private member nb_values_ which is in the range [2-308]. 00160 */ 00161 void 00162 initValuesAndVisualization () 00163 { 00164 cloud_.points.resize(1); 00165 00166 PCL_WARN("Setting buffer size to %d entries.\n", nb_values_); 00167 values_.resize(nb_values_); 00168 00169 // add the cloud to the histogram viewer 00170 histo_->addFeatureHistogram(cloud_, nb_values_); 00171 00172 // init GUI-related variables 00173 initGUIValues(); 00174 } 00175 00176 /** \brief pushes the values contained inside the buffer to the cloud used for visualization. */ 00177 void 00178 updateValuesToDisplay () 00179 { 00180 for(int i = 0 ; i < nb_values_ ; ++i) 00181 { 00182 cloud_.points[0].histogram[i] = values_[i]; 00183 } 00184 } 00185 00186 /** \brief initialize private variables linked to the GUI */ 00187 void 00188 initGUIValues () 00189 { 00190 control_background_color_ = false; 00191 lowest_threshold_ = 0.0f; 00192 00193 handle_y_scale_ = false; 00194 00195 min_ = -1.0f; // numeric_limits<float>::max( ); 00196 max_ = 1.0f; // numeric_limits<float>::min( ); 00197 } 00198 00199 /** \brief visualizer object */ 00200 PCLHistogramVisualizer *histo_; 00201 00202 /** \brief cloud used for visualization */ 00203 PointCloud<VFHSignature308> cloud_; 00204 00205 /** \brief buffer of values */ 00206 std::deque<float> values_; 00207 00208 /** \brief number of values stored in the buffer 00209 * \note ([2-308]) 00210 */ 00211 int nb_values_; 00212 00213 /** \brief boolean used to know if we need to change the backgroud color in case of low values. */ 00214 bool control_background_color_; 00215 00216 /** \brief threshold to turn the background orange if latest value is lower. */ 00217 float lowest_threshold_; 00218 00219 /** \brief boolean used to know if we need to change the backgroud color in case of low values. True means we do it ourselves. */ 00220 bool handle_y_scale_; 00221 00222 /** \brief float tracking the minimal and maximal values ever observed. */ 00223 float min_, max_; 00224 }; 00225 } 00226 } 00227 00228 #endif // PCL_VISUALIZATION_SIMPLE_BUFF_H