GeoTessCPP  2.0.0
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 
62 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
63 
64 namespace geotess
65 {
66 
67 // **** _FORWARD REFERENCES_ ***************************************************
68 
69 // **** _CLASS DEFINITION_ *****************************************************
70 
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 GeoTessDataType* 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 GeoTessOptimizationType* 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 
275  : description(""), nLayers(0), nVertices(0), layerNames(NULL), layerTessIds(
276  NULL), dataType(&GeoTessDataType::NONE), nAttributes(-1), attributeNames(
277  NULL), attributeUnits(NULL), boolAttributeFilter(false), optimization(
278  &GeoTessOptimizationType::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 
288  GeoTessMetaData(const string &fileName);
289 
294  GeoTessMetaData(const GeoTessMetaData& md);
295 
301  GeoTessMetaData& operator=(const GeoTessMetaData& other);
302 
309  bool operator==(const GeoTessMetaData& other);
310 
317  bool operator!=(const GeoTessMetaData& other)
318  {
319  return !(*this == other);
320  }
321 
325  virtual ~GeoTessMetaData();
326 
332  {
333  GeoTessMetaData* cpy = new GeoTessMetaData(*this);
334  return cpy;
335  }
336 
341  bool isGridReuseOn()
342  {
343  return reuseGrids;
344  }
345 
351  void setReuseGrids(bool rg)
352  {
353  reuseGrids = rg;
354  }
355 
361  const string& getInputModelFile() const
362  {
363  return inputModelFile;
364  }
365  ;
366 
372  const string& getInputGridFile() const
373  {
374  return inputGridFile;
375  }
376 
382  double getLoadTimeModel() const
383  {
384  return loadTimeModel;
385  }
386 
392  const string& getOutputModelFile() const
393  {
394  return outputModelFile;
395  }
396  ;
397 
403  const string& getOutputGridFile() const
404  {
405  return outputGridFile;
406  }
407  ;
408 
414  double getWriteTimeModel() const
415  {
416  return writeTimeModel;
417  }
418  ;
419 
425  const string& getDescription() const
426  {
427  return description;
428  }
429  ;
430 
436  void setDescription(const string& dscr)
437  {
438  description = dscr;
439  description = CPPUtils::stringReplaceAll("\r\n", "\n", description);
440  description = CPPUtils::stringReplaceAll("\r", "\n", description);
441  //description = CPPUtils::stringReplaceAll("\n", CPPUtils::NEWLINE, description);
442 
443  // make sure that description ends with a newline by removing
444  // newline from the end if it exists and then adding it on.
445  CPPUtils::removeEOL(description);
446  description += CPPUtils::NEWLINE;
447  }
448 
455  void setLayerNames(const string& lyrNms)
456  {
457  vector<string> layrNames;
458  CPPUtils::tokenizeString(lyrNms, ";", layrNames);
459  setLayerNames(layrNames);
460  }
461 
467  void setLayerNames(vector<string>& layrNms);
468 
474  int getNVertices() const
475  {
476  return nVertices;
477  }
478  ;
479 
485  int getNLayers() const
486  {
487  return nLayers;
488  }
489  ;
490 
496  int getLayerIndex(const string& layerName) const;
497 
503  void getLayerNames(vector<string>& layers)
504  {
505  layers.clear();
506  for (int i=0; i<nLayers; ++i)
507  layers.push_back(layerNames[i]);
508  }
509 
515  const string* const getLayerNames()
516  {
517  return layerNames;
518  }
519 
525  string getLayerName(const int& layerIndex)
526  {
527  if (layerIndex < 0 || layerIndex >= nLayers)
528  {
529  ostringstream os;
530  os << endl << "ERROR in GeoTessMetaData::getLayerName(int layerIndex)" << endl
531  << "attributeIndex (" << layerIndex << ") is out of range (0-" << nLayers-1 << ")"
532  << endl;
533  throw GeoTessException(os, __FILE__, __LINE__, 6001);
534  }
535 
536  return layerNames[layerIndex];
537  }
538 
545  string getLayerNamesString();
546 
555  void setLayerTessIds(int layrTsIds[])
556  {
557  if (nLayers <= 0)
558  {
559  ostringstream os;
560  os << "Cannot call GeoTessMetaData::setLayerTessIds() "
561  << "before calling GeoTessMetaData::setLayerNames()" << endl;
562  throw GeoTessException(os, __FILE__, __LINE__, 6002);
563  }
564 
565  if (layerTessIds != NULL)
566  delete[] layerTessIds;
567  layerTessIds = new int[nLayers];
568  for (int i=0; i<nLayers; ++i)
569  layerTessIds[i] = layrTsIds[i];
570  }
571 
577  void setLayerTessIds(vector<int>& layrTsIds);
578 
585  const int* getLayerTessIds() const
586  {
587  return layerTessIds;
588  }
589  ;
590 
597  int getTessellation(int layer) const
598  {
599  return layerTessIds[layer];
600  }
601 
609  void getLayers(const int& tessId, vector<int>& layers)
610  {
611  layers.clear();
612  for (int i=0; i<nLayers; ++i)
613  if (layerTessIds[i] == tessId)
614  layers.push_back(i);
615  }
616 
624  int getFirstLayer(const int& tessId)
625  {
626  for (int i=0; i<nLayers; ++i)
627  if (layerTessIds[i] == tessId)
628  return i;
629  return -1;
630  }
631 
639  int getLastLayer(const int& tessId)
640  {
641  for (int i=nLayers-1; i >= 0; --i)
642  if (layerTessIds[i] == tessId)
643  return i;
644  return -1;
645  }
646 
653  const GeoTessDataType& getDataType() const
654  {
655  return *dataType;
656  }
657 
663  void setDataType(const GeoTessDataType& dt);
664 
671  void setDataType(const string& dt);
672 
694  const GeoTessOptimizationType& getOptimizationType() const
695  {
696  return *optimization;
697  }
698 
720  void setOptimizationType(const GeoTessOptimizationType& ot);
721 
743  void setOptimizationType(const string& ot);
744 
750  void getAttributeNames(vector<string>& attributes)
751  {
752  attributes.clear();
753  for (int i = 0; i < nAttributes; ++i)
754  attributes.push_back(attributeNames[i]);
755  }
756 
762  void getAttributeUnits(vector<string>& units)
763  {
764  units.clear();
765  for (int i = 0; i < nAttributes; ++i)
766  units.push_back(attributeUnits[i]);
767  }
768 
774  const string* const getAttributeNames()
775  {
776  return attributeNames;
777  }
778 
784  const string* const getAttributeUnits()
785  {
786  return attributeUnits;
787  }
788 
796  void setAttributes(const string& nms, const string& unts)
797  {
798  vector<string> names, units;
799  CPPUtils::tokenizeString(nms, ";", names);
800  CPPUtils::tokenizeString(unts, ";", units);
801  if (names.size() != units.size())
802  {
803  ostringstream os;
804  os << "Error in GeoTessMetaData::setAttributes(const string& nms, const string& unts)" << endl
805  << "Attribute names size (" << names.size()
806  << ") is not equal to units size (" << units.size() << ")" << endl;
807  names.clear(); units.clear();
808  throw GeoTessException(os, __FILE__, __LINE__, 6009);
809  }
810  setAttributes(names, units);
811  }
812 
819  void setAttributes(const vector<string>& names, const vector<string>& units);
820 
826  int getNAttributes() const
827  {
828  return nAttributes;
829  }
830 
837  const string& getAttributeName(int attributeIndex) const
838  {
839  if (attributeIndex < 0 || attributeIndex >= nAttributes)
840  {
841  ostringstream os;
842  os << endl << "ERROR in GeoTessMetaData::getAttributeName(int attributeIndex)" << endl
843  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
844  << endl;
845  throw GeoTessException(os, __FILE__, __LINE__, 6003);
846  }
847 
848  return attributeNames[attributeIndex];
849  }
850 
856  int getAttributeIndex(string name);
857 
864  string getAttributeNamesString() const;
865 
872  string getAttributeUnitsString() const;
873 
880  const string& getAttributeUnit(int attributeIndex) const
881  {
882  if (attributeIndex < 0 || attributeIndex >= nAttributes)
883  {
884  ostringstream os;
885  os << endl << "ERROR in GeoTessMetaData::getAttributeUnit(int attributeIndex)" << endl
886  << "attributeIndex (" << attributeIndex << ") is out of range (0-" << nAttributes-1 << ")"
887  << endl;
888  throw GeoTessException(os, __FILE__, __LINE__, 6004);
889  }
890  return attributeUnits[attributeIndex];
891  }
892 
899  string getAttributeString(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 attributeNames[attributeIndex] + " (" + attributeUnits[attributeIndex]+")";
910  }
911 
916  string toString() const;
917 
924  const string& getModelSoftwareVersion() { return modelSoftwareVersion; }
925 
934  const string& getModelGenerationDate()
935  { return modelGenerationDate; }
936 
942  void setModelSoftwareVersion(const string& swVersion)
943  { modelSoftwareVersion = swVersion; }
944 
951  void setModelGenerationDate(const string& genDate)
952  { modelGenerationDate = genDate; }
953 
954  // All methods below this point are public but are not documented in the doxygen documentation.
955  // These are methods that typical applications will never need to call. They have to be
956  // public because other classes in the GeoTess namespace need to access them.
957  //
959 
965  bool applyAttributeFilter() { return boolAttributeFilter; }
966 
975  vector<int>& getAttributeFilter() { return attributeFilter; }
976 
982  void setAttributeFilter(vector<int>& filter) { inputFilter = filter; }
983 
989  void checkComplete();
990 
991  void loadMetaData(IFStreamBinary& input);
992 
993  void loadMetaData(IFStreamAscii& input);
994 
995  int getRefCount() { return refCount; }
996 
1000  void addReference() { ++refCount; }
1001 
1005  void removeReference()
1006  {
1007  if (isNotReferenced())
1008  {
1009  ostringstream os;
1010  os << endl << "ERROR in GeoTessMetaData::removeReference" << endl
1011  << "Reference count (" << refCount << ") is already zero."
1012  << endl;
1013  throw GeoTessException(os, __FILE__, __LINE__, 6005);
1014  }
1015 
1016  --refCount;
1017  }
1018 
1022  bool isNotReferenced() { return (refCount == 0) ? true : false; }
1023 
1027  void setNVertices(const int& nvert) { nVertices = nvert; }
1028 
1034  void setInputModelFile(const string& imf) { inputModelFile = imf; }
1035 
1041  void setInputGridFile(const string& igf) { inputGridFile = igf; }
1042 
1048  void setLoadTimeModel(double ltm) { loadTimeModel = ltm; }
1049 
1055  void setOutputModelFile(const string& omf) { outputModelFile = omf; }
1056 
1062  void setOutputGridFile(const string& ogf) { outputGridFile = ogf; }
1063 
1069  void setWriteTimeModel(double wtm) { writeTimeModel = wtm; }
1070 
1072 
1073 };
1074 // end class GeoTessMetaData
1075 
1076 }// end namespace geotess
1077 
1078 #endif // GEOTESSMETADATA_OBJECT_H