]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSegmentationConnectivity.cxx
#2981 BBTK Feature New Normal - FormatOutput of filters in string
[bbtk.git] / packages / vtk / src / bbvtkSegmentationConnectivity.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkSegmentationConnectivity.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:58 $
33   Version:   $Revision: 1.8 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41 #ifdef _USE_VTK_
42
43 #include "bbvtkSegmentationConnectivity.h"
44 #include "bbvtkPackage.h"
45
46 #include "bbtkStaticLecture.h"
47
48 namespace bbvtk
49 {
50   BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SegmentationConnectivity);
51   BBTK_BLACK_BOX_IMPLEMENTATION(SegmentationConnectivity,
52                                 bbtk::AtomicBlackBox);
53
54 // --------------------------------------------------------------
55
56   void SegmentationConnectivity::bbUserSetDefaultValues() 
57   { 
58           thresh2       = NULL;
59 //        cast2         = NULL;
60           connect2      = NULL;
61           cast4         = NULL;
62                 
63           bbSetInputIn(NULL);
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);
73           bbSetOutputOut(NULL);
74
75           bbSetInputOutputFormat("SAME");
76           bbSetInputValue(255);
77
78
79   }
80
81 // --------------------------------------------------------------
82                 
83         void SegmentationConnectivity::bbUserInitializeProcessing()
84         {
85
86                 thresh2 = vtkImageThreshold::New();
87                         thresh2->SetInValue(255);
88                         thresh2->SetOutputScalarTypeToUnsignedChar();
89                 connect2 = vtkImageSeedConnectivity::New();
90                         connect2->SetInput(thresh2->GetOutput());
91                         connect2->SetInputConnectValue(255);
92                         connect2->SetOutputConnectedValue( 255 );
93                         connect2->SetOutputUnconnectedValue(0);
94                 cast4 = vtkImageCast::New();
95                         cast4->SetInput(connect2->GetOutput());
96
97 // EED 2016 06 15
98
99 /*
100                 thresh2 = vtkImageThreshold::New();
101                         thresh2->SetInValue(255);
102                         thresh2->SetOutputScalarTypeToUnsignedShort();
103                         thresh2->SetOutValue(0);
104                 cast2 = vtkImageCast::New();
105                         cast2->SetInput(thresh2->GetOutput());
106                         cast2->SetOutputScalarTypeToUnsignedChar();
107                 connect2 = vtkImageSeedConnectivity::New();
108                         connect2->SetInput(cast2->GetOutput());
109                         connect2->SetInputConnectValue(255);
110                         connect2->SetOutputConnectedValue(255);
111                         connect2->SetOutputUnconnectedValue(0);
112                 cast4 = vtkImageCast::New();
113                         cast4->SetInput(connect2->GetOutput());
114                         cast4->SetOutputScalarTypeToUnsignedShort();
115 */
116
117         }
118
119 // --------------------------------------------------------------
120                 
121   void SegmentationConnectivity::bbUserFinalizeProcessing() 
122   { 
123           if (thresh2!=NULL)
124           {
125                   thresh2->Delete();
126                   thresh2=NULL;
127           }
128 //        if (cast2!=NULL)
129 //        {
130 //                cast2->Delete();
131 //                cast2=NULL;
132 //        }
133           if (connect2!=NULL)
134           {
135                   connect2->Delete();
136                   connect2=NULL;
137           }
138           if (cast4!=NULL)
139           {
140                   cast4->Delete();
141                   cast4=NULL;
142           }  
143   }
144
145
146
147
148 // --------------------------------------------------------------
149                 
150   void SegmentationConnectivity::DoProcess()
151   {
152         int outputformat = bbtkStaticLecture::GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
153
154
155
156     vtkImageData *imagedata = bbGetInputIn();
157     imagedata->UpdateInformation();
158     imagedata->SetUpdateExtent(imagedata->GetWholeExtent());
159     imagedata->Update();
160     thresh2->ThresholdBetween(3000, 3001);
161     thresh2->SetInput(imagedata);
162     thresh2->ThresholdBetween(bbGetInputThresholdMinMax()[0], bbGetInputThresholdMinMax()[1]);
163     thresh2->Modified();
164     thresh2->Update();
165 // EED 2016 06 15
166 //    cast2->Modified();
167 //    cast2->Update();
168     connect2->RemoveAllSeeds ();
169           
170         int x = bbGetInputPositionXYZ()[0];
171         int y = bbGetInputPositionXYZ()[1];
172         int z = bbGetInputPositionXYZ()[2];
173
174           int ext[6];
175           imagedata->GetWholeExtent(ext);
176           int maxx = ext[1]-ext[0]+1;
177           int maxy = ext[3]-ext[2]+1;
178           int maxz = ext[5]-ext[4]+1;
179           if ( x<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range x: %d -> 0 \n",x ); x=0; }
180           if ( y<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range y: %d -> 0 \n",y ); y=0;}
181           if ( z<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range z: %d -> 0 \n",z ); z=0;}
182
183           if ( x>=maxx ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range x: %d -> %d \n",x, maxx-1 ); x=maxx-1; }
184           if ( y>=maxy ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range y: %d -> %d \n",y, maxy-1 ); y=maxy-1; }
185           if ( z>=maxz ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range z: %d -> %d \n",y, maxz-1 ); z=maxz-1; }
186           
187           connect2->AddSeed( x,y,z );
188           connect2->SetOutputConnectedValue( bbGetInputValue() );
189           cast4->SetOutputScalarType( outputformat );
190
191           connect2->Modified();
192           connect2->Update();
193           cast4->Update();                      
194           bbSetOutputOut(cast4->GetOutput() );
195   }
196   
197 }// EO namespace bbvtk
198
199 #endif //_USE_VTK_
200
201
202
203
204