GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoMeshMergeConvexHullAlgo.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 =========================================================================*/
35 
36 #include "GoImageProcessor.h"
37 
38 #include "itkImage.h"
40 
41 QGoMeshMergeConvexHullAlgo::QGoMeshMergeConvexHullAlgo(std::vector< vtkPoints* >* iSeeds, QWidget* iParent)
42  :QGoMergeConvexHullAlgo(iSeeds, iParent)
43 {
44  this->setObjectName("Merge");
45 }
46 //-------------------------------------------------------------------------
47 
48 //-------------------------------------------------------------------------
50 {
51 }
52 //-------------------------------------------------------------------------
53 
54 //-------------------------------------------------------------------------
55 std::vector<vtkPolyData*> QGoMeshMergeConvexHullAlgo::ApplyAlgo(
56  GoImageProcessor* iImages,
57  std::string iChannel,
58  std::vector<vtkPolyData*> iPolyData,
59  bool iIsInvertedOn)
60 {
61  const unsigned int Dimension = 3;
62  typedef unsigned char PixelType;
63 
64  typedef itk::Image< PixelType, Dimension > ImageType;
65 
66  typedef std::list< vtkPolyData* > PolyDataListType;
67  PolyDataListType listOfPolydatas;
68 
69  // init bounding box
70  std::vector< double > bounds(Dimension*2);
71  for(unsigned int i = 0; i<Dimension; ++i)
72  {
73  bounds[i*2] = std::numeric_limits<int>::max();
74  bounds[i*2+1] = std::numeric_limits<int>::min();
75  }
76 
77  // get bounding box over all selected polydatas
78  std::vector<vtkPolyData*>::iterator iterator = iPolyData.begin();
79  while(iterator != iPolyData.end())
80  {
81  double* boundsPointer = (*iterator)->GetBounds();
82  for(unsigned int i = 0; i<Dimension; ++i)
83  {
84  if(boundsPointer[i*2] < bounds[i*2])
85  bounds[i*2] = static_cast<int>(boundsPointer[i*2]);
86  if(boundsPointer[i*2 + 1] > bounds[i*2 +1])
87  bounds[i*2+1] = static_cast<int>(boundsPointer[i*2+1]);
88  }
89  listOfPolydatas.push_back(*iterator);
90  ++iterator;
91  }
92 
93  ImageType::Pointer ITK_Full_Image = iImages->getImageITK<PixelType, Dimension>(
94  iImages->getChannelName(0));
95 
96  itk::Vector<double> spacing = ITK_Full_Image->GetSpacing();
97 
98  // work on smaller region
99  // increase size of bounding box by 20*spacing... bug itk?
100  for(unsigned int i = 0; i<Dimension; ++i)
101  {
102  bounds[i*2] = bounds[i*2] - 10*spacing[i];
103  bounds[i*2+1] = bounds[i*2+1] + 10*spacing[i];
104  }
105 
106  // then let's extract the Region of Interest
107  // on 1 image as for now - channel 0
108  ImageType::Pointer ITK_ROI_Image =
109  this->ITKExtractROI< PixelType, Dimension >( bounds, ITK_Full_Image);
110 
112  MergerType::Pointer filter = MergerType::New();
113  filter->SetInputs( listOfPolydatas );
114  filter->SetNumberOfImages( 1 );
115  filter->SetFeatureImage( 0, ITK_ROI_Image );
116  filter->Update();
117 
118  std::vector<vtkPolyData*> oVector;
119  oVector.push_back(filter->GetOutput());
120  return oVector;
121 }
122 //-------------------------------------------------------------------------
std::vector< vtkPolyData * > ApplyAlgo(GoImageProcessor *iImages, std::string iChannel, std::vector< vtkPolyData * > iPolyData, bool iIsInvertedOn)
return the vtkpolydata created by the algorithm
itk::Image< PixelType, VImageDimension >::Pointer getImageITK(std::string iIndex, bool iIsInverted=false)
get an ITK image (vs vtkImageData) given its index
class to be the interface between the shape algo for meshes, contours and set of contours and GoFigur...
std::string getChannelName(const unsigned int &iIndex)
get name of a channel given its index.
void setObjectName(const QString &name)
QGoMeshMergeConvexHullAlgo(std::vector< vtkPoints * > *iSeeds, QWidget *iParent=0)
Interface between image reader and vtkImageData.