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
00039 template <typename PointT> bool
00040 pcl_visualization::PCLHistogramVisualizer::addFeatureHistogram (
00041 const pcl::PointCloud<PointT> &cloud, int hsize,
00042 const std::string &id, int win_width, int win_height)
00043 {
00044 RenWinInteractMap::iterator am_it = wins_.find (id);
00045 if (am_it != wins_.end ())
00046 {
00047 terminal_tools::print_warn ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
00048 return (false);
00049 }
00050
00051
00052 RenWinInteract renwinint;
00053 renwinint.xy_plot_->SetDataObjectPlotModeToColumns ();
00054 renwinint.xy_plot_->SetXValuesToValue ();
00055
00056 vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
00057 xy_array->SetNumberOfComponents (2);
00058 xy_array->SetNumberOfTuples (hsize);
00059
00060
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 double min_max[2];
00069 xy_array->GetRange (min_max, 1);
00070
00071
00072 vtkSmartPointer<vtkFieldData> field_values = vtkSmartPointer<vtkFieldData>::New ();
00073 field_values->AddArray (xy_array);
00074
00075 vtkSmartPointer<vtkDataObject> field_data = vtkSmartPointer<vtkDataObject>::New ();
00076 field_data->SetFieldData (field_values);
00077
00078 renwinint.xy_plot_->AddDataObjectInput (field_data);
00079
00080 renwinint.xy_plot_->SetPlotColor (0, 1.0, 0.0, 0.0);
00081
00082 renwinint.xy_plot_->SetDataObjectXComponent (0, 0); renwinint.xy_plot_->SetDataObjectYComponent (0, 1);
00083 renwinint.xy_plot_->PlotPointsOn ();
00084
00085
00086 renwinint.xy_plot_->PlotCurveLinesOn ();
00087
00088 renwinint.xy_plot_->SetYTitle (""); renwinint.xy_plot_->SetXTitle ("");
00089 renwinint.xy_plot_->SetYRange (min_max[0], min_max[1]);
00090 renwinint.xy_plot_->SetXRange (0, hsize - 1);
00091
00092
00093 renwinint.xy_plot_->GetProperty ()->SetColor (0, 0, 0);
00094
00095
00096 vtkSmartPointer<vtkTextProperty> tprop = renwinint.xy_plot_->GetTitleTextProperty ();
00097 renwinint.xy_plot_->AdjustTitlePositionOn ();
00098 tprop->SetFontSize (8);
00099 tprop->ShadowOff (); tprop->ItalicOff ();
00100 tprop->SetColor (renwinint.xy_plot_->GetProperty ()->GetColor ());
00101
00102 renwinint.xy_plot_->SetAxisLabelTextProperty (tprop);
00103 renwinint.xy_plot_->SetAxisTitleTextProperty (tprop);
00104 renwinint.xy_plot_->SetNumberOfXLabels (8);
00105 renwinint.xy_plot_->GetProperty ()->SetPointSize (3);
00106 renwinint.xy_plot_->GetProperty ()->SetLineWidth (2);
00107
00108 renwinint.xy_plot_->SetPosition (0, 0);
00109 renwinint.xy_plot_->SetWidth (1); renwinint.xy_plot_->SetHeight (1);
00110
00111
00112 renwinint.ren_->AddActor2D (renwinint.xy_plot_);
00113 renwinint.ren_->SetBackground (1, 1, 1);
00114 renwinint.win_->SetWindowName (id.c_str ());
00115 renwinint.win_->AddRenderer (renwinint.ren_);
00116 renwinint.win_->SetSize (win_width, win_height);
00117 renwinint.win_->SetBorders (1);
00118
00119
00120 vtkSmartPointer<pcl_visualization::PCLHistogramVisualizerInteractorStyle> style_ = vtkSmartPointer<pcl_visualization::PCLHistogramVisualizerInteractorStyle>::New ();
00121 style_->Initialize ();
00122 renwinint.style_ = style_;
00123 renwinint.style_->UseTimersOn ();
00124 renwinint.interactor_ = vtkSmartPointer<PCLVisualizerInteractor>::New ();
00125 renwinint.interactor_->SetRenderWindow (renwinint.win_);
00126 renwinint.interactor_->SetInteractorStyle (renwinint.style_);
00127
00128 renwinint.interactor_->Initialize ();
00129 renwinint.interactor_->CreateRepeatingTimer (5000L);
00130
00131 exit_main_loop_timer_callback_->right_timer_id = -1;
00132 renwinint.interactor_->AddObserver (vtkCommand::TimerEvent, exit_main_loop_timer_callback_);
00133
00134 renwinint.interactor_->AddObserver (vtkCommand::ExitEvent, exit_callback_);
00135
00136
00137 wins_[id] = renwinint;
00138
00139 resetStoppedFlag ();
00140 return (true);
00141 }
00142
00143