CustusX  18.04
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 
14 #include <ctkPluginContext.h>
15 
16 #include "cxAlgorithmHelpers.h"
18 
19 #include "cxUtilHelpers.h"
21 #include "cxStringProperty.h"
22 #include "cxDoubleProperty.h"
23 #include "cxBoolProperty.h"
24 #include "cxTypeConversions.h"
25 
26 #include "cxRouteToTarget.h"
27 #include "cxPatientModelService.h"
28 #include "cxPointMetric.h"
29 #include "cxVisServices.h"
32 #include "cxViewService.h"
33 #include "cxLog.h"
34 
35 #include <vtkPolyData.h>
36 
37 
38 namespace cx
39 {
40 
42  FilterImpl(services)
43  , mTargetName("")
44 {
45 }
46 
48 {
49  return "Route to target";
50 }
51 
53 {
54  return "routetotarget_filter";
55 }
56 
58 {
59  return "<html>"
60  "<h3>Route to target.</h3>"
61  "<p>Calculates the route to a selected target in navigated bronchocopy. "
62  "The route starts at the top of trachea and ends at the most adjacent airway centerline"
63  "from the target.</p>"
64  "</html>";
65 }
66 
68 {
69  return "_rtt_cl";
70 }
71 
73 {
74  return "_ext";
75 }
76 
77 
79 {
80 
81 }
82 
84 {
85  StringPropertySelectMeshPtr centerline;
86  centerline = StringPropertySelectMesh::New(mServices->patient());
87  centerline->setValueName("Airways centerline");
88  centerline->setHelp("Select airways centerline");
89  mInputTypes.push_back(centerline);
90 
92  targetPoint = StringPropertySelectPointMetric::New(mServices->patient());
93  targetPoint->setValueName("Target point");
94  targetPoint->setHelp("Select target point metric");
95  mInputTypes.push_back(targetPoint);
96 
97 }
98 
100 {
101  StringPropertySelectMeshPtr tempRTTMeshStringAdapter;
102  tempRTTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
103  tempRTTMeshStringAdapter->setValueName("Route to target mesh");
104  tempRTTMeshStringAdapter->setHelp("Generated route to target mesh (vtk-format).");
105  mOutputTypes.push_back(tempRTTMeshStringAdapter);
106 
107  StringPropertySelectMeshPtr tempRTTEXTMeshStringAdapter;
108  tempRTTEXTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
109  tempRTTEXTMeshStringAdapter->setValueName("Route to target extended mesh");
110  tempRTTEXTMeshStringAdapter->setHelp("Generated route to target extended mesh (vtk-format).");
111  mOutputTypes.push_back(tempRTTEXTMeshStringAdapter);
112 }
113 
114 
116 {
117  mRouteToTarget.reset(new RouteToTarget());
118 
119  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
120  if (!mesh)
121  return false;
122 
123  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
124 
125  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
126  if (!targetPoint)
127  return false;
128 
129  Vector3D targetCoordinate_r = targetPoint->getCoordinate();
130 
131  mRouteToTarget->processCenterline(centerline_r);
132 
133  //note: mOutput is in reference space
134  mOutput = mRouteToTarget->findRouteToTarget(targetCoordinate_r);
135 
136  if(mOutput->GetNumberOfPoints() < 1)
137  return false;
138 
139  mExtendedRoute = mRouteToTarget->findExtendedRoute(targetCoordinate_r);
140 
141  return true;
142 }
143 
145 {
146 
147  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
148  if (!inputMesh)
149  return false;
150 
151  QString uidCenterline = inputMesh->getUid() + RouteToTargetFilter::getNameSuffix() + "%1";
152  QString nameCenterline = inputMesh->getName()+RouteToTargetFilter::getNameSuffix() + "%1";
153  if (!mTargetName.isEmpty())
154  {
155  uidCenterline.append("_" + mTargetName);
156  nameCenterline.append("_" + mTargetName);
157  }
158 
159  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
160  outputCenterline->setVtkPolyData(mOutput);
161  patientService()->insertData(outputCenterline);
162 
163  QString uidCenterlineExt = outputCenterline->getUid() + RouteToTargetFilter::getNameSuffixExtension();
164  QString nameCenterlineExt = outputCenterline->getName()+RouteToTargetFilter::getNameSuffixExtension();
165  MeshPtr outputCenterlineExt = patientService()->createSpecificData<Mesh>(uidCenterlineExt, nameCenterlineExt);
166  outputCenterlineExt->setVtkPolyData(mExtendedRoute);
167  outputCenterlineExt->setColor(QColor(0, 0, 255, 255));
168  patientService()->insertData(outputCenterlineExt);
169 
170  //note: mOutput and outputCenterline is in reference(r) space
171 
172 
173  //Meshes are expected to be in data(d) space
174  outputCenterline->get_rMd_History()->setParentSpace(inputMesh->getUid());
175  outputCenterlineExt->get_rMd_History()->setParentSpace(inputMesh->getUid());
176 
177  mServices->view()->autoShowData(outputCenterline);
178 
179  if(mOutputTypes.size() > 0)
180  mOutputTypes[0]->setValue(outputCenterline->getUid());
181  if(mOutputTypes.size() > 1)
182  mOutputTypes[1]->setValue(outputCenterlineExt->getUid());
183 
184 
185  return true;
186 }
187 
189 {
190  mTargetName = name;
191 }
192 
193 
194 } // namespace cx
195 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:73
A mesh data set.
Definition: cxMesh.h:45
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
RouteToTargetFilter(VisServicesPtr services)
VisServicesPtr mServices
Definition: cxFilterImpl.h:82
PatientModelServicePtr patientService()
virtual void setTargetName(QString name)
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:91
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
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