CustusX  16.5
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 
54 
55 namespace cx
56 {
57 
58 RouteToTargetFilter::RouteToTargetFilter(ctkPluginContext *pluginContext) :
59  FilterImpl(VisServicesPtr(new VisServices(pluginContext)) )
60 {
61  mRouteToTarget = RouteToTargetPtr(new RouteToTarget());
62 }
63 
65 {
66  return "Route to target";
67 }
68 
70 {
71  return "RouteToTargetFilter";
72 }
73 
75 {
76  return "<html>"
77  "<h3>Route to target.</h3>"
78  "<p>Calculates the route to a selected target in navigated bronchocopy."
79  "The rout starts at the top of trachea and ends at the most adjacent airway centerline"
80  "from the target.</p>"
81  "</html>";
82 }
83 
84 
86 {
87 
88 }
89 
91 {
92  StringPropertySelectMeshPtr centerline;
93  centerline = StringPropertySelectMesh::New(mServices->patient());
94  centerline->setValueName("Centerline");
95  centerline->setHelp("Select centerline");
96  mInputTypes.push_back(centerline);
97 
99  targetPoint = StringPropertySelectPointMetric::New(mServices->patient());
100  targetPoint->setValueName("Target point");
101  targetPoint->setHelp("Select point metric input");
102  connect(targetPoint.get(), SIGNAL(dataChanged(QString)), this, SLOT(pointMetricChangedSlot(QString)));
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  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
123 
124  vtkPolyDataPtr centerline = mesh->getVtkPolyData();
125 
126  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
127 
128  Vector3D targetCoordinate = targetPoint->getCoordinate();
129 
130  mRouteToTarget->processCenterline(centerline);
131  mOutput = mRouteToTarget->findRouteToTarget(targetCoordinate);
132 
133  return true;
134 }
135 
137 {
138 
139  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
140 
141  QString uidCenterline = inputMesh->getUid() + "_rtt_cl%1";
142  QString nameCenterline = inputMesh->getName()+"_rtt_cl%1";
143 
144  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
145 
146  outputCenterline->setVtkPolyData(mOutput);
147 
148  if (!outputCenterline)
149  return false;
150 
151  outputCenterline->get_rMd_History()->setRegistration(inputMesh->get_rMd());
152 
153  patientService()->insertData(outputCenterline);
154 
155  mOutputTypes[0]->setValue(outputCenterline->getUid());
156 
157 
158  return true;
159 }
160 
161 
162 } // namespace cx
163 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
boost::shared_ptr< class RouteToTarget > RouteToTargetPtr
A mesh data set.
Definition: cxMesh.h:61
RouteToTargetFilter(ctkPluginContext *pluginContext)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
VisServicesPtr mServices
Definition: cxFilterImpl.h:103
PatientModelServicePtr patientService()
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:100
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