Skip to content

Commit

Permalink
#3012 Reanmed point_lonlat to points_lonlat. Added points_XYZ & point…
Browse files Browse the repository at this point in the history
…s_XYZ_km
  • Loading branch information
Howard Soh committed Dec 11, 2024
1 parent 4ed9972 commit 44812ae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
51 changes: 35 additions & 16 deletions src/libcode/vx_grid/grid_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,31 +316,32 @@ void UnstructuredData::clear() {

}


////////////////////////////////////////////////////////////////////////

void UnstructuredData::clear_data() {

n_face = n_node = n_edge = 0;
point_lonlat.clear();
lat_checksum = lon_checksum = 0.;
points_lonlat.clear();
points_XYZ.clear();
points_XYZ_km.clear();
lat_checksum = lon_checksum = alt_checksum = 0.;

if (kdtree) { delete kdtree; kdtree = nullptr; }

}


////////////////////////////////////////////////////////////////////////


void UnstructuredData::dump() const {

mlog << Debug(grid_debug_level)
<< "\nUnstructured Grid Data:\n"
<< " n_face: " << n_face << "\n"
<< " lat_checksum: " << lat_checksum << "\n"
<< " lon_checksum: " << lon_checksum << "\n"
<< " max_distance_km: " << max_distance_km << "\n"
<< " points: " << (0 < points_lonlat.size() ? "PointLonLat" : "PointXYZ") << "\n"
<< " lat_checksum: " << lat_checksum << "\n"
<< " lon_checksum: " << lon_checksum << "\n"
<< " alt_checksum: " << alt_checksum << "\n"
<< " max_distance_km: " << max_distance_km << "\n"
;
}

Expand Down Expand Up @@ -764,7 +765,12 @@ UnstructuredData *D = new UnstructuredData;
D->n_edge = data.n_edge;
D->n_node = data.n_node;
D->max_distance_km = data.max_distance_km;
D->set_points(data.n_face, data.point_lonlat);
if (data.has_PointLatLon()) {
D->set_points(data.n_face, data.points_lonlat);
}
else {
D->set_points(data.n_face, data.points_XYZ);
}
us = D;
D = (UnstructuredData *)nullptr;

Expand Down Expand Up @@ -1690,13 +1696,26 @@ bool is_eq(const UnstructuredData * us1, const UnstructuredData * us2)
bool status = false;
if (us1 && us2) {
if (us1 == us2) status = true;
else status = us1->n_face == us2->n_face
&& us1->n_node == us2->n_node
&& us1->n_edge == us2->n_edge
&& us1->point_lonlat[0] == us2->point_lonlat[0]
&& (us1->n_face > 0 && us1->point_lonlat[us1->n_face-1] == us2->point_lonlat[us2->n_face-1])
&& is_eq(us1->lat_checksum, us2->lat_checksum)
&& is_eq(us1->lon_checksum, us2->lon_checksum);
else {
status = us1->n_face == us2->n_face
&& us1->n_node == us2->n_node
&& us1->n_edge == us2->n_edge
&& us1->has_PointLatLon() == us2->has_PointLatLon()
&& is_eq(us1->lat_checksum, us2->lat_checksum)
&& is_eq(us1->lon_checksum, us2->lon_checksum);
if (status && (us1->n_face > 0)) {
if (us1->has_PointLatLon()) {
status = status
&& us1->points_lonlat[0] == us2->points_lonlat[0]
&& us1->points_lonlat[us1->n_face-1] == us2->points_lonlat[us2->n_face-1];
}
else {
status = status
&& us1->points_XYZ[0] == us2->points_lonlat[0]
&& us1->points_XYZ[us1->n_face-1] == us2->points_XYZ[us2->n_face-1];
&& is_eq(us1->alt_checksum, us2->alt_checksum);
}
}
}

return status;
Expand Down
19 changes: 14 additions & 5 deletions src/libcode/vx_grid/unstructured_grid_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@

////////////////////////////////////////////////////////////////////////




struct UnstructuredData {

const char * name; // not allocated
const char *name; // not allocated

int n_face;
int n_edge;
int n_node;
double max_distance_km; // This should be set after calling set_points()
double lat_checksum;
double lon_checksum;
double alt_checksum;

std::vector<atlas::PointLonLat> point_lonlat;
std::vector<atlas::PointLonLat> points_lonlat;
std::vector<atlas::PointXYZ> points_XYZ; // lat_deg, lon_der, alt_meters
std::vector<atlas::PointXYZ> points_XYZ_km; // x_km, y_km, z_km
atlas::util::IndexKDTree *kdtree;

UnstructuredData();
Expand All @@ -53,10 +53,19 @@ struct UnstructuredData {
bool is_in_distance(double distance_km) const;
void set_points(int count, double *_lon, double *_lat);
void set_points(int count, const std::vector<atlas::PointLonLat> &);
void set_points(int count, double *_lon, double *_lat, double *_alt);
void set_points(int count, const std::vector<atlas::PointXYZ> &);
void copy_from(const UnstructuredData *);
void copy_from(const UnstructuredData &);
void clear();
void clear_data();
bool has_PointLatLon() const;
void test_kdtree();
void test_llh_to_ecef();
atlas::util::IndexKDTree::ValueList closest_points(
const double &lat, const double &lon, const size_t &k,
const double &alt_m=bad_data_double) const;


void dump() const;
};
Expand Down

0 comments on commit 44812ae

Please sign in to comment.