GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Watershed.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #include "Watershed.h"
35 
36 #include "QGoGUILibConfigure.h"
37 
38 // for apply method
39 #include "vtkImageExport.h"
40 #include "vtkImageData.h"
41 
42 //Connection VTK/ITK
43 #include "vtkImageExport.h"
44 #include "itkVTKImageImport.h"
46 #include "vtkitkAdaptor.h"
47 
48 // ITK filter
50 #include "itkImage.h"
51 #include "itkImageFileReader.h"
52 #include "itkImageFileWriter.h"
54 
55 //--------------------------------------------------------------------------
57 {
58  /*m_Radius = 3.0;
59  m_Iterations = 15;
60  m_Curvature = 5;
61  m_Center[0] = 0;
62  m_Center[1] = 0;
63  m_Dimension = 3;*/
64 }
65 
66 //--------------------------------------------------------------------------
67 
68 //--------------------------------------------------------------------------
71 {
72  //m_Input->Delete();
73 }
74 
75 //--------------------------------------------------------------------------
76 /*
77 //--------------------------------------------------------------------------
78 void
79 ChanAndVesLevelSet::
80 setCenter(double* iCenter)
81 {
82  m_Center[0] = iCenter[0];
83  m_Center[1] = iCenter[1];
84  m_Center[2] = iCenter[2];
85 }
86 //--------------------------------------------------------------------------
87 
88 //--------------------------------------------------------------------------
89 void
90 ChanAndVesLevelSet::
91 setRadius(double iRadius)
92 {
93  m_Radius = iRadius;
94 }
95 //--------------------------------------------------------------------------
96 
97 //--------------------------------------------------------------------------
98 void
99 ChanAndVesLevelSet::
100 setIterations(int iIterations)
101 {
102  m_Iterations = iIterations;
103 }
104 //--------------------------------------------------------------------------
105 
106 //--------------------------------------------------------------------------
107 void
108 ChanAndVesLevelSet::
109 setCurvature(int iCurvature)
110 {
111  m_Curvature = iCurvature;
112 }
113 //--------------------------------------------------------------------------
114 */
115 /*
116 //--------------------------------------------------------------------------
117 void
118 ChanAndVesLevelSet::
119 setDimension(int iDimension)
120 {
121  m_Dimension = iDimension;
122 }
123 //--------------------------------------------------------------------------
124 */
125 
126 //--------------------------------------------------------------------------
127 vtkImageData *
129 {
130  //itkWatershedBasedCellSegmentation
131 /*
132  std::cout<<"PARAMETERS:" <<std::endl;
133  std::cout << "Radius: " << m_Radius<<std::endl;
134  std::cout << "Iterations: " << m_Iterations<<std::endl;
135  std::cout << "Curvature: " << m_Curvature<<std::endl;
136  std::cout << "Seed position: " << m_Center[0]
137  << " - " << m_Center[1]
138  << " - " << m_Center[2] << std::endl;
139 */
140 
141  //Export VTK image to ITK
142  vtkImageExport *vtk2itkImage = vtkImageExport::New();
143 
144  vtk2itkImage->SetInput( getInput() );
145  vtk2itkImage->Update();
146 
147  // Define the dimension of the images
148  const unsigned int Dimension = 3;
149  typedef itk::Image< unsigned char, Dimension > FeatureImageType;
150  typedef FeatureImageType::Pointer FeatureImagePointer;
151  typedef itk::Image< double, Dimension > InputImageType;
152  typedef InputImageType::IndexType InputImageIndexType;
153  typedef InputImageType::Pointer InputImagePointer;
154  typedef itk::Image< int, Dimension > SegmentImageType;
155  typedef SegmentImageType::Pointer SegmentImagePointer;
156 
157  typedef itk::ImageFileReader< FeatureImageType > FeatureReaderType;
158  typedef itk::ImageFileWriter< SegmentImageType > SegmentWriterType;
160  SegmentationFilterType;
161 
162  // ImageType
163  typedef itk::Image< unsigned char, Dimension > ImageType;
164  // Import VTK Image to ITK
165  typedef itk::VTKImageImport< ImageType > ImageImportType;
166  typedef ImageImportType::Pointer ImageImportPointer;
167  ImageImportPointer movingImporter = ImageImportType::New();
168 
169  ConnectPipelines< vtkImageExport, ImageImportPointer >(
170  vtk2itkImage,
171  movingImporter);
172 
173  std::cout << "===================IMAGE==========================" << std::endl;
174  std::cout << "==================================================" << std::endl;
175 
176  //movingImporter->Update();
177  movingImporter->GetOutput()->Print(cout);
178 
179  SegmentationFilterType::Pointer filter = SegmentationFilterType::New();
180  filter->SetInput( movingImporter->GetOutput() );
181  //filter->Set
182  filter->Update();
183  // segmentation parameters
184 
185  std::cout << "segmentation finished" << std::endl;
186 
188 
189  ConverterType::Pointer converter = ConverterType::New();
190  converter->SetInput( filter->GetOutput() );
191  converter->Update();
192 
193  std::cout << "conversion finished" << std::endl;
194 
195  vtkImageData *output = vtkImageData::New();
196  output->DeepCopy( converter->GetOutput() );
197 
198  std::cout << "copy finished" << std::endl;
199 
200  return output;
201 }
202 
203 //--------------------------------------------------------------------------
Watershed()
Constructor.
Definition: Watershed.cxx:56
Converts an ITK image into a VTK image and plugs a itk data pipeline to a VTK datapipeline.
~Watershed()
Destructor.
Definition: Watershed.cxx:70
virtual vtkImageData * Apply()
Definition: Watershed.cxx:128