public TransformationData(PointCloudBounds bounds, TreeImportSettings settings) { TransformationMatrix = GetTransformationMatrix(settings); LasRGB8BitWorkaround = settings.lasRGB8BitWorkaround; if (settings.normalize) { OutputCenterX = -0.5 * (bounds.MaxX + bounds.MinX); OutputCenterY = -0.5 * (bounds.MaxY + bounds.MinY); OutputCenterZ = -0.5 * (bounds.MaxZ + bounds.MinZ); OutputScaleX = 2.0 / (bounds.MaxX - bounds.MinX); OutputScaleY = 2.0 / (bounds.MaxY - bounds.MinY); OutputScaleZ = 2.0 / (bounds.MaxZ - bounds.MinZ); } else if (settings.center) { OutputCenterX = -0.5 * (bounds.MaxX + bounds.MinX); OutputCenterY = -0.5 * (bounds.MaxY + bounds.MinY); OutputCenterZ = -0.5 * (bounds.MaxZ + bounds.MinZ); OutputScaleX = OutputScaleY = OutputScaleZ = 1.0; } else { OutputCenterX = OutputCenterY = OutputCenterZ = 0.0; OutputScaleX = OutputScaleY = OutputScaleZ = 1.0; } }
public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds) { var fileName = Path.GetFileName(FilePath); var result = new PointCloudVerticalHistogram(bounds); using (var laz = new Laszip(FilePath)) { long count = laz.Count; try { for (long i = 0; i < count; i++) { if (i % (1024 * 8) == 0) { var progress = (double)i / count; EditorUtility.DisplayProgressBar( $"Generating histogram ({fileName})", $"{i:N0} points", (float)progress); } var p = laz.GetNextPoint(); result.Add(p.Z); } } finally { EditorUtility.ClearProgressBar(); } } return(result); }
public void Encapsulate(PointCloudBounds bounds) { MinX = Math.Min(MinX, bounds.MinX); MinY = Math.Min(MinY, bounds.MinY); MinZ = Math.Min(MinZ, bounds.MinZ); MaxX = Math.Max(MaxX, bounds.MaxX); MaxY = Math.Max(MaxY, bounds.MaxY); MaxZ = Math.Max(MaxZ, bounds.MaxZ); }
public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds) { var fileName = Path.GetFileName(FilePath); long currentOffset = header.PointDataOffset; long processed = 0; long count = header.PointDataCount; if (header.VersionMajor > 1 || header.VersionMajor == 1 && header.VersionMinor >= 4) { if (count == 0) { count = (long)header.PointDataCountLong; } } var result = new PointCloudVerticalHistogram(bounds); using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(header.PointDataSize); var totalBatchCount = Mathf.CeilToInt((float)count / maxArraySize); while (processed < count) { var batchCount = Math.Min(maxArraySize, count - processed); var batchSize = batchCount * header.PointDataSize; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { unsafe { batchIndex++; var progressBarTitle = $"Generating histogram ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var hst = PointImportJobs.GenerateHistogramLas(view, batchCount, header, bounds, progressBarTitle); result.AddData(hst.regions); } } processed += batchCount; currentOffset += batchSize; } } return(result); }
///<inheritdoc/> public override PointCloudBounds CalculateBounds() { var bounds = new PointCloudBounds() { MinX = header.MinX, MinY = header.MinY, MinZ = header.MinZ, MaxX = header.MaxX, MaxY = header.MaxY, MaxZ = header.MaxZ, }; return(bounds); }
///<inheritdoc/> public override PointCloudBounds CalculateBounds() { using (var laz = new Laszip(FilePath)) { var bounds = new PointCloudBounds() { MinX = laz.MinX, MinY = laz.MinY, MinZ = laz.MinZ, MaxX = laz.MaxX, MaxY = laz.MaxY, MaxZ = laz.MaxZ, }; return(bounds); } }
/// <summary> /// Calculates and returns merged bounds of points from all given processors. /// </summary> /// <param name="processors">Enumerable collection of point processors.</param> private static PointCloudVerticalHistogram GenerateHistogram(IEnumerable <PointProcessor> processors, PointCloudBounds bounds) { var result = new PointCloudVerticalHistogram(bounds); foreach (var processor in processors) { unsafe { var processorHistogram = processor.GenerateHistogram(bounds); result.AddData(processorHistogram.regions); } } return(result); }
public static PointCloudVerticalHistogram GenerateHistogramLas(MemoryMappedViewAccessor accessor, long count, LasPointProcessor.LasHeader header, PointCloudBounds bounds, string progressBarTitle = null) { var maxArraySize = TreeUtility.CalculateMaxArraySize(header.PointDataSize); if (count > maxArraySize) { Debug.LogWarning( $"Too many points ({count:n0}), truncating to {maxArraySize:n0}"); count = maxArraySize; } unsafe { byte *ptr = null; accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr); try { var counts = new NativeArray <int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob); var histograms = new NativeArray <PointCloudVerticalHistogram>( JobsUtility.MaxJobThreadCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (var i = 0; i < histograms.Length; i++) { histograms[i] = new PointCloudVerticalHistogram(bounds); } try { var job = new PointCloudCreateHistogramLasJob() { Input = ptr, Stride = header.PointDataSize, InputScaleX = header.ScaleX, InputScaleY = header.ScaleY, InputScaleZ = header.ScaleZ, InputOffsetX = header.OffsetX, InputOffsetY = header.OffsetY, InputOffsetZ = header.OffsetZ, Histogram = (PointCloudVerticalHistogram *)histograms.GetUnsafePtr(), Counts = (int *)counts.GetUnsafePtr(), ThreadIndex = 0, }; var h = job.Schedule((int)count, 65536); while (!h.IsCompleted) { System.Threading.Thread.Sleep(100); var processed = counts.Sum(); var progress = (float)((double)processed / count); EditorUtility.DisplayProgressBar( string.IsNullOrEmpty(progressBarTitle) ? "Generating histogram" : progressBarTitle, $"{processed:N0} points", progress); } var result = new PointCloudVerticalHistogram(bounds); foreach (var hst in histograms) { result.AddData(hst.regions); } return(result); } finally { EditorUtility.ClearProgressBar(); histograms.Dispose(); counts.Dispose(); } } finally { accessor.SafeMemoryMappedViewHandle.ReleasePointer(); } } }
///<inheritdoc/> public override PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds) { return(GenerateHistogramDefault(header, bounds)); }
protected PointCloudVerticalHistogram GenerateHistogramDefault(DefaultHeaderData headerData, PointCloudBounds bounds) { var fileName = Path.GetFileName(FilePath); long currentOffset = headerData.DataOffset; long processed = 0; var result = new PointCloudVerticalHistogram(bounds); using (var file = MemoryMappedFile.CreateFromFile(FilePath ?? throw new Exception("Input file not found."), FileMode.Open)) { var batchIndex = 0; var maxArraySize = TreeUtility.CalculateMaxArraySize(headerData.DataStride); var totalBatchCount = Mathf.CeilToInt((float)headerData.DataCount / maxArraySize); while (processed < headerData.DataCount) { var batchCount = Math.Min(maxArraySize, headerData.DataCount - processed); var batchSize = batchCount * headerData.DataStride; using (var view = file.CreateViewAccessor(currentOffset, batchSize, MemoryMappedFileAccess.Read)) { unsafe { batchIndex++; var progressBarTitle = $"Calculating bounds ({fileName}, batch {batchIndex.ToString()}/{totalBatchCount.ToString()})"; var batchHistogram = PointImportJobs.GenerateHistogram(view, batchCount, headerData.DataStride, headerData.Elements, bounds, progressBarTitle); result.AddData(batchHistogram.regions); } } processed += batchCount; currentOffset += batchSize; } } return(result); }
public abstract PointCloudVerticalHistogram GenerateHistogram(PointCloudBounds bounds);
public PointCloudVerticalHistogram(PointCloudBounds bounds) { zMin = bounds.MinZ; zRange = bounds.MaxZ - bounds.MinZ; }