[vtkusers] How to display contents of vtkImageData

CLEMENTS, ROBERT rclement at kent.edu
Fri Nov 14 09:45:48 EST 2008


I do  the following to zero out a 16x16 image
vtkImageData grids
grids SetDimensions 16 16 1
grids SetScalarTypeToUnsignedChar

set d 0
for {set i 0} {$i <  16} {incr i} {

for {set p 0} {$p <  16} {incr p} {
grids SetScalarComponentFromFloat $i $p 0 0 $d

}
}


Rob




Hi Elvis,

In Tcl, it is best to get the voxels as a vtkDataArray, since there is
no good way to do pointer math in Tcl like there is in C++.  My Tcl is
a bit rusty, but you would use code like this:

set scalars [imageData GetPointData()] GetScalars()

This will return the vtkDataArray object that holds the pixels. It
provides methods for modifying the values.  You can use the
FillComponent method to clear the whole array in one go, rather than
doing any loops.

Here's a warning, though: if you are trying to clear a vtkImageData
that is the output of a Reader or a Filter, then clearing the voxels
probably won't work, because any VTK class can overwrite it output
whenever the pipeline updates.  It is only useful to modify the voxels
in a vtkImageData that you created from scratch.

    David


On Fri, Nov 14, 2008 at 6:28 AM, Elvis Dowson <elvis.dowson at mac.com> wrote:
> Hi,
> Could someone help me convert the following C++ code snippet to tcl? I want
> to initialize vtkImageData with zeros and I'm not sure how to use pointer
> variables with tcl
> Here is the C++ code snippet
>   for (int y=extent1[2]; y <= extent1[3]; y++)
>     {
>     unsigned char *ptr=static_cast<unsigned char *>(
>       image->GetScalarPointer(extent1[0], y, extent1[4] ));
>     for (int x=extent1[0]; x <= extent1[1]; x++)
>       {
>       *ptr = 0;  ++ptr;
>       *ptr = 0;  ++ptr;
>       *ptr = 0;  ++ptr;
>       }
>     }
>
> I just got this far with the tcl code and I'm not sure how to obtain the
> unsigned char* and manipulate it in the inner loop, not sure if I'm getting
> the pointer variable right.
> Would appreciate it if someone could help me out...
> # Fill image with zeroes
> for {set y 0} {$y <= 10} {incr y 1}
> {
>   set &ptr = imageData GetScalarPointer 0 $y 0
> }
>
> Best regards,
> Elvis Dowson
>
>
> On Nov 13, 2008, at 10:20 PM, David Cole wrote:
>
> By calling SetInput on a vtkImageActor and adding that actor to your
> vtkRenderer...
> http://www.vtk.org/doc/nightly/html/classvtkImageActor.html#12bddf9fcf6e6b877116a3c552d05b39
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the 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