#include "wxSnapshotTaker.h" #include #include #include #include #include #include #include #include wxSnapshotTaker::wxSnapshotTaker (wxWindow* parent) { m_Parent = parent; m_Magnification = 1; m_RenderWindow = 0; } wxSnapshotTaker::~wxSnapshotTaker() {} void wxSnapshotTaker::Snap() { if( !m_RenderWindow ) { std::cerr << "Error: RenderWindow is not set." << std::endl; return; } wxFileDialog* myFileDialog = new wxFileDialog(m_Parent, wxT("Save snapshot as"), wxT(""), wxT(""), wxT("Image file (*.jpg;*.jpeg;*.bmp;*.png;*.tiff)|*.jpg;*.jpeg;*.bmp;*.png;*.tiff|") wxT("jpeg (*.jpg;*.jpeg)|*.jpg;*.jpeg|") wxT("bmp (*.bmp)|*.bmp|") wxT("png (*.png)|*.png|") wxT("tiff (*.tiff)|*.tiff|") wxT("all (*.*)|*.*"), wxFD_SAVE|wxFD_CHANGE_DIR|wxFD_OVERWRITE_PROMPT, wxDefaultPosition); wxString fileName; fileName.Empty(); int OK = myFileDialog->ShowModal(); if( OK==wxID_OK ) { fileName = myFileDialog->GetPath(); } myFileDialog->Destroy(); if( fileName.IsEmpty() ) { return; } std::string s_filename (fileName.c_str()); vtksys_stl::string ext = vtksys::SystemTools::GetFilenameLastExtension (s_filename); if( ext=="" ) { fileName += wxT (".jpg"); ext = vtksys::SystemTools::GetFilenameLastExtension (s_filename); } vtkImageWriter* writer = 0; if( ext==".jpg" || ext==".jpeg" ) { writer = vtkJPEGWriter::New(); } else if ( ext==".bmp" ) { writer = vtkBMPWriter::New(); } else if ( ext==".tiff" ) { writer = vtkTIFFWriter::New(); } else if ( ext==".png" ) { writer = vtkPNGWriter::New(); } else { //ERROR message here wxString message = wxT ("Error: Format is not supported."); wxMessageDialog* myDialog = new wxMessageDialog(m_Parent, message, wxT ("Error"), wxOK|wxICON_ERROR); myDialog->ShowModal(); myDialog->Destroy(); return; } vtkWindowToImageFilter* snapper = vtkWindowToImageFilter::New(); snapper->SetMagnification( m_Magnification ); snapper->SetInput( m_RenderWindow ); writer->SetInput( snapper->GetOutput() ); writer->SetFileName( fileName.c_str() ); writer->Write(); snapper->Delete(); writer->Delete(); }