GeoTessCPP  2.1
Software to facilitate storage and retrieval of 3D information about the Earth.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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 
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 
131  virtual const GeoTessProfileType& getType() const
132  { return GeoTessProfileType::CONSTANT; };
133 
137  virtual bool operator == (const GeoTessProfile& p) const
138  { return (GeoTessProfile::operator==(p) &&
139  (radiusBottom == p.getRadiusBottom()) &&
140  (radiusTop == p.getRadiusTop()) &&
141  (*data == p.getData(0)));
142  }
143 
148  virtual float getRadius(int i) const
149  { return i == 0 ? radiusBottom : radiusTop; };
150 
154  virtual int getNRadii() const { return 2; };
155 
159  virtual int getNData() const { return 1; };
160 
164  virtual float* getRadii()
165  { float* fa = new float [2]; fa[0] = radiusBottom; fa[1] = radiusTop; return fa; };
166 
170  virtual GeoTessData** getData()
171  { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; };
172 
176  virtual GeoTessData* getData(int i) { return data; };
177 
181  virtual const GeoTessData& getData(int i) const { return *data; };
182 
186  virtual void setData(const vector<GeoTessData*>& inData)
187  { delete data; data = inData[0]; }
188 
192  virtual void setData(int index, GeoTessData* inData)
193  { delete data; data = inData; }
194 
203  virtual double getValue(int attributeIndex, int nodeIndex) const
204  { return nodeIndex <= 1 ? data->getDouble(attributeIndex) : NaN_DOUBLE; }
205 
215  virtual double getValue(const GeoTessInterpolatorType& rInterpType,
216  int attributeIndex, double radius, bool allowRadiusOutOfRange) const
217  {
218  if (!allowRadiusOutOfRange &&
219  ((radius < getRadiusBottom()) || (radius > getRadiusTop())))
220  return NaN_DOUBLE;
221 
222  // default behavior is to simply return the data value for the first
223  // data object. This works for all the Profile classes that only support
224  // a single Data object like ProfileConstant, ProfileSurface, and
225  // ProfileThin. Profile classes for which the number of supported
226  // Data objects is not equal to 1 must override this method.
227 
228  return getValue(attributeIndex, 0);
229  };
230 
237  virtual double getValueTop(int attributeIndex) const
238  { return data->getDouble(attributeIndex); }
239 
250  virtual bool isNaN(int nodeIndex, int attributeIndex)
251  {
252  return nodeIndex != 0 || data->isNaN(attributeIndex);
253  }
254 
258  virtual void setRadii(const vector<float>& newRadii)
259  { radiusBottom = newRadii[0]; radiusTop = newRadii[1]; }
260 
261  virtual void setRadius(int index, float radius)
262  {
263  switch (index)
264  {
265  case 0:
266  radiusBottom = radius;
267  break;
268  case 1:
269  radiusTop = radius;
270  break;
271  }
272  }
273 
277  virtual float getRadiusTop() const { return radiusTop; };
278 
282  virtual const GeoTessData& getDataTop() const { return *data; };
283 
287  virtual GeoTessData* getDataTop() { return data; };
288 
292  virtual float getRadiusBottom() const { return radiusBottom; };
293 
297  virtual const GeoTessData& getDataBottom() const { return *data; };
298 
302  virtual GeoTessData* getDataBottom() { return data; };
303 
305 
310  { radiusBottom = ifs.readFloat(); radiusTop = ifs.readFloat();
311  data = GeoTessData::getData(ifs, gtmd); };
312 
316  GeoTessProfileConstant(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile()
317  { radiusBottom = ifs.readFloat();
318  radiusTop = ifs.readFloat();
319  data = GeoTessData::getData(ifs, gtmd); };
320 
325  virtual ~GeoTessProfileConstant() { if (data != NULL) delete data; };
326 
330  virtual void write(IFStreamBinary& ofs)
331  {
332  ofs.writeByte((byte) GeoTessProfileType::CONSTANT.ordinal());
333  ofs.writeFloat(radiusBottom);
334  ofs.writeFloat(radiusTop);
335  data->write(ofs);
336  };
337 
341  virtual void write(IFStreamAscii& ofs)
342  { ofs.writeInt(GeoTessProfileType::CONSTANT.ordinal());
343  ofs.writeString(" ");
344  ofs.writeFloat(radiusBottom);
345  ofs.writeString(" ");
346  ofs.writeFloat(radiusTop);
347  data->write(ofs);
348  ofs.writeNL();
349  };
350 
359  virtual int findClosestRadiusIndex(double radius) const
360  { return abs(radiusTop - radius) < abs(radiusBottom - radius) ? 1 : 0; }
361 
369  virtual void setPointIndex(int nodeIndex, int pntIndex)
370  { pointIndex = pntIndex; }
371 
379  virtual void resetPointIndices() { pointIndex = -1; }
380 
388  virtual int getPointIndex(int nodeIndex) const
389  { return pointIndex; }
390 
394  virtual GeoTessProfile* copy()
395  {
396  return new GeoTessProfileConstant(radiusBottom, radiusTop, data->copy());
397  }
398 
400 
401 }; // end class ProfileConstant
402 
403 } // end namespace geotess
404 
405 #endif // PROFILECONSTANT_OBJECT_H
virtual float getRadiusBottom() const
Definition: GeoTessProfileConstant.h:292
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double radius, bool allowRadiusOutOfRange) const
Definition: GeoTessProfileConstant.h:215
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:79
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(int i)
Definition: GeoTessProfileConstant.h:176
virtual GeoTessData * getDataBottom()
Definition: GeoTessProfileConstant.h:302
virtual GeoTessData ** getData()
virtual int getNData() const
Definition: GeoTessProfileConstant.h:159
static string class_name()
Definition: GeoTessProfileConstant.h:118
virtual const GeoTessProfileType & getType() const
Definition: GeoTessProfileConstant.h:131
virtual int class_size() const
Definition: GeoTessProfileConstant.h:123
virtual bool isNaN(int nodeIndex, int attributeIndex)
Definition: GeoTessProfileConstant.h:250
virtual void setData(const vector< GeoTessData * > &inData)
Definition: GeoTessProfileConstant.h:186
A Profile object that defines two radii at the bottom and top of the associated layer, and a single Data object that represents the model values throughout the layer.
Definition: GeoTessProfileConstant.h:76
virtual float getRadiusTop() const
virtual GeoTessData ** getData()
Definition: GeoTessProfileConstant.h:170
virtual GeoTessData * getDataTop()
Definition: GeoTessProfileConstant.h:287
#define byte
signed-byte typedef
Definition: CPPGlobals.h:94
virtual double getValueTop(int attributeIndex) const
Definition: GeoTessProfileConstant.h:237
float readFloat()
Definition: IFStreamBinary.h:1117
virtual float * getRadii()
Definition: GeoTessProfileConstant.h:164
virtual float getRadius(int i) const
Definition: GeoTessProfileConstant.h:148
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
GeoTessProfileConstant(float radBot, float radTop, GeoTessData *dat)
Definition: GeoTessProfileConstant.h:111
virtual void setRadii(const vector< float > &newRadii)
Definition: GeoTessProfileConstant.h:258
virtual void setData(int index, GeoTessData *inData)
Definition: GeoTessProfileConstant.h:192
virtual float getRadiusTop() const
Definition: GeoTessProfileConstant.h:277
Basic metadata information about a GeoTessModel.
Definition: GeoTessMetaData.h:96
virtual const GeoTessData & getDataBottom() const
Definition: GeoTessProfileConstant.h:297
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
virtual int getNRadii() const
Definition: GeoTessProfileConstant.h:154
virtual double getValue(int attributeIndex, int nodeIndex) const
Definition: GeoTessProfileConstant.h:203
virtual const GeoTessData & getData(int i) const
Definition: GeoTessProfileConstant.h:181
virtual const GeoTessData & getDataTop() const
Definition: GeoTessProfileConstant.h:282
virtual void setRadius(int index, float radius)
Definition: GeoTessProfileConstant.h:261
virtual float getRadiusBottom() const