GeoTessCPP: include/GeoTessMetaData.h Source File

GeoTessCPP 2.0.0 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 "DataType.h"
57 #include "OptimizationType.h"
58 #include "GeoTessException.h"
59 #include "IFStreamBinary.h"
60 #include "IFStreamAscii.h"
61
62 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
63
64 namespace geotess
65 {
66
67 // **** _FORWARD REFERENCES_ ***************************************************
68
69 // **** _CLASS DEFINITION_ *****************************************************
70
95 class GEOTESS_EXP_IMP GeoTessMetaData
96 {
97 private:
98
102 string description;
103
107 int nLayers;
108
112 int nVertices;
113
118 string* layerNames;
119
124 int* layerTessIds;
125
130 const DataType* dataType;
131
137 int nAttributes;
138
143 string* attributeNames;
144
149 string* attributeUnits;
150
156 bool boolAttributeFilter;
157
166 vector<int> attributeFilter;
167
173 vector<int> inputFilter;
174
179 string attributeFilterString;
180
200 const OptimizationType* optimization;
201
205 string inputModelFile;
206
210 string inputGridFile;
211
215 double loadTimeModel;
216
220 string outputModelFile;
221
225 string outputGridFile;
226
231 double writeTimeModel;
232
236 int refCount;
237
241 bool reuseGrids;
242
246 string modelSoftwareVersion;
247
252 string modelGenerationDate;
253
254 public:
255
274 GeoTessMetaData()
275 : description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds(
276 NULL), dataType(&DataType::NONE), nAttributes(-1), attributeNames(
277 NULL), attributeUnits(NULL), boolAttributeFilter(false), optimization(
278 &OptimizationType::SPEED), inputModelFile("none"), inputGridFile(
279 "none"), loadTimeModel(-1.0), outputModelFile("none"), outputGridFile(
280 "none"), writeTimeModel(-1.0), refCount(0), reuseGrids(
281 true), modelSoftwareVersion(""), modelGenerationDate("")
282 { }
283
287 GeoTessMetaData(const string &fileName);
288
292 GeoTessMetaData(const GeoTessMetaData& md);
293
297 GeoTessMetaData& operator=(const GeoTessMetaData& other);
298
302 bool operator==(const GeoTessMetaData& other);
303
307 bool operator!=(const GeoTessMetaData& other)
308 {
309 return !(*this == other);
310 }
311
315 virtual ~GeoTessMetaData();
316
320 GeoTessMetaData* copy()
321 {
322 GeoTessMetaData* cpy = new GeoTessMetaData(*this);
323 return cpy;
324 }
325
329 bool isGridReuseOn()
330 {
331 return reuseGrids;
332 }
333
339 void setReuseGrids(bool rg)
340 {
341 reuseGrids = rg;
342 }
343
349 const string& getInputModelFile() const
350 {
351 return inputModelFile;
352 }
353 ;
354
360 const string& getInputGridFile() const
361 {
362 return inputGridFile;
363 }
364
370 double getLoadTimeModel() const
371 {
372 return loadTimeModel;
373 }
374
380 const string& getOutputModelFile() const
381 {
382 return outputModelFile;
383 }
384 ;
385
391 const string& getOutputGridFile() const
392 {
393 return outputGridFile;
394 }
395 ;
396
402 double getWriteTimeModel() const
403 {
404 return writeTimeModel;
405 }
406 ;
407
413 const string& getDescription() const
414 {
415 return description;
416 }
417 ;
418
424 void setDescription(const string& dscr)
425 {
426 description = dscr;
427 description = CPPUtils::stringReplaceAll("\r\n", "\n", description);
428 description = CPPUtils::stringReplaceAll("\r", "\n", description);
429 //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description);
430
431 // make sure that description ends with a newline by removing
432 // newline from the end if it exists and then adding it on.
433 CPPUtils::removeEOL(description);
434 description += CPPUtils::NEWLINE;
435 }
436
442 void setLayerNames(const string& lyrNms)
443 {
444 vector<string> layrNames;
445 CPPUtils::tokenizeString(lyrNms, ";", layrNames);
446 setLayerNames(layrNames);
447 }
448
454 void setLayerNames(vector<string>& layrNms);
455
461 int getNVertices() const
462 {
463 return nVertices;
464 }
465 ;
466
472 int getNLayers() const
473 {
474 return nLayers;
475 }
476 ;
477
482 int getLayerIndex(const string& layerName) const;
483
487 void getLayerNames(vector<string>& layers)
488 {
489 layers.clear();
490 for (int i=0; i<nLayers; ++i)
491 layers.push_back(layerNames[i]);
492 }
493
498 const string* const getLayerNames()
499 {
500 return layerNames;
501 }
502
506 string getLayerName(const int& layerIndex)
507 {
508 if (layerIndex < 0 || layerIndex >= nLayers)
509 {
510 ostringstream os;
511 os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl
512 << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")"
513 << endl;
514 throw GeoTessException(os, __FILE__, __LINE__, 6001);
515 }
516
517 return layerNames[layerIndex];
518 }
519
526 string getLayerNamesString();
527
536 void setLayerTessIds(int layrTsIds[])
537 {
538 if (nLayers <= 0)
539 {
540 ostringstream os;
541 os << "Cannot call GeoTessMetaData::setLayerTessIds() "
542 << "before calling GeoTessMetaData::setLayerNames()" << endl;
543 throw GeoTessException(os, __FILE__, __LINE__, 6002);
544 }
545
546 if (layerTessIds != NULL)
547 delete[] layerTessIds;
548 layerTessIds = new int[nLayers];
549 for (int i=0; i<nLayers; ++i)
550 layerTessIds[i] = layrTsIds[i];
551 }
552
558 void setLayerTessIds(vector<int>& layrTsIds);
559
566 const int* getLayerTessIds() const
567 {
568 return layerTessIds;
569 }
570 ;
571
578 int getTessellation(int layer) const
579 {
580 return layerTessIds[layer];
581 }
582
590 void getLayers(const int& tessId, vector<int>& layers)
591 {
592 layers.clear();
593 for (int i=0; i<nLayers; ++i)
594 if (layerTessIds[i] == tessId)
595 layers.push_back(i);
596 }
597
605 int getFirstLayer(const int& tessId)
606 {
607 for (int i=0; i<nLayers; ++i)
608 if (layerTessIds[i] == tessId)
609 return i;
610 return -1;
611 }
612
620 int getLastLayer(const int& tessId)
621 {
622 for (int i=nLayers-1; i >= 0; --i)
623 if (layerTessIds[i] == tessId)
624 return i;
625 return -1;
626 }
627
634 const DataType& getDataType() const
635 {
636 return *dataType;
637 }
638
644 void setDataType(const DataType& dt);
645
652 void setDataType(const string& dt);
653
675 const OptimizationType& getOptimizationType() const
676 {
677 return *optimization;
678 }
679
701 void setOptimizationType(const OptimizationType& ot);
702
724 void setOptimizationType(const string& ot);
725
729 void getAttributeNames(vector<string>& attributes)
730 {
731 attributes.clear();
732 for (int i = 0; i < nAttributes; ++i)
733 attributes.push_back(attributeNames[i]);
734 }
735
739 void getAttributeUnits(vector<string>& units)
740 {
741 units.clear();
742 for (int i = 0; i < nAttributes; ++i)
743 units.push_back(attributeUnits[i]);
744 }
745
750 const string* const getAttributeNames()
751 {
752 return attributeNames;
753 }
754
759 const string* const getAttributeUnits()
760 {
761 return attributeUnits;
762 }
763
769 void setAttributes(const string& nms, const string& unts)
770 {
771 vector<string> names, units;
772 CPPUtils::tokenizeString(nms, ";", names);
773 CPPUtils::tokenizeString(unts, ";", units);
774 setAttributes(names, units);
775 }
776
783 void setAttributes(const vector<string>& names, const vector<string>& units);
784
790 int getNAttributes() const
791 {
792 return nAttributes;
793 }
794
801 const string& getAttributeName(int attributeIndex) const
802 {
803 if (attributeIndex < 0 || attributeIndex >= nAttributes)
804 {
805 ostringstream os;
806 os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl
807 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
808 << endl;
809 throw GeoTessException(os, __FILE__, __LINE__, 6003);
810 }
811
812 return attributeNames[attributeIndex];
813 }
814
819 int getAttributeIndex(string name);
820
827 string getAttributeNamesString() const;
828
835 string getAttributeUnitsString() const;
836
843 const string& getAttributeUnit(int attributeIndex) const
844 {
845 if (attributeIndex < 0 || attributeIndex >= nAttributes)
846 {
847 ostringstream os;
848 os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
849 << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
850 << endl;
851 throw GeoTessException(os, __FILE__, __LINE__, 6004);
852 }
853 return attributeUnits[attributeIndex];
854 }
855
859 string toString() const;
860
867 const string& getModelSoftwareVersion() { return modelSoftwareVersion; }
868
877 const string& getModelGenerationDate()
878 { return modelGenerationDate; }
879
885 void setModelSoftwareVersion(const string& swVersion)
886 { modelSoftwareVersion = swVersion; }
887
894 void setModelGenerationDate(const string& genDate)
895 { modelGenerationDate = genDate; }
896
897 // All methods below this point are public but are not documented in the doxygen documentation.
898 // These are methods that typical applications will never need to call. They have to be
899 // public because other classes in the GeoTess namespace need to access them.
900 //
902
908 bool applyAttributeFilter() { return boolAttributeFilter; }
909
918 vector<int>& getAttributeFilter() { return attributeFilter; }
919
925 void setAttributeFilter(vector<int>& filter) { inputFilter = filter; }
926
932 void checkComplete();
933
934 void loadMetaData(IFStreamBinary& input);
935
936 void loadMetaData(IFStreamAscii& input);
937
938 int getRefCount() { return refCount; }
939
943 void addReference() { ++refCount; }
944
948 void removeReference()
949 {
950 if (isNotReferenced())
951 {
952 ostringstream os;
953 os << endl << "ERROR in GeoTessMetaData::removeReference" << endl
954 << "Reference count (" << refCount << ") is already zero."
955 << endl;
956 throw GeoTessException(os, __FILE__, __LINE__, 6005);
957 }
958
959 --refCount;
960 }
961
965 bool isNotReferenced() { return (refCount == 0) ? true : false; }
966
970 void setNVertices(const int& nvert) { nVertices = nvert; }
971
977 void setInputModelFile(const string& imf) { inputModelFile = imf; }
978
984 void setInputGridFile(const string& igf) { inputGridFile = igf; }
985
991 void setLoadTimeModel(double ltm) { loadTimeModel = ltm; }
992
998 void setOutputModelFile(const string& omf) { outputModelFile = omf; }
999
1005 void setOutputGridFile(const string& ogf) { outputGridFile = ogf; }
1006
1012 void setWriteTimeModel(double wtm) { writeTimeModel = wtm; }
1013
1015
1016 };
1017 // end class GeoTessMetaData
1018
1019 }// end namespace geotess
1020
1021 #endif // GEOTESSMETADATA_OBJECT_H