GeoTessCPP  2.2
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessPointMap.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 POINTMAP_OBJECT_H
37 #define POINTMAP_OBJECT_H
38 
39 // **** _SYSTEM INCLUDES_ ******************************************************
40 
41 #include <cstdio>
42 
43 // use standard library objects
44 using namespace std;
45 
46 // **** _LOCAL INCLUDES_ *******************************************************
47 
48 #include "CPPUtils.h"
49 #include "GeoTessGrid.h"
50 #include "GeoTessProfile.h"
51 #include "GeoTessMetaData.h"
52 #include "GeoTessPolygon.h"
53 #include "GeoTessPolygon3D.h"
54 #include "GeoTessPolygonFactory.h"
55 
56 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
57 
58 namespace geotess
59 {
60 
61 // **** _FORWARD REFERENCES_ ***************************************************
62 
63 class GeoTessModel;
64 
65 // **** _CLASS DEFINITION_ *****************************************************
66 
75 {
76 private:
77 
81  GeoTessGrid& grid;
82 
87  GeoTessProfile *** profiles;
88 
105  GeoTessMetaData& metaData;
106 
107  GeoTessPolygon* polygon;
108 
114  vector<vector<int> > pointMap;
115 
116  bool populated;
117 
118 public:
119 
125 
130 
134  GeoTessPointMap& operator=(const GeoTessPointMap& other);
135 
140  bool operator==(const GeoTessPointMap& other);
141 
145  bool operator!=(const GeoTessPointMap& other) { return !(*this == other); }
146 
150  ~GeoTessPointMap();
151 
153  {
154  return (LONG_INT) sizeof(GeoTessPointMap)
155  + (LONG_INT)(pointMap.capacity() * sizeof(vector<int>)
156  + pointMap.size() * 3 * (LONG_INT)sizeof(int));
157  }
158 
165  void setActiveRegion();
166 
176  void setActiveRegion(GeoTessPolygon* polygon);
177 
187  void setActiveRegion(const string& polygonFileName)
188  {
189  GeoTessPolygon* plgn = GeoTessPolygonFactory::getPolygon(polygonFileName);
190  setActiveRegion(plgn);
191  }
192 
200  GeoTessPolygon* getPolygon() { return polygon; }
201 
209  void clear();
210 
215  bool isPopulated() { return populated; }
216 
222  int size()
223  {
224  return pointMap.size();
225  }
226 
235  int getVertexIndex(int pointIndex)
236  {
237  return pointMap[pointIndex][0];
238  }
239 
248  int getTessId(int pointIndex)
249  {
250  return metaData.getTessellation(pointMap[pointIndex][1]);
251  }
252 
261  int getLayerIndex(int pointIndex)
262  {
263  return pointMap[pointIndex][1];
264  }
265 
274  int getNodeIndex(int pointIndex)
275  {
276  return pointMap[pointIndex][2];
277  }
278 
287  const vector<int>& getPointIndices(int pointIndex)
288  {
289  return pointMap[pointIndex];
290  }
291 
302  int getPointIndex(int vertex, int layer, int node)
303  {
304  return profiles[vertex][layer]->getPointIndex(node);
305  }
306 
317  int getPointIndexLast(int vertex, int layer)
318  {
319  return profiles[vertex][layer]->getPointIndex(profiles[vertex][layer]->getNData()-1);
320  }
321 
332  int getPointIndexFirst(int vertex, int layer)
333  {
334  return profiles[vertex][layer]->getPointIndex(0);
335  }
336 
340  void setPointData(int pointIndex, GeoTessData* data)
341  {
342  vector<int>& map = pointMap[pointIndex];
343  profiles[map[0]][map[1]]->setData(map[2], data);
344  }
345 
351  GeoTessData* getPointData(int pointIndex)
352  {
353  vector<int>& map = pointMap[pointIndex];
354  return profiles[map[0]][map[1]]->getData(map[2]);
355  }
356 
365  template <typename T>
366  void setPointValue(int pointIndex, int attributeIndex, T value)
367  {
368  vector<int>& map = pointMap[pointIndex];
369  profiles[map[0]][map[1]]->getData(map[2])->setValue(attributeIndex,
370  value);
371  }
372 
380  double getPointValue(int pointIndex, int attributeIndex)
381  {
382  vector<int>& map = pointMap[pointIndex];
383  return profiles[map[0]][map[1]]->getValue(attributeIndex, map[2]);
384  }
385 
395  double getPointValueDouble(int pointIndex, int attributeIndex)
396  {
397  vector<int>& map = pointMap[pointIndex];
398  return profiles[map[0]][map[1]]->getData(map[2])->getDouble(attributeIndex);
399  }
400 
410  float getPointValueFloat(int pointIndex, int attributeIndex)
411  {
412  vector<int>& map = pointMap[pointIndex];
413  return profiles[map[0]][map[1]]->getData(map[2])->getFloat(attributeIndex);
414  }
415 
425  LONG_INT getPointValueLong(int pointIndex, int attributeIndex)
426  {
427  vector<int>& map = pointMap[pointIndex];
428  return profiles[map[0]][map[1]]->getData(map[2])->getLong(attributeIndex);
429  }
430 
440  int getPointValueInt(int pointIndex, int attributeIndex)
441  {
442  vector<int>& map = pointMap[pointIndex];
443  return profiles[map[0]][map[1]]->getData(map[2])->getInt(attributeIndex);
444  }
445 
455  short getPointValueShort(int pointIndex, int attributeIndex)
456  {
457  vector<int>& map = pointMap[pointIndex];
458  return profiles[map[0]][map[1]]->getData(map[2])->getShort(attributeIndex);
459  }
460 
470  byte getPointValueByte(int pointIndex, int attributeIndex)
471  {
472  vector<int>& map = pointMap[pointIndex];
473  return profiles[map[0]][map[1]]->getData(map[2])->getByte(attributeIndex);
474  }
475 
485  bool isNaN(int pointIndex, int attributeIndex)
486  {
487  vector<int>& map = pointMap[pointIndex];
488  return profiles[map[0]][map[1]]->isNaN(map[2], attributeIndex);
489  }
490 
499  void getPointVector(int pointIndex, double* v)
500  {
501  vector<int>& map = pointMap[pointIndex];
502  const double* vv = grid.getVertex(map[0]);
503  double r = profiles[map[0]][map[1]]->getRadius(map[2]);
504  v[0] = vv[0] * r;
505  v[1] = vv[1] * r;
506  v[2] = vv[2] * r;
507  }
508 
515  const double* getPointUnitVector(int pointIndex) const
516  {
517  return grid.getVertex(pointMap[pointIndex][0]);
518  }
519 
526  double getPointRadius(int pointIndex)
527  {
528  vector<int>& map = pointMap[pointIndex];
529  return profiles[map[0]][map[1]]->getRadius(map[2]);
530  }
531 
538  double getPointDepth(int pointIndex)
539  {
540  vector<int>& map = pointMap[pointIndex];
541  return GeoTessUtils::getEarthRadius(
542  grid.getVertex(pointMap[pointIndex][0]))
543  - profiles[map[0]][map[1]]->getRadius(map[2]);
544  }
545 
553  double getDistance3D(int pointIndex1, int pointIndex2)
554  {
555  vector<int>& m1 = pointMap[pointIndex1];
556  vector<int>& m2 = pointMap[pointIndex2];
557  return GeoTessUtils::getDistance3D(grid.getVertex(m1[0]),
558  profiles[m1[0]][m1[1]]->getRadius(m1[2]), grid.getVertex(m2[0]),
559  profiles[m2[0]][m2[1]]->getRadius(m2[2]));
560  }
561 
562 // /**
563 // * Append the input new values array to the profile at pointIndex
564 // */
565 // template<typename T>
566 // void appendData(int pointIndex, T* newValues, int n)
567 // {
568 // vector<int>& map = pointMap[pointIndex];
569 // profiles[map[0]][map[1]]->appendData<T>(map[2], newValues, n);
570 // }
571 
572 
596  void getPointNeighbors(set<int>& pointNeighbors, int pointIndex);
597 
603  string getPointLatLonString(int pointIndex)
604  {
605  return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex));
606  }
607 
613  string toString(int pointIndex)
614  {
615  char s[100];
616  string frmt = "%8.3f";
617  sprintf(s, frmt.c_str(), getPointDepth(pointIndex));
618  return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex))
619  + " " + s;
620  }
621 
622 };
623 // end class PointMap
624 
625 }// end namespace geotess
626 
627 #endif // POINTMAP_OBJECT_H
string toString(int pointIndex)
Retrieve a nicely formated string with lat, lon, depth of the point in degrees and km...
Definition: GeoTessPointMap.h:613
virtual double getDouble(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a double value.
virtual float getFloat(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a float value.
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Definition: GeoTessPolygon.h:111
Relationships between vertices (2D positions in a tessellation), nodes (1D positions along a radial P...
Definition: GeoTessPointMap.h:74
const double * getVertex(int vertex) const
Retrieve the unit vector that corresponds to the specified vertex.
Definition: GeoTessGrid.h:630
bool isNaN(int pointIndex, int attributeIndex)
Return true if the value of the specified attribute at the specified point is NaN.
Definition: GeoTessPointMap.h:485
void setPointData(int pointIndex, GeoTessData *data)
Replace the Data object associated with the specified point.
Definition: GeoTessPointMap.h:340
float getPointValueFloat(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to float if necessary...
Definition: GeoTessPointMap.h:410
int getLayerIndex(int pointIndex)
Retrieve the index of the layer that corresponds to the specified pointIndex.
Definition: GeoTessPointMap.h:261
void getPointVector(int pointIndex, double *v)
Retrieve a vector representation of the specified point (not a unit vector).
Definition: GeoTessPointMap.h:499
Definition: ArrayReuse.h:55
string getPointLatLonString(int pointIndex)
Retrieve nicely formated string with lat, lon of the point in degrees.
Definition: GeoTessPointMap.h:603
bool isPopulated()
Determine whether or not this PointMap is populated.
Definition: GeoTessPointMap.h:215
int getTessellation(int layer) const
Retrieve the index of the tessellation that supports the specified layer.
Definition: GeoTessMetaData.h:683
virtual bool isNaN(int nodeIndex, int attributeIndex)
Return true if the specified Data value is NaN.
double getPointRadius(int pointIndex)
Retrieve the radius of the specified point.
Definition: GeoTessPointMap.h:526
virtual LONG_INT getLong(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a LONG_INT value...
Manages the geometry and topology of one or more multi-level triangular tessellations of a unit spher...
Definition: GeoTessGrid.h:166
int getPointIndexFirst(int vertex, int layer)
Retrieve the pointIndex of the point that corresponds to the first node in profile[vertex][layer].
Definition: GeoTessPointMap.h:332
int getTessId(int pointIndex)
Retrieve the index of the tessellation that corresponds to the specified pointIndex.
Definition: GeoTessPointMap.h:248
int getPointValueInt(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to int if necessary...
Definition: GeoTessPointMap.h:440
virtual GeoTessData ** getData()
Retrieve a shallow copy of the array of Data objects associated with this Profile.
GeoTessData * getPointData(int pointIndex)
Retrieve a reference to the Data object associated with the specified point.
Definition: GeoTessPointMap.h:351
virtual double getValue(const GeoTessInterpolatorType &rInterpType, int attributeIndex, double radius, bool allowRadiusOutOfRange) const
Retrieve the value of the specified attribute interpolated at the specified radius.
void setPointValue(int pointIndex, int attributeIndex, T value)
Set the value of the specified attribute at the specified point to the specified value.
Definition: GeoTessPointMap.h:366
int getVertexIndex(int pointIndex)
Retrieve the index of the vertex that corresponds to the specified pointIndex.
Definition: GeoTessPointMap.h:235
GeoTessPolygon * getPolygon()
Retrieve the pointer to the Polygon or Polygon3D object that supports this PointMap.
Definition: GeoTessPointMap.h:200
void setActiveRegion(const string &polygonFileName)
Populate the PointMap such that nodes located within the specified Polygon are active and all others ...
Definition: GeoTessPointMap.h:187
short getPointValueShort(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to short if necessary...
Definition: GeoTessPointMap.h:455
LONG_INT getPointValueLong(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to LONG_INT if necessary...
Definition: GeoTessPointMap.h:425
int getPointIndex(int vertex, int layer, int node)
Retrieve the pointIndex of the point that corresponds to the specified vertex, layer and node...
Definition: GeoTessPointMap.h:302
const vector< int > & getPointIndices(int pointIndex)
Retrieve a reference to the index map for the specified pointIndex.
Definition: GeoTessPointMap.h:287
virtual byte getByte(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a bute value.
byte getPointValueByte(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to byte if necessary...
Definition: GeoTessPointMap.h:470
#define byte
signed-byte typedef
Definition: CPPGlobals.h:94
virtual int getInt(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a int value.
virtual void setData(int index, GeoTessData *data)
Replace the Data currently associated with this Profile with new Data.
virtual GeoTessData & setValue(int attributeIndex, double v)
Set the value of the specified attributeIndex and return a reference to this Data object...
bool operator!=(const GeoTessPointMap &other)
Overloaded inequality operator.
Definition: GeoTessPointMap.h:145
double getDistance3D(int pointIndex1, int pointIndex2)
Retrieve the straight-line distance between two points in km.
Definition: GeoTessPointMap.h:553
#define LONG_INT
Definition: CPPGlobals.h:111
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition: GeoTessProfile.h:96
Abstract base class that manages the data values attached to a single grid point. ...
Definition: GeoTessData.h:75
virtual int getPointIndex(int nodeIndex) const
Get the pointIndex that corresponds to the supplied nodeIndex.
Top level class that manages the GeoTessMetaData, GeoTessGrid and GeoTessData that comprise a 3D Eart...
Definition: GeoTessModel.h:119
double getPointValueDouble(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point cast to double if necessary...
Definition: GeoTessPointMap.h:395
int getPointIndexLast(int vertex, int layer)
Retrieve the pointIndex of the point that corresponds to the last node in profile[vertex][layer].
Definition: GeoTessPointMap.h:317
Basic metadata information about a GeoTessModel.
Definition: GeoTessMetaData.h:95
int size()
Retrieve the number of points supported by this model.
Definition: GeoTessPointMap.h:222
double getPointDepth(int pointIndex)
Retrieve the radius of the specified point.
Definition: GeoTessPointMap.h:538
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
const double * getPointUnitVector(int pointIndex) const
Retrieve a reference to the unit vector for the specified point.
Definition: GeoTessPointMap.h:515
virtual short getShort(int attributeIndex) const
Retrieve the value of the attribute at the specified attribute index as a short value.
virtual float getRadius(int i) const
Get the i'th radius value in this profile in km.
double getPointValue(int pointIndex, int attributeIndex)
Retrieve the value of the specified attribute at the specified point.
Definition: GeoTessPointMap.h:380
LONG_INT getMemory()
Definition: GeoTessPointMap.h:152
int getNodeIndex(int pointIndex)
Retrieve the index of the node that corresponds to the specified pointIndex.
Definition: GeoTessPointMap.h:274