GeoTessCPP  2.0.0
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 
123  virtual const GeoTessProfileType& getType() const
124  { return GeoTessProfileType::THIN; };
125 
129  virtual bool operator == (const GeoTessProfile& p) const
130  { return (GeoTessProfile::operator==(p) && (radius == p.getRadius(0)) && (*data == p.getData(0))); }
131 
140  virtual double getValue(int attributeIndex, int nodeIndex) const
141  { return nodeIndex == 0 ? data->getDouble(attributeIndex) : NaN_DOUBLE; }
142 
152  virtual double getValue(const GeoTessInterpolatorType& rInterpType,
153  int attributeIndex, double r, bool allowRadiusOutOfRange) const
154  {
155  if (!allowRadiusOutOfRange &&
156  ((r < getRadiusBottom()) || (r > getRadiusTop())))
157  return NaN_DOUBLE;
158 
159  // default behavior is to simply return the data value for the first
160  // data object. This works for all the Profile classes that only support
161  // a single Data object like ProfileConstant, ProfileSurface, and
162  // ProfileThin. Profile classes for which the number of supported
163  // Data objects is not equal to 1 must override this method.
164 
165  return getValue(attributeIndex, 0);
166  };
167 
174  virtual double getValueTop(int attributeIndex) const
175  { return data->getDouble(attributeIndex); }
176 
187  virtual bool isNaN(int nodeIndex, int attributeIndex)
188  {
189  return nodeIndex != 0 || data->isNaN(attributeIndex);
190  }
191 
196  virtual float getRadius(int i) const { return radius; };
197 
201  virtual int getNRadii() const { return 1; };
202 
206  virtual int getNData() const { return 1; };
207 
211  virtual float* getRadii()
212  { float* fa = new float [1]; fa[0] = radius; return fa; };
213 
217  virtual GeoTessData** getData()
218  { GeoTessData** da = new GeoTessData* [1]; da[0] = data; return da; };
219 
223  virtual GeoTessData* getData(int i) { return data; };
224 
228  virtual const GeoTessData& getData(int i) const { return *data; };
229 
233  virtual void setData(const vector<GeoTessData*>& inData)
234  { delete data; data = inData[0]; }
235 
239  virtual void setRadii(const vector<float>& newRadii)
240  { radius = newRadii[0]; }
241 
245  virtual void setData(int index, GeoTessData* inData)
246  { delete data; data = inData; }
247 
251  virtual float getRadiusTop() const { return radius; };
252 
256  virtual const GeoTessData& getDataTop() const { return *data; };
257 
261  virtual GeoTessData* getDataTop() { return data; };
262 
266  virtual float getRadiusBottom() const { return radius; };
267 
271  virtual const GeoTessData& getDataBottom() const { return *data; };
272 
276  virtual GeoTessData* getDataBottom() { return data; };
277 
279 
284  radius(-1.0), data(NULL), pointIndex(-1)
285  { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); };
286 
290  GeoTessProfileThin(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : GeoTessProfile(),
291  radius(-1.0), data(NULL), pointIndex(-1)
292  { radius = ifs.readFloat(); data = GeoTessData::getData(ifs, gtmd); };
293 
298  virtual ~GeoTessProfileThin() { if (data != NULL) delete data; };
299 
303  virtual void write(IFStreamBinary& ofs)
304  { ofs.writeByte((byte) GeoTessProfileType::THIN.ordinal());
305  ofs.writeFloat(radius); data->write(ofs); };
306 
310  virtual void write(IFStreamAscii& ofs)
311  { ofs.writeInt(GeoTessProfileType::THIN.ordinal());
312  ofs.writeString(" ");
313  ofs.writeFloat(radius);
314  data->write(ofs);
315  ofs.writeNL(); };
316 
325  virtual int findClosestRadiusIndex(double r) const
326  { return 0; }
327 
335  virtual void setPointIndex(int nodeIndex, int pntIndex)
336  { pointIndex = pntIndex; }
337 
345  virtual void resetPointIndices() { pointIndex = -1; }
346 
354  virtual int getPointIndex(int nodeIndex) const
355  { return pointIndex; }
356 
360  virtual GeoTessProfile* copy()
361  {
362  return new GeoTessProfileThin(radius, data->copy());
363  }
364 
366 
367 }; // end class ProfileThin
368 
369 } // end namespace geotess
370 
371 #endif // PROFILETHIN_OBJECT_H