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(); }
769 double getRadius(
int vertexId,
int layerId,
int nodeId)
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); }
793 double getValueDouble(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
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);
823 LONG_INT getValueLong(
int vertexId,
int layerId,
int nodeId,
int 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);
868 byte getValueByte(
int vertexId,
int layerId,
int nodeId,
int 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); }
892 double getRadius(
int pointIndex)
893 {
return getPointMap()->getPointRadius(pointIndex); }
901 double getDepth(
int pointIndex)
902 {
return getPointMap()->getPointDepth(pointIndex); }
911 double getValueDouble(
int pointIndex,
int attributeIndex)
913 GeoTessData* data = getPointMap()->getPointData(pointIndex);
914 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
924 float getValueFloat(
int pointIndex,
int attributeIndex)
926 GeoTessData* data = getPointMap()->getPointData(pointIndex);
927 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
937 LONG_INT getValueLong(
int pointIndex,
int attributeIndex)
939 GeoTessData* data = getPointMap()->getPointData(pointIndex);
940 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
950 int getValueInt(
int pointIndex,
int attributeIndex)
952 GeoTessData* data = getPointMap()->getPointData(pointIndex);
953 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
963 short getValueShort(
int pointIndex,
int attributeIndex)
965 GeoTessData* data = getPointMap()->getPointData(pointIndex);
966 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
976 byte getValueByte(
int pointIndex,
int 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())
1066 const set<int>& getConnectedVertices(
int layerIndex)
1076 void setActiveRegion()
1078 pointMap->setActiveRegion();
1093 void setActiveRegion(
const string& polygon)
1095 pointMap->setActiveRegion(polygon);
1111 if (polygon == NULL)
1112 pointMap->setActiveRegion();
1114 pointMap->setActiveRegion(polygon);
1135 void getLayerCount(
bool activeOnly,
int* layerCount)
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>
1238 void setProfile(
const int& vertex,
const int& layer,
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));
1255 void setProfile(
int vertex,
int layer, vector<float>& radii)
1267 template<
typename T>
1268 void setProfile(
const int& vertex,
const int& layer,
float* radii,
const int& nRadii)
1279 template<
typename T>
1280 void setProfile(
const int& vertex, vector<T>& values)
1292 template<
typename T>
1293 void setProfile(
const int& vertex, T* values,
const int& nAttributes)
1301 void setProfile(
const int& vertex)
1327 void writeModel(
const string& outputFile,
const string& gridFileName);
1342 void getLayerCount(vector<int>& layerCount,
const bool& activeOnly)
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();
1371 void profileCount(vector< vector<int> >& count)
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>
1439 void initializeData(
const vector<string>& attributeNames,
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>
1504 void initializeData(
const string& attributeNames,
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