title: Displaying a 3D Image in VTK (.mhd, .raw)
body: <p>I have a simple file that is supposed to display a medical image in the .raw format by reading it's header from a .mhd file using the MetaImageReader.
  I'm not quite familiar with VTK so I tried two different code snippets (actually they are examples from the vtk and the kitware website). None of them worked. As I am new to VTK, I'm not sure if this is the right way to display a 3D Image, since my .mhd file tells me, that the image has 3 dimensions:</p>
  
  <pre><code>void render1() {
  // read input image
  vtkSmartPointer&lt;vtkMetaImageReader&gt; reader = vtkSmartPointer&lt;vtkMetaImageReader&gt;::New();
  reader-&gt;SetFileName("header.mhd");
  reader-&gt;Update();
  
  vtkSmartPointer&lt;vtkImageViewer2&gt; viewer = vtkSmartPointer&lt;vtkImageViewer2&gt;::New();
  viewer-&gt;SetInputConnection(reader-&gt;GetOutputPort());
  
  // render window
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor = vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();
  
  viewer-&gt;SetupInteractor(renderWindowInteractor);
  viewer-&gt;GetRenderer()-&gt;ResetCamera();
  
  renderWindowInteractor-&gt;Initialize();
  renderWindowInteractor-&gt;Start();
  }
  </code></pre>
  
  <p>If I change the reader to e.g. a JPEGReader and load a JPEG File, the image will be displayed.
  Another Example I've tried is the following:</p>
  
  <pre><code>void render2() {
  // read input image
  vtkSmartPointer&lt;vtkMetaImageReader&gt; reader = vtkSmartPointer&lt;vtkMetaImageReader&gt;::New();
  reader-&gt;SetFileName("header.mhd");
  reader-&gt;Update();
  
  // Visualize
  vtkSmartPointer&lt;vtkImageActor&gt; actor = vtkSmartPointer&lt;vtkImageActor&gt;::New();
  actor-&gt;GetMapper()-&gt;SetInputConnection(reader-&gt;GetOutputPort());
  
  vtkSmartPointer&lt;vtkRenderer&gt; renderer = vtkSmartPointer&lt;vtkRenderer&gt;::New();
  renderer-&gt;AddActor(actor);
  renderer-&gt;ResetCamera();
  
  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow = vtkSmartPointer&lt;vtkRenderWindow&gt;::New();
  renderWindow-&gt;AddRenderer(renderer);
  
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor = vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();
  vtkSmartPointer&lt;vtkInteractorStyleImage&gt; style = vtkSmartPointer&lt;vtkInteractorStyleImage&gt;::New();
  
  renderWindowInteractor-&gt;SetInteractorStyle(style);
  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);
  renderWindowInteractor-&gt;Initialize();
  renderWindowInteractor-&gt;Start();
  }
  </code></pre>
  
  <p>I don't get any error. Only a window with a black background appears. When I click in the window and move the mouse, a square in the middle of the window appears in a gray-scale from black to white, depending on how far I move the mouse.</p>
  
  <p>It seems to me, as if I made a common simple mistake, but since I use example code from the kitware company itself, I'm stuck here.</p>