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

Loading...
Searching...
No Matches
GeoTessProfileConstant.h
Go to the documentation of this file.
1//- ****************************************************************************
2//-
3//- Copyright 2009 Sandia Corporation. Under the terms of Contract
4//- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5//- 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//- * Redistributions of source code must retain the above copyright notice,
14//- this list of conditions and the following disclaimer.
15//- * Redistributions in binary form must reproduce the above copyright
16//- notice, this list of conditions and the following disclaimer in the
17//- documentation and/or other materials provided with the distribution.
18//- * Neither the name of Sandia National Laboratories nor the names of its
19//- contributors may be used to endorse or promote products derived from
20//- this software without specific prior written permission.
21//-
22//- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23//- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24//- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25//- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26//- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27//- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28//- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29//- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30//- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31//- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32//- POSSIBILITY OF SUCH DAMAGE.
33//-
34//- ****************************************************************************
35
36#ifndef PROFILECONSTANT_OBJECT_H
37#define PROFILECONSTANT_OBJECT_H
38
39// **** _SYSTEM INCLUDES_ ******************************************************
40
41#include <iostream>
42#include <string>
43#include <fstream>
44
45// use standard library objects
46 using namespace std;
47
48// **** _LOCAL INCLUDES_ *******************************************************
49
50#include "GeoTessData.h"
51#include "GeoTessProfile.h"
52#include "GeoTessProfileType.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 GeoTessMetaData;
63
64// **** _CLASS DEFINITION_ *****************************************************
65
76 class GEOTESS_EXP_IMP GeoTessProfileConstant : virtual public GeoTessProfile
77{
78 private:
79
83 float radiusBottom;
84
88 float radiusTop;
89
93 GeoTessData* data;
94
98 int pointIndex;
99
103 GeoTessProfileConstant() : GeoTessProfile(), radiusBottom(0.0), radiusTop(0.0),
104 data(NULL), pointIndex(-1) {};
105
106 public:
107
111 GeoTessProfileConstant(float radBot, float radTop, GeoTessData* dat) :
112 GeoTessProfile(), radiusBottom(radBot), radiusTop(radTop),
113 data(dat), pointIndex(-1) {};
114
118 static string class_name() { return "ProfileConstant"; };
119
123 virtual int class_size() const
124 { return (int) sizeof(GeoTessProfileConstant); };
125
126 virtual LONG_INT getMemory() { return (LONG_INT)(sizeof(GeoTessProfileConstant) + data->getMemory()); };
127
133 virtual const GeoTessProfileType& getType() const
134 { return GeoTessProfileType::CONSTANT; };
135
139 virtual bool operator == (const GeoTessProfile& p) const
140 { return (GeoTessProfile::operator==(p) &&
141 (radiusBottom == p.getRadiusBottom()) &&
142 (radiusTop == p.getRadiusTop()) &&
143 (*data == p.getData(0)));
144 }
145
150 virtual float getRadius(int i) const
151 { return i == 0 ? radiusBottom : radiusTop; };
152
156 virtual int getNRadii() const { return 2; };
157
161 virtual int getNData() const { return 1; };
162
166 virtual float* getRadii()
167 { float* fa = new float [2]; fa[0] = radiusBottom; fa[1] = radiusTop; return fa; };
168
172 virtual GeoTessData** getData()
173 { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; };
174
178 virtual GeoTessData* getData(int i) { return data; };
179
183 virtual const GeoTessData& getData(int i) const { return *data; };
184
188 virtual void setData(const vector<GeoTessData*>& inData)
189 { delete data; data = inData[0]; }
190
194 virtual void setData(int index, GeoTessData* inData)
195 { delete data; data = inData; }
196
205 virtual double getValue(int attributeIndex, int nodeIndex) const
206 { return nodeIndex <= 1 ? data->getDouble(attributeIndex) : NaN_DOUBLE; }
207
217 virtual double getValue(const GeoTessInterpolatorType& rInterpType,
218 int attributeIndex, double radius, bool allowRadiusOutOfRange) const
219 {
220 if (!allowRadiusOutOfRange &&
221 ((radius < getRadiusBottom()) || (radius > getRadiusTop())))
222 return NaN_DOUBLE;
223
224 // default behavior is to simply return the data value for the first
225 // data object. This works for all the Profile classes that only support
226 // a single Data object like ProfileConstant, ProfileSurface, and
227 // ProfileThin. Profile classes for which the number of supported
228 // Data objects is not equal to 1 must override this method.
229
230 return getValue(attributeIndex, 0);
231 };
232
239 virtual double getValueTop(int attributeIndex) const
240 { return data->getDouble(attributeIndex); }
241
252 virtual bool isNaN(int nodeIndex, int attributeIndex)
253 {
254 return nodeIndex != 0 || data->isNaN(attributeIndex);
255 }
256
260 virtual void setRadii(const vector<float>& newRadii)
261 { radiusBottom = newRadii[0]; radiusTop = newRadii[1]; }
262
263 virtual void setRadius(int index, float radius)
264 {
265 switch (index)
266 {
267 case 0:
268 radiusBottom = radius;
269 break;
270 case 1:
271 radiusTop = radius;
272 break;
273 }
274 }
275
279 virtual float getRadiusTop() const { return radiusTop; };
280
284 virtual const GeoTessData& getDataTop() const { return *data; };
285
289 virtual GeoTessData* getDataTop() { return data; };
290
294 virtual float getRadiusBottom() const { return radiusBottom; };
295
299 virtual const GeoTessData& getDataBottom() const { return *data; };
300
304 virtual GeoTessData* getDataBottom() { return data; };
305
307
311 GeoTessProfileConstant(IFStreamBinary& ifs, GeoTessMetaData& gtmd) : GeoTessProfile()
312 { radiusBottom = ifs.readFloat(); radiusTop = ifs.readFloat();
313 data = GeoTessData::getData(ifs, gtmd); };
314
318 GeoTessProfileConstant(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile()
319 { radiusBottom = ifs.readFloat();
320 radiusTop = ifs.readFloat();
321 data = GeoTessData::getData(ifs, gtmd); };
322
327 virtual ~GeoTessProfileConstant() { if (data != NULL) delete data; };
328
332 virtual void write(IFStreamBinary& ofs)
333 {
334 ofs.writeByte((byte) GeoTessProfileType::CONSTANT.ordinal());
335 ofs.writeFloat(radiusBottom);
336 ofs.writeFloat(radiusTop);
337 data->write(ofs);
338 };
339
343 virtual void write(IFStreamAscii& ofs)
344 { ofs.writeInt(GeoTessProfileType::CONSTANT.ordinal());
345 ofs.writeString(" ");
346 ofs.writeFloat(radiusBottom);
347 ofs.writeString(" ");
348 ofs.writeFloat(radiusTop);
349 data->write(ofs);
350 ofs.writeNL();
351 };
352
361 virtual int findClosestRadiusIndex(double radius) const
362 { return abs(radiusTop - radius) < abs(radiusBottom - radius) ? 1 : 0; }
363
371 virtual void setPointIndex(int nodeIndex, int pntIndex)
372 { pointIndex = pntIndex; }
373
381 virtual void resetPointIndices() { pointIndex = -1; }
382
390 virtual int getPointIndex(int nodeIndex) const
391 { return pointIndex; }
392
396 virtual GeoTessProfile* copy()
397 {
398 return new GeoTessProfileConstant(radiusBottom, radiusTop, data->copy());
399 }
400
402
403}; // end class ProfileConstant
404
405} // end namespace geotess
406
407#endif // PROFILECONSTANT_OBJECT_H
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition CPPGlobals.h:71
LONG_INT
#define LONG_INT
Definition CPPGlobals.h:111
GeoTessData.h
GeoTessProfile.h
GeoTessProfileType.h
IFStreamAscii.h
IFStreamBinary.h
geotess::GeoTessData
Abstract base class that manages the data values attached to a single grid point.
Definition GeoTessData.h:76
geotess::GeoTessData::getData
static GeoTessData * getData(const GeoTessDataType &dataType, int nAttributes)
geotess::GeoTessInterpolatorType
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR,...
Definition GeoTessInterpolatorType.h:72
geotess::GeoTessMetaData
Basic metadata information about a GeoTessModel.
Definition GeoTessMetaData.h:97
geotess::GeoTessProfileConstant
A Profile object that defines two radii at the bottom and top of the associated layer,...
Definition GeoTessProfileConstant.h:77
geotess::GeoTessProfileConstant::getDataTop
virtual const GeoTessData & getDataTop() const
Definition GeoTessProfileConstant.h:284
geotess::GeoTessProfileConstant::getDataBottom
virtual const GeoTessData & getDataBottom() const
Definition GeoTessProfileConstant.h:299
geotess::GeoTessProfileConstant::getData
virtual const GeoTessData & getData(int i) const
Definition GeoTessProfileConstant.h:183
geotess::GeoTessProfileConstant::getData
virtual GeoTessData ** getData()
Definition GeoTessProfileConstant.h:172
geotess::GeoTessProfileConstant::setData
virtual void setData(const vector< GeoTessData * > &inData)
Definition GeoTessProfileConstant.h:188
geotess::GeoTessProfileConstant::getRadiusBottom
virtual float getRadiusBottom() const
Definition GeoTessProfileConstant.h:294
geotess::GeoTessProfileConstant::getRadii
virtual float * getRadii()
Definition GeoTessProfileConstant.h:166
geotess::GeoTessProfileConstant::isNaN
virtual bool isNaN(int nodeIndex, int attributeIndex)
Definition GeoTessProfileConstant.h:252
geotess::GeoTessProfileConstant::getValueTop
virtual double getValueTop(int attributeIndex) const
Definition GeoTessProfileConstant.h:239
geotess::GeoTessProfileConstant::getValue
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double radius, bool allowRadiusOutOfRange) const
Definition GeoTessProfileConstant.h:217
geotess::GeoTessProfileConstant::getData
virtual GeoTessData * getData(int i)
Definition GeoTessProfileConstant.h:178
geotess::GeoTessProfileConstant::setData
virtual void setData(int index, GeoTessData *inData)
Definition GeoTessProfileConstant.h:194
geotess::GeoTessProfileConstant::class_size
virtual int class_size() const
Definition GeoTessProfileConstant.h:123
geotess::GeoTessProfileConstant::getNRadii
virtual int getNRadii() const
Definition GeoTessProfileConstant.h:156
geotess::GeoTessProfileConstant::setRadius
virtual void setRadius(int index, float radius)
Definition GeoTessProfileConstant.h:263
geotess::GeoTessProfileConstant::setRadii
virtual void setRadii(const vector< float > &newRadii)
Definition GeoTessProfileConstant.h:260
geotess::GeoTessProfileConstant::getRadius
virtual float getRadius(int i) const
Definition GeoTessProfileConstant.h:150
geotess::GeoTessProfileConstant::getType
virtual const GeoTessProfileType & getType() const
Definition GeoTessProfileConstant.h:133
geotess::GeoTessProfileConstant::getRadiusTop
virtual float getRadiusTop() const
Definition GeoTessProfileConstant.h:279
geotess::GeoTessProfileConstant::GeoTessProfileConstant
GeoTessProfileConstant(float radBot, float radTop, GeoTessData *dat)
Definition GeoTessProfileConstant.h:111
geotess::GeoTessProfileConstant::getValue
virtual double getValue(int attributeIndex, int nodeIndex) const
Definition GeoTessProfileConstant.h:205
geotess::GeoTessProfileConstant::getMemory
virtual LONG_INT getMemory()
Definition GeoTessProfileConstant.h:126
geotess::GeoTessProfileConstant::getDataTop
virtual GeoTessData * getDataTop()
Definition GeoTessProfileConstant.h:289
geotess::GeoTessProfileConstant::class_name
static string class_name()
Definition GeoTessProfileConstant.h:118
geotess::GeoTessProfileConstant::getDataBottom
virtual GeoTessData * getDataBottom()
Definition GeoTessProfileConstant.h:304
geotess::GeoTessProfileConstant::getNData
virtual int getNData() const
Definition GeoTessProfileConstant.h:161
geotess::GeoTessProfile
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition GeoTessProfile.h:97
geotess::GeoTessProfile::getRadiusTop
virtual float getRadiusTop() const
geotess::GeoTessProfile::getData
virtual GeoTessData ** getData()
geotess::GeoTessProfile::getRadiusBottom
virtual float getRadiusBottom() const
geotess::GeoTessProfileType
Enumeration of the valid Profile types, including EMPTY, THIN, CONSTANT, NPOINT and SURFACE.
Definition GeoTessProfileType.h:70
geotess::GeoTessProfileType::CONSTANT
static const GeoTessProfileType CONSTANT
Definition GeoTessProfileType.h:117
geotess::IFStreamBinary
Opens a file for binary read and write access.
Definition IFStreamBinary.h:80
geotess::IFStreamBinary::readFloat
float readFloat()
Definition IFStreamBinary.h:1117
geotess
Definition ArrayReuse.h:55