]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkScreenShot.cxx
VTK7
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkScreenShot.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkScreenShot.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkWindowToImageFilter.h"
8 #include "vtkPNGWriter.h"
9 #include "vtkWindow.h"
10
11 // #include "vtkFFMPEGWriter.h"
12
13
14 namespace bbcreaVtk
15 {
16
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ScreenShot)
18 BBTK_BLACK_BOX_IMPLEMENTATION(ScreenShot,bbtk::AtomicBlackBox);
19 //===== 
20 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
21 //===== 
22 void ScreenShot::Process()
23 {
24
25 // THE MAIN PROCESSING METHOD BODY
26 //   Here we simply set the input 'In' value to the output 'Out'
27 //   And print out the output value
28 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
29 //    void bbSet{Input|Output}NAME(const TYPE&)
30 //    const TYPE& bbGet{Input|Output}NAME() const 
31 //    Where :
32 //    * NAME is the name of the input/output
33 //      (the one provided in the attribute 'name' of the tag 'input')
34 //    * TYPE is the C++ type of the input/output
35 //      (the one provided in the attribute 'type' of the tag 'input')
36
37 //    bbSetOutputOut( bbGetInputIn() );
38 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
39   
40         vtkWindowToImageFilter *wif = vtkWindowToImageFilter::New();
41                 if (bbGetInputSize().size()==2) 
42                 {
43                         bbGetInputvtkRenderer()->GetVTKWindow()->SetSize( bbGetInputSize()[0], bbGetInputSize()[1] );
44                 }
45         wif->SetInput( bbGetInputvtkRenderer()->GetVTKWindow() );
46         wif->SetMagnification( bbGetInputScale()[0] );
47 //              wif->SetScale( bbGetInputScale()[0], bbGetInputScale()[1] );
48         wif->SetInputBufferTypeToRGB();
49         wif->ReadFrontBufferOff();
50         wif->Update();
51         vtkPNGWriter *writer = vtkPNGWriter::New();
52                 writer->SetFileName( bbGetInputFileName().c_str() );
53
54 //EED 2017-01-01 Migration VTK7
55 #if VTK_MAJOR_VERSION <= 5
56                 writer->SetInput( wif->GetOutput() );
57 #else
58                 writer->SetInputData( wif->GetOutput() );
59 #endif
60
61
62                 writer->Write();        
63
64 /*
65         vtkFFMPEGWriter *writer2 = vtkFFMPEGWriter::New();
66         writer2->SetInput(wif->GetOutput());
67         for (int i=0; i<10; i++)
68         {
69                 // update
70                 writer2->Write();
71         } // for 
72         writer2->End;
73 */
74 }
75 //===== 
76 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
77 //===== 
78 void ScreenShot::bbUserSetDefaultValues()
79 {
80
81 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
82 //    Here we initialize the input 'In' to 0
83    bbSetInputvtkRenderer(NULL);
84    bbSetInputFileName("ScreenShot-BBTK.png");
85    
86    std::vector<int> scale;
87    scale.push_back(1);
88    scale.push_back(1);
89    bbSetInputScale(scale);
90   
91 }
92 //===== 
93 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
94 //===== 
95 void ScreenShot::bbUserInitializeProcessing()
96 {
97
98 //  THE INITIALIZATION METHOD BODY :
99 //    Here does nothing 
100 //    but this is where you should allocate the internal/output pointers 
101 //    if any 
102
103   
104 }
105 //===== 
106 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
107 //===== 
108 void ScreenShot::bbUserFinalizeProcessing()
109 {
110
111 //  THE FINALIZATION METHOD BODY :
112 //    Here does nothing 
113 //    but this is where you should desallocate the internal/output pointers 
114 //    if any
115   
116 }
117 }
118 // EO namespace bbcreaVtk
119
120