Orfeo Toolbox  3.16
otbLayerBasedModel.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbLayerBasedModel_txx
19 #define __otbLayerBasedModel_txx
20 
21 #include "otbLayerBasedModel.h"
22 #include "otbMacro.h"
23 #include "itkTimeProbe.h"
24 
25 namespace otb
26 {
27 
28 template <class TLayer>
30 ::LayerBasedModel() : m_Layers()
31 
32 {
33  // Initializing the layer list
34  m_Layers = LayerListType::New();
35 }
36 
37 template <class TLayer>
40 {}
41 
42 template <class TLayer>
43 unsigned int
46 {
47  // Push back and return the size-1
48  m_Layers->PushBack(layer);
49 
50  // Return the layer index
51  return m_Layers->Size() - 1;
52 }
53 
54 template <class TLayer>
56 ::LayerType *
58 ::GetLayer(unsigned int index)
59 {
60  // Check if not out of bound and return the ith element
61  if (index >= m_Layers->Size())
62  {
63  return NULL;
64  }
65  else
66  {
67  return m_Layers->GetNthElement(index);
68  }
69 }
70 template <class TLayer>
71 bool
73 ::DeleteLayer(unsigned int index)
74 {
75 // Check if not out of bound and delete the ith element
76  if (index >= m_Layers->Size())
77  {
78  return false;
79  }
80  else
81  {
82  m_Layers->Erase(index);
83  return true;
84  }
85 }
86 
87 template <class TLayer>
89 ::LayerType *
91 ::GetLayerByName(const std::string& name)
92 {
93  LayerType * resp = NULL;
94  LayerIteratorType it = m_Layers->Begin();
95  bool found = false;
96 
97  // Look for the layer named after name
98  while (it != m_Layers->End() && !found)
99  {
100  if (it.Get()->GetName() == name)
101  {
102  resp = it.Get();
103  found = true;
104  }
105  ++it;
106  }
107  return resp;
108 }
109 
110 template <class TLayer>
111 bool
113 ::DeleteLayerByName(const std::string& name)
114 {
115  LayerIteratorType it = m_Layers->Begin();
116  bool found = false;
117  unsigned int index = 0;
118 
119  // Look for the layer named after name
120  while (it != m_Layers->End() && !found)
121  {
122  if (it.Get()->GetName() == name)
123  {
124  found = true;
125  }
126  ++index;
127  ++it;
128  }
129 
130  if (found)
131  {
132  m_Layers->Erase(index - 1);
133  }
134  return found;
135 }
136 
137 template <class TLayer>
138 void
141 {
142  // Clear layers list
143  m_Layers->Clear();
144 }
145 
146 template <class TLayer>
147 unsigned int
150 {
151  // return layer list size
152  return m_Layers->Size();
153 }
154 
155 template <class TLayer>
156 void
158 ::PrintSelf(std::ostream& os, itk::Indent indent) const
159 {
160  // Call superclass implementation
161  Superclass::PrintSelf(os, indent);
162 }
163 
164 } // end namespace otb
165 
166 #endif

Generated at Sun Feb 3 2013 00:33:41 for Orfeo Toolbox with doxygen 1.8.1.1