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

Method write_gps_time

LASzip/src/laswriteitemcompressed_v4.cpp:972–1115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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