예제 #1
0
        //-----------------------------------------------------------------------------

        private void ClsToLas <T>(TcClsReader prmReader, String prmOutput) where T : TiLasPoint
        {
            m_Progress = 0;

            ReportMessage(String.Format("Processing {0}", Path.GetFileName(prmOutput)));
            using (TcLasWriter writer = new TcLasWriter(prmOutput))
            {
                writer.WriteHeader(prmReader.Header, prmReader.OffsetBytes);

                Int64           numberOfPointRecords = prmReader.Header.GetNumberOfPoints();
                Int64           noOfPointsLoaded     = 0;
                Int64           noOfPointsToRead     = 0;
                TiLasPoint[]    lasPoints            = new TiLasPoint[TcConstants.MaxLasPointsToProcessAtOnce];
                TsClsLasPoint[] clsPoints;
                Double          pointIndex = 1;

                while (noOfPointsLoaded < numberOfPointRecords)
                {
                    noOfPointsToRead = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, numberOfPointRecords - noOfPointsLoaded);
                    clsPoints        = prmReader.ReadPoints(noOfPointsToRead);
                    for (int i = 0; i < noOfPointsToRead; i++)
                    {
                        lasPoints[i] = ClsToLasByPDRF(clsPoints[i], prmReader.Header.PointDataFormatID, pointIndex++);
                    }

                    writer.WritePoints(lasPoints, noOfPointsToRead);
                    noOfPointsLoaded += noOfPointsToRead;
                    ReportProgress(noOfPointsLoaded, numberOfPointRecords);
                }
            }
            ReportMessage(String.Format("Finished {0}", Path.GetFileName(prmOutput)));
        }
예제 #2
0
        //-----------------------------------------------------------------------------

        private void ClsToLas <T>(TcLasReader prmReader, String prmAclFile, String prmAcbFile, String prmOutputLas) where T : TiLasGPS
        {
            using (BinaryReader acbReader = new BinaryReader(new FileStream(prmAcbFile, FileMode.Open)))
            {
                Int64 totalPoints = acbReader.ReadInt64();

                // When the binary file doesn't have enough points.
                if (totalPoints != (acbReader.BaseStream.Length - acbReader.BaseStream.Position))
                {
                    throw new InvalidDataException(String.Format("Length of data mismatched in {0} file", Path.GetFileName(prmAcbFile)));
                }

                // Check against the number of points in the original LAS files.
                if (totalPoints != prmReader.TotalPoints)
                {
                    throw new InvalidDataException(String.Format("{0} file doesn't have save number of points as LAS", Path.GetFileName(prmAcbFile)));
                }

                using (TcLasWriter lasWriter = new TcLasWriter(prmOutputLas))
                {
                    Int64  noOfPointsToProcess = 0;
                    Int64  noOfPointsProcessed = 0;
                    T[]    points  = new T[TcConstants.MaxLasPointsToProcessAtOnce];
                    Byte[] clsData = acbReader.ReadBytes((Int32)totalPoints);

                    // Write the header.
                    lasWriter.WriteHeader(prmReader.Header, prmReader.OffsetBytes);

                    while (noOfPointsProcessed < prmReader.TotalPoints)
                    {
                        // Calculate how many points to read.
                        noOfPointsToProcess = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, prmReader.TotalPoints - noOfPointsProcessed);

                        // Read a block of points from the LAS file.
                        points = prmReader.ReadPoints <T>(noOfPointsToProcess);

                        // Update the classification flag.
                        for (int i = 0; i < noOfPointsToProcess; i++)
                        {
                            points[i].Classification = clsData[noOfPointsProcessed + i];
                        }

                        lasWriter.WritePoints <T>(points);

                        // Notify the progress to the caller thread.
                        ReportProgress(noOfPointsProcessed, totalPoints);

                        noOfPointsProcessed += noOfPointsToProcess;
                    }

                    // Process the extra points if there is any.
                    if (!String.IsNullOrWhiteSpace(prmAclFile) && File.Exists(prmAclFile))
                    {
                        using (TcClsReader clsReader = new TcClsReader(prmAclFile))
                        {
                            TsClsLasPoint[] extraPoints    = clsReader.ReadPoints(clsReader.TotalPoints);
                            TiLasGPS[]      extraLasPoints = new TiLasGPS[clsReader.TotalPoints];

                            for (int i = 0; i < clsReader.TotalPoints; i++)
                            {
                                extraLasPoints[i] = ClsToLasPoint(extraPoints[i], clsReader.Header.PointDataFormatID);

                                // Point transformation as the offset and/or scaling factor might be changed in different software.
                                extraLasPoints[i].X = (Int32)(((clsReader.Header.XOffset + extraLasPoints[i].X * clsReader.Header.XScaleFactor) - prmReader.Header.XOffset) / prmReader.Header.XScaleFactor);
                                extraLasPoints[i].Y = (Int32)(((clsReader.Header.YOffset + extraLasPoints[i].Y * clsReader.Header.YScaleFactor) - prmReader.Header.YOffset) / prmReader.Header.YScaleFactor);
                                extraLasPoints[i].Z = (Int32)(((clsReader.Header.ZOffset + extraLasPoints[i].Z * clsReader.Header.ZScaleFactor) - prmReader.Header.ZOffset) / prmReader.Header.ZScaleFactor);
                            }
                            lasWriter.WritePoints(extraLasPoints);

                            // Write the updated header.
                            lasWriter.WriteHeader(GetHeaderForMergedLas(prmReader.Header, clsReader.TotalPoints));
                        }
                    }
                }
            }
        }
예제 #3
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);
                }
            }
        }
예제 #4
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);
            }
        }