Exemplo n.º 1
0
        //-----------------------------------------------------------------------------

        /// <summary>
        /// Function that update the grid with given points from a LAS tile block.
        /// </summary>
        /// <param name="prmObj">Gridding data object</param>
        /// <param name="prmInfo">Information of the LAS block</param>
        /// <param name="prmPoints">Collection of LAS points</param>
        private void UpdateGrid(TcGridObject prmObj, TcTileBlockInfo prmInfo, TcLasPointBase[] prmPoints)
        {
            Dictionary <Int32, List <TcLasPointBase> > gridPointCollection = new Dictionary <Int32, List <TcLasPointBase> >(prmObj.GridCount * prmObj.GridCount);
            Int32 row, col, index;

            Int32[] rowCol = new Int32[2];
            //Boolean[] availableIndices = new Boolean[(Int32)Math.Pow((Int32)(prmObj.Info.TileInfo.Row * prmObj.Info.TileInfo.Col * (prmObj.TileSize * 1.0 / prmObj.GridSize)), 2)];
            Boolean[] availableIndices = new Boolean[prmObj.Info.TileInfo.Row * prmObj.GridCount * prmObj.Info.TileInfo.Col * prmObj.GridCount];

            for (int i = 0; i < prmPoints.Length; i++)
            {
                rowCol = TcMathUtil.GetRowCol(prmPoints[i].X, prmPoints[i].Y, prmInfo.East, prmInfo.North, prmObj.GridSize, prmObj.GridSize);
                index  = rowCol[1] * prmObj.GridCount + rowCol[0];

                if (index < 0)
                {
                    index = 0;
                }

                // Add that into the intermediate tile block.
                if (!availableIndices[index])
                {
                    gridPointCollection[index] = new List <TcLasPointBase>();
                    availableIndices[index]    = true;
                }

                gridPointCollection[index].Add(prmPoints[i]);
            }

            Single height;
            Int32  subGridIndex;
            Int32  rowIndex;

            foreach (Int32 key in gridPointCollection.Keys)
            {
                row    = key % prmObj.GridCount;
                col    = (key - row) / prmObj.GridCount;
                height = (Single)GetGridHeight(gridPointCollection[key], prmObj.Type);

                // Save the point into the specific TOR block.
                rowIndex     = prmInfo.Row * prmObj.GridCount + row;
                subGridIndex = (Int32)Math.Floor(rowIndex * 1.0 / prmObj.MaxRowsInGridBlock);
                prmObj.TorBlocks[subGridIndex].Points[rowIndex % prmObj.MaxRowsInGridBlock, prmInfo.Col *prmObj.GridCount + col] = height;

                // Update the min and max.
                if (height != TcConstants.TorNullValue32Bit)
                {
                    prmObj.MinZ = Math.Min(prmObj.MinZ, height);
                    prmObj.MaxZ = Math.Max(prmObj.MaxZ, height);
                }
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        //-----------------------------------------------------------------------------

        private void ProcessTiles <T>(TcLasReader prmReader, String prmOutput) where T : TiLasPoint
        {
            // Variables to be used inside the big loop.
            Int32 tileOffset      = 0;
            Int32 index           = -1;
            Int32 pointsProcessed = 0;

            // Key: Index of the Tile, Value: Array of 1000 points.
            Dictionary <Int32, T[]> m_TileBlocks = new Dictionary <Int32, T[]>();

            TiLasHeader newHeader = UpdateTileCounts <T>(prmReader.Header, TileSize);

            Byte[] offsetBytes = prmReader.OffsetBytes;

            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)
            {
                MinClampZ = MinClampZ, MaxClampZ = MaxClampZ,
                /* Added By Dean */ ZAdjustment = this.ZAdjustment, XAdjustment = this.XAdjustment, YAdjustment = this.YAdjustment
            })
            {
                writer.WriteHeader(newHeader, offsetBytes);
                Int64     numberOfPointRecords = GetNumberOfPoints(prmReader.Header);
                Int32     onePercent           = (Int32)numberOfPointRecords / 100;
                Int32[]   rowCol = new Int32[2];
                DateTime  now = DateTime.Now;
                Boolean[] availIndices = new Boolean[m_TileBlockInfoCollection.TileInfo.Row * m_TileBlockInfoCollection.TileInfo.Col];
                Double    x, y;
                Double    z = 0; // Added Z Property  - Dean


                Int64 noOfPointsLoaded = 0;
                Int64 noOfPointsToRead = 0;
                while (noOfPointsLoaded < numberOfPointRecords)
                {
                    noOfPointsToRead = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, numberOfPointRecords - noOfPointsLoaded);
                    T[] loadedPoints = prmReader.ReadPoints <T>(noOfPointsToRead);
                    noOfPointsLoaded += noOfPointsToRead;

                    for (int i = 0; i < noOfPointsToRead; i++)
                    {
                        x = loadedPoints[i].X * newHeader.XScaleFactor + newHeader.XOffset + XAdjustment;
                        y = loadedPoints[i].Y * newHeader.YScaleFactor + newHeader.YOffset + YAdjustment;

                        //added by dean
                        z = loadedPoints[i].Z * newHeader.ZScaleFactor + newHeader.ZOffset + ZAdjustment;

                        if (x <= 0 || y <= 0)
                        {
                            continue;
                        }

                        // Calculate the tile index for the point.
                        tileOffset = TileSize * Factor;
                        rowCol     = TcMathUtil.GetRowCol(x, y, m_RevisedEast, m_RevisedNorth, tileOffset, tileOffset);
                        index      = rowCol[1] * m_TileRows + rowCol[0];

                        if (!availIndices[index])
                        {
                            m_TileBlocks[index]      = new T[PointBlockSize];
                            m_BlockPointCount[index] = 0;
                            availIndices[index]      = true;
                        }

                        // Convert the int XY back with adjusted values.
                        loadedPoints[i].X = (Int32)((x - newHeader.XOffset) / newHeader.XScaleFactor);
                        loadedPoints[i].Y = (Int32)((y - newHeader.YOffset) / newHeader.YScaleFactor);
                        loadedPoints[i].Z = (Int32)((z - newHeader.ZOffset) / newHeader.ZScaleFactor);

                        m_TileBlocks[index][m_BlockPointCount[index]] = loadedPoints[i];
                        m_BlockPointCount[index]++;

                        // When a tile block is full, write into file and remove the points.
                        if (m_BlockPointCount[index] == PointBlockSize)
                        {
                            // writer.WritePoints<T>(m_TileBlocks[index], PointBlockSize);
                            writer.WritePointsWithOptions <T>(m_TileBlocks[index], ref newHeader, PointBlockSize);
                            ProcessTileBlock <T>(m_TileBlocks, rowCol[0], rowCol[1], index, pointsProcessed);
                            pointsProcessed    += PointBlockSize;
                            availIndices[index] = false;
                        }
                    }
                }

                // 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.WritePointsWithOptions <T>(m_TileBlocks[idx], ref newHeader, m_BlockPointCount[idx]);
                    ProcessTileBlock <T>(m_TileBlocks, row, col, idx, pointsProcessed);
                    pointsProcessed += m_BlockPointCount[idx];
                }

                // Write the updated header.
                writer.WriteHeader(newHeader);

                TcTileUtils.SaveTileBlocks(m_TileBlockInfoCollection, blockFile);
            }
        }