Пример #1
0
        //-----------------------------------------------------------------------------

        public LasPoint2[] GetPointsByTile(String prmInput, Int32 prmRow, Int32 prmCol)
        {
            String blockFile = String.Format(@"{0}\{1}.xml", Path.GetDirectoryName(prmInput), Path.GetFileNameWithoutExtension(prmInput));
            TcTileBlockInfoCollection tileInfoCollection = TcTileUtils.GetTileBlocks(blockFile);

            IEnumerable <TcTileBlockInfo> blocks = tileInfoCollection.TileBlocks.Where(iter => iter.Row == prmRow && iter.Col == prmCol);
            Int32 numberOfPoints = blocks.Aggregate(0, (result, iter) => result += iter.NoOfPoints);

            using (TcLasReader reader = new TcLasReader(prmInput))
            {
                LasHeader   header     = reader.GetHeaderOld();
                LasPoint2[] points     = new LasPoint2[numberOfPoints];
                Int32       arrayStart = 0;
                foreach (TcTileBlockInfo info in blocks)
                {
                    if (reader.GetLasBlock(ref points, arrayStart, info.StartPoint, info.NoOfPoints, header))
                    {
                        arrayStart += info.NoOfPoints;
                    }
                    else
                    {
                        throw new Exception(String.Format("Couldn't read the las tile ({0},{1})", prmRow, prmCol));
                    }
                }
                return(points);
            }
        }
Пример #2
0
        public Form2(LasHeader lasHeader)
        {
            InitializeComponent();
            Text = "InfoBox - " + lasHeader.LasFile.Filename;
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.AppendLine(string.Format("Version LAS File: {0}.{1}", lasHeader.VersionMajor,
                                                lasHeader.VersionMinor));
            strBuilder.AppendLine("System Identifier: " + lasHeader.SystemIdentifier);
            strBuilder.AppendLine("Generating Software: " + lasHeader.GeneratingSoftware);
            strBuilder.AppendLine(string.Format("Number of point record : {0}", lasHeader.NumberOfPointRecords));
            strBuilder.AppendLine(string.Format("Point record format : Format {0}", (int)lasHeader.PointDataFormatId));
            strBuilder.AppendLine(string.Format("Point record length : {0}", lasHeader.PointDataRecordLength));
            strBuilder.AppendLine("Number of points by return: ");
            for (int i = 0; i < lasHeader.NumberOfPointsByReturn.Length; i++)
            {
                strBuilder.AppendLine(string.Format("\tReturn {0} - {1}", i, lasHeader.NumberOfPointsByReturn[i]));
            }
            strBuilder.AppendLine(string.Format("MinX, MaxX - {0}, {1}", lasHeader.MinX, lasHeader.MaxX));
            strBuilder.AppendLine(string.Format("MinY, MaxY - {0}, {1}", lasHeader.MinY, lasHeader.MaxY));
            strBuilder.AppendLine(string.Format("MinZ, MaxZ - {0}, {1}", lasHeader.MinZ, lasHeader.MaxZ));
            strBuilder.AppendLine(string.Format("Scale Factor X - {0}", lasHeader.ScaleFactorX));
            strBuilder.AppendLine(string.Format("Scale Factor Y - {0}", lasHeader.ScaleFactorY));
            strBuilder.AppendLine(string.Format("Scale Factor Z - {0}", lasHeader.ScaleFactorZ));
            strBuilder.AppendLine(string.Format("Offset X - {0}", lasHeader.OffsetX));
            strBuilder.AppendLine(string.Format("Offset Y - {0}", lasHeader.OffsetY));
            strBuilder.AppendLine(string.Format("Offset Z - {0}", lasHeader.OffsetZ));

            infoTextBox.Text += strBuilder;
        }
