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);
501 virtual double getValue(
int attribute);
529 bool noEmptyProfiles();
551 void set(
double lat,
double lon,
double depth)
553 double uVector[3] = {0.0, 0.0, 0.0};
554 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
555 double newRadius = GeoTessUtils::getEarthRadius(uVector) - depth;
556 set(uVector, newRadius);
571 void set(
const double*
const uVector,
const double& newRadius)
573 updatePosition2D(nLayers - 1, uVector);
575 int lid = getLayerId(newRadius);
577 updatePosition2D(lid, uVector);
578 updateRadius(lid, newRadius);
598 void set(
int layid,
double lat,
double lon,
double depth)
601 set(lat, lon, depth);
605 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
606 updatePosition2D(layid, uVector);
607 updateRadius(layid, GeoTessUtils::getEarthRadius(uVector) - depth);
621 void set(
int layid,
const double*
const uVector,
double rad)
627 updatePosition2D(layid, uVector);
628 if (rad >= 0.0) updateRadius(layid, rad);
639 void setTop(
int layid,
const double*
const uVector)
641 updatePosition2D(layid, uVector);
642 updateRadius(layid, getRadiusTop(layid));
653 void setBottom(
int layid,
const double*
const uVector)
655 updatePosition2D(layid, uVector);
656 updateRadius(layid, getRadiusBottom(layid));
666 void setRadius(
int layid,
double rad)
671 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
672 <<
"Geographic position has not been specified." << endl;
675 updateRadius(layid, rad);
684 void setRadius(
double rad)
690 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
691 <<
"Geographic position has not been specified." << endl;
694 updateRadius(getLayerId(rad), rad);
708 void setDepth(
int layer,
double depth)
710 setRadius(layer, getEarthRadius()-depth);
719 void setDepth(
double depth)
721 setRadius(getEarthRadius()-depth);
729 void setTop(
int layid)
734 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
735 <<
"Geographic position has not been specified." << endl;
738 tessid = layerTessIds[layid];
739 checkTessellation(tessid);
740 updateRadius(layid, getRadiusTop(layid));
749 void setBottom(
int layid)
754 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
755 <<
"Geographic position has not been specified." << endl;
758 tessid = layerTessIds[layid];
759 checkTessellation(tessid);
760 updateRadius(layid, getRadiusBottom(layid));
770 double getRadiusTop(
int layid);
778 double getRadiusBottom(
int layid);
785 double getEarthRadius()
787 if (earthRadius < 0.)
788 earthRadius = GeoTessUtils::getEarthRadius(unitVector);
806 void copyVector(
double* u)
807 { u[0] = unitVector[0]; u[1] = unitVector[1]; u[2] = unitVector[2]; };
829 const vector<int>&
getVertices()
const {
return vertices[tessid]; };
836 int getIndexOfClosestVertex()
const;
844 const double* getClosestVertex()
const
846 return grid.getVertex(getIndexOfClosestVertex());
855 int getVertex(
int index)
856 {
return vertices[tessid][index]; }
863 void getCoefficients(map<int, double>& coefficients)
865 coefficients.clear();
866 vector<int>& vtx = vertices[tessid];
867 vector<double>& hc = hCoefficients[tessid];
868 for (
int i = 0; i < (int) vtx.size(); ++i)
869 modlProfiles[vtx[i]][layerId]->getCoefficients(coefficients, radius, hc[i]);
881 void setMaxTessLevel(
int layid,
int maxTess)
883 maxTessLevel[layerTessIds[layid]] = maxTess;
884 triangle[layerTessIds[layid]] = -1;
885 checkTessellation(tessid);
897 int getMaxTessLevel(
int layid)
898 {
return maxTessLevel[layerTessIds[layid]]; }
916 int getTessLevel(
const int& tId) { checkTessellation(tId);
return tessLevels[tId]; }
923 double getRadiusTop()
931 double getRadiusBottom()
941 return getEarthRadius() - getRadiusTop(layerId);
949 double getDepthBottom()
951 return getEarthRadius() - getRadiusBottom(layerId);
960 double getDepthTop(
int layid)
962 return getEarthRadius() - getRadiusTop(layid);
971 double getDepthBottom(
int layid)
973 return getEarthRadius() - getRadiusBottom(layid);
982 double getLayerThickness(
int layid)
984 return getRadiusTop(layid) - getRadiusBottom(layid);
992 double getLayerThickness()
994 return getRadiusTop() - getRadiusBottom();
1010 {
return getEarthRadius() - radius; };
1032 int getLayerId(
double rad)
1034 for (
int i=0; i<nLayers; ++i)
1035 if (rad <= getRadiusTop(i))
1038 for (
int i=nLayers-1; i>=0; --i)
1039 if (getLayerThickness(i) > 0)
1062 double getErrorValue()
1073 void setErrorValue(
double errVal)
1075 errorValue = errVal;
1085 int getVertexIndex()
1087 vector<int>& vtid = vertices[tessid];
1088 vector<double>& htid = hCoefficients[tessid];
1089 for (
int v = 0; v < (int) vtid.size(); ++v)
1090 if (htid[v] > 0.999999999)
1119 void getWeights(map<int, double>& weights,
double dkm)
1121 vector<int>& vtx = vertices[tessid];
1122 vector<double>& htid = hCoefficients[tessid];
1123 for (
int i = 0; i < (int) vtx.size(); ++i)
1124 modlProfiles[vtx[i]][layerId]->getWeights(weights, dkm, radius, htid[i]);
1134 const vector<double>& getHorizontalCoefficients()
const
1136 return hCoefficients[tessid];
1147 double getHorizontalCoefficient(
int index)
const
1149 return hCoefficients[tessid][index];
1167 bool isRadiusOutOfRangeAllowed()
1169 return radiusOutOfRangeAllowed;
1187 void setRadiusOutOfRangeAllowed(
bool allowed)
1189 if (allowed != radiusOutOfRangeAllowed)
1190 clearRadialCoefficients();
1192 radiusOutOfRangeAllowed = allowed;
1203 void removeReference()
1205 if (isNotReferenced())
1208 os << endl <<
"ERROR in Polygon::removeReference" << endl
1209 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1221 int getReferenceCount()
1236 #endif // GEOTESSPOSITION_OBJECT_H