38 #ifndef GEOTESSPOSITION_OBJECT_H
39 #define GEOTESSPOSITION_OBJECT_H
69 class GeoTessInterpolatorType;
153 void updatePosition2D(
int layerid,
const double*
const uVector);
172 void checkTessellation(
const int& tid)
174 if (triangle[tid] < 0)
177 triangle[tid] = grid.getTriangle(tid, 0, 0);
178 getContainingTriangle(tid);
190 void updateRadius(
int lid,
double rad)
192 if ((radius < 0.) || (rad != radius) || (lid != layerId))
196 tessid = layerTessIds[lid];
197 checkTessellation(tessid);
198 clearRadialCoefficients();
202 void clearRadialCoefficients()
204 for (
int i=0; i<(int)radialIndexes.size(); ++i)
206 radialIndexes[i].clear();
207 radialCoefficients[i].clear();
217 void updateRadialCoefficients()
221 if (radialIndexes.size() < vertices[tessid].size())
223 radialIndexes.resize(vertices[tessid].size());
224 radialCoefficients.resize(vertices[tessid].size());
229 if (radialIndexes[0].size() == 0)
231 vector<int>& v = vertices[tessid];
232 for (
int i = 0; i < (int)v.size(); ++i)
233 modlProfiles[v[i]][layerId]->setInterpolationCoefficients(radialInterpolatorType,
234 radialIndexes[i], radialCoefficients[i], radius, radiusOutOfRangeAllowed);
242 static const double TWALK_TOLERANCE;
254 void getContainingTriangle(
int tid);
264 int biggerTriangle(
int t1,
int t2)
266 const int* tv = grid.getTriangleVertexIndexes(t1);
267 double dot1 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
268 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
269 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
271 tv = grid.getTriangleVertexIndexes(t2);
272 double dot2 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
273 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
274 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
276 return dot2 > dot1 ? t1 : t2;
301 vector<double> layerRadii;
320 vector< vector< int> > vertices;
327 vector< vector< double> > linearCoefficients;
340 vector< vector< double> > hCoefficients;
356 vector<vector<int> > radialIndexes;
375 vector<vector<double> > radialCoefficients;
399 double const*
const* gridVertices;
400 int const*
const* gridTriangles;
401 int const* gridDescendants;
402 const vector<vector<Edge*> >& gridEdges;
403 const int* layerTessIds;
420 bool radiusOutOfRangeAllowed;
425 double unitVector[3];
430 int getTriangle(
int tid)
431 { checkTessellation(tid);
return triangle[tid]; };
437 virtual void update2D(
int tid) =
ABSTRACT;
455 m += (long)(layerRadii.capacity() *
sizeof(double));
458 m += (long)(vertices.capacity()*
sizeof(vector<int>));
459 for (
int i=0; i<(int)vertices.size(); ++i)
460 m += (
long)(vertices[i].capacity()*
sizeof(int));
463 m += (long)(linearCoefficients.capacity()*
sizeof(vector<double>));
464 for (
int i=0; i<(int)linearCoefficients.size(); ++i)
465 m += (
long)(linearCoefficients[i].capacity()*
sizeof(double));
468 m += (long)(hCoefficients.capacity()*
sizeof(vector<double>));
469 for (
int i=0; i<(int)hCoefficients.size(); ++i)
470 m += (
long)(hCoefficients[i].capacity()*
sizeof(double));
473 m += (long)(radialIndexes.capacity()*
sizeof(vector<int>));
474 for (
int i=0; i<(int)radialIndexes.size(); ++i)
475 m += (
long)(radialIndexes[i].capacity()*
sizeof(int));
478 m += (long)(radialCoefficients.capacity()*
sizeof(vector<double>));
479 for (
int i=0; i<(int)radialCoefficients.size(); ++i)
480 m += (
long)(radialCoefficients[i].capacity()*
sizeof(double));
608 void set(
double lat,
double lon,
double depth)
610 double uVector[3] = {0.0, 0.0, 0.0};
611 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
612 double newRadius = GeoTessUtils::getEarthRadius(uVector) - depth;
613 set(uVector, newRadius);
628 void set(
const double*
const uVector,
const double& newRadius)
630 updatePosition2D(nLayers - 1, uVector);
632 int lid = getLayerId(newRadius);
634 updatePosition2D(lid, uVector);
635 updateRadius(lid, newRadius);
655 void set(
int layid,
double lat,
double lon,
double depth)
658 set(lat, lon, depth);
662 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
663 updatePosition2D(layid, uVector);
664 updateRadius(layid, GeoTessUtils::getEarthRadius(uVector) - depth);
678 void set(
int layid,
const double*
const uVector,
double rad)
684 updatePosition2D(layid, uVector);
685 if (rad >= 0.0) updateRadius(layid, rad);
696 void setTop(
int layid,
const double*
const uVector)
698 updatePosition2D(layid, uVector);
699 updateRadius(layid, getRadiusTop(layid));
712 updatePosition2D(layid, uVector);
713 updateRadius(layid, getRadiusBottom(layid));
728 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
729 <<
"Geographic position has not been specified." << endl;
732 updateRadius(layid, rad);
747 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
748 <<
"Geographic position has not been specified." << endl;
751 updateRadius(getLayerId(rad), rad);
767 setRadius(layer, getEarthRadius()-depth);
778 setRadius(getEarthRadius()-depth);
791 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
792 <<
"Geographic position has not been specified." << endl;
795 tessid = layerTessIds[layid];
796 checkTessellation(tessid);
797 updateRadius(layid, getRadiusTop(layid));
811 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
812 <<
"Geographic position has not been specified." << endl;
815 tessid = layerTessIds[layid];
816 checkTessellation(tessid);
817 updateRadius(layid, getRadiusBottom(layid));
844 if (earthRadius < 0.)
845 earthRadius = GeoTessUtils::getEarthRadius(unitVector);
864 { u[0] = unitVector[0]; u[1] = unitVector[1]; u[2] = unitVector[2]; };
886 const vector<int>&
getVertices()
const {
return vertices[tessid]; };
903 return grid.
getVertex(getIndexOfClosestVertex());
913 {
return vertices[tessid][index]; }
922 coefficients.clear();
923 vector<int>& vtx = vertices[tessid];
924 vector<double>& hc = hCoefficients[tessid];
925 for (
int i = 0; i < (int) vtx.size(); ++i)
926 modlProfiles[vtx[i]][layerId]->getCoefficients(coefficients, radius, hc[i]);
940 maxTessLevel[layerTessIds[layid]] = maxTess;
941 triangle[layerTessIds[layid]] = -1;
942 checkTessellation(tessid);
955 {
return maxTessLevel[layerTessIds[layid]]; }
973 int getTessLevel(
const int& tId) { checkTessellation(tId);
return tessLevels[tId]; }
981 {
return getRadiusTop(layerId); };
989 {
return getRadiusBottom(layerId); };
998 return getEarthRadius() - getRadiusTop(layerId);
1008 return getEarthRadius() - getRadiusBottom(layerId);
1019 return getEarthRadius() - getRadiusTop(layid);
1030 return getEarthRadius() - getRadiusBottom(layid);
1041 return getRadiusTop(layid) - getRadiusBottom(layid);
1051 return getRadiusTop() - getRadiusBottom();
1067 {
return getEarthRadius() - radius; };
1091 for (
int i=0; i<nLayers; ++i)
1092 if (rad <= getRadiusTop(i))
1095 for (
int i=nLayers-1; i>=0; --i)
1096 if (getLayerThickness(i) > 0)
1132 errorValue = errVal;
1144 vector<int>& vtid = vertices[tessid];
1145 vector<double>& htid = hCoefficients[tessid];
1146 for (
int v = 0; v < (int) vtid.size(); ++v)
1147 if (htid[v] > 0.999999999)
1178 vector<int>& vtx = vertices[tessid];
1179 vector<double>& htid = hCoefficients[tessid];
1181 for (
int i = 0; i < (int) vtx.size(); ++i)
1182 modlProfiles[vtx[i]][layerId]->getWeights(weights, dkm, radius, htid[i]);
1194 return hCoefficients[tessid];
1207 return hCoefficients[tessid][index];
1227 return radiusOutOfRangeAllowed;
1247 if (allowed != radiusOutOfRangeAllowed)
1248 clearRadialCoefficients();
1250 radiusOutOfRangeAllowed = allowed;
1263 if (isNotReferenced())
1266 os << endl <<
"ERROR in Polygon::removeReference" << endl
1267 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1294 #endif // GEOTESSPOSITION_OBJECT_H