]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / GUI / Qt / SurfaceRenderer / qtsurfacerendererpanel.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "qtsurfacerendererpanel.h"
27 #include "ui_qtsurfacerendererpanel.h"
28
29 #include "qfiledialog.h"
30
31 #include "qcolordialog.h"
32 #include "qmessagebox.h"
33
34 #include "Color.xpm"
35 #include "Save.xpm"
36 #include "OpenImage.xpm"
37
38 QtSurfaceRendererPanel::QtSurfaceRendererPanel(QWidget *parent) :
39     QWidget(parent),
40     ui(new Ui::QtSurfaceRendererPanel)
41 {
42     ui->setupUi(this);
43
44
45     this->ui->pushButtonColorChooser->setIcon(QIcon(Color_xpm));
46     //this->ui->pushButtonSave->setIcon(QIcon(Save_xpm));
47     this->ui->pushButtonOpen->setIcon(QIcon(OpenImage_xpm));
48
49     this->ui->comboBoxSave->addItem(QIcon(Save_xpm), QString(""));
50     this->ui->comboBoxSave->addItem(QString("Save surface"));
51     this->ui->comboBoxSave->addItem(QString("Export image stencil"));
52     _ImageSet = false;
53 }
54
55 QtSurfaceRendererPanel::~QtSurfaceRendererPanel()
56 {   
57     delete ui;
58 }
59 void QtSurfaceRendererPanel::setImageData(vtkImageData* img){
60     double *range  =img->GetScalarRange();
61
62     this->ui->horizontalSliderMinIso->setRange(range[0], range[1]);
63
64     this->ui->horizontalSliderMaxIso->setRange(range[0], range[1]);
65
66     wxMaracasSurfaceRenderingManager::setImageData(img);
67     _ImageSet = true;
68 }
69
70 void QtSurfaceRendererPanel::on_OpacitySlider_valueChanged(int value)
71 {
72     try{
73
74         this->ui->lineEditOpacity->setText(QString::number(value));
75
76
77         this->changeOpacity(0, value);
78     }catch(char * e){
79         cout<<e<<endl;
80         QMessageBox::critical(this, tr("Volume Rendering"), tr(e), QMessageBox::Ok);
81     }
82 }
83
84 void QtSurfaceRendererPanel::on_pushButtonColorChooser_clicked()
85 {
86     QColorDialog* qcolor = new QColorDialog(this);
87
88
89
90     if(qcolor->exec()){
91
92         QColor color = qcolor->selectedColor();
93
94         int r = 0, g = 0, b = 0;
95         color.getRgb(&r, &g, &b);
96
97         try{
98
99             this->changeColor(0, r/255.0, g/255.0 ,b/255.0);
100         }catch(char * e){
101             cout<<e<<endl;
102             QMessageBox::critical(this, tr("Surface Rendering"), tr(e), QMessageBox::Ok);
103         }
104     }
105
106
107 }
108
109 void QtSurfaceRendererPanel::on_checkBox_clicked(bool checked)
110 {
111     if(!this->addRemoveActor(0, checked)){
112         this->ui->checkBox->setChecked(false);
113     }else if(!checked){
114         this->ui->checkBoxBoundingBox->setCheckState(Qt::Unchecked);
115         this->on_checkBoxBoundingBox_clicked(false);
116     }
117 }
118
119 void QtSurfaceRendererPanel::on_horizontalSliderMaxIso_valueChanged(int value)
120 {
121
122     this->ui->lineEditMaxIso->setText(QString::number(value));
123 }
124
125 void QtSurfaceRendererPanel::on_horizontalSliderMinIso_valueChanged(int value)
126 {
127     this->ui->lineEditMinIso->setText(QString::number(value));
128 }
129
130 void QtSurfaceRendererPanel::on_horizontalSliderMaxIso_sliderReleased()
131 {
132     onIsoValueChanged();
133 }
134
135 void QtSurfaceRendererPanel::on_horizontalSliderMinIso_sliderReleased()
136 {
137     onIsoValueChanged();
138 }
139
140 void QtSurfaceRendererPanel::onIsoValueChanged(){
141     if(_ImageSet)
142         this->changeIsoValue(0, this->ui->horizontalSliderMinIso->value(), this->ui->horizontalSliderMaxIso->value());
143 }
144
145 /*void QtSurfaceRendererPanel::on_pushButtonSave_clicked()
146 {
147     QString filename = QFileDialog::getSaveFileName(this,
148                                                     tr("Save Mesh File"),
149                                                     QDir::currentPath(),
150                                                     tr("Mesh files (*.stl *.ply *.vtk)") );
151
152     if( !filename.isNull() ){
153         //filename.append(".stl");
154         this->saveProp3DSTL(0, filename.toStdString().c_str());
155     }
156
157 }*/
158
159 void QtSurfaceRendererPanel::on_checkBoxBoundingBox_clicked(bool checked)
160 {
161     this->enableBoundingBox(0, checked);
162
163 }
164
165 void QtSurfaceRendererPanel::on_pushButtonOpen_clicked(bool checked)
166 {
167
168 }
169
170 void QtSurfaceRendererPanel::on_pushButtonOpen_clicked()
171 {
172     QString filename = QFileDialog::getOpenFileName(this, tr("Load Mesh File"), QDir::currentPath(),  tr("Mesh files (*.stl *.ply *.vtk)"));
173
174     if(!filename.isNull()){
175         this->loadProp3DSTL(filename.toStdString().c_str());
176         this->ui->checkBox->setCheckState(Qt::Checked);
177     }
178 }
179
180 void QtSurfaceRendererPanel::on_comboBoxSave_activated(int index)
181 {
182     if(index == 1){
183         QString filename = QFileDialog::getSaveFileName(this,
184                                                         tr("Save Mesh File"),
185                                                         QDir::currentPath(),
186                                                         tr("Mesh files (*.stl *.ply *.vtk)") );
187
188         if( !filename.isNull() ){
189             //filename.append(".stl");
190             this->saveProp3DSTL(0, filename.toStdString().c_str());
191         }
192     }else if(index == 2){
193
194         QString filename = QFileDialog::getSaveFileName(this,
195                                                         tr("Save Image File"),
196                                                         QDir::currentPath(),
197                                                         tr("Meta Image file (*.mhd)") );
198
199         if( !filename.isNull() ){
200
201             this->exportImageStencil(0, filename.toStdString().c_str());
202         }
203     }
204     this->ui->comboBoxSave->setCurrentIndex(0);
205 }