From 4f6aadc0552db99c03057d4aa40a7fc4a1697350 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 4 Nov 2011 10:23:03 +0100 Subject: [PATCH] First version of rel pos database builder --- ...kRelativePositionDataBaseBuilderFilter.txx | 160 ++++++++++++++++++ .../clitkRelativePositionDataBaseBuilder.cxx | 52 ++++++ .../clitkRelativePositionDataBaseBuilder.ggo | 25 +++ ...tivePositionDataBaseBuilderGenericFilter.h | 76 +++++++++ ...vePositionDataBaseBuilderGenericFilter.txx | 101 +++++++++++ 5 files changed, 414 insertions(+) create mode 100644 itk/clitkRelativePositionDataBaseBuilderFilter.txx create mode 100644 tools/clitkRelativePositionDataBaseBuilder.cxx create mode 100644 tools/clitkRelativePositionDataBaseBuilder.ggo create mode 100644 tools/clitkRelativePositionDataBaseBuilderGenericFilter.h create mode 100644 tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx diff --git a/itk/clitkRelativePositionDataBaseBuilderFilter.txx b/itk/clitkRelativePositionDataBaseBuilderFilter.txx new file mode 100644 index 0000000..af482ca --- /dev/null +++ b/itk/clitkRelativePositionDataBaseBuilderFilter.txx @@ -0,0 +1,160 @@ +/*========================================================================= + 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://www.centreleonberard.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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::RelativePositionDataBaseBuilderFilter:: +RelativePositionDataBaseBuilderFilter(): + clitk::FilterBase(), + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(0); // support + VerboseFlagOff(); + SetBackgroundValue(0); + SetForegroundValue(1); + SetNumberOfBins(100); + SetNumberOfAngles(4); + SetAreaLossTolerance(0.01); + m_ListOfAngles.clear(); + // SetSupportSize(0); + // SetTargetSize(0); + // SetSizeWithThreshold(0); + // SetSizeWithReverseThreshold(0); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionDataBaseBuilderFilter:: +PrintOptions() +{ + DD("TODO"); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionDataBaseBuilderFilter:: +GenerateOutputInformation() +{ + // ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + // ImagePointer outputImage = this->GetOutput(0); + // outputImage->SetRegions(outputImage->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionDataBaseBuilderFilter:: +GenerateInputRequestedRegion() +{ + // Call default + // itk::ImageToImageFilter::GenerateInputRequestedRegion(); + // // Get input pointers and set requested region to common region + // ImagePointer input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); + // input1->SetRequestedRegion(input1->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionDataBaseBuilderFilter:: +GenerateData() +{ + // Load database of anatomical elements + static const unsigned int dim = ImageType::ImageDimension; + this->LoadAFDB(); + + // Get some information + std::string patient = this->GetAFDB()->GetTagValue("PatientID"); + + // Get input pointers + m_Support = this->GetAFDB()->template GetImage (GetSupportName()); + m_Target = this->GetAFDB()->template GetImage (GetTargetName()); + + // Build the list of tested directions + m_ListOfAngles.clear(); + for(uint i=0; i180) a = 180-a; + m_ListOfAngles.push_back(clitk::deg2rad(a)); + RelativePositionDirectionType r; + r.angle1 = clitk::deg2rad(a); + r.angle2 = 0; + r.notFlag = false; + m_ListOfDirections.push_back(r); // only one direction + } + + + // Perform the RelativePositionAnalyzerFilter for each objects + typedef typename clitk::RelativePositionAnalyzerFilter FilterType; + for (int i=0; iGetAFDB()->template GetImage (GetObjectName(i)); + + for (int j=0; jSetInputSupport(m_Support); + filter->SetInputTarget(m_Target); + filter->SetInputObject(m_Object); // FIXME do AndNot before + only compute supportSize once. + filter->SetNumberOfBins(GetNumberOfBins()); + filter->SetAreaLossTolerance(GetAreaLossTolerance()); + filter->SetDirection(direction); + filter->Update(); + + // Results + std::ostringstream s; + s << patient << " " + << GetSupportName() << " " + // << GetTargetName() << " " // No need + << GetObjectName(i) <<" "; + // Normal + // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) { + std::ostringstream os; + os << s.str(); + direction.notFlag = false; + direction.Print(os); + filter->GetInfo().Print(os); + std::cout << os.str() << std::endl; + // } + // Inverse + // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) { + std::ostringstream oos; + oos << s.str(); + direction.notFlag = true; + direction.Print(oos); + filter->GetInfoReverse().Print(oos); + std::cout << oos.str() << std::endl; + // } + } // end direction + + } // end object +} +//-------------------------------------------------------------------- + + diff --git a/tools/clitkRelativePositionDataBaseBuilder.cxx b/tools/clitkRelativePositionDataBaseBuilder.cxx new file mode 100644 index 0000000..4c8db03 --- /dev/null +++ b/tools/clitkRelativePositionDataBaseBuilder.cxx @@ -0,0 +1,52 @@ +/*========================================================================= + 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://www.centreleonberard.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 "clitkRelativePositionDataBaseBuilder_ggo.h" +#include "clitkRelativePositionDataBaseBuilderGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkRelativePositionDataBaseBuilder, args_info); + CLITK_INIT; + + // Filter + typedef clitk::RelativePositionDataBaseBuilderGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + // Set options + filter->SetArgsInfo(args_info); + + // Add an input to determine the type of image + NewAFDB(afdb, args_info.afdb_arg); + std::string f = afdb->GetTagValue(args_info.supportName_arg); + f = std::string(args_info.afdb_path_arg)+"/"+f; + filter->AddInputFilename(f); + + try { + filter->Update(); + } catch(std::runtime_error e) { + std::cout << e.what() << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/tools/clitkRelativePositionDataBaseBuilder.ggo b/tools/clitkRelativePositionDataBaseBuilder.ggo new file mode 100644 index 0000000..c71c462 --- /dev/null +++ b/tools/clitkRelativePositionDataBaseBuilder.ggo @@ -0,0 +1,25 @@ +#File clitkRelativePositionDataBaseBuilder.ggo +package "clitkRelativePositionDataBaseBuilder" +version "1.0" +purpose "Analyze relative position of a target according to structures" + +section "General options" +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Display allowed image types" flag off + +section "Input/Output" +option "afdb" a "Input Anatomical Feature DB" string yes +option "afdb_path" - "Path to search image in afdb" string no + +option "supportName" i "Input mask support name in afdb" string yes +option "targetName" t "Input mask target name in afdb" string yes +option "objectName" j "Input mask object name in afdb" string yes multiple + +option "output" o "Output image " string yes + +section "Options for building the relative positions" +option "bins" b "Number of histo bins for fuzzy map" int default="100" no +option "nb" n "Number of angles to test" int default="4" no +option "tol" - "Target area loss tolerance (|0-1])" double default="0.01" no + diff --git a/tools/clitkRelativePositionDataBaseBuilderGenericFilter.h b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.h new file mode 100644 index 0000000..bf88269 --- /dev/null +++ b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.h @@ -0,0 +1,76 @@ +/*========================================================================= + 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://www.centreleonberard.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 CLITKRelativePositionDataBaseBuilderGENERICFILTER_H +#define CLITKRelativePositionDataBaseBuilderGENERICFILTER_H + +// clitk +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" +#include "clitkRelativePositionDataBaseBuilderFilter.h" +#include "clitkSliceBySliceRelativePositionFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT RelativePositionDataBaseBuilderGenericFilter: + public ImageToImageGenericFilter > + { + public: + //-------------------------------------------------------------------- + RelativePositionDataBaseBuilderGenericFilter(); + + //-------------------------------------------------------------------- + typedef ImageToImageGenericFilter > Superclass; + typedef RelativePositionDataBaseBuilderGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + itkNewMacro(Self); + itkTypeMacro(RelativePositionDataBaseBuilderGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const ArgsInfoType & a); + template + void SetOptionsFromArgsInfoToFilter(FilterType * f) ; + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + protected: + template void InitializeImageType(); + ArgsInfoType mArgsInfo; + + private: + RelativePositionDataBaseBuilderGenericFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + };// end class + //-------------------------------------------------------------------- +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkRelativePositionDataBaseBuilderGenericFilter.txx" +#endif + +#endif // #define CLITKRelativePositionDataBaseBuilderGENERICFILTER_H diff --git a/tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx new file mode 100644 index 0000000..6ce6a2a --- /dev/null +++ b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx @@ -0,0 +1,101 @@ +/*========================================================================= + 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://www.centreleonberard.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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::RelativePositionDataBaseBuilderGenericFilter:: +RelativePositionDataBaseBuilderGenericFilter(): + ImageToImageGenericFilter("RelativePositionDataBaseBuilder") +{ + // Default values + cmdline_parser_clitkRelativePositionDataBaseBuilder_init(&mArgsInfo); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionDataBaseBuilderGenericFilter:: +InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::RelativePositionDataBaseBuilderGenericFilter:: +SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionDataBaseBuilderGenericFilter:: +SetOptionsFromArgsInfoToFilter(FilterType * f) +{ + f->SetAFDBFilename(mArgsInfo.afdb_arg); + f->SetAFDBPath(mArgsInfo.afdb_path_arg); + f->SetNumberOfBins(mArgsInfo.bins_arg); + f->SetNumberOfAngles(mArgsInfo.nb_arg); + f->SetAreaLossTolerance(mArgsInfo.tol_arg); + f->SetSupportName(mArgsInfo.supportName_arg); + f->SetTargetName(mArgsInfo.targetName_arg); + for(int i=0; iAddObjectName(mArgsInfo.objectName_arg[i]); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionDataBaseBuilderGenericFilter:: +UpdateWithInputImageType() +{ + // Create filter + typedef clitk::RelativePositionDataBaseBuilderFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set global Options + SetOptionsFromArgsInfoToFilter(filter); + + // Go ! + filter->Update(); + + // Write/Save results + // typename ImageType::Pointer output = filter->GetOutput(); + //this->template SetNextOutput(output); + +} +//-------------------------------------------------------------------- + + -- 2.45.1