GeoTessCPP  2.2
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessProfileThin.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 PROFILETHIN_OBJECT_H
37 #define PROFILETHIN_OBJECT_H
38 
39 // **** _SYSTEM INCLUDES_ ******************************************************
40 
41 #include <iostream>
42 #include <fstream>
43 #include <string>
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 
74 {
75 private:
76 
80  float radius;
81 
85  GeoTessData* data;
86 
90  int pointIndex;
91 
95  GeoTessProfileThin() : GeoTessProfile(), radius(0.0), data(NULL),
96  pointIndex(-1) {};
97 
98 public:
99 
103  GeoTessProfileThin(float rad, GeoTessData* dat) :
104  GeoTessProfile(), radius(rad), data(dat),
105  pointIndex(-1) {};
106 
110  static string class_name() { return "ProfileThin"; };
111 
115  virtual int class_size() const
116  { return (int) sizeof(GeoTessProfileThin); };
117 
118  virtual LONG_INT getMemory() { return (LONG_INT)sizeof(GeoTessProfileThin) + data->getMemory(); }
119 
125  virtual const GeoTessProfileType& getType() const
126  { return GeoTessProfileType::THIN; };
127 
131  virtual bool operator == (const GeoTessProfile& p) const
132  { return (GeoTessProfile::operator==(p) && (radius == p.getRadius(0)) && (*data == p.getData(0))); }
133 
142  virtual double getValue(int attributeIndex, int nodeIndex) const
143  { return nodeIndex == 0 ? data->getDouble(attributeIndex) : NaN_DOUBLE; }
144 
154  virtual double getValue(const GeoTessInterpolatorType& rInterpType,
155  int attributeIndex, double r, bool allowRadiusOutOfRange) const
156  {
157  if (!allowRadiusOutOfRange &&
158  ((r < getRadiusBottom()) || (r > getRadiusTop())))
159  return NaN_DOUBLE;
160 
161  // default behavior is to simply return the data value for the first
162  // data object. This works for all the Profile classes that only support
163  // a single Data object like ProfileConstant, ProfileSurface, and
164  // ProfileThin. Profile classes for which the number of supported
165  // Data objects is not equal to 1 must override this method.
166 
167  return getValue(attributeIndex, 0);
168  };
169 
176  virtual double getValueTop(int attributeIndex) const
177  { return data->getDouble(attributeIndex); }
178 
189  virtual bool isNaN(int nodeIndex, int attributeIndex)
190  {
191  return nodeIndex != 0 || data->isNaN(attributeIndex);
192  }
193 
198  virtual float getRadius(int i) const { return radius; };
199 
203  virtual int getNRadii() const { return 1; };
204 
208  virtual int getNData() const { return 1; };
209 
213  virtual float* getRadii()
214  { float* fa = new float [1]; fa[0] = radius; return fa; };
215 
219  virtual GeoTessData** getData()
220  { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; };
221 
225  virtual GeoTessData* getData(int i) { return data; };
226 
230  virtual const GeoTessData& getData(int i) const { return *data; };
231 
235  virtual void setData(const vector<GeoTessData*>& inData)
236  { delete data; data = inData[0]; }
237 
241  virtual void setRadii(const vector<float>& newRadii)
242  { radius = newRadii[0]; }
243 
244  virtual void setRadius(int index, float newRadius)
245  { if (index == 0) radius = newRadius; }
246 
250  virtual void setData(int index, GeoTessData* inData)
251  { delete data; data = inData; }
252 
256  virtual float getRadiusTop() const { return radius; };
257 
261  virtual const GeoTessData& getDataTop() const { return *data; };
262 
266  virtual GeoTessData* getDataTop() { return data; };
267 
271  virtual float getRadiusBottom() const { return radius; };
272 
276  virtual const GeoTessData& getDataBottom() const { return *data; };
277 
281  virtual GeoTessData* getDataBottom() { return data; };
282 
284 
289  radius(-1.0), data(NULL), pointIndex(-1)
290  { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); };
291 
295  GeoTessProfileThin(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile(),
296  radius(-1.0), data(NULL), pointIndex(-1)
297  { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); };
298 
303  virtual ~GeoTessProfileThin() { if (data != NULL) delete data; };
304 
308  virtual void write(IFStreamBinary& ofs)
309  { ofs.writeByte((byte) GeoTessProfileType::THIN.ordinal());
310  ofs.writeFloat(radius); data->write(ofs); };
311 
315  virtual void write(IFStreamAscii& ofs)
316  { ofs.writeInt(GeoTessProfileType::THIN.ordinal());
317  ofs.writeString(" ");
318  ofs.writeFloat(radius);
319  data->write(ofs);
320  ofs.writeNL(); };
321 
330  virtual int findClosestRadiusIndex(double r) const
331  { return 0; }
332 
340  virtual void setPointIndex(int nodeIndex, int pntIndex)
341  { pointIndex = pntIndex; }
342 
350  virtual void resetPointIndices() { pointIndex = -1; }
351 
359  virtual int getPointIndex(int nodeIndex) const
360  { return pointIndex; }
361 
365  virtual GeoTessProfile* copy()
366  {
367  return new GeoTessProfileThin(radius, data->copy());
368  }
369 
371 
372 }; // end class ProfileThin
373 
374 } // end namespace geotess
375 
376 #endif // PROFILETHIN_OBJECT_H
virtual double getValue(int attributeIndex, int nodeIndex) const
Retrieve the value of the specified attribute from this profile at the specified node index...
Definition: GeoTessProfileThin.h:142
virtual float getRadius(int i) const
Get the i'th radius value in this profile in km.
Definition: GeoTessProfileThin.h:198
virtual void setData(const vector< GeoTessData * > &inData)
Resets the data object to the new input data.
Definition: GeoTessProfileThin.h:235
virtual double getDouble(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a double value.
virtual LONG_INT getMemory()
virtual void setRadii(const vector< float > &newRadii)
Replace the radii currently associated with this Profile with new values.
Definition: GeoTessProfileThin.h:241
virtual void setRadius(int index, float newRadius)
Replace the radius at the specified nodeIndex.
Definition: GeoTessProfileThin.h:244
virtual GeoTessData * getDataTop()
Get the Data object at the top of the profile.
Definition: GeoTessProfileThin.h:266
virtual int class_size() const
Returns the class size.
Definition: GeoTessProfileThin.h:115
virtual double getValueTop(int attributeIndex) const
Retrieve the value of the specified attribute at the top of the layer.
Definition: GeoTessProfileThin.h:176
virtual float * getRadii()
Retrieve a deeep copy of the radii values in km.
Definition: GeoTessProfileThin.h:213
Definition: ArrayReuse.h:55
virtual float getRadiusTop() const
Get the radius at the top of the profile, in km.
Definition: GeoTessProfileThin.h:256
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:79
static string class_name()
Returns the class name.
Definition: GeoTessProfileThin.h:110
GeoTessProfileThin(float rad, GeoTessData *dat)
Default constructor.
Definition: GeoTessProfileThin.h:103
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR, NATURAL_NEIGHBOR and CUBIC_SPLINE.
Definition: GeoTessInterpolatorType.h:71
Enumeration of the valid Profile types, including EMPTY, THIN, CONSTANT, NPOINT and SURFACE...
Definition: GeoTessProfileType.h:69
virtual GeoTessData ** getData()
Retrieve a shallow copy of the array of Data objects associated with this Profile.
virtual LONG_INT getMemory()
Definition: GeoTessProfileThin.h:118
virtual int getNRadii() const
Get the number of radii that comprise this profile.
Definition: GeoTessProfileThin.h:203
virtual void setData(int index, GeoTessData *inData)
Resets the data object at index to the new input data.
Definition: GeoTessProfileThin.h:250
virtual float getRadiusBottom() const
Get the radius at the bottom of the profile, in km.
Definition: GeoTessProfileThin.h:271
virtual bool isNaN(int attributeIndex) const
Returns true if the specified attribute is NaN.
#define byte
signed-byte typedef
Definition: CPPGlobals.h:94
float readFloat()
Read float data.
Definition: IFStreamBinary.h:1117
virtual GeoTessData * getDataBottom()
Get the Data object at the bottom of the profile.
Definition: GeoTessProfileThin.h:281
#define LONG_INT
Definition: CPPGlobals.h:111
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition: GeoTessProfile.h:96
Abstract base class that manages the data values attached to a single grid point. ...
Definition: GeoTessData.h:75
virtual const GeoTessData & getDataBottom() const
Get the Data object at the bottom of the profile.
Definition: GeoTessProfileThin.h:276
virtual int getNData() const
Get the number of Data objects that comprise this profile.
Definition: GeoTessProfileThin.h:208
virtual const GeoTessData & getData(int i) const
Retrieve a reference the i'th Data object.
Definition: GeoTessProfileThin.h:230
Basic metadata information about a GeoTessModel.
Definition: GeoTessMetaData.h:95
virtual bool isNaN(int nodeIndex, int attributeIndex)
Return true if the specified Data value is NaN.
Definition: GeoTessProfileThin.h:189
virtual const GeoTessProfileType & getType() const
Returns ProfileType (THIN).
Definition: GeoTessProfileThin.h:125
virtual GeoTessData * getData(int i)
Retrieve a reference the i'th Data object.
Definition: GeoTessProfileThin.h:225
virtual GeoTessData ** getData()
Retrieve a shallow copy of all of the Data objects associated with thisProfile.
Definition: GeoTessProfileThin.h:219
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double r, bool allowRadiusOutOfRange) const
Retrieve the value of the specified attribute interpolated at the specified radius.
Definition: GeoTessProfileThin.h:154
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual float getRadius(int i) const
Get the i'th radius value in this profile in km.
virtual const GeoTessData & getDataTop() const
Get the Data object at the top of the profile.
Definition: GeoTessProfileThin.h:261
A Profile object consiting of a single radius value and a single Data object.
Definition: GeoTessProfileThin.h:73