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 GEOTESSMETADATA_OBJECT_H 00037 #define GEOTESSMETADATA_OBJECT_H 00038 00039 // **** _SYSTEM INCLUDES_ ****************************************************** 00040 00041 #include <iostream> 00042 #include <string> 00043 #include <fstream> 00044 #include <vector> 00045 #include <set> 00046 #include <list> 00047 #include <sstream> 00048 00049 // use standard library objects 00050 using namespace std; 00051 00052 // **** _LOCAL INCLUDES_ ******************************************************* 00053 00054 #include "CPPUtils.h" 00055 #include "GeoTessUtils.h" 00056 #include "GeoTessDataType.h" 00057 #include "GeoTessOptimizationType.h" 00058 #include "GeoTessException.h" 00059 #include "IFStreamBinary.h" 00060 #include "IFStreamAscii.h" 00061 00062 // **** _BEGIN GEOTESS NAMESPACE_ ********************************************** 00063 00064 namespace geotess 00065 { 00066 00067 // **** _FORWARD REFERENCES_ *************************************************** 00068 00069 // **** _CLASS DEFINITION_ ***************************************************** 00070 00095 class GEOTESS_EXP_IMP GeoTessMetaData 00096 { 00097 private: 00098 00102 string description; 00103 00107 int nLayers; 00108 00112 int nVertices; 00113 00118 string* layerNames; 00119 00124 int* layerTessIds; 00125 00130 const GeoTessDataType* dataType; 00131 00137 int nAttributes; 00138 00143 string* attributeNames; 00144 00149 string* attributeUnits; 00150 00156 bool boolAttributeFilter; 00157 00166 vector<int> attributeFilter; 00167 00173 vector<int> inputFilter; 00174 00179 string attributeFilterString; 00180 00200 const GeoTessOptimizationType* optimization; 00201 00205 string inputModelFile; 00206 00210 string inputGridFile; 00211 00215 double loadTimeModel; 00216 00220 string outputModelFile; 00221 00225 string outputGridFile; 00226 00231 double writeTimeModel; 00232 00236 int refCount; 00237 00241 bool reuseGrids; 00242 00246 string modelSoftwareVersion; 00247 00252 string modelGenerationDate; 00253 00254 public: 00255 00274 GeoTessMetaData() 00275 : description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds( 00276 NULL), dataType(&GeoTessDataType::NONE), nAttributes(-1), attributeNames( 00277 NULL), attributeUnits(NULL), boolAttributeFilter(false), optimization( 00278 &GeoTessOptimizationType::SPEED), inputModelFile("none"), inputGridFile( 00279 "none"), loadTimeModel(-1.0), outputModelFile("none"), outputGridFile( 00280 "none"), writeTimeModel(-1.0), refCount(0), reuseGrids( 00281 true), modelSoftwareVersion(""), modelGenerationDate("") 00282 { } 00283 00288 GeoTessMetaData(const string &fileName); 00289 00294 GeoTessMetaData(const GeoTessMetaData& md); 00295 00301 GeoTessMetaData& operator=(const GeoTessMetaData& other); 00302 00309 bool operator==(const GeoTessMetaData& other); 00310 00317 bool operator!=(const GeoTessMetaData& other) 00318 { 00319 return !(*this == other); 00320 } 00321 00325 virtual ~GeoTessMetaData(); 00326 00331 GeoTessMetaData* copy() 00332 { 00333 GeoTessMetaData* cpy = new GeoTessMetaData(*this); 00334 return cpy; 00335 } 00336 00341 bool isGridReuseOn() 00342 { 00343 return reuseGrids; 00344 } 00345 00351 void setReuseGrids(bool rg) 00352 { 00353 reuseGrids = rg; 00354 } 00355 00361 const string& getInputModelFile() const 00362 { 00363 return inputModelFile; 00364 } 00365 ; 00366 00372 const string& getInputGridFile() const 00373 { 00374 return inputGridFile; 00375 } 00376 00382 double getLoadTimeModel() const 00383 { 00384 return loadTimeModel; 00385 } 00386 00392 const string& getOutputModelFile() const 00393 { 00394 return outputModelFile; 00395 } 00396 ; 00397 00403 const string& getOutputGridFile() const 00404 { 00405 return outputGridFile; 00406 } 00407 ; 00408 00414 double getWriteTimeModel() const 00415 { 00416 return writeTimeModel; 00417 } 00418 ; 00419 00425 const string& getDescription() const 00426 { 00427 return description; 00428 } 00429 ; 00430 00436 void setDescription(const string& dscr) 00437 { 00438 description = dscr; 00439 description = CPPUtils::stringReplaceAll("\r\n", "\n", description); 00440 description = CPPUtils::stringReplaceAll("\r", "\n", description); 00441 //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description); 00442 00443 // make sure that description ends with a newline by removing 00444 // newline from the end if it exists and then adding it on. 00445 CPPUtils::removeEOL(description); 00446 description += CPPUtils::NEWLINE; 00447 } 00448 00455 void setLayerNames(const string& lyrNms) 00456 { 00457 vector<string> layrNames; 00458 CPPUtils::tokenizeString(lyrNms, ";", layrNames); 00459 setLayerNames(layrNames); 00460 } 00461 00467 void setLayerNames(vector<string>& layrNms); 00468 00474 int getNVertices() const 00475 { 00476 return nVertices; 00477 } 00478 ; 00479 00485 int getNLayers() const 00486 { 00487 return nLayers; 00488 } 00489 ; 00490 00496 int getLayerIndex(const string& layerName) const; 00497 00503 void getLayerNames(vector<string>& layers) 00504 { 00505 layers.clear(); 00506 for (int i=0; i<nLayers; ++i) 00507 layers.push_back(layerNames[i]); 00508 } 00509 00515 const string* const getLayerNames() 00516 { 00517 return layerNames; 00518 } 00519 00525 string getLayerName(const int& layerIndex) 00526 { 00527 if (layerIndex < 0 || layerIndex >= nLayers) 00528 { 00529 ostringstream os; 00530 os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl 00531 << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")" 00532 << endl; 00533 throw GeoTessException(os, __FILE__, __LINE__, 6001); 00534 } 00535 00536 return layerNames[layerIndex]; 00537 } 00538 00545 string getLayerNamesString(); 00546 00555 void setLayerTessIds(int layrTsIds[]) 00556 { 00557 if (nLayers <= 0) 00558 { 00559 ostringstream os; 00560 os << "Cannot call GeoTessMetaData::setLayerTessIds() " 00561 << "before calling GeoTessMetaData::setLayerNames()" << endl; 00562 throw GeoTessException(os, __FILE__, __LINE__, 6002); 00563 } 00564 00565 if (layerTessIds != NULL) 00566 delete[] layerTessIds; 00567 layerTessIds = new int[nLayers]; 00568 for (int i=0; i<nLayers; ++i) 00569 layerTessIds[i] = layrTsIds[i]; 00570 } 00571 00577 void setLayerTessIds(vector<int>& layrTsIds); 00578 00585 const int* getLayerTessIds() const 00586 { 00587 return layerTessIds; 00588 } 00589 ; 00590 00597 int getTessellation(int layer) const 00598 { 00599 return layerTessIds[layer]; 00600 } 00601 00609 void getLayers(const int& tessId, vector<int>& layers) 00610 { 00611 layers.clear(); 00612 for (int i=0; i<nLayers; ++i) 00613 if (layerTessIds[i] == tessId) 00614 layers.push_back(i); 00615 } 00616 00624 int getFirstLayer(const int& tessId) 00625 { 00626 for (int i=0; i<nLayers; ++i) 00627 if (layerTessIds[i] == tessId) 00628 return i; 00629 return -1; 00630 } 00631 00639 int getLastLayer(const int& tessId) 00640 { 00641 for (int i=nLayers-1; i >= 0; --i) 00642 if (layerTessIds[i] == tessId) 00643 return i; 00644 return -1; 00645 } 00646 00653 const GeoTessDataType& getDataType() const 00654 { 00655 return *dataType; 00656 } 00657 00663 void setDataType(const GeoTessDataType& dt); 00664 00671 void setDataType(const string& dt); 00672 00694 const GeoTessOptimizationType& getOptimizationType() const 00695 { 00696 return *optimization; 00697 } 00698 00720 void setOptimizationType(const GeoTessOptimizationType& ot); 00721 00743 void setOptimizationType(const string& ot); 00744 00750 void getAttributeNames(vector<string>& attributes) 00751 { 00752 attributes.clear(); 00753 for (int i = 0; i < nAttributes; ++i) 00754 attributes.push_back(attributeNames[i]); 00755 } 00756 00762 void getAttributeUnits(vector<string>& units) 00763 { 00764 units.clear(); 00765 for (int i = 0; i < nAttributes; ++i) 00766 units.push_back(attributeUnits[i]); 00767 } 00768 00774 const string* const getAttributeNames() 00775 { 00776 return attributeNames; 00777 } 00778 00784 const string* const getAttributeUnits() 00785 { 00786 return attributeUnits; 00787 } 00788 00796 void setAttributes(const string& nms, const string& unts) 00797 { 00798 vector<string> names, units; 00799 CPPUtils::tokenizeString(nms, ";", names); 00800 CPPUtils::tokenizeString(unts, ";", units); 00801 if (names.size() != units.size()) 00802 { 00803 ostringstream os; 00804 os << "Error in GeoTessMetaData::setAttributes(const string& nms, const string& unts)" << endl 00805 << "Attribute names size (" << names.size() 00806 << ") is not equal to units size (" << units.size() << ")" << endl; 00807 names.clear(); units.clear(); 00808 throw GeoTessException(os, __FILE__, __LINE__, 6009); 00809 } 00810 setAttributes(names, units); 00811 } 00812 00819 void setAttributes(const vector<string>& names, const vector<string>& units); 00820 00826 int getNAttributes() const 00827 { 00828 return nAttributes; 00829 } 00830 00837 const string& getAttributeName(int attributeIndex) const 00838 { 00839 if (attributeIndex < 0 || attributeIndex >= nAttributes) 00840 { 00841 ostringstream os; 00842 os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl 00843 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")" 00844 << endl; 00845 throw GeoTessException(os, __FILE__, __LINE__, 6003); 00846 } 00847 00848 return attributeNames[attributeIndex]; 00849 } 00850 00856 int getAttributeIndex(string name); 00857 00864 string getAttributeNamesString() const; 00865 00872 string getAttributeUnitsString() const; 00873 00880 const string& getAttributeUnit(int attributeIndex) const 00881 { 00882 if (attributeIndex < 0 || attributeIndex >= nAttributes) 00883 { 00884 ostringstream os; 00885 os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl 00886 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")" 00887 << endl; 00888 throw GeoTessException(os, __FILE__, __LINE__, 6004); 00889 } 00890 return attributeUnits[attributeIndex]; 00891 } 00892 00899 string getAttributeString(int attributeIndex) const 00900 { 00901 if (attributeIndex < 0 || attributeIndex >= nAttributes) 00902 { 00903 ostringstream os; 00904 os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl 00905 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")" 00906 << endl; 00907 throw GeoTessException(os, __FILE__, __LINE__, 6004); 00908 } 00909 return attributeNames[attributeIndex] + " (" + attributeUnits[attributeIndex]+")"; 00910 } 00911 00916 string toString() const; 00917 00924 const string& getModelSoftwareVersion() { return modelSoftwareVersion; } 00925 00934 const string& getModelGenerationDate() 00935 { return modelGenerationDate; } 00936 00942 void setModelSoftwareVersion(const string& swVersion) 00943 { modelSoftwareVersion = swVersion; } 00944 00951 void setModelGenerationDate(const string& genDate) 00952 { modelGenerationDate = genDate; } 00953 00954 // All methods below this point are public but are not documented in the doxygen documentation. 00955 // These are methods that typical applications will never need to call. They have to be 00956 // public because other classes in the GeoTess namespace need to access them. 00957 // 00959 00965 bool applyAttributeFilter() { return boolAttributeFilter; } 00966 00975 vector<int>& getAttributeFilter() { return attributeFilter; } 00976 00982 void setAttributeFilter(vector<int>& filter) { inputFilter = filter; } 00983 00989 void checkComplete(); 00990 00991 void loadMetaData(IFStreamBinary& input); 00992 00993 void loadMetaData(IFStreamAscii& input); 00994 00995 int getRefCount() { return refCount; } 00996 01000 void addReference() { ++refCount; } 01001 01005 void removeReference() 01006 { 01007 if (isNotReferenced()) 01008 { 01009 ostringstream os; 01010 os << endl << "ERROR in GeoTessMetaData::removeReference" << endl 01011 << "Reference count (" << refCount << ") is already zero." 01012 << endl; 01013 throw GeoTessException(os, __FILE__, __LINE__, 6005); 01014 } 01015 01016 --refCount; 01017 } 01018 01022 bool isNotReferenced() { return (refCount == 0) ? true : false; } 01023 01027 void setNVertices(const int& nvert) { nVertices = nvert; } 01028 01034 void setInputModelFile(const string& imf) { inputModelFile = imf; } 01035 01041 void setInputGridFile(const string& igf) { inputGridFile = igf; } 01042 01048 void setLoadTimeModel(double ltm) { loadTimeModel = ltm; } 01049 01055 void setOutputModelFile(const string& omf) { outputModelFile = omf; } 01056 01062 void setOutputGridFile(const string& ogf) { outputGridFile = ogf; } 01063 01069 void setWriteTimeModel(double wtm) { writeTimeModel = wtm; } 01070 01072 01073 }; 01074 // end class GeoTessMetaData 01075 01076 }// end namespace geotess 01077 01078 #endif // GEOTESSMETADATA_OBJECT_H