[vtkusers] Re: C++ and pointeur probleme with vtkActor

Goodwin Lawlor goodwin.lawlor at ucd.ie
Fri Oct 27 10:30:51 EDT 2006


ricca nicola wrote:
> hi,
> 
> I finished my cellulare automata visualisation and it work correctly.
> 
> Now i wish to create a function that update my scene. For that, i use a 
> function named update defined in this way : void update(int**ac, 
> vtkActor *tabActor);
> 
> a is a matrix representing my automata and tabActor is a matrix of 
> vtkActor.
> 
> ac = new int*[nx];
> for (int i = 0; i < nx; i++)ac[i]=new int[ny];
> 
> vtkActor *tabActor[nx][ny];
> 
> The problem come with tabActor. If i define it in the same way of ac, an 
> error is catch.
> So i define like this.
> 
> Now im trying to set tabActor as a parameter of the function.
> 
> Sorry for my english, i link the programme.
> 
> i hope some one have an idea
> 
Hi Ricca,

I'm not exactly sure what you want but I'm guessing you want an array of 
pointers to vtkActor objects

vtkActor **tabActor = new vtkActor* [nx][ny];

for (int i=0; i < nx; i++)
   {
   for (int j=0; j < ny; j++)
     {
     tabActor[i][j] = vtkActor::New();
     }
   }

...
...
// Clean up
for (int i=0; i < nx; i++)
   {
   for (int j=0; j < ny; j++)
     {
     tabActor[i][j]->Delete();
     }
   }

delete [] tabActor;
tabActor = NULL;


A better way to do it, uses smart pointers and a STL vector:

#include <vtkstd/vector>

...
...

// Declare a vector of (nx*ny)smart pointers to vtkActor objects
vtkstd::vector<vtkSmartPointer<vtkActor>> actors(nx*ny);

// Declare an iterator to traverse the above pointers
vtkstd::vector<vtkSmartPointer<vtkActor>>::iterator iter;

for (iter = actors.begin(); iter != actors.end(); iter++)
   {
   *iter = vtkSmartPointer<vtkActor>::New();
   }

...
...

actors.clear();



hth

Goodwin




More information about the vtkusers mailing list