]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSegmentationConnectivity.cxx
2deda14b1e2856a14a06bb4298fcd581e09d02b5
[bbtk.git] / packages / vtk / src / bbvtkSegmentationConnectivity.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkSegmentationConnectivity.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/06/16 12:28:43 $
6   Version:   $Revision: 1.7 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36 #ifdef _USE_VTK_
37
38 #include "bbvtkSegmentationConnectivity.h"
39 #include "bbvtkPackage.h"
40
41 namespace bbvtk
42 {
43   BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SegmentationConnectivity);
44   BBTK_BLACK_BOX_IMPLEMENTATION(SegmentationConnectivity,
45                                 bbtk::AtomicBlackBox);
46
47 // --------------------------------------------------------------
48
49   void SegmentationConnectivity::bbUserSetDefaultValues() 
50   { 
51           thresh2       = NULL;
52           cast2         = NULL;
53           connect2      = NULL;
54           cast4         = NULL;
55                 
56           bbSetInputIn(NULL);
57           std::vector<int> position;
58           position.push_back(0);
59           position.push_back(0);
60           position.push_back(0);
61           bbSetInputPositionXYZ(position);
62           std::vector<int> threshold;
63           threshold.push_back(0);
64           threshold.push_back(0);
65           bbSetInputThresholdMinMax(threshold);
66           bbSetOutputOut(NULL);
67   }
68
69 // --------------------------------------------------------------
70                 
71         void SegmentationConnectivity::bbUserInitializeProcessing()
72         {
73                 thresh2 = vtkImageThreshold::New();
74                         thresh2->SetInValue(255);
75                         thresh2->SetOutputScalarTypeToUnsignedShort();
76                         thresh2->SetOutValue(0);
77                 cast2 = vtkImageCast::New();
78                         cast2->SetInput(thresh2->GetOutput());
79                         cast2->SetOutputScalarTypeToUnsignedChar();
80                 connect2 = vtkImageSeedConnectivity::New();
81                         connect2->SetInput(cast2->GetOutput());
82                         connect2->SetInputConnectValue(255);
83                         connect2->SetOutputConnectedValue(255);
84                         connect2->SetOutputUnconnectedValue(0);
85                 cast4 = vtkImageCast::New();
86                         cast4->SetInput(connect2->GetOutput());
87                         cast4->SetOutputScalarTypeToUnsignedShort();
88         }
89
90 // --------------------------------------------------------------
91                 
92   void SegmentationConnectivity::bbUserFinalizeProcessing() 
93   { 
94           if (thresh2!=NULL)
95           {
96                   thresh2->Delete();
97                   thresh2=NULL;
98           }
99           if (cast2!=NULL)
100           {
101                   cast2->Delete();
102                   cast2=NULL;
103           }
104           if (connect2!=NULL)
105           {
106                   connect2->Delete();
107                   connect2=NULL;
108           }
109           if (cast4!=NULL)
110           {
111                   cast4->Delete();
112                   cast4=NULL;
113           }  
114   }
115
116 // --------------------------------------------------------------
117                 
118   void SegmentationConnectivity::DoProcess()
119   {
120     vtkImageData *imagedata = bbGetInputIn();
121     imagedata->UpdateInformation();
122     imagedata->SetUpdateExtent(imagedata->GetWholeExtent());
123     imagedata->Update();
124     thresh2->ThresholdBetween(3000, 3001);
125     thresh2->SetInput(imagedata);
126     thresh2->ThresholdBetween(bbGetInputThresholdMinMax()[0], bbGetInputThresholdMinMax()[1]);
127     thresh2->Update();
128     cast2->Update();
129     connect2->RemoveAllSeeds ();
130           
131         int x = bbGetInputPositionXYZ()[0];
132         int y = bbGetInputPositionXYZ()[1];
133         int z = bbGetInputPositionXYZ()[2];
134
135           int ext[6];
136           imagedata->GetWholeExtent(ext);
137           int maxx = ext[1]-ext[0]+1;
138           int maxy = ext[3]-ext[2]+1;
139           int maxz = ext[5]-ext[4]+1;
140           if ( x<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range x: %d -> 0 \n",x ); x=0; }
141           if ( y<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range y: %d -> 0 \n",y ); y=0;}
142           if ( z<0 ) {  printf("Warnnig bbtk::vtk::SegmentationConnectivity::DoProcess limites of the image out of range z: %d -> 0 \n",z ); z=0;}
143
144           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; }
145           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; }
146           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; }
147           
148           connect2->AddSeed( x,y,z );
149           connect2->Update();
150           cast4->Update();                      
151           bbSetOutputOut(cast4->GetOutput() );
152   }
153   
154 }// EO namespace bbvtk
155
156 #endif //_USE_VTK_
157
158
159
160
161