ITK  6.0.0
Insight Toolkit
vtkCaptureScreen.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef vtkCaptureScreen_h
20 #define vtkCaptureScreen_h
21 
22 #include <string>
23 #include "vtkSmartPointer.h"
24 #include "vtkWindowToImageFilter.h"
25 #include "vtkRenderWindow.h"
26 
27 template <typename TImageWriter>
29 {
30 public:
31  ITK_DISALLOW_COPY_AND_MOVE(vtkCaptureScreen);
32 
33  using ImageWriterType = TImageWriter;
34 
35  vtkCaptureScreen(vtkRenderWindow * iRenderer)
36  : m_Renderer(iRenderer)
37  {}
38 
39  vtkCaptureScreen() = default;
40  ~vtkCaptureScreen() = default;
41 
42  void
43  operator()(const std::string & iFileName) const
44  {
45  Capture(m_Renderer, iFileName);
46  }
47 
48  void
49  operator()(vtkRenderWindow * iRenderer, const std::string & iFileName)
50  {
51  m_Renderer = iRenderer;
52  Capture(m_Renderer, iFileName);
53  }
54 
55 private:
56  vtkRenderWindow * m_Renderer{ nullptr };
57 
58  void
59  Capture(vtkRenderWindow * iRenderer, const std::string & iFileName) const
60  {
61  if (iRenderer)
62  {
63  vtkSmartPointer<vtkWindowToImageFilter> Dumper = vtkSmartPointer<vtkWindowToImageFilter>::New();
64  Dumper->SetInput(iRenderer);
65  Dumper->Update();
66 
67  vtkSmartPointer<ImageWriterType> writer = vtkSmartPointer<ImageWriterType>::New();
68  writer->SetFileName(iFileName.c_str());
69  writer->SetInputConnection(Dumper->GetOutputPort());
70  writer->Write();
71  }
72  }
73 };
74 
75 #endif
vtkCaptureScreen::operator()
void operator()(vtkRenderWindow *iRenderer, const std::string &iFileName)
Definition: vtkCaptureScreen.h:49
vtkCaptureScreen::vtkCaptureScreen
vtkCaptureScreen()=default
vtkCaptureScreen::m_Renderer
vtkRenderWindow * m_Renderer
Definition: vtkCaptureScreen.h:56
vtkCaptureScreen::ImageWriterType
TImageWriter ImageWriterType
Definition: vtkCaptureScreen.h:33
vtkCaptureScreen::vtkCaptureScreen
vtkCaptureScreen(vtkRenderWindow *iRenderer)
Definition: vtkCaptureScreen.h:35
vtkCaptureScreen::~vtkCaptureScreen
~vtkCaptureScreen()=default
vtkCaptureScreen::operator()
void operator()(const std::string &iFileName) const
Definition: vtkCaptureScreen.h:43
vtkCaptureScreen
Definition: vtkCaptureScreen.h:28
New
static Pointer New()
vtkCaptureScreen::Capture
void Capture(vtkRenderWindow *iRenderer, const std::string &iFileName) const
Definition: vtkCaptureScreen.h:59