simple_buffer_visualizer.h
Go to the documentation of this file.
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   {
00020     class PCL_EXPORTS PCLSimpleBufferVisualizer
00021     {
00022       public:
00024         PCLSimpleBufferVisualizer ()
00025         {
00026           histo_ = new PCLHistogramVisualizer ();
00027           nb_values_ = 308;
00028           
00029           // init values buffer
00030           initValuesAndVisualization();
00031         }
00032         
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 
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   
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     
00115         void
00116         spinOnce (const int time = 1)
00117         {
00118           histo_->spinOnce(time);  
00119         }
00120 
00122         void
00123         spin ()
00124         {
00125           histo_->spin();  
00126         }
00127     
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 
00151         void
00152         setManuallyManageYScale (const bool value = false)
00153         {
00154           handle_y_scale_ = value;  
00155         }
00156     
00157       private:
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     
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     
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     
00200         PCLHistogramVisualizer *histo_;
00201     
00203         PointCloud<VFHSignature308> cloud_;
00204     
00206         std::deque<float> values_;
00207      
00211         int nb_values_;
00212     
00214         bool control_background_color_;
00215     
00217         float lowest_threshold_;
00218 
00220         bool handle_y_scale_;
00221     
00223         float min_, max_;
00224     };    
00225   }  
00226 }
00227 
00228 #endif // PCL_VISUALIZATION_SIMPLE_BUFF_H


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:33:37