GeoTessCPP
2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
|
00001 //- **************************************************************************** 00002 //- 00003 //- Copyright 2009 Sandia Corporation. Under the terms of Contract 00004 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00005 //- retains certain rights in this software. 00006 //- 00007 //- BSD Open Source License. 00008 //- All rights reserved. 00009 //- 00010 //- Redistribution and use in source and binary forms, with or without 00011 //- modification, are permitted provided that the following conditions are met: 00012 //- 00013 //- * Redistributions of source code must retain the above copyright notice, 00014 //- this list of conditions and the following disclaimer. 00015 //- * Redistributions in binary form must reproduce the above copyright 00016 //- notice, this list of conditions and the following disclaimer in the 00017 //- documentation and/or other materials provided with the distribution. 00018 //- * Neither the name of Sandia National Laboratories nor the names of its 00019 //- contributors may be used to endorse or promote products derived from 00020 //- this software without specific prior written permission. 00021 //- 00022 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00026 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00027 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00028 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00029 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00030 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00031 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 //- POSSIBILITY OF SUCH DAMAGE. 00033 //- 00034 //- **************************************************************************** 00035 00036 #ifndef POINTMAP_OBJECT_H 00037 #define POINTMAP_OBJECT_H 00038 00039 // **** _SYSTEM INCLUDES_ ****************************************************** 00040 00041 #include <cstdio> 00042 00043 // use standard library objects 00044 using namespace std; 00045 00046 // **** _LOCAL INCLUDES_ ******************************************************* 00047 00048 #include "CPPUtils.h" 00049 #include "GeoTessGrid.h" 00050 #include "GeoTessProfile.h" 00051 #include "GeoTessMetaData.h" 00052 #include "GeoTessPolygon.h" 00053 #include "GeoTessPolygon3D.h" 00054 #include "GeoTessPolygonFactory.h" 00055 00056 // **** _BEGIN GEOTESS NAMESPACE_ ********************************************** 00057 00058 namespace geotess 00059 { 00060 00061 // **** _FORWARD REFERENCES_ *************************************************** 00062 00063 class GeoTessModel; 00064 00065 // **** _CLASS DEFINITION_ ***************************************************** 00066 00074 class GEOTESS_EXP_IMP GeoTessPointMap 00075 { 00076 private: 00077 00081 GeoTessGrid& grid; 00082 00087 GeoTessProfile *** profiles; 00088 00105 GeoTessMetaData& metaData; 00106 00107 GeoTessPolygon* polygon; 00108 00114 vector<vector<int> > pointMap; 00115 00116 bool populated; 00117 00118 public: 00119 00124 GeoTessPointMap(GeoTessModel& m); 00125 00129 GeoTessPointMap(GeoTessPointMap& other); 00130 00134 GeoTessPointMap& operator=(const GeoTessPointMap& other); 00135 00140 bool operator==(const GeoTessPointMap& other); 00141 00145 bool operator!=(const GeoTessPointMap& other) { return !(*this == other); } 00146 00150 ~GeoTessPointMap(); 00151 00158 void setActiveRegion(); 00159 00169 void setActiveRegion(GeoTessPolygon* polygon); 00170 00180 void setActiveRegion(const string& polygonFileName) 00181 { 00182 GeoTessPolygon* plgn = GeoTessPolygonFactory::getPolygon(polygonFileName); 00183 setActiveRegion(plgn); 00184 } 00185 00193 GeoTessPolygon* getPolygon() { return polygon; } 00194 00202 void clear(); 00203 00208 bool isPopulated() { return populated; } 00209 00215 int size() 00216 { 00217 return pointMap.size(); 00218 } 00219 00228 int getVertexIndex(int pointIndex) 00229 { 00230 return pointMap[pointIndex][0]; 00231 } 00232 00241 int getTessId(int pointIndex) 00242 { 00243 return metaData.getTessellation(pointMap[pointIndex][1]); 00244 } 00245 00254 int getLayerIndex(int pointIndex) 00255 { 00256 return pointMap[pointIndex][1]; 00257 } 00258 00267 int getNodeIndex(int pointIndex) 00268 { 00269 return pointMap[pointIndex][2]; 00270 } 00271 00280 const vector<int>& getPointIndices(int pointIndex) 00281 { 00282 return pointMap[pointIndex]; 00283 } 00284 00295 int getPointIndex(int vertex, int layer, int node) 00296 { 00297 return profiles[vertex][layer]->getPointIndex(node); 00298 } 00299 00310 int getPointIndexLast(int vertex, int layer) 00311 { 00312 return profiles[vertex][layer]->getPointIndex(profiles[vertex][layer]->getNData()-1); 00313 } 00314 00325 int getPointIndexFirst(int vertex, int layer) 00326 { 00327 return profiles[vertex][layer]->getPointIndex(0); 00328 } 00329 00338 template <typename T> 00339 void setPointValue(int pointIndex, int attributeIndex, T value) 00340 { 00341 vector<int>& map = pointMap[pointIndex]; 00342 profiles[map[0]][map[1]]->getData(map[2])->setValue(attributeIndex, 00343 value); 00344 } 00345 00349 void setPointData(int pointIndex, GeoTessData* data) 00350 { 00351 vector<int>& map = pointMap[pointIndex]; 00352 profiles[map[0]][map[1]]->setData(map[2], data); 00353 } 00354 00360 GeoTessData* getPointData(int pointIndex) 00361 { 00362 vector<int>& map = pointMap[pointIndex]; 00363 return profiles[map[0]][map[1]]->getData(map[2]); 00364 } 00365 00373 double getPointValue(int pointIndex, int attributeIndex) 00374 { 00375 vector<int>& map = pointMap[pointIndex]; 00376 return profiles[map[0]][map[1]]->getValue(attributeIndex, map[2]); 00377 } 00378 00388 bool isNaN(int pointIndex, int attributeIndex) 00389 { 00390 vector<int>& map = pointMap[pointIndex]; 00391 return profiles[map[0]][map[1]]->isNaN(map[2], attributeIndex); 00392 } 00393 00402 void getPointVector(int pointIndex, double* v) 00403 { 00404 vector<int>& map = pointMap[pointIndex]; 00405 const double* vv = grid.getVertex(map[0]); 00406 double r = profiles[map[0]][map[1]]->getRadius(map[2]); 00407 v[0] = vv[0] * r; 00408 v[1] = vv[1] * r; 00409 v[2] = vv[2] * r; 00410 } 00411 00418 const double* getPointUnitVector(int pointIndex) const 00419 { 00420 return grid.getVertex(pointMap[pointIndex][0]); 00421 } 00422 00429 double getPointRadius(int pointIndex) 00430 { 00431 vector<int>& map = pointMap[pointIndex]; 00432 return profiles[map[0]][map[1]]->getRadius(map[2]); 00433 } 00434 00441 double getPointDepth(int pointIndex) 00442 { 00443 vector<int>& map = pointMap[pointIndex]; 00444 return GeoTessUtils::getEarthRadius( 00445 grid.getVertex(pointMap[pointIndex][0])) 00446 - profiles[map[0]][map[1]]->getRadius(map[2]); 00447 } 00448 00456 double getDistance3D(int pointIndex1, int pointIndex2) 00457 { 00458 vector<int>& m1 = pointMap[pointIndex1]; 00459 vector<int>& m2 = pointMap[pointIndex2]; 00460 return GeoTessUtils::getDistance3D(grid.getVertex(m1[0]), 00461 profiles[m1[0]][m1[1]]->getRadius(m1[2]), grid.getVertex(m2[0]), 00462 profiles[m2[0]][m2[1]]->getRadius(m2[2])); 00463 } 00464 00465 // /** 00466 // * Append the input new values array to the profile at pointIndex 00467 // */ 00468 // template<typename T> 00469 // void appendData(int pointIndex, T* newValues, int n) 00470 // { 00471 // vector<int>& map = pointMap[pointIndex]; 00472 // profiles[map[0]][map[1]]->appendData<T>(map[2], newValues, n); 00473 // } 00474 00475 00499 void getPointNeighbors(set<int>& pointNeighbors, int pointIndex); 00500 00506 string getPointLatLonString(int pointIndex) 00507 { 00508 return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex)); 00509 } 00510 00516 string toString(int pointIndex) 00517 { 00518 char s[100]; 00519 string frmt = "%8.3f"; 00520 sprintf(s, frmt.c_str(), getPointDepth(pointIndex)); 00521 return GeoTessUtils::getLatLonString(getPointUnitVector(pointIndex)) 00522 + " " + s; 00523 } 00524 00525 }; 00526 // end class PointMap 00527 00528 }// end namespace geotess 00529 00530 #endif // POINTMAP_OBJECT_H