21 #ifndef otbMachineLearningModelFactory_hxx
22 #define otbMachineLearningModelFactory_hxx
25 #include "otbConfigure.h"
28 #include "otb_opencv_api.h"
46 #include "itkMutexLockHolder.h"
51 template <
class TInputValue,
class TOutputValue>
55 RegisterBuiltInFactories();
57 std::list<MachineLearningModelTypePointer> possibleMachineLearningModel;
58 std::list<LightObject::Pointer> allobjects = itk::ObjectFactoryBase::CreateAllInstance(
"otbMachineLearningModel");
59 for (std::list<LightObject::Pointer>::iterator i = allobjects.begin(); i != allobjects.end(); ++i)
64 possibleMachineLearningModel.push_back(io);
68 std::cerr <<
"Error MachineLearningModel Factory did not return an MachineLearningModel: " << (*i)->GetNameOfClass() << std::endl;
71 for (
typename std::list<MachineLearningModelTypePointer>::iterator k = possibleMachineLearningModel.begin(); k != possibleMachineLearningModel.end(); ++k)
75 if ((*k)->CanReadFile(path))
80 else if (mode == WriteMode)
82 if ((*k)->CanWriteFile(path))
91 template <
class TInputValue,
class TOutputValue>
94 itk::MutexLockHolder<itk::SimpleMutexLock> lockHolder(mutex);
105 #ifdef OTB_USE_OPENCV
116 template <
class TInputValue,
class TOutputValue>
122 itk::ObjectFactoryBase::UnRegisterFactory(factory);
123 itk::ObjectFactoryBase::RegisterFactory(factory);
126 template <
class TInputValue,
class TOutputValue>
129 itk::MutexLockHolder<itk::SimpleMutexLock> lockHolder(mutex);
131 std::list<itk::ObjectFactoryBase*> factories = itk::ObjectFactoryBase::GetRegisteredFactories();
132 std::list<itk::ObjectFactoryBase*>::iterator itFac;
134 for (itFac = factories.begin(); itFac != factories.end(); ++itFac)
136 #ifdef OTB_USE_LIBSVM
141 itk::ObjectFactoryBase::UnRegisterFactory(libsvmFactory);
151 itk::ObjectFactoryBase::UnRegisterFactory(sharkRFFactory);
157 if (sharkKMeansFactory)
159 itk::ObjectFactoryBase::UnRegisterFactory(sharkKMeansFactory);
164 #ifdef OTB_USE_OPENCV
170 itk::ObjectFactoryBase::UnRegisterFactory(rfFactory);
177 itk::ObjectFactoryBase::UnRegisterFactory(svmFactory);
185 itk::ObjectFactoryBase::UnRegisterFactory(boostFactory);
193 itk::ObjectFactoryBase::UnRegisterFactory(annFactory);
201 itk::ObjectFactoryBase::UnRegisterFactory(bayesFactory);
209 itk::ObjectFactoryBase::UnRegisterFactory(dtFactory);
217 itk::ObjectFactoryBase::UnRegisterFactory(knnFactory);