OTB  9.0.0
Orfeo Toolbox
otbImportImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbImportImageFilter_hxx
23 #define otbImportImageFilter_hxx
24 
25 #include "otbImportImageFilter.h"
26 #include "itkObjectFactory.h"
27 
28 namespace otb
29 {
30 
34 template <class TOutputImage>
36 {
37  unsigned int idx;
38 
39  for (idx = 0; idx < TOutputImage::ImageDimension; ++idx)
40  {
41  m_Spacing[idx] = 1.0;
42  m_Origin[idx] = 0.0;
43  }
44  m_Direction.SetIdentity();
45 
46  m_ImportPointer = nullptr;
47  m_FilterManageMemory = false;
48  m_Size = 0;
49 }
50 
54 template <class TOutputImage>
56 {
57  if (m_ImportPointer && m_FilterManageMemory)
58  {
59  delete[] m_ImportPointer;
60  }
61 }
63 
67 template <class TOutputImage>
68 void ImportImageFilter<TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
69 {
70  int i;
71 
72  Superclass::PrintSelf(os, indent);
73 
74  if (m_ImportPointer)
75  {
76  os << indent << "Imported pointer: (" << m_ImportPointer << ")" << std::endl;
77  }
78  else
79  {
80  os << indent << "Imported pointer: (None)" << std::endl;
81  }
82  os << indent << "Import buffer size: " << m_Size << std::endl;
83  os << indent << "Import buffer size: " << m_Size << std::endl;
84  os << indent << "Filter manages memory: " << (m_FilterManageMemory ? "true" : "false") << std::endl;
85 
86  os << indent << "Spacing: [";
87  for (i = 0; i < static_cast<int>(TOutputImage::ImageDimension) - 1; ++i)
88  {
89  os << m_Spacing[i] << ", ";
90  }
91  os << m_Spacing[i] << "]" << std::endl;
92 
93  os << indent << "Origin: [";
94  for (i = 0; i < static_cast<int>(TOutputImage::ImageDimension) - 1; ++i)
95  {
96  os << m_Origin[i] << ", ";
97  }
98  os << m_Origin[i] << "]" << std::endl;
99  os << indent << "Direction: " << std::endl << this->GetDirection() << std::endl;
100 }
101 
105 template <class TOutputImage>
106 void ImportImageFilter<TOutputImage>::SetImportPointer(TPixel* ptr, unsigned long num, bool LetFilterManageMemory)
107 {
108  if (ptr != m_ImportPointer)
109  {
110  if (m_ImportPointer && m_FilterManageMemory)
111  {
112  delete[] m_ImportPointer;
113  }
114  m_ImportPointer = ptr;
115  this->Modified();
116  }
117  m_FilterManageMemory = LetFilterManageMemory;
118  m_Size = num;
119 }
121 
125 template <class TOutputImage>
127 {
128  return m_ImportPointer;
129 }
130 
134 template <class TOutputImage>
136 {
137  // call the superclass' implementation of this method
138  Superclass::EnlargeOutputRequestedRegion(output);
139 
140  // get pointer to the output
141  OutputImagePointer outputPtr = this->GetOutput();
142 
143  // set the requested region to the largest possible region (in this case
144  // the amount of data that we have)
145  outputPtr->SetRequestedRegion(outputPtr->GetLargestPossibleRegion());
146 }
147 
151 template <class TOutputImage>
153 {
154  // call the superclass' implementation of this method
155  Superclass::GenerateOutputInformation();
156 
157  // get pointer to the output
158  OutputImagePointer outputPtr = this->GetOutput();
159 
160  // we need to compute the output spacing, the output origin, the
161  // output image size, and the output image start index
162  outputPtr->SetSignedSpacing(m_Spacing);
163  outputPtr->SetOrigin(m_Origin);
164  outputPtr->SetDirection(m_Direction);
165  outputPtr->SetLargestPossibleRegion(m_Region);
166 }
167 
171 template <class TOutputImage>
173 {
174  // Normally, GenerateData() allocates memory. However, the application
175  // provides the memory for this filter via the SetImportPointer() method.
176  // Therefore, this filter does not call outputPtr->Allocate().
177 
178  // get pointer to the output
179  OutputImagePointer outputPtr = this->GetOutput();
180 
181  // the output buffer size is set to the size specified by the user via the
182  // SetRegion() method.
183  outputPtr->SetBufferedRegion(outputPtr->GetLargestPossibleRegion());
184 
185  // pass the pointer down to the container during each Update() since
186  // a call to Initialize() causes the container to forget the
187  // pointer. Note that we tell the container NOT to manage the
188  // memory itself. This filter will properly manage the memory (as
189  // opposed to the container) if the user wants it to.
190  outputPtr->GetPixelContainer()->SetImportPointer(m_ImportPointer, m_Size, false);
191 }
192 
196 template <class TOutputImage>
198 {
199  double dspacing[TOutputImage::ImageDimension];
200  for (unsigned int i = 0; i < TOutputImage::ImageDimension; ++i)
201  {
202  dspacing[i] = spacing[i];
203  }
204  this->SetSpacing(dspacing);
205 }
207 
211 template <class TOutputImage>
213 {
214  double dorigin[TOutputImage::ImageDimension];
215  for (unsigned int i = 0; i < TOutputImage::ImageDimension; ++i)
216  {
217  dorigin[i] = origin[i];
218  }
219  this->SetOrigin(dorigin);
220 }
222 
223 //----------------------------------------------------------------------------
224 template <class TOutputImage>
226 {
227  bool modified = false;
228  for (unsigned int r = 0; r < TOutputImage::ImageDimension; ++r)
229  {
230  for (unsigned int c = 0; c < TOutputImage::ImageDimension; ++c)
231  {
232  if (m_Direction[r][c] != direction[r][c])
233  {
234  m_Direction[r][c] = direction[r][c];
235  modified = true;
236  }
237  }
238  }
239  if (modified)
240  {
241  this->Modified();
242  }
243 }
244 
245 } // end namespace otb
246 
247 #endif
otb::ImportImageFilter::~ImportImageFilter
~ImportImageFilter() override
Definition: otbImportImageFilter.hxx:55
otb::ImportImageFilter::SpacingType
OutputImageType::SpacingType SpacingType
Definition: otbImportImageFilter.h:51
otb::ImportImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbImportImageFilter.hxx:152
otb::ImportImageFilter::GetImportPointer
TPixel * GetImportPointer()
Definition: otbImportImageFilter.hxx:126
otb::ImportImageFilter::SetDirection
virtual void SetDirection(const DirectionType direction)
Definition: otbImportImageFilter.hxx:225
otb::ImportImageFilter::ImportImageFilter
ImportImageFilter()
Definition: otbImportImageFilter.hxx:35
otb::ImportImageFilter::GenerateData
void GenerateData() override
Definition: otbImportImageFilter.hxx:172
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImportImageFilter::OriginType
OutputImageType::PointType OriginType
Definition: otbImportImageFilter.h:52
otb::ImportImageFilter::SetSpacing
virtual void SetSpacing(const double data[])
otb::ImportImageFilter::TPixel
OutputImageType::PixelType TPixel
Definition: otbImportImageFilter.h:77
otb::ImportImageFilter::SetOrigin
virtual void SetOrigin(const double data[])
otb::ImportImageFilter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbImportImageFilter.h:50
otb::ImportImageFilter::DirectionType
itk::Matrix< double, OutputImageType::ImageDimension, OutputImageType::ImageDimension > DirectionType
Definition: otbImportImageFilter.h:135
otb::ImportImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbImportImageFilter.hxx:68
otb::ImportImageFilter::SetImportPointer
void SetImportPointer(TPixel *ptr, unsigned long num, bool LetFilterManageMemory)
Definition: otbImportImageFilter.hxx:106
otbImportImageFilter.h
otb::ImportImageFilter::EnlargeOutputRequestedRegion
void EnlargeOutputRequestedRegion(itk::DataObject *output) override
Definition: otbImportImageFilter.hxx:135