otbUnaryFunctorObjectListFilter.h 3.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


13
14
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
16
17
18
19
20
21
22
23
24
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbUnaryFunctorObjectListFilter_h
#define __otbUnaryFunctorObjectListFilter_h

#include "otbObjectListToObjectListFilter.h"

namespace otb
{
25

26
27
28
/** \class UnaryFunctorObjectListFilter
  * \brief Process each element in the ObjectList with the functor
  *
29
  * Each element of the ObjectList is processed by the functor.
30
31
32
33
34
35
  * This is similar to the python map() function.
  *
  *
  * \ingroup ObjectListFilter
 */
template <class TInputList, class TOutputList, class TFunction >
36
37
class ITK_EXPORT UnaryFunctorObjectListFilter :
    public otb::ObjectListToObjectListFilter<TInputList,TOutputList>
38
39
40
{
public:
  /** Standard class typedefs. */
41
  typedef UnaryFunctorObjectListFilter                               Self;
42
  typedef otb::ObjectListToObjectListFilter<TInputList,TOutputList>  Superclass;
43
44
  typedef itk::SmartPointer<Self>                                    Pointer;
  typedef itk::SmartPointer<const Self>                              ConstPointer;
45
46
47

  /** Method for creation through the object factory. */
  itkNewMacro(Self);
48

49
  /** Run-time type information (and related methods). */
50
  itkTypeMacro(UnaryFunctorObjectListFilter, ObjectListToObjectListFilter);
51
52

  /** Some typedefs. */
53
54
55
56
57
58
  typedef TFunction                           FunctorType;
  typedef TInputList                          InputListType;
  typedef TOutputList                         OutputListType;
  typedef typename TInputList::ConstPointer   InputListPointer;
  typedef typename TOutputList::Pointer       OutputListPointer;
  typedef typename TInputList::ConstIterator  InputListIterator;
59
60
  typedef typename TOutputList::ConstIterator OutputListIterator;

61
62
63
64
65

  /** Get the functor object.  The functor is returned by reference.
   * (Functors do not have to derive from itk::LightObject, so they do
   * not necessarily have a reference count. So we cannot return a
   * SmartPointer.) */
66
67
68
  FunctorType& GetFunctor()
  {
    return m_Functor;
69
70
  }

71
72
73
  const FunctorType& GetFunctor() const
  {
    return m_Functor;
74
  }
75
76
77
78
79
80
81
82
83
84

  /** Set the functor object.  This replaces the current Functor with a
   * copy of the specified Functor. This allows the user to specify a
   * functor that has ivars set differently than the default functor.
   * This method requires an operator!=() be defined on the functor
   * (or the compiler's default implementation of operator!=() being
   * appropriate). */
  void SetFunctor(const FunctorType& functor)
  {
    if (m_Functor != functor)
85
    {
86
87
      m_Functor = functor;
      this->Modified();
88
    }
89
  }
90
91


92
93
94
95
protected:
  UnaryFunctorObjectListFilter();
  virtual ~UnaryFunctorObjectListFilter() {};

96
97
98
99
100
101
102
  /** Multi-threading implementation */


  virtual void AfterThreadedGenerateData();

  /** startIndex and stopIndex represent the indices of the Objects to
  examine in thread threadId */
103
  virtual void ThreadedGenerateData(unsigned int startIndex, unsigned int stopIndex, int threadId);
104
105
106
107


  /** End Multi-threading implementation */

108
109
110
111
112
private:
  UnaryFunctorObjectListFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

  FunctorType m_Functor;
113

114
115
116
117
118
119
120
121
122
};

} // end namespace otb

#ifndef ITK_MANUAL_INSTANTIATION
#include "otbUnaryFunctorObjectListFilter.txx"
#endif

#endif