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();
182 void loadModelAscii(
const string& inputFile,
const string& relGridFilePath);
193 virtual void loadModelAscii(
IFStreamAscii& input,
const string& inputDirectory,
194 const string& relGridFilePath);
203 void loadModelBinary(
const string& inputFile,
const string& relGridFilePath);
213 virtual void loadModelBinary(
IFStreamBinary& input,
const string& inputDirectory,
214 const string& relGridFilePath);
225 void writeModelAscii(
const string& outputFile,
const string& gridFileName);
236 virtual void writeModelAscii(
IFStreamAscii& output,
const string& gridFileName);
247 void writeModelBinary(
const string& outputFile,
const string& gridFileName);
258 virtual void writeModelBinary(
IFStreamBinary& output,
const string& gridFileName);
273 void loadGrid(T& input,
const string& inputDirectory,
274 const string& relGridFilePath,
const string& gridFileName,
275 const string& gridID,
const string& funcName)
280 map<string, GeoTessGrid*>::iterator it = reuseGridMap.find(gridID);
281 if (it != reuseGridMap.end())
284 if (gridFileName ==
"*")
298 reuseGridMap[gridID] = grid;
308 string gridFil = gridFileName;
309 if (relGridFilePath !=
"")
310 gridFil = CPPUtils::insertPathSeparator(relGridFilePath, gridFileName);
311 if (inputDirectory !=
"")
312 gridFil = CPPUtils::insertPathSeparator(inputDirectory, gridFil);
317 reuseGridMap[gridID] = grid;
324 os << endl <<
"ERROR in GeoTessModel::" + funcName << endl
325 <<
"gridIDs in model file and existingGrid are not equal: "
326 << endl <<
" Model File gridID = " << gridID << endl
327 <<
" Grid File gridID = " << grid->
getGridID() << endl;
334 grid->addReference();
420 vector<int>& attributeFilter);
436 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter);
544 static string getClassName(
const string& fileName,
const string& relGridFilePath =
".");
567 for (
int i=0; i<getNVertices(); ++i)
568 for (
int j=0; j<getNLayers(); ++j)
586 LONG_INT memory =
sizeof(map<string, GeoTessGrid*>);
590 for (map<string, GeoTessGrid*>::iterator it = reuseGridMap.begin(); it != reuseGridMap.end(); it++)
591 memory += (
LONG_INT)it->first.length() + it->second->getMemory();
759 int getNData(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->
getNData(); }
775 {
return profiles[vertexId][layerId]->
getRadius(nodeId); }
785 double getDepth(
int vertexId,
int layerId,
int nodeId)
786 {
return getEarthShape().getEarthRadius(grid->
getVertex(vertexId))
787 - profiles[vertexId][layerId]->
getRadius(nodeId); }
801 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
813 float getValueFloat(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
816 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
831 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
843 int getValueInt(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
846 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
858 short getValueShort(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
861 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
873 byte getValueByte(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
876 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
889 void setValue(
int vertexId,
int layerId,
int nodeId,
int attributeIndex, T value)
890 { profiles[vertexId][layerId]->
getData(nodeId)->
setValue(attributeIndex, value); }
898 {
return getPointMap()->getPointRadius(pointIndex); }
907 {
return getPointMap()->getPointDepth(pointIndex); }
918 GeoTessData* data = getPointMap()->getPointData(pointIndex);
919 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
931 GeoTessData* data = getPointMap()->getPointData(pointIndex);
932 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
944 GeoTessData* data = getPointMap()->getPointData(pointIndex);
945 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
957 GeoTessData* data = getPointMap()->getPointData(pointIndex);
958 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
970 GeoTessData* data = getPointMap()->getPointData(pointIndex);
971 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
983 GeoTessData* data = getPointMap()->getPointData(pointIndex);
984 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
995 void setValue(
int pointIndex,
int attributeIndex, T value)
997 GeoTessData* data = getPointMap()->getPointData(pointIndex);
998 if (data != NULL) data->
setValue(attributeIndex, value);
1026 virtual bool operator != (
const GeoTessModel& other)
const {
return !(*
this == other); } ;
1030 return getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE
1031 || getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE_EMPTY;
1116 if (polygon == NULL)
1142 for (
int layer=0; layer<getNLayers(); ++layer)
1143 layerCount[layer] = 0;
1147 for (
int v=0; v<getNVertices(); ++v)
1150 for (
int layer=0; layer<getNLayers(); ++layer)
1155 for (
int n=0; n<p->
getNData(); ++n)
1157 ++layerCount[layer];
1160 layerCount[layer] += pp[layer]->
getNData();
1174 return profiles[vertex][layer];
1185 return profiles[vertex];
1219 template<
typename T>
1220 void setProfile(
int vertex,
int layer, vector<float>& radii, vector<vector<T> >& values)
1222 if (getConnectedVertices(layer).count(vertex) == 1)
1223 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, values));
1242 template<
typename T>
1244 float* radii,
const int& nRadii,
1245 T** values,
const int& nNodes,
const int& nAttributes)
1247 if (getConnectedVertices(layer).count(vertex) == 1)
1248 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, nRadii, values, nNodes, nAttributes));
1272 template<
typename T>
1273 void setProfile(
const int& vertex,
const int& layer,
float* radii,
const int& nRadii)
1284 template<
typename T>
1297 template<
typename T>
1298 void setProfile(
const int& vertex, T* values,
const int& nAttributes)
1323 void writeModel(
const string& outputFile,
const string& gridFileName =
"*");
1340 layerCount.resize(metaData->
getNLayers(), 0);
1344 for (
int vtx=0; vtx<getNVertices(); ++vtx)
1347 for (
int layer = 0; layer < metaData->
getNLayers(); ++layer)
1351 for (
int n = 0; n < p->
getNData(); ++n)
1353 ++layerCount[layer];
1356 layerCount[layer] += pp[layer]->
getNData();
1374 vector<int> totalCount;
1375 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1376 totalCount.push_back(0);
1378 for (
int layer = 0; layer < getNLayers(); ++layer)
1380 vector<int> typeCount;
1382 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1383 typeCount.push_back(0);
1385 count.push_back(typeCount);
1388 for (
int layer = 0; layer < getNLayers(); ++layer)
1390 for (
int vertex = 0; vertex < metaData->
getNVertices(); ++vertex)
1393 count[layer][pType] += 1;
1394 totalCount[pType] += 1;
1398 count.push_back(totalCount);
1434 template<
typename T>
1436 const vector<string>& attributeUnits, T fillValue)
1438 if (profiles == NULL)
1441 os << endl <<
"ERROR in GeoTessModel::initializeData" << endl
1442 <<
"Attempting to initialize the model data before Profiles" << endl
1443 <<
"have been specified (profiles == NULL)" << endl;
1447 const GeoTessDataType& newDataType = GeoTessDataType::getDataType(fillValue);
1448 int nAttributesNew = attributeNames.size();
1450 int newDataTypeOrdinal = newDataType.
ordinal();
1455 if (newDataTypeOrdinal != oldDataTypeOrdinal || nAttributesNew != metaData->
getNAttributes())
1459 T* newValues =
new T[nAttributesNew];
1460 for (
int i=0; i<nAttributesNew; ++i)
1461 newValues[i] = fillValue;
1464 vector<GeoTessData*> data;
1465 for (
int v = 0; v < getNVertices(); ++v)
1466 for (
int lid = 0; lid < getNLayers(); ++lid)
1468 profile = profiles[v][lid];
1471 for (
int n = 0; n < profile->
getNData(); ++n)
1474 data.push_back(GeoTessData::getData(newValues, nAttributesNew));
1499 template<
typename T>
1501 const string& attributeUnits, T fillValue)
1503 vector<string> names;
1504 CPPUtils::tokenizeString(attributeNames,
";", names);
1505 vector<string> units;
1506 CPPUtils::tokenizeString(attributeUnits,
";", units);
1507 initializeData(names, units, fillValue);
1534 void getWeights(
const double* pointA,
const double* pointB,
const double& pointSpacing,
const double& radius,
1587 const vector<double>& radii,
1588 const vector<int>& layerIds,
1591 map<int, double>& weights);
1617 void getWeights(
double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1620 map<int, double>& weights);
1670 double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1672 map<int, double>* weights = NULL);
1707 const vector<double*>& rayPath,
const vector<double>& radii,
const vector<int>& layerIds,
1709 map<int, double>* weights = NULL);
1747 const double* firstPoint,
const double* lastPoint,
double pointSpacing,
1749 map<int, double>* weights = NULL);
1788 map<int, double>* weights = NULL);
1798 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
1800 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter,
1834 bool testLayerRadii();
Defines the ellipsoid that is to be used to convert between geocentric and geographic latitude and be...
Abstract base class that manages the data values attached to a single grid point.
virtual GeoTessData & setValue(int attributeIndex, double v)
virtual byte getByte(int attributeIndex) const
virtual float getFloat(int attributeIndex) const
virtual double getDouble(int attributeIndex) const
virtual LONG_INT getLong(int attributeIndex) const
virtual int getInt(int attributeIndex) const
virtual void getValues(double values[], const int &n)
virtual short getShort(int attributeIndex) const
Enumeration of supported DataType including DOUBLE, FLOAT, LONG, INT, SHORT and BYTE.
An exception class for all GeoTess objects.
Manages information about a great circle path that extends from one point to another point,...
Manages the geometry and topology of one or more multi-level triangular tessellations of a unit spher...
const double * getVertex(int vertex) const
GeoTessGrid * loadGrid(const string &inputFile)
const set< int > & getVertexIndicesTopLevel(const int &tessId)
void setGridInputFile(const string &gridFile)
static string getGridID(const string &fileName)
Enumeration of the interpolation algorithms supported by GeoTess including LINEAR,...
Top level class that manages the GeoTessMetaData, GeoTessGrid and GeoTessData that comprise a 3D Eart...
void setProfile(int vertex, int layer, GeoTessProfile *profile)
GeoTessModel(const string &inputFile, const string &relativeGridPath)
GeoTessProfile *** getProfiles() const
int getNData(int vertexId, int layerId)
int getValueInt(int vertexId, int layerId, int nodeId, int attributeIndex)
void profileCount(vector< vector< int > > &count)
void setActiveRegion(const string &polygon)
void setEarthShape(const string &earthShapeName)
void setProfile(const int &vertex, const int &layer, float *radii, const int &nRadii, T **values, const int &nNodes, const int &nAttributes)
void getWeights(const double *pointA, const double *pointB, const double &pointSpacing, const double &radius, const GeoTessInterpolatorType &horizontalType, map< int, double > &weights)
static string getClassName(const string &fileName, const string &relGridFilePath=".")
short getValueShort(int pointIndex, int attributeIndex)
short getValueShort(int vertexId, int layerId, int nodeId, int attributeIndex)
void getLayerCount(bool activeOnly, int *layerCount)
GeoTessModel(GeoTessGrid *grid, GeoTessMetaData *metaData)
void setValue(int vertexId, int layerId, int nodeId, int attributeIndex, T value)
GeoTessPosition * getPosition(const GeoTessInterpolatorType &horizontalType, const GeoTessInterpolatorType &radialType)
void getWeights(const vector< double * > &rayPath, const vector< double > &radii, const vector< int > &layerIds, const GeoTessInterpolatorType &horizontalType, const GeoTessInterpolatorType &radialType, map< int, double > &weights)
const set< int > & getConnectedVertices(int layerIndex)
void initializeData(const vector< string > &attributeNames, const vector< string > &attributeUnits, T fillValue)
GeoTessModel(const string &inputFile, const string &relativeGridPath, vector< int > &attributeFilter)
virtual LONG_INT getMemory()
void setActiveRegion(GeoTessPolygon *polygon)
void writeModel(const string &outputFile, const string &gridFileName="*")
void setProfile(const int &vertex)
float getValueFloat(int vertexId, int layerId, int nodeId, int attributeIndex)
double getPathIntegral(const int &attribute, const map< int, double > &weights)
GeoTessPosition * getPosition()
GeoTessModel(const string &modelInputFile)
double getRadius(int vertexId, int layerId, int nodeId)
void setProfile(const int &vertex, vector< T > &values)
int getNRadii(int vertexId, int layerId)
byte getValueByte(int vertexId, int layerId, int nodeId, int attributeIndex)
GeoTessMetaData & getMetaData()
GeoTessPosition * getPosition(const GeoTessInterpolatorType &horizontalType)
GeoTessModel(const string &gridFileName, GeoTessMetaData *metaData)
double getDepth(int pointIndex)
GeoTessModel * loadModel(const string &inputFile, const string &relGridFilePath="")
double getPathIntegral2D(const int &attribute, GeoTessGreatCircle &greatCircle, double pointSpacing, double earthRadius, const GeoTessInterpolatorType &horizontalType, map< int, double > *weights=NULL)
void setProfile(const int &vertex, const int &layer, float *radii, const int &nRadii)
EarthShape & getEarthShape()
static LONG_INT getReuseGridMapMemory()
GeoTessPolygon * getPolygon()
void setProfile(int vertex, int layer, vector< float > &radii, vector< vector< T > > &values)
virtual string class_name()
static void clearReuseGrid()
double getPathIntegral2D(const int &attribute, const double *firstPoint, const double *lastPoint, double pointSpacing, double earthRadius, const GeoTessInterpolatorType &horizontalType, map< int, double > *weights=NULL)
float getValueFloat(int pointIndex, int attributeIndex)
GeoTessProfile * getProfile(int vertex, int layer)
double getRadius(int pointIndex)
void getWeights(double **rayPath, double *radii, int *layerIds, const int &numPoints, const GeoTessInterpolatorType &horizontalType, const GeoTessInterpolatorType &radialType, map< int, double > &weights)
static int getReuseGridMapSize()
LONG_INT getValueLong(int pointIndex, int attributeIndex)
void setValue(int pointIndex, int attributeIndex, T value)
double getDepth(int vertexId, int layerId, int nodeId)
static bool isGeoTessModel(const string &fileName)
byte getValueByte(int pointIndex, int attributeIndex)
void getLayerCount(vector< int > &layerCount, const bool &activeOnly)
double getPathIntegral(const int &attribute, double **rayPath, double *radii, int *layerIds, const int &numPoints, const GeoTessInterpolatorType &horizontalType, const GeoTessInterpolatorType &radialType, map< int, double > *weights=NULL)
int getValueInt(int pointIndex, int attributeIndex)
GeoTessPointMap * getPointMap()
GeoTessModel(vector< int > &attributeFilter)
GeoTessProfile ** getProfiles(int vertex)
LONG_INT getValueLong(int vertexId, int layerId, int nodeId, int attributeIndex)
double getValueDouble(int vertexId, int layerId, int nodeId, int attributeIndex)
const GeoTessGrid & getGrid() const
void getWeights(GeoTessGreatCircle &greatCircle, const double &pointSpacing, const double &radius, const GeoTessInterpolatorType &horizontalType, map< int, double > &weights)
void initializeData(const string &attributeNames, const string &attributeUnits, T fillValue)
double getPathIntegral(const int &attribute, const vector< double * > &rayPath, const vector< double > &radii, const vector< int > &layerIds, const GeoTessInterpolatorType &horizontalType, const GeoTessInterpolatorType &radialType, map< int, double > *weights=NULL)
void setProfile(int vertex, int layer, vector< float > &radii)
GeoTessModel(const string &modelInputFile, vector< int > &attributeFilter)
void setProfile(const int &vertex, T *values, const int &nAttributes)
double getValueDouble(int pointIndex, int attributeIndex)
Enumeration of the optimization strategies supported by GeoTess including OptimizationType::SPEED and...
Relationships between vertices (2D positions in a tessellation), nodes (1D positions along a radial P...
GeoTessPolygon * getPolygon()
An ordered list of points on the surface of a unit sphere that define a closed polygon.
Information about an interpolated point at an arbitrary position in a model.
A Profile object that defines two radii at the bottom and top of the associated layer,...
Abstract class that manages the radii and data values that span a single layer associated with a sing...
virtual int getNRadii() const
virtual const GeoTessProfileType & getType() const
virtual LONG_INT getMemory()
virtual float getRadius(int i) const
virtual int getNData() const
virtual void setData(int index, GeoTessData *data)
virtual GeoTessData ** getData()
virtual int getPointIndex(int nodeIndex) const
A Profile object that defines a single Data object and no radius value.
A Profile object that defines a single Data object and no radius value.
Opens ascii file for read and write access.
Opens a file for binary read and write access.