diff --git a/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..cfe1350e0abf49ebcb15f457efd0e5a35fe3ae3c --- /dev/null +++ b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h @@ -0,0 +1,82 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef _otbImageListToRCC8GraphFilter_h +#define _otbImageListToRCC8GraphFilter_h + +#include "otbRCC8GraphSource.h" + +namespace otb +{ +/** \class ImageListToRCC8GraphFilter + * \brief Base class for filters taking an images list as input to + * produce a RCC8 graph. + */ +template <class TInputImage, class TOutputGraph> +class ImageListToRCC8GraphFilter + : public RCC8GraphSource<TOutputGraph> +{ +public: + /** Standard typedefs */ + typedef ImageListToRCC8GraphFilter Self; + typedef RCC8GraphSource<TOutputGraph> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + /** Type macro */ + itkNewMacro(Self); + /** Creation through object factory macro */ + itkTypeMacro(ImageListToRCC8GraphFilter, RCC8GraphSource); + /** Template input parameters typedefs */ + typedef TInputImage InputImageType; + typedef typename InputImageType::ConstPointer InputImagePointer; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename InputImageType::PixelType InputImagePixelType; + typedef typename InputImageType::SizeType SizeType; + typedef typename InputImageType::ValueType ValueType; + typedef ImageList<InputImageType> InputImageListType; + typedef typename InputImageListType::Pointer InputImageListPointerType; + typedef typename InputImageListType::ConstPointer InputImageListConstPointer; + /** Template output parameters typedefs */ + typedef TOutputGraph OutputGraphType; + typedef typename Superclass::OutputGraphPointerType OutputGraphPointerType; + typedef typename OutputGraphType::VertexType VertexType; + typedef typename VertexType::Pointer VertexPointerType; + typedef typename OutputGraphType::RCC8ValueType RCC8ValueType; + /** InputImage dimension constant */ + itkStaticConstMacro(InputImageDimension, unsigned int,TInputImage::ImageDimension); + /** Overiding the SetInput() and GetInput() methods */ + virtual void SetInput( const InputImageListType * imageList); + virtual InputImageListType * GetInput(void); + +protected: + /** Constructor */ + ImageListToRCC8GraphFilter(); + /** Destructor */ + virtual ~ImageListToRCC8GraphFilter() {}; + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageListToRCC8GraphFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; +}// End namespace otb +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageListToRCC8GraphFilter.txx" +#endif + +#endif diff --git a/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..534e9da6362fa90eaaebe7f21c84bf7b24479807 --- /dev/null +++ b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx @@ -0,0 +1,76 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef _otbImageListToRCC8GraphFilter_txx +#define _otbImageListToRCC8GraphFilter_txx + +#include "otbImageListToRCC8GraphFilter.h" + +namespace otb +{ +/** + * Constructor + */ +template <class TInputImage, class TOutputGraph> +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::ImageListToRCC8GraphFilter() +{ + this->SetNumberOfRequiredInputs(1); +} +/** + * Input Connection + * \param image The input image. + */ +template <class TInputImage, class TOutputGraph> +void +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::SetInput(const InputImageListType *imageList) +{ + // A single input image + this->itk::ProcessObject::SetNthInput(0,const_cast<InputImageListType*>(imageList)); +} +/** + * Input image retrieval + * \return The input image. + */ +template <class TInputImage, class TOutputGraph> +typename ImageListToRCC8GraphFilter<TInputImage,TOutputGraph>::InputImageListType * +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::GetInput(void) +{ + // If there is no input + if (this->GetNumberOfInputs()<1) + { + // exit + return 0; + } + // else return the first input + return static_cast<InputImageListType * > + (this->itk::ProcessObject::GetInput(0) ); +} +/** + * PrintSelf Method + */ +template <class TInputImage, class TOutputGraph> +void +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} +} // End namespace otb +#endif diff --git a/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..d63618545ba5e7b187b26bb1503324a8363e3bfd --- /dev/null +++ b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h @@ -0,0 +1,84 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef _otbImageMultiSegmentationToRCC8GraphFilter_h +#define _otbImageMultiSegmentationToRCC8GraphFilter_h + +#include "otbImageListToRCC8GraphFilter.h" + +namespace otb +{ +/** + * \class ImageMultiSegmentationToRCC8GraphFilter + * \brief This class takes a list of labelled segmentation images + * and build the RCC8 graph of the set of regions it represents. + */ +template <class TInputImage, class TOutputGraph> +class ImageMultiSegmentationToRCC8GraphFilter + : public ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +{ +public: + /** Standard class typedefs. */ + typedef ImageMultiSegmentationToRCC8GraphFilter Self; + typedef ImageListToRCC8GraphFilter<TInputImage, TOutputGraph> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + /** Method for creation through the object factory. */ + itkNewMacro(Self); + /** Run-time type information (and related methods). */ + itkTypeMacro(ImageMultiSegmentationToRCC8GraphFilter,ImageListToRCC8GraphFilter); + /** Input related typedefs */ + typedef TInputImage InputImageType; + typedef typename InputImageType::Pointer InputImagePointerType; + /** Output related typedefs */ + typedef TOutputGraph OutputGraphType; + typedef typename OutputGraphType::Pointer OutputGraphPointerType; + typedef typename OutputGraphType::VertexType VertexType; + typedef typename VertexType::Pointer VertexPointerType; + +/* /// Get The statistics for the different relations */ +/* itkGetConstMacro(TotalNumberOfRegions,int); */ +/* itkGetConstMacro(NumberOfRelations,int); */ +/* /// Get the number of regions by segmentation image */ +/* std::vector<int> GetNumberOfRegions(void); */ +/* /// Set a filter to not take in account relations whose index is */ +/* /// under the threshold */ +/* itkGetConstMacro(RelationFilter,int); */ +/* itkSetMacro(RelationFilter,int); */ + +protected: + /** Constructor */ + ImageMultiSegmentationToRCC8GraphFilter(); + /** Destructor */ + ~ImageMultiSegmentationToRCC8GraphFilter(); + /** Main computation method */ + virtual void GenerateData(); + /** PrintSelf method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + /* int m_NumberOfRelations; */ +/* int m_TotalNumberOfRegions; */ +/* std::vector<unsigned int> m_NumberOfRegions; */ +}; +} // End namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageMultiSegmentationToRCC8GraphFilter.txx" +#endif + +#endif diff --git a/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..87901e3696f72d6c955489011ee55b936cf9a24c --- /dev/null +++ b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx @@ -0,0 +1,58 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef _otbImageMultiSegmentationToRCC8GraphFilter_txx +#define _otbImageMultiSegmentationToRCC8GraphFilter_txx + +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" +#include "itkMinimumMaximumImageFilter.h" +#include "otbImageToImageRCC8Calculator.h" + +namespace otb +{ +/** + * Constructor. + */ +template <class TInputImage, class TOutputGraph> +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::ImageMultiSegmentationToRCC8GraphFilter() +{} +/** + * Destructor. + */ +template <class TInputImage, class TOutputGraph> +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::~ImageMultiSegmentationToRCC8GraphFilter() +{} +/** + * Main computation method. + */ +template <class TInputImage, class TOutputGraph> +void +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::GenerateData() +{} +template <class TInputImage, class TOutputGraph> +void +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} +} // end namespace otb +#endif + diff --git a/Testing/Code/SpatialReasoning/CMakeLists.txt b/Testing/Code/SpatialReasoning/CMakeLists.txt index 73eee45636cfcbbdc36f0352d78be5da34d56885..d0a4738441befd05955d76e44d05450426881bd2 100644 --- a/Testing/Code/SpatialReasoning/CMakeLists.txt +++ b/Testing/Code/SpatialReasoning/CMakeLists.txt @@ -115,8 +115,31 @@ ADD_TEST(srTvRCC8GraphIOEndToEnd ${SPATIALREASONING_TESTS} # ------- otb::ImageListToRCC8GraphFilter -------------------------- -#ADD_TEST(srTuImageListToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} -# otbImageListToRCC8GraphFilterNew) + + +ADD_TEST(srTuImageListToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} + otbImageListToRCC8GraphFilterNew) + + +# ------- otb::ImageMultiSegmentationToRCC8GraphFilter -------------------------- + +ADD_TEST(srTuMultiSegToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} + otbImageMultiSegmentationToRCC8GraphFilterNew) + + +#ADD_TEST(srTvMultiSegToRCC8GraphFilter ${SPATIALREASONING_TESTS} +# --compare-ascii ${TOL} +# ${BASELINE_FILES}/srRCC8GraphFilterOutput.dot +# ${TEMP}/srRCC8GraphFilterOutput.dot +# otbImageMultiSegmentationToRCC8GraphFilter +# ${TEMP}/srRCC8GraphFilterOutput.dot +# 4 +# ${INPUTDATA}/ +# ${INPUTDATA}/ +# ${INPUTDATA}/ +# ${INPUTDATA}/ +#) + # ------- Fichiers sources CXX ----------------------------------- @@ -137,7 +160,9 @@ otbRCC8GraphFileWriter.cxx otbRCC8GraphFileReaderNew.cxx otbRCC8GraphFileReader.cxx otbRCC8GraphIOEndToEnd.cxx -#otbImageListTORCC8GraphFilterNew.cxx +otbImageListToRCC8GraphFilterNew.cxx +otbImageMultiSegmentationToRCC8GraphFilterNew.cxx +#otbImageMultiSegmentationToRCC8GraphFilter.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx index 886575dfed5b6fa77b56c4a666b93e1e1fc11aa8..f5ab0cadb9354ee0fe82fb0204f907c1424181dc 100644 --- a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx +++ b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx @@ -17,7 +17,9 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "itkExceptionObject.h" #include "otbRCC8Graph.h" +#include "otbImage.h" #include "otbRCC8VertexBase.h" +#include "otbImageListToRCC8GraphFilter.h" int otbImageListToRCC8GraphFilterNew(int argc, char* argv[]) { @@ -32,7 +34,8 @@ try ImageListToRCC8GraphFilterType; // Instanatiation - ImageListToRCC8GraphFilterType::Pointer filter = ImageListToRCC8GraphFilter::New(); + ImageListToRCC8GraphFilterType::Pointer filter = ImageListToRCC8GraphFilterType::New(); + } catch( itk::ExceptionObject & err ) { @@ -47,27 +50,3 @@ catch( ... ) } return EXIT_SUCCESS; } - - - - - - - - - - - - - - - - - - - - - - - -} diff --git a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..13309620460bfd17c11dd9b98a5a5a5d32ae9b15 --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx @@ -0,0 +1,80 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbRCC8Graph.h" +#include "otbImage.h" +#include "otbImageList.h" +#include "otbRCC8VertexBase.h" +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" +#include "otbImageFileReader.h" +#include "otbRCC8GraphFileWriter.h" + +int otbImageMultiSegmentationToRCC8GraphFilter(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + char * outputFilename = argv[1]; + unsigned int nbImages = atoi(argv[2]); + + // typedefs + typedef unsigned short LabelPixelType; + typedef otb::Image<LabelPixelType,Dimension> LabelImageType; + typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8Graph<VertexType> RCC8GraphType; + typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> + RCC8GraphFilterType; + typedef otb::ImageList<LabelImageType> ImageListType; + typedef otb::ImageFileReader<LabelImageType> ReaderType; + typedef otb::RCC8GraphFileWriter<RCC8GraphType> GraphWriterType; + + ImageListType::Pointer inputList = ImageListType::New(); + + // Reading input images + for(int i=3;i<nbImages+2;i++) + { + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFilename(argv[i]); + reader->Update(); + inputList->PushBack(reader->GetOutput()); + } + + // Instanatiation + RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New(); + filter->SetInput(inputList); + + // Writing output graph + GraphWriterType::Pointer writer = GraphWriterType::New(); + writer->SetFilename(outputFilename); + writer->SetInput(filter->GetOutput()); + writer->Update(); + + } +catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } +catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..215c2bcfd026b13fcbaed58238162ce3f99294c0 --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx @@ -0,0 +1,52 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include "otbRCC8Graph.h" +#include "otbImage.h" +#include "otbRCC8VertexBase.h" +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" + +int otbImageMultiSegmentationToRCC8GraphFilterNew(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + typedef unsigned short LabelPixelType; + typedef otb::Image<LabelPixelType,Dimension> LabelImageType; + typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8Graph<VertexType> RCC8GraphType; + typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> + RCC8GraphFilterType; + + // Instanatiation + RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New(); + + } +catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } +catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx index 4b950487ddb97ec5b8160104302225324a366998..12975ab849432d6cfaad305da1b22f07db88190f 100644 --- a/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx +++ b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx @@ -42,5 +42,7 @@ REGISTER_TEST(otbRCC8GraphFileWriter); REGISTER_TEST(otbRCC8GraphFileReaderNew); REGISTER_TEST(otbRCC8GraphFileReader); REGISTER_TEST(otbRCC8GraphIOEndToEnd); -//REGISTER_TEST(otbImageListToRCC8GraphFilterNew); +REGISTER_TEST(otbImageListToRCC8GraphFilterNew); +REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilterNew); +//REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilter); }