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 ==
"*")
324 if (metaData->isGridReuseOn())
325 reuseGridMap[gridID] = grid;
335 string gridFil = gridFileName;
336 if (relGridFilePath !=
"")
337 gridFil = CPPUtils::insertPathSeparator(relGridFilePath, gridFileName);
338 if (inputDirectory !=
"")
339 gridFil = CPPUtils::insertPathSeparator(inputDirectory, gridFil);
342 grid->loadGrid(gridFil);
343 if (metaData->isGridReuseOn())
344 reuseGridMap[gridID] = grid;
348 if (grid->getGridID() != gridID)
351 os << endl <<
"ERROR in GeoTessModel::" + funcName << endl
352 <<
"gridIDs in model file and existingGrid are not equal: "
353 << endl <<
" Model File gridID = " << gridID << endl
354 <<
" Grid File gridID = " << grid->getGridID() << endl;
361 grid->addReference();
399 GeoTessModel(
const string& inputFile,
const string& relativeGridPath);
446 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
447 vector<int>& attributeFilter);
463 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter);
554 GeoTessModel* loadModel(
const string& inputFile,
const string& relGridFilePath =
"");
562 static bool isGeoTessModel(
const string& fileName);
585 for (
int i=0; i<getNVertices(); ++i)
586 for (
int j=0; j<getNLayers(); ++j)
588 memory += profiles[i][j]->getMemory();
590 memory += pointMap->getMemory();
604 LONG_INT memory =
sizeof(map<string, GeoTessGrid*>);
608 for (map<string, GeoTessGrid*>::iterator it = reuseGridMap.begin(); it != reuseGridMap.end(); it++)
609 memory += (
LONG_INT)it->first.length() + it->second->getMemory();
768 int getNRadii(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNRadii(); }
777 int getNData(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNData(); }
792 double getRadius(
int vertexId,
int layerId,
int nodeId)
793 {
return profiles[vertexId][layerId]->getRadius(nodeId); }
803 double getDepth(
int vertexId,
int layerId,
int nodeId)
804 {
return getEarthShape().getEarthRadius(grid->
getVertex(vertexId))
805 - profiles[vertexId][layerId]->getRadius(nodeId); }
816 double getValueDouble(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
819 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
831 float getValueFloat(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
834 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
846 LONG_INT getValueLong(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
849 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
861 int getValueInt(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
864 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
876 short getValueShort(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
879 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
891 byte getValueByte(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
894 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
907 void setValue(
int vertexId,
int layerId,
int nodeId,
int attributeIndex, T value)
908 { profiles[vertexId][layerId]->getData(nodeId)->setValue(attributeIndex, value); }
915 double getRadius(
int pointIndex)
916 {
return getPointMap()->getPointRadius(pointIndex); }
924 double getDepth(
int pointIndex)
925 {
return getPointMap()->getPointDepth(pointIndex); }
934 double getValueDouble(
int pointIndex,
int attributeIndex)
936 GeoTessData* data = getPointMap()->getPointData(pointIndex);
937 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
947 float getValueFloat(
int pointIndex,
int attributeIndex)
949 GeoTessData* data = getPointMap()->getPointData(pointIndex);
950 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
960 LONG_INT getValueLong(
int pointIndex,
int attributeIndex)
962 GeoTessData* data = getPointMap()->getPointData(pointIndex);
963 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
973 int getValueInt(
int pointIndex,
int attributeIndex)
975 GeoTessData* data = getPointMap()->getPointData(pointIndex);
976 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
986 short getValueShort(
int pointIndex,
int attributeIndex)
988 GeoTessData* data = getPointMap()->getPointData(pointIndex);
989 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
999 byte getValueByte(
int pointIndex,
int attributeIndex)
1001 GeoTessData* data = getPointMap()->getPointData(pointIndex);
1002 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
1012 template<
typename T>
1013 void setValue(
int pointIndex,
int attributeIndex, T value)
1015 GeoTessData* data = getPointMap()->getPointData(pointIndex);
1016 if (data != NULL) data->
setValue(attributeIndex, value);
1034 virtual bool operator == (
const GeoTessModel& other)
const;
1044 virtual bool operator != (
const GeoTessModel& other)
const {
return !(*
this == other); } ;
1048 return getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE
1049 || getProfile(0, 0)->getType() == GeoTessProfileType::SURFACE_EMPTY;
1076 if (!pointMap->isPopulated())
1089 const set<int>& getConnectedVertices(
int layerIndex)
1099 void setActiveRegion()
1101 pointMap->setActiveRegion();
1116 void setActiveRegion(
const string& polygon)
1118 pointMap->setActiveRegion(polygon);
1134 if (polygon == NULL)
1135 pointMap->setActiveRegion();
1137 pointMap->setActiveRegion(polygon);
1158 void getLayerCount(
bool activeOnly,
int* layerCount)
1160 for (
int layer=0; layer<getNLayers(); ++layer)
1161 layerCount[layer] = 0;
1165 for (
int v=0; v<getNVertices(); ++v)
1168 for (
int layer=0; layer<getNLayers(); ++layer)
1173 for (
int n=0; n<p->
getNData(); ++n)
1175 ++layerCount[layer];
1178 layerCount[layer] += pp[layer]->
getNData();
1192 return profiles[vertex][layer];
1203 return profiles[vertex];
1237 template<
typename T>
1238 void setProfile(
int vertex,
int layer, vector<float>& radii, vector<vector<T> >& values)
1240 if (getConnectedVertices(layer).count(vertex) == 1)
1241 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, values));
1260 template<
typename T>
1261 void setProfile(
const int& vertex,
const int& layer,
1262 float* radii,
const int& nRadii,
1263 T** values,
const int& nNodes,
const int& nAttributes)
1265 if (getConnectedVertices(layer).count(vertex) == 1)
1266 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, nRadii, values, nNodes, nAttributes));
1278 void setProfile(
int vertex,
int layer, vector<float>& radii)
1290 template<
typename T>
1291 void setProfile(
const int& vertex,
const int& layer,
float* radii,
const int& nRadii)
1302 template<
typename T>
1303 void setProfile(
const int& vertex, vector<T>& values)
1315 template<
typename T>
1316 void setProfile(
const int& vertex, T* values,
const int& nAttributes)
1324 void setProfile(
const int& vertex)
1350 void writeModel(
const string& outputFile,
const string& gridFileName);
1365 void getLayerCount(vector<int>& layerCount,
const bool& activeOnly)
1367 layerCount.resize(metaData->
getNLayers(), 0);
1371 for (
int vtx=0; vtx<getNVertices(); ++vtx)
1374 for (
int layer = 0; layer < metaData->
getNLayers(); ++layer)
1378 for (
int n = 0; n < p->
getNData(); ++n)
1380 ++layerCount[layer];
1383 layerCount[layer] += pp[layer]->
getNData();
1394 void profileCount(vector< vector<int> >& count)
1401 vector<int> totalCount;
1402 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1403 totalCount.push_back(0);
1405 for (
int layer = 0; layer < getNLayers(); ++layer)
1407 vector<int> typeCount;
1409 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1410 typeCount.push_back(0);
1412 count.push_back(typeCount);
1415 for (
int layer = 0; layer < getNLayers(); ++layer)
1417 for (
int vertex = 0; vertex < metaData->
getNVertices(); ++vertex)
1419 int pType = profiles[vertex][layer]->getType().ordinal();
1420 count[layer][pType] += 1;
1421 totalCount[pType] += 1;
1425 count.push_back(totalCount);
1461 template<
typename T>
1462 void initializeData(
const vector<string>& attributeNames,
1463 const vector<string>& attributeUnits, T fillValue)
1465 if (profiles == NULL)
1468 os << endl <<
"ERROR in GeoTessModel::initializeData" << endl
1469 <<
"Attempting to initialize the model data before Profiles" << endl
1470 <<
"have been specified (profiles == NULL)" << endl;
1474 const GeoTessDataType& newDataType = GeoTessDataType::getDataType(fillValue);
1475 int nAttributesNew = attributeNames.size();
1477 int newDataTypeOrdinal = newDataType.
ordinal();
1482 if (newDataTypeOrdinal != oldDataTypeOrdinal || nAttributesNew != metaData->
getNAttributes())
1486 T* newValues =
new T[nAttributesNew];
1487 for (
int i=0; i<nAttributesNew; ++i)
1488 newValues[i] = fillValue;
1491 vector<GeoTessData*> data;
1492 for (
int v = 0; v < getNVertices(); ++v)
1493 for (
int lid = 0; lid < getNLayers(); ++lid)
1495 profile = profiles[v][lid];
1498 for (
int n = 0; n < profile->
getNData(); ++n)
1501 data.push_back(GeoTessData::getData(newValues, nAttributesNew));
1526 template<
typename T>
1527 void initializeData(
const string& attributeNames,
1528 const string& attributeUnits, T fillValue)
1530 vector<string> names;
1531 CPPUtils::tokenizeString(attributeNames,
";", names);
1532 vector<string> units;
1533 CPPUtils::tokenizeString(attributeUnits,
";", units);
1534 initializeData(names, units, fillValue);
1561 void getWeights(
const double* pointA,
const double* pointB,
const double& pointSpacing,
const double& radius,
1587 void getWeights(
GeoTessGreatCircle& greatCircle,
const double& pointSpacing,
const double& radius,
1613 void getWeights(
const vector<double*>& rayPath,
1614 const vector<double>& radii,
1615 const vector<int>& layerIds,
1618 map<int, double>& weights);
1644 void getWeights(
double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1647 map<int, double>& weights);
1661 double getPathIntegral(
const int& attribute,
const map<int, double>& weights);
1696 double getPathIntegral(
const int& attribute,
1697 double** rayPath,
double* radii,
int* layerIds,
const int& numPoints,
1699 map<int, double>* weights = NULL);
1733 double getPathIntegral(
const int& attribute,
1734 const vector<double*>& rayPath,
const vector<double>& radii,
const vector<int>& layerIds,
1736 map<int, double>* weights = NULL);
1773 double getPathIntegral2D(
const int& attribute,
1774 const double* firstPoint,
const double* lastPoint,
double pointSpacing,
1776 map<int, double>* weights = NULL);
1812 double getPathIntegral2D(
const int& attribute,
1815 map<int, double>* weights = NULL);
1825 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
1827 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter,
1859 bool isSupportedFormatVersion(
int frmtVrsn) {
return (frmtVrsn == 1) ?
true :
false; }
1866 bool testLayerRadii();
1876 #endif // GEOTESSMODEL_OBJECT_H