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
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 
158  void setActiveRegion();
159 
169  void setActiveRegion(GeoTessPolygon* polygon);
170 
180  void setActiveRegion(const string& polygonFileName)
181  {
182  GeoTessPolygon* plgn = GeoTessPolygonFactory::getPolygon(polygonFileName);
183  setActiveRegion(plgn);
184  }
185 
193  GeoTessPolygon* getPolygon() { return polygon; }
194 
202  void clear();
203 
208  bool isPopulated() { return populated; }
209 
215  int size()
216  {
217  return pointMap.size();
218  }
219 
228  int getVertexIndex(int pointIndex)
229  {
230  return pointMap[pointIndex][0];
231  }
232 
241  int getTessId(int pointIndex)
242  {
243  return metaData.getTessellation(pointMap[pointIndex][1]);
244  }
245 
254  int getLayerIndex(int pointIndex)
255  {
256  return pointMap[pointIndex][1];
257  }
258 
267  int getNodeIndex(int pointIndex)
268  {
269  return pointMap[pointIndex][2];
270  }
271 
280  const vector<int>& getPointIndices(int pointIndex)
281  {
282  return pointMap[pointIndex];
283  }
284 
295  int getPointIndex(int vertex, int layer, int node)
296  {
297  return profiles[vertex][layer]->getPointIndex(node);
298  }
299 
310  int getPointIndexLast(int vertex, int layer)
311  {
312  return profiles[vertex][layer]->getPointIndex(profiles[vertex][layer]->getNData()-1);
313  }
314 
325  int getPointIndexFirst(int vertex, int layer)
326  {
327  return profiles[vertex][layer]->getPointIndex(0);
328  }
329 
338  template <typename T>
339  void setPointValue(int pointIndex, int attributeIndex, T value)
340  {
341  vector<int>& map = pointMap[pointIndex];
342  profiles[map[0]][map[1]]->getData(map[2])->setValue(attributeIndex,
343  value);
344  }
345 
349  void setPointData(int pointIndex, GeoTessData* data)
350  {
351  vector<int>& map = pointMap[pointIndex];
352  profiles[map[0]][map[1]]->setData(map[2], data);
353  }
354 
360  GeoTessData* getPointData(int pointIndex)
361  {
362  vector<int>& map = pointMap[pointIndex];
363  return profiles[map[0]][map[1]]->getData(map[2]);
364  }
365 
373  double getPointValue(int pointIndex, int attributeIndex)
374  {
375  vector<int>& map = pointMap[pointIndex];
376  return profiles[map[0]][map[1]]->getValue(attributeIndex, map[2]);
377  }
378 
388  bool isNaN(int pointIndex, int attributeIndex)
389  {
390  vector<int>& map = pointMap[pointIndex];
391  return profiles[map[0]][map[1]]->isNaN(map[2], attributeIndex);
392  }
393 
402  void getPointVector(int pointIndex, double* v)
403  {
404  vector<int>& map = pointMap[pointIndex];
405  const double* vv = grid.getVertex(map[0]);
406  double r = profiles[map[0]][map[1]]->getRadius(map[2]);
407  v[0] = vv[0] * r;
408  v[1] = vv[1] * r;
409  v[2] = vv[2] * r;
410  }
411 
418  const double* getPointUnitVector(int pointIndex) const
419  {
420  return grid.getVertex(pointMap[pointIndex][0]);
421  }
422 
429  double getPointRadius(int pointIndex)
430  {
431  vector<int>& map = pointMap[pointIndex];
432  return profiles[map[0]][map[1]]->getRadius(map[2]);
433  }
434 
441  double getPointDepth(int pointIndex)
442  {
443  vector<int>& map = pointMap[pointIndex];
444  return GeoTessUtils::getEarthRadius(
445  grid.getVertex(pointMap[pointIndex][0]))
446  - profiles[map[0]][map[1]]->getRadius(map[2]);
447  }
448 
456  double getDistance3D(int pointIndex1, int pointIndex2)
457  {
458  vector<int>& m1 = pointMap[pointIndex1];
459  vector<int>& m2 = pointMap[pointIndex2];
460  return GeoTessUtils::getDistance3D(grid.getVertex(m1[0]),
461  profiles[m1[0]][m1[1]]->getRadius(m1[2]), grid.getVertex(m2[0]),
462  profiles[m2[0]][m2[1]]->getRadius(m2[2]));
463  }
464 
465 // /**
466 // * Append the input new values array to the profile at pointIndex
467 // */
468 // template<typename T>
469 // void appendData(int pointIndex, T* newValues, int n)
470 // {
471 // vector<int>& map = pointMap[pointIndex];
472 // profiles[map[0]][map[1]]->appendData<T>(map[2], newValues, n);
473 // }
474 
475 
499  void getPointNeighbors(set<int>& pointNeighbors, int pointIndex);
500 
506  string getPointLatLonString(int pointIndex)
507  {
508  return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex));
509  }
510 
516  string toString(int pointIndex)
517  {
518  char s[100];
519  string frmt = "%8.3f";
520  sprintf(s, frmt.c_str(), getPointDepth(pointIndex));
521  return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex))
522  + " " + s;
523  }
524 
525 };
526 // end class PointMap
527 
528 }// end namespace geotess
529 
530 #endif // POINTMAP_OBJECT_H