GeoTessCPP  2.1
Software to facilitate storage and retrieval of 3D information about the Earth.
 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"
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 
97 {
98 private:
99 
100  EarthShape earthShape;
101 
105  string description;
106 
110  int nLayers;
111 
115  int nVertices;
116 
121  string* layerNames;
122 
127  int* layerTessIds;
128 
133  const GeoTessDataType* dataType;
134 
140  int nAttributes;
141 
146  string* attributeNames;
147 
152  string* attributeUnits;
153 
159  bool boolAttributeFilter;
160 
169  vector<int> attributeFilter;
170 
176  vector<int> inputFilter;
177 
182  string attributeFilterString;
183 
203  //const GeoTessOptimizationType* optimization;
204 
208  string inputModelFile;
209 
213  string inputGridFile;
214 
218  double loadTimeModel;
219 
223  string outputModelFile;
224 
228  string outputGridFile;
229 
234  double writeTimeModel;
235 
239  int refCount;
240 
244  bool reuseGrids;
245 
249  string modelSoftwareVersion;
250 
255  string modelGenerationDate;
256 
257 public:
258 
278  : earthShape(), description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds(
279  NULL), dataType(&GeoTessDataType::NONE), nAttributes(-1), attributeNames(
280  NULL), attributeUnits(NULL), boolAttributeFilter(false),
281  inputModelFile("none"), inputGridFile("none"), loadTimeModel(-1.0),
282  outputModelFile("none"), outputGridFile("none"), writeTimeModel(-1.0),
283  refCount(0), reuseGrids(true), modelSoftwareVersion(""), modelGenerationDate("")
284  { }
285 
290  GeoTessMetaData(const string &fileName);
291 
296  GeoTessMetaData(const GeoTessMetaData& md);
297 
303  GeoTessMetaData& operator=(const GeoTessMetaData& other);
304 
311  bool operator==(const GeoTessMetaData& other);
312 
319  bool operator!=(const GeoTessMetaData& other)
320  {
321  return !(*this == other);
322  }
323 
327  virtual ~GeoTessMetaData();
328 
334  {
335  GeoTessMetaData* cpy = new GeoTessMetaData(*this);
336  return cpy;
337  }
338 
344  {
345  return reuseGrids;
346  }
347 
353  void setReuseGrids(bool rg)
354  {
355  reuseGrids = rg;
356  }
357 
358  EarthShape& getEarthShape() { return earthShape; }
359 
360  void setEarthShape(const string& earthShapeName) { earthShape.setEarthShape(earthShapeName); }
361 
367  const string& getInputModelFile() const
368  {
369  return inputModelFile;
370  }
371  ;
372 
378  const string& getInputGridFile() const
379  {
380  return inputGridFile;
381  }
382 
388  double getLoadTimeModel() const
389  {
390  return loadTimeModel;
391  }
392 
398  const string& getOutputModelFile() const
399  {
400  return outputModelFile;
401  }
402  ;
403 
409  const string& getOutputGridFile() const
410  {
411  return outputGridFile;
412  }
413  ;
414 
420  double getWriteTimeModel() const
421  {
422  return writeTimeModel;
423  }
424  ;
425 
431  const string& getDescription() const
432  {
433  return description;
434  }
435  ;
436 
442  void setDescription(const string& dscr)
443  {
444  description = dscr;
445  description = CPPUtils::stringReplaceAll("\r\n", "\n", description);
446  description = CPPUtils::stringReplaceAll("\r", "\n", description);
447  //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description);
448 
449  // make sure that description ends with a newline by removing
450  // newline from the end if it exists and then adding it on.
451  CPPUtils::removeEOL(description);
452  description += CPPUtils::NEWLINE;
453  }
454 
461  void setLayerNames(const string& lyrNms)
462  {
463  vector<string> layrNames;
464  CPPUtils::tokenizeString(lyrNms, ";", layrNames);
465  setLayerNames(layrNames);
466  }
467 
473  void setLayerNames(vector<string>& layrNms);
474 
480  int getNVertices() const
481  {
482  return nVertices;
483  }
484  ;
485 
491  int getNLayers() const
492  {
493  return nLayers;
494  }
495  ;
496 
502  int getLayerIndex(const string& layerName) const;
503 
509  void getLayerNames(vector<string>& layers)
510  {
511  layers.clear();
512  for (int i=0; i<nLayers; ++i)
513  layers.push_back(layerNames[i]);
514  }
515 
521  const string* const getLayerNames()
522  {
523  return layerNames;
524  }
525 
531  string getLayerName(const int& layerIndex)
532  {
533  if (layerIndex < 0 || layerIndex >= nLayers)
534  {
535  ostringstream os;
536  os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl
537  << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")"
538  << endl;
539  throw GeoTessException(os, __FILE__, __LINE__, 6001);
540  }
541 
542  return layerNames[layerIndex];
543  }
544 
551  string getLayerNamesString();
552 
561  void setLayerTessIds(int layrTsIds[])
562  {
563  if (nLayers <= 0)
564  {
565  ostringstream os;
566  os << "Cannot call GeoTessMetaData::setLayerTessIds() "
567  << "before calling GeoTessMetaData::setLayerNames()" << endl;
568  throw GeoTessException(os, __FILE__, __LINE__, 6002);
569  }
570 
571  if (layerTessIds != NULL)
572  delete[] layerTessIds;
573  layerTessIds = new int[nLayers];
574  for (int i=0; i<nLayers; ++i)
575  layerTessIds[i] = layrTsIds[i];
576  }
577 
583  void setLayerTessIds(vector<int>& layrTsIds);
584 
591  const int* getLayerTessIds() const
592  {
593  return layerTessIds;
594  }
595  ;
596 
603  int getTessellation(int layer) const
604  {
605  return layerTessIds[layer];
606  }
607 
615  void getLayers(const int& tessId, vector<int>& layers)
616  {
617  layers.clear();
618  for (int i=0; i<nLayers; ++i)
619  if (layerTessIds[i] == tessId)
620  layers.push_back(i);
621  }
622 
630  int getFirstLayer(const int& tessId)
631  {
632  for (int i=0; i<nLayers; ++i)
633  if (layerTessIds[i] == tessId)
634  return i;
635  return -1;
636  }
637 
645  int getLastLayer(const int& tessId)
646  {
647  for (int i=nLayers-1; i >= 0; --i)
648  if (layerTessIds[i] == tessId)
649  return i;
650  return -1;
651  }
652 
660  {
661  return *dataType;
662  }
663 
669  void setDataType(const GeoTessDataType& dt);
670 
677  void setDataType(const string& dt);
678 
700  const GeoTessOptimizationType& getOptimizationType() const { return GeoTessOptimizationType::SPEED; }
701 
723  void setOptimizationType(const GeoTessOptimizationType& ot);
724 
746  void setOptimizationType(const string& ot);
747 
753  void getAttributeNames(vector<string>& attributes)
754  {
755  attributes.clear();
756  for (int i = 0; i < nAttributes; ++i)
757  attributes.push_back(attributeNames[i]);
758  }
759 
765  void getAttributeUnits(vector<string>& units)
766  {
767  units.clear();
768  for (int i = 0; i < nAttributes; ++i)
769  units.push_back(attributeUnits[i]);
770  }
771 
777  const string* const getAttributeNames()
778  {
779  return attributeNames;
780  }
781 
787  const string* const getAttributeUnits()
788  {
789  return attributeUnits;
790  }
791 
799  void setAttributes(const string& nms, const string& unts)
800  {
801  vector<string> names, units;
802  CPPUtils::tokenizeString(nms, ";", names);
803  CPPUtils::tokenizeString(unts, ";", units);
804  if (names.size() != units.size())
805  {
806  ostringstream os;
807  os << "Error in GeoTessMetaData::setAttributes(const string& nms, const string& unts)" << endl
808  << "Attribute names size (" << names.size()
809  << ") is not equal to units size (" << units.size() << ")" << endl;
810  names.clear(); units.clear();
811  throw GeoTessException(os, __FILE__, __LINE__, 6009);
812  }
813  setAttributes(names, units);
814  }
815 
822  void setAttributes(const vector<string>& names, const vector<string>& units);
823 
829  int getNAttributes() const
830  {
831  return nAttributes;
832  }
833 
840  const string& getAttributeName(int attributeIndex) const
841  {
842  if (attributeIndex < 0 || attributeIndex >= nAttributes)
843  {
844  ostringstream os;
845  os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl
846  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
847  << endl;
848  throw GeoTessException(os, __FILE__, __LINE__, 6003);
849  }
850 
851  return attributeNames[attributeIndex];
852  }
853 
859  int getAttributeIndex(string name);
860 
867  string getAttributeNamesString() const;
868 
875  string getAttributeUnitsString() const;
876 
883  const string& getAttributeUnit(int attributeIndex) const
884  {
885  if (attributeIndex < 0 || attributeIndex >= nAttributes)
886  {
887  ostringstream os;
888  os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
889  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
890  << endl;
891  throw GeoTessException(os, __FILE__, __LINE__, 6004);
892  }
893  return attributeUnits[attributeIndex];
894  }
895 
902  string getAttributeString(int attributeIndex) const
903  {
904  if (attributeIndex < 0 || attributeIndex >= nAttributes)
905  {
906  ostringstream os;
907  os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
908  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
909  << endl;
910  throw GeoTessException(os, __FILE__, __LINE__, 6004);
911  }
912  return attributeNames[attributeIndex] + " (" + attributeUnits[attributeIndex]+")";
913  }
914 
919  string toString() const;
920 
927  const string& getModelSoftwareVersion() { return modelSoftwareVersion; }
928 
937  const string& getModelGenerationDate()
938  { return modelGenerationDate; }
939 
945  void setModelSoftwareVersion(const string& swVersion)
946  { modelSoftwareVersion = swVersion; }
947 
954  void setModelGenerationDate(const string& genDate)
955  { modelGenerationDate = genDate; }
956 
957  // All methods below this point are public but are not documented in the doxygen documentation.
958  // These are methods that typical applications will never need to call. They have to be
959  // public because other classes in the GeoTess namespace need to access them.
960  //
962 
968  bool applyAttributeFilter() { return boolAttributeFilter; }
969 
978  vector<int>& getAttributeFilter() { return attributeFilter; }
979 
985  void setAttributeFilter(vector<int>& filter) { inputFilter = filter; }
986 
992  void checkComplete();
993 
994  void loadMetaData(IFStreamBinary& input);
995 
996  void loadMetaData(IFStreamAscii& input);
997 
998  int getRefCount() { return refCount; }
999 
1003  void addReference() { ++refCount; }
1004 
1008  void removeReference()
1009  {
1010  if (isNotReferenced())
1011  {
1012  ostringstream os;
1013  os << endl << "ERROR in GeoTessMetaData::removeReference" << endl
1014  << "Reference count (" << refCount << ") is already zero."
1015  << endl;
1016  throw GeoTessException(os, __FILE__, __LINE__, 6005);
1017  }
1018 
1019  --refCount;
1020  }
1021 
1025  bool isNotReferenced() { return (refCount == 0) ? true : false; }
1026 
1030  void setNVertices(const int& nvert) { nVertices = nvert; }
1031 
1037  void setInputModelFile(const string& imf) { inputModelFile = imf; }
1038 
1044  void setInputGridFile(const string& igf) { inputGridFile = igf; }
1045 
1051  void setLoadTimeModel(double ltm) { loadTimeModel = ltm; }
1052 
1058  void setOutputModelFile(const string& omf) { outputModelFile = omf; }
1059 
1065  void setOutputGridFile(const string& ogf) { outputGridFile = ogf; }
1066 
1072  void setWriteTimeModel(double wtm) { writeTimeModel = wtm; }
1073 
1075 
1076 };
1077 // end class GeoTessMetaData
1078 
1079 }// end namespace geotess
1080 
1081 #endif // GEOTESSMETADATA_OBJECT_H
const string *const getLayerNames()
Definition: GeoTessMetaData.h:521
string getLayerName(const int &layerIndex)
Definition: GeoTessMetaData.h:531
const GeoTessOptimizationType & getOptimizationType() const
Definition: GeoTessMetaData.h:700
void setAttributes(const string &nms, const string &unts)
Definition: GeoTessMetaData.h:799
GeoTessMetaData()
Definition: GeoTessMetaData.h:277
const string & getOutputGridFile() const
Definition: GeoTessMetaData.h:409
int getLastLayer(const int &tessId)
Definition: GeoTessMetaData.h:645
const string & getAttributeUnit(int attributeIndex) const
Definition: GeoTessMetaData.h:883
int getNVertices() const
Definition: GeoTessMetaData.h:480
const string & getDescription() const
Definition: GeoTessMetaData.h:431
int getTessellation(int layer) const
Definition: GeoTessMetaData.h:603
const string & getOutputModelFile() const
Definition: GeoTessMetaData.h:398
EarthShape & getEarthShape()
Definition: GeoTessMetaData.h:358
const string & getModelGenerationDate()
Definition: GeoTessMetaData.h:937
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
Definition: GeoTessDataType.h:67
const string & getInputGridFile() const
Definition: GeoTessMetaData.h:378
int getNLayers() const
Definition: GeoTessMetaData.h:491
void setModelSoftwareVersion(const string &swVersion)
Definition: GeoTessMetaData.h:945
bool operator!=(const GeoTessMetaData &other)
Definition: GeoTessMetaData.h:319
int getNAttributes() const
Definition: GeoTessMetaData.h:829
const string *const getAttributeNames()
Definition: GeoTessMetaData.h:777
void getAttributeNames(vector< string > &attributes)
Definition: GeoTessMetaData.h:753
string getAttributeString(int attributeIndex) const
Definition: GeoTessMetaData.h:902
An exception class for all GeoTess objects.
Definition: GeoTessException.h:65
const string & getAttributeName(int attributeIndex) const
Definition: GeoTessMetaData.h:840
Enumeration of the optimization strategies supported by GeoTess including OptimizationType::SPEED and...
Definition: GeoTessOptimizationType.h:66
void setDescription(const string &dscr)
Definition: GeoTessMetaData.h:442
GeoTessMetaData * copy()
Definition: GeoTessMetaData.h:333
void getAttributeUnits(vector< string > &units)
Definition: GeoTessMetaData.h:765
const string *const getAttributeUnits()
Definition: GeoTessMetaData.h:787
void setLayerNames(const string &lyrNms)
Definition: GeoTessMetaData.h:461
const GeoTessDataType & getDataType() const
Definition: GeoTessMetaData.h:659
Definition: EarthShape.h:64
double getWriteTimeModel() const
Definition: GeoTessMetaData.h:420
const int * getLayerTessIds() const
Definition: GeoTessMetaData.h:591
bool isGridReuseOn()
Definition: GeoTessMetaData.h:343
int getFirstLayer(const int &tessId)
Definition: GeoTessMetaData.h:630
const string & getModelSoftwareVersion()
Definition: GeoTessMetaData.h:927
void setReuseGrids(bool rg)
Definition: GeoTessMetaData.h:353
Basic metadata information about a GeoTessModel.
Definition: GeoTessMetaData.h:96
void getLayers(const int &tessId, vector< int > &layers)
Definition: GeoTessMetaData.h:615
void setEarthShape(const string &earthShapeName)
Definition: GeoTessMetaData.h:360
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
double getLoadTimeModel() const
Definition: GeoTessMetaData.h:388
void setModelGenerationDate(const string &genDate)
Definition: GeoTessMetaData.h:954
const string & getInputModelFile() const
Definition: GeoTessMetaData.h:367
void setLayerTessIds(int layrTsIds[])
Definition: GeoTessMetaData.h:561
void getLayerNames(vector< string > &layers)
Definition: GeoTessMetaData.h:509