Skip to content

Decode the points of ReCap scans from the sections of the file - #97

Open
mahach666 wants to merge 1 commit into
mainfrom
codex/rcs-section-layout
Open

mahach666 wants to merge 1 commit into
mainfrom
codex/rcs-section-layout

Conversation

@mahach666

Copy link
Copy Markdown
Contributor

What changes and why

The ReCap scan reader (.rcs) could not decode real files: it took the blocks of the leaves of a scan for point records of one fixed size, and rejected every file whose blocks did not fit. This change decodes the points of container major version 3 from the sections that the table in the header names.

  • Decoding. The leaves section holds one record per leaf of the octree. The points section holds one block per leaf, in the same order, with the index words of the leaf followed by its records. A position is three 18-bit fields on a 1 mm grid, counted from the cube of the leaf. The sections are found through the table whatever their order, the other sections are skipped, and a leaf may hold more index words than its points need.
  • Channels. Intensity, colour and normals follow flags of the header and are known from the header alone. The bytes of a channel are read only when the header states the channel. A point has a normal only when its record states a plain cell code; a zero code, a flag bit beside the code or a code above the last cell leaves it without one.
  • Validation. The file is checked as a whole before the first point is returned. A section table that does not fit in the file, a missing or duplicated section, a leaf table that does not fit its section, a leaf block that does not fit its points and blocks that do not fill the points section are rejected with InvalidDataException, and nothing is returned. Before, the records were checked one at a time while the points were streamed.
  • Point count. RcsScan.PointCount is the number of points the file stores, which a full read returns. The count stated in the header is not that number; it stays available as RcsScanDocument.DeclaredPointCount.

No public signature changes. PointCount, TotalPointCount and HasColors, HasIntensities, HasNormals of a ReCap scan now report the stored points and the flags of the header; the README, the API documentation and the changelog say so.

How it was checked

  • dotnet build PclIO.slnx -c Release has no warnings, and dotnet format PclIO.slnx --verify-no-changes reports nothing.
  • dotnet test passes on net8.0 and net10.0. On the machine the branch was made on, one test of RepositoryHygieneTests also fails: its history check sees a local notes ref of a tool on that machine, which is not part of the repository and not on the remote.
  • Exports of the same files before and after: for every format but ReCap, the LAS export, info and scans of the command line are identical on the private files tried (the LAS files compared by SHA-256). For ReCap scans and ReCap projects the export failed with "node payload does not match a known point record layout" and now writes the points; that is the intended difference.
  • Private scans: every .rcs file of the local corpus, which comes from several scanners and from one converted mesh, was read to its end. Each read returned exactly PointCount points, no point lies outside the bounds of its header, and the channels of every point follow the flags of its header. Records sampled from every file match an independent decoder of the same layout bit for bit in their positions. The normal codes were checked against the geometry of the scans: points on the floor face up, and the stored normals agree with the surfaces their neighbours form, where a mapping with two cell axes exchanged does not.
  • New tests: the exact decoding of records; normal codes of every face with directions computed apart from the reader; both ways a file states that a point has no normal; the channel flags; several leaves; sections in any order; scale and translation; damaged files (the section table, the sections, the leaf table, the leaf blocks, and a file cut at every byte of its length); and a real scan read to its end.
  • No scans, customer data, vendor code or binaries are added
  • No names of sites or projects, serial numbers, GUIDs or local paths are added

The reader took the blocks of the leaves of a scan for point records of
one fixed size and rejected a file whose blocks did not fit that size.
A table in the header names the sections of the file: a leaves section
with one record per leaf of the octree, and a points section with one
block per leaf that holds the index words of the leaf followed by its
16-byte records.

- A position is three 18-bit fields on a 1 mm grid, counted from the
  cube of the leaf. Intensity, colour and a packed normal follow the
  flags of the header, and a point has a normal only when its record
  states a plain cell code.
- The sections are taken from the table whatever their order, and the
  file is checked as a whole before the first point is returned.
- PointCount is the number of points the file stores. The count stated
  in the header is not that number and stays as DeclaredPointCount.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant