OTB  9.0.0
Orfeo Toolbox
otbObjectListSource.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 otbObjectListSource_hxx
22 #define otbObjectListSource_hxx
23 
24 #include "otbObjectListSource.h"
25 #include "itkProgressReporter.h"
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 
34 template <class TOutputList>
36 {
37  // Create the output. We use static_cast<> here because we know the default
38  // output must be of type TOutputImage
39  typename TOutputList::Pointer output = static_cast<TOutputList*>(this->MakeOutput(0).GetPointer());
40  this->Superclass::SetNumberOfRequiredOutputs(1);
41  this->Superclass::SetNthOutput(0, output.GetPointer());
42 }
44 
48 template <class TOutputList>
50 {
51  return static_cast<itk::DataObject*>(TOutputList::New().GetPointer());
52 }
53 
57 template <class TOutputList>
59 {
60  if (this->GetNumberOfOutputs() < 1)
61  {
62  return nullptr;
63  }
64 
65  return static_cast<TOutputList*>(this->Superclass::GetOutput(0));
66 }
67 
71 template <class TOutputList>
73 {
74  return static_cast<TOutputList*>(this->Superclass::GetOutput(idx));
75 }
76 
80 template <class TOutputList>
81 void ObjectListSource<TOutputList>::GraftOutput(itk::DataObject* graft)
82 {
83  this->GraftNthOutput(0, graft);
84 }
85 
89 template <class TOutputList>
91 {
92  if (idx >= this->GetNumberOfOutputs())
93  {
94  itkExceptionMacro(<< "Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
95  }
96 
97  if (!graft)
98  {
99  itkExceptionMacro(<< "Requested to graft output that is a NULL pointer");
100  }
101 
102  itk::DataObject* output = this->GetOutput(idx);
103 
104  // Call GraftImage to copy meta-information, regions, and the pixel container
105  output->Graft(graft);
106 }
107 
108 //----------------------------------------------------------------------------
109 
110 template <class TOutputList>
112 {
113  OutputListPointer outputPtr;
114 
115  // Allocate the output memory
116  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
117  {
118  outputPtr = this->GetOutput(i);
119  outputPtr->Clear();
120  }
121 }
122 
126 template <class TOutputList>
128 {
129  itkExceptionMacro("subclass should override this method!!!");
130 }
131 
135 template <class TOutputList>
136 void ObjectListSource<TOutputList>::PrintSelf(std::ostream& os, itk::Indent indent) const
137 {
138  Superclass::PrintSelf(os, indent);
139 }
140 } // end namespace otb
142 
143 #endif
otb::ObjectListSource::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbObjectListSource.hxx:136
otb::ObjectListSource::DataObjectPointer
itk::DataObject::Pointer DataObjectPointer
Definition: otbObjectListSource.h:67
otb::ObjectListSource::GenerateData
void GenerateData(void) override
Definition: otbObjectListSource.hxx:127
otbObjectListSource.h
otb::ObjectListSource::GetOutput
OutputListType * GetOutput(void)
Definition: otbObjectListSource.hxx:58
otbMath.h
otb::ObjectListSource::GraftNthOutput
void GraftNthOutput(DataObjectPointerArraySizeType idx, itk::DataObject *graft)
Definition: otbObjectListSource.hxx:90
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ObjectListSource< ObjectList< TOutputPath > >::OutputListPointer
ObjectList< TOutputPath > ::Pointer OutputListPointer
Definition: otbObjectListSource.h:65
otb::ObjectListSource::GraftOutput
void GraftOutput(itk::DataObject *graft)
Definition: otbObjectListSource.hxx:81
otb::ObjectListSource::AllocateOutputs
virtual void AllocateOutputs()
Definition: otbObjectListSource.hxx:111
otb::ObjectListSource< ObjectList< TOutputPath > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbObjectListSource.h:60
otb::ObjectListSource::ObjectListSource
ObjectListSource()
Definition: otbObjectListSource.hxx:35
otb::ObjectListSource::OutputListType
TOutputList OutputListType
Definition: otbObjectListSource.h:64
otb::ObjectListSource::MakeOutput
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
Definition: otbObjectListSource.hxx:49