rectangular_frustum_selector.cpp
Go to the documentation of this file.
00001 #include <pcl/apps/cloud_composer/point_selectors/rectangular_frustum_selector.h>
00002 #include <pcl/apps/cloud_composer/point_selectors/selection_event.h>
00003 
00004 namespace pcl
00005 {
00006   namespace cloud_composer
00007   {
00008     vtkStandardNewMacro(RectangularFrustumSelector);
00009   }
00010 }
00011 
00012 pcl::cloud_composer::RectangularFrustumSelector::RectangularFrustumSelector ()
00013   : vtkInteractorStyleRubberBandPick ()
00014 {
00015   selection_complete_event_ = interactor_events::SELECTION_COMPLETE_EVENT;
00016 }
00017 
00018 pcl::cloud_composer::RectangularFrustumSelector::~RectangularFrustumSelector ()
00019 {
00020   
00021 }
00022 
00023 
00024 void
00025 pcl::cloud_composer::RectangularFrustumSelector::OnLeftButtonUp ()
00026 {
00027            
00028   vtkSmartPointer<vtkActor> selected_actor = vtkSmartPointer<vtkActor>::New();
00029   vtkSmartPointer<vtkDataSetMapper> selected_mapper = vtkSmartPointer<vtkDataSetMapper>::New();
00030   selected_actor->SetMapper(selected_mapper);
00031   
00032   vtkInteractorStyleRubberBandPick::OnLeftButtonUp ();
00033  
00034   vtkPlanes* frustum = static_cast<vtkAreaPicker*> (this->GetInteractor ()->GetPicker ())->GetFrustum ();
00035  
00036   vtkSmartPointer<vtkIdFilter> id_filter = vtkSmartPointer<vtkIdFilter>::New ();
00037   id_filter->PointIdsOn ();
00038   
00039   vtkSmartPointer<vtkExtractGeometry> extract_geometry = vtkSmartPointer<vtkExtractGeometry>::New ();
00040   extract_geometry->SetImplicitFunction (frustum);
00041   extract_geometry->SetInputConnection (id_filter->GetOutputPort ());
00042 
00043   vtkSmartPointer<vtkVertexGlyphFilter> glyph_filter = vtkSmartPointer<vtkVertexGlyphFilter>::New ();
00044   glyph_filter->SetInputConnection (extract_geometry->GetOutputPort ());
00045   
00046   vtkSmartPointer<vtkAppendPolyData> append = vtkAppendPolyData::New ();
00047   
00048   pcl::visualization::CloudActorMap::iterator it;
00049   it = actors_->begin ();
00050   QMap < QString, vtkPolyData* > id_selected_data_map;
00051   for (it = actors_->begin (); it != actors_->end (); ++it)
00052   {
00053         pcl::visualization::CloudActor *act = &(*it).second;
00054         vtkMapper* mapper = act->actor->GetMapper ();
00055         vtkDataSet* data = mapper->GetInput ();
00056         vtkPolyData* poly_data = vtkPolyData::SafeDownCast (data);
00057         id_filter->SetInput (poly_data);
00058         //extract_geometry->SetInput (poly_data);
00059           
00060         vtkSmartPointer<vtkPolyData> selected = vtkSmartPointer<vtkPolyData>::New ();
00061         glyph_filter->SetOutput (selected);
00062         glyph_filter->Update ();
00063         selected->SetSource (0);
00064         if (selected->GetNumberOfPoints() > 0)
00065         {
00066           qDebug () << "Selected " << selected->GetNumberOfPoints () << " points.";
00067           id_selected_data_map.insert ( QString::fromStdString ((*it).first), selected);
00068           #if VTK_MAJOR_VERSION <= 5
00069             append->AddInput (selected);
00070           #else // VTK 6
00071             append->AddInputData (selected);
00072           #endif
00073         }
00074         
00075         
00076   }
00077   append->Update ();
00078   vtkSmartPointer<vtkPolyData> all_points = append->GetOutput ();
00079   qDebug () << "Allpoints = " <<all_points->GetNumberOfPoints ();
00080   
00081   selected_mapper->SetInput (all_points);
00082 
00083   selected_mapper->ScalarVisibilityOff ();
00084 
00085   vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast (all_points->GetPointData ()->GetArray ("OriginalIds"));
00086   
00087   selected_actor->GetProperty ()->SetColor (0.0, 1.0, 0.0); //(R,G,B)
00088   selected_actor->GetProperty ()->SetPointSize (3);
00089 
00090   this->CurrentRenderer->AddActor (selected_actor);
00091   this->GetInteractor ()->GetRenderWindow ()->Render ();
00092   this->HighlightProp (NULL);
00093  
00094   if (all_points->GetNumberOfPoints () > 0)
00095   {
00096     SelectionEvent* selected = new SelectionEvent (all_points, selected_actor, selected_mapper, id_selected_data_map, this->CurrentRenderer);
00097     this->InvokeEvent (this->selection_complete_event_, selected);
00098   }
00099 }
00100 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:32:01