Orfeo Toolbox  3.16
otbSOMClassifier.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 #ifndef __otbSOMClassifier_txx
19 #define __otbSOMClassifier_txx
20 
21 #include "otbSOMClassifier.h"
22 #include "otbMacro.h"
23 
24 namespace otb
25 {
29 template<class TSample, class TSOMMap, class TLabel>
32 {
33  this->SetNumberOfRequiredInputs(1);
34  SOMMapPointerType sommap = SOMMapType::New();
35  this->SetNthInput(0, sommap.GetPointer());
36  m_Sample = SampleType::New();
37  m_Output = OutputType::New();
38  this->SetNthOutput(0, sommap.GetPointer());
39 }
43 template<class TSample, class TSOMMap, class TLabel>
45 ::SOMMapType *
47 ::GetMap(void)
48 {
49  return dynamic_cast<SOMMapType *>(this->itk::ProcessObject::GetInput(0));
50 }
54 template<class TSample, class TSOMMap, class TLabel>
55 void
58 {
59  this->itk::ProcessObject::SetNthInput(0, const_cast<SOMMapType *>(sommap));
60 }
64 template<class TSample, class TSOMMap, class TLabel>
65 void
67 ::PrintSelf(std::ostream& os, itk::Indent indent) const
68 {
69  Superclass::PrintSelf(os, indent);
70 }
74 template<class TSample, class TSOMMap, class TLabel>
75 void
78 {
79  typename OutputType::Pointer outputPtr = this->GetOutput();
80  outputPtr->SetSample(this->GetSample());
81  outputPtr->Resize(this->GetSample()->Size());
82  typename SOMMapType::SizeType size = this->GetMap()->GetLargestPossibleRegion().GetSize();
83  unsigned int numberOfClasses = 1;
84  for (unsigned int i = 0; i < SOMMapType::ImageDimension; ++i)
85  {
86  numberOfClasses *= size[i];
87  }
88  outputPtr->SetNumberOfClasses(numberOfClasses);
89 
90  typename TSample::Iterator iter = this->GetSample()->Begin();
91  typename TSample::Iterator end = this->GetSample()->End();
92 
93  typename OutputType::ConstIterator iterO = outputPtr->Begin();
94  typename OutputType::ConstIterator endO = outputPtr->End();
95  typename TSample::MeasurementVectorType measurements;
96 
97  typename SOMMapType::IndexType index;
98 
99  SOMMapPointerType somMap = this->GetMap();
100 
101  otbMsgDebugMacro(<< "Starting iterations ");
102  while (iter != end && iterO != endO)
103  {
104 
105  measurements = iter.GetMeasurementVector();
106  index = somMap->GetWinner(measurements);
107  ClassLabelType classLabel = static_cast<ClassLabelType>((index[1] * size[1]) + index[0]);
108  outputPtr->AddInstance(classLabel, iterO.GetInstanceIdentifier());
109  ++iter;
110  ++iterO;
111  }
112 }
113 } // end of namespace otb
114 
115 #endif

Generated at Sun May 19 2013 00:49:44 for Orfeo Toolbox with doxygen 1.8.3.1