This file is indexed.

/usr/include/OTB-6.4/otbMachineLearningModelFactory.txx is in libotb-dev 6.4.0+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef otbMachineLearningModelFactory_txx
#define otbMachineLearningModelFactory_txx

#include "otbMachineLearningModelFactory.h"
#include "otbConfigure.h"

#ifdef OTB_USE_OPENCV
#include "otb_opencv_api.h"
#include "otbKNearestNeighborsMachineLearningModelFactory.h"
#include "otbRandomForestsMachineLearningModelFactory.h"
#include "otbSVMMachineLearningModelFactory.h"
#include "otbBoostMachineLearningModelFactory.h"
#include "otbNeuralNetworkMachineLearningModelFactory.h"
#include "otbNormalBayesMachineLearningModelFactory.h"
#include "otbDecisionTreeMachineLearningModelFactory.h"
#ifndef OTB_OPENCV_3
#include "otbGradientBoostedTreeMachineLearningModelFactory.h"
#endif
#endif
#ifdef OTB_USE_LIBSVM
#include "otbLibSVMMachineLearningModelFactory.h"
#endif

#ifdef OTB_USE_SHARK
#include "otbSharkRandomForestsMachineLearningModelFactory.h"
#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_LIBSVM
  RegisterFactory(LibSVMMachineLearningModelFactory<TInputValue,TOutputValue>::New());
#endif

#ifdef OTB_USE_SHARK
  RegisterFactory(SharkRandomForestsMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(SharkKMeansMachineLearningModelFactory<TInputValue,TOutputValue>::New());
#endif
  
#ifdef OTB_USE_OPENCV
  RegisterFactory(RandomForestsMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(SVMMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(BoostMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(NeuralNetworkMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(NormalBayesMachineLearningModelFactory<TInputValue,TOutputValue>::New());
  RegisterFactory(DecisionTreeMachineLearningModelFactory<TInputValue,TOutputValue>::New());
#ifndef OTB_OPENCV_3
  RegisterFactory(GradientBoostedTreeMachineLearningModelFactory<TInputValue,TOutputValue>::New());
#endif
  RegisterFactory(KNearestNeighborsMachineLearningModelFactory<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_LIBSVM
    LibSVMMachineLearningModelFactory<TInputValue,TOutputValue> *libsvmFactory =
      dynamic_cast<LibSVMMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (libsvmFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(libsvmFactory);
      continue;
      }
#endif

#ifdef OTB_USE_SHARK
    SharkRandomForestsMachineLearningModelFactory<TInputValue,TOutputValue> *sharkRFFactory =
      dynamic_cast<SharkRandomForestsMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (sharkRFFactory)
      {
      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
    // RandomForest
    RandomForestsMachineLearningModelFactory<TInputValue,TOutputValue> *rfFactory =
      dynamic_cast<RandomForestsMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (rfFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(rfFactory);
      continue;
      }
    // SVM
    SVMMachineLearningModelFactory<TInputValue,TOutputValue> *svmFactory =
      dynamic_cast<SVMMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (svmFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(svmFactory);
      continue;
      }
    // Boost
    BoostMachineLearningModelFactory<TInputValue,TOutputValue> *boostFactory =
      dynamic_cast<BoostMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (boostFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(boostFactory);
      continue;
      }
    // ANN
    NeuralNetworkMachineLearningModelFactory<TInputValue,TOutputValue> *annFactory =
      dynamic_cast<NeuralNetworkMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (annFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(annFactory);
      continue;
      }
    // Bayes
    NormalBayesMachineLearningModelFactory<TInputValue,TOutputValue> *bayesFactory =
      dynamic_cast<NormalBayesMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (bayesFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(bayesFactory);
      continue;
      }
    // Decision Tree
    DecisionTreeMachineLearningModelFactory<TInputValue,TOutputValue> *dtFactory =
      dynamic_cast<DecisionTreeMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (dtFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(dtFactory);
      continue;
      }
#ifndef OTB_OPENCV_3
    // Gradient Boosted tree
    GradientBoostedTreeMachineLearningModelFactory<TInputValue,TOutputValue> *gbtFactory =
      dynamic_cast<GradientBoostedTreeMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (gbtFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(gbtFactory);
      continue;
      }
#endif
    // KNN
    KNearestNeighborsMachineLearningModelFactory<TInputValue,TOutputValue> *knnFactory =
      dynamic_cast<KNearestNeighborsMachineLearningModelFactory<TInputValue,TOutputValue> *>(*itFac);
    if (knnFactory)
      {
      itk::ObjectFactoryBase::UnRegisterFactory(knnFactory);
      continue;
      }
#endif   
    }

}

} // end namespace otb

#endif