Fraxinus  18.10
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 
41 RouteToTargetFilter::RouteToTargetFilter(VisServicesPtr services, bool createRouteInformationFile) :
42  FilterImpl(services),
43  mTargetName(""),
44  mGenerateFileWithRouteInformation(createRouteInformationFile)
45 {
46 }
47 
49 {
50  return "Route to target";
51 }
52 
54 {
55  return "routetotarget_filter";
56 }
57 
59 {
60  return "<html>"
61  "<h3>Route to target.</h3>"
62  "<p>Calculates the route to a selected target in navigated bronchocopy. "
63  "The route starts at the top of trachea and ends at the most adjacent airway centerline"
64  "from the target.</p>"
65  "</html>";
66 }
67 
69 {
70  return "_rtt_cl";
71 }
72 
74 {
75  return "_ext";
76 }
77 
78 
80 {
81 
82 }
83 
85 {
86  StringPropertySelectMeshPtr centerline;
87  centerline = StringPropertySelectMesh::New(mServices->patient());
88  centerline->setValueName("Airways centerline");
89  centerline->setHelp("Select airways centerline");
90  mInputTypes.push_back(centerline);
91 
93  targetPoint = StringPropertySelectPointMetric::New(mServices->patient());
94  targetPoint->setValueName("Target point");
95  targetPoint->setHelp("Select target point metric");
96  mInputTypes.push_back(targetPoint);
97 
98 }
99 
101 {
102  StringPropertySelectMeshPtr tempRTTMeshStringAdapter;
103  tempRTTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
104  tempRTTMeshStringAdapter->setValueName("Route to target mesh");
105  tempRTTMeshStringAdapter->setHelp("Generated route to target mesh (vtk-format).");
106  mOutputTypes.push_back(tempRTTMeshStringAdapter);
107 
108  StringPropertySelectMeshPtr tempRTTEXTMeshStringAdapter;
109  tempRTTEXTMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
110  tempRTTEXTMeshStringAdapter->setValueName("Route to target extended mesh");
111  tempRTTEXTMeshStringAdapter->setHelp("Generated route to target extended mesh (vtk-format).");
112  mOutputTypes.push_back(tempRTTEXTMeshStringAdapter);
113 }
114 
115 
117 {
118  mRouteToTarget.reset(new RouteToTarget());
119 
120  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
121  if (!mesh)
122  return false;
123 
124  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
125 
126  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
127  if (!targetPoint)
128  return false;
129 
130  Vector3D targetCoordinate_r = targetPoint->getCoordinate();
131 
132  mRouteToTarget->processCenterline(centerline_r);
133 
134  //note: mOutput is in reference space
135  mOutput = mRouteToTarget->findRouteToTarget(targetCoordinate_r);
136 
137  if(mOutput->GetNumberOfPoints() < 1)
138  return false;
139 
140  mExtendedRoute = mRouteToTarget->findExtendedRoute(targetCoordinate_r);
141 
142  if (mGenerateFileWithRouteInformation)
143  mRouteToTarget->addRouteInformationToFile(mServices);
144 
145  return true;
146 }
147 
149 {
150 
151  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
152  if (!inputMesh)
153  return false;
154 
155  QString uidCenterline = inputMesh->getUid() + RouteToTargetFilter::getNameSuffix() + "%1";
156  QString nameCenterline = inputMesh->getName()+RouteToTargetFilter::getNameSuffix() + "%1";
157  if (!mTargetName.isEmpty())
158  {
159  uidCenterline.append("_" + mTargetName);
160  nameCenterline.append("_" + mTargetName);
161  }
162 
163  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
164  outputCenterline->setVtkPolyData(mOutput);
165  patientService()->insertData(outputCenterline);
166 
167  QString uidCenterlineExt = outputCenterline->getUid() + RouteToTargetFilter::getNameSuffixExtension();
168  QString nameCenterlineExt = outputCenterline->getName()+RouteToTargetFilter::getNameSuffixExtension();
169  MeshPtr outputCenterlineExt = patientService()->createSpecificData<Mesh>(uidCenterlineExt, nameCenterlineExt);
170  outputCenterlineExt->setVtkPolyData(mExtendedRoute);
171  outputCenterlineExt->setColor(QColor(0, 0, 255, 255));
172  patientService()->insertData(outputCenterlineExt);
173 
174  //note: mOutput and outputCenterline is in reference(r) space
175 
176 
177  //Meshes are expected to be in data(d) space
178  outputCenterline->get_rMd_History()->setParentSpace(inputMesh->getUid());
179  outputCenterlineExt->get_rMd_History()->setParentSpace(inputMesh->getUid());
180 
181  mServices->view()->autoShowData(outputCenterline);
182 
183  if(mOutputTypes.size() > 0)
184  mOutputTypes[0]->setValue(outputCenterline->getUid());
185  if(mOutputTypes.size() > 1)
186  mOutputTypes[1]->setValue(outputCenterlineExt->getUid());
187 
188 
189  return true;
190 }
191 
193 {
194  mTargetName = name;
195 }
196 
197 
198 } // namespace cx
199 
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
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
RouteToTargetFilter(VisServicesPtr services, bool createRouteInformationFile=false)
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr