otbGeometriesSet.cxx 4.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

/*===========================================================================*/
/*===============================[ Includes ]================================*/
/*===========================================================================*/
#include "otbGeometriesSet.h"
23
#include <cassert>
24
25

/*===========================================================================*/
26
/*================================[ Helpers ]================================*/
27
/*===========================================================================*/
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
template <typename DataType>
inline
DataType & getRef(typename itk::SmartPointer<DataType> const& ds)
{
  assert(ds && "unexpected nil datasource");
  return *ds;
}

#if 0
template <typename DataType>
inline
DataType const& getRef(typename DataType::ConstPointer ds)
{
  assert(ds);
  return *ds;
}
#endif
45

46
47
48
49
50
51
52
53
54
55
56
57
58
otb::ogr::Layer const& getRef(otb::ogr::Layer const& layer)
{
  return layer;
}

otb::ogr::Layer & getRef(otb::ogr::Layer & layer)
{
  return layer;
}

/*===========================================================================*/
/*=======================[ Setting and construction ]========================*/
/*===========================================================================*/
59
otb::GeometriesSet::GeometriesSet()
60
: m_geometriesSet(otb::ogr::DataSource::New())
61
, m_ImageReference(*this)
62
63
64
65
66
{
}

otb::GeometriesSet::GeometriesSet(ogr::DataSource::Pointer datasource)
: m_geometriesSet(datasource)
67
, m_ImageReference(*this)
68
69
70
71
72
73
{
  assert(datasource && "unexpected nil datasource");
}

otb::GeometriesSet::GeometriesSet(ogr::Layer layer)
: m_geometriesSet(layer)
74
, m_ImageReference(*this)
75
76
77
{
}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*static*/
otb::GeometriesSet::Pointer otb::GeometriesSet::New(ogr::DataSource::Pointer datasource)
{
  Pointer res = new Self(datasource);
  res->UnRegister();
  return res;
}

/*static*/
otb::GeometriesSet::Pointer otb::GeometriesSet::New(ogr::Layer layer)
{
  Pointer res = new Self(layer);
  res->UnRegister();
  return res;
}

/*virtual*/
otb::GeometriesSet::~GeometriesSet()
96
97
98
99
100
{
}

void otb::GeometriesSet::Set(ogr::Layer layer)
{
101
  assert(layer && "unexpected nil layer");
102
103
104
105
106
  m_geometriesSet = layer;
}

void otb::GeometriesSet::Set(ogr::DataSource::Pointer datasource)
{
107
  assert(datasource && "unexpected nil datasource");
108
109
110
  m_geometriesSet = datasource;
}

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*===========================================================================*/
/*=================================[ IsSet ]=================================*/
/*===========================================================================*/
struct IsSetTester : boost::static_visitor<bool>
{
  template <typename T>
  bool operator()(T const& gs) const
    {
    return getRef(gs);
    }
};

bool otb::GeometriesSet::IsSet() const
{
  return this->apply(IsSetTester());
}

/*===========================================================================*/
/*===============================[ Printing ]================================*/
/*===========================================================================*/
131
132
133
134
135
136
struct Printer : boost::static_visitor<>
{
  Printer(std::ostream& os, itk::Indent indent)
    : m_os(os), m_indent(indent) {}
  void operator()(otb::ogr::Layer layer) const
    {
137
    assert(layer && "unexpected nil layer...");
138
139
140
141
    layer.PrintSelf(m_os, m_indent);
    }
  void operator()(otb::ogr::DataSource::Pointer datasource) const
    {
142
    assert(datasource && "unexpected nil datasource...");
143
144
145
146
147
148
149
150
151
152
153
    datasource->Print(m_os, m_indent);
    }
private:
  std::ostream &m_os;
  itk::Indent   m_indent;
};

void otb::GeometriesSet::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  this->apply(Printer(os, indent));
}
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

/*===========================================================================*/
/*=========================[ GetMetaDataDictionary ]=========================*/
/*===========================================================================*/
struct MetaDataDictionaryGetter : boost::static_visitor<itk::MetaDataDictionary&>
{
  itk::MetaDataDictionary& operator()(otb::ogr::Layer layer) const
    {
    return layer.GetMetaDataDictionary();
    }
  itk::MetaDataDictionary& operator()(otb::ogr::DataSource::Pointer datasource) const
    {
    return datasource->GetMetaDataDictionary();
    }
};

itk::MetaDataDictionary & otb::GeometriesSet::GetMetaDataDictionary()
{
  return this->apply(MetaDataDictionaryGetter());
}

itk::MetaDataDictionary const& otb::GeometriesSet::GetMetaDataDictionary() const
{
  return const_cast <GeometriesSet *>(this)->GetMetaDataDictionary();
}