37 #include <vtkImageImport.h>
38 #include <vtkImageData.h>
39 #include <vtkImageShiftScale.h>
40 #include <ctkPluginContext.h>
56 #include "FAST/Algorithms/AirwaySegmentation/AirwaySegmentation.hpp"
57 #include "FAST/Algorithms/CenterlineExtraction/CenterlineExtraction.hpp"
58 #include "FAST/Importers/ImageFileImporter.hpp"
59 #include "FAST/Exporters/VTKImageExporter.hpp"
60 #include "FAST/Exporters/VTKLineSetExporter.hpp"
61 #include "FAST/Data/Segmentation.hpp"
62 #include "FAST/SceneGraph.hpp"
74 return "Airway Segmentation Filter";
79 return "AirwaysFilter";
85 "<h3>Airway Segmentation.</h3>"
86 "<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>"
97 std::string filename = (
patientService()->getActivePatientFolder()+
"/"+mInputImage->getFilename()).toStdString();
101 fast::DeviceManager::getInstance().setKernelRootPath(kernelDir.toStdString());
103 fast::ImageFileImporter::pointer importer = fast::ImageFileImporter::New();
104 importer->setFilename(filename);
108 fast::Image::pointer image = importer->getOutputData<fast::Image>();
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();
122 fast::Segmentation::pointer segmentationData = segmentation->getOutputData<fast::Segmentation>(0);
127 std::cout << segmentationData << std::endl;
128 std::cout << segmentationData->getTimestamp() << std::endl;
131 Eigen::Affine3f T = fast::SceneGraph::getEigenAffineTransformationFromData(segmentationData);
132 mTransformation.matrix() = T.matrix().cast<
double>();
135 fast::CenterlineExtraction::pointer centerline = fast::CenterlineExtraction::New();
136 centerline->setInputConnection(segmentation->getOutputPort());
139 vtkSmartPointer<fast::VTKLineSetExporter> vtkCenterlineExporter = fast::VTKLineSetExporter::New();
140 vtkCenterlineExporter->setInputConnection(centerline->getOutputPort());
141 mCenterlineOutput = vtkCenterlineExporter->GetOutput();
142 vtkCenterlineExporter->Update();
144 }
catch(fast::Exception& e) {
145 std::string error = e.what();
149 }
catch(cl::Error& e) {
153 }
catch (std::exception& e){
158 reportError(
"Airway segmentation algorithm threw a unknown exception.");
167 if(!mSegmentationOutput)
170 std::cout <<
"POST PROCESS" << std::endl;
173 double threshold = 1;
192 contour->get_rMd_History()->setRegistration(mTransformation);
198 QString uid = mInputImage->getUid() +
"_centerline%1";
199 QString name = mInputImage->getName() +
" centerline%1";
202 centerline->get_rMd_History()->setParentSpace(mInputImage->getUid());
203 centerline->get_rMd_History()->setRegistration(mTransformation);
220 temp->setValueName(
"Input");
221 temp->setHelp(
"Select input to run airway segmentation on.");
231 tempMeshStringAdapter->setValueName(
"Centerline");
232 tempMeshStringAdapter->setHelp(
"Generated centerline mesh (vtk-format).");
237 tempMeshStringAdapter->setValueName(
"Segmentation");
238 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)
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
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