GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoFilterWatershed.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 "QGoFilterWatershed.h"
35 
36 #include "QGoGUILibConfigure.h"
37 
38 // for apply method
39 #include "vtkImageExport.h"
40 #include "vtkImageData.h"
41 #include "vtkMetaImageWriter.h"
42 // ITK filter
43 #include "itkImageFileWriter.h"
45 #include "itkImage.h"
46 #include "itkVTKImageImport.h"
47 
48 // to cut
49 #include "vtkPlane.h"
50 #include "vtkCutter.h"
51 
52 // to translate
53 #include "vtkTransform.h"
54 #include "vtkTransformPolyDataFilter.h"
55 
56 #include "GoImageProcessor.h"
57 
58 //--------------------------------------------------------------------------
60  QGoFilterSemiAutoBase(iParent)
61 {
62  m_Image3D = itk::Image< int, 3 >::New();
63  m_Image2D = itk::Image< int, 2 >::New();
64 
65  m_Dimension = iDimension;
66  m_TreshMin = 10;
67  m_TreshMax = 30;
68  m_CorrTresh = 0.50;
69  m_Alpha = 1.5;
70  m_Beta = 3.0;
71 }
72 
73 //--------------------------------------------------------------------------
74 
75 //--------------------------------------------------------------------------
78 {
79 }
80 
81 //--------------------------------------------------------------------------
82 
83 //--------------------------------------------------------------------------
84 void
85 QGoFilterWatershed::Filter2D(double *iCenter, const int & iOrientation)
86 {
87  (void)iCenter;
88  (void)iOrientation;
89  /*
90  const int dimension = 2;
91 
92  // useful to translate the polydata afterwards
93  setCenter(iCenter);
94 
95  vtkImageData* slice = vtkImageData::New();
96 
97  // Extract one slice if dimenesion == 2
98  vtkImageData* input = extractOneSlice(getInput(), iCenter, iOrientation);
99  slice->DeepCopy(input);
100  input->Delete();
101 
102  // Recompute new center
103  double* newOrigin = slice->GetOrigin();
104  double center[3];
105 
106  switch (iOrientation)
107  {
108  case 0:
109  {
110  center[0] = iCenter[0] + newOrigin[0];
111  center[1] = iCenter[1] + newOrigin[1];
112  center[2] = 0.;
113  break;
114  }
115  case 1:
116  {
117  center[0] = iCenter[0] + newOrigin[0];
118  center[1] = iCenter[2] + newOrigin[1];
119  center[2] = 0.;
120  break;
121  }
122  case 2:
123  {
124  center[0] = iCenter[1] + newOrigin[0];
125  center[1] = iCenter[2] + newOrigin[1];
126  center[2] = 0.;
127  break;
128  }
129  default:
130  {
131  break;
132  }
133  }
134 
135  // run filter
136  typedef itk::Image<unsigned char, dimension> FeatureImageType;
137  typedef itk::Image<float, dimension> OutputImageType;
138 
139  //VTK to ITK
140  //---------------------------------------------------------
141  FeatureImageType::Pointer
142  itkImage = ConvertVTK2ITK<unsigned char, dimension>( slice );
143 
144  // Extract ROI
145  //---------------------------------------------------------
146  FeatureImageType::Pointer
147  test2 = ExtractROI<unsigned char, dimension>(itkImage, center, getRadius());
148 
149  // Apply filter
150  // Apply LevelSet segmentation filter
151  //---------------------------------------------------------
152  typedef itk::ChanAndVeseSegmentationFilter<FeatureImageType>
153  SegmentationFilterType;
154 
155  FeatureImageType::PointType pt;
156 
157  SegmentationFilterType::Pointer filter = SegmentationFilterType::New();
158 
159  filter->SetFeatureImage(test2);
160  filter->SetPreprocess(1);
161 
162  pt[0] = center[0];
163  pt[1] = center[1];
164  pt[2] = center[2];
165  filter->SetCenter(pt);
166 
167  filter->SetRadius(getRadius());
168  filter->SetNumberOfIterations(m_Iterations);
169  filter->SetCurvatureWeight(m_Curvature);
170  filter->Update();
171 
172  OutputImageType::Pointer test3 = filter->GetOutput();
173 
174  // Convert output
175  //---------------------------------------------------------
176  vtkImageData* itk2vtk = ConvertITK2VTK<float, dimension>(test3);
177  setOutput(itk2vtk);
178  itk2vtk->Delete();
179 
180  vtkPolyData* reconstructed = ReconstructContour( getOutput(), 0. );
181 
182  // Translate to real location (i.e. see_pos[])
183  vtkTransform* t = vtkTransform::New();
184  t->Translate(getCenter()[0],
185  getCenter()[1],
186  getCenter()[2]);
187 
188  vtkTransformPolyDataFilter* tf = vtkTransformPolyDataFilter::New();
189  tf->SetTransform(t);
190  tf->SetInput( reconstructed );
191  tf->Update();
192 
193  vtkPolyData* contour = vtkPolyData::New();
194  contour->DeepCopy( tf->GetOutput() );
195 
196  tf->Delete();
197  t->Delete();
198  reconstructed->Delete();
199 
200  emit ContourCreated( contour );
201  */
202 }
203 //--------------------------------------------------------------------------
204 
205 //--------------------------------------------------------------------------
206 std::vector<std::vector<vtkPolyData*> > QGoFilterWatershed::
207  ApplyFilterSetOf2D(double iRadius,
208  int iThresMin, int iThresMax, double iCorrTresh, double iAlpha,
209  double iBeta, int iSampling,
210  std::vector< vtkPoints* >* iPoints,
211  GoImageProcessor* iImages, int iChannel)
212 {
213  std::vector<std::vector<vtkPolyData*> > oSetOfContours =
214  std::vector<std::vector<vtkPolyData*> >();
215 
216 
217  return oSetOfContours;
218 }
std::vector< std::vector< vtkPolyData * > > ApplyFilterSetOf2D(double iRadius, int iThresMin, int iThresMax, double iCorrTresh, double iAlpha, double iBeta, int iSampling, std::vector< vtkPoints * > *iPoints, GoImageProcessor *iImages, int iChannel)
~QGoFilterWatershed()
Destructor.
QGoFilterWatershed(QObject *iParent=NULL, int iDimension=2)
Constructor.
Output3DType::Pointer m_Image3D
Output2DType::Pointer m_Image2D
void Filter2D(double *iCenter, const int &iOrientation)
Connects the common signals regarding the seeds segmentation Provides methods to convert images from ...
Interface between image reader and vtkImageData.