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"
70 fast::ImageFileImporter::pointer importer = fast::ImageFileImporter::New();
80 return "Airway Segmentation Filter";
85 return "AirwaysFilter";
91 "<h3>Airway Segmentation.</h3>"
92 "<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>"
104 QString q_filename =
"";
105 QString activePatienFolder =
patientService()->getActivePatientFolder();
106 QString inputImageFileName = mInputImage->getFilename();
107 if(!activePatienFolder.isEmpty())
108 q_filename = activePatienFolder+
"/"+inputImageFileName;
110 q_filename = inputImageFileName;
112 std::string filename = q_filename.toStdString();
115 fast::DeviceManager::getInstance().setKernelRootPath(kernelDir.toStdString());
117 fast::DeviceManager::getInstance().setWritableCachePath(cacheDir.toStdString());
120 fast::ImageFileImporter::pointer importer = fast::ImageFileImporter::New();
121 importer->setFilename(filename);
125 fast::Image::pointer image = importer->getOutputData<fast::Image>();
128 fast::AirwaySegmentation::pointer segmentation = fast::AirwaySegmentation::New();
129 segmentation->setInputConnection(importer->getOutputPort());
132 vtkSmartPointer<fast::VTKImageExporter> vtkExporter = fast::VTKImageExporter::New();
133 vtkExporter->setInputConnection(segmentation->getOutputPort());
134 vtkExporter->Update();
135 mSegmentationOutput = vtkExporter->GetOutput();
139 fast::Segmentation::pointer segmentationData = segmentation->getOutputData<fast::Segmentation>(0);
142 Eigen::Affine3f T = fast::SceneGraph::getEigenAffineTransformationFromData(segmentationData);
143 mTransformation.matrix() = T.matrix().cast<
double>();
146 fast::CenterlineExtraction::pointer centerline = fast::CenterlineExtraction::New();
147 centerline->setInputConnection(segmentation->getOutputPort());
150 vtkSmartPointer<fast::VTKLineSetExporter> vtkCenterlineExporter = fast::VTKLineSetExporter::New();
151 vtkCenterlineExporter->setInputConnection(centerline->getOutputPort());
152 mCenterlineOutput = vtkCenterlineExporter->GetOutput();
153 vtkCenterlineExporter->Update();
155 }
catch(fast::Exception& e) {
156 std::string error = e.what();
160 }
catch(cl::Error& e) {
164 }
catch (std::exception& e){
169 reportError(
"Airway segmentation algorithm threw a unknown exception.");
178 if(!mSegmentationOutput)
181 std::cout <<
"POST PROCESS" << std::endl;
184 double threshold = 1;
203 contour->get_rMd_History()->setRegistration(mTransformation);
209 QString uid = mInputImage->getUid() +
"_centerline%1";
210 QString name = mInputImage->getName() +
" centerline%1";
213 centerline->get_rMd_History()->setParentSpace(mInputImage->getUid());
214 centerline->get_rMd_History()->setRegistration(mTransformation);
230 temp->setValueName(
"Input");
231 temp->setHelp(
"Select input to run airway segmentation on.");
241 tempMeshStringAdapter->setValueName(
"Centerline");
242 tempMeshStringAdapter->setHelp(
"Generated centerline mesh (vtk-format).");
247 tempMeshStringAdapter->setValueName(
"Segmentation");
248 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()
static QString getCachePath()
return path to a folder that is used during execution, will be cleared at start and stop...
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