GeoTessCPP: rstt/GeoTessCPP/include/GeoTessProfile.h Source File

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

GeoTessProfile.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 PROFILE_OBJECT_H
39 #define PROFILE_OBJECT_H
40
41 // **** _SYSTEM INCLUDES_ ******************************************************
42
43 #include <vector>
44 #include <iostream>
45 #include <string>
46 #include <fstream>
47 #include <map>
48
49 // use standard library objects
50 using namespace std;
51
52 // **** _LOCAL INCLUDES_ *******************************************************
53
54 #include "GeoTessProfileType.h"
55 #include "GeoTessData.h"
56 #include "GeoTessDataArray.h"
57
58 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
59
60 namespace geotess {
61
62 // **** _FORWARD REFERENCES_ ***************************************************
63
64 class GeoTessInterpolatorType;
65 class GeoTessMetaData;
66 class IFStreamAscii;
67 class IFStreamBinary;
68
69
70 // **** _CLASS DEFINITION_ *****************************************************
71
98 class GEOTESS_EXP_IMP GeoTessProfile
99 {
100 private:
101
105 static int aClassCount;
106
107 public:
108
128 static GeoTessProfile* newProfile(const vector<float>& radii, vector<GeoTessData*>& data);
129
130 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<double> >& data);
131 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<float> >& data);
132 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<LONG_INT> >& data);
133 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<int> >& data);
134 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<short> >& data);
135 static GeoTessProfile* newProfile(const vector<float>& radii, vector<vector<byte> >& data);
136
159 static GeoTessProfile* newProfile(float* radii, const int& nRadii, GeoTessData** data, const int& nData);
160
161 static GeoTessProfile* newProfile(float* radii, const int& nRadii, double** values, const int& nNodes, const int& nAttributes)
162 {
163 if (nNodes < 1 && nRadii == 2)
164 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
165
166 if (nNodes == 1)
167 {
168 GeoTessData* d[1];
169 d[0] = GeoTessData::getData(values[0], nAttributes);
170 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
171 }
172
173 GeoTessData** d = new GeoTessData*[nNodes];
174 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
175 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
176 delete[] d;
177 return profile;
178 }
179
180 static GeoTessProfile* newProfile(float* radii, const int& nRadii, float** values, const int& nNodes, const int& nAttributes)
181 {
182 if (nNodes < 1 && nRadii == 2)
183 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
184
185 if (nNodes == 1)
186 {
187 GeoTessData* d[1];
188 d[0] = GeoTessData::getData(values[0], nAttributes);
189 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
190 }
191
192 GeoTessData** d = new GeoTessData*[nNodes];
193 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
194 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
195 delete[] d;
196 return profile;
197 }
198
199 static GeoTessProfile* newProfile(float* radii, const int& nRadii, LONG_INT** values, const int& nNodes, const int& nAttributes)
200 {
201 if (nNodes < 1 && nRadii == 2)
202 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
203
204 if (nNodes == 1)
205 {
206 GeoTessData* d[1];
207 d[0] = GeoTessData::getData(values[0], nAttributes);
208 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
209 }
210
211 GeoTessData** d = new GeoTessData*[nNodes];
212 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
213 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
214 delete[] d;
215 return profile;
216 }
217
218 static GeoTessProfile* newProfile(float* radii, const int& nRadii, int** values, const int& nNodes, const int& nAttributes)
219 {
220 if (nNodes < 1 && nRadii == 2)
221 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
222
223 if (nNodes == 1)
224 {
225 GeoTessData* d[1];
226 d[0] = GeoTessData::getData(values[0], nAttributes);
227 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
228 }
229
230 GeoTessData** d = new GeoTessData*[nNodes];
231 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
232 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
233 delete[] d;
234 return profile;
235 }
236
237 static GeoTessProfile* newProfile(float* radii, const int& nRadii, short** values, const int& nNodes, const int& nAttributes)
238 {
239 if (nNodes < 1 && nRadii == 2)
240 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
241
242 if (nNodes == 1)
243 {
244 GeoTessData* d[1];
245 d[0] = GeoTessData::getData(values[0], nAttributes);
246 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
247 }
248
249 GeoTessData** d = new GeoTessData*[nNodes];
250 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
251 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
252 delete[] d;
253 return profile;
254 }
255
256 static GeoTessProfile* newProfile(float* radii, const int& nRadii, byte** values, const int& nNodes, const int& nAttributes)
257 {
258 if (nNodes < 1 && nRadii == 2)
259 return GeoTessProfile::newProfile(radii, nRadii, NULL, 0);
260
261 if (nNodes == 1)
262 {
263 GeoTessData* d[1];
264 d[0] = GeoTessData::getData(values[0], nAttributes);
265 return GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
266 }
267
268 GeoTessData** d = new GeoTessData*[nNodes];
269 for (int i=0; i<nNodes; ++i) d[i] = GeoTessData::getData(values[i], nAttributes);
270 GeoTessProfile* profile = GeoTessProfile::newProfile(radii, nRadii, d, nNodes);
271 delete[] d;
272 return profile;
273 }
274
278 static string class_name() { return "Profile"; };
279
283 virtual int class_size() const { return (int) sizeof(GeoTessProfile); };
284
285 virtual LONG_INT getMemory() = ABSTRACT;
286
290 static int class_count() { return aClassCount; };
291
297 virtual const GeoTessProfileType& getType() const = ABSTRACT;
298
303 virtual bool operator == (const GeoTessProfile& p) const { return (getType() == p.getType()); }
304
309 virtual double getValue(const GeoTessInterpolatorType& rInterpType,
310 int attributeIndex, double radius, bool allowRadiusOutOfRange) const = ABSTRACT;
311
316 double getValue(const vector<int>& nodeIds,
317 const vector<double>& coefficients, int attributeIndex) const
318 {
319 double value = 0;
320 for (int i=0; i<(int)nodeIds.size(); ++i)
321 value += getValue(attributeIndex, nodeIds[i])*coefficients[i];
322 return value;
323 }
324
333 virtual double getValue(int attributeIndex, int nodeIndex) const = ABSTRACT;
334
345 virtual bool isNaN(int nodeIndex, int attributeIndex) = ABSTRACT;
346
353 virtual double getValueTop(int attributeIndex) const = ABSTRACT;
354
361 virtual double getValueBottom(int attributeIndex) const
362 {
363 return getValue(attributeIndex, 0);
364 }
365
370 virtual float getRadius(int i) const = ABSTRACT;
371
375 virtual int getNRadii() const = ABSTRACT;
376
380 virtual int getNData() const = ABSTRACT;
381
386 virtual float* getRadii() = ABSTRACT;
387
393 virtual GeoTessData** getData() = ABSTRACT;
394
399 virtual GeoTessData* getData(int i) = ABSTRACT;
400
404 virtual const GeoTessData& getData(int i) const = ABSTRACT;
405
412 virtual void setData(int index, GeoTessData* data) = ABSTRACT;
413
420 virtual void setData(const vector<GeoTessData*>& inData) = ABSTRACT;
421
427 virtual void setRadii(const vector<float>& newRadii) = ABSTRACT;
428
432 virtual void setRadius(int index, float radius) = ABSTRACT;
433
437 virtual float getRadiusTop() const = ABSTRACT;
438
442 virtual const GeoTessData& getDataTop() const = ABSTRACT;
443
447 virtual GeoTessData* getDataTop() = ABSTRACT;
448
452 virtual float getRadiusBottom() const = ABSTRACT;
453
457 virtual const GeoTessData& getDataBottom() const = ABSTRACT;
458
462 virtual GeoTessData* getDataBottom() = ABSTRACT;
463
467 double getThickness() { return getRadiusTop() - getRadiusBottom(); }
468
474 int getRadiusIndex(double radius) const
475 { return getRadiusIndex(radius, -1); }
476
488 virtual int getRadiusIndex(double radius, int jlo) const
489 {
490 // note that ProfileNPoint will override this method.
491 return 0;
492 }
493
506 virtual double getInterpolationCoefficient(int i, double radius,
507 bool allowOutOfRange) const
508 {
509 if (!allowOutOfRange && (radius < getRadiusBottom() || radius > getRadiusTop()))
510 return NaN_DOUBLE;
511
512 // note that ProfileNPoint will override this method.
513 return 1.;
514 }
515
523 virtual int getPointIndex(int nodeIndex) const = ABSTRACT;
524
529 virtual int findClosestRadiusIndex(double radius) const = ABSTRACT;
530
532
539 virtual void getWeights(map<int, double>& weights,
540 double dkm, double radius, double hcoefficient) const
541 {
542 // get the point index of the one-and-only node.
543
544 int index = getPointIndex(0);
545
546 // find the current weight of the point, if it exists.
547 // either set the weight of pointIndex (if it does not already exist),
548 // or add the new weight to the existing weight.
549
550 map<int, double>::iterator it = weights.find(index);
551 if (it == weights.end())
552 weights[index] = dkm * hcoefficient;
553 else
554 it->second += dkm * hcoefficient;
555 }
556
563 virtual void getCoefficients(map<int, double>& coefficients, double radius,
564 double horizontalCoefficient) const
565 {
566 // this works for Profile types Constant, Thin and Surface since they only have a single node
567 // in the profile. It does not work for ProfileNPoint and ProfileEmpty so they override this method.
568
569 coefficients[getPointIndex(0)] = horizontalCoefficient;
570 }
571
575 GeoTessProfile() { ++aClassCount; };
576
580 virtual ~GeoTessProfile() { --aClassCount; };
581
585 static GeoTessProfile* newProfile(IFStreamBinary& ifs, GeoTessMetaData& gtmd);
586
590 static GeoTessProfile* newProfile(IFStreamAscii& ifs, GeoTessMetaData& gtmd);
591
595 virtual void write(IFStreamBinary& ofs) = ABSTRACT;
596
600 virtual void write(IFStreamAscii& ofs) = ABSTRACT;
601
609 virtual void setPointIndex(int nodeIndex, int pointIndex) = ABSTRACT;
610
618 virtual void resetPointIndices() = ABSTRACT;
619
620 virtual void setInterpolationCoefficients(const GeoTessInterpolatorType& interpType,
621 vector<int>& nodeIndexes, vector<double>& coefficients,
622 double& radius, bool& allowOutOfRange)
623 {
624 // this code works for Profiles constant, thin and surface.
625 // ProfileNPoint and ProfileEmpty will override it.
626 nodeIndexes.push_back(0);
627 if (!allowOutOfRange && (radius < getRadiusBottom() || radius > getRadiusTop()))
628 coefficients.push_back(NaN_DOUBLE);
629 else
630 coefficients.push_back(1.);
631 }
632
636 virtual GeoTessProfile* copy() = ABSTRACT;
637
639
640 }; // end class Profile
641
642 } // end namespace geotess
643
644 #endif // PROFILE_OBJECT_H
geotess::GeoTessProfile::getRadiusIndex
virtual int getRadiusIndex(double radius, int jlo) const
Definition: GeoTessProfile.h:488
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< GeoTessData * > &data)
geotess::GeoTessProfile::findClosestRadiusIndex
virtual int findClosestRadiusIndex(double radius) const
geotess
Definition: ArrayReuse.h:57
geotess::GeoTessProfile::getInterpolationCoefficient
virtual double getInterpolationCoefficient(int i, double radius, bool allowOutOfRange) const
Definition: GeoTessProfile.h:506
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::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< int > > &data)
geotess::GeoTessProfile::getRadiusTop
virtual float getRadiusTop() const
geotess::GeoTessProfile::setRadius
virtual void setRadius(int index, float radius)
geotess::GeoTessProfileType
Enumeration of the valid Profile types, including EMPTY, THIN, CONSTANT, NPOINT and SURFACE.
Definition: GeoTessProfileType.h:72
geotess::GeoTessProfile::getValueTop
virtual double getValueTop(int attributeIndex) const
geotess::GeoTessProfile::getData
virtual const GeoTessData & getData(int i) const
geotess::GeoTessProfile::setData
virtual void setData(const vector< GeoTessData * > &inData)
geotess::GeoTessProfile::getRadius
virtual float getRadius(int i) const
GeoTessDataArray.h
geotess::GeoTessProfile::class_name
static string class_name()
Definition: GeoTessProfile.h:278
geotess::GeoTessProfile::setRadii
virtual void setRadii(const vector< float > &newRadii)
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< double > > &data)
geotess::GeoTessProfile::getRadii
virtual float * getRadii()
geotess::GeoTessProfile::getMemory
virtual LONG_INT getMemory()
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, short **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:237
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< byte > > &data)
geotess::GeoTessProfile::getValue
virtual double getValue(int attributeIndex, int nodeIndex) const
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< short > > &data)
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, double **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:161
geotess::GeoTessProfile::getDataTop
virtual const GeoTessData & getDataTop() const
geotess::GeoTessProfile::getRadiusIndex
int getRadiusIndex(double radius) const
Definition: GeoTessProfile.h:474
geotess::GeoTessProfile::getNRadii
virtual int getNRadii() const
geotess::GeoTessProfile::getDataBottom
virtual const GeoTessData & getDataBottom() const
geotess::GeoTessProfile::getRadiusBottom
virtual float getRadiusBottom() const
LONG_INT
#define LONG_INT
Definition: CPPGlobals.h:113
geotess::GeoTessProfile::class_count
static int class_count()
Definition: GeoTessProfile.h:290
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< LONG_INT > > &data)
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, LONG_INT **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:199
geotess::GeoTessData
Abstract base class that manages the data values attached to a single grid point.
Definition: GeoTessData.h:78
geotess::GeoTessProfile::getPointIndex
virtual int getPointIndex(int nodeIndex) const
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:73
geotess::GeoTessProfile::getValue
double getValue(const vector< int > &nodeIds, const vector< double > &coefficients, int attributeIndex) const
Definition: GeoTessProfile.h:316
geotess::GeoTessProfile::getThickness
double getThickness()
Definition: GeoTessProfile.h:467
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, int **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:218
geotess::GeoTessProfile::getValueBottom
virtual double getValueBottom(int attributeIndex) const
Definition: GeoTessProfile.h:361
geotess::GeoTessProfile::getNData
virtual int getNData() const
geotess::GeoTessProfile::getDataBottom
virtual GeoTessData * getDataBottom()
ABSTRACT
#define ABSTRACT
Global constant used to make pure virtual functions readable.
Definition: CPPGlobals.h:80
geotess::GeoTessProfile::getType
virtual const GeoTessProfileType & getType() const
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, byte **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:256
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, float **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessProfile.h:180
geotess::GeoTessProfile::getData
virtual GeoTessData * getData(int i)
geotess::GeoTessProfile::getDataTop
virtual GeoTessData * getDataTop()
geotess::GeoTessProfile::class_size
virtual int class_size() const
Definition: GeoTessProfile.h:283
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(float *radii, const int &nRadii, GeoTessData **data, const int &nData)
geotess::GeoTessProfile::isNaN
virtual bool isNaN(int nodeIndex, int attributeIndex)
geotess::GeoTessProfile::getValue
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double radius, bool allowRadiusOutOfRange) const
geotess::GeoTessProfile::setData
virtual void setData(int index, GeoTessData *data)
geotess::GeoTessProfile::newProfile
static GeoTessProfile * newProfile(const vector< float > &radii, vector< vector< float > > &data)
geotess::GeoTessProfile::getData
virtual GeoTessData ** getData()
geotess::GeoTessInterpolatorType
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR,...
Definition: GeoTessInterpolatorType.h:74