OTB  9.0.0
Orfeo Toolbox
otbVectorDataSource.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 
22 #ifndef otbVectorDataSource_hxx
23 #define otbVectorDataSource_hxx
24 
25 #include "otbVectorDataSource.h"
26 
27 namespace otb
28 {
32 template <class TOutputVectorData>
34 {
35  this->Superclass::SetNumberOfRequiredOutputs(1);
36  this->Superclass::SetNthOutput(0, OutputVectorDataType::New().GetPointer());
37 }
39 
40 template <class TOutputVectorData>
42 {
43 }
44 
49 template <class TOutputVectorData>
51 {
52  this->GraftNthOutput(0, graft);
53 }
54 
59 template <class TOutputVectorData>
60 void VectorDataSource<TOutputVectorData>::GraftNthOutput(unsigned int idx, itk::DataObject* graft)
61 {
62  if (idx >= this->GetNumberOfOutputs())
63  {
64  itkExceptionMacro(<< "Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
65  }
66 
67  if (!graft)
68  {
69  itkExceptionMacro(<< "Requested to graft output that is a NULL pointer");
70  }
71 
72  // we use the process object method since all out output may not be
73  // of the same type
74  itk::DataObject* output = this->ProcessObject::GetOutput(idx);
75 
76  // Call GraftImage to copy meta-information, regions, and the pixel container
77  output->Graft(graft);
78 }
79 
80 
81 template <class TOutputVectorData>
83 {
84  OutputVectorDataPointer outputPtr;
85 
86  // Allocate the output memory
87  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
88  {
89  outputPtr = this->GetOutput(i);
90  outputPtr->Clear();
91  }
92 }
93 
98 template <class TOutputVectorData>
100 {
101  if (this->GetNumberOfOutputs() < 1)
102  {
103  return nullptr;
104  }
105  return static_cast<OutputVectorDataType*>(this->ProcessObject::GetOutput(0));
106 }
108 
109 template <class TOutputVectorData>
111 {
112  return static_cast<OutputVectorDataType*>(this->Superclass::GetOutput(idx));
113 }
114 
118 template <class TOutputVectorData>
119 void VectorDataSource<TOutputVectorData>::PrintSelf(std::ostream& os, itk::Indent indent) const
120 {
121  Superclass::PrintSelf(os, indent);
122 }
123 
124 } // End namespace otb
125 
126 #endif
otb::VectorDataSource::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbVectorDataSource.hxx:119
otb::VectorDataSource::GetOutput
virtual OutputVectorDataType * GetOutput(void)
Definition: otbVectorDataSource.hxx:99
otb::VectorData
This class represents a hierarchy of vector data.
Definition: otbVectorData.h:58
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VectorDataSource::OutputVectorDataType
TOutputVectorData OutputVectorDataType
Definition: otbVectorDataSource.h:58
otb::VectorDataSource::~VectorDataSource
~VectorDataSource() override
Definition: otbVectorDataSource.hxx:41
otb::VectorDataSource< otb::VectorData< double > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbVectorDataSource.h:55
otb::VectorDataSource::GraftNthOutput
virtual void GraftNthOutput(unsigned int idx, itk::DataObject *output)
Definition: otbVectorDataSource.hxx:60
otbVectorDataSource.h
otb::VectorDataSource< otb::VectorData< double > >::OutputVectorDataPointer
otb::VectorData< double > ::Pointer OutputVectorDataPointer
Definition: otbVectorDataSource.h:59
otb::VectorDataSource::AllocateOutputs
virtual void AllocateOutputs()
Definition: otbVectorDataSource.hxx:82
otb::VectorDataSource::VectorDataSource
VectorDataSource()
Definition: otbVectorDataSource.hxx:33
otb::VectorDataSource::GraftOutput
virtual void GraftOutput(itk::DataObject *output)
Definition: otbVectorDataSource.hxx:50