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