GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoFilterChanAndVese.h
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 #ifndef __QGoFilterChanAndVese_h
35 #define __QGoFilterChanAndVese_h
36 
37 #include "QGoFilterSemiAutoBase.h"
38 #include <QObject>
39 #include "QGoGUILibConfigure.h"
40 #include "itkImage.h"
42 #include "itkVTKImageImport.h"
43 #include "vtkSmartPointer.h"
44 #include "vtkPolyData.h"
45 
46 class GoImageProcessor;
47 
54 class QGOGUILIB_EXPORT QGoFilterChanAndVese : public QGoFilterSemiAutoBase
55 {
56  Q_OBJECT
57 public:
58  typedef float OutputPixelType;
59 
60  typedef itk::Image< float, 3 > Output3DType;
61  typedef Output3DType::Pointer Output3DPointer;
62 
63  typedef itk::Image< float, 2 > Output2DType;
64  typedef Output2DType::Pointer Output2DPointer;
65 
67  explicit QGoFilterChanAndVese(QObject *iParent = NULL, int iDimension = 2);
68 
71 
72  std::vector<vtkPolyData*> ApplyFilterLevelSet3D(double iRadius, vtkPoints* iPoints,
73  int iIterations, int iCurvature,
74  GoImageProcessor* iImages,
75  int iChannel);
76 
77  template< typename TPixel >
79  typename itk::Image< TPixel, 3 >::Pointer iITKInput,
80  const std::vector< double >& iCenter,
81  const double& iRadius,
82  const int& iIterations,
83  const int& iCurvature)
84  {
85  typedef itk::Image< TPixel, 3 > FeatureImageType;
87  SegmentationFilterType;
88  typedef typename SegmentationFilterType::Pointer SegmentationFilterPointer;
89 
90  typedef typename SegmentationFilterType::InternalPointType ITKPointType;
91  typedef typename SegmentationFilterType::InternalCoordRepType ITKCoordType;
92 
93  // convert center into ITKPointType
94  ITKPointType itk_center;
95 
96  for( unsigned int dim = 0; dim < 3; dim++ )
97  {
98  itk_center[dim] = static_cast< ITKCoordType >( iCenter[dim] );
99  }
100 
101  // convert radius into ITKCoordType
102  ITKCoordType itk_radius = static_cast< ITKCoordType >( iRadius );
103 
104  // ITK filter
105  SegmentationFilterPointer filter = SegmentationFilterType::New();
106  filter->SetCenter( itk_center );
107  filter->SetRadius( itk_radius );
108  filter->SetFeatureImage(iITKInput);
109  filter->SetPreprocess(0);//1);
110  filter->SetNumberOfIterations(iIterations);
111  filter->SetCurvatureWeight(iCurvature);
112  filter->Update();
113 
114  typename Output3DType::Pointer resulting_image = filter->GetOutput();
115 
116  if( resulting_image.IsNotNull() )
117  {
118  m_Image3D->Graft( resulting_image );
119  }
120  else
121  {
122  itkGenericExceptionMacro(
123  <<"ChanAndVeseSegmentationFilter's output is NULL" );
124  }
125  }
126 
127 
128  template< typename TPixel >
130  typename itk::Image< TPixel, 2 >::Pointer iITKInput,
131  const std::vector< double >& iCenter,
132  const double& iRadius,
133  const int& iIterations,
134  const int& iCurvature)
135  {
136  typedef itk::Image< TPixel, 2 > FeatureImageType;
138  SegmentationFilterType;
139  typedef typename SegmentationFilterType::Pointer SegmentationFilterPointer;
140 
141  typedef typename SegmentationFilterType::InternalPointType ITKPointType;
142  typedef typename SegmentationFilterType::InternalCoordRepType ITKCoordType;
143 
144  // convert center into ITKPointType
145  ITKPointType itk_center;
146 
147  for( unsigned int dim = 0; dim < 2; dim++ )
148  {
149  itk_center[dim] = static_cast< ITKCoordType >( iCenter[dim] );
150  }
151 
152  // convert radius into ITKCoordType
153  ITKCoordType itk_radius = static_cast< ITKCoordType >( iRadius );
154 
155  // ITK filter
156  SegmentationFilterPointer filter = SegmentationFilterType::New();
157  filter->SetCenter( itk_center );
158  filter->SetRadius( itk_radius );
159  filter->SetFeatureImage(iITKInput);
160  filter->SetPreprocess(0);//1);
161  filter->SetNumberOfIterations(iIterations);
162  filter->SetCurvatureWeight(iCurvature);
163  filter->Update();
164 
165  typename Output2DType::Pointer resulting_image = filter->GetOutput();
166 
167  if( resulting_image.IsNotNull() )
168  {
169  m_Image2D->Graft( resulting_image );
170  }
171  else
172  {
173  itkGenericExceptionMacro(
174  <<"ChanAndVeseSegmentationFilter's output is NULL" );
175  }
176  }
177 
178  std::vector<std::vector<vtkPolyData*> > ApplyFilterSetOf2D(
179  double iRadius, std::vector< vtkPoints* >* iPoints,
180  int iIterations, int iCurvature, int iSampling,
181  GoImageProcessor* iImages, int iChannel);
182 
183  Output3DType::Pointer GetOutput3D()
184  {
185  return m_Image3D;
186  }
187 
188  Output2DType::Pointer GetOutput2D()
189  {
190  return m_Image2D;
191  }
192 
193 private:
194  //void Filter2D(double *iCenter, const int & iOrientation);
195  Output3DType::Pointer m_Image3D;
196  Output2DType::Pointer m_Image2D;
197 
201 };
202 #endif
Levelset segmentation algorithm implementation. Can generate contours and meshes. Will generate 2D ob...
Output2DType::Pointer Output2DPointer
void Apply3DFilter(typename itk::Image< TPixel, 3 >::Pointer iITKInput, const std::vector< double > &iCenter, const double &iRadius, const int &iIterations, const int &iCurvature)
Output3DType::Pointer m_Image3D
Output3DType::Pointer Output3DPointer
void Apply2DFilter(typename itk::Image< TPixel, 2 >::Pointer iITKInput, const std::vector< double > &iCenter, const double &iRadius, const int &iIterations, const int &iCurvature)
Output2DType::Pointer GetOutput2D()
Output2DType::Pointer m_Image2D
Output3DType::Pointer GetOutput3D()
itk::Image< float, 3 > Output3DType
Connects the common signals regarding the seeds segmentation Provides methods to convert images from ...
Interface between image reader and vtkImageData.
itk::Image< float, 2 > Output2DType