Hi,<br><br>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:<br><br>1- ipp sorter<br>2- setfilenames<br>3- vtkimagechangeinformation<br><br>After these, I tried to visualize them using vtkimageviewer2. <br>
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
<br><br>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Monospace';font-size:9pt;color:#3c3c3c">Sorting succeeded:0.5</span></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Monospace';font-size:9pt;color:#3c3c3c">Sorting succeeded:1.5</span></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><span style="font-family:'Monospace';font-size:9pt;font-weight:600;color:#be1414">The program has unexpectedly finished. <span style="background-color:rgb(0,0,0)"><span><span style="background-color:rgb(255,255,255)"><span></span></span></span></span></span></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br><br>vtkGDCMImageReader *dicomReader =<br> vtkGDCMImageReader::New();<br><br>std::vector<std::string> filenames;<br>
const char *filename = "/home/telemed/Downloads/Dentascan";<br><br>gdcm::Directory d;<br>d.Load( filename, false);<br><br>filenames = d.GetFilenames();<br><br>gdcm::IPPSorter s;<br>s.SetComputeZSpacing( true );<br>
s.SetZSpacingTolerance( 1e-3 );<br>bool b = s.Sort( filenames );<br> if( !b )<br> {<br> std::cerr << "Failed to sort:" << "s" << std::endl;<br> return 1;<br> }<br> std::cout << "Sorting succeeded:" << s.GetZSpacing() << std::endl;<br>
//s.Print( std::cout );<br> const std::vector<std::string> & sorted = s.GetFilenames();<br><br> vtkStringArray *files =<br> vtkStringArray::New();<br> std::vector< std::string >::const_iterator it = sorted.begin();<br>
for( ; it != sorted.end(); ++it)<br> {<br> const std::string &f = *it;<br><br> files->InsertNextValue( f.c_str() );<br> }<br> dicomReader->SetFileNames( files );<br> //dicomReader->Update();<br><br> vtkImageChangeInformation *changer =<br>
vtkImageChangeInformation::New();<br> changer->SetInputConnection(dicomReader->GetOutputPort());<br> changer->SetOutputSpacing(VTK_DOUBLE_MAX,VTK_DOUBLE_MAX, 2.0);<br> changer->Update();<br>
<br><br> vtkInteractorStyleImage *imageStyle =<br> vtkInteractorStyleImage::New();<br> vtkRenderWindowInteractor *interactor =<br> vtkRenderWindowInteractor::New();<br> // Calculate the center of the volume<br>
<br> dicomReader->GetOutput()->UpdateInformation();<br> int extent[6];<br> double spacing[3];<br> double origin[3];<br> dicomReader->GetOutput()->GetWholeExtent(extent);<br> dicomReader->GetOutput()->GetSpacing(spacing);<br>
dicomReader->GetOutput()->GetOrigin(origin);<br> spacing[2] = 1.5;<br><br> vtkImageData* image = vtkImageData ::New();<br> image->SetSpacing(spacing);<br><br> std::cout << "Sorting succeeded:" << spacing[2] << std::endl;<br>
double center[3];<br> center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);<br> center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);<br> center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);<br>
<br> // Matrices for axial, coronal, sagittal, oblique view orientations<br> static double axialElements[16] = {<br> 1, 0, 0, center[0],<br> 0, 1, 0, center[1],<br> 0, 0, 1, center[2],<br>
0, 0, 0, 1 };<br><br> static double coronalElements[16] = {<br> 1, 0, 0, center[0],<br> 0, 0, 1, center[1],<br> 0,-1, 0, center[2],<br> 0, 0, 0, 1 };<br>
<br> static double sagittalElements[16] = {<br> 0, 0,-1, center[0],<br> 1, 0, 0, center[1],<br> 0,-1, 0, center[2],<br> 0, 0, 0, 1 };<br><br> // Set the slice orientation<br>
vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();<br> resliceAxes->DeepCopy(coronalElements);<br><br><br> vtkImageReslice *Reslice = vtkImageReslice::New();<br> Reslice->SetInputConnection(changer->GetOutputPort());<br>
Reslice->SetOutputDimensionality(3);<br> Reslice->SetResliceAxes(resliceAxes);<br> Reslice->SetInterpolationModeToLinear();<br><br> vtkImageViewer2 *viewer = vtkImageViewer2::New();<br> viewer->SetupInteractor(interactor);<br>
viewer->SetSize(500,500);<br> viewer->SetColorWindow(1024);<br> viewer->SetColorLevel(800);<br> viewer->SetInputConnection(Reslice->GetOutputPort());<br><br> // Create a greyscale lookup table<br>
vtkLookupTable *table = vtkLookupTable::New();<br> table->SetRange(0, 200); // image intensity range<br> table->SetValueRange(0.0, 1.0); // from black to white<br> table->SetSaturationRange(0.0, 0.0); // no color saturation<br>
table->SetRampToLinear();<br> table->Build();<br><br> // Map the image through the lookup table<br> vtkImageMapToColors *color = vtkImageMapToColors::New();<br> color->SetLookupTable(table);<br>
color->SetInputConnection(Reslice->GetOutputPort());<br><br> // Display the image<br> vtkImageActor *actor = vtkImageActor::New();<br> actor->SetInput(color->GetOutput());<br> vtkRenderer *renderer = vtkRenderer::New();<br>
renderer->AddActor(actor);<br> vtkRenderWindow *window = vtkRenderWindow::New();<br> window->AddRenderer(renderer);<br><br><br> interactor->SetInteractorStyle(imageStyle);<br> window->SetInteractor(interactor);<br>
window->Render();<br> interactor->Start();<br><br>Thanks for your help.<br> <br><span style="font-family:'Monospace';font-size:9pt;font-weight:600;color:#be1414"><span style="background-color:rgb(0,0,0)"><span><span style="background-color:rgb(255,255,255)"><span></span></span></span></span></span></p>