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