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
ProfileThin.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 "Data.h"
51 #include "Profile.h"
52 #include "ProfileType.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 
73 class GEOTESS_EXP_IMP ProfileThin : virtual public Profile
74 {
75 private:
76 
80  float radius;
81 
85  Data* data;
86 
90  int pointIndex;
91 
95  ProfileThin() : Profile(), radius(0.0), data(NULL),
96  pointIndex(-1) {};
97 
98 public:
99 
103  ProfileThin(float rad, Data* dat) :
104  Profile(), 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(ProfileThin); };
117 
123  virtual const ProfileType& getType() const
124  { return ProfileType::THIN; };
125 
129  virtual bool operator == (const Profile& p) const
130  { return (Profile::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 InterpolatorType& 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 
202  virtual Data** getData()
203  { Data** da = new Data* [1]; da[0] = data; return da; };
204 
208  virtual Data* getData(int i) { return data; };
209 
213  virtual const Data& getData(int i) const { return *data; };
214 
218  virtual void setData(const vector<Data*>& inData)
219  { delete data; data = inData[0]; }
220 
224  virtual void setRadii(const vector<float>& newRadii)
225  { radius = newRadii[0]; }
226 
230  virtual void setData(int index, Data* inData)
231  { delete data; data = inData; }
232 
236  virtual float getRadiusTop() const { return radius; };
237 
241  virtual const Data& getDataTop() const { return *data; };
242 
246  virtual Data* getDataTop() { return data; };
247 
251  virtual float getRadiusBottom() const { return radius; };
252 
256  virtual const Data& getDataBottom() const { return *data; };
257 
261  virtual Data* getDataBottom() { return data; };
262 
266  virtual int getNRadii() const { return 1; };
267 
271  virtual int getNData() const { return 1; };
272 
276  virtual float* getRadii()
277  { float* fa = new float [1]; fa[0] = radius; return fa; };
278 
280 
285  radius(-1.0), data(NULL), pointIndex(-1)
286  { radius = ifs.readFloat(); data = Data::getData(ifs, gtmd); };
287 
291  ProfileThin(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : Profile(),
292  radius(-1.0), data(NULL), pointIndex(-1)
293  { radius = ifs.readFloat(); data = Data::getData(ifs, gtmd); };
294 
299  virtual ~ProfileThin() { if (data != NULL) delete data; };
300 
304  virtual void write(IFStreamBinary& ofs)
305  { ofs.writeByte((byte) ProfileType::THIN.ordinal());
306  ofs.writeFloat(radius); data->write(ofs); };
307 
311  virtual void write(IFStreamAscii& ofs)
312  { ofs.writeInt(ProfileType::THIN.ordinal());
313  ofs.writeString(" ");
314  ofs.writeFloat(radius);
315  data->write(ofs);
316  ofs.writeNL(); };
317 
326  virtual int findClosestRadiusIndex(double r) const
327  { return 0; }
328 
336  virtual void setPointIndex(int nodeIndex, int pntIndex)
337  { pointIndex = pntIndex; }
338 
346  virtual void resetPointIndices() { pointIndex = -1; }
347 
355  virtual int getPointIndex(int nodeIndex) const
356  { return pointIndex; }
357 
361  virtual Profile* copy()
362  {
363  return new ProfileThin(radius, data->copy());
364  }
365 
367 
368 }; // end class ProfileThin
369 
370 } // end namespace geotess
371 
372 #endif // PROFILETHIN_OBJECT_H