MCPcopy Create free account
hub / github.com/LAStools/LAStools / write_gps_time

Method write_gps_time

LASzip/src/laswriteitemcompressed_v3.cpp:975–1118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

973}
974
975void LASwriteItemCompressed_POINT14_v3::write_gps_time(const U64I64F64 gps_time)
976{
977 if (contexts[current_context].last_gpstime_diff[contexts[current_context].last] == 0) // if the last integer difference was zero
978 {
979 // calculate the difference between the two doubles as an integer
980 I64 curr_gpstime_diff_64 = gps_time.i64 - contexts[current_context].last_gpstime[contexts[current_context].last].i64;
981 I32 curr_gpstime_diff = (I32)curr_gpstime_diff_64;
982 if (curr_gpstime_diff_64 == (I64)(curr_gpstime_diff))
983 {
984 enc_gps_time->encodeSymbol(contexts[current_context].m_gpstime_0diff, 0); // the difference can be represented with 32 bits
985 contexts[current_context].ic_gpstime->compress(0, curr_gpstime_diff, 0);
986 contexts[current_context].last_gpstime_diff[contexts[current_context].last] = curr_gpstime_diff;
987 contexts[current_context].multi_extreme_counter[contexts[current_context].last] = 0;
988 }
989 else // the difference is huge
990 {
991 U32 i;
992 // maybe the double belongs to another time sequence
993 for (i = 1; i < 4; i++)
994 {
995 I64 other_gpstime_diff_64 = gps_time.i64 - contexts[current_context].last_gpstime[(contexts[current_context].last+i)&3].i64;
996 I32 other_gpstime_diff = (I32)other_gpstime_diff_64;
997 if (other_gpstime_diff_64 == (I64)(other_gpstime_diff))
998 {
999 enc_gps_time->encodeSymbol(contexts[current_context].m_gpstime_0diff, i+1); // it belongs to another sequence
1000 contexts[current_context].last = (contexts[current_context].last+i)&3;
1001 write_gps_time(gps_time);
1002 return;
1003 }
1004 }
1005 // no other sequence found. start new sequence.
1006 enc_gps_time->encodeSymbol(contexts[current_context].m_gpstime_0diff, 1);
1007 contexts[current_context].ic_gpstime->compress((I32)(contexts[current_context].last_gpstime[contexts[current_context].last].u64 >> 32), (I32)(gps_time.u64 >> 32), 8);
1008 enc_gps_time->writeInt((U32)(gps_time.u64));
1009 contexts[current_context].next = (contexts[current_context].next+1)&3;
1010 contexts[current_context].last = contexts[current_context].next;
1011 contexts[current_context].last_gpstime_diff[contexts[current_context].last] = 0;
1012 contexts[current_context].multi_extreme_counter[contexts[current_context].last] = 0;
1013 }
1014 contexts[current_context].last_gpstime[contexts[current_context].last].i64 = gps_time.i64;
1015 }
1016 else // the last integer difference was *not* zero
1017 {
1018 // calculate the difference between the two doubles as an integer
1019 I64 curr_gpstime_diff_64 = gps_time.i64 - contexts[current_context].last_gpstime[contexts[current_context].last].i64;
1020 I32 curr_gpstime_diff = (I32)curr_gpstime_diff_64;
1021
1022 // if the current gpstime difference can be represented with 32 bits
1023 if (curr_gpstime_diff_64 == (I64)(curr_gpstime_diff))
1024 {
1025 // compute multiplier between current and last integer difference
1026 F32 multi_f = (F32)curr_gpstime_diff / (F32)(contexts[current_context].last_gpstime_diff[contexts[current_context].last]);
1027 I32 multi = I32_QUANTIZE(multi_f);
1028
1029 // compress the residual curr_gpstime_diff in dependance on the multiplier
1030 if (multi == 1)
1031 {
1032 // this is the case we assume we get most often for regular spaced pulses

Callers

nothing calls this directly

Calls 3

compressMethod · 0.80
encodeSymbolMethod · 0.45
writeIntMethod · 0.45

Tested by

no test coverage detected