GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoMeshWaterShedAlgo.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 __QGoMeshWaterShedAlgo_h
35 #define __QGoMeshWaterShedAlgo_h
36 
37 #include "QGoWaterShedAlgo.h"
38 #include "QGoFilterWatershed.h"
39 #include "QGoAlgorithmWidget.h"
40 #include "QGoAlgoParameter.h"
41 #include "QGoGUILibConfigure.h"
42 #include "vtkSmartPointer.h"
43 #include "vtkPolyData.h"
44 #include "vtkImageData.h"
45 #include "vtkTransform.h"
46 #include "vtkTransformPolyDataFilter.h"
47 
48 #include "GoImageProcessor.h"
49 
56 {
57 public:
58  QGoMeshWaterShedAlgo(std::vector< vtkPoints* >* iSeeds,
59  int iMaxThreshold,
60  QWidget* iParent = 0);
62 
63  std::vector<vtkPolyData*> ApplyAlgo(
64  GoImageProcessor* iImages,
65  std::string iChannel,
66  bool iIsInvertedOn = false);
67 
68 protected:
69 
70  template < class TPixel >
71  // note this will work only in 3D, so we can remove the template
72  // parameter on the image dimension
73  //unsigned int VImageDimension >
74  vtkPolyData * ApplyWaterShedFilter(
75  const std::vector<double>& iCenter,
76  typename itk::Image< TPixel, 3 >::Pointer iImages)
77  {
78  assert( iCenter.size() == 3);
79 
80  const unsigned int ImageDimension = 3;
81 
82  typedef TPixel PixelType;
83 
84  typedef itk::Image< PixelType, ImageDimension > ImageType;
85  typedef typename ImageType::Pointer ImagePointer;
86 
87  // let's compute the bounds of the region of interest
88  double radius = this->m_Radius->GetValue();
89 
90  std::vector< double > bounds( 2 * ImageDimension, 0. );
91  unsigned int k = 0;
92  for( unsigned int dim = 0; dim < ImageDimension; dim++ )
93  {
94  bounds[k++] = iCenter[dim] - 2. * radius;
95  bounds[k++] = iCenter[dim] + 2. * radius;
96  }
97 
98  // then let's extract the Region of Interest
99  ImagePointer ITK_ROI_Image =
100  this->ITKExtractROI< PixelType, ImageDimension >( bounds, iImages );
101 
102  // Compute the segmentation in 3D
103  QGoFilterWatershed Filter;
104  Filter.Apply3DFilter< PixelType >(
105  ITK_ROI_Image,
106  this->m_ThresMin->GetValue(),
107  this->m_ThresMax->GetValue(),
108  this->m_CorrThres->GetValue(),
109  this->m_Alpha->GetValue(),
110  this->m_Beta->GetValue());
111 
113  ItkOutPut = Filter.GetOutput3D();
114 
115  // Here it would be better if the mesh extraction would be performed directly
116  // in ITK instead.
117  vtkImageData * FilterOutPutToVTK =
118  this->ConvertITK2VTK<
120  ImageDimension>( ItkOutPut );
121 
122  // Nicolas- should be able to tune the parameter -0.5-
123  vtkPolyData* temp_output = this->ExtractPolyData(FilterOutPutToVTK, 0.5);
124  FilterOutPutToVTK->Delete();
125 
126  // MIGHT LEAK! CHECK IT IS DELETED!
127  vtkPolyData* mesh = vtkPolyData::New();
128  mesh->DeepCopy( temp_output );
129 
130  return mesh;
131  }
132 };
133 
134 #endif
QGoAlgoParameter< double > * m_Beta
QGoMeshWaterShedAlgo(std::vector< vtkPoints * > *iSeeds, int iMaxThreshold, QWidget *iParent=0)
QGoAlgoParameter< int > * m_ThresMin
Output3DType::Pointer Output3DPointer
vtkPolyData * ApplyWaterShedFilter(const std::vector< double > &iCenter, typename itk::Image< TPixel, 3 >::Pointer iImages)
class to be the interface between the watershed algo for meshes and GoFigure
QGoAlgoParameter< int > * m_ThresMax
std::vector< vtkPolyData * > ApplyAlgo(GoImageProcessor *iImages, std::string iChannel, bool iIsInvertedOn=false)
return the vtkpolydata created by the algorithm
std::vector< vtkPolyData * > ExtractPolyData(std::vector< vtkImageData * > &iInputImage, const double &iThreshold)
QGoAlgoParameter< double > * m_CorrThres
QGoAlgoParameter< double > * m_Radius
QGoAlgoParameter< double > * m_Alpha
Watershed segmentation algorithm implementation. Can generate contours and meshes. Will generate 2D objects if m_Dimension&lt;2, 3D objects in the other case.
Interface between image reader and vtkImageData.
vtkImageData * ConvertITK2VTK(typename itk::Image< PixelType, VImageDimension >::Pointer iInput)
void Apply3DFilter(typename itk::Image< TPixel, 3 >::Pointer iITKInput, const int &iThresMin, const int &iThresMax, const double &iCorrTresh, const double &iAlpha, const double &iBeta)
class to be the interface between the watershed algo for meshes and GoFigure