Example #1
0
 public static System.Drawing.Color ToColor(this C3us color)
 {
     return(System.Drawing.Color.FromArgb(
                Col.ByteFromUShort(color.R),
                Col.ByteFromUShort(color.G),
                Col.ByteFromUShort(color.B)));
 }
Example #2
0
        private static IEnumerable <Points> ReadPoints(laszip_dll reader, int numberOfPointsPerChunk, bool verbose)
        {
            var n = reader.header.number_of_point_records;
            //var numberOfChunks = n / numberOfPointsPerChunk;

            var format        = reader.header.point_data_format;
            var hasGpsTime    = format == 1 || format == 3 || format == 4 || format == 5;
            var hasColor      = format == 2 || format == 3 || format == 5;
            var hasWavePacket = format == 4 || format == 5;

            for (var j = 0; j < n; j += numberOfPointsPerChunk)
            {
                if (j + numberOfPointsPerChunk > n)
                {
                    numberOfPointsPerChunk = (int)(n - j);
                }
                if (verbose)
                {
                    Console.WriteLine($"j: {j}, numberOfPointsPerChunk: {numberOfPointsPerChunk}, n: {n}");
                }

                // POINT10
                var p                       = new double[3];
                var ps                      = new V3d[numberOfPointsPerChunk];
                var intensities             = new ushort[numberOfPointsPerChunk];
                var returnNumbers           = new byte[numberOfPointsPerChunk];
                var numberOfReturnsOfPulses = new byte[numberOfPointsPerChunk];
                var scanDirectionFlags      = new BitArray(numberOfPointsPerChunk);
                var edgeOfFlightLines       = new BitArray(numberOfPointsPerChunk);
                var classifications         = new byte[numberOfPointsPerChunk];
                var scanAngleRanks          = new byte[numberOfPointsPerChunk];
                var userDatas               = new byte[numberOfPointsPerChunk];
                var pointSourceIds          = new ushort[numberOfPointsPerChunk];

                // GPSTIME10
                var gpsTimes = hasGpsTime ? new double[numberOfPointsPerChunk] : null;

                // RGB12
                var  colorsRaw   = hasColor ? new C3us[numberOfPointsPerChunk] : null;
                bool colorIs8Bit = true;

                // WAVEPACKET13
                var wavePacketDescriptorIndices  = hasWavePacket ? new byte[numberOfPointsPerChunk] : null;
                var bytesOffsetToWaveformDatas   = hasWavePacket ? new ulong[numberOfPointsPerChunk] : null;
                var waveformPacketSizesInBytes   = hasWavePacket ? new uint[numberOfPointsPerChunk] : null;
                var returnPointWaveformLocations = hasWavePacket ? new float[numberOfPointsPerChunk] : null;
                var xts = hasWavePacket ? new float[numberOfPointsPerChunk] : null;
                var yts = hasWavePacket ? new float[numberOfPointsPerChunk] : null;
                var zts = hasWavePacket ? new float[numberOfPointsPerChunk] : null;

                for (var i = 0; i < numberOfPointsPerChunk; i++)
                {
                    reader.laszip_read_point();

                    reader.laszip_get_coordinates(p);
                    ps[i]                      = new V3d(p);
                    intensities[i]             = reader.point.intensity;
                    returnNumbers[i]           = reader.point.return_number;
                    numberOfReturnsOfPulses[i] = reader.point.number_of_returns_of_given_pulse;
                    scanDirectionFlags[i]      = reader.point.scan_direction_flag != 0;
                    edgeOfFlightLines[i]       = reader.point.edge_of_flight_line != 0;
                    classifications[i]         = reader.point.classification;
                    scanAngleRanks[i]          = (byte)reader.point.scan_angle_rank;
                    userDatas[i]               = reader.point.user_data;
                    pointSourceIds[i]          = reader.point.point_source_ID;

                    if (hasGpsTime)
                    {
                        gpsTimes[i] = reader.point.gps_time;
                    }

                    if (hasColor)
                    {
                        var c = new C3us(reader.point.rgb[0], reader.point.rgb[1], reader.point.rgb[2]);
                        colorsRaw[i] = c;
                        if (colorIs8Bit && (c.R > 255 || c.G > 255 || c.B > 255))
                        {
                            colorIs8Bit = false;
                        }
                    }

                    if (hasWavePacket)
                    {
                        var buffer = reader.point.wave_packet;
                        wavePacketDescriptorIndices[i]  = buffer[0];
                        bytesOffsetToWaveformDatas[i]   = BitConverter.ToUInt64(buffer, 1);
                        waveformPacketSizesInBytes[i]   = BitConverter.ToUInt32(buffer, 9);
                        returnPointWaveformLocations[i] = BitConverter.ToSingle(buffer, 13);
                        xts[i] = BitConverter.ToSingle(buffer, 17);
                        yts[i] = BitConverter.ToSingle(buffer, 21);
                        zts[i] = BitConverter.ToSingle(buffer, 25);
                    }
                }

                var colors = (colorsRaw, colorIs8Bit) switch
                {
                    (null, _) => null,
                    (not null, true) => colorsRaw.Map(c => new C3b(c.R, c.G, c.B)),
                    (not null, false) => colorsRaw.Map(c => new C3b(c.R >> 8, c.G >> 8, c.B >> 8))
                };

                //if (verbose)
                //{
                //    if (ps?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] positions");
                //    if (intensities?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] intensities");
                //    if (returnNumbers?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] returnNumbers");
                //    if (numberOfReturnsOfPulses?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] numberOfReturnsOfPulses");
                //    if (classifications?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] classifications");
                //    if (scanAngleRanks?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] scanAngleRanks");
                //    if (userDatas?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] userDatas");
                //    if (pointSourceIds?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] pointSourceIds");
                //    if (gpsTimes?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] gpsTimes");
                //    if (colors?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] colors");
                //    if (wavePacketDescriptorIndices?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] wavePacketDescriptorIndices");
                //    if (bytesOffsetToWaveformDatas?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] bytesOffsetToWaveformDatas");
                //    if (waveformPacketSizesInBytes?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] waveformPacketSizesInBytes");
                //    if (returnPointWaveformLocations?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] returnPointWaveformLocations");
                //    if (xts?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] xts");
                //    if (yts?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] yts");
                //    if (zts?.Distinct()?.Count() > 1) Report.WarnNoPrefix("[Laszip.ReadPoints] zts");
                //}

                yield return(new Points
                {
                    Positions = ps,
                    Intensities = intensities,
                    ReturnNumbers = returnNumbers,
                    NumberOfReturnsOfPulses = numberOfReturnsOfPulses,
                    ScanDirectionFlags = scanDirectionFlags,
                    EdgeOfFlightLines = edgeOfFlightLines,
                    Classifications = classifications,
                    ScanAngleRanks = scanAngleRanks,
                    UserDatas = userDatas,
                    PointSourceIds = pointSourceIds,

                    GpsTimes = gpsTimes,

                    Colors = colors,

                    WavePacketDescriptorIndices = wavePacketDescriptorIndices,
                    BytesOffsetToWaveformDatas = bytesOffsetToWaveformDatas,
                    WaveformPacketSizesInBytes = waveformPacketSizesInBytes,
                    ReturnPointWaveformLocations = returnPointWaveformLocations,
                    Xts = xts,
                    Yts = yts,
                    Zts = zts
                });
            }

            reader.laszip_close_reader();
        }
 public void Write(C3us c)
 {
     Write(c.R); Write(c.G); Write(c.B);
 }
 /// <summary>
 /// C3us to System.Drawing.Color.
 /// </summary>
 public static Color ToColor(this C3us color) => Color.FromArgb(
     Col.ByteFromUShort(color.R),
     Col.ByteFromUShort(color.G),
     Col.ByteFromUShort(color.B));