diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 1a7c8a4c11..5c2ee1cd15 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -63,11 +63,6 @@ void cv::viz::InteractorStyle::Initialize() win_pos_ = Vec2i(0, 0); max_win_size_ = Vec2i(-1, -1); - // Create the image filter and PNG writer objects - wif_ = vtkSmartPointer::New(); - snapshot_writer_ = vtkSmartPointer::New(); - snapshot_writer_->SetInputConnection(wif_->GetOutputPort()); - init_ = true; stereo_anaglyph_mask_default_ = true; @@ -84,11 +79,14 @@ void cv::viz::InteractorStyle::Initialize() void cv::viz::InteractorStyle::saveScreenshot(const String &file) { FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); - wif_->SetInput(Interactor->GetRenderWindow()); - wif_->Modified(); // Update the WindowToImageFilter - snapshot_writer_->Modified(); - snapshot_writer_->SetFileName(file.c_str()); - snapshot_writer_->Write(); + + vtkSmartPointer wif = vtkSmartPointer::New(); + wif->SetInput(Interactor->GetRenderWindow()); + + vtkSmartPointer snapshot_writer = vtkSmartPointer::New(); + snapshot_writer->SetInputConnection(wif->GetOutputPort()); + snapshot_writer->SetFileName(file.c_str()); + snapshot_writer->Write(); } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -196,21 +194,13 @@ int cv::viz::InteractorStyle::getModifiers() } ////////////////////////////////////////////////////////////////////////////////////////////// -void -cv::viz::InteractorStyle::OnKeyDown() +void cv::viz::InteractorStyle::OnKeyDown() { CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_); CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_); FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); - if (wif_->GetInput() == NULL) - { - wif_->SetInput(Interactor->GetRenderWindow()); - wif_->Modified(); - snapshot_writer_->Modified(); - } - // Save the initial windows width/height if (win_size_[0] == -1 || win_size_[1] == -1) win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); diff --git a/modules/viz/src/interactor_style.hpp b/modules/viz/src/interactor_style.hpp index 51f98635bc..7ae4fa75c2 100644 --- a/modules/viz/src/interactor_style.hpp +++ b/modules/viz/src/interactor_style.hpp @@ -79,12 +79,6 @@ namespace cv Vec2i win_pos_; Vec2i max_win_size_; - /** \brief A PNG writer for screenshot captures. */ - vtkSmartPointer snapshot_writer_; - - /** \brief Internal window to image filter. Needed by \a snapshot_writer_. */ - vtkSmartPointer wif_; - /** \brief Interactor style internal method. Gets called whenever a key is pressed. */ virtual void OnChar();