]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx
0c431b4e68145b193d1f83ee56e03ff96ef815d2
[creaMaracasVisu.git] / lib / GUI / Qt / SurfaceRenderer / qtsurfacerendererpanel.cxx
1 #include "qtsurfacerendererpanel.h"
2 #include "ui_qtsurfacerendererpanel.h"
3
4 #include "qfiledialog.h"
5
6 #include "qcolordialog.h"
7 #include "qmessagebox.h"
8
9 #include "Color.xpm"
10 #include "Save.xpm"
11 #include "OpenImage.xpm"
12
13 QtSurfaceRendererPanel::QtSurfaceRendererPanel(QWidget *parent) :
14     QWidget(parent),
15     ui(new Ui::QtSurfaceRendererPanel)
16 {
17     ui->setupUi(this);
18
19
20     this->ui->pushButtonColorChooser->setIcon(QIcon(Color_xpm));
21     //this->ui->pushButtonSave->setIcon(QIcon(Save_xpm));
22     this->ui->pushButtonOpen->setIcon(QIcon(OpenImage_xpm));
23
24     this->ui->comboBoxSave->addItem(QIcon(Save_xpm), QString(""));
25     this->ui->comboBoxSave->addItem(QString("Save surface"));
26     this->ui->comboBoxSave->addItem(QString("Export image stencil"));
27     _ImageSet = false;
28 }
29
30 QtSurfaceRendererPanel::~QtSurfaceRendererPanel()
31 {   
32     delete ui;
33 }
34 void QtSurfaceRendererPanel::setImageData(vtkImageData* img){
35     double *range  =img->GetScalarRange();
36
37     this->ui->horizontalSliderMinIso->setRange(range[0], range[1]);
38
39     this->ui->horizontalSliderMaxIso->setRange(range[0], range[1]);
40
41     wxMaracasSurfaceRenderingManager::setImageData(img);
42     _ImageSet = true;
43 }
44
45 void QtSurfaceRendererPanel::on_OpacitySlider_valueChanged(int value)
46 {
47     try{
48
49         this->ui->lineEditOpacity->setText(QString::number(value));
50
51
52         this->changeOpacity(0, value);
53     }catch(char * e){
54         cout<<e<<endl;
55         QMessageBox::critical(this, tr("Volume Rendering"), tr(e), QMessageBox::Ok);
56     }
57 }
58
59 void QtSurfaceRendererPanel::on_pushButtonColorChooser_clicked()
60 {
61     QColorDialog* qcolor = new QColorDialog(this);
62
63
64
65     if(qcolor->exec()){
66
67         QColor color = qcolor->selectedColor();
68
69         int r = 0, g = 0, b = 0;
70         color.getRgb(&r, &g, &b);
71
72         try{
73
74             this->changeColor(0, r/255.0, g/255.0 ,b/255.0);
75         }catch(char * e){
76             cout<<e<<endl;
77             QMessageBox::critical(this, tr("Surface Rendering"), tr(e), QMessageBox::Ok);
78         }
79     }
80
81
82 }
83
84 void QtSurfaceRendererPanel::on_checkBox_clicked(bool checked)
85 {
86     if(!this->addRemoveActor(0, checked)){
87         this->ui->checkBox->setChecked(false);
88     }else if(!checked){
89         this->ui->checkBoxBoundingBox->setCheckState(Qt::Unchecked);
90         this->on_checkBoxBoundingBox_clicked(false);
91     }
92 }
93
94 void QtSurfaceRendererPanel::on_horizontalSliderMaxIso_valueChanged(int value)
95 {
96
97     this->ui->lineEditMaxIso->setText(QString::number(value));
98 }
99
100 void QtSurfaceRendererPanel::on_horizontalSliderMinIso_valueChanged(int value)
101 {
102     this->ui->lineEditMinIso->setText(QString::number(value));
103 }
104
105 void QtSurfaceRendererPanel::on_horizontalSliderMaxIso_sliderReleased()
106 {
107     onIsoValueChanged();
108 }
109
110 void QtSurfaceRendererPanel::on_horizontalSliderMinIso_sliderReleased()
111 {
112     onIsoValueChanged();
113 }
114
115 void QtSurfaceRendererPanel::onIsoValueChanged(){
116     if(_ImageSet)
117         this->changeIsoValue(0, this->ui->horizontalSliderMinIso->value(), this->ui->horizontalSliderMaxIso->value());
118 }
119
120 /*void QtSurfaceRendererPanel::on_pushButtonSave_clicked()
121 {
122     QString filename = QFileDialog::getSaveFileName(this,
123                                                     tr("Save Mesh File"),
124                                                     QDir::currentPath(),
125                                                     tr("Mesh files (*.stl *.ply *.vtk)") );
126
127     if( !filename.isNull() ){
128         //filename.append(".stl");
129         this->saveProp3DSTL(0, filename.toStdString().c_str());
130     }
131
132 }*/
133
134 void QtSurfaceRendererPanel::on_checkBoxBoundingBox_clicked(bool checked)
135 {
136     this->enableBoundingBox(0, checked);
137
138 }
139
140 void QtSurfaceRendererPanel::on_pushButtonOpen_clicked(bool checked)
141 {
142
143 }
144
145 void QtSurfaceRendererPanel::on_pushButtonOpen_clicked()
146 {
147     QString filename = QFileDialog::getOpenFileName(this, tr("Load Mesh File"), QDir::currentPath(),  tr("Mesh files (*.stl *.ply *.vtk)"));
148
149     if(!filename.isNull()){
150         this->loadProp3DSTL(filename.toStdString().c_str());
151         this->ui->checkBox->setCheckState(Qt::Checked);
152     }
153 }
154
155 void QtSurfaceRendererPanel::on_comboBoxSave_activated(int index)
156 {
157     if(index == 1){
158         QString filename = QFileDialog::getSaveFileName(this,
159                                                         tr("Save Mesh File"),
160                                                         QDir::currentPath(),
161                                                         tr("Mesh files (*.stl *.ply *.vtk)") );
162
163         if( !filename.isNull() ){
164             //filename.append(".stl");
165             this->saveProp3DSTL(0, filename.toStdString().c_str());
166         }
167     }else if(index == 2){
168
169         QString filename = QFileDialog::getSaveFileName(this,
170                                                         tr("Save Image File"),
171                                                         QDir::currentPath(),
172                                                         tr("Meta Image file (*.mhd)") );
173
174         if( !filename.isNull() ){
175
176             this->exportImageStencil(0, filename.toStdString().c_str());
177         }
178     }
179     this->ui->comboBoxSave->setCurrentIndex(0);
180 }