[vtkusers] setSlice problem on QVTKWidget

Massi Massinissa.Bandou at USherbrooke.ca
Thu Sep 6 17:28:43 EDT 2012


I'm sorry if you can't compile. I will try to reproduce the problem with
VisualStrudio2010 and display it later. 

You need more than just the includes. If you're using Netbeans, probably I
will send you the whole project, I will try my best to explain you how it
works. Reading dicom series is just a part of the project. first you need to
create a GUI which will contain a QVTKWidget and an Edit Line. Secondly, vtk
should be built with mingw. Finally, Netbeans will generate you 4 files;
main.cpp, form.cpp (in my case I gave a name to my form:
ImageCoregistration) , a form.h and form.ui.
so I have:
1-main.cpp
2-ImageCoregistration.cpp
3-ImageCoregistration.h  
4-ImageCoregistration.ui (GUI + QVTKWidget)
 

I put the entire code in a function and I'm reading the file directory from
a Line Edit in my GUI.

*in the main.cpp*

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    ImageCoregistration form;
    form.show();
    return app.exec();
}

*in the ImageCoregistration.cpp file:*

void ImageCoregistration::ReadMovingImage2D(){

QString str = widget.MovingImageLocation2D->text();
const char *filename = str.toLatin1();

vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(filename);
reader->Update();

...
...
... (same code above)
...
...
widget.qvtkWidget_2->SetRenderWindow(imageViewer->GetRenderWindow());
widget.qvtkWidget_2->GetRenderWindow()->GetInteractor()->SetInteractorStyle(myInteractorStyle);
imageViewer->Render();
widget.qvtkWidget_2->update();
}

*in the ImageCoregistration.h file*

#ifndef _IMAGECOREGISTRATION_H
#define	_IMAGECOREGISTRATION_H

#include "ui_ImageCoregistration.h"
#include "sstream"
#include "QMainWindow"

using namespace std;

class ImageCoregistration : public QMainWindow {
    Q_OBJECT
    
public:
    ImageCoregistration();
    virtual ~ImageCoregistration();
    
public slots:
    void ReadMovingImage2D();
public:

    Ui::ImageCoregistration widget;
};

class StatusMessage{  
public:
    static std::string Format(int slice, int maxSlice){
        std::stringstream tmp;
        tmp<<"Slice Number: "<< slice+1 <<"/"<<maxSlice +1;
        return tmp.str();
    }
};

class myVtkInteractorStyleImage : public vtkInteractorStyleImage{
public:
    myVtkInteractorStyleImage(): ImageViewer(NULL),StatusMapper(NULL){};
    Ui::ImageCoregistration widget;
public:
    static myVtkInteractorStyleImage *New();
    vtkTypeMacro(myVtkInteractorStyleImage,vtkInteractorStyleImage);
protected:
    vtkImageViewer2* ImageViewer;
    vtkTextMapper *StatusMapper;
    int Slice;
    int MinSlice;
    int MaxSlice;
public:
    void SetImageViewer(vtkImageViewer2* imageViewer){
        this->ImageViewer = imageViewer;
        MinSlice = imageViewer->GetSliceMin();
        MaxSlice = imageViewer->GetSliceMax();
        Slice = MinSlice;
        cout<< "Slicer: Min =" << MinSlice <<", Max =
"<<MaxSlice&lt;&lt;std::endl;
    }
    
    void SetStatusMapper(vtkTextMapper* statusMapper){
        StatusMapper = statusMapper;
    }
protected:
    void MoveSliceForward(){
        if (Slice &lt; MaxSlice){
            Slice += 1;
            cout&lt;&lt;&quot;MoveSliceForward::Slice =
&quot;&lt;&lt;Slice&lt;&lt;std::endl;
            this->ImageViewer->SetSlice(Slice);   
            std::string msg = StatusMessage::Format(Slice, MaxSlice);
            StatusMapper->SetInput(msg.c_str());
            ImageViewer->Render();
        }
    }
    void MoveSliceBackward(){
        if (Slice > MinSlice){
            Slice -= 1;
            cout<<"MoveSliceBackward::Slice = "<<Slice&lt;&lt;std::endl;         
            this->ImageViewer->SetSlice(Slice); ;   
            std::string msg = StatusMessage::Format(Slice, MaxSlice);
            StatusMapper->SetInput(msg.c_str());
            ImageViewer->Render();
        }
    }
    virtual void OnKeyDown(){
        std::string key = this->GetInteractor()->GetKeySym();
        if (key.compare("Up") == 0){
            MoveSliceForward();
        }
        else if(key.compare("Down") == 0){
            MoveSliceBackward();
        }
 
    }    
};
#endif	

I didn't add the includes, I have at least 40!!!

Thx

Massi






--
View this message in context: http://vtk.1045678.n5.nabble.com/setSlice-problem-on-QVTKWidget-tp5715880p5715915.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list