Fraxinus  17.12
An IGT application
cxRouteToTargetFilterService.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 
37 #include "cxAlgorithmHelpers.h"
39 
40 #include "cxUtilHelpers.h"
42 #include "cxStringProperty.h"
43 #include "cxDoubleProperty.h"
44 #include "cxBoolProperty.h"
45 #include "cxTypeConversions.h"
46 
47 #include "cxRouteToTarget.h"
48 #include "cxPatientModelService.h"
49 #include "cxPointMetric.h"
50 #include "cxVisServices.h"
53 #include "cxViewService.h"
54 #include "cxLog.h"
55 
56 #include <vtkPolyData.h>
57 
58 
59 namespace cx
60 {
61 
63  FilterImpl(services)
64  , mTargetName("")
65 {
66 }
67 
69 {
70  return "Route to target";
71 }
72 
74 {
75  return "routetotarget_filter";
76 }
77 
79 {
80  return "<html>"
81  "<h3>Route to target.</h3>"
82  "<p>Calculates the route to a selected target in navigated bronchocopy. "
83  "The route starts at the top of trachea and ends at the most adjacent airway centerline"
84  "from the target.</p>"
85  "</html>";
86 }
87 
89 {
90  return "_rtt_cl";
91 }
92 
94 {
95  return "_ext";
96 }
97 
98 
100 {
101 
102 }
103 
105 {
106  StringPropertySelectMeshPtr centerline;
107  centerline = StringPropertySelectMesh::New(mServices->patient());
108  centerline->setValueName("Airways centerline");
109  centerline->setHelp("Select airways centerline");
110  mInputTypes.push_back(centerline);
111 
113  targetPoint = StringPropertySelectPointMetric::New(mServices->patient());
114  targetPoint->setValueName("Target point");
115  targetPoint->setHelp("Select target point metric");
116  mInputTypes.push_back(targetPoint);
117 
118 }
119 
121 {
122  StringPropertySelectMeshPtr tempRTTMeshStringAdapter;
123  tempRTTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
124  tempRTTMeshStringAdapter->setValueName("Route to target mesh");
125  tempRTTMeshStringAdapter->setHelp("Generated route to target mesh (vtk-format).");
126  mOutputTypes.push_back(tempRTTMeshStringAdapter);
127 
128  StringPropertySelectMeshPtr tempRTTEXTMeshStringAdapter;
129  tempRTTEXTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
130  tempRTTEXTMeshStringAdapter->setValueName("Route to target extended mesh");
131  tempRTTEXTMeshStringAdapter->setHelp("Generated route to target extended mesh (vtk-format).");
132  mOutputTypes.push_back(tempRTTEXTMeshStringAdapter);
133 }
134 
135 
137 {
138  mRouteToTarget.reset(new RouteToTarget());
139 
140  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
141  if (!mesh)
142  return false;
143 
144  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
145 
146  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
147  if (!targetPoint)
148  return false;
149 
150  Vector3D targetCoordinate_r = targetPoint->getCoordinate();
151 
152  mRouteToTarget->processCenterline(centerline_r);
153 
154  //note: mOutput is in reference space
155  mOutput = mRouteToTarget->findRouteToTarget(targetCoordinate_r);
156 
157  if(mOutput->GetNumberOfPoints() < 1)
158  return false;
159 
160  mExtendedRoute = mRouteToTarget->findExtendedRoute(targetCoordinate_r);
161 
162  return true;
163 }
164 
166 {
167 
168  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
169  if (!inputMesh)
170  return false;
171 
172  QString uidCenterline = inputMesh->getUid() + RouteToTargetFilter::getNameSuffix() + "%1";
173  QString nameCenterline = inputMesh->getName()+RouteToTargetFilter::getNameSuffix() + "%1";
174  if (!mTargetName.isEmpty())
175  {
176  uidCenterline.append("_" + mTargetName);
177  nameCenterline.append("_" + mTargetName);
178  }
179 
180  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
181  outputCenterline->setVtkPolyData(mOutput);
182  patientService()->insertData(outputCenterline);
183 
184  QString uidCenterlineExt = outputCenterline->getUid() + RouteToTargetFilter::getNameSuffixExtension();
185  QString nameCenterlineExt = outputCenterline->getName()+RouteToTargetFilter::getNameSuffixExtension();
186  MeshPtr outputCenterlineExt = patientService()->createSpecificData<Mesh>(uidCenterlineExt, nameCenterlineExt);
187  outputCenterlineExt->setVtkPolyData(mExtendedRoute);
188  outputCenterlineExt->setColor(QColor(0, 0, 255, 255));
189  patientService()->insertData(outputCenterlineExt);
190 
191  //note: mOutput and outputCenterline is in reference(r) space
192 
193 
194  //Meshes are expected to be in data(d) space
195  outputCenterline->get_rMd_History()->setParentSpace(inputMesh->getUid());
196  outputCenterlineExt->get_rMd_History()->setParentSpace(inputMesh->getUid());
197 
198  mServices->view()->autoShowData(outputCenterline);
199 
200  if(mOutputTypes.size() > 0)
201  mOutputTypes[0]->setValue(outputCenterline->getUid());
202  if(mOutputTypes.size() > 1)
203  mOutputTypes[1]->setValue(outputCenterlineExt->getUid());
204 
205 
206  return true;
207 }
208 
210 {
211  mTargetName = name;
212 }
213 
214 
215 } // namespace cx
216 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
A mesh data set.
Definition: cxMesh.h:66
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
RouteToTargetFilter(VisServicesPtr services)
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
PatientModelServicePtr patientService()
virtual void setTargetName(QString name)
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:112
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:95
static StringPropertySelectPointMetricPtr New(PatientModelServicePtr patientModelService)
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class StringPropertySelectPointMetric > StringPropertySelectPointMetricPtr
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr