OTB  9.0.0
Orfeo Toolbox
otbSpatialisationFilter.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 otbSpatialisationFilter_hxx
22 #define otbSpatialisationFilter_hxx
23 
24 #include "itkNumericTraits.h"
25 
27 
28 namespace otb
29 {
30 
31 template <class TLabelMap>
33 {
34  // default value
35 }
36 
37 
38 template <class TLabelMap>
40 {
41 
42  if (m_AreaVector.size() != (m_NumberOfObjects[0] * m_NumberOfObjects[1]))
43  {
44  itkExceptionMacro(<< "Size problem : AreaVector size must be equal to " << m_NumberOfObjects[0] * m_NumberOfObjects[1]);
45  }
46  if (m_PathVector.size() != (m_NumberOfObjects[0] * m_NumberOfObjects[1]))
47  {
48  itkExceptionMacro(<< "Size problem : PathVector size must be equal to " << m_NumberOfObjects[0] * m_NumberOfObjects[1]);
49  }
50  if (m_Labels.size() != (m_NumberOfObjects[0] * m_NumberOfObjects[1]))
51  {
52  itkExceptionMacro(<< "Size problem : Labels size must be equal to " << m_NumberOfObjects[0] * m_NumberOfObjects[1]);
53  }
54 
55  unsigned int numberOfObjects = m_NumberOfObjects[0] * m_NumberOfObjects[1];
56  // first object must have label 1. 0 is for background value in a label map.
57  for (unsigned int i = 0; i < numberOfObjects; ++i)
58  {
59  this->ProcessObject(i);
60  }
61 }
62 
63 template <class TLabelMap>
65 {
66  IndexType index;
67  IndexType startIndex;
68  startIndex[1] = static_cast<unsigned int>(((obj) / m_NumberOfObjects[0]) * m_ObjectSize[1]);
69  startIndex[0] = static_cast<unsigned int>(((obj) % m_NumberOfObjects[0]) * m_ObjectSize[0]);
70 
71  for (unsigned int col = startIndex[0]; col < startIndex[0] + m_ObjectSize[0]; col++)
72  {
73  for (unsigned int line = startIndex[1]; line < startIndex[1] + m_ObjectSize[1]; line++)
74  {
75  index[0] = col;
76  index[1] = line;
77  this->GetOutput()->AddPixel(index, m_Labels[obj]);
78  }
79  }
80  this->GetOutput()->GetLabelObject(m_Labels[obj])->SetAttribute("area", m_AreaVector[obj]);
81  if (m_PathVector[obj] != "")
82  this->GetOutput()->GetLabelObject(m_Labels[obj])->SetAttribute("path", m_PathVector[obj]);
83 }
84 
85 template <class TLabelMap>
87 {
88 
89  Superclass::GenerateOutputInformation();
90 
91  RegionType region;
92  SizeType size;
93  IndexType index;
94  index.Fill(0);
95  size[0] = m_ObjectSize[0] * m_NumberOfObjects[0];
96  size[1] = m_ObjectSize[1] * m_NumberOfObjects[1];
97  region.SetSize(size);
98  region.SetIndex(index);
99 
100  // RegionType requestedRegion;
101  // size[0]=m_ObjectSize[0];
102  // size[1]=m_ObjectSize[1];
103  // requestedRegion.SetSize(size);
104  // requestedRegion.SetIndex(index);
105 
106  this->GetOutput()->SetLargestPossibleRegion(region);
107  // this->GetOutput()->SetRequestedRegion(requestedRegion);
108 }
109 
110 template <class TLabelMap>
111 void SpatialisationFilter<TLabelMap>::PrintSelf(std::ostream& os, itk::Indent indent) const
112 {
113  Superclass::PrintSelf(os, indent);
114 }
115 
116 } // end namespace otb
117 
118 #endif
otb::SpatialisationFilter::GenerateData
void GenerateData() override
Definition: otbSpatialisationFilter.hxx:39
otb::SpatialisationFilter::IndexType
OutputLabelMapType::IndexType IndexType
Definition: otbSpatialisationFilter.h:69
otb::SpatialisationFilter::ProcessObject
virtual void ProcessObject(unsigned int obj)
Definition: otbSpatialisationFilter.hxx:64
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SpatialisationFilter::SizeType
itk::Size< 2 > SizeType
Definition: otbSpatialisationFilter.h:75
otb::SpatialisationFilter::RegionType
OutputLabelMapType::RegionType RegionType
Definition: otbSpatialisationFilter.h:70
otb::SpatialisationFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbSpatialisationFilter.hxx:86
otb::SpatialisationFilter::SpatialisationFilter
SpatialisationFilter()
Definition: otbSpatialisationFilter.hxx:32
otb::SpatialisationFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbSpatialisationFilter.hxx:111
otbSpatialisationFilter.h