Fraxinus  17.12
An IGT application
cxAccusurfFilterService.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 
35 #include <ctkPluginContext.h>
36 #include "cxImage.h"
37 
38 #include "cxAlgorithmHelpers.h"
40 
41 #include "cxUtilHelpers.h"
43 #include "cxStringProperty.h"
44 #include "cxDoubleProperty.h"
45 #include "cxBoolProperty.h"
46 #include "cxTypeConversions.h"
47 #include "cxVolumeHelpers.h"
48 #include "cxAccusurf.h"
49 #include "cxPatientModelService.h"
50 #include "cxPointMetric.h"
51 #include "cxVisServices.h"
54 #include "cxViewService.h"
55 #include "cxLog.h"
56 
57 
58 namespace cx
59 {
60 
62  FilterImpl(services)
63 {
64 }
65 
66 QString AccusurfFilter::getName() const
67 {
68  return "ACCuSurf";
69 }
70 
71 QString AccusurfFilter::getType() const
72 {
73  return "accusurf_filter";
74 }
75 
76 QString AccusurfFilter::getHelp() const
77 {
78  return "<html>"
79  "<h3>Accusurf</h3>"
80  "<p>Filter to generate an ACCuSurf volume to be usen in navigated bronchoscopy."
81  "The ACCuSurf is generated based on a standard thorax CT and a route-to-target centerline."
82  "</p>"
83  "</html>";
84 }
85 
86 
88 {
91 }
92 
94 {
95  StringPropertySelectMeshPtr centerline;
96  centerline = StringPropertySelectMesh::New(mServices->patient());
97  centerline->setValueName("Route-to-Target");
98  centerline->setHelp("Select centerline");
99  mInputTypes.push_back(centerline);
100 
102  image = StringPropertySelectImage::New(mServices->patient());
103  image->setValueName("Input image");
104  image->setHelp("Select image input for ACCuSurf.");
105  //connect(image.get(), SIGNAL(dataChanged(QString)), this, SLOT(imageChangedSlot(QString)));
106  mInputTypes.push_back(image);
107 
108 }
109 
111 {
113 
114  image = StringPropertySelectData::New(mServices->patient());
115  image->setValueName("Output");
116  image->setHelp("Output ACCuSurf");
117  mOutputTypes.push_back(image);
118 }
119 
120 
122 {
123  mAccusurf.reset(new Accusurf());
124 
125  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
126 
127  ImagePtr inputImage = this->getCopiedInputImage(1);
128  if (!inputImage)
129  return false;
130 
131  vtkPolyDataPtr route_d_image = mesh->getTransformedPolyDataCopy((inputImage->get_rMd().inverse())*mesh->get_rMd());
132  mAccusurf->setRoutePositions(route_d_image);
133  mAccusurf->setInputImage(inputImage);
134 
137  mAccusurf->setThickness(thicknessUp->getValue(), thicknessDown->getValue());
138 
139  mAccusurfImage = mAccusurf->createAccusurfImage();
140 
141  return true;
142 }
143 
145 {
146  if (!mAccusurfImage)
147  return false;
148 
149  ImagePtr input = this->getCopiedInputImage(1);
150 
151  if (!input)
152  return false;
153 
154  QString uid = input->getUid() + "_ACCuSurf%1";
155  QString name = input->getName()+" ACCuSurf%1";
156  ImagePtr output = createDerivedImage(mServices->patient(),
157  uid, name,
158  mAccusurfImage, input);
159  output->mergevtkSettingsIntosscTransform();
160 
161  mAccusurfImage = NULL;
162  if (!output)
163  return false;
164 
165  mServices->patient()->insertData(output);
166 
167  // set output
168  mOutputTypes.front()->setValue(output->getUid());
169 
170  return true;
171 }
172 
173 
175 {
176  DoublePropertyPtr retval = DoubleProperty::initialize("ACCuSurf thickness anterior/up (voxels)", "",
177  "Set slice thickness up in voxels", 0, DoubleRange(0, 50, 1), 0,
178  root);
179  retval->setGuiRepresentation(DoublePropertyBase::grSLIDER);
180  return retval;
181 }
182 
184 {
185  DoublePropertyPtr retval = DoubleProperty::initialize("ACCuSurf thickness posterior/down (voxels)", "",
186  "Set slice thickness down in voxels", 15, DoubleRange(0, 50, 1), 0,
187  root);
188  retval->setGuiRepresentation(DoublePropertyBase::grSLIDER);
189  return retval;
190 }
191 
192 
193 } // namespace cx
194 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
virtual QString getName() const
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
AccusurfFilter(VisServicesPtr services)
virtual QString getHelp() const
std::vector< PropertyPtr > mOptionsAdapters
Definition: cxFilterImpl.h:96
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
ImagePtr createDerivedImage(PatientModelServicePtr dataManager, QString uid, QString name, vtkImageDataPtr raw, ImagePtr parent)
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
DoublePropertyPtr getAccusurfThicknessDown(QDomElement root)
DoublePropertyPtr getAccusurfThicknessUp(QDomElement root)
ImagePtr getCopiedInputImage(int index=0)
virtual QString getType() const
QDomElement mOptions
Definition: cxFilterImpl.h:97
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Namespace for all CustusX production code.