Orfeo Toolbox  3.16
otbParserConditionDataNodeFeatureFunction.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 __otbParserConditionDataNodeFeatureFunction_txx
19 #define __otbParserConditionDataNodeFeatureFunction_txx
20 
22 
23 namespace otb
24 {
25 
29 template <class TImage, class TCoordRep, class TPrecision>
32 {
33  m_ParserConditionFunctor = ParserConditionFunctorType::New();
34 }
35 
39 template <class TImage, class TCoordRep, class TPrecision>
40 void
42 ::PrintSelf( std::ostream& os, itk::Indent indent) const
43 {
44  Superclass::PrintSelf( os, indent );
45  //os << indent << "ParserCondition : " << m_ParserConditionFunctor << std::endl;
46 }
47 
48 template <class TImage, class TCoordRep, class TPrecision>
50 ::OutputType
52 ::Evaluate( const DataNodeType& node ) const
53 {
54  // The parser evaluation can't be const since the parser state
55  // changes at the first evaluation, but in fact we don't modify
56  // anything here.
57  // To fit with the rest of the framework, we try to keep the Evaluate
58  // function const
59  Self* _this = const_cast<Self*>(this);
61  // Ugly things over
62 
63 
64  const typename ImageLineIteratorType::PathType* path;
65 
66  switch (node.GetNodeType())
67  {
68  case FEATURE_POINT:
69  {
70  itkExceptionMacro(<< "This DataNode type is not handle yet");
71  break;
72  }
73  case FEATURE_LINE:
74  {
75  path = node.GetLine();
76  break;
77  }
78  case FEATURE_POLYGON:
79  {
80  path = node.GetPolygonExteriorRing();
81  break;
82  }
83  default:
84  {
85  itkExceptionMacro(<< "This DataNode type is not handle yet");
86  break;
87  }
88  }
89 
90  ImageLineIteratorType lineIt(this->GetInputImage(), path);
91  lineIt.GoToBegin();
92 
93  double nbValidPixel = 0.;
94  double nbVisitedPixel = 0.;
95 
96  while(!lineIt.IsAtEnd())
97  {
98  if(this->IsInsideBuffer(lineIt.GetIndex()))
99  {
100  if( parser(this->GetInputImage()->GetPixel(lineIt.GetIndex())) )
101  {
102  nbValidPixel += 1;
103  }
104  nbVisitedPixel += 1;
105  }
106  ++lineIt;
107  }
108 
109  OutputType output;
110  if(nbVisitedPixel == 0)
111  {
112  output.push_back(static_cast<PrecisionType>(0.));
113  }
114  else
115  {
116  output.push_back(static_cast<PrecisionType>(nbValidPixel/nbVisitedPixel));
117  }
118 
119  output.push_back(static_cast<PrecisionType>(nbValidPixel));
120  output.push_back(static_cast<PrecisionType>(nbVisitedPixel));
121  return output;
122 }
123 
124 } // end namespace otb
125 
126 #endif

Generated at Sun May 19 2013 00:43:10 for Orfeo Toolbox with doxygen 1.8.3.1