OTB  10.0.0
Orfeo Toolbox
otbThresholdImageToPointSetFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 
22 #ifndef otbThresholdImageToPointSetFilter_hxx
23 #define otbThresholdImageToPointSetFilter_hxx
24 
26 #include "itkImageRegionConstIterator.h"
27 
28 namespace otb
29 {
30 
31 template <class TInputImage, class TOutputPointSet>
33 {
34  m_LowerThreshold = itk::NumericTraits<InputPixelType>::NonpositiveMin();
35  m_UpperThreshold = itk::NumericTraits<InputPixelType>::max();
36 }
37 
38 template <class TInputImage, class TOutputPointSet>
40  itk::ThreadIdType threadId)
41 {
42  this->m_PointsContainerPerThread[threadId] = PointsContainerType::New();
43  this->m_PointDataContainerPerThread[threadId] = PointDataContainerType::New();
44  InputImageConstPointer inputPtr = this->GetInput();
45 
46  // Define the iterators
47  itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
48 
49  itk::ProgressReporter progress(this, threadId, inputRegionForThread.GetNumberOfPixels());
50 
51  typename OutputPointSetType::PointType position;
52  inputIt.GoToBegin();
53 
54  unsigned long currentIndex = 0;
55 
56  while (!inputIt.IsAtEnd())
57  {
58  const InputPixelType value = inputIt.Get();
59  if ((value >= m_LowerThreshold) && (value <= m_UpperThreshold))
60  {
61  // FIXME: non valid for image with dim > 2
62  const IndexType index = inputIt.GetIndex();
63  position[0] = index[0];
64  position[1] = index[1];
65  this->m_PointsContainerPerThread[threadId]->InsertElement(currentIndex, position);
66  this->m_PointDataContainerPerThread[threadId]->InsertElement(currentIndex, static_cast<typename PointDataContainerType::Element>(value));
67  ++currentIndex;
68  }
69  ++inputIt;
70  progress.CompletedPixel(); // potential exception thrown here
71  }
72 }
73 
77 template <class TInputImage, class TOutputPointSet>
78 void ThresholdImageToPointSetFilter<TInputImage, TOutputPointSet>::PrintSelf(std::ostream& os, itk::Indent indent) const
79 {
80  Superclass::PrintSelf(os, indent);
81  os << indent << "LowerThreshold : " << m_LowerThreshold << std::endl;
82  os << indent << "UpperThreshold : " << m_UpperThreshold << std::endl;
83 }
85 
86 } // end namespace otb
87 
88 #endif
Superclass::InputImageType::IndexType IndexType
void ThreadedGenerateData(const InputImageRegionType &inputRegionForThread, itk::ThreadIdType threadId) override
Superclass::InputImageRegionType InputImageRegionType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Superclass::InputImageConstPointer InputImageConstPointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.