0

I want to read a series of 2D dicom images. Then, I'll display it as a 3D volume. For that, I followed this steps:

1- ipp sorter 2- setfilenames 3- vtkimagechangeinformation

After these, I tried to visualize them using vtkimageviewer2. I'm sending almost all the code I wrote. I'm pretty sure it loads and sorts the images. But it gives an error like

Sorting succeeded:0.5

Sorting succeeded:1.5

The program has unexpectedly finished.

Here is my code:

vtkGDCMImageReader *dicomReader =
vtkGDCMImageReader::New();

std::vector<std::string> filenames;
const char *filename = "/home/telemed/Downloads/Dentascan";

gdcm::Directory d;
d.Load( filename, false);

filenames = d.GetFilenames();

gdcm::IPPSorter s;

s.SetComputeZSpacing( true );

s.SetZSpacingTolerance( 1e-3 );

bool b = s.Sort( filenames );

if( !b )

{

    std::cerr << "Failed to sort:" << "s" << std::endl;

    return 1;

}

std::cout << "Sorting succeeded:" << s.GetZSpacing() << std::endl;

//s.Print( std::cout );

const std::vector<std::string> & sorted = s.GetFilenames();


vtkStringArray *files =vtkStringArray::New();

std::vector< std::string >::const_iterator it = sorted.begin();

for( ; it != sorted.end(); ++it)

{

    const std::string &f = *it;


    files->InsertNextValue( f.c_str() );

}

dicomReader->SetFileNames( files );

//dicomReader->Update();

vtkImageChangeInformation *changer =

vtkImageChangeInformation::New();

changer->SetInputConnection(dicomReader->GetOutputPort());

changer->SetOutputSpacing(VTK_DOUBLE_MAX,VTK_DOUBLE_MAX, 2.0);

changer->Update();


vtkInteractorStyleImage *imageStyle =vtkInteractorStyleImage::New();

vtkRenderWindowInteractor *interactor =vtkRenderWindowInteractor::New();

/ Calculate the center of the volume

dicomReader->GetOutput()->UpdateInformation();
int extent[6];

double spacing[3];

double origin[3];

dicomReader->GetOutput()->GetWholeExtent(extent);

dicomReader->GetOutput()->GetSpacing(spacing);

dicomReader->GetOutput()->GetOrigin(origin);

spacing[2] = 1.5;

vtkImageData* image = vtkImageData ::New();

image->SetSpacing(spacing);

std::cout << "Sorting succeeded:" << spacing[2] << std::endl;

double center[3];

center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);

center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);

center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);

// Matrices for axial, coronal, sagittal, oblique view orientations

static double axialElements[16] = {
    1, 0, 0, center[0],

    0, 1, 0, center[1],

    0, 0, 1, center[2],

    0, 0, 0, 1 };

static double coronalElements[16] = {

    1, 0, 0, center[0],

    0, 0, 1, center[1],

    0,-1, 0, center[2],

    0, 0, 0, 1 };

static double sagittalElements[16] = {

    0, 0,-1, center[0],

    1, 0, 0, center[1],

    0,-1, 0, center[2],

    0, 0, 0, 1 };

// Set the slice orientation

vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();

resliceAxes->DeepCopy(coronalElements);


vtkImageReslice *Reslice = vtkImageReslice::New();

Reslice->SetInputConnection(changer->GetOutputPort());

Reslice->SetOutputDimensionality(3);

Reslice->SetResliceAxes(resliceAxes);

Reslice->SetInterpolationModeToLinear();

vtkImageViewer2 *viewer = vtkImageViewer2::New();

viewer->SetupInteractor(interactor);

viewer->SetSize(500,500);

viewer->SetColorWindow(1024);

viewer->SetColorLevel(800);

viewer->SetInputConnection(Reslice->GetOutputPort());

// Create a greyscale lookup table

vtkLookupTable *table = vtkLookupTable::New();

table->SetRange(0, 200); // image intensity range

table->SetValueRange(0.0, 1.0); // from black to white

table->SetSaturationRange(0.0, 0.0); // no color saturation

table->SetRampToLinear();

table->Build();

// Map the image through the lookup table

vtkImageMapToColors *color = vtkImageMapToColors::New();

color->SetLookupTable(table);

color->SetInputConnection(Reslice->GetOutputPort());

// Display the image

vtkImageActor *actor = vtkImageActor::New();

actor->SetInput(color->GetOutput());

vtkRenderer *renderer = vtkRenderer::New();

renderer->AddActor(actor);

vtkRenderWindow *window = vtkRenderWindow::New();

window->AddRenderer(renderer);

interactor->SetInteractorStyle(imageStyle);

window->SetInteractor(interactor);

window->Render();

interactor->Start();

Thanks for your help.

abierto
  • 1,447
  • 7
  • 29
  • 57
TahaYusuf
  • 335
  • 3
  • 5
  • 16

2 Answers2

0

Could you try to simplify your code and identify where the issue is coming from. Use a divide and conquer approach. Comment out the second half your code, re-compile and run it.

malat
  • 12,152
  • 13
  • 89
  • 158
0

Try implementing VTK_gdcmorthoplanes.

faisal
  • 53
  • 1
  • 9