]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Qt/Viewers/qtvtkviewer.cpp
addition of image stencil to surface rendering
[creaMaracasVisu.git] / lib / GUI / Qt / Viewers / qtvtkviewer.cpp
1 #include "qtvtkviewer.h"
2
3 #include "vtkImageMapToColors.h"
4
5 QtVTKViewer::QtVTKViewer(QWidget* parent)
6     : QVTKWidget(parent)
7 {
8
9
10     vtkRenderer* renderer = vtkRenderer::New();
11     this->GetRenderWindow()->AddRenderer(renderer);
12     this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->SetBackground(1,1,1);
13
14     SuperImagePlaneWidget::initialize(this->GetRenderWindow()->GetInteractor());
15
16     this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->ResetCamera();    
17
18
19     _rayorigin[0] = 0;
20     _rayorigin[1] = 0;
21     _rayorigin[2] = 0;
22     _rayorigin[3] = 0;
23
24     _imageindex[0] = 0;
25     _imageindex[1] = 0;
26     _imageindex[2] = 0;
27
28 }
29
30 void QtVTKViewer::mouseMoveEvent(QMouseEvent* event){
31     int x=0, y=0;
32
33     QVTKWidget::mouseMoveEvent(event);
34
35     x = event->pos().x();
36     y = this->size().height() - event->pos().y();
37
38 #ifdef debug
39     std::cout<<"X= "<<x<<" Y= "<<y<<std::endl;
40 #endif
41
42
43     this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->SetDisplayPoint(x, y, 0);
44     this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->DisplayToWorld();
45     this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetWorldPoint(_rayorigin);
46 #ifdef debug
47     std::cout<<"X= "<<x<<" Y= "<<y<<std::endl;
48     std::cout<<"X= "<<_rayorigin[0]<<" Y= "<<_rayorigin[1]<<" Z= "<<_rayorigin[2]<<" R= "<<_rayorigin[3]<<std::endl;
49 #endif
50
51
52
53
54
55 }
56
57 void QtVTKViewer::mousePressEvent(QMouseEvent* event){
58     QVTKWidget::mousePressEvent(event);
59     vtkImagePlaneWidget * temp = 0;
60     if(_xwidget->GetCursorDataStatus()==1){
61         temp = _xwidget;
62     }else if(_ywidget->GetCursorDataStatus()==1){
63         temp = _ywidget;
64     }else if(_zwidget->GetCursorDataStatus()==1){
65         temp = _zwidget;
66     }
67
68     if(temp){
69         _imageindex[0]=temp->GetCurrentCursorPosition()[0];
70         _imageindex[1]=temp->GetCurrentCursorPosition()[1];
71         _imageindex[2]=temp->GetCurrentCursorPosition()[2];
72 #ifdef debug
73          std::cout<<"X= "<<_imageindex[0]<<" Y= "<<_imageindex[1]<<" Z= "<<_imageindex[2]<<std::endl;
74 #endif
75     }
76 }
77
78 void QtVTKViewer::SetOutputFormatToRGBA(){
79     _xwidget->GetColorMap()->SetOutputFormatToRGBA();
80     _ywidget->GetColorMap()->SetOutputFormatToRGBA();
81     _zwidget->GetColorMap()->SetOutputFormatToRGBA();
82 }