Fraxinus  16.5.0-fx-rc3
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 "RouteToTargetFilter";
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 
126  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyData(mesh->get_rMd());
127 
128  PointMetricPtr targetPoint = boost::dynamic_pointer_cast<StringPropertySelectPointMetric>(mInputTypes[1])->getPointMetric();
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  return true;
138 }
139 
141 {
142 
143  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
144 
145  QString uidCenterline = inputMesh->getUid() + "_rtt_cl%1";
146  QString nameCenterline = inputMesh->getName()+"_rtt_cl%1";
147 
148  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
149 
150  //note: mOutput and outputCenterline is in reference(r) space
151  outputCenterline->setVtkPolyData(mOutput);
152 
153  if (!outputCenterline)
154  return false;
155 
156  //Meshes are expected to be in data(d) space
157  outputCenterline->get_rMd_History()->setParentSpace(inputMesh->getUid());
158 
159  patientService()->insertData(outputCenterline);
160  mServices->view()->autoShowData(outputCenterline);
161 
162  mOutputTypes[0]->setValue(outputCenterline->getUid());
163 
164  return true;
165 }
166 
167 
168 } // namespace cx
169 
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
Definition: cxFilterImpl.h:94
A mesh data set.
Definition: cxMesh.h:61
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: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