CustusX  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxBinaryThinningImageFilter3DFilter.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. 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 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 
36 
37 #include "cxLogger.h"
39 #include "cxMesh.h"
40 #include "cxImage.h"
41 #include "cxColorProperty.h"
44 #include "cxAlgorithmHelpers.h"
45 #include "cxPatientModelService.h"
46 #include "cxVolumeHelpers.h"
47 #include "cxVisServices.h"
48 
49 namespace cx
50 {
52  FilterImpl(services)
53 {
54 }
55 
57 {
58  return "Centerline";
59 }
60 
62 {
63  return "BinaryThinningImageFilter3DFilter";
64 }
65 
67 {
68  return "<html>"
69  "<h3>itk::BinaryThinningImageFilter3D</h3>"
70  "<p>"
71  "This filter computes one-pixel-wide skeleton of a 3D input image."
72  "</p><p>"
73  "This class is parametrized over the type of the input image "
74  "and the type of the output image."
75  "</p><p>"
76  "The input is assumed to be a binary image. All non-zero valued voxels "
77  "are set to 1 internally to simplify the computation. The filter will "
78  "produce a skeleton of the object. The output background values are 0, "
79  "and the foreground values are 1."
80  "</p><p>"
81  "A 26-neighbourhood configuration is used for the foreground and a "
82  "6-neighbourhood configuration for the background. Thinning is performed "
83  "symmetrically in order to guarantee that the skeleton lies medial within "
84  "the object."
85  "</p><p>"
86  "This filter is a parallel thinning algorithm and is an implementation "
87  "of the algorithm described in:"
88  "</p><p>"
89  "T.C. Lee, R.L. Kashyap, and C.N. Chu.<br>"
90  "Building skeleton models via 3-D medial surface/axis thinning algorithms.<br>"
91  "Computer Vision, Graphics, and Image Processing, 56(6):462--478, 1994."
92  "</p></html>";
93 }
94 
96 {
97  return ColorProperty::initialize("Color", "",
98  "Color of output model.",
99  QColor("green"), root);
100 }
101 
103 {
104  mOptionsAdapters.push_back(this->getColorOption(mOptions));
105 }
106 
108 {
110 
111  temp = StringPropertySelectImage::New(mServices->patient());
112  temp->setValueName("Input");
113  temp->setHelp("Select binary volume input for thinning");
114  // connect(temp.get(), SIGNAL(dataChanged(QString)), this, SLOT(imageChangedSlot(QString)));
115  mInputTypes.push_back(temp);
116 }
117 
119 {
121 
122  temp = StringPropertySelectMesh::New((mServices->patient()));
123  temp->setValueName("Output");
124  temp->setHelp("Output centerline model");
125  mOutputTypes.push_back(temp);
126 }
127 
129 {
130  bool retval = FilterImpl::preProcess();
131  if (!retval)
132  return false;
133 
134  ImagePtr input = this->getCopiedInputImage();
135  if (!input)
136  return false;
137 
138  if (input->getMax() != 1 || input->getMin() != 0)
139  {
140  reportWarning(QString("Centerline: Input image %1 must be binary, aborting.").arg(input->getName()));
141  return false;
142  }
143 
144  return true;
145 }
146 
148 {
149  ImagePtr input = this->getCopiedInputImage();
150  if (!input)
151  return false;
152 
153  if (input->getMax() != 1 || input->getMin() != 0)
154  {
155  return false;
156  }
157 
158  // report(QString("Creating centerline from \"%1\"...").arg(input->getName()));
159 
160  itkImageType::ConstPointer itkImage = AlgorithmHelper::getITKfromSSCImage(input);
161 
162  //Centerline extraction
164  centerlineFilterType::Pointer centerlineFilter = centerlineFilterType::New();
165  centerlineFilter->SetInput(itkImage);
166  centerlineFilter->Update();
167  itkImage = centerlineFilter->GetOutput();
168 
169  //Convert ITK to VTK
170  itkToVtkFilterType::Pointer itkToVtkFilter = itkToVtkFilterType::New();
171  itkToVtkFilter->SetInput(itkImage);
172  itkToVtkFilter->Update();
173 
174  vtkImageDataPtr rawResult = vtkImageDataPtr::New();
175  rawResult->DeepCopy(itkToVtkFilter->GetOutput());
176 
177  mRawResult = rawResult;
178  return true;
179 }
180 
182 {
183  bool success = false;
184  if(!mRawResult)
185  return success;
186 
188 
189  ImagePtr input = this->getCopiedInputImage();
190 
191  ImagePtr outImage = createDerivedImage(mServices->patient(),
192  input->getUid() + "_cl_temp%1", input->getName()+" cl_temp%1",
193  mRawResult, input);
194 
195  mRawResult = NULL;
196  outImage->resetTransferFunctions();
197 
198  //automatically generate a mesh from the centerline
199  vtkPolyDataPtr centerlinePolyData = SeansVesselReg::extractPolyData(outImage, 1, 0);
200 
201  QString uid = input->getUid() + "_cl%1";
202  QString name = input->getName()+" cl%1";
203  MeshPtr mesh = mServices->patient()->createSpecificData<Mesh>(uid, name);
204  mesh->setVtkPolyData(centerlinePolyData);
205  mesh->setColor(outputColor->getValue());
206  mesh->get_rMd_History()->setParentSpace(input->getUid());
207  mServices->patient()->insertData(mesh);
208 
209  // set output
210  mOutputTypes.front()->setValue(mesh->getUid());
211  success = true;
212 
213  return success;
214 }
215 
216 
217 
218 } // namespace cx
219 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
QDomElement mCopiedOptions
Definition: cxFilterImpl.h:101
A mesh data set.
Definition: cxMesh.h:61
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
virtual bool preProcess()
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:96
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:100
ColorPropertyBasePtr getColorOption(QDomElement root)
ImagePtr getCopiedInputImage(int index=0)
QDomElement mOptions
Definition: cxFilterImpl.h:97
static vtkPolyDataPtr extractPolyData(ImagePtr image, int p_neighborhoodFilterThreshold, double p_BoundingBox[6])
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
boost::shared_ptr< class ColorPropertyBase > ColorPropertyBasePtr
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
static itkImageType::ConstPointer getITKfromSSCImage(ImagePtr image)
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
boost::shared_ptr< class Mesh > MeshPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
This filter computes one-pixel-wide skeleton of a 3D input image.