OTB  6.1.0
Orfeo Toolbox
otbLikelihoodPathListFilter.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbLikelihoodPathListFilter_txx
22 #define otbLikelihoodPathListFilter_txx
23 
26 #include "itkMetaDataObject.h"
27 
28 namespace otb
29 {
33 template <class TPath, class TImage>
36 {
37  m_Key = "Value";
38  this->SetNumberOfRequiredInputs(2);
39  this->SetNumberOfRequiredInputs(2);
40 }
41 template <class TPath, class TImage>
42 void
44 ::SetInputImage(const ImageType * image)
45 {
46  this->itk::ProcessObject::SetNthInput(1, const_cast<ImageType *>(image));
47 }
48 template <class TPath, class TImage>
50 ::ImageType *
53 {
54  if (this->GetNumberOfInputs() < 1)
55  {
56  return ITK_NULLPTR;
57  }
58  return static_cast<const ImageType *>(this->itk::ProcessObject::GetInput(1));
59 }
61 
62 template <class TPath, class TImage>
63 void
66 {
67  // I/O wiring
68  ImageConstPointerType inputImagePtr = this->GetInputImage();
69  const PathListType * inputPtr = this->GetInput();
70  PathListType * outputPtr = this->GetOutput();
71 
73 
74  for (IteratorType it = inputPtr->Begin(); it != inputPtr->End(); ++it)
75  {
76  PathPointerType path = it.Get();
77  ImageIteratorType imageIt(inputImagePtr, path);
78  double cumulatedValues = 0.0;
79  double nbPoints = 0.0;
80  for (imageIt.GoToBegin(); !imageIt.IsAtEnd(); ++imageIt, ++nbPoints)
81  {
82  cumulatedValues += static_cast<double>(imageIt.Get());
83  }
84  itk::MetaDataDictionary& dict = path->GetMetaDataDictionary();
85  itk::EncapsulateMetaData<double>(dict, m_Key, cumulatedValues / nbPoints);
86  outputPtr->PushBack(path);
87  }
88 }
92 template <class TPath, class TImage>
93 void
95 ::PrintSelf(std::ostream& os, itk::Indent indent) const
96 {
97  Superclass::PrintSelf(os, indent);
98 }
99 
100 } // End namespace otb
101 #endif
PathListType::ConstIterator IteratorType
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
Uses the bresenham algorithm to iterate over a polyline on an image (const version).
Affect a value to each path of the list based on the image.
DataObject * GetInput(const DataObjectIdentifierType &key)
void SetInputImage(const ImageType *image)
Superclass::InputListType PathListType
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
ImageType::ConstPointer ImageConstPointerType