36 #ifndef GEOTESSPOSITION_OBJECT_H
37 #define GEOTESSPOSITION_OBJECT_H
67 class GeoTessInterpolatorType;
151 void updatePosition2D(
int layerid,
const double*
const uVector);
170 void checkTessellation(
const int& tid)
172 if (triangle[tid] < 0)
175 triangle[tid] = grid.getTriangle(tid, 0, 0);
176 getContainingTriangle(tid);
188 void updateRadius(
int lid,
double rad)
190 if ((radius < 0.) || (rad != radius) || (lid != layerId))
194 tessid = layerTessIds[lid];
195 checkTessellation(tessid);
196 clearRadialCoefficients();
200 void clearRadialCoefficients()
202 for (
int i=0; i<(int)radialIndexes.size(); ++i)
204 radialIndexes[i].clear();
205 radialCoefficients[i].clear();
215 void updateRadialCoefficients()
219 if (radialIndexes.size() < vertices[tessid].size())
221 radialIndexes.resize(vertices[tessid].size());
222 radialCoefficients.resize(vertices[tessid].size());
227 if (radialIndexes[0].size() == 0)
229 vector<int>& v = vertices[tessid];
230 for (
int i = 0; i < (int)v.size(); ++i)
231 modlProfiles[v[i]][layerId]->setInterpolationCoefficients(radialInterpolatorType,
232 radialIndexes[i], radialCoefficients[i], radius, radiusOutOfRangeAllowed);
240 static const double TWALK_TOLERANCE;
252 void getContainingTriangle(
int tid);
262 int biggerTriangle(
int t1,
int t2)
264 const int* tv = grid.getTriangleVertexIndexes(t1);
265 double dot1 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
266 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
267 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
269 tv = grid.getTriangleVertexIndexes(t2);
270 double dot2 = GeoTessUtils::dot(grid.getVertex(tv[0]), grid.getVertex(tv[1]))
271 + GeoTessUtils::dot(grid.getVertex(tv[1]), grid.getVertex(tv[2]))
272 + GeoTessUtils::dot(grid.getVertex(tv[2]), grid.getVertex(tv[0]));
274 return dot2 > dot1 ? t1 : t2;
299 vector<double> layerRadii;
318 vector< vector< int> > vertices;
325 vector< vector< double> > linearCoefficients;
338 vector< vector< double> > hCoefficients;
354 vector<vector<int> > radialIndexes;
373 vector<vector<double> > radialCoefficients;
397 double const*
const* gridVertices;
398 int const*
const* gridTriangles;
399 int const* gridDescendants;
400 const vector<vector<Edge*> >& gridEdges;
401 const int* layerTessIds;
418 bool radiusOutOfRangeAllowed;
423 double unitVector[3];
428 int getTriangle(
int tid)
429 { checkTessellation(tid);
return triangle[tid]; };
435 virtual void update2D(
int tid) =
ABSTRACT;
509 virtual double getValue(
int attribute);
537 bool noEmptyProfiles();
559 void set(
double lat,
double lon,
double depth)
561 double uVector[3] = {0.0, 0.0, 0.0};
562 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
563 double newRadius = GeoTessUtils::getEarthRadius(uVector) - depth;
564 set(uVector, newRadius);
579 void set(
const double*
const uVector,
const double& newRadius)
581 updatePosition2D(nLayers - 1, uVector);
583 int lid = getLayerId(newRadius);
585 updatePosition2D(lid, uVector);
586 updateRadius(lid, newRadius);
606 void set(
int layid,
double lat,
double lon,
double depth)
609 set(lat, lon, depth);
613 GeoTessUtils::getVectorDegrees(lat, lon, uVector);
614 updatePosition2D(layid, uVector);
615 updateRadius(layid, GeoTessUtils::getEarthRadius(uVector) - depth);
629 void set(
int layid,
const double*
const uVector,
double rad)
635 updatePosition2D(layid, uVector);
636 if (rad >= 0.0) updateRadius(layid, rad);
647 void setTop(
int layid,
const double*
const uVector)
649 updatePosition2D(layid, uVector);
650 updateRadius(layid, getRadiusTop(layid));
661 void setBottom(
int layid,
const double*
const uVector)
663 updatePosition2D(layid, uVector);
664 updateRadius(layid, getRadiusBottom(layid));
674 void setRadius(
int layid,
double rad)
679 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
680 <<
"Geographic position has not been specified." << endl;
683 updateRadius(layid, rad);
692 void setRadius(
double rad)
698 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
699 <<
"Geographic position has not been specified." << endl;
702 updateRadius(getLayerId(rad), rad);
716 void setDepth(
int layer,
double depth)
718 setRadius(layer, getEarthRadius()-depth);
727 void setDepth(
double depth)
729 setRadius(getEarthRadius()-depth);
737 void setTop(
int layid)
742 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
743 <<
"Geographic position has not been specified." << endl;
746 tessid = layerTessIds[layid];
747 checkTessellation(tessid);
748 updateRadius(layid, getRadiusTop(layid));
757 void setBottom(
int layid)
762 os << endl <<
"ERROR in GeoTessPosition::setRadius" << endl
763 <<
"Geographic position has not been specified." << endl;
766 tessid = layerTessIds[layid];
767 checkTessellation(tessid);
768 updateRadius(layid, getRadiusBottom(layid));
778 double getRadiusTop(
int layid);
786 double getRadiusBottom(
int layid);
793 double getEarthRadius()
795 if (earthRadius < 0.)
796 earthRadius = GeoTessUtils::getEarthRadius(unitVector);
814 void copyVector(
double* u)
815 { u[0] = unitVector[0]; u[1] = unitVector[1]; u[2] = unitVector[2]; };
837 const vector<int>&
getVertices()
const {
return vertices[tessid]; };
844 int getIndexOfClosestVertex()
const;
852 const double* getClosestVertex()
const
854 return grid.getVertex(getIndexOfClosestVertex());
863 int getVertex(
int index)
864 {
return vertices[tessid][index]; }
871 void getCoefficients(map<int, double>& coefficients)
873 coefficients.clear();
874 vector<int>& vtx = vertices[tessid];
875 vector<double>& hc = hCoefficients[tessid];
876 for (
int i = 0; i < (int) vtx.size(); ++i)
877 modlProfiles[vtx[i]][layerId]->getCoefficients(coefficients, radius, hc[i]);
889 void setMaxTessLevel(
int layid,
int maxTess)
891 maxTessLevel[layerTessIds[layid]] = maxTess;
892 triangle[layerTessIds[layid]] = -1;
893 checkTessellation(tessid);
905 int getMaxTessLevel(
int layid)
906 {
return maxTessLevel[layerTessIds[layid]]; }
924 int getTessLevel(
const int& tId) { checkTessellation(tId);
return tessLevels[tId]; }
931 double getRadiusTop()
939 double getRadiusBottom()
949 return getEarthRadius() - getRadiusTop(layerId);
957 double getDepthBottom()
959 return getEarthRadius() - getRadiusBottom(layerId);
968 double getDepthTop(
int layid)
970 return getEarthRadius() - getRadiusTop(layid);
979 double getDepthBottom(
int layid)
981 return getEarthRadius() - getRadiusBottom(layid);
990 double getLayerThickness(
int layid)
992 return getRadiusTop(layid) - getRadiusBottom(layid);
1000 double getLayerThickness()
1002 return getRadiusTop() - getRadiusBottom();
1018 {
return getEarthRadius() - radius; };
1040 int getLayerId(
double rad)
1042 for (
int i=0; i<nLayers; ++i)
1043 if (rad <= getRadiusTop(i))
1046 for (
int i=nLayers-1; i>=0; --i)
1047 if (getLayerThickness(i) > 0)
1070 double getErrorValue()
1081 void setErrorValue(
double errVal)
1083 errorValue = errVal;
1093 int getVertexIndex()
1095 vector<int>& vtid = vertices[tessid];
1096 vector<double>& htid = hCoefficients[tessid];
1097 for (
int v = 0; v < (int) vtid.size(); ++v)
1098 if (htid[v] > 0.999999999)
1127 void getWeights(map<int, double>& weights,
double dkm)
1129 vector<int>& vtx = vertices[tessid];
1130 vector<double>& htid = hCoefficients[tessid];
1132 for (
int i = 0; i < (int) vtx.size(); ++i)
1133 modlProfiles[vtx[i]][layerId]->getWeights(weights, dkm, radius, htid[i]);
1143 const vector<double>& getHorizontalCoefficients()
const
1145 return hCoefficients[tessid];
1156 double getHorizontalCoefficient(
int index)
const
1158 return hCoefficients[tessid][index];
1176 bool isRadiusOutOfRangeAllowed()
1178 return radiusOutOfRangeAllowed;
1196 void setRadiusOutOfRangeAllowed(
bool allowed)
1198 if (allowed != radiusOutOfRangeAllowed)
1199 clearRadialCoefficients();
1201 radiusOutOfRangeAllowed = allowed;
1212 void removeReference()
1214 if (isNotReferenced())
1217 os << endl <<
"ERROR in Polygon::removeReference" << endl
1218 <<
"Reference count (" << refCount <<
") is already zero." << endl;
1230 int getReferenceCount()
1245 #endif // GEOTESSPOSITION_OBJECT_H