37 #include "GeoTessGrid.h"
38 #include "GeoTessModel.h"
39 #include "GeoTessPosition.h"
58 int main(
int argc,
char** argv)
64 cout <<
"Must supply a single command line argument specifying path to the GeoTessModels directory" << endl;
68 string path = argv[1];
78 string inputGridFileName = CPPUtils::insertPathSeparator(path,
"small_model_grid.ascii");
80 cout <<
"Example that illustrates how to populate a 3D model." << endl << endl;
84 GeoTessMetaData* metaData =
new GeoTessMetaData();
89 metaData->setEarthShape(
"WGS84");
94 metaData->setDescription(
"Simple example of populating a 3D GeoTess model\ncomprised of 3 multi-level tessellations\nauthor: Sandy Ballard\ncontact: sballar@sandia.gov");
97 metaData->setLayerNames(
"INNER_CORE; OUTER_CORE; LOWER_MANTLE; TRANSITION_ZONE; UPPER_MANTLE; LOWER_CRUST; UPPER_CRUST");
110 int layerTessIds[] = {0, 0, 1, 1, 1, 2, 2};
114 metaData->setLayerTessIds(layerTessIds);
118 metaData->setAttributes(
"Vp; Vs; rho",
"km/sec; km/sec; g/cc");
123 metaData->setDataType(GeoTessDataType::FLOAT);
127 metaData->setModelSoftwareVersion(
"GeoTessCPPExamples.PopulateModel3D 1.0.0");
131 metaData->setModelGenerationDate(CpuTimer::now());
138 GeoTessModel* model =
new GeoTessModel(inputGridFileName, metaData);
143 EarthShape& ellipsoid = model->getEarthShape();
151 vector<vector<float> > attributeValues;
160 for (
int layer=0; layer<model->getNLayers(); ++layer)
163 for (
int vtx = 0; vtx < model->getNVertices(); ++vtx)
166 const double* vertex = model->getGrid().getVertex(vtx);
169 double lat = ellipsoid.getLatDegrees(vertex);
170 double lon = ellipsoid.getLonDegrees(vertex);
192 model->setProfile(vtx, layer, radii, attributeValues);
201 cout << model->toString() << endl << endl;
203 cout <<
"Radial profile at the south pole:" << endl;
204 cout <<
"Radius (km) Vp (km/sec) Vs (km/sec) Density (g/cc)" << endl;
205 cout << fixed << setprecision(3);
206 for (
int layer=0; layer < model->getNLayers(); ++layer)
208 GeoTessProfile* p = model->getProfile(11, layer);
209 cout <<
"Layer " << layer <<
" " << model->getMetaData().getLayerName(layer) <<
210 " of type " << p->getType().toString() << endl;
211 for (
int j=0; j<p->getNRadii(); ++j)
213 cout << setw(10) << p->getRadius(j);
214 if (j < p->getNData())
215 for (
int k=0; k<model->getMetaData().getNAttributes(); ++k)
216 cout << setw(10) << p->getData(j)->getFloat(k);
221 cout << endl << endl;
239 GeoTessPosition* position = model->getPosition(GeoTessInterpolatorType::NATURAL_NEIGHBOR);
248 ellipsoid.getVectorDegrees(lat, lon, v);
251 int layerID = model->getMetaData().getLayerIndex(
"UPPER_CRUST");
256 position->setTop(layerID, v);
258 cout << fixed << setprecision(3);
260 cout <<
"Interpolation lat, lon, depth = "
261 << ellipsoid.getLatDegrees(position->getVector()) <<
" deg, "
262 << ellipsoid.getLonDegrees(position->getVector()) <<
" deg, "
263 << position->getDepth() <<
" km" << endl << endl;
268 double vp = position->getValue(0);
269 double vs = position->getValue(1);
270 double rho = position->getValue(2);
273 cout <<
"Interpolated vp = " << setw(6) << vp <<
" " << model->getMetaData().getAttributeUnit(0) << endl;
274 cout <<
"Interpolated vs = " << setw(6) << vs <<
" " << model->getMetaData().getAttributeUnit(1) << endl;
275 cout <<
"Interpolated rho = " << setw(6) << rho <<
" " << model->getMetaData().getAttributeUnit(2) << endl;
279 cout <<
"Interpolated point resides in triangle index = " << position->getTriangle() << endl;
284 cout <<
" Node Lat Lon Coeff" << endl;
287 const vector<int>& x = position->getVertices();
290 const vector<double>& coef = position->getHorizontalCoefficients();
292 const GeoTessGrid& gridnew = model->getGrid();
293 for (
int j = 0; j < (int) x.size(); ++j)
295 cout << setw(6) << x[j] <<
296 setprecision(4) << setw(11) <<
297 ellipsoid.getLatDegrees(gridnew.getVertex(x[j])) <<
298 setprecision(4) << setw(11) <<
299 ellipsoid.getLonDegrees(gridnew.getVertex(x[j])) <<
300 setprecision(6) << setw(11) <<
307 cout << endl <<
"End of populateModel3D" << endl << endl;
310 catch (
const GeoTessException& ex)
312 cout << endl << ex.emessage << endl;
317 cout << endl <<
"Unidentified error detected " << endl
318 << __FILE__ <<
" " << __LINE__ << endl;