OTB  6.1.0
Orfeo Toolbox
otbObjectListSource.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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_txx
22 #define otbObjectListSource_txx
23 
24 #include "otbObjectListSource.h"
25 #include "itkProgressReporter.h"
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 
34 template <class TOutputList>
37 {
38  // Create the output. We use static_cast<> here because we know the default
39  // output must be of type TOutputImage
40  typename TOutputList::Pointer output
41  = static_cast<TOutputList*>(this->MakeOutput(0).GetPointer());
42  this->Superclass::SetNumberOfRequiredOutputs(1);
43  this->Superclass::SetNthOutput(0, output.GetPointer());
45 
46 }
47 
51 template<class TOutputList>
55 {
56  return static_cast<itk::DataObject*>(TOutputList::New().GetPointer());
57 }
58 
62 template <class TOutputList>
66 {
67  if (this->GetNumberOfOutputs() < 1)
68  {
69  return ITK_NULLPTR;
70  }
71 
72  return static_cast<TOutputList*>
73  (this->Superclass::GetOutput(0));
74 }
75 
79 template <class TOutputList>
83 {
84  return static_cast<TOutputList*>
85  (this->Superclass::GetOutput(idx));
86 }
87 
91 template<class TOutputList>
92 void
95 {
96  this->GraftNthOutput(0, graft);
97 }
98 
102 template<class TOutputList>
103 void
106 {
107  if (idx >= this->GetNumberOfOutputs())
108  {
109  itkExceptionMacro(<< "Requested to graft output " << idx <<
110  " but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
111  }
112 
113  if (!graft)
114  {
115  itkExceptionMacro(<< "Requested to graft output that is a NULL pointer");
116  }
117 
118  itk::DataObject * output = this->GetOutput(idx);
119 
120  // Call GraftImage to copy meta-information, regions, and the pixel container
121  output->Graft(graft);
122 }
123 
124 //----------------------------------------------------------------------------
125 
126 template <class TOutputList>
127 void
130 {
131  OutputListPointer outputPtr;
132 
133  // Allocate the output memory
134  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
135  {
136  outputPtr = this->GetOutput(i);
137  outputPtr->Clear();
138  }
139 }
140 
144 template <class TOutputList>
145 void
148 {
149  itkExceptionMacro("subclass should ITK_OVERRIDE this method!!!");
150 }
151 
155 template <class TOutputList>
156 void
158 ::PrintSelf(std::ostream& os, itk::Indent indent) const
159 {
160  Superclass::PrintSelf(os, indent);
161 }
162 } // end namespace otb
164 
165 #endif
void GenerateData(void) ITK_OVERRIDE
virtual void Graft(const DataObject *)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void GraftOutput(itk::DataObject *graft)
TOutputList::Pointer OutputListPointer
OutputListType * GetOutput(void)
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) ITK_OVERRIDE
void GraftNthOutput(DataObjectPointerArraySizeType idx, itk::DataObject *graft)