LAS-Read/LASRead/RawPoints.cs
2021-03-13 21:31:51 +13:00

60 lines
1.6 KiB
C#

using LASFormat;
using LASRead.LASFormat;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace LASRead
{
public class RawPoints
{
// Creates a raw point cloud from a LAS file input.
LASFile source;
FileStream output;
public RawPoints(LASFile source, FileStream output)
{
this.source = source;
this.output = output;
}
public void Run()
{
GenerateHeader();
byte[] tData = new byte[12];
foreach (IPointDataRecord pdr in source.points)
{
byte[] t = BitConverter.GetBytes(pdr.X);
t.CopyTo(tData, 0);
t = BitConverter.GetBytes(pdr.Y);
t.CopyTo(tData, 4);
t = BitConverter.GetBytes(pdr.Z);
t.CopyTo(tData, 8);
output.Write(tData);
}
output.Flush();
output.Close();
}
/// <summary>
/// Header is 24 bytes (3 doubles)
/// </summary>
private void GenerateHeader()
{
byte[] finalBytes = new byte[24];
double x_scale = source.Header.X_scaleFactor;
double y_scale = source.Header.Y_scaleFactor;
double z_scale = source.Header.Z_scaleFactor;
byte[] t = BitConverter.GetBytes(x_scale);
t.CopyTo(finalBytes, 0);
t = BitConverter.GetBytes(y_scale);
t.CopyTo(finalBytes, 8);
t = BitConverter.GetBytes(z_scale);
t.CopyTo(finalBytes, 16);
output.Write(finalBytes);
}
}
}