2021-03-13 21:31:51 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace LASRead.LASFormat
|
|
|
|
|
{
|
|
|
|
|
public class RecordCollection : IEnumerable<Record>
|
|
|
|
|
{
|
|
|
|
|
RecordEnumerator enumerator;
|
2021-11-17 13:16:14 +13:00
|
|
|
|
public RecordCollection(ref Stream source, ulong startPosition, uint maxItems, IRecordPayloadHeader firstHeader)
|
2021-03-13 21:31:51 +13:00
|
|
|
|
{
|
2021-11-17 13:16:14 +13:00
|
|
|
|
enumerator = new RecordEnumerator(ref source, startPosition, maxItems, firstHeader);
|
2021-03-13 21:31:51 +13:00
|
|
|
|
}
|
|
|
|
|
public IEnumerator<Record> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return enumerator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return enumerator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class RecordEnumerator : IEnumerator<Record>
|
|
|
|
|
{
|
|
|
|
|
Stream dataSource;
|
|
|
|
|
ulong streamStart;
|
|
|
|
|
ulong currentPosition;
|
|
|
|
|
uint currentCount;
|
|
|
|
|
uint maxCount;
|
|
|
|
|
|
2021-11-17 13:16:14 +13:00
|
|
|
|
public RecordEnumerator(ref Stream source, ulong startPosition, uint maxItems, IRecordPayloadHeader firstHeader)
|
2021-03-13 21:31:51 +13:00
|
|
|
|
{
|
|
|
|
|
dataSource = source;
|
|
|
|
|
streamStart = startPosition;
|
|
|
|
|
currentPosition = startPosition;
|
|
|
|
|
currentCount = 0;
|
|
|
|
|
maxCount = maxItems;
|
|
|
|
|
Current = new Record(firstHeader, (long)startPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object IEnumerator.Current => Current;
|
|
|
|
|
|
|
|
|
|
public Record Current { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
dataSource = null;
|
|
|
|
|
streamStart = 0;
|
|
|
|
|
currentPosition = 0;
|
|
|
|
|
currentCount = 0;
|
|
|
|
|
maxCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool MoveNext()
|
|
|
|
|
{
|
|
|
|
|
if (currentCount >= maxCount)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
long oldPos = dataSource.Position;
|
|
|
|
|
currentPosition = (ulong)Current.header.HeaderLength + currentPosition;
|
|
|
|
|
dataSource.Position = (long)currentPosition;
|
|
|
|
|
Record nextRecord = new Record(Current.header.ParseRecord(dataSource), (long)currentPosition);
|
|
|
|
|
Current = nextRecord;
|
|
|
|
|
dataSource.Position = oldPos;
|
|
|
|
|
currentCount++;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|