36 #ifndef GEOTESSPOSITION_OBJECT_H
37 #define GEOTESSPOSITION_OBJECT_H
66 class InterpolatorType;
150 void updatePosition2D(
int layerid,
const double*
const uVector);
169 void checkTessellation(
const int& tid)
171 if (triangle[tid] < 0)
174 triangle[tid] = grid.getTriangle(tid, 0, 0);
175 getContainingTriangle(tid);
187 void updateRadius(
int lid,
double rad)
189 if ((radius < 0.) || (rad != radius) || (lid != layerId))
193 tessid = layerTessIds[lid];
194 checkTessellation(tessid);
195 clearRadialCoefficients();
199 void clearRadialCoefficients()
201 for (
int i=0; i<(int)radialIndexes.size(); ++i)
203 radialIndexes[i].clear();
204 radialCoefficients[i].clear();
214 void updateRadialCoefficients()
218 if (radialIndexes[0].size() == 0)
220 vector<int>& v = vertices[tessid];
221 for (
int i = 0; i < (int)v.size(); ++i)
222 modlProfiles[v[i]][layerId]->setInterpolationCoefficients(radialInterpolatorType,
223 radialIndexes[i], radialCoefficients[i], radius, radiusOutOfRangeAllowed);
231 static const double TWALK_TOLERANCE;
243 void getContainingTriangle(
int tid);
253 int biggerTriangle(
int t1,
int t2)
255 const int* tv = grid.getTriangleVertexIndexes(t1);
256 double dot1 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
257 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
258 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
260 tv = grid.getTriangleVertexIndexes(t2);
261 double dot2 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
262 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
263 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
265 return dot2 > dot1 ? t1 : t2;
290 vector<double> layerRadii;
309 vector< vector< int> > vertices;
316 vector< vector< double> > linearCoefficients;
324 vector< vector< double> > nnCoefficients;
329 vector< vector< double> >& hCoefficients;
345 vector<vector<int> > radialIndexes;
364 vector<vector<double> > radialCoefficients;
388 double const*
const* gridVertices;
389 int const*
const* gridTriangles;
390 int const*
const* gridNeighbors;
391 double const*
const*
const* gridEdges;
392 const int* layerTessIds;
409 bool radiusOutOfRangeAllowed;
414 double unitVector[3];
419 int getTriangle(
int tid)
420 { checkTessellation(tid);
return triangle[tid]; };
426 virtual void update2D(
int tid) =
ABSTRACT;
432 vector< vector<double> >& c);
499 virtual double getValue(
int attribute);
525 bool noEmptyProfiles();
547 void set(
double lat,
double lon,
double depth)
549 double uVector[3] = {0.0, 0.0, 0.0};
550 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
551 double newRadius = GeoTessUtils::getEarthRadius(uVector) - depth;
552 set(uVector, newRadius);
567 void set(
const double*
const uVector,
const double& newRadius)
569 updatePosition2D(nLayers - 1, uVector);
571 int lid = getLayerId(newRadius);
573 updatePosition2D(lid, uVector);
574 updateRadius(lid, newRadius);
594 void set(
int layid,
double lat,
double lon,
double depth)
597 set(lat, lon, depth);
601 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
602 updatePosition2D(layid, uVector);
603 updateRadius(layid, GeoTessUtils::getEarthRadius(uVector) - depth);
617 void set(
int layid,
const double*
const uVector,
double rad)
623 updatePosition2D(layid, uVector);
624 if (rad >= 0.0) updateRadius(layid, rad);
635 void setTop(
int layid,
const double*
const uVector)
637 updatePosition2D(layid, uVector);
638 updateRadius(layid, getRadiusTop(layid));
649 void setBottom(
int layid,
const double*
const uVector)
651 updatePosition2D(layid, uVector);
652 updateRadius(layid, getRadiusBottom(layid));
662 void setRadius(
int layid,
double rad)
667 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
668 <<
"Geographic position has not been specified." << endl;
671 updateRadius(layid, rad);
680 void setRadius(
double rad)
686 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
687 <<
"Geographic position has not been specified." << endl;
690 updateRadius(getLayerId(rad), rad);
704 void setDepth(
int layer,
double depth)
706 setRadius(layer, getEarthRadius()-depth);
715 void setDepth(
double depth)
717 setRadius(getEarthRadius()-depth);
725 void setTop(
int layid)
730 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
731 <<
"Geographic position has not been specified." << endl;
734 tessid = layerTessIds[layid];
735 checkTessellation(tessid);
736 updateRadius(layid, getRadiusTop(layid));
745 void setBottom(
int layid)
750 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
751 <<
"Geographic position has not been specified." << endl;
754 tessid = layerTessIds[layid];
755 checkTessellation(tessid);
756 updateRadius(layid, getRadiusBottom(layid));
766 double getRadiusTop(
int layid);
774 double getRadiusBottom(
int layid);
781 double getEarthRadius()
783 if (earthRadius < 0.)
784 earthRadius = GeoTessUtils::getEarthRadius(unitVector);
802 void copyVector(
double* u)
803 { u[0] = unitVector[0]; u[1] = unitVector[1]; u[2] = unitVector[2]; };
824 const vector<int>&
getVertices()
const {
return vertices[tessid]; };
829 int getIndexOfClosestVertex()
const;
835 const double* getClosestVertex()
const
837 return grid.getVertex(getIndexOfClosestVertex());
846 int getVertex(
int index)
847 {
return vertices[tessid][index]; }
854 void getCoefficients(map<int, double>& coefficients)
856 coefficients.clear();
857 vector<int>& vtx = vertices[tessid];
858 vector<double>& hc = hCoefficients[tessid];
859 for (
int i = 0; i < (int) vtx.size(); ++i)
860 modlProfiles[vtx[i]][layerId]->getCoefficients(coefficients, radius, hc[i]);
872 void setMaxTessLevel(
int layid,
int maxTess)
874 maxTessLevel[layerTessIds[layid]] = maxTess;
875 triangle[layerTessIds[layid]] = -1;
876 checkTessellation(tessid);
888 int getMaxTessLevel(
int layid)
889 {
return maxTessLevel[layerTessIds[layid]]; }
906 int getTessLevel(
const int& tId) { checkTessellation(tId);
return tessLevels[tId]; }
913 double getRadiusTop()
921 double getRadiusBottom()
931 return getEarthRadius() - getRadiusTop(layerId);
939 double getDepthBottom()
941 return getEarthRadius() - getRadiusBottom(layerId);
950 double getDepthTop(
int layid)
952 return getEarthRadius() - getRadiusTop(layid);
961 double getDepthBottom(
int layid)
963 return getEarthRadius() - getRadiusBottom(layid);
972 double getLayerThickness(
int layid)
974 return getRadiusTop(layid) - getRadiusBottom(layid);
982 double getLayerThickness()
984 return getRadiusTop() - getRadiusBottom();
1000 {
return getEarthRadius() - radius; };
1022 int getLayerId(
double rad)
1024 for (
int i=0; i<nLayers; ++i)
1025 if (rad <= getRadiusTop(i))
1028 for (
int i=nLayers-1; i>=0; --i)
1029 if (getLayerThickness(i) > 0)
1050 double getErrorValue()
1060 void setErrorValue(
double errVal)
1062 errorValue = errVal;
1072 int getVertexIndex()
1074 vector<int>& vtid = vertices[tessid];
1075 vector<double>& htid = hCoefficients[tessid];
1076 for (
int v = 0; v < (int) vtid.size(); ++v)
1077 if (htid[v] > 0.999999999)
1085 void getWeights(map<int, double>& weights,
double dkm)
1087 vector<int>& vtx = vertices[tessid];
1088 vector<double>& htid = hCoefficients[tessid];
1089 for (
int i = 0; i < (int) vtx.size(); ++i)
1090 modlProfiles[vtx[i]][layerId]->getWeights(weights, dkm, radius, htid[i]);
1100 const vector<double>& getHorizontalCoefficients()
const
1102 return hCoefficients[tessid];
1113 double getHorizontalCoefficient(
int index)
const
1115 return hCoefficients[tessid][index];
1132 bool isRadiusOutOfRangeAllowed()
1134 return radiusOutOfRangeAllowed;
1151 void setRadiusOutOfRangeAllowed(
bool allowed)
1153 if (allowed != radiusOutOfRangeAllowed)
1154 clearRadialCoefficients();
1156 radiusOutOfRangeAllowed = allowed;
1161 return grid.getGridID();
1172 void removeReference()
1174 if (isNotReferenced())
1177 os << endl <<
"ERROR in Polygon::removeReference" << endl
1178 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1185 int getReferenceCount()
1199 #endif // GEOTESSPOSITION_OBJECT_H