[vtkusers] Arrays of vtk objects in C++
Mark Gooding
mark.gooding at gmail.com
Thu Feb 23 07:19:28 EST 2006
Hello,
I noticed the question below in the vtk archives while trying to find
out the answer to the same problem. I thought I'd post my solution in
case it is of help to anyone.
>Jenny Rich lost_bits1110 at hotmail.com
>Thu Apr 22 15:53:25 EDT 2004
>
>Hi
>
>How do I create an array of some vtk type
>say I want an array of vtkImageData?
>
>Normally I would declare
>vtkImageData *image = vtkImageData::New();
>
>but say I want a dynamic 1D array (i.e. i want to use pointer notation),
>then how would I do this?
Under java and vtk4.? it was possible to do
vtkImageData *image = new vtkImageData[25];
but this appears no longer possible. My current solution is to use the
standard template library vector to achieve the same goal. eg.
std::vector<vtkImageData*> image;
for(i=0;i<25;i++){
image.push_back(vtkImageData::New());
}
then at each point I want to use the object:
image.at(index)->doWhatever();
I hope this is of help. If there is a better way to achieve the same
ends (which I'm sure there is) I'd be happy to hear it.
Cheers,
Mark
More information about the vtkusers
mailing list