[vtkusers] Storing actors into memory C++

chasank chasank at gmail.com
Sat Jan 10 20:41:22 EST 2015


Hi again,

You're welcome. First of all you did not have to write any class structure
for storing vtkActor instances. I did not understand purpose of PickerClass
I'll ignore it. With your structure you may improve your classes as follows

class Actor
{

   public:
   Actor(vtkProp* prop)
   {
      this.prop = prop;
   }
 
   // Control functions consider adding a method that takes vtkImageProperty
reference.
   void reset();
   void setColour(); 
   void setOpacity();
   double getOpacity();
   ..

   protected:

   vtkProp* prop;
   
}

class ScreenObjects
{

   public:
   ScreenObjects(); 
   ~ScreenObjects();
   void addObject(vtkProp* prop)
   {
       Actor* actor = new Actor(prop);
       this.actors.push_back(actor);
   }

   Actor* removeObject()
   {
      return this->actors.pop_back(); // Takes the reference of object and
removes it from vector.
   }

   vtkPropCollection* getCollection() // get all of the actors as a
collection
   {
       vtkPropCollection *collection = vtkPropCollection::New();

       std::vector< Actor* >::iterator it = this->actors.begin();

      for( it; it != this->actors.end(); ++it)
      {
          collection->AddItem(*it);
      }
      
       return collection;
   }

  protected:
  std::vector< Actor* > actors;
}

- In your main program you may cast dynamically to children objects of base
vtkProp such as;

vtkImageSlice* slice = dynamic_cast< vtkImageSlice*
>(screenObjects->removeObject());

- For adding your actors to renderer;

vtkPropCollection* collection = screenObjects->getCollection();
collection->InitTraversal();

vtkProp* prop;

while (prop = collection->GetNextProp())
{
  renderer->AddViewProp(prop);
}




--
View this message in context: http://vtk.1045678.n5.nabble.com/Storing-actors-into-memory-C-tp5729971p5730062.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list