OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRectilinearDataObject.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 // Contributor: David A. Horner (DAH) - http://dave.thehorners.com
9 //
10 //*************************************************************************
11 // $Id: ossimRectilinearDataObject.cpp 22828 2014-07-11 15:56:19Z dburken $
12 
17 #include <sstream>
18 
19 RTTI_DEF1(ossimRectilinearDataObject, "ossimRectilinearDataObject", ossimDataObject);
20 
22  : ossimDataObject(),
23  m_numberOfDataComponents(0),
24  m_scalarType(),
25  m_dataBuffer(),
26  m_spatialExtents()
27 {
28 }
29 
31  const ossimRectilinearDataObject& rhs)
32  : ossimDataObject(rhs),
33  m_numberOfDataComponents(rhs.m_numberOfDataComponents),
34  m_scalarType(rhs.m_scalarType),
35  m_dataBuffer(rhs.m_dataBuffer),
36  m_spatialExtents(rhs.m_spatialExtents)
37 {
38 }
39 
41  ossim_uint32 numberOfSpatialComponents,
42  ossimSource* owner,
43  ossim_uint32 numberOfDataComponents,
44  ossimScalarType scalarType,
45  ossimDataObjectStatus /* status */)
46  :ossimDataObject(owner, OSSIM_NULL),
47  m_numberOfDataComponents(numberOfDataComponents),
48  m_scalarType(scalarType),
49  m_dataBuffer(0),
50  m_spatialExtents(numberOfSpatialComponents)
51 {
52 }
53 
55  ossimSource* owner,
56  ossim_uint32 numberOfDataComponents,
57  ossim_uint32 length,
58  ossimScalarType scalarType,
59  ossimDataObjectStatus /* status */ )
60  :ossimDataObject(owner, OSSIM_NULL),
61  m_numberOfDataComponents(numberOfDataComponents),
62  m_scalarType(scalarType),
63  m_dataBuffer(0),
64  m_spatialExtents(1)
65 {
66  m_spatialExtents[0] = length;
67 }
68 
70  ossimSource* owner,
71  ossim_uint32 numberOfDataComponents,
72  ossim_uint32 width,
73  ossim_uint32 height,
74  ossimScalarType scalarType,
75  ossimDataObjectStatus /* status */)
76  :ossimDataObject(owner, OSSIM_NULL),
77  m_numberOfDataComponents(numberOfDataComponents),
78  m_scalarType(scalarType),
79  m_dataBuffer(0),
80  m_spatialExtents(2)
81 {
82  m_spatialExtents[0] = width;
83  m_spatialExtents[1] = height;
84 }
85 
87  ossimSource* owner,
88  ossim_uint32 numberOfDataComponents,
89  ossim_uint32 width,
90  ossim_uint32 height,
91  ossim_uint32 depth,
92  ossimScalarType scalarType,
93  ossimDataObjectStatus /* status */)
94  :ossimDataObject(owner, OSSIM_NULL),
95  m_numberOfDataComponents(numberOfDataComponents),
96  m_scalarType(scalarType),
97  m_dataBuffer(0),
98  m_spatialExtents(3)
99 {
100  m_spatialExtents[0] = width;
101  m_spatialExtents[1] = height;
102  m_spatialExtents[2] = depth;
103 }
104 
106 {
107 }
108 
110 {
111  ossim_uint32 spatialProduct = 0;
112  for(ossim_uint32 index = 0; index < m_spatialExtents.size(); ++index)
113  {
114  spatialProduct *= m_spatialExtents[index];
115  }
116  return spatialProduct;
117 }
118 
120 {
122 }
123 
126 {
127  if (extents)
128  {
129  m_spatialExtents.resize(size);
130  for(ossim_uint32 i =0; i < size; ++i)
131  {
132  m_spatialExtents[i] = extents[i];
133  }
134  }
135 }
136 
138 {
139  m_scalarType = type;
140 }
141 
143 {
145 }
146 
148 {
149  return (ossim_uint32)m_spatialExtents.size();
150 }
151 
153 {
154  return &(m_spatialExtents.front());
155 }
156 
158 {
159  return m_scalarType;
160 }
161 
163 {
165 }
166 
168 {
169  if (m_dataBuffer.size() > 0)
170  {
171  return static_cast<void*>(&m_dataBuffer.front());
172  }
173  return NULL;
174 }
175 
177 {
178  if (m_dataBuffer.size() > 0)
179  {
180  return static_cast<const void*>(&m_dataBuffer.front());
181  }
182  return NULL;
183 }
184 
186 {
187  if(data)
188  {
189  if (this != data)
190  {
192 
194  m_scalarType = data->m_scalarType;
195  m_dataBuffer = data->m_dataBuffer;
197  }
198  }
199 }
200 
202 {
203  if (m_dataBuffer.size() != getDataSizeInBytes())
204  {
205  // std::vector::resize can throw a std::bad_alloc so wrap it...
206  try
207  {
208  m_dataBuffer.resize( getDataSizeInBytes() );
209  }
210  catch( std::exception& e )
211  {
212  std::ostringstream errMsg;
213  errMsg << "ossimRectilinearDataObject::initialize caught exception on resize:\n"
214  << "Buffer size in bytes: " << getDataSizeInBytes()
215  << "\n" << e.what() << std::endl;
216  throw ossimException( errMsg.str() );
217  }
218 
220  }
221 }
222 
224 {
228 }
229 
231 {
232  out << "ossimRectilinearDataObject::print:"
233  << "\nm_numberOfDataComponents: " << m_numberOfDataComponents
234  << "\ntheNumberOfSpatialComponents: " << m_spatialExtents.size()
235  << "\nm_scalarType: "
237  << endl;
238 
239  return ossimDataObject::print(out);
240 }
241 
243  const ossimRectilinearDataObject& rhs)
244 {
245  if (this != &rhs)
246  {
247  // ossimDataObject initialization:
249 
250  // ossimRectilinearDataObject (this) initialization:
255  }
256  return *this;
257 }
258 
259 bool ossimRectilinearDataObject::saveState(ossimKeywordlist& kwl, const char* prefix)const
260 {
261  ossimString byteEncoded;
263  kwl.add(prefix, "data_buffer", byteEncoded, true);
265  kwl.add(prefix, "spatial_extents", byteEncoded, true);
267 
268  return ossimDataObject::saveState(kwl, prefix);
269 }
270 
271 bool ossimRectilinearDataObject::loadState(const ossimKeywordlist& kwl, const char* prefix)
272 {
273  if(!ossimDataObject::loadState(kwl, prefix)) return false;
274 
275  const char* spatial_extents = kwl.find(prefix, "spatial_extents");
276  const char* data_buffer = kwl.find(prefix, "data_buffer");
277  const char* scalar_type = kwl.find(prefix, ossimKeywordNames::SCALAR_TYPE_KW);
278  m_spatialExtents.clear();
279  m_dataBuffer.clear();
280 
281  if(spatial_extents)
282  {
283  if(!ossim::toSimpleVector(m_spatialExtents, ossimString(spatial_extents)))
284  {
285  return false;
286  }
287  }
288  if(data_buffer)
289  {
290  if(!ossim::toSimpleVector(m_dataBuffer, ossimString(kwl.find(prefix, "data_buffer"))))
291  {
292  return false;
293  }
294  }
295  if(scalar_type)
296  {
298  }
299  else
300  {
302  }
303 
305 
306  return true;
307 
308 }
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimScalarType getScalarTypeFromString(const ossimString &s) const
Represents serializable keyword/value map.
virtual const ossim_uint32 * getSpatialExtents() const
const char * find(const char *key) const
virtual ossimString getEntryString(ossim_int32 entry_number) const
virtual const ossimDataObject * operator=(const ossimDataObject *rhs)
void toSimpleStringList(ossimString &result, const std::vector< T > &valuesList)
This will output a vector of values inst a string.
Definition: ossimCommon.h:484
virtual void assign(const ossimRectilinearDataObject *data)
virtual ossim_uint32 getNumberOfSpatialComponents() const
virtual ossim_uint32 getDataSizeInBytes() const
bool toSimpleVector(std::vector< T > &result, const ossimString &stringOfPoints)
Definition: ossimCommon.h:537
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
virtual std::ostream & print(std::ostream &out) const
Generic print method.
std::vector< ossim_uint8 > m_dataBuffer
virtual void setNumberOfDataComponents(ossim_uint32 n)
How many components make up this data object.
virtual ossim_uint32 computeSpatialProduct() const
virtual void setSpatialExtents(ossim_uint32 *extents, ossim_uint32 size)
yy_size_t size
os2<< "> n<< " > nendobj n
unsigned int ossim_uint32
virtual void assign(const ossimDataObject *rhs)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
std::vector< ossim_uint32 > m_spatialExtents
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossimScalarType
virtual ossim_uint32 getScalarSizeInBytes() const
RTTI_DEF1(ossimRectilinearDataObject, "ossimRectilinearDataObject", ossimDataObject)
virtual void initialize()
Initializes m_dataBuffer to current spatial extents.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual ossimScalarType getScalarType() const
ossimRectilinearDataObject()
default constructor
static const char * SCALAR_TYPE_KW
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
virtual const ossimRectilinearDataObject & operator=(const ossimRectilinearDataObject &rhs)
assignment operator=
virtual ossim_uint32 getNumberOfDataComponents() const
ossimDataObjectStatus
Definitions for data object status.
virtual void setScalarType(ossimScalarType type)
See ossimScalarType in ossimConstants for a full list.
virtual std::ostream & print(std::ostream &out) const
Generic print method.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23