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