public override void read(laszip_point item)
        {
            for (uint i = 0; i < number; i++)
            {
                int value = (int)(last_item[i] + dec.decodeSymbol(m_byte[i]));
                item.extra_bytes[i] = (byte)MyDefs.U8_FOLD(value);
            }

            Buffer.BlockCopy(item.extra_bytes, 0, last_item, 0, (int)number);
        }
Exemplo n.º 2
0
        public override bool write(laszip_point item)
        {
            for (uint i = 0; i < number; i++)
            {
                int diff = item.extra_bytes[i] - last_item[i];
                enc.encodeSymbol(m_byte[i], (byte)MyDefs.U8_FOLD(diff));
            }

            Buffer.BlockCopy(item.extra_bytes, 0, last_item, 0, (int)number);
            return(true);
        }
Exemplo n.º 3
0
        public override bool write(laszip_point item)
        {
            int diff_l = 0;
            int diff_h = 0;

            uint sym = 0;

            bool rl = (last_item[0] & 0x00FF) != (item.rgb[0] & 0x00FF); if (rl)
            {
                sym |= 1;
            }
            bool rh = (last_item[0] & 0xFF00) != (item.rgb[0] & 0xFF00); if (rh)
            {
                sym |= 2;
            }
            bool gl = (last_item[1] & 0x00FF) != (item.rgb[1] & 0x00FF); if (gl)
            {
                sym |= 4;
            }
            bool gh = (last_item[1] & 0xFF00) != (item.rgb[1] & 0xFF00); if (gh)
            {
                sym |= 8;
            }
            bool bl = (last_item[2] & 0x00FF) != (item.rgb[2] & 0x00FF); if (bl)
            {
                sym |= 16;
            }
            bool bh = (last_item[2] & 0xFF00) != (item.rgb[2] & 0xFF00); if (bh)
            {
                sym |= 32;
            }

            bool allColors = ((item.rgb[0] & 0x00FF) != (item.rgb[1] & 0x00FF)) || ((item.rgb[0] & 0x00FF) != (item.rgb[2] & 0x00FF)) ||
                             ((item.rgb[0] & 0xFF00) != (item.rgb[1] & 0xFF00)) || ((item.rgb[0] & 0xFF00) != (item.rgb[2] & 0xFF00));

            if (allColors)
            {
                sym |= 64;
            }

            enc.encodeSymbol(m_byte_used, sym);
            if (rl)
            {
                diff_l = ((int)(item.rgb[0] & 255)) - (last_item[0] & 255);
                enc.encodeSymbol(m_rgb_diff_0, (byte)MyDefs.U8_FOLD(diff_l));
            }
            if (rh)
            {
                diff_h = ((int)(item.rgb[0] >> 8)) - (last_item[0] >> 8);
                enc.encodeSymbol(m_rgb_diff_1, (byte)MyDefs.U8_FOLD(diff_h));
            }

            if (allColors)
            {
                if (gl)
                {
                    int corr = ((int)(item.rgb[1] & 255)) - MyDefs.U8_CLAMP(diff_l + (last_item[1] & 255));
                    enc.encodeSymbol(m_rgb_diff_2, (byte)MyDefs.U8_FOLD(corr));
                }
                if (bl)
                {
                    diff_l = (diff_l + (item.rgb[1] & 255) - (last_item[1] & 255)) / 2;
                    int corr = ((int)(item.rgb[2] & 255)) - MyDefs.U8_CLAMP(diff_l + (last_item[2] & 255));
                    enc.encodeSymbol(m_rgb_diff_4, (byte)MyDefs.U8_FOLD(corr));
                }
                if (gh)
                {
                    int corr = ((int)(item.rgb[1] >> 8)) - MyDefs.U8_CLAMP(diff_h + (last_item[1] >> 8));
                    enc.encodeSymbol(m_rgb_diff_3, (byte)MyDefs.U8_FOLD(corr));
                }
                if (bh)
                {
                    diff_h = (diff_h + (item.rgb[1] >> 8) - (last_item[1] >> 8)) / 2;
                    int corr = ((int)(item.rgb[2] >> 8)) - MyDefs.U8_CLAMP(diff_h + (last_item[2] >> 8));
                    enc.encodeSymbol(m_rgb_diff_5, (byte)MyDefs.U8_FOLD(corr));
                }
            }

            last_item[0] = item.rgb[0];
            last_item[1] = item.rgb[1];
            last_item[2] = item.rgb[2];

            return(true);
        }
        public override void read(laszip_point item)
        {
            int corr;
            int diff = 0;

            uint sym = dec.decodeSymbol(m_byte_used);

            if ((sym & (1 << 0)) != 0)
            {
                corr        = (int)dec.decodeSymbol(m_rgb_diff_0);
                item.rgb[0] = (ushort)MyDefs.U8_FOLD(corr + (last_item[0] & 255));
            }
            else
            {
                item.rgb[0] = (ushort)(last_item[0] & 0xFF);
            }

            if ((sym & (1 << 1)) != 0)
            {
                corr         = (int)dec.decodeSymbol(m_rgb_diff_1);
                item.rgb[0] |= (ushort)((MyDefs.U8_FOLD(corr + (last_item[0] >> 8))) << 8);
            }
            else
            {
                item.rgb[0] |= (ushort)(last_item[0] & 0xFF00);
            }

            if ((sym & (1 << 6)) != 0)
            {
                diff = (item.rgb[0] & 0x00FF) - (last_item[0] & 0x00FF);
                if ((sym & (1 << 2)) != 0)
                {
                    corr        = (int)dec.decodeSymbol(m_rgb_diff_2);
                    item.rgb[1] = (ushort)MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[1] & 255)));
                }
                else
                {
                    item.rgb[1] = (ushort)(last_item[1] & 0xFF);
                }

                if ((sym & (1 << 4)) != 0)
                {
                    corr        = (int)dec.decodeSymbol(m_rgb_diff_4);
                    diff        = (diff + ((item.rgb[1] & 0x00FF) - (last_item[1] & 0x00FF))) / 2;
                    item.rgb[2] = (ushort)MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[2] & 255)));
                }
                else
                {
                    item.rgb[2] = (ushort)(last_item[2] & 0xFF);
                }

                diff = (item.rgb[0] >> 8) - (last_item[0] >> 8);
                if ((sym & (1 << 3)) != 0)
                {
                    corr         = (int)dec.decodeSymbol(m_rgb_diff_3);
                    item.rgb[1] |= (ushort)((MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[1] >> 8)))) << 8);
                }
                else
                {
                    item.rgb[1] |= (ushort)(last_item[1] & 0xFF00);
                }

                if ((sym & (1 << 5)) != 0)
                {
                    corr         = (int)dec.decodeSymbol(m_rgb_diff_5);
                    diff         = (diff + ((item.rgb[1] >> 8) - (last_item[1] >> 8))) / 2;
                    item.rgb[2] |= (ushort)((MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[2] >> 8)))) << 8);
                }
                else
                {
                    item.rgb[2] |= (ushort)(last_item[2] & 0xFF00);
                }
            }
            else
            {
                item.rgb[1] = item.rgb[0];
                item.rgb[2] = item.rgb[0];
            }

            last_item[0] = item.rgb[0];
            last_item[1] = item.rgb[1];
            last_item[2] = item.rgb[2];
        }
