2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbvtkSegmentationConnectivity.cxx,v $
32 Date: $Date: 2012/11/16 08:51:58 $
33 Version: $Revision: 1.8 $
34 =========================================================================*/
43 #include "bbvtkSegmentationConnectivity.h"
44 #include "bbvtkPackage.h"
46 #include "bbtkStaticLecture.h"
50 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SegmentationConnectivity);
51 BBTK_BLACK_BOX_IMPLEMENTATION(SegmentationConnectivity,
52 bbtk::AtomicBlackBox);
54 // --------------------------------------------------------------
56 void SegmentationConnectivity::bbUserSetDefaultValues()
64 std::vector<int> position;
65 position.push_back(0);
66 position.push_back(0);
67 position.push_back(0);
68 bbSetInputPositionXYZ(position);
69 std::vector<int> threshold;
70 threshold.push_back(0);
71 threshold.push_back(0);
72 bbSetInputThresholdMinMax(threshold);
75 bbSetInputOutputFormat("SAME");
81 // --------------------------------------------------------------
83 void SegmentationConnectivity::bbUserInitializeProcessing()
86 thresh2 = vtkImageThreshold::New();
87 thresh2->SetInValue(255);
88 thresh2->SetOutputScalarTypeToUnsignedChar();
89 connect2 = vtkImageSeedConnectivity::New();
91 //EED 2017-01-01 Migration VTK7
92 #if VTK_MAJOR_VERSION <= 5
93 connect2->SetInput(thresh2->GetOutput());
95 connect2->SetInputData(thresh2->GetOutput());
98 connect2->SetInputConnectValue(255);
99 connect2->SetOutputConnectedValue( 255 );
100 connect2->SetOutputUnconnectedValue(0);
101 cast4 = vtkImageCast::New();
102 //EED 2017-01-01 Migration VTK7
103 #if VTK_MAJOR_VERSION <= 5
104 cast4->SetInput(connect2->GetOutput());
106 cast4->SetInputData(connect2->GetOutput());
112 thresh2 = vtkImageThreshold::New();
113 thresh2->SetInValue(255);
114 thresh2->SetOutputScalarTypeToUnsignedShort();
115 thresh2->SetOutValue(0);
116 cast2 = vtkImageCast::New();
117 cast2->SetInput(thresh2->GetOutput());
118 cast2->SetOutputScalarTypeToUnsignedChar();
119 connect2 = vtkImageSeedConnectivity::New();
120 connect2->SetInput(cast2->GetOutput());
121 connect2->SetInputConnectValue(255);
122 connect2->SetOutputConnectedValue(255);
123 connect2->SetOutputUnconnectedValue(0);
124 cast4 = vtkImageCast::New();
125 cast4->SetInput(connect2->GetOutput());
126 cast4->SetOutputScalarTypeToUnsignedShort();
131 // --------------------------------------------------------------
133 void SegmentationConnectivity::bbUserFinalizeProcessing()
160 // --------------------------------------------------------------
162 void SegmentationConnectivity::DoProcess()
166 int i,numPoints = bbGetInputPositionXYZ().size()/3;
167 int verif = (bbGetInputPositionXYZ().size()-1) % 3;
168 if (( numPoints>=1) && (verif==2) && (bbGetInputIn()!=NULL))
170 int outputformat = bbtkStaticLecture::GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
171 vtkImageData *imagedata = bbGetInputIn();
172 //EED 2017-01-01 Migration VTK7
173 #if VTK_MAJOR_VERSION <= 5
174 imagedata->UpdateInformation();
175 imagedata->SetUpdateExtent(imagedata->GetWholeExtent());
177 thresh2->SetInput(imagedata);
179 imagedata->SetExtent(imagedata->GetExtent());
180 thresh2->SetInputData(imagedata);
183 thresh2->ThresholdBetween(3000, 3001);
184 thresh2->ThresholdBetween(bbGetInputThresholdMinMax()[0], bbGetInputThresholdMinMax()[1]);
187 connect2->RemoveAllSeeds ();
191 //EED 2017-01-01 Migration VTK7
192 #if VTK_MAJOR_VERSION <= 5
193 imagedata->GetWholeExtent(ext);
195 imagedata->GetExtent(ext);
198 int maxX = ext[1]-ext[0]+1;
199 int maxY = ext[3]-ext[2]+1;
200 int maxZ = ext[5]-ext[4]+1;
202 for (i=0;i<numPoints;i++)
204 x=bbGetInputPositionXYZ()[i*3+0];
205 y=bbGetInputPositionXYZ()[i*3+1];
206 z=bbGetInputPositionXYZ()[i*3+2];
207 if ( (x>=0) || (x<maxX) || (y>=0) || (y<maxY) || (z>=0) || (z<maxZ) )
209 connect2->AddSeed( x,y,z );
211 printf("EED WARNNIG! In box: SegmentationConnectivity point out of range \n");
212 } // if point inside image
215 connect2->SetOutputConnectedValue( bbGetInputValue() );
216 cast4->SetOutputScalarType( outputformat );
217 connect2->Modified();
220 bbSetOutputOut(cast4->GetOutput() );
222 printf("EED WARNNIG! In box: SegmentationConnectivity List of points are not coherent. \n");
223 bbSetOutputOut( NULL );
224 }// if numPoints verif
229 }// EO namespace bbvtk