Orfeo Toolbox  3.16
otbSVMSampleListModelEstimator.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 #ifndef __otbSVMSampleListModelEstimator_txx
20 #define __otbSVMSampleListModelEstimator_txx
21 
23 #include "itkCommand.h"
24 #include "otbMacro.h"
25 
26 namespace otb
27 {
28 template<class TInputSampleList,
29  class TTrainingSampleList, class TMeasurementFunctor>
31 ::SVMSampleListModelEstimator(void) : SVMModelEstimator<typename TInputSampleList::MeasurementType,
32  typename TTrainingSampleList::MeasurementType>()
33 {}
34 
35 template<class TInputSampleList,
36  class TTrainingSampleList, class TMeasurementFunctor>
39 {}
40 
41 /*
42  * PrintSelf
43  */
44 template<class TInputSampleList,
45  class TTrainingSampleList, class TMeasurementFunctor>
46 void
48 ::PrintSelf(std::ostream& os, itk::Indent indent) const
49 {
50  Superclass::PrintSelf(os, indent);
51 } // end PrintSelf
52 
56 template<class TInputSampleList,
57  class TTrainingSampleList, class TMeasurementFunctor>
58 void
61 {
62  //Do some error checking
63  InputSampleListPointer inputSampleList = this->GetInputSampleList();
64  TrainingSampleListPointer trainingSampleList = this->GetTrainingSampleList();
65  typename Superclass::ModelType * model = this->GetModel();
66 
67  int inputSampleListSize = inputSampleList->Size();
68  int trainingSampleListSize = trainingSampleList->Size();
69 
70  // Check if size of the two inputs are same
71  if (inputSampleListSize != trainingSampleListSize)
72  {
73  /*throw itk::ExceptionObject(
74  __FILE__,
75  __LINE__,
76  "Input pointset size is not the same as the training pointset size.",
77  ITK_LOCATION); */
78  itkExceptionMacro(<< "Input pointset size is not the same as the training pointset size ("
79  << inputSampleListSize << " vs "<< trainingSampleListSize << ").");
80  }
81 
82  // Declaration of the iterators on the input and training images
83  InputSampleListIteratorType inIt = inputSampleList->Begin();
84  TrainingSampleListIteratorType trIt = trainingSampleList->Begin();
85 
86  InputSampleListIteratorType inEnd = inputSampleList->End();
87  TrainingSampleListIteratorType trEnd = trainingSampleList->End();
88 
89  // Clear previous samples
90  model->ClearSamples();
91 
92  otbMsgDebugMacro(<< " Input nb points " << inputSampleListSize);
93  otbMsgDebugMacro(<< " Training nb points " << trainingSampleListSize);
94 
95  MeasurementFunctorType mfunctor;
96  while (inIt != inEnd && trIt != trEnd)
97  {
98  typename TTrainingSampleList::MeasurementType label =
99  trIt.GetMeasurementVector()[0];
100  typename TInputSampleList::MeasurementVectorType value =
101  inIt.GetMeasurementVector();
102  model->AddSample(mfunctor(value), label);
103  ++inIt;
104  ++trIt;
105  }
106 }
107 } //End namespace OTB
108 #endif

Generated at Sun Feb 3 2013 00:51:23 for Orfeo Toolbox with doxygen 1.8.1.1