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 ===========================================================================**/
18 #ifndef _vvSurfaceViewerDialog_CXX
19 #define _vvSurfaceViewerDialog_CXX
23 #include "vvSurfaceViewerDialog.h"
24 #include "vtkOBJReader.h"
25 #include "vtkInteractorStyle.h"
28 #include "vtkPolyDataMapper.h"
30 #include "vtkPolyData.h"
31 #include "vtkRenderWindow.h"
32 #include "vtkRendererCollection.h"
33 #include "vtkRenderer.h"
35 #include <QMessageBox>
37 //----------------------------------------------------------------------------
38 class vvManagerCallback : public vtkCommand
41 static vvManagerCallback *New() {
42 return new vvManagerCallback;
45 void Execute(vtkObject *caller,
47 void *vtkNotUsed(callData)) {
48 vtkInteractorStyle *isi = static_cast<vtkInteractorStyle *>(caller);
50 std::string KeyPress = isi->GetInteractor()->GetKeySym();
51 if (KeyPress == "Left") {
52 this->IV->PreviousTime();
54 if (KeyPress == "Right") {
59 vvSurfaceViewerDialog *IV;
63 //====================================================================
64 vvSurfaceViewerDialog::vvSurfaceViewerDialog(QWidget * parent, Qt::WindowFlags f)
65 :QDialog(parent,f), Ui::vvSurfaceViewerDialog()
77 connect(loadButton,SIGNAL(clicked()),this,SLOT(LoadSurface()));
80 vvSurfaceViewerDialog::~vvSurfaceViewerDialog()
82 for (unsigned int i = 0; i < mReaders.size(); i++)
83 mReaders[i]->Delete();
95 void vvSurfaceViewerDialog::LoadSurface()
97 QString Extensions = "All Files (*)";
98 Extensions += ";;Surface ( *.vtk)";
99 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Surfaces"),tr(""),Extensions);
104 mMapper = vtkPolyDataMapper::New();
107 for (int i = 0; i < files.size(); i++) {
108 vtkOBJReader* reader = vtkOBJReader::New();
109 reader->SetFileName(files[i].toStdString().c_str());
111 mReaders.push_back(reader);
114 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
117 mActor = vtkActor::New();
118 mActor->SetMapper(mMapper);
121 mRenderer = vtkRenderer::New();
122 mRenderer->AddActor(mActor);
123 renderWidget->GetRenderWindow()->AddRenderer(mRenderer);
126 mRenderer->ResetCamera();
127 renderWidget->GetRenderWindow()->Render();
129 vvManagerCallback *smc = vvManagerCallback::New();
132 if (renderWidget->GetRenderWindow()->GetInteractor())
133 renderWidget->GetRenderWindow()->GetInteractor()->
134 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
135 //readHeader->Delete();
138 void vvSurfaceViewerDialog::NextTime()
141 if (mCurrentTime >= mReaders.size())
143 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
145 renderWidget->GetRenderWindow()->Render();
148 void vvSurfaceViewerDialog::PreviousTime()
151 if (mCurrentTime < 0)
152 mCurrentTime = (unsigned int) mReaders.size() - 1;
153 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
155 renderWidget->GetRenderWindow()->Render();
158 #endif /* end #define _vvSurfaceViewerDialog_CXX */