<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi all,<br><br>I am doing my own MPR slicer by following the Examples/ImageProcessing/Cxx/ImageSlicing.cxx example. <br>The interface is made with Qt, so I use QVTKwidget as a 3D container.<br><br>The goal is to change the position of the slicing plane (orientation) controlling that orientation with a qslider, showing how the image sliced is changing on the qvtkwidget.<br>It compiles fine, but when I change the values on the matrix to perform that rotation my application crashes.<br><br>The first thing I just want to perform is a simple translation. Then controlling pitch, yaw angles and movements will be straighforward.<br><br>My sourcecode (important parts):<br>....<br>//Load dicom stuff and I export that data with vtkImageImport (vtkImporter contains the 3dImage data)<br>....<br>&nbsp;&nbsp;&nbsp; int dimensiones[6];<br>&nbsp;&nbsp;&nbsp; vtkImporter-&gt;GetWholeExtent(dimensiones);<br>&nbsp;&nbsp;&nbsp; qDebug()&lt;&lt;"Xmin:"&lt;&lt;dimensiones[0]<br>&nbsp;&nbsp;&nbsp; &lt;&lt;"Xmax:"&lt;&lt;dimensiones[1]<br>&nbsp;&nbsp;&nbsp; &lt;&lt;"Ymin:"&lt;&lt;dimensiones[2]<br>&nbsp;&nbsp;&nbsp; &lt;&lt;"Ymax:"&lt;&lt;dimensiones[3]<br>&nbsp;&nbsp;&nbsp; &lt;&lt;"Zmin:"&lt;&lt;dimensiones[4]<br>&nbsp;&nbsp;&nbsp; &lt;&lt;"Zmax:"&lt;&lt;dimensiones[5];<br><br>&nbsp;&nbsp;&nbsp; horizontalSlider-&gt;setRange(0,dimensiones[5]); //This is my slider with which I want to control the movement of the slicing plane<br><br>&nbsp;&nbsp;&nbsp; double espacing[3];<br>&nbsp;&nbsp;&nbsp; vtkImporter-&gt;GetDataSpacing(espacing);<br>&nbsp;&nbsp;&nbsp; double origen[3];<br>&nbsp;&nbsp;&nbsp; vtkImporter-&gt;GetDataOrigin(origen);<br>&nbsp;&nbsp;&nbsp; double centro[3];&nbsp; //Obtenemos el punto centro para ponerselo al plano<br>&nbsp;&nbsp;&nbsp; centro[0]=origen[0] + espacing[0] * 0.5 * (dimensiones[0] + dimensiones[1]);<br>&nbsp;&nbsp;&nbsp; centro[1]=origen[1] + espacing[1] * 0.5 * (dimensiones[2] + dimensiones[3]);<br>&nbsp;&nbsp;&nbsp; centro[2]=origen[2] + espacing[2] * 0.5 * (dimensiones[4] + dimensiones[5]);<br>&nbsp;&nbsp;&nbsp; qDebug()&lt;&lt;"Espacios de voxeles:"&lt;&lt;espacing[0]&lt;&lt;","&lt;&lt;espacing[1]&lt;&lt;","&lt;&lt;espacing[2];<br>&nbsp;&nbsp;&nbsp; qDebug()&lt;&lt;"Coordenadas del origen:"&lt;&lt;origen[0]&lt;&lt;","&lt;&lt;origen[1]&lt;&lt;","&lt;&lt;origen[2];<br>&nbsp;&nbsp;&nbsp; qDebug()&lt;&lt;"Coordenadas del centro:"&lt;&lt;centro[0]&lt;&lt;","&lt;&lt;centro[1]&lt;&lt;","&lt;&lt;centro[2];<br><br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkMatrix4x4&gt; resliceAxes =vtkSmartPointer&lt;vtkMatrix4x4&gt;::New();<br><br>This matrix is which I use to slice the plane and show the 3dImage sliced<br><br>&nbsp;&nbsp;&nbsp; static double matrizRotacion[16] = {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1, 0, 0, centro[0],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 1, 0, centro[1],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 0, 1, centro[2],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0, 0, 0, 1};<br>&nbsp;&nbsp;&nbsp; resliceAxes-&gt;DeepCopy(matrizRotacion);<br>&nbsp;&nbsp;&nbsp; // Extract a slice in the desired orientation<br>&nbsp;&nbsp;&nbsp; reslice = vtkSmartPointer&lt;vtkImageReslice&gt;::New();<br>&nbsp;&nbsp;&nbsp; reslice-&gt;SetInputConnection(vtkImporter-&gt;GetOutputPort());<br>&nbsp;&nbsp;&nbsp; reslice-&gt;SetOutputDimensionality(2);<br>&nbsp;&nbsp;&nbsp; reslice-&gt;SetResliceAxes(resliceAxes);<br>&nbsp;&nbsp;&nbsp; reslice-&gt;SetInterpolationModeToCubic();<br><br>&nbsp;&nbsp;&nbsp; // Create a greyscale lookup table<br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkLookupTable&gt; table =vtkSmartPointer&lt;vtkLookupTable&gt;::New();<br>&nbsp;&nbsp;&nbsp; table-&gt;SetRange(0, 2000); // image intensity range<br>&nbsp;&nbsp;&nbsp; table-&gt;SetValueRange(0.0, 1.0); // from black to white<br>&nbsp;&nbsp;&nbsp; table-&gt;SetSaturationRange(0.0, 0.0); // no color saturation<br>&nbsp;&nbsp;&nbsp; table-&gt;SetRampToLinear();<br>&nbsp;&nbsp;&nbsp; table-&gt;Build();<br>&nbsp;&nbsp;&nbsp; // Map the image through the lookup table<br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageMapToColors&gt; color =vtkSmartPointer&lt;vtkImageMapToColors&gt;::New();<br>&nbsp;&nbsp;&nbsp; color-&gt;SetLookupTable(table);<br>&nbsp;&nbsp;&nbsp; color-&gt;SetInputConnection(reslice-&gt;GetOutputPort());<br>&nbsp;&nbsp;&nbsp; // Display the image<br>&nbsp;&nbsp;&nbsp; actor =vtkSmartPointer&lt;vtkImageActor&gt;::New();<br>&nbsp;&nbsp;&nbsp; actor-&gt;GetMapper()-&gt;SetInputConnection(color-&gt;GetOutputPort());<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkRenderer&gt; renderer =vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>&nbsp;&nbsp;&nbsp; renderer-&gt;AddActor(actor);<br>&nbsp;&nbsp;&nbsp; qvtkSlices-&gt;GetRenderWindow()-&gt;AddRenderer(renderer);<br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkInteractorStyleImage&gt; imageStyle =vtkSmartPointer&lt;vtkInteractorStyleImage&gt;::New();<br>&nbsp;&nbsp;&nbsp; interactor =vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>&nbsp;&nbsp;&nbsp; interactor-&gt;SetInteractorStyle(imageStyle);<br><br>qvtkWidget for 3d rendering:<br>&nbsp;&nbsp;&nbsp; qvtkSlices-&gt;GetRenderWindow()-&gt;SetInteractor(interactor);<br>&nbsp;&nbsp;&nbsp; qvtkSlices-&gt;GetRenderWindow()-&gt;Render();<br><br>&nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageInteractionCallback&gt; callback =vtkSmartPointer&lt;vtkImageInteractionCallback&gt;::New();<br>&nbsp;&nbsp;&nbsp; callback-&gt;SetImageReslice(reslice);<br>&nbsp;&nbsp;&nbsp; callback-&gt;SetInteractor(interactor);<br>&nbsp;&nbsp;&nbsp; imageStyle-&gt;AddObserver(vtkCommand::MouseMoveEvent, callback);<br>&nbsp;&nbsp;&nbsp; imageStyle-&gt;AddObserver(vtkCommand::LeftButtonPressEvent, callback);<br>&nbsp;&nbsp;&nbsp; imageStyle-&gt;AddObserver(vtkCommand::LeftButtonReleaseEvent, callback);<br>&nbsp;&nbsp;&nbsp; // Start interaction<br>&nbsp;&nbsp;&nbsp; // The Start() method doesn't return until the window is closed by the user<br><br>I don't know why but seems that if I put this the application never loads.<br><br>&nbsp;&nbsp;&nbsp; //interactor-&gt;Start(); <br><br>The function that is called when the slider changes is this<br><br>void Ver2D::muestraSlice(int sliceIn)<br>{<br>&nbsp;&nbsp;&nbsp; vtkMatrix4x4 *matrix = reslice-&gt;GetResliceAxes();<br>&nbsp;&nbsp;&nbsp; matrix-&gt;SetElement(2, 3,matrix-&gt;GetElement(2,3)-sliceIn);<br>&nbsp;&nbsp;&nbsp; qvtkSlices-&gt;GetRenderWindow()-&gt;Render();<br>}<br><br>As you can see I only want to perform a simple translation by changing the value 2,3 of the orientation matrix but when I enter in muestraSlice function the whole application crahes.<br>The reslice pointer is the one created at the begining.<br><br>Where is the problem?? also crashes if I copy the whole sourcecode of the given example (subclasing vtkCommand for initeracting with the image), when entering to MouseMoveEvent:<br><br>else if (event == vtkCommand::MouseMoveEvent)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (this-&gt;Slicing)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;vtkImageReslice *reslice = this-&gt;ImageReslice;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Increment slice position by deltaY of mouse<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int deltaY = lastPos[1] - currPos[1];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;reslice-&gt;Update();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double sliceSpacing = reslice-&gt;GetOutput()-&gt;GetSpacing()[2];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;vtkMatrix4x4 *matrix = reslice-&gt;GetResliceAxes();//Puntero a la matriz <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// move the center point that we are slicing through<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double point[4];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double center[4];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;point[0] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;point[1] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;point[2] = sliceSpacing * deltaY;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;point[3] = 1.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;matrix-&gt;MultiplyPoint(point, center);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;matrix-&gt;SetElement(0, 3, center[0]); <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;matrix-&gt;SetElement(1, 3, center[1]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;matrix-&gt;SetElement(2, 3, center[2]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;interactor-&gt;Render();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>If the matrix changes the application crashes. Why? Is there something wrong or I missing something? All works fine except for that.<br><br>Thank you,<br>Nacho N.<br>Virtual Reality and Robotics laboratory Dept.<br><br>                                               </div></body>
</html>