OTB  9.0.0
Orfeo Toolbox
otbPointSetExtractROI.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 #ifndef otbPointSetExtractROI_hxx
22 #define otbPointSetExtractROI_hxx
23 
24 #include "otbPointSetExtractROI.h"
25 #include "itkMacro.h"
26 
27 namespace otb
28 {
29 
33 template <class TInputPointSet, class TOutputPointSet>
34 PointSetExtractROI<TInputPointSet, TOutputPointSet>::PointSetExtractROI() : m_StartX(0), m_StartY(0), m_SizeX(0), m_SizeY(0)
35 {
36 }
37 
41 template <class TInputPointSet, class TOutputPointSet>
42 void PointSetExtractROI<TInputPointSet, TOutputPointSet>::PrintSelf(std::ostream& os, itk::Indent indent) const
43 {
44  Superclass::PrintSelf(os, indent);
45 }
46 
50 template <class TInputPointSet, class TOutputPointSet>
52 {
53  typedef typename TInputPointSet::PointsContainer InputPointsContainer;
54  typedef typename TInputPointSet::PointsContainerPointer InputPointsContainerPointer;
55  typedef typename TOutputPointSet::PointsContainerPointer OutputPointsContainerPointer;
56 
57  typedef typename TInputPointSet::PointDataContainerPointer InputPointDataContainerPointer;
58  typedef typename TOutputPointSet::PointDataContainerPointer OutputPointDataContainerPointer;
59 
60  InputPointSetPointer inputPointSet = this->GetInput();
61  OutputPointSetPointer outputPointSet = this->GetOutput();
62 
63  if (!inputPointSet)
64  {
65  itkExceptionMacro(<< "Missing Input PointSet");
66  }
67 
68  if (!outputPointSet)
69  {
70  itkExceptionMacro(<< "Missing Output PointSet");
71  }
72 
73  outputPointSet->SetBufferedRegion(outputPointSet->GetRequestedRegion()); // TODO update outputRegion
74 
75  InputPointsContainerPointer inPoints = inputPointSet->GetPoints();
76  InputPointDataContainerPointer inData = inputPointSet->GetPointData();
77  OutputPointsContainerPointer outPoints = outputPointSet->GetPoints();
78  OutputPointDataContainerPointer outData = outputPointSet->GetPointData();
79 
80  typename InputPointsContainer::ConstIterator inputPoint = inPoints->Begin();
81 
82  // Commented cause using iterator on the pointSetData crash
83  // Use a direct access to pointSet Data instead to avoid segfault
84  // typename InputPointDataContainer::ConstIterator inputData = inData->Begin();
85  // if (inData.IsNotNull())
86  // {
87  // inputData = inData->Begin();
88  // }
89 
90  while (inputPoint != inPoints->End())
91  {
92  typename InputPointsContainer::Element point = inputPoint.Value();
93 
94  if ((((point[0] >= m_StartX) && (point[0] < m_StartX + m_SizeX)) ||
95  ((point[0] <= m_StartX) && (point[0] > m_StartX + m_SizeX))) // cover the case when size<0
96  && (((point[1] >= m_StartY) && (point[1] < m_StartY + m_SizeY)) || ((point[1] <= m_StartY) && (point[1] > m_StartY + m_SizeY))))
97  {
98  // Add the point
99  outPoints->push_back(point);
100  // Get & Add the data
101  typename InputPointSetType::PixelType data;
102  inputPointSet->GetPointData(inputPoint.Index(), &data);
103  outData->push_back(data /*inputData.Value()*/);
104  }
105 
106  ++inputPoint;
107  //++inputData;
108  }
109 }
110 
111 } // end namespace otb
112 
113 #endif
otb::PointSetExtractROI::InputPointSetPointer
InputPointSetType::Pointer InputPointSetPointer
Definition: otbPointSetExtractROI.h:55
otb::PointSetExtractROI::PointSetExtractROI
PointSetExtractROI()
Definition: otbPointSetExtractROI.hxx:34
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbPointSetExtractROI.h
otb::PointSetExtractROI::GenerateData
void GenerateData(void) override
Definition: otbPointSetExtractROI.hxx:51
otb::PointSetExtractROI::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbPointSetExtractROI.hxx:42
otb::PointSetExtractROI::OutputPointSetPointer
OutputPointSetType::Pointer OutputPointSetPointer
Definition: otbPointSetExtractROI.h:56