object.cpp
Go to the documentation of this file.
00001 // PCL
00002 #include <pcl/outofcore/visualization/object.h>
00003 #include <pcl/outofcore/visualization/scene.h>
00004 
00005 // Operators
00006 // -----------------------------------------------------------------------------
00007 Object::Object (std::string name)
00008 {
00009   name_ = name;
00010 
00011   actors_ = vtkSmartPointer<vtkActorCollection>::New ();
00012 }
00013 
00014 // Accessors
00015 // -----------------------------------------------------------------------------
00016 std::string
00017 Object::getName () const
00018 {
00019   return name_;
00020 }
00021 
00022 void
00023 Object::setName (std::string name)
00024 {
00025   name_ = name;
00026 }
00027 
00028 vtkSmartPointer<vtkActorCollection>
00029 Object::getActors ()
00030 {
00031   return actors_;
00032 }
00033 
00034 void
00035 Object::render (vtkRenderer* renderer)
00036 {
00037   boost::mutex::scoped_lock lock (actors_mutex_);
00038   // Iterate over the objects actors
00039   actors_->InitTraversal ();
00040   for (vtkIdType i = 0; i < actors_->GetNumberOfItems (); i++)
00041   {
00042     vtkActor* actor = actors_->GetNextActor ();
00043 
00044     // If the actor hasn't been added to the renderer add it
00045     std::set<vtkRenderer*>::iterator renderer_it;
00046     renderer_it = associated_renderers_[actor].find (renderer);
00047     if (renderer_it == associated_renderers_[actor].end ())
00048     {
00049       associated_renderers_[actor].insert (renderer);
00050       renderer->AddActor (actor);
00051     }
00052   }
00053 }
00054 
00055 bool
00056 Object::hasActor (vtkActor *actor)
00057 {
00058   boost::mutex::scoped_lock lock (actors_mutex_);
00059 
00060   return actors_->IsItemPresent (actor);
00061 }
00062 
00063 void
00064 Object::addActor (vtkActor *actor)
00065 {
00066 //  Scene::instance ()->lock ();
00067   boost::mutex::scoped_lock lock (actors_mutex_);
00068 
00069   if (!actors_->IsItemPresent (actor))
00070     actors_->AddItem (actor);
00071 
00072   // If the actor doesn't exist in the associated_renderers_ map add it
00073   std::map<vtkActor*, std::set<vtkRenderer*> >::iterator actor_it;
00074   actor_it = associated_renderers_.find (actor);
00075   if (actor_it == associated_renderers_.end ())
00076   {
00077     associated_renderers_[actor] = std::set<vtkRenderer*> ();
00078   }
00079 //  Scene::instance ()->unlock ();
00080 
00081 //  Scene *scene = Scene::instance();
00082 //  std::vector<Viewport*> viewports = scene->getViewports();
00083 //  for(int i=0; i < viewports.size(); i++)
00084 //  {
00085 //
00086 //    vtkRenderer *renderer = viewports[i]->getRenderer();
00087 //    // If the actor hasn't been added to the renderer add it
00088 //    std::set<vtkRenderer*>::iterator renderer_it;
00089 //    renderer_it = associated_renderers_[actor].find(renderer);
00090 //    if (renderer_it == associated_renderers_[actor].end())
00091 //    {
00092 //      associated_renderers_[actor].insert(renderer);
00093 //      renderer->AddActor(actor);
00094 //    }
00095 //  }
00096 }
00097 
00098 void
00099 Object::removeActor (vtkActor *actor)
00100 {
00101 //  Scene::instance ()->lock ();
00102   //std::cout << "Removing Actor" << std::endl;
00103   boost::mutex::scoped_lock lock (actors_mutex_);
00104   actors_->RemoveItem (actor);
00105 
00106   std::map<vtkActor*, std::set<vtkRenderer*> >::iterator actor_it;
00107   actor_it = associated_renderers_.find (actor);
00108 
00109   if (actor_it != associated_renderers_.end ())
00110   {
00111     std::set<vtkRenderer*>::iterator renderer_it;
00112     for (renderer_it = associated_renderers_[actor].begin (); renderer_it != associated_renderers_[actor].end ();
00113         renderer_it++)
00114     {
00115       (*renderer_it)->RemoveActor (actor);
00116     }
00117     associated_renderers_.erase (actor);
00118   }
00119   //std::cout << "Removing Actor - DONE" << std::endl;
00120 //  Scene::instance ()->unlock ();
00121 }


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