[vtkusers] Automatic building of Cubes

Alex Southern mrapsouthern at gmail.com
Sat Feb 12 06:18:42 EST 2011


Hi,

On this subject, I've used vector templates for this purpose before in 
the past and I found that while it gives immediate flexibility to the 
programmer, for large vector arrays in the 1000's -> 100,000s range (not 
necessarily VTK objects), releasing the memory they hold is painfully 
slow compared to the good old new & delete approach.

Also clear() doesn't do what it says on the tin, check here
http://stackoverflow.com/questions/3477715/c-vectorclear

Of course this is only relevant if you have large vector and speed is an 
issue.

Here's how to do without vectors...

     int len;
     vtkSmartPointer<vtkCubeSource>* cubes;

     len = 5;
     cubes = new vtkSmartPointer<vtkCubeSource> [len];

     for (int i = 0; i < len; i++)
     {
         cubes[i] = vtkSmartPointer<vtkCubeSource>::New();
     }

     // rembember to put a delete somewhere
     // when you have finished with the array
     delete []cubes;

Cheers
Alex


On 12.2.2011 6:02, Bill Lorensen wrote:
> Rene,
>
> Try using an std::vector and use smart pointers so that you need not
> worry about deleting them.
>
> Something like
>
> std::vector<vtkSmartPointer<vtkCubeSource>  >  cubes;
> for(i=0; i<= x; i++)
>    {
>     vtkSmartPointer<vtkCubeSource>  cube =
>        vtkSmartPointer<vtkCubeSource>::New();
>     cubes.push_back(cube);
>    }
>
> The wiki example here stores actors in an std::vector
> http://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/VectorOfActors
>
> Bill
> On Fri, Feb 11, 2011 at 10:05 AM, Rene_Wohlgethan
> <rwohlgethan at icqmail.com>  wrote:
>>
>> I´ve got a problem again and i don´t know how to solve it.
>>
>>
>> i want to do a procedure like this
>>
>>
>> for(i=0; i<=x, i++)
>>
>> vtkCubeSource *cube[i] = vtkCubeSource::New();
>>
>> but i can´t do it like this, because cube needs a constant where "i" is.
>>
>>
>> Is there a way to build a Vector or Array of Cubes?
>> --
>> View this message in context: http://vtk.1045678.n5.nabble.com/Automatic-building-of-Cubes-tp3381336p3381336.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list