diff --git a/Modules/Learning/LearningBase/include/otbMachineLearningModelFactoryBase.h b/Modules/Learning/LearningBase/include/otbMachineLearningModelFactoryBase.h index 6ac9b2728f4cb8726214b8523ce9cbec93af91f8..81f771ac5304e7eb58f8f4cc33c49f40f7a550ed 100644 --- a/Modules/Learning/LearningBase/include/otbMachineLearningModelFactoryBase.h +++ b/Modules/Learning/LearningBase/include/otbMachineLearningModelFactoryBase.h @@ -30,7 +30,6 @@ namespace otb * part of a template class (ld error). * * - * \ingroup OTBSupervised */ class OTBSupervised_EXPORT MachineLearningModelFactoryBase : public itk::Object { diff --git a/Modules/Learning/Supervised/include/otbSharkUtils.h b/Modules/Learning/LearningBase/include/otbSharkUtils.h similarity index 100% rename from Modules/Learning/Supervised/include/otbSharkUtils.h rename to Modules/Learning/LearningBase/include/otbSharkUtils.h diff --git a/Modules/Learning/LearningBase/otb-module.cmake b/Modules/Learning/LearningBase/otb-module.cmake index 49350ed383ee17f9281016e09c64ec419ad60b9d..78f6c010994a94ab2c80baf3c477a10c7cb166b6 100644 --- a/Modules/Learning/LearningBase/otb-module.cmake +++ b/Modules/Learning/LearningBase/otb-module.cmake @@ -6,6 +6,9 @@ otb_module(OTBLearningBase OTBCommon OTBITK + OPTIONAL_DEPENDS + OTBShark + TEST_DEPENDS OTBTestKernel OTBImageIO diff --git a/Modules/Learning/Supervised/include/otbMachineLearningModelFactory.txx b/Modules/Learning/Supervised/include/otbMachineLearningModelFactory.txx index a99aa0f78e4d86f128b855299bfd4eacb340948b..5e72ce37dbca81c67ad1d33ae72baff2a86436d9 100644 --- a/Modules/Learning/Supervised/include/otbMachineLearningModelFactory.txx +++ b/Modules/Learning/Supervised/include/otbMachineLearningModelFactory.txx @@ -37,6 +37,7 @@ #ifdef OTB_USE_SHARK #include "otbSharkRandomForestsMachineLearningModelFactory.h" +#include "otbSharkKMeansMachineLearningModelFactory.h" #endif #include "itkMutexLockHolder.h" @@ -104,6 +105,7 @@ MachineLearningModelFactory<TInputValue,TOutputValue> #ifdef OTB_USE_SHARK RegisterFactory(SharkRandomForestsMachineLearningModelFactory<TInputValue,TOutputValue>::New()); + RegisterFactory(SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue>::New()); #endif #ifdef OTB_USE_OPENCV @@ -160,6 +162,14 @@ MachineLearningModelFactory<TInputValue,TOutputValue> itk::ObjectFactoryBase::UnRegisterFactory(sharkRFFactory); continue; } + + SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue> *sharkKMeansFactory = + dynamic_cast<SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac); + if (sharkKMeansFactory) + { + itk::ObjectFactoryBase::UnRegisterFactory(sharkKMeansFactory); + continue; + } #endif #ifdef OTB_USE_OPENCV diff --git a/Modules/Learning/Supervised/otb-module.cmake b/Modules/Learning/Supervised/otb-module.cmake index b46c75f574f8b9bb68eabb14e3a704af1e5b8df5..34aa00494ee10a8f55258cce5f01bec786cbf551 100644 --- a/Modules/Learning/Supervised/otb-module.cmake +++ b/Modules/Learning/Supervised/otb-module.cmake @@ -10,6 +10,7 @@ ENABLE_SHARED OTBITK OTBImageBase OTBLearningBase + OTBUnsupervised OPTIONAL_DEPENDS OTBOpenCV @@ -22,6 +23,7 @@ ENABLE_SHARED OTBImageBase OTBLearningBase OTBBoost + OTBUnsupervised DESCRIPTION "${DOCUMENTATION}" diff --git a/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.h b/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.h deleted file mode 100644 index 62b0c6add6797f1be9854f7a8157ff82f1d50ce8..0000000000000000000000000000000000000000 --- a/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.h +++ /dev/null @@ -1,81 +0,0 @@ -/*========================================================================= - - 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 otbMachineLearningClusteringModelFactory_h -#define otbMachineLearningClusteringModelFactory_h - -#include "otbMachineLearningModel.h" -#include "otbMachineLearningModelFactoryBase.h" - -namespace otb -{ -/** \class MachineLearningModelFactory - * \brief Creation of object instance using object factory. - * - * \ingroup OTBUnsupervised - */ -template <class TInputValue, class TOutputValue> -class MachineLearningModelFactory : public MachineLearningModelFactoryBase -{ -public: - /** Standard class typedefs. */ - typedef MachineLearningModelFactory Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Class Methods used to interface with the registered factories */ - - /** Run-time type information (and related methods). */ - itkTypeMacro(MachineLearningModelFactory, itk::Object); - - /** Convenient typedefs. */ - typedef otb::MachineLearningModel<TInputValue,TOutputValue> MachineLearningModelType; - typedef typename MachineLearningModelType::Pointer MachineLearningModelTypePointer; - - /** Mode in which the files is intended to be used */ - typedef enum { ReadMode, WriteMode } FileModeType; - - /** Create the appropriate MachineLearningModel depending on the particulars of the file. */ - static MachineLearningModelTypePointer CreateMachineLearningModel(const std::string& path, FileModeType mode); - - static void CleanFactories(); - -protected: - MachineLearningModelFactory(); - ~MachineLearningModelFactory() ITK_OVERRIDE; - -private: - MachineLearningModelFactory(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented - - /** Register Built-in factories */ - static void RegisterBuiltInFactories(); - - /** Register a single factory, ensuring it has not been registered - * twice */ - static void RegisterFactory(itk::ObjectFactoryBase * factory); - -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbMachineLearningClusteringModelFactory.txx" -#endif - -#endif //otbMachineLearningClusteringModelFactory_h diff --git a/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.txx b/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.txx deleted file mode 100644 index 9e06486f78376dda92a1cf64afa9992fb3c7e6e5..0000000000000000000000000000000000000000 --- a/Modules/Learning/Unsupervised/include/otbMachineLearningClusteringModelFactory.txx +++ /dev/null @@ -1,134 +0,0 @@ -/*========================================================================= - - 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 otbMachineLearningModelFactory_txx -#define otbMachineLearningModelFactory_txx - -#include "otbMachineLearningClusteringModelFactory.h" -#include "otbConfigure.h" - -#ifdef OTB_USE_SHARK -#include "otbSharkKMeansMachineLearningModelFactory.h" -#endif - -#include "itkMutexLockHolder.h" - - -namespace otb -{ -template <class TInputValue, class TOutputValue> -typename MachineLearningModel<TInputValue,TOutputValue>::Pointer -MachineLearningModelFactory<TInputValue,TOutputValue> -::CreateMachineLearningModel(const std::string& path, FileModeType mode) -{ - RegisterBuiltInFactories(); - - std::list<MachineLearningModelTypePointer> possibleMachineLearningModel; - std::list<LightObject::Pointer> allobjects = - itk::ObjectFactoryBase::CreateAllInstance("otbMachineLearningModel"); - for(std::list<LightObject::Pointer>::iterator i = allobjects.begin(); - i != allobjects.end(); ++i) - { - MachineLearningModel<TInputValue,TOutputValue> * io = dynamic_cast<MachineLearningModel<TInputValue,TOutputValue>*>(i->GetPointer()); - if(io) - { - possibleMachineLearningModel.push_back(io); - } - else - { - std::cerr << "Error MachineLearningModel Factory did not return an MachineLearningModel: " - << (*i)->GetNameOfClass() - << std::endl; - } - } - for(typename std::list<MachineLearningModelTypePointer>::iterator k = possibleMachineLearningModel.begin(); - k != possibleMachineLearningModel.end(); ++k) - { - if( mode == ReadMode ) - { - if((*k)->CanReadFile(path)) - { - return *k; - } - } - else if( mode == WriteMode ) - { - if((*k)->CanWriteFile(path)) - { - return *k; - } - - } - } - return ITK_NULLPTR; -} - -template <class TInputValue, class TOutputValue> -void -MachineLearningModelFactory<TInputValue,TOutputValue> -::RegisterBuiltInFactories() -{ - itk::MutexLockHolder<itk::SimpleMutexLock> lockHolder(mutex); - -#ifdef OTB_USE_SHARK - RegisterFactory(SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue>::New()); -#endif - -} - -template <class TInputValue, class TOutputValue> -void -MachineLearningModelFactory<TInputValue,TOutputValue> -::RegisterFactory(itk::ObjectFactoryBase * factory) -{ - // Unregister any previously registered factory of the same class - // Might be more intensive but static bool is not an option due to - // ld error. - itk::ObjectFactoryBase::UnRegisterFactory(factory); - itk::ObjectFactoryBase::RegisterFactory(factory); -} - -template <class TInputValue, class TOutputValue> -void -MachineLearningModelFactory<TInputValue,TOutputValue> -::CleanFactories() -{ - itk::MutexLockHolder<itk::SimpleMutexLock> lockHolder(mutex); - - std::list<itk::ObjectFactoryBase*> factories = itk::ObjectFactoryBase::GetRegisteredFactories(); - std::list<itk::ObjectFactoryBase*>::iterator itFac; - - for (itFac = factories.begin(); itFac != factories.end() ; ++itFac) - { - -#ifdef OTB_USE_SHARK - SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue> *sharkKMeansFactory = - dynamic_cast<SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac); - if (sharkKMeansFactory) - { - itk::ObjectFactoryBase::UnRegisterFactory(sharkKMeansFactory); - continue; - } -#endif - - } - -} - -} // end namespace otb - -#endif diff --git a/Modules/Learning/Unsupervised/otb-module.cmake b/Modules/Learning/Unsupervised/otb-module.cmake index d849a226116fc612935e97002430f69e3b263028..5f8789e0084b14b2ad562e79f9a6f5fd9152e869 100644 --- a/Modules/Learning/Unsupervised/otb-module.cmake +++ b/Modules/Learning/Unsupervised/otb-module.cmake @@ -7,7 +7,6 @@ otb_module(OTBUnsupervised OTBITK OTBImageBase OTBLearningBase - OTBSupervised OPTIONAL_DEPENDS OTBShark @@ -17,7 +16,6 @@ otb_module(OTBUnsupervised OTBImageIO OTBImageBase OTBLearningBase - OTBSupervised DESCRIPTION "${DOCUMENTATION}"