]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageThresholdConnectivity.cxx
Memory bug
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkImageThresholdConnectivity.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 "bbcreaVtkImageThresholdConnectivity.h"
5 #include "bbcreaVtkPackage.h"
6 #include "vtkImageThresholdConnectivity.h"
7 #include "vtkPoints.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageThresholdConnectivity)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ImageThresholdConnectivity,bbtk::AtomicBlackBox);
14 //===== 
15 // 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)
16 //===== 
17 void ImageThresholdConnectivity::Process()
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     std::vector<int> lstX;
32     std::vector<int> lstY;
33     std::vector<int> lstZ;
34     std::vector<int> point = bbGetInputPoint();
35
36     if (bbGetInputPoint().size()==3)
37     {
38         lstX.push_back( point[0] );
39         lstY.push_back( point[1] );
40         lstZ.push_back( point[2] );
41     } else {
42         lstX = bbGetInputLstX();
43         lstY = bbGetInputLstY();
44         lstZ = bbGetInputLstZ();
45     }
46     
47     if ( (bbGetInputIn()!=NULL) && (lstX.size()>0) && (lstX.size()==lstY.size()) && (lstX.size()==lstZ.size()) )
48     {
49                 if (filter!=NULL) { filter->Delete(); }
50         filter = vtkImageThresholdConnectivity::New();
51         double spc[3];
52         bbGetInputIn()->GetSpacing(spc);
53         int border  = bbGetInputBorder();
54         int minX    = 32000;
55         int minY    = 32000;
56         int minZ    = 32000;
57         int maxX    = -32000;
58         int maxY    = -32000;
59         int maxZ    = -32000;
60         int i,size  = lstX.size();
61         double p[3];
62         vtkPoints *points = vtkPoints::New();
63         for (i=0; i<size; i++)
64         {
65             p[0] = lstX[i]*spc[0];
66             p[1] = lstY[i]*spc[1];
67             p[2] = lstZ[i]*spc[2];
68             points->InsertNextPoint(p);
69             if ( lstX[i] < minX ) { minX = lstX[i]; }
70             if ( lstY[i] < minY ) { minY = lstY[i]; }
71             if ( lstZ[i] < minZ ) { minZ = lstZ[i]; }
72             if ( lstX[i] > maxX ) { maxX = lstX[i]; }
73             if ( lstY[i] > maxY ) { maxY = lstY[i]; }
74             if ( lstZ[i] > maxZ ) { maxZ = lstZ[i]; }
75         } // for i
76         filter->SetSeedPoints( points );
77         filter->SetInputData( bbGetInputIn() );
78         if (bbGetInputThreshold().size()==2)
79         {
80                         if ( bbGetInputThreshold()[0] < bbGetInputThreshold()[1] )            
81                         {
82                                 filter->ThresholdBetween( bbGetInputThreshold()[0] , bbGetInputThreshold()[1] );
83                         } else {
84                                 filter->ThresholdBetween( bbGetInputThreshold()[1] , bbGetInputThreshold()[0] );
85                         }// if Thershold min max
86         } else {
87             filter->ThresholdBetween( 0, 100 );
88         }// if Thershold size
89         
90     //    filter->SetNeighborhoodRadius (4, 4, 4 );
91         filter->SetInValue(255);
92         filter->SetOutValue(0);
93     //    filter->ReplaceInOn();
94     //    filter->ReplaceOutOn();
95         filter->SetSliceRangeX(minX-border,maxX+border);
96         filter->SetSliceRangeY(minY-border,maxY+border);
97         filter->SetSliceRangeZ(minZ-border,maxZ+border);
98         filter->Update();
99         bbSetOutputOut( filter->GetOutput() );
100     } else {
101         bbSetOutputOut( NULL );
102     }// if lst
103 }
104 //===== 
105 // 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)
106 //===== 
107 void ImageThresholdConnectivity::bbUserSetDefaultValues()
108 {
109 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
110 //    Here we initialize the input 'In' to 0
111         filter=NULL;
112     bbSetInputIn(NULL);
113     bbSetInputBorder(10);
114     std::vector<double> maskValue;
115     maskValue.push_back(0);
116     maskValue.push_back(255);
117     bbSetInputMaskValue(maskValue);
118 }
119
120 //===== 
121 // 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)
122 //===== 
123 void ImageThresholdConnectivity::bbUserInitializeProcessing()
124 {
125 //  THE INITIALIZATION METHOD BODY :
126 //    Here does nothing 
127 //    but this is where you should allocate the internal/output pointers 
128 //    if any
129 }
130
131 //===== 
132 // 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)
133 //===== 
134 void ImageThresholdConnectivity::bbUserFinalizeProcessing()
135 {
136 //  THE FINALIZATION METHOD BODY :
137 //    Here does nothing 
138 //    but this is where you should desallocate the internal/output pointers 
139 //    if any
140 }
141
142 }// EO namespace bbcreaVtk
143
144