Exemplo n.º 5
0
        public override bool write(laszip_point item)
        {
            uint r = item.return_number;
            uint n = item.number_of_returns_of_given_pulse;
            uint m = Laszip_Common_v2.number_return_map[n, r];
            uint l = Laszip_Common_v2.number_return_level[n, r];

            // compress which other values have changed
            uint changed_values = 0;

            bool needFlags = last.flags != item.flags; if (needFlags)
            {
                changed_values |= 32;                                                            // bit_byte
            }
            bool needIntensity = last_intensity[m] != item.intensity; if (needIntensity)
            {
                changed_values |= 16;
            }
            bool needClassification = last.classification != item.classification; if (needClassification)
            {
                changed_values |= 8;
            }
            bool needScanAngleRank = last.scan_angle_rank != item.scan_angle_rank; if (needScanAngleRank)
            {
                changed_values |= 4;
            }
            bool needUserData = last.user_data != item.user_data; if (needUserData)
            {
                changed_values |= 2;
            }
            bool needPointSourceID = last.point_source_ID != item.point_source_ID; if (needPointSourceID)

            {
                changed_values |= 1;
            }

            enc.encodeSymbol(m_changed_values, changed_values);

            // compress the bit_byte (edge_of_flight_line, scan_direction_flag, returns, ...) if it has changed
            if (needFlags)
            {
                if (m_bit_byte[last.flags] == null)
                {
                    m_bit_byte[last.flags] = enc.createSymbolModel(256);
                    enc.initSymbolModel(m_bit_byte[last.flags]);
                }
                enc.encodeSymbol(m_bit_byte[last.flags], item.flags);
            }

            // compress the intensity if it has changed
            if (needIntensity)
            {
                ic_intensity.compress(last_intensity[m], item.intensity, (m < 3?m:3u));
                last_intensity[m] = item.intensity;
            }

            // compress the classification ... if it has changed
            if (needClassification)
            {
                if (m_classification[last.classification] == null)
                {
                    m_classification[last.classification] = enc.createSymbolModel(256);
                    enc.initSymbolModel(m_classification[last.classification]);
                }
                enc.encodeSymbol(m_classification[last.classification], item.classification);
            }

            // compress the scan_angle_rank ... if it has changed
            if (needScanAngleRank)
            {
                enc.encodeSymbol(m_scan_angle_rank[item.scan_direction_flag], (uint)MyDefs.U8_FOLD(item.scan_angle_rank - last.scan_angle_rank));
            }

            // compress the user_data ... if it has changed
            if (needUserData)
            {
                if (m_user_data[last.user_data] == null)
                {
                    m_user_data[last.user_data] = enc.createSymbolModel(256);
                    enc.initSymbolModel(m_user_data[last.user_data]);
                }
                enc.encodeSymbol(m_user_data[last.user_data], item.user_data);
            }

            // compress the point_source_ID ... if it has changed
            if (needPointSourceID)
            {
                ic_point_source_ID.compress(last.point_source_ID, item.point_source_ID);
            }

            // compress x coordinate
            int median = last_x_diff_median5[m].get();
            int diff   = item.X - last.x;

            ic_dx.compress(median, diff, n == 1?1u:0u);
            last_x_diff_median5[m].add(diff);

            // compress y coordinate
            uint k_bits = ic_dx.getK();

            median = last_y_diff_median5[m].get();
            diff   = item.Y - last.y;
            ic_dy.compress(median, diff, (n == 1?1u:0u) + (k_bits < 20?k_bits & 0xFEu:20u));     // &0xFE round k_bits to next even number
            last_y_diff_median5[m].add(diff);

            // compress z coordinate
            k_bits = (ic_dx.getK() + ic_dy.getK()) / 2;
            ic_z.compress(last_height[l], item.Z, (n == 1?1u:0u) + (k_bits < 18?k_bits & 0xFEu:18u));     // &0xFE round k_bits to next even number
            last_height[l] = item.Z;

            // copy the last point
            last.x               = item.X;
            last.y               = item.Y;
            last.z               = item.Z;
            last.intensity       = item.intensity;
            last.flags           = item.flags;
            last.classification  = item.classification;
            last.scan_angle_rank = item.scan_angle_rank;
            last.user_data       = item.user_data;
            last.point_source_ID = item.point_source_ID;

            return(true);
        }