OTB  9.0.0
Orfeo Toolbox
otbSOMbasedImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbSOMbasedImageFilter_hxx
23 #define otbSOMbasedImageFilter_hxx
24 
25 #include "otbSOMbasedImageFilter.h"
26 
27 namespace otb
28 {
29 
30 namespace Functor
31 {
32 
33 template <class TInput, class TOutput, class TDistanceMetric, class TMap>
35 {
36  return static_cast<TOutput>(GetMap()->GetPixel(this->GetWinner(input)));
37 }
38 
39 template <class TInput, class TOutput, class TDistanceMetric, class TMap>
41 {
42  m_Map = const_cast<MapType*>(theMap);
43  m_Distance = DistanceType::New();
44 }
45 
46 template <class TInput, class TOutput, class TDistanceMetric, class TMap>
49 {
50  typedef itk::ImageRegionIteratorWithIndex<MapType> IteratorType;
51  IteratorType it(GetMap(), GetMap()->GetLargestPossibleRegion());
52  it.GoToBegin();
53 
54  IndexType minPos = it.GetIndex();
55 
56  double tempDistance, minDistance = GetDistance()->Evaluate(sample, it.Get());
57  ++it;
58 
59  while (!it.IsAtEnd())
60  {
61  tempDistance = GetDistance()->Evaluate(sample, it.Get());
62 
63  if (tempDistance < minDistance)
64  {
65  minDistance = tempDistance;
66  minPos = it.GetIndex();
67  }
68 
69  ++it;
70  }
71 
72  return minPos;
73 }
74 
75 } // end of namespace Functor
76 
77 /*
78  * Implementation of the class SOMbasedImageFilter
79  */
80 template <class TInputImage, class TOutputImage, class TDistanceMetric, class TMap>
82 {
83  this->SetNumberOfRequiredInputs(1);
84  this->InPlaceOff();
85 }
86 
87 template <class TInputImage, class TOutputImage, class TDistanceMetric, class TMap>
89 {
90  m_Map = const_cast<MapType*>(theMap);
91  this->Modified();
92 }
93 
94 template <class TInputImage, class TOutputImage, class TDistanceMetric, class TMap>
96 {
97  m_Map->Update();
98  this->GetFunctor().SetMap(m_Map);
99 }
100 
101 } // end of namespace otb
102 
103 #endif
otb::Functor::SOMbasedImageFilterFunctor::MapType
TMap MapType
Definition: otbSOMbasedImageFilter.h:49
otb::SOMbasedImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbSOMbasedImageFilter.hxx:95
otb::SOMbasedImageFilter::SOMbasedImageFilter
SOMbasedImageFilter()
Definition: otbSOMbasedImageFilter.hxx:81
otb::Functor::SOMbasedImageFilterFunctor::operator()
TOutput operator()(const TInput &input)
Definition: otbSOMbasedImageFilter.hxx:34
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::SOMbasedImageFilterFunctor::SetMap
void SetMap(const MapType *theMap)
Definition: otbSOMbasedImageFilter.hxx:40
otbSOMbasedImageFilter.h
otb::SOMbasedImageFilter::SetMap
void SetMap(const MapType *theMap)
Definition: otbSOMbasedImageFilter.hxx:88
otb::Functor::SOMbasedImageFilterFunctor::GetWinner
IndexType GetWinner(const NeuronType &sample)
Definition: otbSOMbasedImageFilter.hxx:48
otb::Functor::SOMbasedImageFilterFunctor::IndexType
MapType::IndexType IndexType
Definition: otbSOMbasedImageFilter.h:51
otb::Functor::SOMbasedImageFilterFunctor::NeuronType
MapType::PixelType NeuronType
Definition: otbSOMbasedImageFilter.h:52
otb::SOMbasedImageFilter::MapType
TMap MapType
Definition: otbSOMbasedImageFilter.h:141