36 #ifndef GEOTESSMODEL_OBJECT_H
37 #define GEOTESSMODEL_OBJECT_H
70 class GeoTessPosition;
72 class GeoTessMetaData;
73 class GeoTessOptimizationType;
136 static map<string, GeoTessGrid*> reuseGridMap;
177 void deleteProfiles();
189 void loadModelAscii(
const string& inputFile,
const string& relGridFilePath);
207 virtual void loadModelAscii(
IFStreamAscii& input,
const string& inputDirectory,
208 const string& relGridFilePath);
223 void loadModelBinary(
const string& inputFile,
const string& relGridFilePath);
240 virtual void loadModelBinary(
IFStreamBinary& input,
const string& inputDirectory,
241 const string& relGridFilePath);
252 void writeModelAscii(
const string& outputFile,
const string& gridFileName);
263 virtual void writeModelAscii(
IFStreamAscii& output,
const string& gridFileName);
274 void writeModelBinary(
const string& outputFile,
const string& gridFileName);
285 virtual void writeModelBinary(
IFStreamBinary& output,
const string& gridFileName);
300 void loadGrid(T& input,
const string& inputDirectory,
301 const string& relGridFilePath,
const string& gridFileName,
302 const string& gridID,
const string& funcName)
307 map<string, GeoTessGrid*>::iterator it = reuseGridMap.find(gridID);
308 if (it != reuseGridMap.end())
311 if (gridFileName ==
"*")
318 &metaData->getOptimizationType());
325 if (metaData->isGridReuseOn())
326 reuseGridMap[gridID] = grid;
336 string gridFil = gridFileName;
337 if (relGridFilePath !=
"")
338 gridFil = CPPUtils::insertPathSeparator(relGridFilePath, gridFileName);
339 if (inputDirectory !=
"")
340 gridFil = CPPUtils::insertPathSeparator(inputDirectory, gridFil);
342 grid =
new GeoTessGrid(&metaData->getOptimizationType());
344 if (metaData->isGridReuseOn())
345 reuseGridMap[gridID] = grid;
349 if (grid->getGridID() != gridID)
352 os << endl <<
"ERROR in GeoTessModel::" + funcName << endl
353 <<
"gridIDs in model file and existingGrid are not equal: "
354 << endl <<
" Model File gridID = " << gridID << endl
355 <<
" Grid File gridID = " << grid->
getGridID() << endl;
362 grid->addReference();
408 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
469 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
470 vector<int>& attributeFilter,
491 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter,
585 GeoTessModel* loadModel(
const string& inputFile,
const string& relGridFilePath =
"");
593 static bool isGeoTessModel(
const string& fileName);
745 int getNRadii(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNRadii(); }
754 int getNData(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNData(); }
770 {
return profiles[vertexId][layerId]->getRadius(nodeId); }
780 double getDepth(
int vertexId,
int layerId,
int nodeId)
781 {
return GeoTessUtils::getEarthRadius(grid->
getVertex(vertexId))
782 - profiles[vertexId][layerId]->getRadius(nodeId); }
796 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
808 float getValueFloat(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
811 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
826 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
838 int getValueInt(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
841 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
853 short getValueShort(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
856 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
871 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
884 void setValue(
int vertexId,
int layerId,
int nodeId,
int attributeIndex, T value)
885 { profiles[vertexId][layerId]->getData(nodeId)->setValue(attributeIndex, value); }
893 {
return getPointMap()->getPointRadius(pointIndex); }
902 {
return getPointMap()->getPointDepth(pointIndex); }
913 GeoTessData* data = getPointMap()->getPointData(pointIndex);
914 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
926 GeoTessData* data = getPointMap()->getPointData(pointIndex);
927 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
939 GeoTessData* data = getPointMap()->getPointData(pointIndex);
940 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
952 GeoTessData* data = getPointMap()->getPointData(pointIndex);
953 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
965 GeoTessData* data = getPointMap()->getPointData(pointIndex);
966 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
978 GeoTessData* data = getPointMap()->getPointData(pointIndex);
979 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
990 void setValue(
int pointIndex,
int attributeIndex, T value)
992 GeoTessData* data = getPointMap()->getPointData(pointIndex);
993 if (data != NULL) data->
setValue(attributeIndex, value);
1011 virtual bool operator == (
const GeoTessModel& other)
const;
1021 virtual bool operator != (
const GeoTessModel& other)
const {
return !(*
this == other); } ;
1025 return getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE
1026 || getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE_EMPTY;
1053 if (!pointMap->isPopulated())
1078 pointMap->setActiveRegion();
1095 pointMap->setActiveRegion(polygon);
1111 if (polygon == NULL)
1112 pointMap->setActiveRegion();
1114 pointMap->setActiveRegion(polygon);
1137 for (
int layer=0; layer<getNLayers(); ++layer)
1138 layerCount[layer] = 0;
1142 for (
int v=0; v<getNVertices(); ++v)
1145 for (
int layer=0; layer<getNLayers(); ++layer)
1150 for (
int n=0; n<p->
getNData(); ++n)
1152 ++layerCount[layer];
1155 layerCount[layer] += pp[layer]->
getNData();
1169 return profiles[vertex][layer];
1180 return profiles[vertex];
1214 template<
typename T>
1215 void setProfile(
int vertex,
int layer, vector<float>& radii, vector<vector<T> >& values)
1217 if (getConnectedVertices(layer).count(vertex) == 1)
1218 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, values));
1237 template<
typename T>
1239 float* radii,
const int& nRadii,
1240 T** values,
const int& nNodes,
const int& nAttributes)
1242 if (getConnectedVertices(layer).count(vertex) == 1)
1243 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, nRadii, values, nNodes, nAttributes));
1267 template<
typename T>
1268 void setProfile(
const int& vertex,
const int& layer,
float* radii,
const int& nRadii)
1279 template<
typename T>
1292 template<
typename T>
1293 void setProfile(
const int& vertex, T* values,
const int& nAttributes)
1327 void writeModel(
const string& outputFile,
const string& gridFileName);
1344 layerCount.resize(metaData->
getNLayers(), 0);
1348 for (
int vtx=0; vtx<getNVertices(); ++vtx)
1351 for (
int layer = 0; layer < metaData->
getNLayers(); ++layer)
1355 for (
int n = 0; n < p->
getNData(); ++n)
1357 ++layerCount[layer];
1360 layerCount[layer] += pp[layer]->
getNData();
1378 vector<int> totalCount;
1379 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1380 totalCount.push_back(0);
1382 for (
int layer = 0; layer < getNLayers(); ++layer)
1384 vector<int> typeCount;
1386 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1387 typeCount.push_back(0);
1389 count.push_back(typeCount);
1392 for (
int layer = 0; layer < getNLayers(); ++layer)
1394 for (
int vertex = 0; vertex < metaData->
getNVertices(); ++vertex)
1396 int pType = profiles[vertex][layer]->getType().ordinal();
1397 count[layer][pType] += 1;
1398 totalCount[pType] += 1;
1402 count.push_back(totalCount);
1438 template<
typename T>
1440 const vector<string>& attributeUnits, T fillValue)
1442 if (profiles == NULL)
1445 os << endl <<
"ERROR in GeoTessModel::initializeData" << endl
1446 <<
"Attempting to initialize the model data before Profiles" << endl
1447 <<
"have been specified (profiles == NULL)" << endl;
1451 const GeoTessDataType& newDataType = GeoTessDataType::getDataType(fillValue);
1452 int nAttributesNew = attributeNames.size();
1454 int newDataTypeOrdinal = newDataType.
ordinal();
1459 if (newDataTypeOrdinal != oldDataTypeOrdinal || nAttributesNew != metaData->
getNAttributes())
1463 T* newValues =
new T[nAttributesNew];
1464 for (
int i=0; i<nAttributesNew; ++i)
1465 newValues[i] = fillValue;
1468 vector<GeoTessData*> data;
1469 for (
int v = 0; v < getNVertices(); ++v)
1470 for (
int lid = 0; lid < getNLayers(); ++lid)
1472 profile = profiles[v][lid];
1475 for (
int n = 0; n < profile->
getNData(); ++n)
1478 data.push_back(GeoTessData::getData(newValues, nAttributesNew));
1503 template<
typename T>
1505 const string& attributeUnits, T fillValue)
1507 vector<string> names;
1508 CPPUtils::tokenizeString(attributeNames,
";", names);
1509 vector<string> units;
1510 CPPUtils::tokenizeString(attributeUnits,
";", units);
1511 initializeData(names, units, fillValue);
1538 void getWeights(
const double* pointA,
const double* pointB,
const double& pointSpacing,
const double& radius,
1564 void getWeights(
GeoTessGreatCircle& greatCircle,
const double& pointSpacing,
const double& radius,
1590 void getWeights(
const vector<double*>& rayPath,
1591 const vector<double>& radii,
1592 const vector<int>& layerIds,
1595 map<int, double>& weights);
1621 void getWeights(
double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1624 map<int, double>& weights);
1638 double getPathIntegral(
const int& attribute,
const map<int, double>& weights);
1676 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
1677 double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1679 map<int, double>* weights = NULL);
1716 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
1717 const vector<double*>& rayPath,
const vector<double>& radii,
const vector<int>& layerIds,
1719 map<int, double>* weights = NULL);
1758 double getPathIntegral2D(
const int& attribute,
const bool& reciprocal,
1759 const double* firstPoint,
const double* lastPoint,
double pointSpacing,
1761 map<int, double>* weights = NULL);
1799 double getPathIntegral2D(
const int& attribute,
const bool& reciprocal,
1802 map<int, double>* weights = NULL);
1809 void getWeights(
const vector<double*>& rayPath,
const vector<double>& radii,
1811 { vector<int> layerIds; getWeights(rayPath, radii, layerIds, ht, rt, weights);}
1813 void getWeights(
double** rayPath,
double* radii,
const int& numPoints,
1814 const GeoTessInterpolatorType& ht,
const GeoTessInterpolatorType& rt,map<int, double>& weights)
1815 { getWeights(rayPath, radii, NULL, numPoints, ht, rt, weights);}
1817 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
double** rayPath,
double* radii,
const int& numPoints,
1818 const GeoTessInterpolatorType& ht,
const GeoTessInterpolatorType& rt)
1819 {
return getPathIntegral(attribute, reciprocal, rayPath, radii, NULL, numPoints, ht, rt); }
1821 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
double** rayPath,
double* radii,
const int& numPoints,
1822 const GeoTessInterpolatorType& ht,
const GeoTessInterpolatorType& rt, map<int, double>& weights)
1823 {
return getPathIntegral(attribute, reciprocal, rayPath, radii, NULL, numPoints, ht, rt, &weights); }
1825 double getPathIntegral2D(
const int& attribute,
const bool& reciprocal,
1826 const double* firstPoint,
const double* lastPoint,
const double& pointSpacing,
1827 const double& earthRadius,
1828 const GeoTessInterpolatorType& horizontalType, map<int, double>& weights)
1829 {
return getPathIntegral2D(attribute, reciprocal, firstPoint, lastPoint, pointSpacing, earthRadius, horizontalType, &weights); }
1835 bool isSupportedFormatVersion(
int frmtVrsn) {
return (frmtVrsn == 1) ?
true :
false; }
1842 bool testLayerRadii();
1852 #endif // GEOTESSMODEL_OBJECT_H
GeoTessGrid * loadGrid(const string &inputFile)
GeoTessGrid & getGrid()
Definition: GeoTessModel.h:674
void setProfile(int vertex, int layer, vector< float > &radii, vector< vector< T > > &values)
Definition: GeoTessModel.h:1215
void setEarthShape(const string &earthShapeName)
Definition: GeoTessModel.h:662
virtual double getDouble(int attributeIndex) const
virtual float getFloat(int attributeIndex) const
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Definition: GeoTessPolygon.h:111
void setValue(int pointIndex, int attributeIndex, T value)
Definition: GeoTessModel.h:990
Relationships between vertices (2D positions in a tessellation), nodes (1D positions along a radial P...
Definition: GeoTessPointMap.h:74
A Profile object that defines a single Data object and no radius value.
Definition: GeoTessProfileSurface.h:76
void getLayerCount(vector< int > &layerCount, const bool &activeOnly)
Definition: GeoTessModel.h:1342
const GeoTessGrid & getGrid() const
Definition: GeoTessModel.h:668
void setActiveRegion()
Definition: GeoTessModel.h:1076
LONG_INT getValueLong(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:937
const double * getVertex(int vertex) const
Definition: GeoTessGrid.h:573
A Profile object that defines a single Data object and no radius value.
Definition: GeoTessProfileSurfaceEmpty.h:77
int getNData(int vertexId, int layerId)
Definition: GeoTessModel.h:754
Information about an interpolated point at an arbitrary position in a model.
Definition: GeoTessPosition.h:101
void setProfile(const int &vertex, vector< T > &values)
Definition: GeoTessModel.h:1280
short getValueShort(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:853
float getValueFloat(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:924
Opens a file for binary read and write access.
Definition: IFStreamBinary.h:79
virtual LONG_INT getLong(int attributeIndex) const
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR, NATURAL_NEIGHBOR and CUBIC_SPLINE.
Definition: GeoTessInterpolatorType.h:71
Manages the geometry and topology of one or more multi-level triangular tessellations of a unit spher...
Definition: GeoTessGrid.h:163
int getValueInt(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:838
static void clearReuseGrid()
Definition: GeoTessModel.h:600
bool is3D()
Definition: GeoTessModel.h:1029
double getValueDouble(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:793
int getNVertices() const
Definition: GeoTessGrid.h:763
static string getGridID(const string &fileName)
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
Definition: GeoTessDataType.h:67
static GeoTessData * getData(const GeoTessDataType &dataType, int nAttributes)
void getLayerCount(bool activeOnly, int *layerCount)
Definition: GeoTessModel.h:1135
virtual GeoTessData ** getData()
void setActiveRegion(const string &polygon)
Definition: GeoTessModel.h:1093
int getNAttributes()
Definition: GeoTessModel.h:760
byte getValueByte(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:868
Manages information about a great circle path that extends from one point to another point...
Definition: GeoTessGreatCircle.h:168
void setProfile(int vertex, int layer, vector< float > &radii)
Definition: GeoTessModel.h:1255
static int getReuseGridMapSize()
Definition: GeoTessModel.h:608
double getDepth(int vertexId, int layerId, int nodeId)
Definition: GeoTessModel.h:780
byte getValueByte(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:976
bool is2D()
Definition: GeoTessModel.h:1023
const set< int > & getConnectedVertices(int layerIndex)
Definition: GeoTessModel.h:1066
int getNRadii(int vertexId, int layerId)
Definition: GeoTessModel.h:745
An exception class for all GeoTess objects.
Definition: GeoTessException.h:65
virtual byte getByte(int attributeIndex) const
Enumeration of the optimization strategies supported by GeoTess including OptimizationType::SPEED and...
Definition: GeoTessOptimizationType.h:66
double getDepth(int pointIndex)
Definition: GeoTessModel.h:901
A Profile object that defines two radii at the bottom and top of the associated layer, and no Data.
Definition: GeoTessProfileEmpty.h:74
LONG_INT getValueLong(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:823
void setGridInputFile(const string &gridFile)
Definition: GeoTessGrid.h:548
#define byte
signed-byte typedef
Definition: CPPGlobals.h:94
Opens ascii file for read and write access.
Definition: IFStreamAscii.h:80
GeoTessProfile ** getProfiles(int vertex)
Definition: GeoTessModel.h:1178
virtual int getInt(int attributeIndex) const
void profileCount(vector< vector< int > > &count)
Definition: GeoTessModel.h:1371
void writeModel(const string &outputFile)
Definition: GeoTessModel.h:1311
virtual void setData(int index, GeoTessData *data)
Definition: EarthShape.h:64
GeoTessMetaData & getMetaData()
Definition: GeoTessModel.h:683
virtual GeoTessData & setValue(int attributeIndex, double v)
void setActiveRegion(GeoTessPolygon *polygon)
Definition: GeoTessModel.h:1109
GeoTessProfile *** getProfiles() const
Definition: GeoTessModel.h:1187
void initializeData(const vector< string > &attributeNames, const vector< string > &attributeUnits, T fillValue)
Definition: GeoTessModel.h:1439
float getValueFloat(int vertexId, int layerId, int nodeId, int attributeIndex)
Definition: GeoTessModel.h:808
GeoTessProfile * getProfile(int vertex, int layer)
Definition: GeoTessModel.h:1167
GeoTessPointMap * getPointMap()
Definition: GeoTessModel.h:1051
void setProfile(const int &vertex, const int &layer, float *radii, const int &nRadii)
Definition: GeoTessModel.h:1268
double getValueDouble(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:911
EarthShape & getEarthShape()
Definition: GeoTessModel.h:635
#define LONG_INT
Definition: CPPGlobals.h:111
GeoTessPolygon * getPolygon()
Definition: GeoTessModel.h:1125
Abstract class that manages the radii and data values that span a single layer associated with a sing...
Definition: GeoTessProfile.h:96
Abstract base class that manages the data values attached to a single grid point. ...
Definition: GeoTessData.h:75
int getValueInt(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:950
virtual int getPointIndex(int nodeIndex) const
Top level class that manages the GeoTessMetaData, GeoTessGrid and Data that comprise a 3D Earth model...
Definition: GeoTessModel.h:119
short getValueShort(int pointIndex, int attributeIndex)
Definition: GeoTessModel.h:963
virtual void getValues(double values[], const int &n)
void initializeData(const string &attributeNames, const string &attributeUnits, T fillValue)
Definition: GeoTessModel.h:1504
double getRadius(int pointIndex)
Definition: GeoTessModel.h:892
void setProfile(const int &vertex)
Definition: GeoTessModel.h:1301
void setValue(int vertexId, int layerId, int nodeId, int attributeIndex, T value)
Definition: GeoTessModel.h:884
const set< int > & getVertexIndicesTopLevel(const int &tessId)
Definition: GeoTessGrid.h:756
static string class_name()
Definition: GeoTessModel.h:572
int getNVertices() const
Definition: GeoTessModel.h:730
double getRadius(int vertexId, int layerId, int nodeId)
Definition: GeoTessModel.h:769
int ordinal() const
Definition: GeoTessEnumType.h:148
void setProfile(const int &vertex, const int &layer, float *radii, const int &nRadii, T **values, const int &nNodes, const int &nAttributes)
Definition: GeoTessModel.h:1238
int getNPoints()
Definition: GeoTessModel.h:1001
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:71
int getNLayers() const
Definition: GeoTessModel.h:736
virtual short getShort(int attributeIndex) const
void setProfile(const int &vertex, T *values, const int &nAttributes)
Definition: GeoTessModel.h:1293
virtual int getNData() const