GeoTessCPP: rstt/GeoTessCPP/include/GeoTessDataArray.h Source File

GeoTessCPP 2.2.3 Software to facilitate storage and retrieval of 3D information about the Earth.

GeoTessDataArray.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government retains certain rights in this software.
6 //-
7 //- BSD Open Source License
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37
38 #ifndef DATAARRAY_OBJECT_H
39 #define DATAARRAY_OBJECT_H
40
41 // **** _SYSTEM INCLUDES_ ******************************************************
42
43 #include <iostream>
44 #include <fstream>
45
46 // use standard library objects
47 using namespace std;
48
49 // **** _LOCAL INCLUDES_ *******************************************************
50
51 #include "GeoTessDataType.h"
52 #include "GeoTessData.h"
53 #include "IFStreamAscii.h"
54 #include "IFStreamBinary.h"
55
56 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
57
58 namespace geotess {
59
60 // **** _FORWARD REFERENCES_ ***************************************************
61
62 //class IFStreamAscii;
63
64 // **** _CLASS DEFINITION_ *****************************************************
65
73 template<typename T>
74 class GEOTESS_EXP_IMP GeoTessDataArray : public GeoTessData
75 {
76 private:
77
81 int nValues;
82
86 T* values;
87
91 GeoTessDataArray() : GeoTessData(), nValues(0), values(NULL) {};
92
93 public:
94
99 GeoTessDataArray(T v[], const int& n) : GeoTessData(), nValues(n), values(NULL)
100 {
101 values = new T [nValues];
102 for (int i = 0; i < nValues; ++i) values[i] = v[i];
103 }
104
109 GeoTessDataArray(const vector<T>& v) : GeoTessData(), nValues(v.size()), values(NULL)
110 {
111 values = new T [nValues];
112 for (int i = 0; i < nValues; ++i) values[i] = v[i];
113 }
114
118 GeoTessDataArray(const int& n) : GeoTessData(), nValues(n), values(NULL)
119 {
120 values = new T [nValues];
121 for (int i = 0; i < n; ++i) values[i] = (T) 0;
122 }
123
125
130 GeoTessDataArray(IFStreamAscii& ifs, int n) : GeoTessData(), nValues(n), values(NULL)
131 {
132 if (nValues > 0)
133 {
134 values = new T [nValues];
135 for (int i = 0; i < nValues; ++i) ifs.readType(values[i]);
136 }
137 }
138
143 GeoTessDataArray(IFStreamBinary& ifs, int n) : GeoTessData(), nValues(n), values(NULL)
144 {
145 if (nValues > 0)
146 {
147 values = new T [nValues];
148 ifs.readTypeArray(values, nValues);
149 }
150 }
151
161 GeoTessDataArray(IFStreamAscii& ifs, int n, vector<int>& filter) : GeoTessData(), nValues(n), values(NULL)
162 {
163 if (nValues > 0)
164 {
165 values = new T [nValues];
166 T val;
167 for (int i=0; i<(int)filter.size(); ++i)
168 {
169 ifs.readType(val);
170 if (filter[i] >= 0)
171 values[filter[i]] = val;
172 }
173 }
174 }
175
185 GeoTessDataArray(IFStreamBinary& ifs, int n, vector<int>& filter) : GeoTessData(), nValues(n), values(NULL)
186 {
187 if (nValues > 0)
188 {
189 values = new T [nValues];
190
191 T val;
192 for (int i=0; i<(int)filter.size(); ++i)
193 {
194 ifs.readType(val);
195 if (filter[i] >= 0)
196 values[filter[i]] = val;
197 }
198 }
199 }
200
204 virtual ~GeoTessDataArray()
205 { if (values != NULL) delete [] values; };
206
210 virtual void write(IFStreamBinary& ofs)
211 {
212 for (int i = 0; i < nValues; ++i) ofs.writeType(values[i]);
213 }
214
218 virtual void write(IFStreamAscii& ofs)
219 {
220 for (int i = 0; i < nValues; ++i)
221 { ofs.writeString(" "); ofs.writeType(values[i]); }
222 }
223
225
226 /*
227 * Return DataType.
228 */
229 virtual const GeoTessDataType& getDataType() const { return GeoTessDataType::NONE; };
230
234 virtual int size() const { return nValues; };
235
236 virtual LONG_INT getMemory()
237 { return (LONG_INT)sizeof(GeoTessDataArray<T>) + (LONG_INT)nValues * (LONG_INT)sizeof(T); }
238
243 bool operator == (const GeoTessDataArray<T>& d) const
244 {
245 if (!GeoTessData::operator==(d)) return false;
246 if (nValues != d.nValues) return false;
247
248 for (int i = 0; i < nValues; ++i)
249 if ((values[i] != d.values[i]) &&
250 !(isNaN(i) && d.isNaN(i))) return false;
251
252 return true;
253 }
254
259 virtual bool operator == (const GeoTessData& d) const
260 { return operator==(*((const GeoTessDataArray<T>*) &d)); }
261
265 virtual double getDouble(int attributeIndex) const
266 { return (double) values[attributeIndex]; }
267
271 virtual float getFloat(int attributeIndex) const
272 { return (float) values[attributeIndex]; };
273
277 virtual LONG_INT getLong(int attributeIndex) const
278 { return (LONG_INT) values[attributeIndex]; };
279
283 virtual int getInt(int attributeIndex) const
284 { return (int) values[attributeIndex]; };
285
289 virtual short getShort(int attributeIndex) const
290 { return (short) values[attributeIndex]; };
291
295 virtual byte getByte(int attributeIndex) const
296 { return (byte) values[attributeIndex]; };
297
301 virtual void getValue(int attributeIndex, double& val) const
302 { val = (double) values[attributeIndex]; };
303
307 virtual void getValue(int attributeIndex, float& val) const
308 { val = (float) values[attributeIndex]; };
309
313 virtual void getValue(int attributeIndex, LONG_INT& val) const
314 { val = (LONG_INT) values[attributeIndex]; };
315
319 virtual void getValue(int attributeIndex, int& val) const
320 { val = (int) values[attributeIndex]; };
321
325 virtual void getValue(int attributeIndex, short& val) const
326 { val = (short) values[attributeIndex]; };
327
331 virtual void getValue(int attributeIndex, byte& val) const
332 { val = (byte) values[attributeIndex]; };
333
337 virtual void getValues(double vals[], const int& n)
338 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (double) values[i]; }
339
343 virtual void getValues(float vals[], const int& n)
344 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (float) values[i]; }
345
349 virtual void getValues(LONG_INT vals[], const int& n)
350 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (LONG_INT) values[i]; }
351
355 virtual void getValues(int vals[], const int& n)
356 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (int) values[i]; }
357
361 virtual void getValues(short vals[], const int& n)
362 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (short) values[i]; }
363
367 virtual void getValues(byte vals[], const int& n)
368 { for (int i=0; i<n && i<nValues; ++i) vals[i] = (byte) values[i]; }
369
373 virtual GeoTessData& setValue(int attributeIndex, double v)
374 { values[attributeIndex] = (T) v; return *this; }
375
379 virtual GeoTessData& setValue(int attributeIndex, float v)
380 { values[attributeIndex] = (T) v; return *this; }
381
385 virtual GeoTessData& setValue(int attributeIndex, LONG_INT v)
386 { values[attributeIndex] = (T) v; return *this; }
387
391 virtual GeoTessData& setValue(int attributeIndex, int v)
392 { values[attributeIndex] = (T) v; return *this; }
393
397 virtual GeoTessData& setValue(int attributeIndex, short v)
398 { values[attributeIndex] = (T) v; return *this; };
399
403 virtual GeoTessData& setValue(int attributeIndex, byte v)
404 { values[attributeIndex] = (T) v; return *this; }
405
417 virtual bool isNaN(int attributeIndex) const {return false;};
418
422 virtual GeoTessDataArray<T>* copy()
423 {
424 return new GeoTessDataArray<T>(values, nValues);
425 }
426
427 }; // end class DataArray
428
430
434 template<>
435 inline bool GeoTessDataArray<double>::isNaN(int attributeIndex) const
436 {
437 return (isnan(values[attributeIndex]));
438 }
439
443 template<>
444 inline bool GeoTessDataArray<float>::isNaN(int attributeIndex) const
445 {
446 double v = (double) values[attributeIndex];
447 return (isnan(v));
448 }
449
453 template<>
454 inline const GeoTessDataType& GeoTessDataArray<double>::getDataType() const
455 {
456 return GeoTessDataType::DOUBLE;
457 }
458
462 template<>
463 inline const GeoTessDataType& GeoTessDataArray<float>::getDataType() const
464 {
465 return GeoTessDataType::FLOAT;
466 }
467
471 template<>
472 inline const GeoTessDataType& GeoTessDataArray<LONG_INT>::getDataType() const
473 {
474 return GeoTessDataType::LONG;
475 }
476
480 template<>
481 inline const GeoTessDataType& GeoTessDataArray<int>::getDataType() const
482 {
483 return GeoTessDataType::INT;
484 }
485
489 template<>
490 inline const GeoTessDataType& GeoTessDataArray<short>::getDataType() const
491 {
492 return GeoTessDataType::SHORT;
493 }
494
498 template<>
499 inline const GeoTessDataType& GeoTessDataArray<byte>::getDataType() const
500 {
501 return GeoTessDataType::BYTE;
502 }
503
505
506 } // end namespace geotess
507
508 #endif // DATAARRAY_OBJECT_H
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, float &val) const
Definition: GeoTessDataArray.h:307
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, double &val) const
Definition: GeoTessDataArray.h:301
geotess::GeoTessDataArray::getValues
virtual void getValues(float vals[], const int &n)
Definition: GeoTessDataArray.h:343
geotess::GeoTessDataArray::getValues
virtual void getValues(LONG_INT vals[], const int &n)
Definition: GeoTessDataArray.h:349
geotess
Definition: ArrayReuse.h:57
IFStreamBinary.h
GeoTessData.h
geotess::GeoTessDataArray::getDouble
virtual double getDouble(int attributeIndex) const
Definition: GeoTessDataArray.h:265
geotess::GeoTessDataArray::GeoTessDataArray
GeoTessDataArray(T v[], const int &n)
Definition: GeoTessDataArray.h:99
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, LONG_INT &val) const
Definition: GeoTessDataArray.h:313
geotess::GeoTessDataArray::GeoTessDataArray
GeoTessDataArray(const int &n)
Definition: GeoTessDataArray.h:118
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, short &val) const
Definition: GeoTessDataArray.h:325
geotess::GeoTessDataArray::getFloat
virtual float getFloat(int attributeIndex) const
Definition: GeoTessDataArray.h:271
geotess::GeoTessDataArray::GeoTessDataArray
GeoTessDataArray(const vector< T > &v)
Definition: GeoTessDataArray.h:109
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, int &val) const
Definition: GeoTessDataArray.h:319
geotess::GeoTessDataArray::getLong
virtual LONG_INT getLong(int attributeIndex) const
Definition: GeoTessDataArray.h:277
geotess::GeoTessDataArray::getValues
virtual void getValues(double vals[], const int &n)
Definition: GeoTessDataArray.h:337
geotess::GeoTessDataArray::getValue
virtual void getValue(int attributeIndex, byte &val) const
Definition: GeoTessDataArray.h:331
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, byte v)
Definition: GeoTessDataArray.h:403
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, LONG_INT v)
Definition: GeoTessDataArray.h:385
geotess::GeoTessDataArray::getDataType
virtual const GeoTessDataType & getDataType() const
Definition: GeoTessDataArray.h:229
geotess::IFStreamAscii
Opens ascii file for read and write access.
Definition: IFStreamAscii.h:83
geotess::GeoTessDataType
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
Definition: GeoTessDataType.h:70
LONG_INT
#define LONG_INT
Definition: CPPGlobals.h:113
geotess::GeoTessDataArray::size
virtual int size() const
Definition: GeoTessDataArray.h:234
geotess::GeoTessDataArray::getInt
virtual int getInt(int attributeIndex) const
Definition: GeoTessDataArray.h:283
geotess::GeoTessDataArray::getShort
virtual short getShort(int attributeIndex) const
Definition: GeoTessDataArray.h:289
geotess::GeoTessData
Abstract base class that manages the data values attached to a single grid point.
Definition: GeoTessData.h:78
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, float v)
Definition: GeoTessDataArray.h:379
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:73
geotess::GeoTessDataArray::getByte
virtual byte getByte(int attributeIndex) const
Definition: GeoTessDataArray.h:295
IFStreamAscii.h
geotess::GeoTessDataArray::getValues
virtual void getValues(byte vals[], const int &n)
Definition: GeoTessDataArray.h:367
byte
#define byte
signed-byte typedef
Definition: CPPGlobals.h:96
geotess::GeoTessDataArray::getValues
virtual void getValues(int vals[], const int &n)
Definition: GeoTessDataArray.h:355
geotess::GeoTessDataArray::getValues
virtual void getValues(short vals[], const int &n)
Definition: GeoTessDataArray.h:361
geotess::IFStreamAscii::readType
bool readType(byte &b)
Definition: IFStreamAscii.h:451
geotess::GeoTessDataArray::isNaN
virtual bool isNaN(int attributeIndex) const
Definition: GeoTessDataArray.h:417
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, double v)
Definition: GeoTessDataArray.h:373
GeoTessDataType.h
geotess::GeoTessDataArray
Manages a 1D array of data values attached to a single grid node.
Definition: GeoTessData.h:64
geotess::GeoTessDataArray::getMemory
virtual LONG_INT getMemory()
Definition: GeoTessDataArray.h:236
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, int v)
Definition: GeoTessDataArray.h:391
geotess::GeoTessDataArray::setValue
virtual GeoTessData & setValue(int attributeIndex, short v)
Definition: GeoTessDataArray.h:397
geotess::GeoTessDataArray::copy
virtual GeoTessDataArray< T > * copy()
Definition: GeoTessDataArray.h:422