From: malaterre Date: Wed, 3 Oct 2007 15:50:13 +0000 (+0000) Subject: ENH: s key is now save to a file a screenshot X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b20cb3a9c288cb0c019df4245899666eeda55649;p=gdcm.git ENH: s key is now save to a file a screenshot --- diff --git a/vtk/vtkgdcmViewer2.cxx b/vtk/vtkgdcmViewer2.cxx index deefba6f..72dd2379 100644 --- a/vtk/vtkgdcmViewer2.cxx +++ b/vtk/vtkgdcmViewer2.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkgdcmViewer2.cxx,v $ Language: C++ - Date: $Date: 2007/09/13 11:32:53 $ - Version: $Revision: 1.14 $ + Date: $Date: 2007/10/03 15:50:13 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -39,6 +39,9 @@ #endif #include #include +#include +#include +#include #include #include #include @@ -67,11 +70,14 @@ public: { this->ImageViewer = NULL; } - virtual void Execute(vtkObject *, unsigned long event, void* ) + virtual void Execute(vtkObject *caller, unsigned long event, void* /*callData*/ ) { if ( this->ImageViewer ) { - if ( event == vtkCommand::CharEvent ) + vtkRenderWindowInteractor * rwi = vtkRenderWindowInteractor::SafeDownCast( caller ); + char keycode = 0; + if( rwi ) keycode = rwi->GetKeyCode(); + if ( event == vtkCommand::CharEvent && keycode != 's' ) { #if VTK_MAJOR_VERSION >= 5 int max = ImageViewer->GetSliceMax(); @@ -88,6 +94,16 @@ public: #endif ImageViewer->Render(); } + else if ( keycode == 's' ) + { + vtkPNGWriter * writer = vtkPNGWriter::New(); + vtkWindowToImageFilter * w2i = vtkWindowToImageFilter::New(); + w2i->SetInput( rwi->GetRenderWindow() ); + writer->SetInput( w2i->GetOutput() ); + writer->SetFileName( "snapshot.png" ); + writer->Write(); + //std::cerr << "Screenshort saved to snapshot.png" << std::endl; + } } } #if VTK_MAJOR_VERSION >= 5