<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-09-11 16:17 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a target="_blank" href="mailto:elvis.stansvik@orexplore.com">elvis.stansvik@orexplore.com</a>></span>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">2016-09-09 11:08 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a target="_blank" href="mailto:elvis.stansvik@orexplore.com">elvis.stansvik@orexplore.com</a>></span><wbr>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>2016-09-09 11:04 GMT+02:00 Elvis Stansvik <span dir="ltr"><<a target="_blank" href="mailto:elvis.stansvik@orexplore.com">elvis.stansvik@orexplore.com</a>></span><wbr>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div><div><div><div>Hi all,<br><br></div>I have a hopefully simple question:<br><br></div>Since the bounds of a vtkImageData start and end in the center of the corner voxels, if I want to place two volumes in the world adjacent (right next to eachother) using SetPosition, will I have to compensate for this, to avoid the volumes overlapping by 0.5*spacing_of_first_volume + 0.5*spacing_of_second_volume ?<br></div></div></div></blockquote><div><br></div></span><div>I guess this is really two questions:<br><br></div><div>1) Is the (visual, in world) size of a volume in the first dimension (extent[1] - extent[0]) * spacing[2] or (extent[1] - extent[0] + 1) * spacing[2].<br>2) Will SetPosition move the volume such that the center of the corner voxel is at the given world position?<br></div></div></div></div></blockquote><div><br></div></span><div>Okay, I made the following small test program:<br><br>#include <iostream><br><br>#include <vtkColorTransferFunction.h><br>#include <vtkGPUVolumeRayCastMapper.h><br>#include <vtkPiecewiseFunction.h><br>#include <vtkRenderer.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>#include <vtkSmartPointer.h><br>#include <vtkVolume.h><br>#include <vtkVolumeProperty.h><br>#include <vtkXMLImageDataReader.h><br>#include <vtkCubeAxesActor.h><br>#include <vtkTextProperty.h><br><br>int main(int argc, char* argv[])<br>{<br>Â if (argc != 2) {<br>Â Â Â std::cerr << "Usage: " << argv[0] << "<file>" << std::endl;<br>Â Â Â return 1;<br>Â }<br>Â <br>Â auto reader = vtkSmartPointer<<wbr>vtkXMLImageDataReader>::New();<br>Â reader->SetFileName(argv[1]);<br>Â reader->Update();<br>Â <br>Â auto mapper = vtkSmartPointer<<wbr>vtkGPUVolumeRayCastMapper>::<wbr>New();<br>Â mapper->SetInputConnection(<wbr>reader->GetOutputPort());<br>Â <br>Â auto color = vtkSmartPointer<<wbr>vtkColorTransferFunction>::<wbr>New();<br>Â color->AddRGBPoint(0.0, 0.0, 0.0, 1.0); // blue<br>Â color->AddRGBPoint(1.0, 0.0, 0.0, 1.0); // blue<br><br>Â auto opacity = vtkSmartPointer<<wbr>vtkPiecewiseFunction>::New();<br>Â opacity->AddPoint(0.0, 0.4);<br>Â opacity->AddPoint(1.0, 0.4);<br><br>Â auto property = vtkSmartPointer<<wbr>vtkVolumeProperty>::New();<br>Â property->SetColor(color);<br>Â property->SetScalarOpacity(<wbr>opacity);<br><br>Â auto volume = vtkSmartPointer<vtkVolume>::<wbr>New();<br>Â volume->SetMapper(mapper);<br>Â volume->SetProperty(property);<br>Â volume->SetPosition(0, 0, 0);<br><br>Â auto renderer = vtkSmartPointer<vtkRenderer>::<wbr>New();<br>Â renderer->AddVolume(volume);<br><br>Â // Cube axes actor<br>Â auto cubeAxesActor = vtkSmartPointer<<wbr>vtkCubeAxesActor>::New();<br>Â cubeAxesActor->SetBounds(0, 4, 0, 4, 0, 4);<br>Â cubeAxesActor->SetCamera(<wbr>renderer->GetActiveCamera());<br>Â cubeAxesActor-><wbr>GetTitleTextProperty(0)-><wbr>SetColor(1.0, 0.0, 0.0);<br>Â cubeAxesActor-><wbr>GetLabelTextProperty(0)-><wbr>SetColor(1.0, 0.0, 0.0);<br>Â cubeAxesActor-><wbr>GetTitleTextProperty(1)-><wbr>SetColor(0.0, 1.0, 0.0);<br>Â cubeAxesActor-><wbr>GetLabelTextProperty(1)-><wbr>SetColor(0.0, 1.0, 0.0);<br>Â cubeAxesActor-><wbr>GetTitleTextProperty(2)-><wbr>SetColor(0.0, 0.0, 1.0);<br>Â cubeAxesActor-><wbr>GetLabelTextProperty(2)-><wbr>SetColor(0.0, 0.0, 1.0);<br>Â cubeAxesActor-><wbr>DrawXGridlinesOn();<br>Â cubeAxesActor-><wbr>DrawYGridlinesOn();<br>Â cubeAxesActor-><wbr>DrawZGridlinesOn();<br>Â cubeAxesActor-><wbr>SetGridLineLocation(VTK_GRID_<wbr>LINES_FURTHEST);<br>Â renderer->AddActor(<wbr>cubeAxesActor);<br><br>Â renderer->ResetCamera();<br><br>Â auto renderWindow = vtkSmartPointer<<wbr>vtkRenderWindow>::New();<br>Â renderWindow->AddRenderer(<wbr>renderer);<br>Â <br>Â auto interactor = vtkSmartPointer<<wbr>vtkRenderWindowInteractor>::<wbr>New();<br>Â interactor->SetRenderWindow(<wbr>renderWindow);<br>Â interactor->Initialize();<br>Â <br>Â interactor->Start();<br>Â <br>Â return EXIT_SUCCESS;<br>}<br><br></div><div>And then loaded each of the following three files, containing a 2x2x2 (extent: 0 1 0 1 0 1), a 3x3x3 (extent: 0 2 0 2 0 2) and a 4x4x4 (extent: 0 3 0 3 0 3) image, all of them with spacing 1.0 1.0 1.0:<br><br><!-- 2x2x2 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 1 0 1 0 1" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 1 0 1 0 1"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br><br><!-- 3x3x3 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 2 0 2 0 2" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 2 0 2 0 2"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br><br><!-- 4x4x4 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 3 0 3 0 3" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 3 0 3 0 3"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br></div></div></div></div></blockquote><div><br></div><div>Sorry, these files had a bit too many scalars in them (but the result is the same of course). Here they are corrected:<br><br><!-- 2x2x2 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 1 0 1 0 1" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 1 0 1 0 1"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br><br><!-- 3x3x3 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 2 0 2 0 2" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 2 0 2 0 2"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br><br><!-- 4x4x4 image --><br><VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"><br>Â Â Â <ImageData WholeExtent="0 3 0 3 0 3" Origin="0 0 0" Spacing="1.0 1.0 1.0"><br>Â Â Â Â Â Â Â <Piece Extent="0 3 0 3 0 3"><br>Â Â Â Â Â Â Â Â Â Â Â <PointData Scalars="density"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <DataArray type="Float32" Name="density" format="ascii"><br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0<br>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â </DataArray><br>Â Â Â Â Â Â Â Â Â Â Â </PointData><br>Â Â Â Â Â Â Â </Piece><br>Â Â Â </ImageData><br></VTKFile><br><br></div><div>Elvis<br><br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>I'm attaching the result.<br><br></div><div>As you can see, the 2x2x2 volume has a visual dimension of 1x1x1, the 3x3x3 a visual dimension of 2x2x2 and the 4x4x4 a visual dimension of 3x3x3, so one less than what I would have expected.<br><br></div><div>I thought that with e.g. a 2x2x2 volume with spacing 1.0 1.0 1.0, I would get 2x2x2 area occupied when the volume is mapped into the world.<br><br></div><div>If someone could clarify what is going on here, it would be much appreciated.<br><br></div><div>I understand now that to "stack" my volumes adjacently on top of each other, I should add extent[5] * spacing[2], not (extent[5] + 1) * spacing[2] (I don't have access to the vtkVolume at that point, so can't use GetBounds), and that it's precisely this position I should give to SetPosition (no need to "compensate" for the half spacing to the voxel center).<br><br></div><div>But I'm still surprised that a volume containing 2x2x2 voxels values gives a 1x1x1 visual rendering.<span class="gmail-HOEnZb"><font color="#888888"><br><br></font></span></div><span class="gmail-HOEnZb"><font color="#888888"><div>Elvis<br></div></font></span><span class="gmail-"><div><br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Elvis<br><br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div><div><br></div>Thanks in advance,<br></div>Elvis<br></div>
</blockquote></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>