ITK  5.0.0
Insight Segmentation and Registration Toolkit
vtkCaptureScreen.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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  using ImageWriterType = TImageWriter;
32 
33  vtkCaptureScreen( vtkRenderWindow* iRenderer ) : m_Renderer ( iRenderer )
34  {}
35 
37  {}
38 
40  {}
41 
42  void operator( ) ( const std::string& iFileName ) const
43  {
44  Capture( m_Renderer, iFileName );
45  }
46 
47  void operator( ) ( vtkRenderWindow* iRenderer,
48  const std::string& iFileName ) const
49  {
50  m_Renderer = iRenderer;
51  Capture( m_Renderer, iFileName );
52  }
53 
54  private:
56  void operator = ( const vtkCaptureScreen& );
57 
58  vtkRenderWindow* m_Renderer;
59 
60  void Capture( vtkRenderWindow* iRenderer,
61  const std::string& iFileName ) const
62  {
63  if( iRenderer )
64  {
65  vtkSmartPointer< vtkWindowToImageFilter > Dumper =
66  vtkSmartPointer< vtkWindowToImageFilter >::New( );
67  Dumper->SetInput( iRenderer );
68  Dumper->Update( );
69 
70  vtkSmartPointer< ImageWriterType > writer =
71  vtkSmartPointer< ImageWriterType >::New( );
72  writer->SetFileName ( iFileName.c_str( ) );
73  writer->SetInputConnection ( Dumper->GetOutputPort( ) );
74  writer->Write( );
75  }
76  }
77  };
78 
79 #endif
vtkCaptureScreen(vtkRenderWindow *iRenderer)
vtkRenderWindow * m_Renderer
void operator=(const vtkCaptureScreen &)
void Capture(vtkRenderWindow *iRenderer, const std::string &iFileName) const
TImageWriter ImageWriterType