GeoTessCPP  2.6.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 #include <map>
49 
50 
51 // use standard library objects
52 using namespace std;
53 
54 // **** _LOCAL INCLUDES_ *******************************************************
55 
56 #include "CPPUtils.h"
57 #include "GeoTessUtils.h"
58 #include "GeoTessDataType.h"
59 #include "GeoTessException.h"
60 #include "IFStreamBinary.h"
61 #include "IFStreamAscii.h"
62 #include "EarthShape.h"
63 
64 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
65 
66 namespace geotess
67 {
68 
69 // **** _FORWARD REFERENCES_ ***************************************************
70 
71 // **** _CLASS DEFINITION_ *****************************************************
72 
97 {
98 private:
99 
100  EarthShape earthShape;
101 
102  int modelFileFormat;
103 
107  string description;
108 
112  int nLayers;
113 
117  int nVertices;
118 
123  string* layerNames;
124 
129  int* layerTessIds;
130 
135  const GeoTessDataType* dataType;
136 
142  int nAttributes;
143 
148  string* attributeNames;
149 
154  string* attributeUnits;
155 
161  bool boolAttributeFilter;
162 
171  vector<int> attributeFilter;
172 
178  vector<int> inputFilter;
179 
184  string attributeFilterString;
185 
189  string inputModelFile;
190 
194  string inputGridFile;
195 
199  double loadTimeModel;
200 
204  string outputModelFile;
205 
209  string outputGridFile;
210 
215  double writeTimeModel;
216 
220  int refCount;
221 
225  bool reuseGrids;
226 
230  string modelSoftwareVersion;
231 
236  string modelGenerationDate;
237 
238  map<string, string> properties;
239 
240 public:
241 
260  : earthShape(), description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds(
261  NULL), dataType(&GeoTessDataType::NONE), nAttributes(-1), attributeNames(
262  NULL), attributeUnits(NULL), boolAttributeFilter(false),
263  inputModelFile("none"), inputGridFile("none"), loadTimeModel(-1.0),
264  outputModelFile("none"), outputGridFile("none"), writeTimeModel(-1.0),
265  refCount(0), reuseGrids(true), modelSoftwareVersion(""), modelGenerationDate("")
266  { }
267 
272  GeoTessMetaData(const string &fileName);
273 
279 
286 
293  bool operator==(const GeoTessMetaData& other);
294 
301  bool operator!=(const GeoTessMetaData& other)
302  {
303  return !(*this == other);
304  }
305 
310  static string class_name() { return "GeoTessMetaData"; }
311 
315  virtual ~GeoTessMetaData();
316 
318  {
319  LONG_INT memory = (LONG_INT) sizeof(GeoTessMetaData);
320 
321  // EarthShape earthShape;
322  memory += (LONG_INT) sizeof(EarthShape);
323 
324  memory += (LONG_INT) (description.length() + attributeFilterString.length()
325  + inputModelFile.length() + inputGridFile.length() + outputModelFile.length()
326  + outputGridFile.length() + modelSoftwareVersion.length() + modelGenerationDate.length());
327 
328  // string* layerNames;
329  memory += nLayers * (LONG_INT) sizeof(string);
330  for (int i=0; i<nLayers; ++i)
331  memory += (LONG_INT) layerNames[i].length();
332 
333  // int* layerTessIds;
334  memory += nLayers * (LONG_INT)sizeof(int);
335 
336  // GeoTessDataType* dataType;
337  memory += nLayers * (int)sizeof(GeoTessDataType);
338 
339  // string* attributeNames;
340  // string* attributeUnits;
341  if (nAttributes > 0)
342  {
343  memory += 2 * nAttributes * (LONG_INT) sizeof(string);
344  for (int i=0; i<nAttributes; ++i)
345  {
346  memory += (LONG_INT) attributeNames[i].length();
347  memory += (LONG_INT) attributeUnits[i].length();
348  }
349  }
350 
351  // vector<int> attributeFilter;
352  memory += (LONG_INT) (attributeFilter.capacity() * sizeof(int));
353 
354  // vector<int> inputFilter;
355  memory += (LONG_INT) (inputFilter.capacity() * sizeof(int));
356 
357  return memory;
358  }
359 
365  {
366  GeoTessMetaData* cpy = new GeoTessMetaData(*this);
367  return cpy;
368  }
369 
375  {
376  return reuseGrids;
377  }
378 
384  void setReuseGrids(bool rg)
385  {
386  reuseGrids = rg;
387  }
388 
417  EarthShape& getEarthShape() { return earthShape; }
418 
445  void setEarthShape(const string& earthShapeName) { earthShape.setEarthShape(earthShapeName); }
446 
452  const string& getInputModelFile() const
453  {
454  return inputModelFile;
455  }
456 
462  const string& getInputGridFile() const
463  {
464  return inputGridFile;
465  }
466 
472  double getLoadTimeModel() const
473  {
474  return loadTimeModel;
475  }
476 
482  const string& getOutputModelFile() const
483  {
484  return outputModelFile;
485  }
486  ;
487 
493  const string& getOutputGridFile() const
494  {
495  return outputGridFile;
496  }
497  ;
498 
504  double getWriteTimeModel() const
505  {
506  return writeTimeModel;
507  }
508  ;
509 
515  const string& getDescription() const
516  {
517  return description;
518  }
519  ;
520 
526  void setDescription(const string& dscr)
527  {
528  description = dscr;
529  description = CPPUtils::stringReplaceAll("\r\n", "\n", description);
530  description = CPPUtils::stringReplaceAll("\r", "\n", description);
531  //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description);
532 
533  // make sure that description ends with a newline by removing
534  // newline from the end if it exists and then adding it on.
535  CPPUtils::removeEOL(description);
536  description += CPPUtils::NEWLINE;
537  }
538 
545  void setLayerNames(const string& lyrNms)
546  {
547  vector<string> layrNames;
548  CPPUtils::tokenizeString(lyrNms, ";", layrNames);
549  setLayerNames(layrNames);
550  }
551 
557  void setLayerNames(vector<string>& layrNms);
558 
564  int getNVertices() const
565  {
566  return nVertices;
567  }
568 
574  int getNLayers() const
575  {
576  return nLayers;
577  }
578 
584  int getLayerIndex(const string& layerName) const;
585 
591  void getLayerNames(vector<string>& layers)
592  {
593  layers.clear();
594  for (int i=0; i<nLayers; ++i)
595  layers.push_back(layerNames[i]);
596  }
597 
603  const string* const getLayerNames()
604  {
605  return layerNames;
606  }
607 
613  string getLayerName(const int& layerIndex)
614  {
615  if (layerIndex < 0 || layerIndex >= nLayers)
616  {
617  ostringstream os;
618  os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl
619  << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")"
620  << endl;
621  throw GeoTessException(os, __FILE__, __LINE__, 6001);
622  }
623 
624  return layerNames[layerIndex];
625  }
626 
634 
643  void setLayerTessIds(int layrTsIds[])
644  {
645  if (nLayers <= 0)
646  {
647  ostringstream os;
648  os << "Cannot call GeoTessMetaData::setLayerTessIds() "
649  << "before calling GeoTessMetaData::setLayerNames()" << endl;
650  throw GeoTessException(os, __FILE__, __LINE__, 6002);
651  }
652 
653  if (layerTessIds != NULL)
654  delete[] layerTessIds;
655  layerTessIds = new int[nLayers];
656  for (int i=0; i<nLayers; ++i)
657  layerTessIds[i] = layrTsIds[i];
658  }
659 
665  void setLayerTessIds(vector<int>& layrTsIds);
666 
673  const int* getLayerTessIds() const
674  {
675  return layerTessIds;
676  }
677  ;
678 
685  int getTessellation(int layer) const
686  {
687  return layerTessIds[layer];
688  }
689 
697  void getLayers(const int& tessId, vector<int>& layers)
698  {
699  layers.clear();
700  for (int i=0; i<nLayers; ++i)
701  if (layerTessIds[i] == tessId)
702  layers.push_back(i);
703  }
704 
712  int getFirstLayer(const int& tessId)
713  {
714  for (int i=0; i<nLayers; ++i)
715  if (layerTessIds[i] == tessId)
716  return i;
717  return -1;
718  }
719 
727  int getLastLayer(const int& tessId)
728  {
729  for (int i=nLayers-1; i >= 0; --i)
730  if (layerTessIds[i] == tessId)
731  return i;
732  return -1;
733  }
734 
742  {
743  return *dataType;
744  }
745 
751  void setDataType(const GeoTessDataType& dt);
752 
759  void setDataType(const string& dt);
760 
766  void getAttributeNames(vector<string>& attributes)
767  {
768  attributes.clear();
769  for (int i = 0; i < nAttributes; ++i)
770  attributes.push_back(attributeNames[i]);
771  }
772 
778  void getAttributeUnits(vector<string>& units)
779  {
780  units.clear();
781  for (int i = 0; i < nAttributes; ++i)
782  units.push_back(attributeUnits[i]);
783  }
784 
790  const string* const getAttributeNames()
791  {
792  return attributeNames;
793  }
794 
800  const string* const getAttributeUnits()
801  {
802  return attributeUnits;
803  }
804 
812  void setAttributes(const string& nms, const string& unts)
813  {
814  vector<string> names, units;
815  CPPUtils::tokenizeString(nms, ";", names);
816  CPPUtils::tokenizeString(unts, ";", units);
817  if (names.size() != units.size())
818  {
819  ostringstream os;
820  os << "Error in GeoTessMetaData::setAttributes(const string& nms, const string& unts)" << endl
821  << "Attribute names size (" << names.size()
822  << ") is not equal to units size (" << units.size() << ")" << endl;
823  names.clear(); units.clear();
824  throw GeoTessException(os, __FILE__, __LINE__, 6009);
825  }
826  setAttributes(names, units);
827 
828  properties["attributeNames"] = nms;
829  properties["attributeUnits"] = unts;
830  }
831 
838  void setAttributes(const vector<string>& names, const vector<string>& units);
839 
845  int getNAttributes() const
846  {
847  return nAttributes;
848  }
849 
856  const string& getAttributeName(int attributeIndex) const
857  {
858  if (attributeIndex < 0 || attributeIndex >= nAttributes)
859  {
860  ostringstream os;
861  os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl
862  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
863  << endl;
864  throw GeoTessException(os, __FILE__, __LINE__, 6003);
865  }
866 
867  return attributeNames[attributeIndex];
868  }
869 
875  int getAttributeIndex(string name);
876 
883  string getAttributeNamesString() const;
884 
891  string getAttributeUnitsString() const;
892 
899  const string& getAttributeUnit(int attributeIndex) const
900  {
901  if (attributeIndex < 0 || attributeIndex >= nAttributes)
902  {
903  ostringstream os;
904  os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
905  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
906  << endl;
907  throw GeoTessException(os, __FILE__, __LINE__, 6004);
908  }
909  return attributeUnits[attributeIndex];
910  }
911 
918  string getAttributeString(int attributeIndex) const
919  {
920  if (attributeIndex < 0 || attributeIndex >= nAttributes)
921  {
922  ostringstream os;
923  os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
924  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
925  << endl;
926  throw GeoTessException(os, __FILE__, __LINE__, 6004);
927  }
928  return attributeNames[attributeIndex] + " (" + attributeUnits[attributeIndex]+")";
929  }
930 
935  string toString(const string& className, LONG_INT memory) const;
936 
941  string toString() const;
942 
949  const string& getModelSoftwareVersion() { return modelSoftwareVersion; }
950 
959  const string& getModelGenerationDate()
960  { return modelGenerationDate; }
961 
967  void setModelSoftwareVersion(const string& swVersion)
968  { modelSoftwareVersion = swVersion; }
969 
976  void setModelGenerationDate(const string& genDate)
977  { modelGenerationDate = genDate; }
978 
979  // All methods below this point are public but are not documented in the doxygen documentation.
980  // These are methods that typical applications will never need to call. They have to be
981  // public because other classes in the GeoTess namespace need to access them.
982  //
984 
990  bool applyAttributeFilter() { return boolAttributeFilter; }
991 
1000  vector<int>& getAttributeFilter() { return attributeFilter; }
1001 
1007  void setAttributeFilter(vector<int>& filter) { inputFilter = filter; }
1008 
1014  void checkComplete();
1015 
1016  void loadMetaData(IFStreamBinary& input);
1017 
1018  void loadMetaData(IFStreamAscii& input);
1019 
1020  void writeMetaData(IFStreamAscii& output, const string& modelClassName,
1021  int nVertices);
1022 
1023  void writeMetaData(IFStreamBinary& output, const string& modelClassName,
1024  int nVertices);
1025 
1026  int getRefCount() { return refCount; }
1027 
1031  void addReference() { ++refCount; }
1032 
1036  void removeReference()
1037  {
1038  if (isNotReferenced())
1039  {
1040  ostringstream os;
1041  os << endl << "ERROR in GeoTessMetaData::removeReference" << endl
1042  << "Reference count (" << refCount << ") is already zero."
1043  << endl;
1044  throw GeoTessException(os, __FILE__, __LINE__, 6005);
1045  }
1046 
1047  --refCount;
1048  }
1049 
1053  bool isNotReferenced() { return (refCount == 0) ? true : false; }
1054 
1055  const map<string, string>& getProperties() { return properties; }
1056 
1060  void setNVertices(const int& nvert) { nVertices = nvert; }
1061 
1067  void setInputModelFile(const string& imf) { inputModelFile = imf; }
1068 
1074  void setInputGridFile(const string& igf) { inputGridFile = igf; }
1075 
1081  void setLoadTimeModel(double ltm) { loadTimeModel = ltm; }
1082 
1088  void setOutputModelFile(const string& omf) { outputModelFile = omf; }
1089 
1095  void setOutputGridFile(const string& ogf) { outputGridFile = ogf; }
1096 
1102  void setWriteTimeModel(double wtm) { writeTimeModel = wtm; }
1103 
1104  int getModelFileFormat() { return modelFileFormat; }
1105 
1106  void setModelFileFormat(int version) { modelFileFormat = version; }
1107 
1109 
1110 };
1111 // end class GeoTessMetaData
1112 
1113 }// end namespace geotess
1114 
1115 #endif // GEOTESSMETADATA_OBJECT_H
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
#define LONG_INT
Definition: CPPGlobals.h:111
Defines the ellipsoid that is to be used to convert between geocentric and geographic latitude and be...
Definition: EarthShape.h:86
void setEarthShape(const string &earthShape)
Definition: EarthShape.h:185
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
An exception class for all GeoTess objects.
Basic metadata information about a GeoTessModel.
const int * getLayerTessIds() const
string getAttributeUnitsString() const
GeoTessMetaData(const string &fileName)
void setLayerNames(vector< string > &layrNms)
GeoTessMetaData & operator=(const GeoTessMetaData &other)
void setDescription(const string &dscr)
void setDataType(const string &dt)
void getLayerNames(vector< string > &layers)
const string & getModelSoftwareVersion()
const GeoTessDataType & getDataType() const
const string & getAttributeUnit(int attributeIndex) const
void setAttributes(const vector< string > &names, const vector< string > &units)
const string & getModelGenerationDate()
const string *const getLayerNames()
const string & getInputGridFile() const
void getLayers(const int &tessId, vector< int > &layers)
const string *const getAttributeNames()
const string & getInputModelFile() const
bool operator==(const GeoTessMetaData &other)
const string & getOutputModelFile() const
void setLayerTessIds(vector< int > &layrTsIds)
int getFirstLayer(const int &tessId)
void setDataType(const GeoTessDataType &dt)
int getLayerIndex(const string &layerName) const
void getAttributeNames(vector< string > &attributes)
GeoTessMetaData * copy()
void setEarthShape(const string &earthShapeName)
double getWriteTimeModel() const
const string & getAttributeName(int attributeIndex) const
EarthShape & getEarthShape()
GeoTessMetaData(const GeoTessMetaData &md)
string getLayerName(const int &layerIndex)
void setModelGenerationDate(const string &genDate)
static string class_name()
void setAttributes(const string &nms, const string &unts)
double getLoadTimeModel() const
const string & getOutputGridFile() const
string toString(const string &className, LONG_INT memory) const
string getAttributeNamesString() const
void setModelSoftwareVersion(const string &swVersion)
const string & getDescription() const
void getAttributeUnits(vector< string > &units)
string getAttributeString(int attributeIndex) const
void setLayerNames(const string &lyrNms)
void setLayerTessIds(int layrTsIds[])
const string *const getAttributeUnits()
int getAttributeIndex(string name)
int getTessellation(int layer) const
int getLastLayer(const int &tessId)
bool operator!=(const GeoTessMetaData &other)
string toString() const