1 Commits

Author SHA1 Message Date
Michele Adduci
671a9233cb Added Docker Image for local testing, refactored API and LAS tool for using newer API 2024-01-28 07:59:43 +01:00
17 changed files with 268 additions and 238 deletions

25
.dev/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
FROM ubuntu:22.04
ARG CONAN_VERSION=2.0.17
ARG USERID=1000
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
clang-format \
curl \
cppcheck && \
curl -L https://github.com/conan-io/conan/releases/download/${CONAN_VERSION}/conan-ubuntu-64.deb -o /tmp/conan.deb && \
dpkg -i /tmp/conan.deb && \
apt-get install --fix-broken -y && \
apt-get autoremove --purge -y && \
apt-get autoclean -y && \
rm -rf /var/apt/cache/* && \
useradd -rm -d /home/user -s /bin/bash -g root -G sudo -u ${USERID} user
USER user
WORKDIR /home/user
RUN conan profile detect

View File

@@ -29,16 +29,17 @@
#ifndef LASREADER_INCLUDED
#define LASREADER_INCLUDED
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>
#ifndef E57FOUNDATIONIMPL_H_INCLUDED
# include <openE57/impl/openE57Impl.h>
# include <openE57/impl/time_conversion.h>
#endif
#include <openE57/openE57.h>
namespace e57
{
// The URI of the LAS extension.
// Used to identify the extended field names for encoding data from LAS files (LAS versions 1.0 to 1.3).
// By convention, will typically be used with prefix "las". ???"las13"?
constexpr const char* LAS_V1_0_URI = "http://www.astm.org/COMMIT/E57/2010-las-v1.0";
struct LASPublicHeaderBlock
{ // file format#: 1.0 1.1 1.2 1.3
char fileSignature[4]; // required 4 4 4 4

View File

@@ -104,7 +104,10 @@ namespace core
double colorBlueMinimum{0.0}; //!< The minimum producible blue color value. Unit is unspecified.
double colorBlueMaximum{0.0}; //!< The maximum producible blue color value. Unit is unspecified.
};
} // namespace core
namespace time
{
/**
* @brief The UtcTime structure defines a valid UTC Date Time representation.
*/
@@ -142,16 +145,12 @@ namespace core
*/
GpsTime(const uint16_t gps_week, const double gps_tow);
};
} // namespace core
namespace utils
{
/**
* @brief This function returns the current GPS time as core::GpsTime.
*
* @return the current GPS Time as core::GpsTime
*/
[[nodiscard]] core::GpsTime current_gps_time() noexcept;
[[nodiscard]] GpsTime current_gps_time() noexcept;
/**
* @brief This function returns the current UTC time as core::UtcTime.
@@ -161,7 +160,7 @@ namespace utils
*
* @return the current Date/Time as core::UtcTime
*/
[[nodiscard]] core::UtcTime current_utc_time() noexcept;
[[nodiscard]] UtcTime current_utc_time() noexcept;
/**
* @brief This function converts the date and time from the double dateTimeValue.
@@ -172,7 +171,7 @@ namespace utils
* @param gps_time the value holding the GPS Date/Time value as core::GpsTime structure
* @return the UTC Date/Time as core::UtcTime
*/
[[nodiscard]] core::UtcTime utc_time_from_gps_time(const core::GpsTime& gps_time);
[[nodiscard]] UtcTime utc_time_from_gps_time(const GpsTime& gps_time) noexcept;
/**
* @brief This function converts the date and time from the structure core::UtcTime dateTimeValue.
@@ -183,9 +182,21 @@ namespace utils
* @param utc_time the value holding the UTC Date/Time value as core::UtcTime structure
* @return the GPS Date/Time as core::GpsTime
*/
[[nodiscard]] core::GpsTime gps_time_from_utc_time(const core::UtcTime& utc_time);
[[nodiscard]] GpsTime gps_time_from_utc_time(const UtcTime& utc_time) noexcept;
} // namespace utils
/**
* @brief This function determines the time as core::GpsTime of the start of a day from the day of year and the year.
* @details The date and time is encoded using a single
* floating point number, stored as an E57 Float element which is based on the Global Positioning
* System (GPS) time scale.
*
* @param year the year to be converted from
* @param day_of_year the number of days into the year (1-366) [days]
* @return the GPS Date/Time as core::GpsTime
*/
[[nodiscard]] GpsTime gps_time_from_year_and_day(const unsigned short year, const unsigned short day_of_year) noexcept;
} // namespace time
} // namespace e57

View File

