]> 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                 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                 writer->SetInput(wif->GetOutput());
54                 writer->Write();        
55
56 /*
57         vtkFFMPEGWriter *writer2 = vtkFFMPEGWriter::New();
58         writer2->SetInput(wif->GetOutput());
59         for (int i=0; i<10; i++)
60         {
61                 // update
62                 writer2->Write();
63         } // for 
64         writer2->End;
65 */
66 }
67 //===== 
68 // 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)
69 //===== 
70 void ScreenShot::bbUserSetDefaultValues()
71 {
72
73 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
74 //    Here we initialize the input 'In' to 0
75    bbSetInputvtkRenderer(NULL);
76    bbSetInputFileName("ScreenShot-BBTK.png");
77    
78    std::vector<int> scale;
79    scale.push_back(1);
80    scale.push_back(1);
81    bbSetInputScale(scale);
82   
83 }
84 //===== 
85 // 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)
86 //===== 
87 void ScreenShot::bbUserInitializeProcessing()
88 {
89
90 //  THE INITIALIZATION METHOD BODY :
91 //    Here does nothing 
92 //    but this is where you should allocate the internal/output pointers 
93 //    if any 
94
95   
96 }
97 //===== 
98 // 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)
99 //===== 
100 void ScreenShot::bbUserFinalizeProcessing()
101 {
102
103 //  THE FINALIZATION METHOD BODY :
104 //    Here does nothing 
105 //    but this is where you should desallocate the internal/output pointers 
106 //    if any
107   
108 }
109 }
110 // EO namespace bbcreaVtk
111
112