CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
57 namespace cx
58 {
59 
61  FilterImpl(services)
62 {
63 }
64 
66 {
67  return "Route to target";
68 }
69 
71 {
72  return "routetotarget_filter";
73 }
74 
76 {
77  return "<html>"
78  "<h3>Route to target.</h3>"
79  "<p>Calculates the route to a selected target in navigated bronchocopy."
80  "The rout starts at the top of trachea and ends at the most adjacent airway centerline"
81  "from the target.</p>"
82  "</html>";
83 }
84 
85 
87 {
88 
89 }
90 
92 {
93  StringPropertySelectMeshPtr centerline;
94  centerline = StringPropertySelectMesh::New(mServices->patient());
95  centerline->setValueName("Centerline");
96  centerline->setHelp("Select centerline");
97  mInputTypes.push_back(centerline);
98 
100  targetPoint = StringPropertySelectPointMetric::New(mServices->patient());
101  targetPoint->setValueName("Target point");
102  targetPoint->setHelp("Select point metric input");
103  mInputTypes.push_back(targetPoint);
104 
105 }
106 
108 {
109 
110  StringPropertySelectMeshPtr tempMeshStringAdapter;
111 
112  tempMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
113  tempMeshStringAdapter->setValueName("Centerline mesh");
114  tempMeshStringAdapter->setHelp("Generated route to target mesh (vtk-format).");
115  mOutputTypes.push_back(tempMeshStringAdapter);
116 
117 }
118 
119 
121 {
122  mRouteToTarget.reset(new RouteToTarget());
123 
124  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
125  if (!mesh)
126  return false;
127 
128  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyData(mesh->get_rMd());
129 
130  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
131  if (!targetPoint)
132  return false;
133 
134  Vector3D targetCoordinate_r = targetPoint->getCoordinate();
135 
136  mRouteToTarget->processCenterline(centerline_r);
137 
138  //note: mOutput is in reference space
139  mOutput = mRouteToTarget->findRouteToTarget(targetCoordinate_r);
140  mExtendedRoute = mRouteToTarget->findExtendedRoute(targetCoordinate_r);
141 
142  return true;
143 }
144 
146 {
147 
148  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
149  if (!inputMesh)
150  return false;
151 
152  QString uidCenterline = inputMesh->getUid() + "_rtt_cl%1";
153  QString nameCenterline = inputMesh->getName()+"_rtt_cl%1";
154  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
155  outputCenterline->setVtkPolyData(mOutput);
156  patientService()->insertData(outputCenterline);
157 
158  QString uidCenterlineExt = outputCenterline->getUid() + "_ext";
159  QString nameCenterlineExt = outputCenterline->getName()+"_ext";
160  MeshPtr outputCenterlineExt = patientService()->createSpecificData<Mesh>(uidCenterlineExt, nameCenterlineExt);
161  outputCenterlineExt->setVtkPolyData(mExtendedRoute);
162  outputCenterlineExt->setColor(QColor(0, 0, 255, 255));
163  patientService()->insertData(outputCenterlineExt);
164 
165  //note: mOutput and outputCenterline is in reference(r) space
166 
167 
168  //Meshes are expected to be in data(d) space
169  outputCenterline->get_rMd_History()->setParentSpace(inputMesh->getUid());
170  outputCenterlineExt->get_rMd_History()->setParentSpace(inputMesh->getUid());
171 
172  mServices->view()->autoShowData(outputCenterline);
173 
174  mOutputTypes[0]->setValue(outputCenterline->getUid());
175 
176  return true;
177 }
178 
179 
180 } // namespace cx
181 
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:62
RouteToTargetFilter(VisServicesPtr services)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
PatientModelServicePtr patientService()
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:112
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
boost::shared_ptr< class PointMetric > PointMetricPtr