GeoTessCPP  2.6.1
Software to facilitate storage and retrieval of 3D information about the Earth.
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
#define LONG_INT
Definition: CPPGlobals.h:111
Abstract base class that manages the data values attached to a single grid point.
Definition: GeoTessData.h:76
virtual LONG_INT getMemory()
virtual double getDouble(int attributeIndex) const
virtual bool isNaN(int attributeIndex) const
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR,...
Basic metadata information about a GeoTessModel.
Abstract class that manages the radii and data values that span a single layer associated with a sing...
virtual float getRadius(int i) const
virtual GeoTessData ** getData()
A Profile object consiting of a single radius value and a single Data object. It represents a profile...
virtual const GeoTessData & getDataBottom() const
virtual void setRadii(const vector< float > &newRadii)
virtual GeoTessData * getDataBottom()
virtual float getRadiusTop() const
virtual GeoTessData * getData(int i)
virtual const GeoTessData & getData(int i) const
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double r, bool allowRadiusOutOfRange) const
virtual float getRadiusBottom() const
virtual int class_size() const
virtual bool isNaN(int nodeIndex, int attributeIndex)
virtual void setData(const vector< GeoTessData * > &inData)
GeoTessProfileThin(float rad, GeoTessData *dat)
virtual GeoTessData * getDataTop()
virtual double getValueTop(int attributeIndex) const
virtual double getValue(int attributeIndex, int nodeIndex) const
virtual void setRadius(int index, float newRadius)
virtual const GeoTessData & getDataTop() const
virtual const GeoTessProfileType & getType() const
virtual void setData(int index, GeoTessData *inData)
virtual GeoTessData ** getData()
virtual float getRadius(int i) const
Enumeration of the valid Profile types, including EMPTY, THIN, CONSTANT, NPOINT and SURFACE.
Opens a file for binary read and write access.