]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx
66543b2179dfddb744d9cf802ddca067da97b7cc
[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 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
37                 int ext[6];
38                 bbGetInputInImage()->GetExtent( ext );
39         double spc[3];
40         bbGetInputInImage()->GetSpacing( spc );
41         double org[3];
42         bbGetInputInImage()->GetOrigin( org );
43
44 //              vtkCleanPolyData *clean1 = vtkCleanPolyData::New();             
45                 if (clean1!=NULL) clean1->Delete();
46                 clean1 = vtkCleanPolyData::New();
47                 clean1->SetInputData( bbGetInputInPolyData() );
48                 clean1->Update();
49                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
50                 triangle1->SetInputData( clean1->GetOutput() );
51                 triangle1->Update();
52 //              vtkPolyDataToImageStencil *dataToStencil = vtkPolyDataToImageStencil::New();
53                 if (dataToStencil!=NULL) dataToStencil->Delete();
54                 dataToStencil = vtkPolyDataToImageStencil::New();
55                 dataToStencil->SetInputData( triangle1->GetOutput() );
56         dataToStencil->SetOutputOrigin( org );
57         dataToStencil->SetOutputSpacing( spc );
58                 dataToStencil->SetOutputWholeExtent( ext );
59                 dataToStencil->Update();
60 //              vtkExtractVOI *extract = vtkExtractVOI::New();
61                 if (extract!=NULL) extract->Delete();
62                 extract = vtkExtractVOI::New();
63                 extract->SetVOI( ext );
64                 extract->SetSampleRate(1, 1, 1);
65                 extract->SetInputData( bbGetInputInImage() );
66                 extract->ReleaseDataFlagOff();
67                 extract->Update();      
68 //              vtkImageStencil *stencil = vtkImageStencil::New();
69                 if (stencil!=NULL) stencil->Delete();
70                 stencil = vtkImageStencil::New();
71                 stencil->SetInputData( extract->GetOutput() );
72                 stencil->Update();
73                 stencil->SetStencilData(  dataToStencil->GetOutput() );
74                 stencil->ReverseStencilOn();
75                 stencil->SetBackgroundValue( bbGetInputBackgroundValue() );
76                 stencil->Update();
77                 bbSetOutputOut( stencil->GetOutput() );
78         } else {
79                 printf("EED Warnning!  PolyDataToImageData::Process  > Missing Image or PolyData inputs\n");
80                 bbSetOutputOut( NULL);
81         }// if In NULL
82 }
83 //===== 
84 // 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)
85 //===== 
86 void PolyDataToImageData::bbUserSetDefaultValues()
87 {
88 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
89 //    Here we initialize the input 'In' to 0
90         bbSetInputInPolyData(NULL);
91         bbSetInputInImage(NULL);
92         bbSetInputBackgroundValue(255);
93 }
94 //===== 
95 // 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)
96 //===== 
97 void PolyDataToImageData::bbUserInitializeProcessing()
98 {
99 //  THE INITIALIZATION METHOD BODY :
100 //    Here does nothing 
101 //    but this is where you should allocate the internal/output pointers 
102 //    if any 
103         clean1                  = NULL;
104         dataToStencil   = NULL;
105         extract                 = NULL;
106         stencil                 = NULL;
107 }
108 //===== 
109 // 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)
110 //===== 
111 void PolyDataToImageData::bbUserFinalizeProcessing()
112 {
113
114 //  THE FINALIZATION METHOD BODY :
115 //    Here does nothing 
116 //    but this is where you should desallocate the internal/output pointers 
117 //    if any
118   
119 }
120 }
121 // EO namespace bbcreaVtk
122
123