From d4cd70545f71357714f5d7aa6ff64e1bc4494cbc Mon Sep 17 00:00:00 2001 From: mahach666 <79989386+mahach666@users.noreply.github.com> Date: Mon, 16 Nov 2026 03:26:58 +0000 Subject: [PATCH] Take the point count of a PinPoint data object from its data file --- CHANGELOG.md | 2 + README.md | 2 +- docs/public-api.md | 2 +- .../Formats/PinPoint/PinPointDocument.cs | 5 +- tests/PclIO.Tests/FormatTests.cs | 55 +++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 870f0e4..99b7fa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The PinPoint coordinate plausibility rule is now `PclReadOptions.MaxCoordinateMagnitude` (default 5000, null for no limit); non-finite coordinates are still never returned. A full read reports how many points it dropped in the warnings of the document, and fails instead with `PclReadOptions.Strict`. +- The point count of a PinPoint location of a manifest with a data object list is taken from the data file the object + refers to, as for manifests with a scan position list. Locations that share one file each report its full count. ## [0.1.0] - 2026-11-15 diff --git a/README.md b/README.md index 0852843..0b95d8c 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ The library targets .NET 8 and .NET 10. It is managed code with no dependencies | ReCap project | `.rcp` | Lists the scans of the project manifest and opens the `.rcs` files it finds next to the project. The transform of a scan node places the scan in the project and is applied to its points unless `ApplyTransform` is false; when the manifest states no transform, the transform of the scan file is used. | | Leica scan container | `.lgsx`, `.lgs` | Experimental. Points are decoded from the compressed point blocks: position, and colour, intensity and normals when the block has them. When the container assigns its points to its setups, there is one scan per setup, named after the setup, with the pose and the bounds of the setup when its record holds them; the pose is applied unless `ApplyTransform` is false. When the container does not assign its points, all points of the container form one scan and a warning says so. The point count is taken from the container when it states one; otherwise it is found by decoding the data, which is slow on large files. | | FARO scan | `.fls`, or a FARO scan folder | Experimental. The scan grid and angles are read from the stored parameters and points are projected from the range grid; a file without them fails to open. The point count is the number of valid returns, which is counted on the first access; `FaroScan.GridSize` is the size of the scan grid. For a scan folder the layout of the samples is derived from the size of the data stream and the size of the grid, and the scale of the intensity from the values that are stored; when the sizes do not fit, the layout is assumed and a warning says so. | -| PinPoint project | `.srf`, `.smf`, or a folder with `ScanProject.json` or `.smf`/`.srf` files | Experimental. The manifest (scan names, ids, poses, counts) is read. Points come from the referenced `.bin` files, in either of two layouts: a table of named channels, or numbered sections with a property table and Snappy-compressed channels, which PclIO decodes itself. Colour, intensity and normals are reported only when the file has that channel; in the second layout positions, colours, intensities, normals (`Normals`, three float32 components per point) and the per-point flags (`FilterBits`, one byte per point) are read, while the grid indices stored beside them are not interpreted, so by default every stored point that passes the plausibility rule below is returned. With `PclReadOptions.ExcludeFilteredPoints` the points with a non-zero flag are not returned. A manifest with a scan position list takes the point count from the manifest, else from the data file; a manifest with a data object list always reports 0 because that count is not known. | +| PinPoint project | `.srf`, `.smf`, or a folder with `ScanProject.json` or `.smf`/`.srf` files | Experimental. The manifest (scan names, ids, poses, counts) is read. Points come from the referenced `.bin` files, in either of two layouts: a table of named channels, or numbered sections with a property table and Snappy-compressed channels, which PclIO decodes itself. Colour, intensity and normals are reported only when the file has that channel; in the second layout positions, colours, intensities, normals (`Normals`, three float32 components per point) and the per-point flags (`FilterBits`, one byte per point) are read, while the grid indices stored beside them are not interpreted, so by default every stored point that passes the plausibility rule below is returned. With `PclReadOptions.ExcludeFilteredPoints` the points with a non-zero flag are not returned. A manifest with a scan position list takes the point count from the manifest, else from the data file; a manifest with a data object list takes it from the data file the object refers to, and every location that shares one file reports its full count, because the shares are not recorded. | | EdgeWise | `.c3db`, `.c3ptx` | Experimental. A `.c3db` point database lists the scan clusters and a `.c3ptx` is one cluster file; the cluster files give positions only. The scale of the cluster positions is not stored in the files, so it is an assumption of the reader and positions are only as exact as it. | ### Format detection diff --git a/docs/public-api.md b/docs/public-api.md index d15bfea..f2e9d50 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -64,7 +64,7 @@ drop points that fail a plausibility rule (see the README), so a scan can yield | ReCap project | Declared by the project manifest; 0 when the manifest states none. | | Leica | The number of points the container states, when it states one; otherwise it is computed. The computed value needs the first access to decode all of the point data and caches the result, which can be slow on large files; the access throws `InvalidDataException` for corrupt data. A container that assigns its points to its setups has one scan per setup, each with the id and the name of its setup; otherwise the container is one scan with the id `unified-cloud`. The `Transform` and the `Bounds` of a setup are read from its record and are empty when the record does not hold them. | | FARO | The number of valid returns, which is counted on the first access by reading the distance data of the scan; `FaroScan.GridSize` is the size of the scan grid (rows times columns). For a folder scan the grid size is limited by the size of the data stream, and `FaroScan.RecordSize` is the size of one sample in bytes. | -| PinPoint | A manifest with a scan position list: declared by the manifest, else derived from the data file, else 0 (not known). A manifest with a data object list: always 0 (not known), so `TotalPointCount` is 0 for such a project. | +| PinPoint | A manifest with a scan position list: declared by the manifest, else derived from the data file, else 0 (not known). A manifest with a data object list: derived from the data file the object refers to, else 0 (not known); locations that share one file each report its full count. | | EdgeWise | A `.c3db` database node: the count the database declares. A `.c3ptx` file: computed by walking the cluster headers when the file is opened. | `HasColors`, `HasIntensities` and `HasNormals` follow what the file contains, except for the scans of a ReCap project, where all three diff --git a/src/PclIO/Formats/PinPoint/PinPointDocument.cs b/src/PclIO/Formats/PinPoint/PinPointDocument.cs index 483db74..0e739f3 100644 --- a/src/PclIO/Formats/PinPoint/PinPointDocument.cs +++ b/src/PclIO/Formats/PinPoint/PinPointDocument.cs @@ -168,12 +168,13 @@ public static PinPointDocument Open(string path, PclReadOptions? options = null) string locHash = TryProp(loc, "HashId", out var lh) ? ReadText(lh) : ""; var transform = TryProp(loc, "Pose", out var poseElem) ? ParseTransform(poseElem) : PclTransform.Identity; - // The share of the data file that belongs to one location is not recorded, so the count stays unknown. + // A location holds the whole data file it refers to; when several locations share one file, + // each of them reports its full count, because their shares are not recorded. if (binPath == null) document._warnings.Add($"Location '{locHash}': point data file not found."); var table = ReadTableOrWarn(document, locHash, binPath); - document.AddScan(new PinPointScan(locHash, locHash, 0, transform, binPath, table, document)); + document.AddScan(new PinPointScan(locHash, locHash, table?.PointCount ?? 0, transform, binPath, table, document)); } } } diff --git a/tests/PclIO.Tests/FormatTests.cs b/tests/PclIO.Tests/FormatTests.cs index b4180cd..e1c9a58 100644 --- a/tests/PclIO.Tests/FormatTests.cs +++ b/tests/PclIO.Tests/FormatTests.cs @@ -1087,6 +1087,61 @@ public void PinPoint_A_Read_Stopped_By_MaxPoints_Reports_Nothing() Assert.Throws(() => scan.ReadPoints(new PclReadOptions { ApplyTransform = false, Strict = true }).ToList()); } + [Fact] + public void A_Data_Object_Location_Takes_Its_Point_Count_From_The_Data_File() + { + using var dir = new TempDirectory(); + const string manifest = """{ "DataObjects": [ { "HashId": "h1", "Locations": [ { "HashId": "loc1" } ] } ] }"""; + dir.Write("h1.bin", SyntheticFixtures.CreateSyntheticPinPointBin([(1, 2, 3), (4, 5, 6)])); + using var doc = PinPointDocument.Open(dir.WriteText("project.smf", manifest)); + + var scan = Assert.Single(doc.Scans); + Assert.Equal("loc1", scan.Id); + Assert.Equal(2, scan.PointCount); + Assert.Equal(2, doc.TotalPointCount); + Assert.Equal(2, scan.ReadPoints(NoTransform).Count()); + } + + [Fact] + public void Locations_That_Share_A_Data_File_Each_Report_Its_Full_Count() + { + // The shares of one file are not recorded, so every location reports the whole file. + using var dir = new TempDirectory(); + const string manifest = """{ "DataObjects": [ { "HashId": "h1", "Locations": [ { "HashId": "a" }, { "HashId": "b" } ] } ] }"""; + dir.Write("h1.bin", SyntheticFixtures.CreateSyntheticPinPointBin([(1, 2, 3), (4, 5, 6)])); + using var doc = PinPointDocument.Open(dir.WriteText("project.smf", manifest)); + + Assert.Equal([2L, 2L], doc.Scans.Select(s => s.PointCount)); + Assert.Equal(4, doc.TotalPointCount); + } + + [Fact] + public void A_Data_Object_Location_Without_A_Data_File_Reports_Zero_Points() + { + using var dir = new TempDirectory(); + const string manifest = """{ "DataObjects": [ { "HashId": "h1", "Locations": [ { "HashId": "loc1" } ] } ] }"""; + using var doc = PinPointDocument.Open(dir.WriteText("project.smf", manifest)); + + var scan = Assert.Single(doc.Scans); + Assert.Equal(0, scan.PointCount); + Assert.Contains(doc.Warnings, w => w.Contains("not found", StringComparison.Ordinal)); + Assert.Empty(scan.ReadPoints()); + } + + [Fact] + public void A_Data_Object_Location_With_A_Damaged_Data_File_Reports_Zero_Points_And_Fails_When_Read() + { + using var dir = new TempDirectory(); + const string manifest = """{ "DataObjects": [ { "HashId": "h1", "Locations": [ { "HashId": "loc1" } ] } ] }"""; + dir.Write("h1.bin", new byte[240]); + using var doc = PinPointDocument.Open(dir.WriteText("project.smf", manifest)); + + var scan = Assert.Single(doc.Scans); + Assert.Equal(0, scan.PointCount); + Assert.Contains(doc.Warnings, w => w.Contains("no recognised channel layout", StringComparison.Ordinal)); + Assert.Throws(() => scan.ReadPoints().ToList()); + } + // ---- EdgeWise -------------------------------------------------------------------------------------------- private static readonly C3Cluster[] Clusters =