]> Creatis software - clitk.git/blob - vv/vvWipeImage.cxx
c2d5a7e303378483d01924a61b7e6aca7c6c4f9b
[clitk.git] / vv / vvWipeImage.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18
19 // vv
20 #include "vvWipeImage.h"
21 #include "vvSlicer.h"
22
23 // clitk
24 #include "clitkCropImage_ggo.h"
25 #include "clitkCropImageGenericFilter.h"
26 #include "clitkExceptionObject.h"
27
28 // qt
29 #include <QComboBox>
30 #include <QCursor>
31 #include <QApplication>
32 #include <QMessageBox>
33 #include <QSignalMapper>
34 #include <QFileDialog>
35
36 // vtk
37 #include <vtkVersion.h>
38 #include <vtkStreamingDemandDrivenPipeline.h>
39 #include <vtkInformation.h>
40 #include <vtkImageData.h>
41 #include <vtkSmartPointer.h>
42
43
44 #include <extensions.h>
45
46 #define COLUMN_TREE 0
47 #define COLUMN_UL_VIEW 1
48 #define COLUMN_UR_VIEW 2
49 #define COLUMN_DL_VIEW 3
50 #define COLUMN_DR_VIEW 4
51 #define COLUMN_CLOSE_IMAGE 5
52 #define COLUMN_RELOAD_IMAGE 6
53 #define COLUMN_IMAGE_NAME 7
54
55 //------------------------------------------------------------------------------
56 vvWipeImage::vvWipeImage():
57   Ui::vvWipeImage()
58 {
59     vtkSmartPointer<vtkImageRectilinearWipe> mWipe = vtkSmartPointer<vtkImageRectilinearWipe>::New();
60     mWipe->SetWipe(0);
61     mWipe->SetPosition(256,256);
62 }
63 //------------------------------------------------------------------------------
64
65
66 //------------------------------------------------------------------------------
67 vvWipeImage::~vvWipeImage()
68 {
69 }
70 //------------------------------------------------------------------------------
71
72 void vvWipeImage::Initialize(QString inputPathName, std::vector<vvSlicerManager*> slicerManagers)
73 {
74   mInputPathName = inputPathName;
75   mSlicerManagers = slicerManagers;
76 }
77
78 //------------------------------------------------------------------------------
79 void vvWipeImage::setInputImage(int number, vvImage::Pointer image)
80 {
81   if (image->GetVTKImages().size()) {
82     mImage = image;
83     mWipe->SetInputData(number, mImage->GetVTKImages()[0]); //[0] pour du 4D ?
84   }
85 }
86 //------------------------------------------------------------------------------
87
88
89
90 //------------------------------------------------------------------------------
91 void vvWipeImage::crossPointerChanged()
92 {
93   mWipe->SetPosition(256,256);
94   UpdateWipe();
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 void vvWipeImage::UpdateWipe()
101 {
102
103 }
104 //------------------------------------------------------------------------------
105
106
107 //------------------------------------------------------------------------------
108 void vvWipeImage::selectWipeImage(int index)
109
110
111   QString Extensions = EXTENSIONS;
112   Extensions += ";;All Files (*)";
113   QStringList files = QFileDialog::getOpenFileNames(NULL,tr("Load Wipe image"),mInputPathName,Extensions);
114   if (files.isEmpty())
115     return;
116
117   std::vector<std::string> vecFileNames;
118   for (int i = 0; i < files.size(); i++) {
119     vecFileNames.push_back(files[i].toStdString());
120   }
121
122   AddWipeImage(index,vecFileNames,vvImageReader::IMAGE);
123 }
124 //------------------------------------------------------------------------------
125
126 void vvWipeImage::AddWipeImage(int index, std::vector<std::string> fileNames, vvImageReader::LoadedImageType type)
127
128   QString file(fileNames[0].c_str());
129   if (QFile::exists(file))
130   {
131     mInputPathName = itksys::SystemTools::GetFilenamePath(file.toStdString()).c_str();
132     itk::ImageIOBase::Pointer reader = itk::ImageIOFactory::CreateImageIO(
133       file.toStdString().c_str(), itk::ImageIOFactory::ReadMode);
134     reader->SetFileName(fileNames[0].c_str());
135     reader->ReadImageInformation();
136     std::string component = reader->GetComponentTypeAsString(reader->GetComponentType());
137     int dimension = reader->GetNumberOfDimensions();
138     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
139     vvProgressDialog progress("Opening " + file.toStdString());
140     qApp->processEvents();
141
142     std::string filename = itksys::SystemTools::GetFilenameWithoutExtension(file.toStdString()).c_str();
143 //    if (mSlicerManagers[index]->SetOverlay(fileNames,dimension, component,type)) {
144       //create an item in the tree with good settings
145       QTreeWidgetItem *item = new QTreeWidgetItem();
146       item->setData(0,Qt::UserRole,file.toStdString().c_str());
147       item->setData(1,Qt::UserRole,tr("overlay"));
148       QFileInfo fileinfo(file); //Do not show the path
149       item->setData(COLUMN_IMAGE_NAME,Qt::DisplayRole,fileinfo.fileName());
150       item->setToolTip(COLUMN_IMAGE_NAME, mSlicerManagers[index]->GetListOfAbsoluteFilePathInOneString("overlay").c_str());
151       qApp->processEvents();
152 #if VTK_MAJOR_VERSION > 5
153       for ( unsigned int i = 0; i < mSlicerManagers[index]->GetNumberOfSlicers(); i++)
154         mSlicerManagers[index]->GetSlicer(i)->ForceUpdateDisplayExtent();
155 #endif
156
157       for (int j = 1; j <= 4; j++) {
158         item->setData(j,Qt::CheckStateRole,GetTree()->topLevelItem(index)->data(j,Qt::CheckStateRole));
159       }
160
161       //Create the buttons for reload and close
162       qApp->processEvents();
163       QTreePushButton* cButton = new QTreePushButton;
164       cButton->setItem(item);
165       cButton->setColumn(COLUMN_CLOSE_IMAGE);
166       cButton->setToolTip(tr("close image"));
167       cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
168       /*connect(cButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
169         this,SLOT(CloseImage(QTreeWidgetItem*, int)));
170
171       QTreePushButton* rButton = new QTreePushButton;
172       rButton->setItem(item);
173       rButton->setColumn(COLUMN_RELOAD_IMAGE);
174       rButton->setToolTip(tr("reload image"));
175       rButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/rotateright.png")));
176       connect(rButton,SIGNAL(clickedInto(QTreeWidgetItem*, int)),
177         this,SLOT(ReloadImage(QTreeWidgetItem*, int)));
178
179       DataTree->topLevelItem(index)->setExpanded(1);
180       DataTree->topLevelItem(index)->addChild(item);
181       DataTree->setItemWidget(item, COLUMN_CLOSE_IMAGE, cButton);
182       DataTree->setItemWidget(item, COLUMN_RELOAD_IMAGE, rButton);
183
184       //set the id of the image
185       QString id = DataTree->topLevelItem(index)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString();
186       item->setData(COLUMN_IMAGE_NAME,Qt::UserRole,id.toStdString().c_str());
187       UpdateTree();
188       qApp->processEvents();
189       ImageInfoChanged();
190       QApplication::restoreOverrideCursor();
191
192       // Update the display to update, e.g., the sliders
193       for(int i=0; i<4; i++)
194         DisplaySliders(index, i);
195     } else {
196       QApplication::restoreOverrideCursor();
197       QString error = "Cannot import the new image.\n";
198       error += mSlicerManagers[index]->GetLastError().c_str();
199       QMessageBox::information(this,tr("Problem reading image !"),error);
200     }
201     WindowLevelChanged(); */
202   }
203   else
204     QMessageBox::information(NULL,tr("Problem reading wipe Image !"),"File doesn't exist!");
205 }
206 //------------------------------------------------------------------------------
207
208
209