[vtkusers] vtkImageData Beginner Question

Francois Bertel francois.bertel at kitware.com
Fri Jul 3 19:49:52 EDT 2009

```What do you mean by "size"? If it is the dimension (GetDimensions()),
it is just the number of points/pixels in each dimension.
To get the size in world coordinate you have to get the bounding box:
image->GetBounds(bounds) and then compute the size:

size_x=bounds[1]-bounds[0];
size_y=bounds[3]-bounds[2];
size_z=bounds[5]-bounds[4];

On Fri, Jul 3, 2009 at 7:01 PM, Michael
Jackson<mike.jackson at bluequartz.net> wrote:
> Ok, here is the problem, if I set my extents to 46979 48525 48443 49981 0 0
>  then the size of the image is only 1547 x 1539 pixels. It should be 7433 x
> 7394 pixels. The 1547 x 1539 is the correct _micron_ length of each side but
> this NOT the correct pixel size.
>
>  So I need to create a vtkImage object with a true pixel size of 7433 x 7394
> x 1 that represents a volume in physical space with an origin at 46979,
> 48443, 0 and a maximum at 48525, 49981, 1.
>
> I can not seem to "get there from here"..
>
> ---
> Mike Jackson                 www.bluequartz.net
>
>
>
> On Jul 3, 2009, at 6:13 PM, Francois Bertel wrote:
>
>> Hello,
>>
>> I think you should use SetExtent(), not SetDimensions().
>>
>> because the code of vtkImageData::SetDimensions() is actually:
>>
>>  SetExtent(0, dim[0]-1, 0, dim[1]-1, 0, dim[2]-1);
>>
>> Also Origin is the position in world coordinate of the point of
>> extent(0,0,0): the origin does not have to be part of the dataset, in
>> other words, the dataset extent does not have to start at (0,0,0) and
>> the origin can be outside of the dataset bounding box.
>>
>>
>> On Fri, Jul 3, 2009 at 5:50 PM, Michael
>> Jackson<mike.jackson at bluequartz.net> wrote:
>>>
>>> I have consulted all the vtk and paraview books but I am just coming up
>>> empty on this.
>>>
>>> Here is what I have: A volume of Grayscale pixels being read from a file.
>>> The data represents a volume starting at 46979 Microns in x and 48443
>>> Microns in Y. Each Slice in the z direction represents 1.2 microns. The
>>> "scaling" is 0.207987 Microns/Pixel. The volume is roughly 821 slices by
>>> about 1500 Microns in X and about 1500 Microns in Y.
>>>
>>>  Here is what I would like: This to show in a window (ParaView) so that
>>> when
>>> I set the "Show Axis" all the values are "correct", ie, the values should
>>> start at about 46979,48443,0 and go to their maximum values. Currently I
>>> have the user fill in some text fields that represent the VOI that the
>>> user
>>> would like to render. When the code hits what I have written I either get
>>> a
>>> crash or errors of the type:
>>>
>>> ERROR: In
>>> /Users/Shared/Kitware-CVS/ParaView3/VTK/Filtering/vtkImageData.cxx, line
>>> 2101
>>> vtkImageData (0x122a31b70): GetPointer: Pixel (46979, 48443, 0) not in
>>> current extent: (0, 7432, 0, 7393, 0, 1)
>>>
>>> or
>>>
>>> Warning: In
>>> /Users/Shared/Kitware-CVS/ParaView3/VTK/Filtering/vtkDataSet.cxx, line
>>> 414
>>> vtkImageData (0x12a0e5ee0): Point array RoboMet Voxels with 1 components,
>>> has 0 tuples but there are only -1048158596 points
>>>
>>>
>>> Here is the code that I am using to init the vtkImageData object during
>>> the
>>> pipeline excution:
>>>
>>> int dims[3];
>>> dims[0] = (requestedExtent[1] -
>>> requestedExtent[0])/this->CurrentScalingFactor;
>>> dims[1] = (requestedExtent[3] -
>>> requestedExtent[2])/this->CurrentScalingFactor;
>>> dims[2] =  requestedExtent[5] - requestedExtent[4] + 1;
>>> if (dims[2] == 0)
>>> {
>>> dims[2] = 1;
>>> }
>>> output->SetDimensions(dims[0], dims[1], dims[2]);
>>> output->SetSpacing(this->DataSpacing);
>>> output->SetOrigin(this->DataOrigin);
>>> output->SetScalarType(VTK_TYPE_UINT8);
>>>
>>> //output->SetExtent(requestedExtent);
>>> output->SetNumberOfScalarComponents( 1 );
>>> output->AllocateScalars();
>>> output->GetPointData()->GetScalars()->SetName("RoboMet Voxels");
>>> output->GetPointData()->SetActiveScalars("RoboMet Voxels");
>>>
>>> Here is the values of the requestedExtent when the method gets called:
>>>
>>> 46979 48525 48443 49981 0 0
>>>
>>> Any help is appreciated..
>>> _________________________________________________________
>>> Mike Jackson                  mike.jackson at bluequartz.net
>>> BlueQuartz Software                    www.bluequartz.net
>>> Principal Software Engineer                  Dayton, Ohio
>>>
>>>
>>>
>>> _______________________________________________
>>>
>>> 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
>>>
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>>
>>
>> --
>> François Bertel, PhD  | Kitware Inc. Suite 204
>> 1 (518) 371 3971 x113 | 28 Corporate Drive
>>                     | Clifton Park NY 12065, USA
>> _______________________________________________
>>
>> 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
>>
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
> _______________________________________________
>
> 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
>
> http://www.vtk.org/mailman/listinfo/vtkusers
>

--
François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
| Clifton Park NY 12065, USA

```