GeoTessCPP  2.2.3
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessProfileConstant.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 PROFILECONSTANT_OBJECT_H
39 #define PROFILECONSTANT_OBJECT_H
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 
43 #include <iostream>
44 #include <string>
45 #include <fstream>
46 
47 // use standard library objects
48 using namespace std;
49 
50 // **** _LOCAL INCLUDES_ *******************************************************
51 
52 #include "GeoTessData.h"
53 #include "GeoTessProfile.h"
54 #include "GeoTessProfileType.h"
55 #include "IFStreamAscii.h"
56 #include "IFStreamBinary.h"
57 
58 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
59 
60 namespace geotess {
61 
62 // **** _FORWARD REFERENCES_ ***************************************************
63 
64 class GeoTessMetaData;
65 
66 // **** _CLASS DEFINITION_ *****************************************************
67 
79 {
80  private:
81 
85  float radiusBottom;
86 
90  float radiusTop;
91 
95  GeoTessData* data;
96 
100  int pointIndex;
101 
105  GeoTessProfileConstant() : GeoTessProfile(), radiusBottom(0.0), radiusTop(0.0),
106  data(NULL), pointIndex(-1) {};
107 
108  public:
109 
113  GeoTessProfileConstant(float radBot, float radTop, GeoTessData* dat) :
114  GeoTessProfile(), radiusBottom(radBot), radiusTop(radTop),
115  data(dat), pointIndex(-1) {};
116 
120  static string class_name() { return "ProfileConstant"; };
121 
125  virtual int class_size() const
126  { return (int) sizeof(GeoTessProfileConstant); };
127 
128  virtual LONG_INT getMemory() { return (LONG_INT)(sizeof(GeoTessProfileConstant) + data->getMemory()); };
129 
135  virtual const GeoTessProfileType& getType() const
136  { return GeoTessProfileType::CONSTANT; };
137 
141  virtual bool operator == (const GeoTessProfile& p) const
142  { return (GeoTessProfile::operator==(p) &&
143  (radiusBottom == p.getRadiusBottom()) &&
144  (radiusTop == p.getRadiusTop()) &&
145  (*data == p.getData(0)));
146  }
147 
152  virtual float getRadius(int i) const
153  { return i == 0 ? radiusBottom : radiusTop; };
154 
158  virtual int getNRadii() const { return 2; };
159 
163  virtual int getNData() const { return 1; };
164 
168  virtual float* getRadii()
169  { float* fa = new float [2]; fa[0] = radiusBottom; fa[1] = radiusTop; return fa; };
170 
174  virtual GeoTessData** getData()
175  { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; };
176 
180  virtual GeoTessData* getData(int i) { return data; };
181 
185  virtual const GeoTessData& getData(int i) const { return *data; };
186 
190  virtual void setData(const vector<GeoTessData*>& inData)
191  { delete data; data = inData[0]; }
192 
196  virtual void setData(int index, GeoTessData* inData)
197  { delete data; data = inData; }
198 
207  virtual double getValue(int attributeIndex, int nodeIndex) const
208  { return nodeIndex <= 1 ? data->getDouble(attributeIndex) : NaN_DOUBLE; }
209 
219  virtual double getValue(const GeoTessInterpolatorType& rInterpType,
220  int attributeIndex, double radius, bool allowRadiusOutOfRange) const
221  {
222  if (!allowRadiusOutOfRange &&
223  ((radius < getRadiusBottom()) || (radius > getRadiusTop())))
224  return NaN_DOUBLE;
225 
226  // default behavior is to simply return the data value for the first
227  // data object. This works for all the Profile classes that only support
228  // a single Data object like ProfileConstant, ProfileSurface, and
229  // ProfileThin. Profile classes for which the number of supported
230  // Data objects is not equal to 1 must override this method.
231 
232  return getValue(attributeIndex, 0);
233  };
234 
241  virtual double getValueTop(int attributeIndex) const
242  { return data->getDouble(attributeIndex); }
243 
254  virtual bool isNaN(int nodeIndex, int attributeIndex)
255  {
256  return nodeIndex != 0 || data->isNaN(attributeIndex);
257  }
258 
262  virtual void setRadii(const vector<float>& newRadii)
263  { radiusBottom = newRadii[0]; radiusTop = newRadii[1]; }
264 
265  virtual void setRadius(int index, float radius)
266  {
267  switch (index)
268  {
269  case 0:
270  radiusBottom = radius;
271  break;
272  case 1:
273  radiusTop = radius;
274  break;
275  }
276  }
277 
281  virtual float getRadiusTop() const { return radiusTop; };
282 
286  virtual const GeoTessData& getDataTop() const { return *data; };
287 
291  virtual GeoTessData* getDataTop() { return data; };
292 
296  virtual float getRadiusBottom() const { return radiusBottom; };
297 
301  virtual const GeoTessData& getDataBottom() const { return *data; };
302 
306  virtual GeoTessData* getDataBottom() { return data; };
307 
309 
314  { radiusBottom = ifs.readFloat(); radiusTop = ifs.readFloat();
315  data = GeoTessData::getData(ifs, gtmd); };
316 
320  GeoTessProfileConstant(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile()
321  { radiusBottom = ifs.readFloat();
322  radiusTop = ifs.readFloat();
323  data = GeoTessData::getData(ifs, gtmd); };
324 
329  virtual ~GeoTessProfileConstant() { if (data != NULL) delete data; };
330 
334  virtual void write(IFStreamBinary& ofs)
335  {
336  ofs.writeByte((byte) GeoTessProfileType::CONSTANT.ordinal());
337  ofs.writeFloat(radiusBottom);
338  ofs.writeFloat(radiusTop);
339  data->write(ofs);
340  };
341 
345  virtual void write(IFStreamAscii& ofs)
346  { ofs.writeInt(GeoTessProfileType::CONSTANT.ordinal());
347  ofs.writeString(" ");
348  ofs.writeFloat(radiusBottom);
349  ofs.writeString(" ");
350  ofs.writeFloat(radiusTop);
351  data->write(ofs);
352  ofs.writeNL();
353  };
354 
363  virtual int findClosestRadiusIndex(double radius) const
364  { return abs(radiusTop - radius) < abs(radiusBottom - radius) ? 1 : 0; }
365 
373  virtual void setPointIndex(int nodeIndex, int pntIndex)
374  { pointIndex = pntIndex; }
375 
383  virtual void resetPointIndices() { pointIndex = -1; }
384 
392  virtual int getPointIndex(int nodeIndex) const
393  { return pointIndex; }
394 
398  virtual GeoTessProfile* copy()
399  {
400  return new GeoTessProfileConstant(radiusBottom, radiusTop, data->copy());
401  }
402 
404 
405 }; // end class ProfileConstant
406 
407 } // end namespace geotess
408 
409 #endif // PROFILECONSTANT_OBJECT_H
geotess::GeoTessProfileConstant::getMemory
virtual LONG_INT getMemory()
Definition: GeoTessProfileConstant.h:128
geotess
Definition: ArrayReuse.h:57
IFStreamBinary.h
geotess::GeoTessProfile
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition: GeoTessProfile.h:99
GeoTessProfileType.h
GeoTessData.h
geotess::GeoTessProfile::getRadiusTop
virtual float getRadiusTop() const
geotess::GeoTessData::getMemory
virtual LONG_INT getMemory()
GeoTessProfile.h
geotess::GeoTessProfileConstant::getData
virtual GeoTessData ** getData()
Definition: GeoTessProfileConstant.h:174
geotess::GeoTessProfileType
Enumeration of the valid Profile types, including EMPTY, THIN, CONSTANT, NPOINT and SURFACE.
Definition: GeoTessProfileType.h:72
geotess::GeoTessProfileConstant::getValueTop
virtual double getValueTop(int attributeIndex) const
Definition: GeoTessProfileConstant.h:241
geotess::GeoTessProfileConstant::getData
virtual const GeoTessData & getData(int i) const
Definition: GeoTessProfileConstant.h:185
geotess::GeoTessProfileConstant::getDataTop
virtual const GeoTessData & getDataTop() const
Definition: GeoTessProfileConstant.h:286
geotess::GeoTessProfileConstant::isNaN
virtual bool isNaN(int nodeIndex, int attributeIndex)
Definition: GeoTessProfileConstant.h:254
geotess::GeoTessProfileConstant::setData
virtual void setData(const vector< GeoTessData * > &inData)
Definition: GeoTessProfileConstant.h:190
geotess::GeoTessProfileConstant::getRadius
virtual float getRadius(int i) const
Definition: GeoTessProfileConstant.h:152
geotess::GeoTessProfileConstant::getRadiusTop
virtual float getRadiusTop() const
Definition: GeoTessProfileConstant.h:281
geotess::GeoTessProfileConstant::getNData
virtual int getNData() const
Definition: GeoTessProfileConstant.h:163
geotess::GeoTessProfileConstant::getDataBottom
virtual const GeoTessData & getDataBottom() const
Definition: GeoTessProfileConstant.h:301
geotess::GeoTessProfileConstant::getNRadii
virtual int getNRadii() const
Definition: GeoTessProfileConstant.h:158
geotess::GeoTessProfileConstant::getValue
virtual double getValue(int attributeIndex, int nodeIndex) const
Definition: GeoTessProfileConstant.h:207
geotess::GeoTessProfileConstant::getType
virtual const GeoTessProfileType & getType() const
Definition: GeoTessProfileConstant.h:135
geotess::GeoTessProfile::getRadiusBottom
virtual float getRadiusBottom() const
geotess::GeoTessProfileConstant
A Profile object that defines two radii at the bottom and top of the associated layer,...
Definition: GeoTessProfileConstant.h:79
LONG_INT
#define LONG_INT
Definition: CPPGlobals.h:113
geotess::GeoTessProfileConstant::setRadius
virtual void setRadius(int index, float radius)
Definition: GeoTessProfileConstant.h:265
geotess::GeoTessProfileConstant::getData
virtual GeoTessData * getData(int i)
Definition: GeoTessProfileConstant.h:180
geotess::IFStreamBinary::readFloat
float readFloat()
Definition: IFStreamBinary.h:1155
geotess::GeoTessProfileConstant::getDataTop
virtual GeoTessData * getDataTop()
Definition: GeoTessProfileConstant.h:291
geotess::GeoTessData
Abstract base class that manages the data values attached to a single grid point.
Definition: GeoTessData.h:78
geotess::GeoTessProfileConstant::getValue
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double radius, bool allowRadiusOutOfRange) const
Definition: GeoTessProfileConstant.h:219
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:73
IFStreamAscii.h
geotess::GeoTessProfileConstant::class_size
virtual int class_size() const
Definition: GeoTessProfileConstant.h:125
geotess::GeoTessProfileConstant::getDataBottom
virtual GeoTessData * getDataBottom()
Definition: GeoTessProfileConstant.h:306
geotess::IFStreamBinary
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:82
geotess::GeoTessData::getDouble
virtual double getDouble(int attributeIndex) const
geotess::GeoTessMetaData
Basic metadata information about a GeoTessModel.
Definition: GeoTessMetaData.h:98
geotess::GeoTessProfileConstant::getRadiusBottom
virtual float getRadiusBottom() const
Definition: GeoTessProfileConstant.h:296
geotess::GeoTessProfileConstant::getRadii
virtual float * getRadii()
Definition: GeoTessProfileConstant.h:168
geotess::GeoTessProfileConstant::setRadii
virtual void setRadii(const vector< float > &newRadii)
Definition: GeoTessProfileConstant.h:262
geotess::GeoTessProfileConstant::setData
virtual void setData(int index, GeoTessData *inData)
Definition: GeoTessProfileConstant.h:196
geotess::GeoTessProfileConstant::GeoTessProfileConstant
GeoTessProfileConstant(float radBot, float radTop, GeoTessData *dat)
Definition: GeoTessProfileConstant.h:113
geotess::GeoTessProfileConstant::class_name
static string class_name()
Definition: GeoTessProfileConstant.h:120
geotess::GeoTessProfile::getData
virtual GeoTessData ** getData()
geotess::GeoTessInterpolatorType
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR,...
Definition: GeoTessInterpolatorType.h:74
geotess::GeoTessData::isNaN
virtual bool isNaN(int attributeIndex) const