]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx
#3370 creaVtk Feature New Normal - Compare Images with RGB
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkPolyDataToImageData.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 "bbcreaVtkPolyDataToImageData.h"
5 #include "bbcreaVtkPackage.h"
6
7
8 namespace bbcreaVtk
9 {
10
11 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PolyDataToImageData)
12 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataToImageData,bbtk::AtomicBlackBox);
13 //===== 
14 // 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)
15 //===== 
16 void PolyDataToImageData::Process()
17 {
18
19 // THE MAIN PROCESSING METHOD BODY
20 //   Here we simply set the input 'In' value to the output 'Out'
21 //   And print out the output value
22 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
23 //    void bbSet{Input|Output}NAME(const TYPE&)
24 //    const TYPE& bbGet{Input|Output}NAME() const 
25 //    Where :
26 //    * NAME is the name of the input/output
27 //      (the one provided in the attribute 'name' of the tag 'input')
28 //    * TYPE is the C++ type of the input/output
29 //      (the one provided in the attribute 'type' of the tag 'input')
30
31 //    bbSetOutputOut( bbGetInputIn() );
32 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
33
34         if ((bbGetInputInPolyData()!=NULL) && (bbGetInputInImage()!=NULL) )
35         {
36
37 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
38 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
39 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
40 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
41 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
42 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
43 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
44 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
45 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
46 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
47 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
48 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
49 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
50 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
51 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
52 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
53
54                 int ext[6];
55                 bbGetInputInImage()->GetExtent( ext );
56
57 //              vtkCleanPolyData *clean1 = vtkCleanPolyData::New();             
58                 if (clean1!=NULL) clean1->Delete();
59                 clean1 = vtkCleanPolyData::New();
60                 clean1->SetInputData( bbGetInputInPolyData() );
61                 clean1->Update();
62                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
63                 triangle1->SetInputData( clean1->GetOutput() );
64                 triangle1->Update();
65
66 //              vtkPolyDataToImageStencil *dataToStencil = vtkPolyDataToImageStencil::New();
67                 if (dataToStencil!=NULL) dataToStencil->Delete();
68                 dataToStencil = vtkPolyDataToImageStencil::New();
69                 dataToStencil->SetInputData( triangle1->GetOutput() );
70                 dataToStencil->SetOutputWholeExtent( ext );
71                 dataToStencil->Update();
72
73 //              vtkExtractVOI *extract = vtkExtractVOI::New();
74                 if (extract!=NULL) extract->Delete();
75                 extract = vtkExtractVOI::New();
76                 extract->SetVOI( ext );
77                 extract->SetSampleRate(1, 1, 1);
78                 extract->SetInputData( bbGetInputInImage() );
79                 extract->ReleaseDataFlagOff();
80                 extract->Update();      
81
82 //              vtkImageStencil *stencil = vtkImageStencil::New();
83                 if (stencil!=NULL) stencil->Delete();
84                 stencil = vtkImageStencil::New();
85                 stencil->SetInputData( extract->GetOutput() );
86                 stencil->Update();
87                 stencil->SetStencilData(  dataToStencil->GetOutput() );
88                 stencil->ReverseStencilOn();
89                 stencil->SetBackgroundValue( bbGetInputBackgroundValue() );
90                 stencil->Update();
91
92                 bbSetOutputOut( stencil->GetOutput() );
93         } else {
94                 printf("EED Warnning!  PolyDataToImageData::Process  > Missing Image or PolyData inputs\n");
95         }// if In NULL
96   
97 }
98 //===== 
99 // 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)
100 //===== 
101 void PolyDataToImageData::bbUserSetDefaultValues()
102 {
103
104 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
105 //    Here we initialize the input 'In' to 0
106         bbSetInputInPolyData(NULL);
107         bbSetInputInImage(NULL);
108         bbSetInputBackgroundValue(255);
109  
110 }
111 //===== 
112 // 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)
113 //===== 
114 void PolyDataToImageData::bbUserInitializeProcessing()
115 {
116
117 //  THE INITIALIZATION METHOD BODY :
118 //    Here does nothing 
119 //    but this is where you should allocate the internal/output pointers 
120 //    if any 
121         clean1                  = NULL;
122         dataToStencil   = NULL;
123         extract                 = NULL;
124         stencil                 = NULL;
125
126 }
127 //===== 
128 // 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)
129 //===== 
130 void PolyDataToImageData::bbUserFinalizeProcessing()
131 {
132
133 //  THE FINALIZATION METHOD BODY :
134 //    Here does nothing 
135 //    but this is where you should desallocate the internal/output pointers 
136 //    if any
137   
138 }
139 }
140 // EO namespace bbcreaVtk
141
142