Пример #3
0
        //-----------------------------------------------------------------------------

        private void UpdateTileCounts(LasHeader prmHeader, Int32 prmSize)
        {
            prmHeader.MinX = prmHeader.MinX - (prmHeader.MinX % (prmSize * m_Factor));
            prmHeader.MinY = prmHeader.MinY - (prmHeader.MinY % (prmSize * m_Factor));
            prmHeader.MaxX = prmHeader.MaxX - (prmHeader.MaxX % (prmSize * m_Factor)) + (prmSize * m_Factor);
            prmHeader.MaxY = prmHeader.MaxY - (prmHeader.MaxY % (prmSize * m_Factor)) + (prmSize * m_Factor);

            m_RevisedEast  = (Int32)prmHeader.MinX;
            m_RevisedNorth = (Int32)prmHeader.MaxY;
            m_TileColumns  = (Int32)(prmHeader.MaxX - prmHeader.MinX) / (prmSize * m_Factor);
            m_TileRows     = (Int32)(prmHeader.MaxY - prmHeader.MinY) / (prmSize * m_Factor);

            m_TileBlockInfoCollection = new TcTileBlockInfoCollection(prmSize, m_TileRows, m_TileColumns);
        }
Пример #4
0
 public LasPointProcessor(string filePath) : base(filePath)
 {
     header = ReadHeader();
 }
        unsafe bool LasConvert(AssetImportContext context, byte *ptr, int stride, int count, ref LasHeader header, PointCloudBounds bounds, PointCloudPoint *points)
        {
            var name = Path.GetFileName(context.assetPath);

            var counts = new NativeArray <int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob);

            try
            {
                double scaleX, scaleY, scaleZ;
                double centerX, centerY, centerZ;

                if (Normalize)
                {
                    centerX = -0.5 * (bounds.MaxX + bounds.MinX);
                    centerY = -0.5 * (bounds.MaxY + bounds.MinY);
                    centerZ = -0.5 * (bounds.MaxZ + bounds.MinZ);

                    scaleX = 2.0 / (bounds.MaxX - bounds.MinX);
                    scaleY = 2.0 / (bounds.MaxY - bounds.MinY);
                    scaleZ = 2.0 / (bounds.MaxZ - bounds.MinZ);
                }
                else if (Center)
                {
                    centerX = -0.5 * (bounds.MaxX + bounds.MinX);
                    centerY = -0.5 * (bounds.MaxY + bounds.MinY);
                    centerZ = -0.5 * (bounds.MaxZ + bounds.MinZ);

                    scaleX = scaleY = scaleZ = 1.0;
                }
                else
                {
                    centerX = centerY = centerZ = 0.0;

                    scaleX = scaleY = scaleZ = 1.0;
                }

                var job = new LasConvertJob()
                {
                    LasRGB8BitWorkaround = LasRGB8BitWorkaround,
                    Input     = ptr,
                    Stride    = stride,
                    Output    = points,
                    Transform = GetTransform(),

                    InputScaleX = header.ScaleX,
                    InputScaleY = header.ScaleY,
                    InputScaleZ = header.ScaleZ,

                    InputOffsetX = header.OffsetX,
                    InputOffsetY = header.OffsetY,
                    InputOffsetZ = header.OffsetZ,

                    OutputCenterX = centerX,
                    OutputCenterY = centerY,
                    OutputCenterZ = centerZ,

                    OutputScaleX = scaleX,
                    OutputScaleY = scaleY,
                    OutputScaleZ = scaleZ,

                    Counts      = (int *)counts.GetUnsafePtr(),
                    ThreadIndex = 0,
                };

                bool hasColor = false;

                if (header.PointDataFormat == 2)
                {
                    job.ColorInput = ptr + 20;
                    hasColor       = true;
                }
                else if (header.PointDataFormat == 3 || header.PointDataFormat == 5)
                {
                    job.ColorInput = ptr + 28;
                    hasColor       = true;
                }
                else if (header.PointDataFormat == 7 || header.PointDataFormat == 8 || header.PointDataFormat == 10)
                {
                    job.ColorInput = ptr + 30;
                    hasColor       = true;
                }

                var h = job.Schedule((int)count, 65536);
                while (!h.IsCompleted)
                {
                    System.Threading.Thread.Sleep(100);

                    int   processed = counts.Sum();
                    float progress  = (float)((double)processed / count);
                    EditorUtility.DisplayProgressBar($"Importing {name}", $"{processed:N0} points", progress);
                }

                return(hasColor);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                counts.Dispose();
            }
        }
