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