[vtkusers] Trying to slice 3d Image but application crashes

Naxo Nuñez naxola at hotmail.com
Tue Aug 14 14:17:00 EDT 2012


Hi all,

I am doing my own MPR slicer by following the Examples/ImageProcessing/Cxx/ImageSlicing.cxx example. 
The interface is made with Qt, so I use QVTKwidget as a 3D container.

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.
It compiles fine, but when I change the values on the matrix to perform that rotation my application crashes.

The first thing I just want to perform is a simple translation. Then controlling pitch, yaw angles and movements will be straighforward.

My sourcecode (important parts):
....
//Load dicom stuff and I export that data with vtkImageImport (vtkImporter contains the 3dImage data)
....
    int dimensiones[6];
    vtkImporter->GetWholeExtent(dimensiones);
    qDebug()<<"Xmin:"<<dimensiones[0]
    <<"Xmax:"<<dimensiones[1]
    <<"Ymin:"<<dimensiones[2]
    <<"Ymax:"<<dimensiones[3]
    <<"Zmin:"<<dimensiones[4]
    <<"Zmax:"<<dimensiones[5];

    horizontalSlider->setRange(0,dimensiones[5]); //This is my slider with which I want to control the movement of the slicing plane

    double espacing[3];
    vtkImporter->GetDataSpacing(espacing);
    double origen[3];
    vtkImporter->GetDataOrigin(origen);
    double centro[3];  //Obtenemos el punto centro para ponerselo al plano
    centro[0]=origen[0] + espacing[0] * 0.5 * (dimensiones[0] + dimensiones[1]);
    centro[1]=origen[1] + espacing[1] * 0.5 * (dimensiones[2] + dimensiones[3]);
    centro[2]=origen[2] + espacing[2] * 0.5 * (dimensiones[4] + dimensiones[5]);
    qDebug()<<"Espacios de voxeles:"<<espacing[0]<<","<<espacing[1]<<","<<espacing[2];
    qDebug()<<"Coordenadas del origen:"<<origen[0]<<","<<origen[1]<<","<<origen[2];
    qDebug()<<"Coordenadas del centro:"<<centro[0]<<","<<centro[1]<<","<<centro[2];

    vtkSmartPointer<vtkMatrix4x4> resliceAxes =vtkSmartPointer<vtkMatrix4x4>::New();

This matrix is which I use to slice the plane and show the 3dImage sliced

    static double matrizRotacion[16] = {
        1, 0, 0, centro[0],
        0, 1, 0, centro[1],
        0, 0, 1, centro[2],
        0, 0, 0, 1};
    resliceAxes->DeepCopy(matrizRotacion);
    // Extract a slice in the desired orientation
    reslice = vtkSmartPointer<vtkImageReslice>::New();
    reslice->SetInputConnection(vtkImporter->GetOutputPort());
    reslice->SetOutputDimensionality(2);
    reslice->SetResliceAxes(resliceAxes);
    reslice->SetInterpolationModeToCubic();

    // Create a greyscale lookup table
    vtkSmartPointer<vtkLookupTable> table =vtkSmartPointer<vtkLookupTable>::New();
    table->SetRange(0, 2000); // 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
    vtkSmartPointer<vtkImageMapToColors> color =vtkSmartPointer<vtkImageMapToColors>::New();
    color->SetLookupTable(table);
    color->SetInputConnection(reslice->GetOutputPort());
    // Display the image
    actor =vtkSmartPointer<vtkImageActor>::New();
    actor->GetMapper()->SetInputConnection(color->GetOutputPort());
    
    vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    qvtkSlices->GetRenderWindow()->AddRenderer(renderer);
    vtkSmartPointer<vtkInteractorStyleImage> imageStyle =vtkSmartPointer<vtkInteractorStyleImage>::New();
    interactor =vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetInteractorStyle(imageStyle);

qvtkWidget for 3d rendering:
    qvtkSlices->GetRenderWindow()->SetInteractor(interactor);
    qvtkSlices->GetRenderWindow()->Render();

    vtkSmartPointer<vtkImageInteractionCallback> callback =vtkSmartPointer<vtkImageInteractionCallback>::New();
    callback->SetImageReslice(reslice);
    callback->SetInteractor(interactor);
    imageStyle->AddObserver(vtkCommand::MouseMoveEvent, callback);
    imageStyle->AddObserver(vtkCommand::LeftButtonPressEvent, callback);
    imageStyle->AddObserver(vtkCommand::LeftButtonReleaseEvent, callback);
    // Start interaction
    // The Start() method doesn't return until the window is closed by the user

I don't know why but seems that if I put this the application never loads.

    //interactor->Start(); 

The function that is called when the slider changes is this

void Ver2D::muestraSlice(int sliceIn)
{
    vtkMatrix4x4 *matrix = reslice->GetResliceAxes();
    matrix->SetElement(2, 3,matrix->GetElement(2,3)-sliceIn);
    qvtkSlices->GetRenderWindow()->Render();
}

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.
The reslice pointer is the one created at the begining.

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:

else if (event == vtkCommand::MouseMoveEvent)
            {
                if (this->Slicing)
                {
                     vtkImageReslice *reslice = this->ImageReslice;
                     // Increment slice position by deltaY of mouse
                     int deltaY = lastPos[1] - currPos[1];
                     reslice->Update();
                     double sliceSpacing = reslice->GetOutput()->GetSpacing()[2];
                     vtkMatrix4x4 *matrix = reslice->GetResliceAxes();//Puntero a la matriz 
                     // move the center point that we are slicing through
                     double point[4];
                     double center[4];
                     point[0] = 0.0;
                     point[1] = 0.0;
                     point[2] = sliceSpacing * deltaY;
                     point[3] = 1.0;
                     matrix->MultiplyPoint(point, center);
                     matrix->SetElement(0, 3, center[0]); 
                     matrix->SetElement(1, 3, center[1]);
                     matrix->SetElement(2, 3, center[2]);
                     interactor->Render();
                }

If the matrix changes the application crashes. Why? Is there something wrong or I missing something? All works fine except for that.

Thank you,
Nacho N.
Virtual Reality and Robotics laboratory Dept.

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120814/7ed98848/attachment.htm>


More information about the vtkusers mailing list