Generating and reading .vtk files from .dcm files, and modifying model

Viewed 2139

I would like to have a better understanding about dicom volume rendering.

I have a set of dicom images, from which I've been able to extract axial, coronal and sagittal cuts, as follow :

enter image description here

I first wanted to generate a 3D model from scratch, but it seems to be way too hard.

So I heard about VTK/ITK, and I've been using this code to generate a .vtk file from my set of images :

http://www.itk.org/Doxygen46/html/IO_2DicomSeriesReadImageWrite2_8cxx-example.html

It works, but I need some explanations :

When I open this file with ParaView, I get the following result :

enter image description here

First, it might be a stupid question, but why is it blue?

Is there a way to cut and see the inside of the model?

My aim is not to use ParaView, and I'd like to make my own .vtk reader, I found this code I don't remember where, which I think is suppose to work, but all I get with it is the green background with nothing more :

#include <vtkPolyDataReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

int main ( int argc, char *argv[] ) {

  // Parse command line arguments                                                                     
  if (argc != 2) {
    std::cerr << "Usage: " << argv[0] << " Filename(.vtk)" << std::endl;
    return EXIT_FAILURE;
  }

  std::string filename = argv[1];

  // Read all the data from the file                                                                  
  vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
  reader->SetFileName(filename.c_str());
  reader->Update();

  // Visualize                                                                                        
  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(reader->GetOutputPort());

  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(actor);
  renderer->SetBackground(.3, .6, .3); // Background color green                                      

  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

any idea why? I saw in ParaView that I had to activate the "Volume" mode to be able to see my model, is there something similar to handle here?

Last thing, which is very important : Is it possible to modify the 3D volume inside a .vtk file? For instance, if I want to change the color of a specific part of the model, does VTK provides tools allowing that?

1 Answers
Related