]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkScreenShot.cxx
#3233 creaVtk Feature New Normal - GetCameraInfo SetCameraInfo ScreenShot
[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         wif->SetInput( bbGetInputvtkRenderer()->GetVTKWindow() );
42         wif->SetMagnification( bbGetInputScale()[0] );
43 //              wif->SetScale( bbGetInputScale()[0], bbGetInputScale()[1] );
44         wif->SetInputBufferTypeToRGB();
45         wif->ReadFrontBufferOff();
46         wif->Update();
47       vtkPNGWriter *writer = vtkPNGWriter::New();
48         writer->SetFileName( bbGetInputFileName().c_str() );
49         writer->SetInput(wif->GetOutput());
50         writer->Write();        
51
52 /*
53         vtkFFMPEGWriter *writer2 = vtkFFMPEGWriter::New();
54         writer2->SetInput(wif->GetOutput());
55         for (int i=0; i<10; i++)
56         {
57                 // update
58                 writer2->Write();
59         } // for 
60         writer2->End;
61 */
62 }
63 //===== 
64 // 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)
65 //===== 
66 void ScreenShot::bbUserSetDefaultValues()
67 {
68
69 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
70 //    Here we initialize the input 'In' to 0
71    bbSetInputvtkRenderer(NULL);
72    bbSetInputFileName("ScreenShot-BBTK.png");
73    
74    std::vector<int> scale;
75    scale.push_back(1);
76    scale.push_back(1);
77    bbSetInputScale(scale);
78   
79 }
80 //===== 
81 // 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)
82 //===== 
83 void ScreenShot::bbUserInitializeProcessing()
84 {
85
86 //  THE INITIALIZATION METHOD BODY :
87 //    Here does nothing 
88 //    but this is where you should allocate the internal/output pointers 
89 //    if any 
90
91   
92 }
93 //===== 
94 // 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)
95 //===== 
96 void ScreenShot::bbUserFinalizeProcessing()
97 {
98
99 //  THE FINALIZATION METHOD BODY :
100 //    Here does nothing 
101 //    but this is where you should desallocate the internal/output pointers 
102 //    if any
103   
104 }
105 }
106 // EO namespace bbcreaVtk
107
108