1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include <QApplication>
21 #include <vtkImageClip.h>
22 #include <vtkImageTranslateExtent.h>
23 #include <vtkImageData.h>
24 #include <vtkSmartPointer.h>
25 #include "vvCropDialog.h"
26 #include "vvSlicerManager.h"
27 #include "clitkCommon.h"
29 vvCropDialog::vvCropDialog(std::vector<vvSlicerManager*> sms,int current) :
33 for (unsigned int i=0; i<mSlicerManagers.size(); i++)
34 inputSequenceBox->addItem(vtksys::SystemTools::GetFilenameName(mSlicerManagers[i]->GetFileName()).c_str());
35 connect(inputSequenceBox,SIGNAL(currentIndexChanged(int)),this,SLOT(ImageChanged(int)));
36 inputSequenceBox->setCurrentIndex(current);
37 ImageChanged(current);
38 connect(this,SIGNAL(accepted()),this,SLOT(ComputeCroppedImage()));
41 void vvCropDialog::ImageChanged(int newindex)
43 std::vector<int> imsize=mSlicerManagers[newindex]->GetImage()->GetSize();
44 xminSlider->setMaximum(imsize[0]-1);
45 xmaxSlider->setMaximum(imsize[0]-1);
46 xmaxSlider->setValue(imsize[0]-1);
47 yminSlider->setMaximum(imsize[1]-1);
48 ymaxSlider->setMaximum(imsize[1]-1);
49 ymaxSlider->setValue(imsize[1]-1);
50 zminSlider->setMaximum(imsize[2]-1);
51 zmaxSlider->setMaximum(imsize[2]-1);
52 zmaxSlider->setValue(imsize[2]-1);
53 spin_xmin->setMaximum(imsize[0]-1);
54 spin_xmax->setMaximum(imsize[0]-1);
55 spin_xmax->setValue(imsize[0]-1);
56 spin_ymin->setMaximum(imsize[1]-1);
57 spin_ymax->setMaximum(imsize[1]-1);
58 spin_ymax->setValue(imsize[1]-1);
59 spin_zmin->setMaximum(imsize[2]-1);
60 spin_zmax->setMaximum(imsize[2]-1);
61 spin_zmax->setValue(imsize[2]-1);
64 void vvCropDialog::ComputeCroppedImage()
66 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
67 mResult=vvImage::New();
68 vvSlicerManager * current=mSlicerManagers[inputSequenceBox->currentIndex()];
69 vvImage::Pointer image=current->GetImage();
70 for (std::vector<vtkImageData*>::const_iterator i=image->GetVTKImages().begin();
71 i!=image->GetVTKImages().end(); i++) {
72 vtkSmartPointer<vtkImageClip> filter=vtkSmartPointer<vtkImageClip>::New();
73 ///Vtk is very weird, you need to "translate the extent" to get the correct origin
74 //http://markmail.org/message/vndc2tr6kcabiakp#query:vtkImageClip%20origin+page:1+mid:6na7y57floutklvz+state:results
75 vtkSmartPointer<vtkImageTranslateExtent> translate=vtkSmartPointer<vtkImageTranslateExtent>::New();
77 filter->SetOutputWholeExtent(xminSlider->value(),xmaxSlider->value(),
78 yminSlider->value(),ymaxSlider->value(),
79 zminSlider->value(),zmaxSlider->value());
80 translate->SetTranslation(-xminSlider->value(),-yminSlider->value(),-zminSlider->value());
81 translate->SetInput(filter->GetOutput());
82 filter->ClipDataOn(); //Really create a cropped copy of the image
84 vtkImageData* output=vtkImageData::New();
85 output->ShallowCopy(translate->GetOutput());
86 mResult->AddImage(output);
88 QApplication::restoreOverrideCursor();