]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx
#3498 Connectivity Filter Threshold
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkImageConnectivityFilter.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 "bbcreaVtkImageConnectivityFilter.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include <vtkPolyData.h>
8 #include <vtkPoints.h>
9 #include <vtkPointData.h>
10
11 namespace bbcreaVtk
12 {
13
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ImageConnectivityFilter)
15 BBTK_BLACK_BOX_IMPLEMENTATION(ImageConnectivityFilter,bbtk::AtomicBlackBox);
16 //===== 
17 // 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)
18 //===== 
19 void ImageConnectivityFilter::Process()
20 {
21
22 // THE MAIN PROCESSING METHOD BODY
23 //   Here we simply set the input 'In' value to the output 'Out'
24 //   And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 //    void bbSet{Input|Output}NAME(const TYPE&)
27 //    const TYPE& bbGet{Input|Output}NAME() const 
28 //    Where :
29 //    * NAME is the name of the input/output
30 //      (the one provided in the attribute 'name' of the tag 'input')
31 //    * TYPE is the C++ type of the input/output
32 //      (the one provided in the attribute 'type' of the tag 'input')
33     
34         if (bbGetInputIn()!=NULL)
35     {
36                 if (imgConnfilter) {imgConnfilter->Delete();}
37                 imgConnfilter=vtkImageConnectivityFilter::New();
38         imgConnfilter->SetInputData( bbGetInputIn() );
39                 if (bbGetInputExtractionMode()==0)  // LargestRegion
40                 {
41                         imgConnfilter->SetExtractionModeToLargestRegion();
42                 } // ExtractionMode
43
44                 if (bbGetInputExtractionMode()==1) // AllRegions   
45                 {
46                         printf("EED Warning!!!! ImageConnectivityFilter - AllRegions Not Implemented\n ");
47                 } // ExtractionMode
48                 if (bbGetInputExtractionMode()==2)  // SeedRegions
49                 {
50             std::vector<double> lstX = bbGetInputLstX();
51             std::vector<double> lstY = bbGetInputLstY();
52             std::vector<double> lstZ = bbGetInputLstZ();
53             int size = lstX.size();
54             if ( (lstX.size()>0) && (lstX.size()==lstY.size()) && (lstX.size()==lstZ.size()) )
55             {
56                 int i;
57                 double p[3];
58                 vtkPoints *points = vtkPoints::New();
59                 for (i=0; i<size; i++)
60                 {
61                     p[0] = lstX[i];
62                     p[1] = lstY[i];
63                     p[2] = lstZ[i];
64                     points->InsertNextPoint(p);
65                 } // for i
66                 vtkPolyData *seedData =  vtkPolyData::New();
67                 seedData->SetPoints( points );
68 //              vtkUnsignedCharArray  *seedScalars = vtkUnsignedCharArray::New();
69 //              seedScalars->InsertNextValue(100);
70 //              seedData->GetPointData()->SetScalars(seedScalars);
71                 seedData->GetPointData()->SetScalars(nullptr);
72                 
73                 imgConnfilter->SetExtractionModeToSeededRegions();
74                 imgConnfilter->SetSeedData( seedData );
75 //              imgConnfilter->SetSizeRange(0, 99);
76             } // if lst
77
78                 } // ExtractionMode
79
80                 if (bbGetInputScalarRange().size()==2)  
81                 {
82                         imgConnfilter->SetScalarRange( bbGetInputScalarRange()[0], bbGetInputScalarRange()[1] );
83                 } // Range
84                 imgConnfilter->Update( );
85                 bbSetOutputOut( imgConnfilter->GetOutput() );
86         } else {
87                         printf("EED Warning!!!! ImageConnectivityFilter  - Input image not defined.\n ");
88         }// In
89 }
90 //===== 
91 // 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)
92 //===== 
93 void ImageConnectivityFilter::bbUserSetDefaultValues()
94 {
95
96 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
97 //    Here we initialize the input 'In' to 0
98         bbSetInputIn(NULL);
99 //      bbSetInputScalarRange();
100         imgConnfilter=NULL;
101         bbSetInputExtractionMode(0);
102
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 ImageConnectivityFilter::bbUserInitializeProcessing()
108 {
109
110 //  THE INITIALIZATION METHOD BODY :
111 //    Here does nothing 
112 //    but this is where you should allocate the internal/output pointers 
113 //    if any 
114
115   
116 }
117 //===== 
118 // 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)
119 //===== 
120 void ImageConnectivityFilter::bbUserFinalizeProcessing()
121 {
122
123 //  THE FINALIZATION METHOD BODY :
124 //    Here does nothing 
125 //    but this is where you should desallocate the internal/output pointers 
126 //    if any
127   
128 }
129 }
130 // EO namespace bbcreaVtk
131
132