OTB  6.7.0
Orfeo Toolbox
otbVectorDataSource.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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>
35 {
36  this->Superclass::SetNumberOfRequiredOutputs(1);
37  this->Superclass::SetNthOutput(0, OutputVectorDataType::New().GetPointer());
38 }
40 
41 template <class TOutputVectorData>
44 {
45 }
46 
51 template <class TOutputVectorData>
52 void
55 {
56  this->GraftNthOutput(0, graft);
57 }
58 
63 template <class TOutputVectorData>
64 void
66 ::GraftNthOutput(unsigned int idx, itk::DataObject *graft)
67 {
68  if ( idx >= this->GetNumberOfOutputs() )
69  {
70  itkExceptionMacro(<<"Requested to graft output " << idx <<
71  " but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
72  }
73 
74  if ( !graft )
75  {
76  itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" );
77  }
78 
79  // we use the process object method since all out output may not be
80  // of the same type
81  itk::DataObject * output = this->ProcessObject::GetOutput(idx);
82 
83  // Call GraftImage to copy meta-information, regions, and the pixel container
84  output->Graft( graft );
85 }
86 
87 
88 template <class TOutputVectorData>
89 void
92 {
93  OutputVectorDataPointer outputPtr;
94 
95  // Allocate the output memory
96  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
97  {
98  outputPtr = this->GetOutput(i);
99  outputPtr->Clear();
100  }
101 }
102 
107 template <class TOutputVectorData>
111 {
112  if (this->GetNumberOfOutputs() < 1)
113  {
114  return nullptr;
115  }
116  return static_cast<OutputVectorDataType *> (this->ProcessObject::GetOutput(0));
117 }
119 
120 template <class TOutputVectorData>
124 {
125  return static_cast<OutputVectorDataType*>
126  (this->Superclass::GetOutput(idx));
127 }
128 
132 template<class TOutputVectorData>
133 void
135 ::PrintSelf(std::ostream& os, itk::Indent indent) const
136 {
137  Superclass::PrintSelf(os, indent);
138 }
139 
140 } // End namespace otb
141 
142 #endif
virtual OutputVectorDataType * GetOutput(void)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual void Graft(const DataObject *)
TOutputVectorData::Pointer OutputVectorDataPointer
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual void GraftNthOutput(unsigned int idx, itk::DataObject *output)
virtual void GraftOutput(itk::DataObject *output)
TOutputVectorData OutputVectorDataType