The following code works correctly, and produces <a href="http://rpi.edu/~doriad/test_ok.vtk">rpi.edu/~doriad/test_ok.vtk</a> (there was a few more lines to set 3 voxels to non-zero values). Visualized with 'representation=slice' in paraview, the first slice is uniform in color (should be all 0 except one corner pixel)<br>
<br>typedef itk::Image< float, 3 > ImageType;<br> ImageType::Pointer image = ImageType::New();<br> <br> ImageType::IndexType start;<br> start[0] = 0; // first index on X<br> start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br> <br> ImageType::SizeType size;<br> size[0] = 20; // size along X<br> size[1] = 20; // size along Y<br> size[2] = 20; // size along Z<br> <br> ImageType::RegionType region;<br>
region.SetSize( size );<br> region.SetIndex( start );<br> image->SetRegions( region );<br> <br> image->Allocate();<br> <br> ImageType::SpacingType spacing;<br> spacing[0] = .5;<br> spacing[1] = .5;<br>
spacing[2] = .5;<br> image->SetSpacing(spacing);<br><br><br>However, if the spacing setting is moved to before the allocate(), the z=0 voxels are not uniformly zero (again, via visualization in paraview) <a href="http://www.rpi.edu/~doriad/test_bad.vtk">http://www.rpi.edu/~doriad/test_bad.vtk</a><br>
<br><br>
typedef itk::Image< float, 3 > ImageType;<br>
ImageType::Pointer image = ImageType::New();<br>
<br>
ImageType::IndexType start;<br>
start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br>
<br>
ImageType::SizeType size;<br>
size[0] = 20; // size along X<br>
size[1] = 20; // size along Y<br>
size[2] = 20; // size along Z<br>
<br>
ImageType::RegionType region;<br>
region.SetSize( size );<br>
region.SetIndex( start );<br>
image->SetRegions( region );<br>
<br>
//this block is now moved BEFORE allocate<br>
ImageType::SpacingType spacing;<br>
spacing[0] = .5;<br>
spacing[1] = .5;<br>
spacing[2] = .5;<br>
image->SetSpacing(spacing);<br>
<br>
image->Allocate();<br><br><br>Is it supposed to work like that? (i.e. you have to allocate() the image before you set it's properties like spacing/origin?). Also, is there a way to initialize the image so all pixels have a constant non-zero value? I can post the entire code in a file if necessary, but the problem seemed localized to this bit.<br>
<br clear="all">Thanks,<br><br>David<br>