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>"
91 std::cout <<
"EXECUTING AIRWAYS FILTER" << std::endl;
96 std::string filename = (
patientService()->getActivePatientFolder()+
"/"+mInputImage->getFilename()).toStdString();
100 fast::ImageFileImporter::pointer importer = fast::ImageFileImporter::New();
101 importer->setFilename(filename);
105 fast::Image::pointer image = importer->getOutputData<fast::Image>();
106 std::cout <<
"IMAGE LOADED" << std::endl;
109 fast::AirwaySegmentation::pointer segmentation = fast::AirwaySegmentation::New();
110 segmentation->setInputConnection(importer->getOutputPort());
113 vtkSmartPointer<fast::VTKImageExporter> vtkExporter = fast::VTKImageExporter::New();
114 vtkExporter->setInputConnection(segmentation->getOutputPort());
115 vtkExporter->Update();
116 mSegmentationOutput = vtkExporter->GetOutput();
117 std::cout <<
"FINISHED AIRWAY SEGMENTATION" << std::endl;
120 fast::Segmentation::pointer segmentationData = segmentation->getOutputData<fast::Segmentation>(0);
123 Eigen::Affine3f T = fast::SceneGraph::getEigenAffineTransformationFromData(segmentationData);
124 mTransformation.matrix() = T.matrix().cast<
double>();
127 fast::CenterlineExtraction::pointer centerline = fast::CenterlineExtraction::New();
128 centerline->setInputConnection(segmentation->getOutputPort());
131 vtkSmartPointer<fast::VTKLineSetExporter> vtkCenterlineExporter = fast::VTKLineSetExporter::New();
132 vtkCenterlineExporter->setInputConnection(centerline->getOutputPort());
133 mCenterlineOutput = vtkCenterlineExporter->GetOutput();
134 vtkCenterlineExporter->Update();
136 }
catch(fast::Exception& e) {
137 std::string error = e.what();
141 }
catch(cl::Error& e) {
145 }
catch (std::exception& e){
150 reportError(
"Airway segmentation algorithm threw a unknown exception.");
159 if(!mSegmentationOutput)
162 std::cout <<
"POST PROCESS" << std::endl;
165 double threshold = 1;
184 contour->get_rMd_History()->setRegistration(mTransformation);
190 QString uid = mInputImage->getUid() +
"_centerline%1";
191 QString name = mInputImage->getName() +
" centerline%1";
194 centerline->get_rMd_History()->setParentSpace(mInputImage->getUid());
195 centerline->get_rMd_History()->setRegistration(mTransformation);
212 temp->setValueName(
"Input");
213 temp->setHelp(
"Select input to run airway segmentation on.");
223 tempMeshStringAdapter->setValueName(
"Centerline");
224 tempMeshStringAdapter->setHelp(
"Generated centerline mesh (vtk-format).");
229 tempMeshStringAdapter->setValueName(
"Segmentation");
230 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 VisServices > VisServicesPtr
boost::shared_ptr< class Image > ImagePtr
virtual void createOutputTypes()
virtual void createOptions()
virtual bool postProcess()
AirwaysFilter(VisServicesPtr services)
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
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