GeoTessCPP: include/ProfileConstant.h Source File

GeoTessCPP 2.0.0 Software to facilitate storage and retrieval of 3D information about the Earth.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Friends Macros
ProfileConstant.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 "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
76 class GEOTESS_EXP_IMP ProfileConstant : virtual public Profile
77 {
78 private:
79
83 float radiusBottom;
84
88 float radiusTop;
89
93 Data* data;
94
98 int pointIndex;
99
103 ProfileConstant() : Profile(), radiusBottom(0.0), radiusTop(0.0),
104 data(NULL), pointIndex(-1) {};
105
106 public:
107
111 ProfileConstant(float radBot, float radTop, Data* dat) :
112 Profile(), 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(ProfileConstant); };
125
131 virtual const ProfileType& getType() const
132 { return ProfileType::CONSTANT; };
133
137 virtual bool operator == (const Profile& p) const
138 { return (Profile::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
155 virtual Data** getData()
156 { Data** da = new Data* [1]; da[0] = data; return da; };
157
161 virtual Data* getData(int i) { return data; };
162
166 virtual const Data& getData(int i) const { return *data; };
167
171 virtual void setData(const vector<Data*>& inData)
172 { delete data; data = inData[0]; }
173
177 virtual void setData(int index, Data* inData)
178 { delete data; data = inData; }
179
188 virtual double getValue(int attributeIndex, int nodeIndex) const
189 {
190 return nodeIndex == 0 ? data->getDouble(attributeIndex) : NaN_DOUBLE;
191 }
192
202 virtual double getValue(const InterpolatorType& rInterpType,
203 int attributeIndex, double radius, bool allowRadiusOutOfRange) const
204 {
205 if (!allowRadiusOutOfRange &&
206 ((radius < getRadiusBottom()) || (radius > getRadiusTop())))
207 return NaN_DOUBLE;
208
209 // default behavior is to simply return the data value for the first
210 // data object. This works for all the Profile classes that only support
211 // a single Data object like ProfileConstant, ProfileSurface, and
212 // ProfileThin. Profile classes for which the number of supported
213 // Data objects is not equal to 1 must override this method.
214
215 return getValue(attributeIndex, 0);
216 };
217
224 virtual double getValueTop(int attributeIndex) const
225 { return data->getDouble(attributeIndex); }
226
237 virtual bool isNaN(int nodeIndex, int attributeIndex)
238 {
239 return nodeIndex != 0 || data->isNaN(attributeIndex);
240 }
241
245 virtual void setRadii(const vector<float>& newRadii)
246 { radiusBottom = newRadii[0]; radiusTop = newRadii[1]; }
247
251 virtual float getRadiusTop() const { return radiusTop; };
252
256 virtual const Data& getDataTop() const { return *data; };
257
261 virtual Data* getDataTop() { return data; };
262
266 virtual float getRadiusBottom() const { return radiusBottom; };
267
271 virtual const Data& getDataBottom() const { return *data; };
272
276 virtual Data* getDataBottom() { return data; };
277
281 virtual int getNRadii() const { return 2; };
282
286 virtual int getNData() const { return 1; };
287
291 virtual float* getRadii()
292 { float* fa = new float [2]; fa[0] = radiusBottom;\
293 fa[1] = radiusTop; return fa; };
294
296
300 ProfileConstant(IFStreamBinary& ifs, GeoTessMetaData& gtmd) : Profile()
301 { radiusBottom = ifs.readFloat(); radiusTop = ifs.readFloat();
302 data = Data::getData(ifs, gtmd); };
303
307 ProfileConstant(IFStreamAscii& ifs, GeoTessMetaData& gtmd) : Profile()
308 { radiusBottom = ifs.readFloat();
309 radiusTop = ifs.readFloat();
310 data = Data::getData(ifs, gtmd); };
311
316 virtual ~ProfileConstant() { if (data != NULL) delete data; };
317
321 virtual void write(IFStreamBinary& ofs)
322 {
323 ofs.writeByte((byte) ProfileType::CONSTANT.ordinal());
324 ofs.writeFloat(radiusBottom);
325 ofs.writeFloat(radiusTop);
326 data->write(ofs);
327 };
328
332 virtual void write(IFStreamAscii& ofs)
333 { ofs.writeInt(ProfileType::CONSTANT.ordinal());
334 ofs.writeString(" ");
335 ofs.writeFloat(radiusBottom);
336 ofs.writeString(" ");
337 ofs.writeFloat(radiusTop);
338 data->write(ofs);
339 ofs.writeNL();
340 };
341
350 virtual int findClosestRadiusIndex(double radius) const
351 { return abs(radiusTop - radius) < abs(radiusBottom - radius) ? 1 : 0; }
352
360 virtual void setPointIndex(int nodeIndex, int pntIndex)
361 { pointIndex = pntIndex; }
362
370 virtual void resetPointIndices() { pointIndex = -1; }
371
379 virtual int getPointIndex(int nodeIndex) const
380 { return pointIndex; }
381
385 virtual Profile* copy()
386 {
387 return new ProfileConstant(radiusBottom, radiusTop, data->copy());
388 }
389
391
392 }; // end class ProfileConstant
393
394 } // end namespace geotess
395
396 #endif // PROFILECONSTANT_OBJECT_H