From 4fd095bff2ac4dde50817d37522d2360e7b7e6c2 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Tue, 5 Oct 2010 09:31:29 +0000 Subject: [PATCH] new Airway filter (experimental) --- segmentation/clitkExtractAirwaysTreeInfo.cxx | 45 +++ segmentation/clitkExtractAirwaysTreeInfo.ggo | 23 ++ .../clitkExtractAirwaysTreeInfoFilter.h | 170 ++++++++ .../clitkExtractAirwaysTreeInfoFilter.txx | 365 ++++++++++++++++++ ...clitkExtractAirwaysTreeInfoGenericFilter.h | 70 ++++ ...itkExtractAirwaysTreeInfoGenericFilter.txx | 93 +++++ 6 files changed, 766 insertions(+) create mode 100644 segmentation/clitkExtractAirwaysTreeInfo.cxx create mode 100644 segmentation/clitkExtractAirwaysTreeInfo.ggo create mode 100644 segmentation/clitkExtractAirwaysTreeInfoFilter.h create mode 100644 segmentation/clitkExtractAirwaysTreeInfoFilter.txx create mode 100644 segmentation/clitkExtractAirwaysTreeInfoGenericFilter.h create mode 100644 segmentation/clitkExtractAirwaysTreeInfoGenericFilter.txx diff --git a/segmentation/clitkExtractAirwaysTreeInfo.cxx b/segmentation/clitkExtractAirwaysTreeInfo.cxx new file mode 100644 index 0000000..8e3fee4 --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfo.cxx @@ -0,0 +1,45 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +// clitk +#include "clitkExtractAirwaysTreeInfo_ggo.h" +#include "clitkExtractAirwaysTreeInfoGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) +{ + + // Init command line + GGO(clitkExtractAirwaysTreeInfo, args_info); + CLITK_INIT; + + // Filter + typedef clitk::ExtractAirwaysTreeInfoGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + filter->SetArgsInfo(args_info); + + try { + filter->Update(); + } catch(std::runtime_error e) { + std::cout << e.what() << std::endl; + } + + return EXIT_SUCCESS; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/segmentation/clitkExtractAirwaysTreeInfo.ggo b/segmentation/clitkExtractAirwaysTreeInfo.ggo new file mode 100644 index 0000000..cb1701c --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfo.ggo @@ -0,0 +1,23 @@ +#File clitkExtractAirwaysTreeInfos.ggo +package "clitkExtractAirwaysTreeInfos" +version "1.0" +purpose "From trachea binary image, extract skeleton and carena point." + +option "config" - "Config file" string no +option "imagetypes" - "Display allowed image types" flag off +option "verbose" v "Verbose" flag off +option "verboseStep" - "Verbose each step" flag off +option "writeStep" w "Write image at each step" flag off +option "verboseOption" - "Display options values" flag off +option "verboseWarningOff" - "Do not display warning" flag off + +section "I/O" + +option "input" i "Input trachea mask image filename" string yes +option "afdb" a "Output Anatomical Feature DB (Carina position)" string no +option "output" o "Output skeleton mask image filename" string yes + +section "Main options" + +option "writeSkeleton" - "Write skeleton" flag off +option "skeletonFilename" - "Skeleton filename" string no diff --git a/segmentation/clitkExtractAirwaysTreeInfoFilter.h b/segmentation/clitkExtractAirwaysTreeInfoFilter.h new file mode 100644 index 0000000..220d8ce --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfoFilter.h @@ -0,0 +1,170 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKEXTRACTAIRWAYTREEINFOSFILTER_H +#define CLITKEXTRACTAIRWAYTREEINFOSFILTER_H + +// clitk +#include "clitkFilterBase.h" +#include "clitkDecomposeAndReconstructImageFilter.h" +#include "clitkExplosionControlledThresholdConnectedImageFilter.h" +#include "clitkSegmentationUtils.h" +#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h" +#include "tree.hh" + +// itk +#include "itkStatisticsImageFilter.h" + +namespace clitk { + + //-------------------------------------------------------------------- + /* + From a trachea binary image, compute the skeleton and track the + path to find the carena. + */ + //-------------------------------------------------------------------- + + + + class Bifurcation + { + public: + typedef itk::Index<3> IndexType; + typedef itk::Point PointType; + typedef double PixelType; + Bifurcation(IndexType _index, PixelType _l, PixelType _l1, PixelType _l2) { + index = _index; + _l = l; + _l1 = l1; + _l2 = l2; + } + IndexType index; + PointType point; + PixelType l; + PixelType l1; + PixelType l2; + typedef itk::Index<3> NodeType; + typedef tree TreeType; + typedef TreeType::iterator TreeIterator; + TreeIterator treeIter; + }; + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + class ITK_EXPORT ExtractAirwaysTreeInfoFilter: + public virtual clitk::FilterBase, + public clitk::FilterWithAnatomicalFeatureDatabaseManagement, + public itk::ImageToImageFilter + { + + public: + /** Standard class typedefs. */ + typedef itk::ImageToImageFilter Superclass; + typedef ExtractAirwaysTreeInfoFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ExtractAirwaysTreeInfoFilter, ImageToImageFilter); + FILTERBASE_INIT; + + /** Some convenient typedefs */ + typedef TImageType ImageType; + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType ImageRegionType; + typedef typename ImageType::PixelType ImagePixelType; + typedef typename ImageType::SizeType ImageSizeType; + typedef typename ImageType::IndexType ImageIndexType; + typedef typename ImageType::PointType ImagePointType; + + typedef Bifurcation BifurcationType; + typedef ImageIndexType NodeType; + typedef tree TreeType; + typedef typename TreeType::iterator TreeIterator; + + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + typedef int InternalPixelType; + typedef itk::Image InternalImageType; + typedef typename InternalImageType::Pointer InternalImagePointer; + typedef typename InternalImageType::IndexType InternalIndexType; + typedef LabelizeParameters LabelParamType; + + /** Connect inputs */ + void SetInput(const ImageType * image); + + // Set all options at a time + template + void SetArgsInfo(ArgsInfoType arg); + + // Background / Foreground + itkGetConstMacro(BackgroundValue, ImagePixelType); + itkGetConstMacro(ForegroundValue, ImagePixelType); + + // Get results + itkGetConstMacro(FirstTracheaPoint, ImagePointType); + itkGetConstMacro(CarinaPoint, ImagePointType); + + protected: + ExtractAirwaysTreeInfoFilter(); + virtual ~ExtractAirwaysTreeInfoFilter() {} + + // Main members + ImageConstPointer input; + ImagePointer skeleton; + ImagePointer working_input; + + // Global options + itkSetMacro(BackgroundValue, ImagePixelType); + itkSetMacro(ForegroundValue, ImagePixelType); + ImagePixelType m_BackgroundValue; + ImagePixelType m_ForegroundValue; + + // Results + ImagePointType m_FirstTracheaPoint; + ImagePointType m_CarinaPoint; + + virtual void GenerateOutputInformation(); + virtual void GenerateData(); + + TreeType m_SkeletonTree; + void TrackFromThisIndex(std::vector & listOfBifurcations, + ImagePointer skeleton, + ImageIndexType index, + ImagePixelType label, + TreeIterator currentNode); + private: + ExtractAirwaysTreeInfoFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtractAirwaysTreeInfoFilter.txx" +#endif + +#endif diff --git a/segmentation/clitkExtractAirwaysTreeInfoFilter.txx b/segmentation/clitkExtractAirwaysTreeInfoFilter.txx new file mode 100644 index 0000000..69b7380 --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfoFilter.txx @@ -0,0 +1,365 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKEXTRACTAIRWAYSTREEINFOSFILTER_TXX +#define CLITKEXTRACTAIRWAYSTREEINFOSFILTER_TXX + +// clitk +#include "clitkImageCommon.h" +#include "clitkSetBackgroundImageFilter.h" +#include "clitkSegmentationUtils.h" +#include "clitkAutoCropFilter.h" +#include "clitkExtractSliceFilter.h" + +// itk +#include "itkBinaryThresholdImageFilter.h" +#include "itkConnectedComponentImageFilter.h" +#include "itkRelabelComponentImageFilter.h" +#include "itkOtsuThresholdImageFilter.h" +#include "itkBinaryThinningImageFilter3D.h" +#include "itkImageIteratorWithIndex.h" + + +//-------------------------------------------------------------------- +template +clitk::ExtractAirwaysTreeInfoFilter:: +ExtractAirwaysTreeInfoFilter(): + clitk::FilterBase(), + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() +{ + // Default global options + this->SetNumberOfRequiredInputs(1); + SetBackgroundValue(0); + SetForegroundValue(1); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractAirwaysTreeInfoFilter:: +SetInput(const ImageType * image) +{ + this->SetNthInput(0, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void +clitk::ExtractAirwaysTreeInfoFilter:: +SetArgsInfo(ArgsInfoType mArgsInfo) +{ + SetVerboseOption_GGO(mArgsInfo); + SetVerboseStep_GGO(mArgsInfo); + SetWriteStep_GGO(mArgsInfo); + SetVerboseWarningOff_GGO(mArgsInfo); + SetAFDBFilename_GGO(mArgsInfo); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractAirwaysTreeInfoFilter:: +GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); + //this->GetOutput(0)->SetRequestedRegion(this->GetOutput(0)->GetLargestPossibleRegion()); + + // Get input pointer + input = dynamic_cast(itk::ProcessObject::GetInput(0)); + + // Try to load the DB + try { + LoadAFDB(); + } catch (clitk::ExceptionObject e) { + // Do nothing if not found, it will be used anyway to write the result + } + + +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractAirwaysTreeInfoFilter:: +GenerateData() +{ + StartNewStep("Thinning filter (skeleton)"); + // Extract skeleton + typedef itk::BinaryThinningImageFilter3D ThinningFilterType; + typename ThinningFilterType::Pointer thinningFilter = ThinningFilterType::New(); + thinningFilter->SetInput(input); // input = trachea + thinningFilter->Update(); + skeleton = thinningFilter->GetOutput(); + StopCurrentStep(skeleton); + + // Find first point for tracking + StartNewStep("Find first point for tracking"); + typedef itk::ImageRegionConstIteratorWithIndex IteratorType; + IteratorType it(skeleton, skeleton->GetLargestPossibleRegion()); + it.GoToReverseBegin(); + while ((!it.IsAtEnd()) && (it.Get() == GetBackgroundValue())) { + --it; + } + if (it.IsAtEnd()) { + clitkExceptionMacro("first point in the trachea skeleton not found."); + } + typename ImageType::IndexType index = it.GetIndex(); + DD(index); + + // Initialize neighborhooditerator + typedef itk::NeighborhoodIterator NeighborhoodIteratorType; + typename NeighborhoodIteratorType::SizeType radius; + radius.Fill(1); + NeighborhoodIteratorType nit(radius, skeleton, skeleton->GetLargestPossibleRegion()); + + // Find first label number (must be different from BG and FG) + typename ImageType::PixelType label = GetForegroundValue()+1; + while ((label == GetBackgroundValue()) || (label == GetForegroundValue())) { label++; } + DD(label); + + /* + Tracking ? + Goal : find position of C, RUL, RML, RLL, LUL, LLL bronchus + Carina : ok "easy", track, slice by slice until 2 path into different label + -> follow at Right + - + -> follow at Left + */ + + + // Track from the first point + StartNewStep("Start tracking"); + std::vector listOfBifurcations; + m_SkeletonTree.set_head(index); + TrackFromThisIndex(listOfBifurcations, skeleton, index, label, m_SkeletonTree.begin()); + DD("end track"); + + // Convert index into physical point coordinates + for(unsigned int i=0; iTransformIndexToPhysicalPoint(listOfBifurcations[i].index, + listOfBifurcations[i].point); + } + + // Search for the first slice that separate the bronchus + // (carina). Labelize slice by slice, stop when the two points of + // the skeleton ar not in the same connected component + StartNewStep("Search for carina position"); + typedef clitk::ExtractSliceFilter ExtractSliceFilterType; + typename ExtractSliceFilterType::Pointer extractSliceFilter = ExtractSliceFilterType::New(); + extractSliceFilter->SetInput(input); + extractSliceFilter->SetDirection(2); + extractSliceFilter->Update(); + typedef typename ExtractSliceFilterType::SliceType SliceType; + std::vector mInputSlices; + extractSliceFilter->GetOutputSlices(mInputSlices); + DD(mInputSlices.size()); + + bool stop = false; + int slice_index = listOfBifurcations[0].index[2]; // first slice from carina in skeleton + int i=0; + TreeIterator firstIter = m_SkeletonTree.child(listOfBifurcations[0].treeIter, 0); + TreeIterator secondIter = m_SkeletonTree.child(listOfBifurcations[0].treeIter, 1); + typename SliceType::IndexType in1; + typename SliceType::IndexType in2; + while (!stop) { + // Labelize the current slice + typename SliceType::Pointer temp = Labelize(mInputSlices[slice_index], + GetBackgroundValue(), + true, + 0); // min component size=0 + // Check the value of the two skeleton points; + in1[0] = (*firstIter)[0]; + in1[1] = (*firstIter)[1]; + typename SliceType::PixelType v1 = temp->GetPixel(in1); + in2[0] = (*secondIter)[0]; + in2[1] = (*secondIter)[1]; + typename SliceType::PixelType v2 = temp->GetPixel(in2); + + // Check the label value of the two points + DD(slice_index); + if (v1 != v2) { + stop = true; // We found it ! + } + else { + // Check error + if (slice_index == (int)(mInputSlices.size()-1)) { + clitkExceptionMacro("Error while searching for carina, the two skeleton points are always in the same CC ... ???"); + } + // Iterate + i++; + --slice_index; + ++firstIter; + ++secondIter; + } + } + ImageIndexType carina_index; // middle position in X/Y + carina_index[0] = lrint(in2[0] + in1[0])/2.0; + carina_index[1] = lrint(in2[1] + in1[1])/2.0; + carina_index[2] = slice_index; + // Get physical coordinates + ImagePointType carina_position; + skeleton->TransformIndexToPhysicalPoint(carina_index, + carina_position); + + // Set and save Carina position + if (GetVerboseStep()) { + std::cout << "\t Found carina at " << carina_position << " mm" << std::endl; + } + GetAFDB()->SetPoint3D("Carina", carina_position); + + // Write bifurcation (debug) + for(uint i=0; iSetPoint3D("Bif"+toString(i), listOfBifurcations[i].point); + } + + // Set the output (skeleton); + this->GraftOutput(skeleton); // not SetNthOutput +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractAirwaysTreeInfoFilter:: +TrackFromThisIndex(std::vector & listOfBifurcations, + ImagePointer skeleton, + ImageIndexType index, + ImagePixelType label, + TreeIterator currentNode) +{ + // Create NeighborhoodIterator + typedef itk::NeighborhoodIterator NeighborhoodIteratorType; + typename NeighborhoodIteratorType::SizeType radius; + radius.Fill(1); + NeighborhoodIteratorType nit(radius, skeleton, skeleton->GetLargestPossibleRegion()); + + // Track + std::vector listOfTrackedPoint; + bool stop = false; + while (!stop) { + nit.SetLocation(index); + nit.SetCenterPixel(label); + listOfTrackedPoint.clear(); + for(unsigned int i=0; iSetPixel(index, label); // change label in skeleton image + } + else { + if (listOfTrackedPoint.size() == 2) { + // m_SkeletonTree->Add(listOfTrackedPoint[0], index); // the parent is 'index' + // m_SkeletonTree->Add(listOfTrackedPoint[1], index); // the parent is 'index' + BifurcationType bif(index, label, label+1, label+2); + bif.treeIter = currentNode; + listOfBifurcations.push_back(bif); + TreeIterator firstNode = m_SkeletonTree.append_child(currentNode, listOfTrackedPoint[0]); + TreeIterator secondNode = m_SkeletonTree.append_child(currentNode, listOfTrackedPoint[1]); + TrackFromThisIndex(listOfBifurcations, skeleton, listOfTrackedPoint[0], label+1, firstNode); + TrackFromThisIndex(listOfBifurcations, skeleton, listOfTrackedPoint[1], label+2, secondNode); + } + else { + //DD(listOfTrackedPoint.size()); + if (listOfTrackedPoint.size() > 2) { + //clitkExceptionMacro("error while tracking trachea bifurcation. Too much bifurcation points ... ?"); + stop = true; // this it the end of the tracking + } + // Else this it the end of the tracking + } + stop = true; + } + } +} +//-------------------------------------------------------------------- + +/*TrackFromThisIndex(std::vector & listOfBifurcations, + ImagePointer skeleton, + ImageIndexType index, + ImagePixelType label) + { + DD("TrackFromThisIndex"); + DD(index); + DD((int)label); + // Create NeighborhoodIterator + typedef itk::NeighborhoodIterator NeighborhoodIteratorType; + typename NeighborhoodIteratorType::SizeType radius; + radius.Fill(1); + NeighborhoodIteratorType nit(radius, skeleton, skeleton->GetLargestPossibleRegion()); + + // Track + std::vector listOfTrackedPoint; + bool stop = false; + while (!stop) { + nit.SetLocation(index); + // DD((int)nit.GetCenterPixel()); + nit.SetCenterPixel(label); + listOfTrackedPoint.clear(); + for(unsigned int i=0; i 2) { + std::cerr << "too much bifurcation points ... ?" << std::endl; + exit(0); + } + // Else this it the end of the tracking + } + stop = true; + } + } + } +*/ +//-------------------------------------------------------------------- + + +#endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX diff --git a/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.h b/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.h new file mode 100644 index 0000000..f730e33 --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.h @@ -0,0 +1,70 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +#ifndef CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_H +#define CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_H + +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" +#include "clitkExtractAirwaysTreeInfoFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT ExtractAirwaysTreeInfoGenericFilter: + public ImageToImageGenericFilter > + { + + public: + //-------------------------------------------------------------------- + ExtractAirwaysTreeInfoGenericFilter(); + + //-------------------------------------------------------------------- + typedef ExtractAirwaysTreeInfoGenericFilter Self; + typedef ImageToImageGenericFilter > Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + itkNewMacro(Self); + itkTypeMacro(ExtractAirwaysTreeInfoGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const ArgsInfoType & a); + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + protected: + template void InitializeImageType(); + ArgsInfoType mArgsInfo; + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtractAirwaysTreeInfoGenericFilter.txx" +#endif + +#endif // #define CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_H diff --git a/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.txx b/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.txx new file mode 100644 index 0000000..3f802fc --- /dev/null +++ b/segmentation/clitkExtractAirwaysTreeInfoGenericFilter.txx @@ -0,0 +1,93 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_TXX +#define CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_TXX + +#include "clitkImageCommon.h" + +//-------------------------------------------------------------------- +template +clitk::ExtractAirwaysTreeInfoGenericFilter::ExtractAirwaysTreeInfoGenericFilter(): + ImageToImageGenericFilter("ExtractAirwaysTreeInfo") +{ + this->SetFilterBase(NULL); + // Default values + cmdline_parser_clitkExtractAirwaysTreeInfo_init(&mArgsInfo); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::ExtractAirwaysTreeInfoGenericFilter::InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); + // ADD_IMAGE_TYPE(Dim, int); + // ADD_IMAGE_TYPE(Dim, float); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::ExtractAirwaysTreeInfoGenericFilter::SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.input_given) AddInputFilename(mArgsInfo.input_arg); + if (mArgsInfo.output_given) AddOutputFilename(mArgsInfo.output_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::ExtractAirwaysTreeInfoGenericFilter::UpdateWithInputImageType() +{ + // Reading input + typename ImageType::Pointer input = this->template GetInput(0); + + // Create filter + typedef clitk::ExtractAirwaysTreeInfoFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set the filter (needed for example for threaded monitoring) + this->SetFilterBase(filter); + + // Set global Options + filter->SetArgsInfo(mArgsInfo); + filter->SetInput(input); + + // Go ! + filter->Update(); + + // Write/Save results + typename ImageType::Pointer output = filter->GetOutput(); + this->template SetNextOutput(output); + filter->WriteAFDB(); +} +//-------------------------------------------------------------------- + +#endif //#define CLITKEXTRACTAIRWAYTREEINFOSGENERICFILTER_TXX -- 2.47.1