36 #ifndef GEOTESSMODEL_OBJECT_H
37 #define GEOTESSMODEL_OBJECT_H
68 class GeoTessPosition;
70 class GeoTessMetaData;
71 class GeoTessOptimizationType;
134 static map<string, GeoTessGrid*> reuseGridMap;
175 void deleteProfiles();
187 void loadModelAscii(
const string& inputFile,
const string& relGridFilePath);
205 virtual void loadModelAscii(
IFStreamAscii& input,
const string& inputDirectory,
206 const string& relGridFilePath);
221 void loadModelBinary(
const string& inputFile,
const string& relGridFilePath);
238 virtual void loadModelBinary(
IFStreamBinary& input,
const string& inputDirectory,
239 const string& relGridFilePath);
250 void writeModelAscii(
const string& outputFile,
const string& gridFileName);
261 virtual void writeModelAscii(
IFStreamAscii& output,
const string& gridFileName);
272 void writeModelBinary(
const string& outputFile,
const string& gridFileName);
283 virtual void writeModelBinary(
IFStreamBinary& output,
const string& gridFileName);
298 void loadGrid(T& input,
const string& inputDirectory,
299 const string& relGridFilePath,
const string& gridFileName,
300 const string& gridID,
const string& funcName)
305 map<string, GeoTessGrid*>::iterator it = reuseGridMap.find(gridID);
306 if (it != reuseGridMap.end())
309 if (gridFileName ==
"*")
316 &metaData->getOptimizationType());
323 if (metaData->isGridReuseOn())
324 reuseGridMap[gridID] = grid;
334 string gridFil = gridFileName;
335 if (relGridFilePath !=
"")
336 gridFil = CPPUtils::insertPathSeparator(relGridFilePath, gridFileName);
337 if (inputDirectory !=
"")
338 gridFil = CPPUtils::insertPathSeparator(inputDirectory, gridFil);
340 grid =
new GeoTessGrid(&metaData->getOptimizationType());
342 if (metaData->isGridReuseOn())
343 reuseGridMap[gridID] = grid;
347 if (grid->getGridID() != gridID)
350 os << endl <<
"ERROR in GeoTessModel::" + funcName << endl
351 <<
"gridIDs in model file and existingGrid are not equal: "
352 << endl <<
" Model File gridID = " << gridID << endl
353 <<
" Grid File gridID = " << grid->
getGridID() << endl;
360 grid->addReference();
406 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
467 GeoTessModel(
const string& inputFile,
const string& relativeGridPath,
468 vector<int>& attributeFilter,
489 GeoTessModel(
const string& modelInputFile, vector<int>& attributeFilter,
583 GeoTessModel* loadModel(
const string& inputFile,
const string& relGridFilePath =
"");
591 static bool isGeoTessModel(
const string& fileName);
598 static void clearReuseGrid()
600 reuseGridMap.clear();
609 static int getReuseGridMapSize()
611 return reuseGridMap.size();
704 int getNRadii(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNRadii(); }
713 int getNData(
int vertexId,
int layerId) {
return profiles[vertexId][layerId]->getNData(); }
728 double getRadius(
int vertexId,
int layerId,
int nodeId)
729 {
return profiles[vertexId][layerId]->getRadius(nodeId); }
739 double getDepth(
int vertexId,
int layerId,
int nodeId)
740 {
return GeoTessUtils::getEarthRadius(grid->
getVertex(vertexId))
741 - profiles[vertexId][layerId]->getRadius(nodeId); }
752 double getValueDouble(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
755 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
767 float getValueFloat(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
770 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
782 LONG_INT getValueLong(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
785 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
797 int getValueInt(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
800 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
812 short getValueShort(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
815 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
827 byte getValueByte(
int vertexId,
int layerId,
int nodeId,
int attributeIndex)
830 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
843 void setValue(
int vertexId,
int layerId,
int nodeId,
int attributeIndex, T value)
844 { profiles[vertexId][layerId]->getData(nodeId)->setValue(attributeIndex, value); }
851 double getRadius(
int pointIndex)
852 {
return getPointMap()->getPointRadius(pointIndex); }
860 double getDepth(
int pointIndex)
861 {
return getPointMap()->getPointDepth(pointIndex); }
870 double getValueDouble(
int pointIndex,
int attributeIndex)
872 GeoTessData* data = getPointMap()->getPointData(pointIndex);
873 return data == NULL ? NaN_DOUBLE : data->
getDouble(attributeIndex);
883 float getValueFloat(
int pointIndex,
int attributeIndex)
885 GeoTessData* data = getPointMap()->getPointData(pointIndex);
886 return data == NULL ? NaN_FLOAT : data->
getFloat(attributeIndex);
896 LONG_INT getValueLong(
int pointIndex,
int attributeIndex)
898 GeoTessData* data = getPointMap()->getPointData(pointIndex);
899 return data == NULL ? LONG_MIN : data->
getLong(attributeIndex);
909 int getValueInt(
int pointIndex,
int attributeIndex)
911 GeoTessData* data = getPointMap()->getPointData(pointIndex);
912 return data == NULL ? INT_MIN : data->
getInt(attributeIndex);
922 short getValueShort(
int pointIndex,
int attributeIndex)
924 GeoTessData* data = getPointMap()->getPointData(pointIndex);
925 return data == NULL ? SHRT_MIN : data->
getShort(attributeIndex);
935 byte getValueByte(
int pointIndex,
int attributeIndex)
937 GeoTessData* data = getPointMap()->getPointData(pointIndex);
938 return data == NULL ? CHAR_MIN : data->
getByte(attributeIndex);
949 void setValue(
int pointIndex,
int attributeIndex, T value)
951 GeoTessData* data = getPointMap()->getPointData(pointIndex);
952 if (data != NULL) data->
setValue(attributeIndex, value);
970 virtual bool operator == (
const GeoTessModel& other)
const;
980 virtual bool operator != (
const GeoTessModel& other)
const {
return !(*
this == other); } ;
1001 if (!pointMap->isPopulated())
1014 const set<int>& getConnectedVertices(
int layerIndex)
1024 void setActiveRegion()
1026 pointMap->setActiveRegion();
1041 void setActiveRegion(
const string& polygon)
1043 pointMap->setActiveRegion(polygon);
1059 pointMap->setActiveRegion(polygon);
1070 void getLayerCount(
bool activeOnly,
int* layerCount)
1072 for (
int layer=0; layer<getNLayers(); ++layer)
1073 layerCount[layer] = 0;
1077 for (
int v=0; v<getNVertices(); ++v)
1080 for (
int layer=0; layer<getNLayers(); ++layer)
1085 for (
int n=0; n<p->
getNData(); ++n)
1087 ++layerCount[layer];
1090 layerCount[layer] += pp[layer]->
getNData();
1104 return profiles[vertex][layer];
1115 return profiles[vertex];
1149 template<
typename T>
1150 void setProfile(
int vertex,
int layer, vector<float>& radii, vector<vector<T> >& values)
1152 if (getConnectedVertices(layer).count(vertex) == 1)
1153 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, values));
1172 template<
typename T>
1173 void setProfile(
const int& vertex,
const int& layer,
1174 float* radii,
const int& nRadii,
1175 T** values,
const int& nNodes,
const int& nAttributes)
1177 if (getConnectedVertices(layer).count(vertex) == 1)
1178 setProfile(vertex, layer, GeoTessProfile::newProfile(radii, nRadii, values, nNodes, nAttributes));
1190 void setProfile(
int vertex,
int layer, vector<float>& radii)
1202 template<
typename T>
1203 void setProfile(
const int& vertex,
const int& layer,
float* radii,
const int& nRadii)
1214 template<
typename T>
1215 void setProfile(
const int& vertex, vector<T>& values)
1227 template<
typename T>
1228 void setProfile(
const int& vertex, T* values,
const int& nAttributes)
1236 void setProfile(
const int& vertex)
1253 void writeModel(
const string& outputFile,
const string& gridFileName);
1268 void getLayerCount(vector<int>& layerCount,
const bool& activeOnly)
1270 layerCount.resize(metaData->
getNLayers(), 0);
1274 for (
int vtx=0; vtx<getNVertices(); ++vtx)
1277 for (
int layer = 0; layer < metaData->
getNLayers(); ++layer)
1281 for (
int n = 0; n < p->
getNData(); ++n)
1283 ++layerCount[layer];
1286 layerCount[layer] += pp[layer]->
getNData();
1297 void profileCount(vector< vector<int> >& count)
1304 vector<int> totalCount;
1305 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1306 totalCount.push_back(0);
1308 for (
int layer = 0; layer < getNLayers(); ++layer)
1310 vector<int> typeCount;
1312 for (
int profileType=0; profileType<GeoTessProfileType::size(); ++profileType)
1313 typeCount.push_back(0);
1315 count.push_back(typeCount);
1318 for (
int layer = 0; layer < getNLayers(); ++layer)
1320 for (
int vertex = 0; vertex < metaData->
getNVertices(); ++vertex)
1322 int pType = profiles[vertex][layer]->getType().ordinal();
1323 count[layer][pType] += 1;
1324 totalCount[pType] += 1;
1328 count.push_back(totalCount);
1364 template<
typename T>
1365 void initializeData(
const vector<string>& attributeNames,
1366 const vector<string>& attributeUnits, T fillValue)
1368 if (profiles == NULL)
1371 os << endl <<
"ERROR in GeoTessModel::initializeData" << endl
1372 <<
"Attempting to initialize the model data before Profiles" << endl
1373 <<
"have been specified (profiles == NULL)" << endl;
1377 const GeoTessDataType& newDataType = GeoTessDataType::getDataType(fillValue);
1378 int nAttributesNew = attributeNames.size();
1380 int newDataTypeOrdinal = newDataType.
ordinal();
1385 if (newDataTypeOrdinal != oldDataTypeOrdinal || nAttributesNew != metaData->
getNAttributes())
1389 T* newValues =
new T[nAttributesNew];
1390 for (
int i=0; i<nAttributesNew; ++i)
1391 newValues[i] = fillValue;
1394 vector<GeoTessData*> data;
1395 for (
int v = 0; v < getNVertices(); ++v)
1396 for (
int lid = 0; lid < getNLayers(); ++lid)
1398 profile = profiles[v][lid];
1401 for (
int n = 0; n < profile->
getNData(); ++n)
1404 data.push_back(GeoTessData::getData(newValues, nAttributesNew));
1429 template<
typename T>
1430 void initializeData(
const string& attributeNames,
1431 const string& attributeUnits, T fillValue)
1433 vector<string> names;
1434 CPPUtils::tokenizeString(attributeNames,
";", names);
1435 vector<string> units;
1436 CPPUtils::tokenizeString(attributeUnits,
";", units);
1437 initializeData(names, units, fillValue);
1459 void getWeights(
const vector<double*>& rayPath,
const vector<double>& radii,
1461 map<int, double>& weights);
1483 void getWeights(
double** rayPath,
double* radii,
const int& numPoints,
1485 map<int, double>& weights);
1516 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
1517 double** rayPath,
double* radii,
const int& numPoints,
1557 double getPathIntegral(
const int& attribute,
const bool& reciprocal,
1558 double** rayPath,
double* radii,
const int& numPoints,
1561 map<int, double>& weights);
1569 bool isSupportedFormatVersion(
int frmtVrsn)
1570 {
return (frmtVrsn == 1) ?
true :
false; }
1577 bool testLayerRadii();
1592 void writeModel(
const string& outputFile)
1593 { writeModel(outputFile, getGridFileReference()); }
1604 string getGridFileReference()
const
1619 #endif // GEOTESSMODEL_OBJECT_H