//----------------------------------------------------------------------------- #region LasToCls - Converter function from LAS to Classification format private void LasToCls <T>(TcLasReader prmReader, String prmOutput) where T : TiLasPoint { m_Progress = 0; ReportMessage(String.Format("Processing {0}", Path.GetFileName(prmOutput))); using (TcClsWriter writer = new TcClsWriter(prmReader.Header, prmOutput)) { writer.WriteHeader(prmReader.OffsetBytes); Int64 numberOfPointRecords = prmReader.Header.GetNumberOfPoints(); Int64 noOfPointsLoaded = 0; Int64 noOfPointsToRead = 0; while (noOfPointsLoaded < numberOfPointRecords) { noOfPointsToRead = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, numberOfPointRecords - noOfPointsLoaded); writer.WritePoints <T>(prmReader.ReadPoints <T>(noOfPointsToRead)); noOfPointsLoaded += noOfPointsToRead; ReportProgress(noOfPointsLoaded, numberOfPointRecords); } } ReportMessage(String.Format("Finished {0}", Path.GetFileName(prmOutput))); }
//----------------------------------------------------------------------------- private void LasToCls <T>(TcLasReader prmReader, Int64 prmOriginalNumberOfPoints, String prmOutputAcl, String prmOutputAcb) where T : TiLasGPS { ReportMessage(String.Format("Processing {0}", Path.GetFileName(prmOutputAcb))); ReportMessage("Reading all LAS points"); // Read all the points. T[] clsPoints = prmReader.ReadPoints <T>(prmReader.TotalPoints); ReportMessage("Sorting LAS points according to the GPS time"); // Sort the points according to the GPS time. new TcLasSort <T>().SortByGpsTime(clsPoints, 0, prmReader.TotalPoints - 1); Int64 pointsProcessed = 0; Byte[] clsData = new Byte[prmOriginalNumberOfPoints]; ReportMessage("Extracting the new points"); // Count the number of points with GPSTime ~ 0 (new point) Int32 exptCnt = 0; while (clsPoints[exptCnt].GPSTime < 1) { exptCnt++; } // Write the new points in .acl file. if (exptCnt > 0) { using (TcClsWriter clsWriter = new TcClsWriter(GetHeaderForCls(prmReader.Header, exptCnt), prmOutputAcl)) { clsWriter.WriteHeader(prmReader.OffsetBytes); clsWriter.WritePoints <T>(clsPoints.Take(exptCnt).ToArray()); } } pointsProcessed += exptCnt; // Counter for the original points. Int64 origPtCnt = 0; // Current expected GPS time to map the deleted points. Double expecteGPSTime = 1.0; ReportMessage("Processing original points"); while (pointsProcessed < clsPoints.Length && origPtCnt < prmOriginalNumberOfPoints) { // If deleted points have been detected. if (clsPoints[pointsProcessed].GPSTime != expecteGPSTime) { clsData[origPtCnt++] = 255; expecteGPSTime++; continue; } clsData[origPtCnt++] = clsPoints[pointsProcessed++].Classification; expecteGPSTime++; } ReportMessage("Writing the output classification files"); // Write into the stream. if (origPtCnt > 0) { using (BinaryWriter acbWriter = new BinaryWriter(new FileStream(prmOutputAcb, FileMode.Create))) { acbWriter.Write(origPtCnt); acbWriter.Write(clsData); } } ReportMessage(String.Format("Finished {0}", Path.GetFileName(prmOutputAcb))); }