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