Пример #6
0
        //-----------------------------------------------------------------------------

        public void Tile(String prmInput, String prmOutput)
        {
            // Variables to be used inside the big loop.
            LasPoint2 point;
            // Int32 east, north, col, row;
            Int32 tileOffset      = 0;
            Int32 index           = -1;
            Int32 pointsProcessed = 0;

            using (TcLasReader reader = new TcLasReader(prmInput))
            {
                LasHeader header = reader.GetHeaderOld();
                UpdateTileCounts(header, m_TileSize);

                String blockFile = String.Format(@"{0}\{1}.xml", Path.GetDirectoryName(prmOutput), Path.GetFileNameWithoutExtension(prmOutput));
                if (File.Exists(blockFile))
                {
                    File.Delete(blockFile);
                }

                using (TcLasWriter writer = new TcLasWriter(prmOutput))
                {
                    header.MinX = m_RevisedEast;
                    header.MaxY = m_RevisedNorth;

                    writer.WriteHeader(header);
                    Int32 onePercent = header.NumberOfPointRecords / 100;

                    for (int i = 0; i < header.NumberOfPointRecords; i++)
                    {
                        point = reader.ReadPoint(header);
                        if (point.X <= 0 || point.Y <= 0)
                        {
                            continue;
                        }

                        // Calculate the tile index for the point.
                        tileOffset = m_TileSize * m_Factor;

/*
 *                      east = Convert.ToInt32(point.X - (point.X % tileOffset));
 *                      north = Convert.ToInt32(point.Y - (point.Y % tileOffset)) + tileOffset;
 *                      col = (east - m_RevisedEast) / tileOffset;
 *                      row = (m_RevisedNorth - north) / tileOffset;
 */
                        Int32[] rowCol = TcMathUtil.GetRowCol(point.X, point.Y, m_RevisedEast, m_RevisedNorth, tileOffset, tileOffset);
                        index = rowCol[1] * m_TileRows + rowCol[0];

                        // Add that into the intermediate tile block.
                        if (!m_TileBlocks.ContainsKey(index))
                        {
                            m_TileBlocks[index]      = new LasPoint2[m_TileBlockSize];
                            m_BlockPointCount[index] = 0;
                        }

                        m_TileBlocks[index][m_BlockPointCount[index]] = point;
                        m_BlockPointCount[index]++;

                        // When a tile block is full, write into file and remove the points.
                        if (m_BlockPointCount[index] == m_TileBlockSize)
                        {
                            writer.WritePoints(m_TileBlocks[index], header, m_TileBlockSize);
                            ProcessTileBlock(rowCol[0], rowCol[1], index, pointsProcessed);
                            pointsProcessed += m_TileBlockSize;
                        }

                        if (i % onePercent == 0)
                        {
                            NotifyTileProgress(prmInput, prmOutput, rowCol[0], rowCol[1], pointsProcessed, i / onePercent);
                        }
                    }

                    // Process the remaining blocks with incomplete size.
                    int row, col;
                    foreach (Int32 idx in m_TileBlocks.Keys.ToList())
                    {
                        row = idx % m_TileRows;
                        col = (idx - row) / m_TileRows;

                        writer.WritePoints(m_TileBlocks[idx], header, m_BlockPointCount[idx]);
                        ProcessTileBlock(row, col, idx, pointsProcessed);
                        pointsProcessed += m_BlockPointCount[idx];
                    }

                    TcTileUtils.SaveTileBlocks(m_TileBlockInfoCollection, blockFile);
                }
            }
        }