37 #include <vtkImageImport.h>
38 #include <vtkImageData.h>
39 #include <vtkImageShiftScale.h>
40 #include <ctkPluginContext.h>
55 #include "FAST/Algorithms/AirwaySegmentation/AirwaySegmentation.hpp"
56 #include "FAST/Algorithms/CenterlineExtraction/CenterlineExtraction.hpp"
57 #include "FAST/Importers/ImageFileImporter.hpp"
58 #include "FAST/Exporters/VTKImageExporter.hpp"
59 #include "FAST/Exporters/VTKLineSetExporter.hpp"
60 #include "FAST/Data/Segmentation.hpp"
61 #include "FAST/SceneGraph.hpp"
73 return "Airway Segmentation Filter";
78 return "AirwaysFilter";
84 "<h3>Airway Segmentation.</h3>"
85 "<p><i>Extracts segmentation and centerline from a CT volume. If method fails, try to crop volume. </br>Algorithm written by Erik Smistad.</i></p>"
92 std::cout <<
"EXECUTING AIRWAYS FILTER" << std::endl;
98 std::string filename = (
patientService()->getActivePatientFolder()+
"/"+input->getFilename()).toStdString();
102 fast::ImageFileImporter::pointer importer = fast::ImageFileImporter::New();
103 importer->setFilename(filename);
107 fast::Image::pointer image = importer->getOutputData<fast::Image>();
108 std::cout <<
"IMAGE LOADED" << std::endl;
111 fast::AirwaySegmentation::pointer segmentation = fast::AirwaySegmentation::New();
112 segmentation->setInputConnection(importer->getOutputPort());
115 vtkSmartPointer<fast::VTKImageExporter> vtkExporter = fast::VTKImageExporter::New();
116 vtkExporter->setInputConnection(segmentation->getOutputPort());
117 vtkExporter->Update();
118 mSegmentationOutput = vtkExporter->GetOutput();
119 std::cout <<
"FINISHED AIRWAY SEGMENTATION" << std::endl;
122 fast::Segmentation::pointer segmentationData = segmentation->getOutputData<fast::Segmentation>(0);
125 Eigen::Affine3f T = fast::SceneGraph::getEigenAffineTransformationFromData(segmentationData);
126 mTransformation.matrix() = T.matrix().cast<
double>();
129 fast::CenterlineExtraction::pointer centerline = fast::CenterlineExtraction::New();
130 centerline->setInputConnection(segmentation->getOutputPort());
133 vtkSmartPointer<fast::VTKLineSetExporter> vtkCenterlineExporter = fast::VTKLineSetExporter::New();
134 vtkCenterlineExporter->setInputConnection(centerline->getOutputPort());
135 mCenterlineOutput = vtkCenterlineExporter->GetOutput();
136 vtkCenterlineExporter->Update();
138 }
catch(fast::Exception& e) {
139 std::string error = e.what();
143 }
catch(cl::Error& e) {
147 }
catch (std::exception& e){
152 reportError(
"Airway segmentation algorithm threw a unknown exception.");
161 if(!mSegmentationOutput)
164 std::cout <<
"POST PROCESS" << std::endl;
167 double threshold = 1;
186 contour->get_rMd_History()->setRegistration(mTransformation);
192 QString uid = mInputImage->getUid() +
"_centerline%1";
193 QString name = mInputImage->getName() +
" centerline%1";
196 centerline->get_rMd_History()->setParentSpace(mInputImage->getUid());
197 centerline->get_rMd_History()->setRegistration(mTransformation);
214 temp->setValueName(
"Input");
215 temp->setHelp(
"Select input to run airway segmentation on.");
225 tempMeshStringAdapter->setValueName(
"Centerline");
226 tempMeshStringAdapter->setHelp(
"Generated centerline mesh (vtk-format).");
231 tempMeshStringAdapter->setValueName(
"Segmentation");
232 tempMeshStringAdapter->setHelp(
"Generated surface of the segmented volume.");
QString qstring_cast(const T &val)
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
void reportError(QString msg)
boost::shared_ptr< class Image > ImagePtr
virtual void createOutputTypes()
virtual void createOptions()
virtual bool postProcess()
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
PatientModelServicePtr patientService()
void setVtkPolyData(const vtkPolyDataPtr &polyData)
virtual void createInputTypes()
ImagePtr getCopiedInputImage(int index=0)
virtual QString getType() const
AirwaysFilter(ctkPluginContext *pluginContext)
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
virtual bool postProcess()
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class Mesh > MeshPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
virtual QString getName() const
virtual QString getHelp() const