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"
27 #include <vtkVersion.h>
28 #include "vtkPolyDataMapper.h"
30 #include "vtkPolyData.h"
31 #include "vtkRenderWindow.h"
32 #include "vtkRendererCollection.h"
33 #include "vtkRenderer.h"
35 #include <QMessageBox>
36 #include <QFileDialog>
39 # include "vvOSXHelper.h"
42 //----------------------------------------------------------------------------
43 class vvManagerCallback : public vtkCommand
46 static vvManagerCallback *New() {
47 return new vvManagerCallback;
50 void Execute(vtkObject *caller,
52 void *vtkNotUsed(callData)) {
53 vtkInteractorStyle *isi = static_cast<vtkInteractorStyle *>(caller);
55 std::string KeyPress = isi->GetInteractor()->GetKeySym();
56 if (KeyPress == "Left") {
57 this->IV->PreviousTime();
59 if (KeyPress == "Right") {
64 vvSurfaceViewerDialog *IV;
68 //====================================================================
69 vvSurfaceViewerDialog::vvSurfaceViewerDialog(QWidget * parent, Qt::WindowFlags f)
70 :QDialog(parent,f), Ui::vvSurfaceViewerDialog()
82 connect(loadButton,SIGNAL(clicked()),this,SLOT(LoadSurface()));
85 disableGLHiDPI(renderWidget->winId());
89 vvSurfaceViewerDialog::~vvSurfaceViewerDialog()
91 for (unsigned int i = 0; i < mReaders.size(); i++)
92 mReaders[i]->Delete();
104 void vvSurfaceViewerDialog::LoadSurface()
106 QString Extensions = "All Files (*)";
107 Extensions += ";;Surface ( *.vtk)";
108 QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Surfaces"),tr(""),Extensions);
113 mMapper = vtkPolyDataMapper::New();
116 for (int i = 0; i < files.size(); i++) {
117 vtkOBJReader* reader = vtkOBJReader::New();
118 reader->SetFileName(files[i].toStdString().c_str());
120 mReaders.push_back(reader);
122 #if VTK_MAJOR_VERSION <= 5
123 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
125 mMapper->SetInputConnection(mReaders[mCurrentTime]->GetOutputPort());
129 mActor = vtkActor::New();
130 mActor->SetMapper(mMapper);
133 mRenderer = vtkRenderer::New();
134 mRenderer->AddActor(mActor);
135 renderWidget->GetRenderWindow()->AddRenderer(mRenderer);
138 mRenderer->ResetCamera();
139 renderWidget->GetRenderWindow()->Render();
141 vvManagerCallback *smc = vvManagerCallback::New();
144 if (renderWidget->GetRenderWindow()->GetInteractor())
145 renderWidget->GetRenderWindow()->GetInteractor()->
146 GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
147 //readHeader->Delete();
150 void vvSurfaceViewerDialog::NextTime()
153 if (mCurrentTime >= mReaders.size())
155 #if VTK_MAJOR_VERSION <= 5
156 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
158 mMapper->SetInputConnection(mReaders[mCurrentTime]->GetOutputPort());
161 renderWidget->GetRenderWindow()->Render();
164 void vvSurfaceViewerDialog::PreviousTime()
167 if (mCurrentTime < 0)
168 mCurrentTime = (unsigned int) mReaders.size() - 1;
169 #if VTK_MAJOR_VERSION <= 5
170 mMapper->SetInput(mReaders[mCurrentTime]->GetOutput());
172 mMapper->SetInputConnection(mReaders[mCurrentTime]->GetOutputPort());
175 renderWidget->GetRenderWindow()->Render();
178 #endif /* end #define _vvSurfaceViewerDialog_CXX */