VTK/Tutorials/Extents: Difference between revisions
Daviddoria (talk | contribs) (Created page with '==Extents== The extent of a dataset is a set of 6 integers. It says what the first and last pixel indices are in each of the three directions. E.g. <source lang="cpp> int exten…') |
m (→Bounds) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
==Extents== | ==Extents== | ||
The extent of a dataset is a set of 6 integers. It says what the first and last pixel indices are in each of the three directions. E.g. | The extent of a dataset is a set of 6 integers. It says what the first and last pixel indices are in each of the three directions. E.g. | ||
<source lang="cpp> | <source lang="cpp"> | ||
int extent[6] = { i_min, i_max, j_min, j_max, k_min, k_max }; | int extent[6] = { i_min, i_max, j_min, j_max, k_min, k_max }; | ||
</source> | </source> | ||
Line 9: | Line 9: | ||
==Bounds== | ==Bounds== | ||
The Bounds of an image are | The Bounds of an image are | ||
<source lang="cpp> | <source lang="cpp"> | ||
double bounds[6] = { i_min*Spacing[0] + Origin[0], i_max*Spacing[0] + Origin[0], | double bounds[6] = { i_min*Spacing[0] + Origin[0], i_max*Spacing[0] + Origin[0], | ||
j_min*Spacing[1] + Origin[1], j_max*Spacing[1] + Origin[1], | j_min*Spacing[1] + Origin[1], j_max*Spacing[1] + Origin[1], | ||
Line 15: | Line 15: | ||
</source> | </source> | ||
You can't directly set the bounds. First you need to decide how many pixels across | You can't directly set the bounds. First you need to decide how many pixels across your image will be (i.e. what the extent should be), and then you must find the origin and spacing that will produce the bounds that you need from the extent that you have. This is simple algebra. | ||
In general, always set the extent to start at zero, e.g. [0, 9, 0, 9, 0, 9] for a 10x10x10 image. Calling SetDimensions(10,10,10) does | In general, always set the extent to start at zero, e.g. [0, 9, 0, 9, 0, 9] for a 10x10x10 image. Calling SetDimensions(10,10,10) does | ||
exactly the same thing as SetExtent(0,9,0,9,0,9) but you should always do the latter to be explicit about where your extent starts. | exactly the same thing as SetExtent(0,9,0,9,0,9) but you should always do the latter to be explicit about where your extent starts. |
Latest revision as of 19:03, 25 April 2014
Extents
The extent of a dataset is a set of 6 integers. It says what the first and last pixel indices are in each of the three directions. E.g. <source lang="cpp"> int extent[6] = { i_min, i_max, j_min, j_max, k_min, k_max }; </source>
VTK images (and grids) do not always start at (i,j,k) = (0,0,0). They can start anywhere. They can even start at negative indices. One of the beautiful things about the VTK streaming pipeline is that VTK can take just one slice of an image e.g. at k=10 and pass just that one slice along the pipeline.
Bounds
The Bounds of an image are <source lang="cpp"> double bounds[6] = { i_min*Spacing[0] + Origin[0], i_max*Spacing[0] + Origin[0],
j_min*Spacing[1] + Origin[1], j_max*Spacing[1] + Origin[1], k_min*Spacing[2] + Origin[2], k_max*Spacing[2] + Origin[2] };
</source>
You can't directly set the bounds. First you need to decide how many pixels across your image will be (i.e. what the extent should be), and then you must find the origin and spacing that will produce the bounds that you need from the extent that you have. This is simple algebra.
In general, always set the extent to start at zero, e.g. [0, 9, 0, 9, 0, 9] for a 10x10x10 image. Calling SetDimensions(10,10,10) does exactly the same thing as SetExtent(0,9,0,9,0,9) but you should always do the latter to be explicit about where your extent starts.