FIX: fixed a issue where copied positions are alway valid

This commit is contained in:
hwinkel
2023-08-04 12:34:38 +02:00
parent 6fab3540bb
commit 6c5b17c90c
2 changed files with 24 additions and 13 deletions

View File

@@ -63,7 +63,7 @@ namespace SimCore {
mutable std::mutex mx; mutable std::mutex mx;
std::atomic_bool valid_; std::atomic_bool valid_ = false;
}; };

View File

@@ -6,33 +6,38 @@ namespace SimCore {
Position::Position():mx() Position::Position():mx()
{ {
valid_ = false;
earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
valid_ = false;
} }
Position::Position(double X, double Y, double Z):mx() Position::Position(double X, double Y, double Z):mx()
{ {
valid_ = false;
earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
setGeocentricPos( X, Y, Z); setGeocentricPos( X, Y, Z);
valid_ = true;
} }
Position::Position(const Position& other){ Position::Position(const Position& other){
std::lock_guard<std::mutex> lock(other.mx); std::lock_guard<std::mutex> lock(other.mx);
GeocentricPos_ = other.GeocentricPos_;
GeodesicPos_ = other.GeodesicPos_; valid_ = false;
if (other.valid_ == true)
{
this->setGeocentricPos(other.GeocentricPos_[X],other.GeocentricPos_[Y],other.GeocentricPos_[Z]);
}
// GeocentricPos_ = other.GeocentricPos_;
// GeodesicPos_ = other.GeodesicPos_;
earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); earth_ = std::make_unique<GeographicLib::Geocentric>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); geod_ = std::make_unique<GeographicLib::Geodesic>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); wgs84_ = std::make_unique<GeographicLib::Ellipsoid>(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
valid_ = true;
} }
Eigen::Vector3d Position::getGeocentricPos() Eigen::Vector3d Position::getGeocentricPos()
@@ -129,9 +134,15 @@ namespace SimCore {
Position& Position::operator=(const Position other) Position& Position::operator=(const Position other)
{ {
std::lock_guard<std::mutex> lock(other.mx); std::lock_guard<std::mutex> lock(other.mx);
GeocentricPos_ = other.GeocentricPos_; if (other.valid_ == true)
GeodesicPos_ = other.GeodesicPos_; {
valid_ = true; this->setGeocentricPos(other.GeocentricPos_[X],other.GeocentricPos_[Y],other.GeocentricPos_[Z]);
}
// GeocentricPos_ = other.GeocentricPos_;
// GeodesicPos_ = other.GeodesicPos_;
// valid_ = true;
return *this; return *this;
} }