<div dir="ltr">Hello,<br><br>I&#39;m trying to read DICOM image slices and to view them with a vtkImageViewer. The thing is that I want to change the axis before I view the slices, that is, if the slices are in axial direction I want to change it to coronal direction. I&#39;m doing that using the a vtkImageReslice. The thing is that when I pass the DICOM reader directly to the vtkImageViewer things work fine. However, when I use first the vtkImageReslice and than pass it to the vtkImageViewer I can&#39;t view the slices anymore. It&#39;s strange because when I call GetWholeZMax it returns 0. Does anybody could help me? The code is attached.<br>
<br>Thank you,<br><br>Talita<br clear="all"><br>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::string strFolderPath = &quot;/home/talita/Desktop/COMUNIX/Neck 1HEAD_NECK_PETCT/CT HEAD-NK 5.0 B30s&quot;;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkDICOMImageReader *reader = vtkDICOMImageReader::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;SetDirectoryName (strFolderPath.c_str());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp; reader-&gt;SetDataScalarTypeToUnsignedShort();<br>&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;UpdateWholeExtent(); <br><br>&nbsp; &nbsp;&nbsp;&nbsp; // Calculate the center of the volume<br>&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;GetOutput()-&gt;UpdateInformation();<br>
&nbsp; &nbsp;&nbsp;&nbsp; int extent[6];<br>&nbsp; &nbsp;&nbsp;&nbsp; double spacing[3];<br>&nbsp; &nbsp;&nbsp;&nbsp; double origin[3];<br>&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;GetOutput()-&gt;GetWholeExtent(extent);<br>&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;GetOutput()-&gt;GetSpacing(spacing);<br>&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;GetOutput()-&gt;GetOrigin(origin);<br>
<br>&nbsp; &nbsp;&nbsp;&nbsp; double center[3];<br>&nbsp; &nbsp;&nbsp;&nbsp; center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]); <br>&nbsp; &nbsp;&nbsp;&nbsp; center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]); <br>&nbsp; &nbsp;&nbsp;&nbsp; center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]); <br>
<br>&nbsp; &nbsp;&nbsp;&nbsp; // Matrices for axial, coronal, sagittal, oblique view orientations<br>&nbsp; &nbsp;&nbsp;&nbsp; static double axialElements[16] = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1, 0, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 1, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 0, 1, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 0, 0, 1 };<br>
<br>&nbsp; &nbsp;&nbsp;&nbsp; static double coronalElements[16] = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1, 0, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 1, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,-1, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 1 };<br><br>&nbsp; &nbsp;&nbsp;&nbsp; static double sagittalElements[16] = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0,-1, 0,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1, 0, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,-1, 0, 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 1 };<br><br>&nbsp; &nbsp;&nbsp;&nbsp; //static double obliqueElements[16] = {<br>&nbsp; &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1, 0, 0, 0,<br>&nbsp; &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0.866025, -0.5, 0,<br>&nbsp; &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0.5, 0.866025, 0,<br>
&nbsp; &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 1 };<br><br>&nbsp; &nbsp;&nbsp;&nbsp; // Set the slice orientation<br>&nbsp; &nbsp;&nbsp;&nbsp; vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();<br>&nbsp; &nbsp;&nbsp;&nbsp; resliceAxes-&gt;DeepCopy(coronalElements);<br>&nbsp; &nbsp;&nbsp;&nbsp; // Set the point through which to slice<br>
&nbsp; &nbsp;&nbsp;&nbsp; resliceAxes-&gt;SetElement(0, 3, center[0]);<br>&nbsp; &nbsp;&nbsp;&nbsp; resliceAxes-&gt;SetElement(1, 3, center[1]);<br>&nbsp; &nbsp;&nbsp;&nbsp; resliceAxes-&gt;SetElement(2, 3, center[2]);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; &nbsp;&nbsp;&nbsp; // Extract a slice in the desired orientation<br>
&nbsp; &nbsp;&nbsp;&nbsp; vtkImageReslice *reslice = vtkImageReslice::New();<br>&nbsp; &nbsp;&nbsp;&nbsp; reslice-&gt;SetInputConnection(reader-&gt;GetOutputPort());<br>&nbsp; &nbsp;&nbsp;&nbsp; reslice-&gt;SetOutputDimensionality(2);<br>&nbsp; &nbsp;&nbsp;&nbsp; reslice-&gt;SetResliceAxes(resliceAxes);<br>
&nbsp; &nbsp;&nbsp;&nbsp; //reslice-&gt;SetInterpolationModeToNearestNeighbor();<br><br>&nbsp; &nbsp;&nbsp;&nbsp; // Create a greyscale lookup table<br>&nbsp; &nbsp;&nbsp;&nbsp; vtkLookupTable *table = vtkLookupTable::New();<br>&nbsp; &nbsp;&nbsp;&nbsp; table-&gt;SetRange(0, 2000); // image intensity range<br>
&nbsp; &nbsp;&nbsp;&nbsp; table-&gt;SetValueRange(0.0, 1.0); // from black to white<br>&nbsp; &nbsp;&nbsp;&nbsp; table-&gt;SetSaturationRange(0.0, 0.0); // no color saturation<br>&nbsp; &nbsp;&nbsp;&nbsp; table-&gt;SetRampToLinear();<br>&nbsp; &nbsp;&nbsp;&nbsp; table-&gt;Build();<br><br>&nbsp; &nbsp;&nbsp;&nbsp; // Map the image through the lookup table<br>
&nbsp; &nbsp;&nbsp;&nbsp; vtkImageMapToColors *color = vtkImageMapToColors::New();<br>&nbsp; &nbsp;&nbsp;&nbsp; color-&gt;SetLookupTable(table);<br>&nbsp; &nbsp;&nbsp;&nbsp; color-&gt;SetInputConnection(reslice-&gt;GetOutputPort());<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; vtkImageViewer *viewer = vtkImageViewer::New();<br>
<br>&nbsp;&nbsp;&nbsp; viewer-&gt;SetInput(color-&gt;GetOutput());<br>&nbsp;&nbsp;&nbsp; printf(&quot;\n%d\n&quot;,viewer-&gt;GetWholeZMax());<br>&nbsp;&nbsp;&nbsp; viewer-&gt;SetZSlice(35);<br>&nbsp;&nbsp;&nbsp; viewer-&gt;SetColorWindow(2000);<br>&nbsp;&nbsp;&nbsp; viewer-&gt;SetColorLevel(1000);<br>
&nbsp;&nbsp;&nbsp; viewer-&gt;Render();<br><br></div>