@@ -115,11 +115,6 @@ inline ustring exception_string(const char* errorName, const char* fileName, int
#define E57_EXCEPTION1(ecode) (E57Exception((ecode), ustring(), __FILE__, __LINE__, __FUNCTION__))
#define E57_EXCEPTION2(ecode, context) (E57Exception((ecode), (context), __FILE__, __LINE__, __FUNCTION__))
// The URI of the LAS extension. !!! should not be in E57Foundation.h, should be in separate file with names of fields
// Used to identify the extended field names for encoding data from LAS files (LAS versions 1.0 to 1.3).
// By convention, will typically be used with prefix "las". ???"las13"?
#define LAS_V1_0_URI "http://www.astm.org/COMMIT/E57/2010-las-v1.0" //??? change to v1.0 before final release
/// Create whitespace of given length, for indenting printouts in dump() functions
inline std::string space(const size_t n)
{

View File

@@ -9,16 +9,13 @@
University of Calgary Graduate Course. \n
*/
#ifndef TIME_CONVERSION_H
#define TIME_CONVERSION_H
#ifndef E57TIME_H_INCLUDED
# define E57TIME_H
namespace e57
{
namespace utils
namespace time
{
// Constants definition
constexpr const double SECONDS_IN_A_DAY = 86400.0;
constexpr const double SECONDS_IN_A_WEEK = SECONDS_IN_A_DAY * 7; // 604800.0
/**
* @brief Obtains the UTC time, GPS time, and Julian date from PC system time.
*
@@ -302,8 +299,8 @@ namespace utils
double& gps_tow //!< GPS time of week (0-604800.0) [s])
) noexcept;
} // namespace utils
} // namespace time
} // namespace e57
#endif // TIME_CONVERSION_H
#endif // E57TIME_H

View File

@@ -2,7 +2,7 @@
* openE57.h - public header of E57 Foundation API for reading/writing .e57 files.
*
* Copyright (c) 2009 - 2010 Kevin Ackley (kackley@gwi.net)
* Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
* Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by

View File

@@ -3,7 +3,7 @@
// openE57Simple.h - public header of E57 Simple API for reading/writing .e57 files.
//
// Copyright (c) 2010 Stan Coleby (scoleby@intelisum.com)
// Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
// Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
//
// All rights reserved.
//

View File

@@ -3,12 +3,12 @@
using namespace e57;
core::GpsTime::GpsTime(const double gps_time) : time{gps_time}
time::GpsTime::GpsTime(const double gps_time) : time{gps_time}
{
unsigned short gps_week{};
double gps_tow{};
if (!utils::gps_time_from_value(gps_time, gps_week, gps_tow))
if (!time::gps_time_from_value(gps_time, gps_week, gps_tow))
{
this->week = 0;
this->tow = 0.0;
@@ -19,10 +19,10 @@ core::GpsTime::GpsTime(const double gps_time) : time{gps_time}
this->tow = gps_tow;
}
core::GpsTime::GpsTime(const uint16_t gps_week, const double gps_tow) : week{gps_week}, tow{gps_tow}
time::GpsTime::GpsTime(const uint16_t gps_week, const double gps_tow) : week{gps_week}, tow{gps_tow}
{
double gps_time{};
if (!utils::gps_time_to_value(week, tow, gps_time))
if (!time::gps_time_to_value(week, tow, gps_time))
{
this->time = 0.0;
return;
@@ -31,26 +31,20 @@ core::GpsTime::GpsTime(const uint16_t gps_week, const double gps_tow) : week{gps
this->time = gps_time;
}
[[nodiscard]] core::GpsTime utils::current_gps_time() noexcept
[[nodiscard]] time::GpsTime time::current_gps_time() noexcept
{
uint16_t gps_week{};
double gps_tow{};
double gps_time{};
if (!utils::current_gps_time(gps_week, gps_tow))
if (!time::current_gps_time(gps_week, gps_tow))
{
return core::GpsTime{};
return time::GpsTime{};
}
if (!utils::gps_time_to_value(gps_week, gps_tow, gps_time))
{
return core::GpsTime(0.0);
}
return core::GpsTime(gps_time);
return time::GpsTime(gps_week, gps_tow);
}
[[nodiscard]] core::UtcTime utils::current_utc_time() noexcept
[[nodiscard]] time::UtcTime time::current_utc_time() noexcept
{
unsigned short utc_year{};
unsigned char utc_month{};
@@ -59,15 +53,15 @@ core::GpsTime::GpsTime(const uint16_t gps_week, const double gps_tow) : week{gps
unsigned char utc_minute{};
float utc_seconds{};
if (!utils::current_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!time::current_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
return core::UtcTime{};
return time::UtcTime{};
}
return core::UtcTime{utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds};
return time::UtcTime{utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds};
}
[[nodiscard]] core::UtcTime utils::utc_time_from_gps_time(const core::GpsTime& gps_time)
[[nodiscard]] time::UtcTime time::utc_time_from_gps_time(const time::GpsTime& gps_time) noexcept
{
unsigned short utc_year{};
unsigned char utc_month{};
@@ -76,23 +70,35 @@ core::GpsTime::GpsTime(const uint16_t gps_week, const double gps_tow) : week{gps
unsigned char utc_minute{};
float utc_seconds{};
if (!utils::utc_time_from_gps_time(gps_time.week, gps_time.tow, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!time::utc_time_from_gps_time(gps_time.week, gps_time.tow, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
return core::UtcTime{};
return time::UtcTime{};
}
return core::UtcTime{utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds};
return time::UtcTime{utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds};
}
[[nodiscard]] core::GpsTime utils::gps_time_from_utc_time(const core::UtcTime& utc_time)
[[nodiscard]] time::GpsTime time::gps_time_from_utc_time(const time::UtcTime& utc_time) noexcept
{
unsigned short gps_week{};
double gps_tow{};
if (!utils::gps_time_from_utc_time(utc_time.year, utc_time.month, utc_time.day, utc_time.hour, utc_time.minute, utc_time.seconds, gps_week, gps_tow))
if (!time::gps_time_from_utc_time(utc_time.year, utc_time.month, utc_time.day, utc_time.hour, utc_time.minute, utc_time.seconds, gps_week, gps_tow))
{
return core::GpsTime{};
return time::GpsTime{};
}
return core::GpsTime(gps_week, gps_tow);
return time::GpsTime(gps_week, gps_tow);
}
[[nodiscard]] time::GpsTime time::gps_time_from_year_and_day(const unsigned short year, const unsigned short day_of_year) noexcept
{
unsigned short gps_week{};
double gps_tow{};
if (!time::gps_time_from_year_and_day_of_year(year, day_of_year, gps_week, gps_tow))
{
return time::GpsTime{};
}
return time::GpsTime(gps_week, gps_tow);
}

View File

@@ -3,7 +3,7 @@
* Reference Implementation.
*
* Copyright (c) 2009 - 2010 Kevin Ackley (kackley@gwi.net)
* Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
* Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by

View File

@@ -3,7 +3,7 @@
* reference implementation.
*
* Copyright (c) 2009 - 2010 Kevin Ackley (kackley@gwi.net)
* Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
* Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by

View File

@@ -3,7 +3,7 @@
// openE57Simple.cpp - private implementation header of E57 format reference implementation.
//
// Copyright (c) 2010 Stan Coleby (scoleby@intelisum.com)
// Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
// Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
// All rights reserved.
//
// Permission is hereby granted, free of charge, to any person or organization

View File

@@ -3,7 +3,7 @@
// openE57SimpleImpl.cpp - private implementation header of E57 format reference implementation.
//
// Copyright (c) 2010 Stan Coleby (scoleby@intelisum.com)
// Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
// Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
// All rights reserved.
//
// Permission is hereby granted, free of charge, to any person or organization

View File

@@ -2,7 +2,7 @@
* lasreader.cpp - simple routines for reading LAS files.
*
* Copyright (c) 2009 - 2010 Kevin Ackley (kackley@gwi.net)
* Copyright (c) 2020 - 2022 Michele Adduci (adduci@tutanota.com)
* Copyright (c) 2020 - 2024 Michele Adduci (adduci@tutanota.com)
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
@@ -29,8 +29,6 @@
#include <openE57/LAS/openE57las.h>
#include <openE57/impl/openE57Impl.h>
#include <algorithm>
using namespace std;
using namespace e57;

View File

@@ -35,6 +35,8 @@ constexpr const double JULIAN_DATE_OFFSET_2006 = 2453736.5000; // Jan 01 2006 00
constexpr const double JULIAN_DATE_OFFSET_2009 = 2454832.5000; // Jan 01 2009 00:00:00.0
// Constants definition
constexpr const double SECONDS_IN_A_DAY = 86400.0;
constexpr const double SECONDS_IN_A_WEEK = SECONDS_IN_A_DAY * 7; // 604800.0
constexpr const double JULIAN_DATE_START_OF_GPS_TIME = JULIAN_DATE_OFFSET_1980; // [days]
constexpr const double JULIAN_DATE_START_OF_PC_TIME = 2440587.5; // [days]
constexpr const int DAYS_IN_JAN = 31;
@@ -49,7 +51,7 @@ constexpr const int DAYS_IN_OCT = 31;
constexpr const int DAYS_IN_NOV = 30;
constexpr const int DAYS_IN_DEC = 31;
[[nodiscard]] bool e57::utils::current_system_time(
[[nodiscard]] bool e57::time::current_system_time(
unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
unsigned char& utc_day, //!< Universal Time Coordinated [1-31 days]
@@ -62,25 +64,25 @@ constexpr const int DAYS_IN_DEC = 31;
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
{
if (!e57::utils::current_julian_date(julian_date))
if (!e57::time::current_julian_date(julian_date))
{
ERROR_MESSAGE("current_julian_date returned false.");
return false;
}
if (!e57::utils::determine_utc_offset(julian_date, utc_offset))
if (!e57::time::determine_utc_offset(julian_date, utc_offset))
{
ERROR_MESSAGE("determine_utc_offset returned false.");
return false;
}
if (!e57::utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
if (!e57::time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
{
ERROR_MESSAGE("gps_time_from_julian_date returned false.");
return false;
}
if (!e57::utils::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("utc_time_from_julian_date returned false");
return false;
@@ -89,8 +91,8 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::current_julian_date(double& julian_date //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
) noexcept
[[nodiscard]] bool e57::time::current_julian_date(double& julian_date //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
) noexcept
{
std::timespec time_spec;
@@ -114,26 +116,26 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::current_gps_time(unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
[[nodiscard]] bool e57::time::current_gps_time(unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
{
double julian_date{};
unsigned char utc_offset{};
if (!e57::utils::current_julian_date(julian_date))
if (!e57::time::current_julian_date(julian_date))
{
ERROR_MESSAGE("current_julian_date returned false.");
return false;
}
if (!e57::utils::determine_utc_offset(julian_date, utc_offset))
if (!e57::time::determine_utc_offset(julian_date, utc_offset))
{
ERROR_MESSAGE("determine_utc_offset returned false.");
return false;
}
if (!e57::utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
if (!e57::time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
{
ERROR_MESSAGE("gps_time_from_julian_date returned false.");
return false;
@@ -142,23 +144,23 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::current_utc_time(unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
unsigned char& utc_day, //!< Universal Time Coordinated [1-31 days]
unsigned char& utc_hour, //!< Universal Time Coordinated [hours]
unsigned char& utc_minute, //!< Universal Time Coordinated [minutes]
float& utc_seconds //!< Universal Time Coordinated [s]
) noexcept
[[nodiscard]] bool e57::time::current_utc_time(unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
unsigned char& utc_day, //!< Universal Time Coordinated [1-31 days]
unsigned char& utc_hour, //!< Universal Time Coordinated [hours]
unsigned char& utc_minute, //!< Universal Time Coordinated [minutes]
float& utc_seconds //!< Universal Time Coordinated [s]
) noexcept
{
double julian_date{};
if (!e57::utils::current_julian_date(julian_date))
if (!e57::time::current_julian_date(julian_date))
{
ERROR_MESSAGE("current_julian_date returned false.");
return false;
}
if (!e57::utils::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("utc_time_from_julian_date returned false");
return false;
@@ -167,7 +169,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::day_of_week_from_julian_date(
[[nodiscard]] bool e57::time::day_of_week_from_julian_date(
const double julian_date, //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned char& day_of_week //!< 0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday [].
) noexcept
@@ -222,7 +224,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::julian_date_from_gps_time(
[[nodiscard]] bool e57::time::julian_date_from_gps_time(
const unsigned short gps_week, //!< GPS week (0-1024+) [week]
const double gps_tow, //!< GPS time of week (0-604800.0) [s]
const unsigned char utc_offset, //!< Integer seconds that GPS is ahead of UTC time, always positive [s]
@@ -240,7 +242,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::julian_date_from_utc_time(
[[nodiscard]] bool e57::time::julian_date_from_utc_time(
const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
@@ -254,7 +256,7 @@ constexpr const int DAYS_IN_DEC = 31;
double m{0.0}; // temp for month
// Check the input.
if (!e57::utils::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("is_utc_time_valid returned false.");
return false;
@@ -276,7 +278,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_from_julian_date(
[[nodiscard]] bool e57::time::gps_time_from_julian_date(
const double julian_date, //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
const unsigned char utc_offset, //!< Integer seconds that GPS is ahead of UTC time, always positive [s]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
@@ -309,7 +311,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::utc_time_from_julian_date(
[[nodiscard]] bool e57::time::utc_time_from_julian_date(
const double julian_date, //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
@@ -368,7 +370,7 @@ constexpr const int DAYS_IN_DEC = 31;
hour -= 24;
day++;
if (!e57::utils::number_days_in_month(year, month, days_in_month))
if (!e57::time::number_days_in_month(year, month, days_in_month))
{
ERROR_MESSAGE("number_days_in_month returned false.");
return false;
@@ -398,39 +400,39 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_from_utc_time(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds, //!< Universal Time Coordinated [s]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
[[nodiscard]] bool e57::time::gps_time_from_utc_time(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds, //!< Universal Time Coordinated [s]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
{
double julian_date{0.0};
unsigned char utc_offset{0};
// Check the input.
if (!e57::utils::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("is_utc_time_valid returned false.");
return false;
}
if (!e57::utils::julian_date_from_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, julian_date))
if (!e57::time::julian_date_from_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, julian_date))
{
ERROR_MESSAGE("julian_date_from_utc_time returned false.");
return false;
}
if (!e57::utils::determine_utc_offset(julian_date, utc_offset))
if (!e57::time::determine_utc_offset(julian_date, utc_offset))
{
ERROR_MESSAGE("determine_utc_offset returned false.");
return false;
}
if (!e57::utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
if (!e57::time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
{
ERROR_MESSAGE("gps_time_from_julian_date returned false.");
return false;
@@ -439,33 +441,33 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_from_rinex_time(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds, //!< Universal Time Coordinated [s]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
[[nodiscard]] bool e57::time::gps_time_from_rinex_time(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds, //!< Universal Time Coordinated [s]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
{
double julian_date{0.0};
unsigned char utc_offset{0};
// Check the input.
if (!e57::utils::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::is_utc_time_valid(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("is_utc_time_valid returned false.");
return false;
}
if (!e57::utils::julian_date_from_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, julian_date))
if (!e57::time::julian_date_from_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, julian_date))
{
ERROR_MESSAGE("julian_date_from_utc_time returned false.");
return false;
}
if (!e57::utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
if (!e57::time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
{
ERROR_MESSAGE("GetGPSTimeFromJulianDate returned false.");
return false;
@@ -474,15 +476,15 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::utc_time_from_gps_time(const unsigned short gps_week, //!< GPS week (0-1024+) [week]
const double gps_tow, //!< GPS time of week (0-604800.0) [s]
unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
unsigned char& utc_day, //!< Universal Time Coordinated [1-31 days]
unsigned char& utc_hour, //!< Universal Time Coordinated [hours]
unsigned char& utc_minute, //!< Universal Time Coordinated [minutes]
float& utc_seconds //!< Universal Time Coordinated [s]
) noexcept
[[nodiscard]] bool e57::time::utc_time_from_gps_time(const unsigned short gps_week, //!< GPS week (0-1024+) [week]
const double gps_tow, //!< GPS time of week (0-604800.0) [s]
unsigned short& utc_year, //!< Universal Time Coordinated [year]
unsigned char& utc_month, //!< Universal Time Coordinated [1-12 months]
unsigned char& utc_day, //!< Universal Time Coordinated [1-31 days]
unsigned char& utc_hour, //!< Universal Time Coordinated [hours]
unsigned char& utc_minute, //!< Universal Time Coordinated [minutes]
float& utc_seconds //!< Universal Time Coordinated [s]
) noexcept
{
double julian_date{0.0};
unsigned char utc_offset{0};
@@ -497,20 +499,20 @@ constexpr const int DAYS_IN_DEC = 31;
// iterate to get the right utc offset
for (i = 0; i < 4; i++)
{
if (!e57::utils::julian_date_from_gps_time(gps_week, gps_tow, utc_offset, julian_date))
if (!e57::time::julian_date_from_gps_time(gps_week, gps_tow, utc_offset, julian_date))
{
ERROR_MESSAGE("julian_date_from_gps_time returned false.");
return false;
}
if (!e57::utils::determine_utc_offset(julian_date, utc_offset))
if (!e57::time::determine_utc_offset(julian_date, utc_offset))
{
ERROR_MESSAGE("determine_utc_offset returned false.");
return false;
}
}
if (!e57::utils::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
if (!e57::time::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
{
ERROR_MESSAGE("utc_time_from_julian_date returned false.");
return false;
@@ -519,7 +521,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::determine_utc_offset(
[[nodiscard]] bool e57::time::determine_utc_offset(
const double julian_date, //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned char& utc_offset //!< Integer seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table
) noexcept
@@ -577,12 +579,12 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::number_days_in_month(const unsigned short year, //!< Universal Time Coordinated [year]
const unsigned char month, //!< Universal Time Coordinated [1-12 months]
unsigned char& days_in_month //!< Days in the specified month [1-28|29|30|31 days]
) noexcept
[[nodiscard]] bool e57::time::number_days_in_month(const unsigned short year, //!< Universal Time Coordinated [year]
const unsigned char month, //!< Universal Time Coordinated [1-12 months]
unsigned char& days_in_month //!< Days in the specified month [1-28|29|30|31 days]
) noexcept
{
const bool is_a_leapyear = e57::utils::is_leap_year(year);
const bool is_a_leapyear = e57::time::is_leap_year(year);
unsigned char utmp{0};
switch (month)
@@ -642,7 +644,7 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::is_leap_year(const unsigned short year) noexcept
[[nodiscard]] bool e57::time::is_leap_year(const unsigned short year) noexcept
{
bool is_a_leap_year{false};
@@ -670,14 +672,14 @@ constexpr const int DAYS_IN_DEC = 31;
return false;
}
[[nodiscard]] bool e57::utils::day_of_year(const unsigned short utc_year, // Universal Time Coordinated [year]
const unsigned char utc_month, // Universal Time Coordinated [1-12 months]
const unsigned char utc_day, // Universal Time Coordinated [1-31 days]
unsigned short& day_of_year // the day of the year (1-366) [days]
) noexcept
[[nodiscard]] bool e57::time::day_of_year(const unsigned short utc_year, // Universal Time Coordinated [year]
const unsigned char utc_month, // Universal Time Coordinated [1-12 months]
const unsigned char utc_day, // Universal Time Coordinated [1-31 days]
unsigned short& day_of_year // the day of the year (1-366) [days]
) noexcept
{
unsigned char days_in_feb{0};
if (!e57::utils::number_days_in_month(utc_year, 2, days_in_feb))
if (!e57::time::number_days_in_month(utc_year, 2, days_in_feb))
{
ERROR_MESSAGE("number_days_in_month returned false.");
return false;
@@ -731,11 +733,11 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_from_year_and_day_of_year(const unsigned short year, // The year [year]
const unsigned short day_of_year, // The number of days into the year (1-366) [days]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
[[nodiscard]] bool e57::time::gps_time_from_year_and_day_of_year(const unsigned short year, // The year [year]
const unsigned short day_of_year, // The number of days into the year (1-366) [days]
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s]
) noexcept
{
double julian_date{0.0};
unsigned char utc_offset{};
@@ -746,13 +748,13 @@ constexpr const int DAYS_IN_DEC = 31;
return false;
}
if (!e57::utils::julian_date_from_utc_time(year, 1, 1, 0, 0, 0, julian_date))
if (!e57::time::julian_date_from_utc_time(year, 1, 1, 0, 0, 0, julian_date))
{
ERROR_MESSAGE("julian_date_from_utc_time returned false.");
return false;
}
if (!e57::utils::determine_utc_offset(julian_date, utc_offset))
if (!e57::time::determine_utc_offset(julian_date, utc_offset))
{
ERROR_MESSAGE("determine_utc_offset returned false.");
return false;
@@ -760,7 +762,7 @@ constexpr const int DAYS_IN_DEC = 31;
julian_date += day_of_year - 1; // at the start of the day so -1.
if (!e57::utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
if (!e57::time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow))
{
ERROR_MESSAGE("gps_time_from_julian_date returned false.");
return false;
@@ -769,13 +771,13 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::is_utc_time_valid(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds //!< Universal Time Coordinated [s]
) noexcept
[[nodiscard]] bool e57::time::is_utc_time_valid(const unsigned short utc_year, //!< Universal Time Coordinated [year]
const unsigned char utc_month, //!< Universal Time Coordinated [1-12 months]
const unsigned char utc_day, //!< Universal Time Coordinated [1-31 days]
const unsigned char utc_hour, //!< Universal Time Coordinated [hours]
const unsigned char utc_minute, //!< Universal Time Coordinated [minutes]
const float utc_seconds //!< Universal Time Coordinated [s]
) noexcept
{
unsigned char daysInMonth;
if (utc_month == 0 || utc_month > 12)
@@ -799,7 +801,7 @@ constexpr const int DAYS_IN_DEC = 31;
return false;
}
if (!e57::utils::number_days_in_month(utc_year, utc_month, daysInMonth))
if (!e57::time::number_days_in_month(utc_year, utc_month, daysInMonth))
{
ERROR_MESSAGE("number_days_in_month returned false.");
return false;
@@ -814,10 +816,10 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_to_value(const unsigned short gps_week, //!< GPS week (0-1024+) [week]
const double gps_tow, //!< GPS time of week (0-604800.0) [s])
double& gps_time //!< GPS time expressed as a single double value)
) noexcept
[[nodiscard]] bool e57::time::gps_time_to_value(const unsigned short gps_week, //!< GPS week (0-1024+) [week]
const double gps_tow, //!< GPS time of week (0-604800.0) [s])
double& gps_time //!< GPS time expressed as a single double value)
) noexcept
{
if (gps_tow < 0.0 || gps_tow > SECONDS_IN_A_WEEK)
{
@@ -830,10 +832,10 @@ constexpr const int DAYS_IN_DEC = 31;
return true;
}
[[nodiscard]] bool e57::utils::gps_time_from_value(const double gps_time, //!< GPS time expressed as a single double value)
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s])
) noexcept
[[nodiscard]] bool e57::time::gps_time_from_value(const double gps_time, //!< GPS time expressed as a single double value)
unsigned short& gps_week, //!< GPS week (0-1024+) [week]
double& gps_tow //!< GPS time of week (0-604800.0) [s])
) noexcept
{
if (gps_time <= 0.0)
{

View File

@@ -9,20 +9,20 @@ TEST_SUITE("API Date/Time Tests")
{
TEST_CASE("Tests the creation of GpsTime from week and tow works successfully")
{
const core::GpsTime gps_time(2191, 15.0);
const time::GpsTime gps_time(2191, 15.0);
REQUIRE_EQ(1325116815.0, gps_time.time);
}
TEST_CASE("Tests the creation of GpsTime works from time works successfully")
{
const core::GpsTime gps_time(1325116815.0);
const time::GpsTime gps_time(1325116815.0);
REQUIRE_EQ(2191, gps_time.week);
REQUIRE_EQ(15.0, gps_time.tow);
}
TEST_CASE("Tests the conversion to UTC Time from a given GPS Time")
{
const core::UtcTime utc_time = utils::utc_time_from_gps_time(core::GpsTime(2191, 15.0));
const time::UtcTime utc_time = time::utc_time_from_gps_time(time::GpsTime(2191, 15.0));
REQUIRE_EQ(2022, utc_time.year);
REQUIRE_EQ(1, utc_time.month);
REQUIRE_EQ(2, utc_time.day);

View File

@@ -20,7 +20,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned short gps_week{};
double gps_tow{};
REQUIRE_EQ(true, utils::current_system_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, utc_offset, julian_date, gps_week, gps_tow));
REQUIRE_EQ(true, time::current_system_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, utc_offset, julian_date, gps_week, gps_tow));
REQUIRE(utc_year >= 0);
REQUIRE(utc_month >= 1);
REQUIRE(utc_day >= 1);
@@ -37,7 +37,7 @@ TEST_SUITE("Date/Time Conversion Tests")
{
double julian_date{};
REQUIRE_EQ(true, utils::current_julian_date(julian_date));
REQUIRE_EQ(true, time::current_julian_date(julian_date));
REQUIRE(julian_date >= 0);
}
@@ -50,7 +50,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned char utc_minute{};
float utc_seconds{};
REQUIRE_EQ(true, utils::current_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE_EQ(true, time::current_utc_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE(utc_year >= 0);
REQUIRE(utc_month >= 1);
REQUIRE(utc_day >= 1);
@@ -64,7 +64,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned short gps_week{};
double gps_tow{};
REQUIRE_EQ(true, utils::current_gps_time(gps_week, gps_tow));
REQUIRE_EQ(true, time::current_gps_time(gps_week, gps_tow));
REQUIRE(gps_week >= 0);
REQUIRE(gps_tow >= 0);
}
@@ -74,7 +74,7 @@ TEST_SUITE("Date/Time Conversion Tests")
double julian_date{};
// This is the same as doing 2022-01-02 00:00:00
REQUIRE_EQ(true, utils::julian_date_from_utc_time(2022, 1, 1, 23, 59, 60, julian_date));
REQUIRE_EQ(true, time::julian_date_from_utc_time(2022, 1, 1, 23, 59, 60, julian_date));
REQUIRE_EQ(2459581.5, julian_date);
}
@@ -84,7 +84,7 @@ TEST_SUITE("Date/Time Conversion Tests")
double gps_tow{};
// This is the same as doing 2022-01-02 00:00:00
REQUIRE_EQ(true, utils::gps_time_from_utc_time(2022, 1, 1, 23, 59, 60, gps_week, gps_tow));
REQUIRE_EQ(true, time::gps_time_from_utc_time(2022, 1, 1, 23, 59, 60, gps_week, gps_tow));
REQUIRE_EQ(2191, gps_week);
REQUIRE_EQ(15.0, gps_tow);
}
@@ -99,7 +99,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned char utc_minute{};
float utc_seconds{};
REQUIRE_EQ(true, utils::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE_EQ(true, time::utc_time_from_julian_date(julian_date, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE_EQ(2022, utc_year);
REQUIRE_EQ(1, utc_month);
REQUIRE_EQ(2, utc_day);
@@ -116,7 +116,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned short gps_week{};
double gps_tow{};
REQUIRE_EQ(true, utils::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow));
REQUIRE_EQ(true, time::gps_time_from_julian_date(julian_date, utc_offset, gps_week, gps_tow));
REQUIRE_EQ(2191, gps_week);
REQUIRE_EQ(15.0, gps_tow);
}
@@ -128,7 +128,7 @@ TEST_SUITE("Date/Time Conversion Tests")
const unsigned char utc_offset{15};
double julian_date{};
REQUIRE_EQ(true, utils::julian_date_from_gps_time(gps_week, gps_tow, utc_offset, julian_date));
REQUIRE_EQ(true, time::julian_date_from_gps_time(gps_week, gps_tow, utc_offset, julian_date));
REQUIRE_EQ(2459581.5, julian_date);
}
@@ -143,7 +143,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned char utc_minute{};
float utc_seconds{};
REQUIRE_EQ(true, utils::utc_time_from_gps_time(gps_week, gps_tow, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE_EQ(true, time::utc_time_from_gps_time(gps_week, gps_tow, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds));
REQUIRE_EQ(2022, utc_year);
REQUIRE_EQ(1, utc_month);
REQUIRE_EQ(2, utc_day);
@@ -157,26 +157,26 @@ TEST_SUITE("Date/Time Conversion Tests")
const double julian_date{2459581.5};
unsigned char utc_offset{};
REQUIRE_EQ(true, utils::determine_utc_offset(julian_date, utc_offset));
REQUIRE_EQ(true, time::determine_utc_offset(julian_date, utc_offset));
REQUIRE_EQ(15, utc_offset);
}
TEST_CASE("Tests for Leap Year")
{
REQUIRE_EQ(false, utils::is_leap_year(2022));
REQUIRE_EQ(false, utils::is_leap_year(1399));
REQUIRE_EQ(true, utils::is_leap_year(2000));
REQUIRE_EQ(true, utils::is_leap_year(2004));
REQUIRE_EQ(false, time::is_leap_year(2022));
REQUIRE_EQ(false, time::is_leap_year(1399));
REQUIRE_EQ(true, time::is_leap_year(2000));
REQUIRE_EQ(true, time::is_leap_year(2004));
}
TEST_CASE("Tests for days in a month")
{
unsigned char days_in_month{};
REQUIRE_EQ(true, utils::number_days_in_month(2022, 2, days_in_month));
REQUIRE_EQ(true, time::number_days_in_month(2022, 2, days_in_month));
REQUIRE_EQ(28, days_in_month);
REQUIRE_EQ(true, utils::number_days_in_month(2000, 2, days_in_month));
REQUIRE_EQ(true, time::number_days_in_month(2000, 2, days_in_month));
REQUIRE_EQ(29, days_in_month);
}
@@ -184,10 +184,10 @@ TEST_SUITE("Date/Time Conversion Tests")
{
unsigned short day_of_year{};
REQUIRE_EQ(true, utils::day_of_year(2022, 1, 1, day_of_year));
REQUIRE_EQ(true, time::day_of_year(2022, 1, 1, day_of_year));
REQUIRE_EQ(1, day_of_year);
REQUIRE_EQ(true, utils::day_of_year(2022, 12, 31, day_of_year));
REQUIRE_EQ(true, time::day_of_year(2022, 12, 31, day_of_year));
REQUIRE_EQ(365, day_of_year);
}
@@ -196,7 +196,7 @@ TEST_SUITE("Date/Time Conversion Tests")
unsigned short gps_week{};
double gps_tow{};
REQUIRE_EQ(true, utils::gps_time_from_year_and_day_of_year(2022, 2, gps_week, gps_tow));
REQUIRE_EQ(true, time::gps_time_from_year_and_day_of_year(2022, 2, gps_week, gps_tow));
REQUIRE_EQ(2191, gps_week);
REQUIRE_EQ(15.0, gps_tow);

View File

@@ -27,8 +27,8 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <openE57/LAS/openE57las.h>
#include <openE57/api.h>
#include <openE57/openE57.h>
//#include <time_conversion/time_conversion.h> // code from Essential GNSS Project
#include <fstream> // std::ifstream
#include <iomanip>
@@ -52,9 +52,24 @@
using namespace std;
using namespace e57;
/// Define the following symbols to get various amounts of debug printing:
//#define E57_VERBOSE 1
//#define E57_MAX_VERBOSE 1
inline ustring exception_string(const char* errorName, const char* fileName, int lineNumber)
{
std::ostringstream ss;
ss << errorName << " at " << fileName << ":" << lineNumber;
return (ss.str());
}
/// Create whitespace of given length, for indenting printouts in dump() functions
inline std::string space(const size_t n)
{
return (std::string(n, ' '));
}
#define EXCEPTION(e_name) (std::runtime_error(exception_string((e_name), __FILE__, __LINE__)))
// Constants definition
constexpr const double SECONDS_IN_A_DAY = 86400.0;
constexpr const double SECONDS_IN_A_WEEK = SECONDS_IN_A_DAY * 7; // 604800.0
/// Declare local functions:
ustring guidUnparse(uint32_t data1, uint16_t data2, uint16_t data3, uint8_t data4[8]);
@@ -1114,13 +1129,16 @@ void copyPerScanData(CommandLineOptions& options, LASReader& lasf, ImageFile imf
/// Path name: "/data3D/0/acquisitionStart/dateTimeValue"
if (hdr.fileCreationDayOfYear > 0 && hdr.fileCreationYear > 0)
{
unsigned short year = static_cast<unsigned short>(hdr.fileCreationYear);
unsigned short dayOfYear = static_cast<unsigned short>(hdr.fileCreationDayOfYear);
unsigned short gpsWeek = 0;
double gpsTOW = 0.0;
if (!utils::gps_time_from_year_and_day_of_year(year, dayOfYear, gpsWeek, gpsTOW))
const unsigned short year = static_cast<unsigned short>(hdr.fileCreationYear);
const unsigned short dayOfYear = static_cast<unsigned short>(hdr.fileCreationDayOfYear);
const auto gpsTime = time::gps_time_from_year_and_day(year, dayOfYear);
if (gpsTime.week == 0 && gpsTime.tow == 0.0)
{
throw EXCEPTION("bad year,day");
double acquisitionStartGpsTime = gpsWeek * utils::SECONDS_IN_A_WEEK + gpsTOW;
}
const double acquisitionStartGpsTime = gpsTime.time;
StructureNode dateTimeStruct = StructureNode(imf);
scan0.set("acquisitionStart", dateTimeStruct);
dateTimeStruct.set("dateTimeValue", FloatNode(imf, acquisitionStartGpsTime, E57_DOUBLE));
@@ -1445,10 +1463,9 @@ void copyPerPointData(CommandLineOptions& options, LASReader& lasf, ImageFile im
/// We assume that the gps week is the one that contains the file creation day.
if (hdr.fileCreationDayOfYear > 0 && hdr.fileCreationYear > 0)
{
unsigned short gpsWeek = 0;
double gpsTOW = 0.0;
if (utils::gps_time_from_year_and_day_of_year(hdr.fileCreationYear, hdr.fileCreationDayOfYear, gpsWeek, gpsTOW))
lasTimeOffset = gpsWeek * utils::SECONDS_IN_A_WEEK;
const auto gpsTime = time::gps_time_from_year_and_day(hdr.fileCreationYear, hdr.fileCreationDayOfYear);
if (gpsTime.week != 0)
lasTimeOffset = gpsTime.week * SECONDS_IN_A_WEEK;
else
lasTimeOffset = 0.0;
}
@@ -1607,30 +1624,15 @@ void copyPerFileData(CommandLineOptions& /*options*/, LASReader& /*lasf*/, Image
root.set("versionMajor", IntegerNode(imf, astmMajor, 0, E57_UINT8_MAX));
root.set("versionMinor", IntegerNode(imf, astmMinor, 0, E57_UINT8_MAX));
/// Mark file with current GPS time (the time the file was opened for writing).
/// Path name: "/creationDateTime/dateTimeValue"
unsigned short utc_year; // Universal Time Coordinated [year]
unsigned char utc_month; // Universal Time Coordinated [1-12 months]
unsigned char utc_day; // Universal Time Coordinated [1-31 days]
unsigned char utc_hour; // Universal Time Coordinated [hours]
unsigned char utc_minute; // Universal Time Coordinated [minutes]
float utc_seconds; // Universal Time Coordinated [s]
unsigned char utc_offset; // Integer seconds that GPS is ahead of UTC time; always positive [s], obtained from a look up table
double julian_date; // Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned short gps_week; // GPS week (0-1024+) [week]
double gps_tow; // GPS time of week (0-604800.0) [s]
if (!utils::current_system_time(utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds, utc_offset, julian_date, gps_week, gps_tow))
throw EXCEPTION("Failed to retrieve current system time");
double gpsTime = gps_week * utils::SECONDS_IN_A_WEEK + gps_tow;
const auto gpsTime = time::current_gps_time();
if (gpsTime.week == 0 && gpsTime.tow == 0.0 && gpsTime.time == 0.0)
{
throw EXCEPTION("Failed to retrieve current GPS time");
}
StructureNode dateTimeStruct = StructureNode(imf);
root.set("creationDateTime", dateTimeStruct);
dateTimeStruct.set("dateTimeValue", FloatNode(imf, gpsTime, E57_DOUBLE));
#ifdef E57_MAX_VERBOSE
cout << "utc_year=" << utc_year << " utc_month=" << static_cast<unsigned>(utc_month) << " utc_day=" << static_cast<unsigned>(utc_day)
<< " utc_hour=" << static_cast<unsigned>(utc_hour) << " utc_minute=" << static_cast<unsigned>(utc_minute) << " utc_seconds=" << utc_seconds
<< " utc_offset=" << static_cast<unsigned>(utc_offset) << endl;
cout << "julian_date=" << julian_date << " gps_week=" << gps_week << " gps_tow=" << gps_tow << " gpsTime=" << gpsTime << endl;
#endif
dateTimeStruct.set("dateTimeValue", FloatNode(imf, gpsTime.time, E57_DOUBLE));
/// The guid in the LAS file uniquely ids the project, not the file.
/// The combination of the projectID and fileSourceId uniquely ids the original source, but this file might contain processed data.
@@ -1681,22 +1683,15 @@ ustring guidUnparse(uint32_t data1, uint16_t data2, uint16_t data3, uint8_t data
return (guid.str());
}
ustring gpsTimeUnparse(double gpsTime)
ustring gpsTimeUnparse(double gpsTimeInSeconds)
{
unsigned short gpsWeek = static_cast<unsigned short>(floor(gpsTime / utils::SECONDS_IN_A_WEEK));
double gpsTOW = gpsTime - gpsWeek * utils::SECONDS_IN_A_WEEK;
const time::GpsTime gpsTime(gpsTimeInSeconds);
const auto utcTime = time::utc_time_from_gps_time(gpsTime);
unsigned short utc_year; //!< Universal Time Coordinated [year]
unsigned char utc_month; //!< Universal Time Coordinated [1-12 months]
unsigned char utc_day; //!< Universal Time Coordinated [1-31 days]
unsigned char utc_hour; //!< Universal Time Coordinated [hours]
unsigned char utc_minute; //!< Universal Time Coordinated [minutes]
float utc_seconds; //!< Universal Time Coordinated [s]
ostringstream ss;
if (utils::utc_time_from_gps_time(gpsWeek, gpsTOW, utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds))
std::ostringstream ss;
if (utcTime.year != 0)
{
ss << utc_year << "-" << (unsigned)utc_month << "-" << (unsigned)utc_day << " " << (unsigned)utc_hour << ":" << (unsigned)utc_minute << ":" << utc_seconds;
ss << utcTime.year << "-" << utcTime.month << "-" << utcTime.day << " " << utcTime.hour << ":" << utcTime.minute << ":" << utcTime.seconds;
return (ss.str());
}
else