public TcTorWriter(String prmTorFile) { using (TcTorReader reader = new TcTorReader(prmTorFile)) { m_TolObject = reader.Info; } }
//------------------------------------------------------------------ public void Write(TcTorObject prmTor, String prmOutputFile) { m_TolObject = prmTor.Info; using (BinaryWriter writer = new BinaryWriter(new FileStream(prmOutputFile, FileMode.Create))) { WriteTol(prmOutputFile); foreach (TcTorBlock32 block in prmTor.Blocks) { Write(writer, block); } } }
//------------------------------------------------------------------ private List <TcTorBlock32> GetTorBlocks(TcTolObject prmTol) { Int32 pointSize = sizeof(Single); Int32 rowsInBlock = (Int32)Math.Floor(TcConstants.MaxBytesToLoadInTorBlock * 1.0 / (prmTol.Columns * pointSize)); Int64 noOfPointsAvailable = (Int64)((m_Reader.BaseStream.Length - m_Reader.BaseStream.Position) / pointSize); // Create a las point array of required size. List <TcTorBlock32> returnBlocks = new List <TcTorBlock32>(); // Memory stream. Byte[] readBuffer; Int32 index = 0; Int32 rowsProcessed = 0; while (rowsProcessed < prmTol.Rows) { Int32 rowsToProcess = Math.Min(rowsInBlock, prmTol.Rows - rowsProcessed); Int32 bytesToRead = pointSize * rowsToProcess * prmTol.Columns; // Reads the points in a byte array. readBuffer = m_Reader.ReadBytes(bytesToRead); TcTorBlock32 block = new TcTorBlock32(index++, rowsToProcess, prmTol.Columns) { Points = new Single[rowsToProcess, prmTol.Columns] }; // Set a handle to the las point array. GCHandle pinnedHandle = GCHandle.Alloc(block.Points, GCHandleType.Pinned); // Copy the stream to the structures. Marshal.Copy(readBuffer, 0, pinnedHandle.AddrOfPinnedObject(), bytesToRead); returnBlocks.Add(block); rowsProcessed += rowsToProcess; } return(returnBlocks); }
public TcTorWriter(TcTolObject prmTolObject) { m_TolObject = prmTolObject; }
//------------------------------------------------------------------ static public TcTolObject ReadTol(String prmTorFile) { if (!prmTorFile.EndsWith(".tor", StringComparison.CurrentCultureIgnoreCase)) { throw new FileNotFoundException(String.Format("Invalid TOR file : {0}", prmTorFile)); } if (!File.Exists(prmTorFile)) { throw new FileNotFoundException(String.Format("Cannot find the TOL file : {0}", prmTorFile)); } TcTolObject returnObject = new TcTolObject(prmTorFile); String[] lines = File.ReadAllLines(returnObject.TolFile); String[] splittedItems; foreach (String line in lines) { IEnumerable <String> keys = line.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(iter => iter.Trim()); if (keys.Count() < 1) { continue; } TeTolTags info = TcEnums.GetEnumFromDescription <TeTolTags>(keys.First()); switch (TcEnums.GetEnumFromDescription <TeTolTags>(keys.First())) { case TeTolTags.ImageName: returnObject.ImageName = keys.ElementAt(1); break; case TeTolTags.DateTime: returnObject.DateTime = keys.ElementAt(1); break; case TeTolTags.Rows: returnObject.Rows = Int32.Parse(keys.ElementAt(1)); break; case TeTolTags.Columns: returnObject.Columns = Int32.Parse(keys.ElementAt(1)); break; case TeTolTags.BitSize: splittedItems = keys.ElementAt(1).Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (splittedItems.Length >= 1) { returnObject.BitSize = Int32.Parse(splittedItems[0]); } break; case TeTolTags.Scaling: splittedItems = keys.ElementAt(1).Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (splittedItems.Length >= 2) { returnObject.ScalingX = Double.Parse(splittedItems[0]); returnObject.ScalingY = Double.Parse(splittedItems[1]); } break; case TeTolTags.UpperLeftEast: returnObject.UpperLeftEast = Double.Parse(keys.ElementAt(1)); break; case TeTolTags.UpperLeftNorth: returnObject.UpperLeftNorth = Double.Parse(keys.ElementAt(1)); break; case TeTolTags.LowerRightEast: returnObject.LowerRightEast = Double.Parse(keys.ElementAt(1)); break; case TeTolTags.LowerRightNorth: returnObject.LowerRightNorth = Double.Parse(keys.ElementAt(1)); break; case TeTolTags.MinHeight: returnObject.MinHeight = Single.Parse(keys.ElementAt(1)); break; case TeTolTags.MaxHeight: returnObject.MaxHeight = Single.Parse(keys.ElementAt(1)); break; case TeTolTags.Model: returnObject.Model = Int32.Parse(keys.ElementAt(1)); break; case TeTolTags.Adjusted: returnObject.Adjusted = Int32.Parse(keys.ElementAt(1)) == 1; break; case TeTolTags.Unknown: break; } } return(returnObject); }
public TcTorReader(String prmTorFile) { m_TorFile = prmTorFile; Info = ReadTol(prmTorFile); m_Reader = new BinaryReader(new FileStream(prmTorFile, FileMode.Open)); }
//----------------------------------------------------------------------------- /// <summary> /// This function reads the LAS file and arrange points into the specific grid. /// It also applies filtering for some given pre-defined gridding types. /// </summary> /// <typeparam name="T">Type of the LAS points</typeparam> /// <param name="prmReader">Tile LAS reader which reads LAS points by tile</param> /// <param name="prmObjects">A collection of grid data objects (1 per gridding type)</param> private void Grid <T>(TcTileLasReader prmReader, IEnumerable <TcGridObject> prmObjects) where T : TiLasPoint { TcLasPointBase[] points; TcTileBlockInfo info; for (int row = 0; row < m_Info.TileInfo.Row; row++) { for (int col = 0; col < m_Info.TileInfo.Col; col++) { if ((info = m_Info.TileBlocks.FirstOrDefault(iter => iter.Row == row && iter.Col == col)) != null) { points = prmReader.GetPointObjectsByTile <T>(row, col, m_LasHeader); foreach (TcGridObject gridObject in prmObjects) { // Report the message. ReportMessage(String.Format("Processing Tile({0},{1}) of {2} ({3}m)", row, col, TcEnums.ShortName(gridObject.Type), gridObject.GridSize)); // Filter points that are not required by 1M grid. if (gridObject.Type == TeGriddingType.M1FirstEcho || gridObject.Type == TeGriddingType.M1LastEcho) { FilterOutOfInterestPoints(points); } UpdateGrid(gridObject, info, points); } } } } foreach (TcGridObject gridObject in prmObjects) { // Write the tor file. TcTolObject objDiff = new TcTolObject(gridObject.OutputFile) { Rows = m_Info.TileInfo.Row * gridObject.GridCount, Columns = m_Info.TileInfo.Col * gridObject.GridCount, UpperLeftEast = m_LasHeader.MinX, UpperLeftNorth = m_LasHeader.MaxY, LowerRightEast = m_LasHeader.MaxX, LowerRightNorth = m_LasHeader.MinY, MinHeight = (Single)gridObject.MinZ, MaxHeight = (Single)gridObject.MaxZ, ScalingX = gridObject.GridSize, ScalingY = gridObject.GridSize, Model = m_CoordinateSystem, BitSize = 32 }; // Report the message. ReportMessage(String.Format("Writing {0}", Path.GetFileName(gridObject.OutputFile))); TcTorObject objTor = new TcTorObject(objDiff) { Blocks = gridObject.TorBlocks }; using (TcTorWriter writer = new TcTorWriter(objDiff)) { writer.WriteTol(); writer.Write(objTor); } } ReportFinished(); }