CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxAirwaysFromCenterlineFilterService.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 
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 {
44 }
45 
47 {
48  return "Airways from centerline";
49 }
50 
52 {
53  return "airwaysfromcenterline_filter";
54 }
55 
57 {
58  return "<html>"
59  "<h3>Airways from centerline.</h3>"
60  "<p>Generates artificial surface models of airways around input centerline.</p>"
61  "</html>";
62 }
63 
65 {
66  return "_AirwaysModel";
67 }
68 
70 {
71  return "_SmoothedCenterline";
72 }
73 
75 {
76 
77 }
78 
80 {
81  StringPropertySelectMeshPtr centerline;
82  centerline = StringPropertySelectMesh::New(mServices->patient());
83  centerline->setValueName("Airways centerline");
84  centerline->setHelp("Select airways centerline");
85  mInputTypes.push_back(centerline);
86 
87 }
88 
90 {
91  StringPropertySelectMeshPtr tempAirwaysModelMeshStringAdapter;
92  tempAirwaysModelMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
93  tempAirwaysModelMeshStringAdapter->setValueName("Airways surface model mesh");
94  tempAirwaysModelMeshStringAdapter->setHelp("Generated airways surface model mesh (vtk-format).");
95  mOutputTypes.push_back(tempAirwaysModelMeshStringAdapter);
96 
97  StringPropertySelectMeshPtr tempSmoothedCenterlineMeshStringAdapter;
98  tempSmoothedCenterlineMeshStringAdapter = StringPropertySelectMesh::New(mServices->patient());
99  tempSmoothedCenterlineMeshStringAdapter->setValueName("Smoothed centerline");
100  tempSmoothedCenterlineMeshStringAdapter->setHelp("Smoothed centerline (vtk-format).");
101  mOutputTypes.push_back(tempSmoothedCenterlineMeshStringAdapter);
102 }
103 
104 
106 {
107  mAirwaysFromCenterline.reset(new AirwaysFromCenterline());
108 
109  MeshPtr mesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
110  if (!mesh)
111  return false;
112 
113  vtkPolyDataPtr centerline_r = mesh->getTransformedPolyDataCopy(mesh->get_rMd());
114 
115  mAirwaysFromCenterline->processCenterline(centerline_r);
116 
117  //note: mOutputAirwayMesh is in reference space
118  mOutputAirwayMesh = mAirwaysFromCenterline->generateTubes();
119 
120  //if(mOutputAirwayMesh->GetNumberOfPoints() < 1)
121  // return false;
122 
123  return true;
124 }
125 
127 {
128 
129  MeshPtr inputMesh = boost::dynamic_pointer_cast<StringPropertySelectMesh>(mInputTypes[0])->getMesh();
130  if (!inputMesh)
131  return false;
132 
133  QString uidSurfaceModel = inputMesh->getUid() + AirwaysFromCenterlineFilter::getNameSuffix() + "%1";
134  QString nameSurfaceModel = inputMesh->getName() + AirwaysFromCenterlineFilter::getNameSuffix() + "%1";
135 
136  MeshPtr outputMesh = patientService()->createSpecificData<Mesh>(uidSurfaceModel, nameSurfaceModel);
137  outputMesh->setVtkPolyData(mOutputAirwayMesh);
138  outputMesh->setColor(QColor(253, 173, 136, 255));
139  patientService()->insertData(outputMesh);
140 
141  //Meshes are expected to be in data(d) space
142  outputMesh->get_rMd_History()->setParentSpace(inputMesh->getUid());
143 
144  mServices->view()->autoShowData(outputMesh);
145 
146  QString uidCenterline = inputMesh->getUid() + AirwaysFromCenterlineFilter::getNameSuffixCenterline() + "%1";
147  QString nameCenterline = inputMesh->getName() + AirwaysFromCenterlineFilter::getNameSuffixCenterline() + "%1";
148 
149  MeshPtr outputCenterline = patientService()->createSpecificData<Mesh>(uidCenterline, nameCenterline);
150  outputCenterline->setVtkPolyData(mAirwaysFromCenterline->getVTKPoints());
151  outputCenterline->setColor(QColor(0, 200, 0, 255));
152  patientService()->insertData(outputCenterline);
153 
154  if(mOutputTypes.size() > 0)
155  mOutputTypes[0]->setValue(outputMesh->getUid());
156  if(mOutputTypes.size() > 1)
157  mOutputTypes[1]->setValue(outputCenterline->getUid());
158 
159  return true;
160 }
161 
162 } // namespace cx
163 
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()
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:92
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
Definition: cxFilterImpl.h:74
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Namespace for all CustusX production code.