GeoTessCPP: include/GeoTessMetaData.h Source File

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

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Friends Macros
GeoTessMetaData.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 GEOTESSMETADATA_OBJECT_H
37 #define GEOTESSMETADATA_OBJECT_H
38
39 // **** _SYSTEM INCLUDES_ ******************************************************
40
41 #include <iostream>
42 #include <string>
43 #include <fstream>
44 #include <vector>
45 #include <set>
46 #include <list>
47 #include <sstream>
48
49 // use standard library objects
50 using namespace std;
51
52 // **** _LOCAL INCLUDES_ *******************************************************
53
54 #include "CPPUtils.h"
55 #include "GeoTessUtils.h"
56 #include "GeoTessDataType.h"
57 #include "GeoTessOptimizationType.h"
58 #include "GeoTessException.h"
59 #include "IFStreamBinary.h"
60 #include "IFStreamAscii.h"
61 #include "EarthShape.h"
62
63 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
64
65 namespace geotess
66 {
67
68 // **** _FORWARD REFERENCES_ ***************************************************
69
70 // **** _CLASS DEFINITION_ *****************************************************
71
95 class GEOTESS_EXP_IMP GeoTessMetaData
96 {
97 private:
98
99 EarthShape earthShape;
100
104 string description;
105
109 int nLayers;
110
114 int nVertices;
115
120 string* layerNames;
121
126 int* layerTessIds;
127
132 const GeoTessDataType* dataType;
133
139 int nAttributes;
140
145 string* attributeNames;
146
151 string* attributeUnits;
152
158 bool boolAttributeFilter;
159
168 vector<int> attributeFilter;
169
175 vector<int> inputFilter;
176
181 string attributeFilterString;
182
186 string inputModelFile;
187
191 string inputGridFile;
192
196 double loadTimeModel;
197
201 string outputModelFile;
202
206 string outputGridFile;
207
212 double writeTimeModel;
213
217 int refCount;
218
222 bool reuseGrids;
223
227 string modelSoftwareVersion;
228
233 string modelGenerationDate;
234
235 public:
236
254 GeoTessMetaData()
255 : earthShape(), description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds(
256 NULL), dataType(&GeoTessDataType::NONE), nAttributes(-1), attributeNames(
257 NULL), attributeUnits(NULL), boolAttributeFilter(false),
258 inputModelFile("none"), inputGridFile("none"), loadTimeModel(-1.0),
259 outputModelFile("none"), outputGridFile("none"), writeTimeModel(-1.0),
260 refCount(0), reuseGrids(true), modelSoftwareVersion(""), modelGenerationDate("")
261 { }
262
267 GeoTessMetaData(const string &fileName);
268
273 GeoTessMetaData(const GeoTessMetaData& md);
274
280 GeoTessMetaData& operator=(const GeoTessMetaData& other);
281
288 bool operator==(const GeoTessMetaData& other);
289
296 bool operator!=(const GeoTessMetaData& other)
297 {
298 return !(*this == other);
299 }
300
305 static string class_name() { return "GeoTessMetaData"; }
306
310 virtual ~GeoTessMetaData();
311
312 LONG_INT getMemory()
313 {
314 LONG_INT memory = (LONG_INT) sizeof(GeoTessMetaData);
315
316 // EarthShape earthShape;
317 memory += (LONG_INT) sizeof(EarthShape);
318
319 memory += (LONG_INT) (description.length() + attributeFilterString.length()
320 + inputModelFile.length() + inputGridFile.length() + outputModelFile.length()
321 + outputGridFile.length() + modelSoftwareVersion.length() + modelGenerationDate.length());
322
323 // string* layerNames;
324 memory += nLayers * (LONG_INT) sizeof(string);
325 for (int i=0; i<nLayers; ++i)
326 memory += (LONG_INT) layerNames[i].length();
327
328 // int* layerTessIds;
329 memory += nLayers * (LONG_INT)sizeof(int);
330
331 // GeoTessDataType* dataType;
332 memory += nLayers * (int)sizeof(GeoTessDataType);
333
334 // string* attributeNames;
335 // string* attributeUnits;
336 if (nAttributes > 0)
337 {
338 memory += 2 * nAttributes * (LONG_INT) sizeof(string);
339 for (int i=0; i<nAttributes; ++i)
340 {
341 memory += (LONG_INT) attributeNames[i].length();
342 memory += (LONG_INT) attributeUnits[i].length();
343 }
344 }
345
346 // vector<int> attributeFilter;
347 memory += (LONG_INT) (attributeFilter.capacity() * sizeof(int));
348
349 // vector<int> inputFilter;
350 memory += (LONG_INT) (inputFilter.capacity() * sizeof(int));
351
352 return memory;
353 }
354
359 GeoTessMetaData* copy()
360 {
361 GeoTessMetaData* cpy = new GeoTessMetaData(*this);
362 return cpy;
363 }
364
369 bool isGridReuseOn()
370 {
371 return reuseGrids;
372 }
373
379 void setReuseGrids(bool rg)
380 {
381 reuseGrids = rg;
382 }
383
412 EarthShape& getEarthShape() { return earthShape; }
413
440 void setEarthShape(const string& earthShapeName) { earthShape.setEarthShape(earthShapeName); }
441
447 const string& getInputModelFile() const
448 {
449 return inputModelFile;
450 }
451 ;
452
458 const string& getInputGridFile() const
459 {
460 return inputGridFile;
461 }
462
468 double getLoadTimeModel() const
469 {
470 return loadTimeModel;
471 }
472
478 const string& getOutputModelFile() const
479 {
480 return outputModelFile;
481 }
482 ;
483
489 const string& getOutputGridFile() const
490 {
491 return outputGridFile;
492 }
493 ;
494
500 double getWriteTimeModel() const
501 {
502 return writeTimeModel;
503 }
504 ;
505
511 const string& getDescription() const
512 {
513 return description;
514 }
515 ;
516
522 void setDescription(const string& dscr)
523 {
524 description = dscr;
525 description = CPPUtils::stringReplaceAll("\r\n", "\n", description);
526 description = CPPUtils::stringReplaceAll("\r", "\n", description);
527 //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description);
528
529 // make sure that description ends with a newline by removing
530 // newline from the end if it exists and then adding it on.
531 CPPUtils::removeEOL(description);
532 description += CPPUtils::NEWLINE;
533 }
534
541 void setLayerNames(const string& lyrNms)
542 {
543 vector<string> layrNames;
544 CPPUtils::tokenizeString(lyrNms, ";", layrNames);
545 setLayerNames(layrNames);
546 }
547
553 void setLayerNames(vector<string>& layrNms);
554
560 int getNVertices() const
561 {
562 return nVertices;
563 }
564 ;
565
571 int getNLayers() const
572 {
573 return nLayers;
574 }
575 ;
576
582 int getLayerIndex(const string& layerName) const;
583
589 void getLayerNames(vector<string>& layers)
590 {
591 layers.clear();
592 for (int i=0; i<nLayers; ++i)
593 layers.push_back(layerNames[i]);
594 }
595
601 const string* const getLayerNames()
602 {
603 return layerNames;
604 }
605
611 string getLayerName(const int& layerIndex)
612 {
613 if (layerIndex < 0 || layerIndex >= nLayers)
614 {
615 ostringstream os;
616 os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl
617 << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")"
618 << endl;
619 throw GeoTessException(os, __FILE__, __LINE__, 6001);
620 }
621
622 return layerNames[layerIndex];
623 }
624
631 string getLayerNamesString();
632
641 void setLayerTessIds(int layrTsIds[])
642 {
643 if (nLayers <= 0)
644 {
645 ostringstream os;
646 os << "Cannot call GeoTessMetaData::setLayerTessIds() "
647 << "before calling GeoTessMetaData::setLayerNames()" << endl;
648 throw GeoTessException(os, __FILE__, __LINE__, 6002);
649 }
650
651 if (layerTessIds != NULL)
652 delete[] layerTessIds;
653 layerTessIds = new int[nLayers];
654 for (int i=0; i<nLayers; ++i)
655 layerTessIds[i] = layrTsIds[i];
656 }
657
663 void setLayerTessIds(vector<int>& layrTsIds);
664
671 const int* getLayerTessIds() const
672 {
673 return layerTessIds;
674 }
675 ;
676
683 int getTessellation(int layer) const
684 {
685 return layerTessIds[layer];
686 }
687
695 void getLayers(const int& tessId, vector<int>& layers)
696 {
697 layers.clear();
698 for (int i=0; i<nLayers; ++i)
699 if (layerTessIds[i] == tessId)
700 layers.push_back(i);
701 }
702
710 int getFirstLayer(const int& tessId)
711 {
712 for (int i=0; i<nLayers; ++i)
713 if (layerTessIds[i] == tessId)
714 return i;
715 return -1;
716 }
717
725 int getLastLayer(const int& tessId)
726 {
727 for (int i=nLayers-1; i >= 0; --i)
728 if (layerTessIds[i] == tessId)
729 return i;
730 return -1;
731 }
732
739 const GeoTessDataType& getDataType() const
740 {
741 return *dataType;
742 }
743
749 void setDataType(const GeoTessDataType& dt);
750
757 void setDataType(const string& dt);
758
764 void getAttributeNames(vector<string>& attributes)
765 {
766 attributes.clear();
767 for (int i = 0; i < nAttributes; ++i)
768 attributes.push_back(attributeNames[i]);
769 }
770
776 void getAttributeUnits(vector<string>& units)
777 {
778 units.clear();
779 for (int i = 0; i < nAttributes; ++i)
780 units.push_back(attributeUnits[i]);
781 }
782
788 const string* const getAttributeNames()
789 {
790 return attributeNames;
791 }
792
798 const string* const getAttributeUnits()
799 {
800 return attributeUnits;
801 }
802
810 void setAttributes(const string& nms, const string& unts)
811 {
812 vector<string> names, units;
813 CPPUtils::tokenizeString(nms, ";", names);
814 CPPUtils::tokenizeString(unts, ";", units);
815 if (names.size() != units.size())
816 {
817 ostringstream os;
818 os << "Error in GeoTessMetaData::setAttributes(const string& nms, const string& unts)" << endl
819 << "Attribute names size (" << names.size()
820 << ") is not equal to units size (" << units.size() << ")" << endl;
821 names.clear(); units.clear();
822 throw GeoTessException(os, __FILE__, __LINE__, 6009);
823 }
824 setAttributes(names, units);
825 }
826
833 void setAttributes(const vector<string>& names, const vector<string>& units);
834
840 int getNAttributes() const
841 {
842 return nAttributes;
843 }
844
851 const string& getAttributeName(int attributeIndex) const
852 {
853 if (attributeIndex < 0 || attributeIndex >= nAttributes)
854 {
855 ostringstream os;
856 os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl
857 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
858 << endl;
859 throw GeoTessException(os, __FILE__, __LINE__, 6003);
860 }
861
862 return attributeNames[attributeIndex];
863 }
864
870 int getAttributeIndex(string name);
871
878 string getAttributeNamesString() const;
879
886 string getAttributeUnitsString() const;
887
894 const string& getAttributeUnit(int attributeIndex) const
895 {
896 if (attributeIndex < 0 || attributeIndex >= nAttributes)
897 {
898 ostringstream os;
899 os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
900 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
901 << endl;
902 throw GeoTessException(os, __FILE__, __LINE__, 6004);
903 }
904 return attributeUnits[attributeIndex];
905 }
906
913 string getAttributeString(int attributeIndex) const
914 {
915 if (attributeIndex < 0 || attributeIndex >= nAttributes)
916 {
917 ostringstream os;
918 os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
919 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
920 << endl;
921 throw GeoTessException(os, __FILE__, __LINE__, 6004);
922 }
923 return attributeNames[attributeIndex] + " (" + attributeUnits[attributeIndex]+")";
924 }
925
930 string toString(const string& className, LONG_INT memory) const;
931
936 string toString() const;
937
944 const string& getModelSoftwareVersion() { return modelSoftwareVersion; }
945
954 const string& getModelGenerationDate()
955 { return modelGenerationDate; }
956
962 void setModelSoftwareVersion(const string& swVersion)
963 { modelSoftwareVersion = swVersion; }
964
971 void setModelGenerationDate(const string& genDate)
972 { modelGenerationDate = genDate; }
973
974 // All methods below this point are public but are not documented in the doxygen documentation.
975 // These are methods that typical applications will never need to call. They have to be
976 // public because other classes in the GeoTess namespace need to access them.
977 //
979
985 bool applyAttributeFilter() { return boolAttributeFilter; }
986
995 vector<int>& getAttributeFilter() { return attributeFilter; }
996
1002 void setAttributeFilter(vector<int>& filter) { inputFilter = filter; }
1003
1009 void checkComplete();
1010
1011 void loadMetaData(IFStreamBinary& input);
1012
1013 void loadMetaData(IFStreamAscii& input);
1014
1015 int getRefCount() { return refCount; }
1016
1020 void addReference() { ++refCount; }
1021
1025 void removeReference()
1026 {
1027 if (isNotReferenced())
1028 {
1029 ostringstream os;
1030 os << endl << "ERROR in GeoTessMetaData::removeReference" << endl
1031 << "Reference count (" << refCount << ") is already zero."
1032 << endl;
1033 throw GeoTessException(os, __FILE__, __LINE__, 6005);
1034 }
1035
1036 --refCount;
1037 }
1038
1042 bool isNotReferenced() { return (refCount == 0) ? true : false; }
1043
1047 void setNVertices(const int& nvert) { nVertices = nvert; }
1048
1054 void setInputModelFile(const string& imf) { inputModelFile = imf; }
1055
1061 void setInputGridFile(const string& igf) { inputGridFile = igf; }
1062
1068 void setLoadTimeModel(double ltm) { loadTimeModel = ltm; }
1069
1075 void setOutputModelFile(const string& omf) { outputModelFile = omf; }
1076
1082 void setOutputGridFile(const string& ogf) { outputGridFile = ogf; }
1083
1089 void setWriteTimeModel(double wtm) { writeTimeModel = wtm; }
1090
1091 // the following methods that involve Optimization type are all deprecated.
1092 // They no longer have any effect since GeoTess is always optimized for speed.
1093 const GeoTessOptimizationType& getOptimizationType() const { return GeoTessOptimizationType::SPEED; }
1094 void setOptimizationType(const GeoTessOptimizationType& ot);
1095 void setOptimizationType(const string& ot);
1096
1098
1099 };
1100 // end class GeoTessMetaData
1101
1102 }// end namespace geotess
1103
1104 #endif // GEOTESSMETADATA_OBJECT_H