Skip to content

Improve Revit PDF parity across sheets and views - #303

Draft
mahach666 wants to merge 27 commits into
feat/viewport-crop-scalefrom
codex/revit-pdf-parity-checkpoint
Draft

mahach666 wants to merge 27 commits into
feat/viewport-crop-scalefrom
codex/revit-pdf-parity-checkpoint

Conversation

@mahach666

@mahach666 mahach666 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This draft records the verified PDF-printing checkpoint on top of feat/viewport-crop-scale at b12e943. It keeps the accumulated changes across the title sheet, site plan, floor plans, elevations, sections and details in one reviewable branch. The section-plane units fix in #300 has its own main-based review.

  • Print saved schedules, title-block graphics and annotations. Use saved placement, visibility and style data in model viewports.

  • Restore supported model surfaces, cut profiles, material patterns, stair and railing geometry, site graphics and shadows.

  • Include the latest verified elevation and section visibility and shading fixes in 0eb5fbc. These cover RPC foliage at the view plane on A103, foreground furniture occlusion on A104, and glazing, stair surfaces and retaining-wall shading on A105.

  • Print the continuous drafting grid from the saved paint region on the A104 Building Section wall. The parent face retains its solid geometry and openings.

  • Use the saved uniform Arial body style to align the evaluated schedule rows and column headers on A001.

  • Project the terrain material's saved drafting hatch and cut colour onto the vertical section-box faces of Solar Analysis on A101.

  • Restore the daily paths, saved hour limits and geometric sunrise and sunset labels in A101 Solar Analysis. Shade the exposed solar band and vertical terrain cuts with the saved sun settings. Hide compass marks behind opaque geometry.

  • Use the saved placed type outline to reject clipped RPC plants and render both sides of the retained planting meshes.

Verification

All six sheets were reprinted with rvtio print --all-sheets. Both b12e943 and this checkpoint were compared with the same Revit 2022 PDF. Values are percentages.

Sheet rvt_prt recall / precision, base rvt_prt recall / precision, branch Raster F1 at 72 / 144 dpi, base Raster F1 at 72 / 144 dpi, branch
A001 99.40 / 99.96 100.00 / 99.96 27.39 / 41.98 98.87 / 98.87
A101 92.36 / 56.57 100.00 / 51.92 45.28 / 58.75 94.41 / 93.36
A102 84.14 / 92.19 99.29 / 99.39 62.29 / 68.00 95.53 / 96.96
A103 91.57 / 71.45 100.00 / 55.91 53.83 / 65.12 94.53 / 93.17
A104 79.08 / 64.12 99.94 / 59.55 43.61 / 54.29 94.54 / 90.94
A105 88.40 / 64.75 100.00 / 46.97 48.89 / 51.72 80.84 / 96.28

The A104 painted cladding reduced RGB mean absolute error in its crop from 15.77 to 14.72 at 144 dpi and from 14.38 to 13.01 at 288 dpi. The living room crop matched the previous print pixel for pixel at both resolutions. A104 whole-sheet raster F1 changed from 91.02% to 90.94% at 144 dpi. It held at 94.54% at 72 dpi. A104 vector scores and all A103 sheet scores held within the displayed precision.

The earlier A105 retaining-wall change reduced RGB mean absolute error in the target crop from 16.89 to 9.29 at 144 dpi. It preserved vector paths on all six sheets. A001–A104 matched the preceding print pixel for pixel after masking timestamps, including A103 South and A104 West and Building Section.

The A001 schedule crop RGB mean absolute error at 144 dpi fell from 4.32 to 0.80 after restoring the row layout. The A101 soil cut RGB mean absolute error at 144 dpi fell from 36.81 to 31.20 after restoring the hatch. The soil tone still differs from Revit. A103 South, A104 West and A104 Building Section are pixel-identical to the preceding checkpoint at 72 and 144 dpi.

Compared with the preceding PR commit (f68cb9a1), A101 raster F1 rose from 93.51% to 94.41% at 72 dpi and from 92.76% to 93.36% at 144 dpi. A101 vector scores held at 100.00% recall and 51.92% precision. The other five sheets preserved their reported scores. Timestamp-normalized raster comparisons preserved A103 South, A104 West and A104 Building Section.

  • dotnet build src/RvtIO.Cli/RvtIO.Cli.csproj -c Release -f net10.0
  • dotnet test tests/RvtIO.Tests/RvtIO.Tests.csproj -c Release passed on .NET 8 (12,126 passed) and .NET 10 (12,130 passed), with 502 skips on each target. The earlier schedule-style and terrain-pattern real-file tests also passed separately on .NET 10.
  • git diff --cached --check

Residual styling and geometry differences remain. Vector precision is lower than the base on A101, A103, A104 and A105. The Revit reference carries drawing content in raster tiles on those sheets, so the raster comparison measures visible geometry that rvt_prt cannot match as vectors. The model and comparison PDFs remain in the local validation workspace.

@mahach666

Copy link
Copy Markdown
Collaborator Author

Review notes from a static read of head 55a08a9 against its base b12e943 (CI is green; nothing was executed beyond the existing test suite).

Merge order and size

  • The base feat/viewport-crop-scale is not in main (59 commits, no PR) and by itself conflicts with main in docs/printing.md, src/RvtIO/Model/Element.cs and src/RvtIO/Parsing/TfBlockDeserializer.cs. The base has to land (or be rebased) first, then this PR retargeted.
  • 115 files and +21k lines is hard to review as one unit. The sheet image API/CLI, the site plan, datum and section annotations, and localisation could each go separately. The description already admits worse vector precision on sheets A101/A103/A104/A105 than the base.

Needs a fix

  • src/RvtIO/Print/PlanPrinter.WallCuts.cs:133: ElevationPrinter.ClipToWindow(ring, frame.X0, frame.Y0, frame.X1, frame.Y1), but the signature is (polygon, left, right, bottom, top), so the window becomes x ∈ [X0, Y0], y ∈ [X1, Y1]. In cropped views the wall-cut fill is lost or clipped to a meaningless window. The other callers pass (X0, X1, Y0, Y1) correctly (PlanPrinter.cs:862, PlanPrinter.Columns.cs:86). PlanPrinterTests.cs:261 only checks strokes, so it does not catch this.
  • src/RvtIO/Pdf/PdfSerializer.cs:83 (also 96 and 102): font.Name comes from Path.GetFileNameWithoutExtension and is written raw into /BaseFont and /FontName. The new macOS candidate /System/Library/Fonts/Supplemental/Arial Bold.ttf gives the name Arial Bold; the space ends the PDF name token and Bold lands in the dictionary, which makes it invalid. Normalising the name once in PdfTrueTypeFont (or #XX-escaping on write) plus a test would fix it.

Minor

  • ElevationPrinter.RailingTubes.cs:104 and PlanPrinter.Columns.cs:49: both apply GeoInstance.Transform transposed (t[1] and t[3] swapped relative to the documented x' = t[9] + p.X·t[0] + p.Y·t[1] + p.Z·t[2]), which is only wrong for rotated instances. Reusing ElementBuilder.TransformGeometryPoint would remove the duplicate.
  • PlanPrinter.Datums.cs:88, DetailAnnotations.cs:267: page.DrawText is called without checking the font, so a non-ASCII grid name or detail/sheet number throws ArgumentException when no TrueType font is embedded. PlanPrinter.cs:928 shows the pattern to follow.
  • ElementBuilder.cs:7018: AppendGeometry mutates a ViewFacingLines list that is shared with GRepData (assigned by reference at lines 628 and 745).
  • PlanPrinter.cs:424, PlanPrinter.cs:587 (both already present on the base): a door hidden in the view still gets a gap and a tag, a window still gets its windowGap, and ViewHiddenCategories is not consulted for doors, windows, furniture and fixtures.
  • SitePrinter.cs:212: property lines skip the view-visibility check (IsPlaced) that terrain, planting and entourage get.
  • SheetComposer.cs:709: the native viewport title prints the nominal scale, not the effectiveScale the view is actually drawn at after FitFrame.
  • PrintCommand.cs:222, PrintCommand.cs:364: a failure to read a --viewport-image file is reported as "Cannot write ", and test coverage of the flag is one case.
  • ElevationPrinterTests.cs:3572: five tests throw SkipException but are plain [Fact]/[Theory]; only SkippableFact / SkippableTheory turn that into a skip, so without a TrueType font they fail instead.
  • docs/printing.md:686 still lists property bearings, distances and setback lines as unsupported, while lines 137-140 and the comparison table (line 729) describe the property boundaries as drawn.
  • docs/public-api.md:87: SheetComposeOptions.ViewportImages and SheetViewportImage are not listed; SheetComposer.cs:117 has incomplete validation (raster null) and no tests for the invalid cases.
  • PlanPrinter.RoomTags.cs:67: LocalizeRoomArea depends on CultureInfo.CurrentUICulture. The docs describe this as intended, but the PDF then differs between machines for the same input.

Test gaps (minor)

  • TfBlockDeserializer.PlanRoomTags.cs:8 (ReadFamilyAnnotationCurve / ReadFamilyAnnotationArc) and the new ElementBuilder readers (ViewFacingLines, door symbols, fixture graphics, schedule rows, dimensions, notes, room colours) have no direct tests on synthetic blocks.
  • FillPatternTests.cs:12: FillHatch.DraftingTiles, ProjectModelGrid and the refusal branches of ProjectGrid, plus DecodePng edge cases, are untested.
  • PdfTrueTypeFontTests.cs:61: the bold-font and dashed-tile tests assert substrings of the content stream, not the page /Font dictionary or xref, so they would not have caught the font-name issue above.

A door or window that the view hides, by element or category, keeps
its opening in the wall and draws no leaf, glass, symbol or mark. The
saved opening marks of hidden hosts are not printed and still stand
in for the generated ones. Hidden stairs, railings and their top
rails draw no outline. A view that hides Property Lines prints
neither the boundaries nor their segment tags.

--viewport-image refuses a blank path, a file that is not a JPEG and
a viewport that is not on the printed sheets with a message that
names the viewport, before any page is composed. An unreadable file
exits with code 2. SheetComposer.RenderSheets applies the same check
and names the entry it throws for.

Tests cover each of these, the viewport title scale, the wall cut
clip window, column cuts and the plan labels written without a font.
The plan annotation, room colour, contour label, schedule row and
fixture graphics readers, and the family annotation curve reader, now
have tests on synthetic blocks. The readers become internal so the
tests reach them; their behaviour does not change.

The PNG decoder is tested for every scanline filter, the size and
chunk limits and the colour types it refuses. Fill pattern projection
and drafting tiles are tested on both sides of each limit. The embedded
font dictionaries, the page font resources and the cross-reference table
are checked object by object. Tests also pin that a clipped or built
geometry owns its view-facing line list.
The railing tube and round shaft projections are tested with a rail
turned about Z, a cylinder off the symbol origin and a non-zero
placement origin. The tests assert the printed endpoints and the
silhouette position, so a transposed matrix, centre or axis, or a
dropped origin, changes the result.

The door plan symbol and view-facing line readers of the GRep parser
are tested on a hand-built node queue: the conditions, curve checks,
side pairing and viewing directions they accept and refuse. A door
test pins that the family cutout inputs take the plan symbols of the
symbol with the placement of the instance. The reader entry points and
the walker state become internal so the tests reach them; their
behaviour does not change.
With the axis along y the offset test could not tell the depth term of
the pair check from a constant, so a pair along x with a line shifted
in depth is tested as well.
The saved opening tag of a door hidden through its element id is now
tested next to the hidden-category case. The changelog and the printing
guide named the viewport in every --viewport-image error; only the
JPEG, size and sheet checks do, so they now say which problems print
the usage text and which name the ID.
The mask, top projection and fixture graphics readers are tested on a
hand-built node queue: root filters with their conditions, faces with
EdgeLoops and Edges, and curves. The tests cover what each reader draws
and every rule it refuses on, including the detail condition ranges, the
hidden flags and the all-or-nothing handling of a branch.

The three readers become internal so the tests reach them; their
behaviour does not change.
A rail slanted along all three axes and placed by a rotation with nine distinct non-zero terms moves the printed endpoints for a mixed matrix row or a transposed matrix.
Cover the left versus upper-left and above versus upper-left ties of the Paeth predictor, an unknown comparison side of 8 beside a valid pair, and the 1e-9 limit on the difference of the two spacings.
The small-project lookup now takes the first sheet that has a number, as its skip message says.
mahach666 and others added 15 commits November 26, 2026 20:22
Opaque fine sections now omit the defining instances of model groups and their template members, so only placed geometry projects. A nearer projected slab side clips upright wall and railing profiles in every opaque fine section, not only in callouts. A fine section callout masks the projection behind a closed floor cut the way regular sections already mask a closed wall cut. Hidden-line fine sections render projected structural slab sides as a white base and approximate ambient shading from nearby blockers plus the distance from the side to the section plane, instead of tinting them with the material graphics colour. PlanPrinter stair-centre literals now use a 3 mm tolerance because the Test_2022 fixture is the same model with different ids and can differ by millimetres.
Dropping the defining instances of model groups and their template members cost 0.6% raster recall on the stair sheet: the reference draws that copy. The filter is removed and the unit test now asserts both the placed instance and its template project. Measured raster recall A105 92.0 -> 92.6, precision 93.5 -> 93.6, other sheets unchanged; print test classes 835/835 green on net8.0 and net10.0.
The bathtub basin is an inner loop of the fitting top face, and the face-union silhouette drew only the outer rim, so the basin and drain outline were missing from both plans. The plan now emits each top face inner loop after the silhouette. Measured: raster line score A102 recall 93.86 -> 94.00 with precision unchanged at 96.91; other sheets unchanged. Test updated to allow the longer inner-loop runs (over 90% of the furniture lines remain 5 mm grid edges). Print test classes 593/593 green on net8.0 and net10.0.
Raster scoring at 100 dpi with a 2 px match radius gives recall 98.6/94.2/94.0/95.8/96.3/92.6% and precision 99.1/93.2/96.9/93.4/95.6/93.6% for A001 and A101-A105. The residual is not missing geometry in most places: A105 reaches 98.8/99.7% at 300 dpi because the reference page is a raster whose thin lines survive resampling, and A101 worst blocks are inside the Solar Analysis study, where the decoded site contours, the pad faces and the terrain mesh boundary and creases were each measured and rejected. A103 loses one block to a small hatched site element the reference draws and we omit; exempting the placed-site category filter did not bring it back.
…ing occlusion

The 0%-recall block at the lower left of A103 is the topography cut cap: a 13 m x 0.21 m section polygon at the section plane, drawn unhatched while the reference fills it. Its hatch pitch matches no decoded cut pattern (site cut 6.35 mm brick, concrete 6-11 mm, both sub-pixel at 1:100). The larger A103 gaps are the South elevation guardrail bars, decoded at view depth -18200 but dropped by the occlusion pass behind the railing own nearer faces; exempting railings from that occlusion raises recall by 0.1-0.3% on A103/A104/A105 but costs up to 2.3% precision on A104, so the occlusion stands.
Instrumenting OccludeEdges on the five bars at view depth -18200 names the occluders: the railing own near face (566588, -18203), a floor slab (550255 Generic 150mm, -18202) and a clad wall (427092 Wall - Timber Clad, -18404). No glass pane is involved. Exempting the railing alone restores no bar, and a 5 mm envelope around the bar restores some on A104/A105 only: A103 95.8/93.4 unchanged, A104 96.3/95.6 -> 96.6/93.8, A105 92.6/93.6 -> 92.9/93.3. All variants lose more precision than they gain, so the occlusion stands. Print classes 650/650 on net8.0 and net10.0.
Dumping the decoded polygons of the presumed occluders shows the clad wall and the floor slab never contain the five bars: the wall spans x 13.06-13.26 m and the floor sits at z -0.70..-0.55 m, below the bars at -0.30..0.40 m. Every bar is covered only by the railing itself (566588, faces 3 mm nearer) and its nested symbol (566589, 14 mm nearer). Exempting the assembly envelope restores the bars: A103 95.8 -> 96.1 at unchanged precision and A001 98.6 -> 98.7, but A104 precision falls 95.6 -> 93.8 for +0.3 recall and A105 92.6 -> 92.3. Restricting to horizontal bars leaves A104 at 93.7. The net score drops in every variant, so the occlusion stands. Print classes 650/650 on net8.0 and net10.0; the print itself is unchanged at 98.6/94.2/94.0/95.8/96.3/92.6 recall and 99.1/93.2/96.9/93.4/95.6/93.6 precision.
A railing repeats every bar in its element and in the nested symbol it places, and the copies project within a millimetre of each other, so both were inked. DedupeEdges now groups the horizontal railing bars within a one-millimetre tolerance and keeps the copy nearest the viewer; a second bar more than 20 mm behind stays its own line. Measured: raster line score A001 recall 98.6 -> 98.7, A103 95.8 -> 95.9 with precision 93.4 -> 93.5; A101, A102, A104 and A105 unchanged. New test Collect_KeepsOneOfTwoCoincidentRailingBars fails without the pass and passes with it. Print classes 651/651 on net8.0 and net10.0.
Instrumenting both views shows the un-hidden bars split the same way: A103 adds 2171 pixels on the reference and 2173 off it, A104 1149 against 1456. A104 off-reference ink is concentrated on the bottom rails, which the reference hides behind the solid base band while the bars between the posts stay visible. The railing materials Stainless Steel 1 and Iron Gray decode transparency 0, so no glass pane is involved. An extent-based exemption (the covering face must match the bar projected rectangle within 2 mm) leaves A103 at 95.9/93.5 and loses A001 0.1, because the covering face is a panel taller than the bar. Railing rails print as symbolic elevation lines in the reference; the decode carries no such lines (ViewFacingLines is empty on both railing elements), so reproducing them needs a railing display rule rather than an occlusion exemption. No code change; the print stays at 98.7/94.2/94.0/95.9/96.3/92.6 recall and 99.1/93.2/96.9/93.5/95.6/93.6 precision.
… to a midpoint test

The railing type 490129 stores no family or geometry, and both railing elements report zero ViewFacingLines and zero Edges while their faces are the modelled rails; 118 other elements carry view-facing lines, so the decoder is not the limit. The South elevation bars run from 7.06 to 13.06 m with their midpoint at 10.06 m, exactly behind the post at 10.05-10.07 m, so the midpoint occlusion test drops the whole bar. Clipping each bar around the railing faces it crosses restores the segmented bars: A103 96.0/93.2 alone and 96.2/93.2 with a 2 mm filter against neighbouring rails, but A104 loses 1.8-2.0 precision and A105 0.3, so the net score drops and the clip is reverted. A faithful fix has to clip per span against the real 3D occluders of each bar copy. No code change; the print stays at 98.7/94.2/94.0/95.9/96.3/92.6 recall with 99.1/93.2/96.9/93.5/95.5/93.6 precision (the raster score jitters by 0.1 between runs: two prints of the same tree differ by 115 ink pixels on A104).
Clipping each horizontal railing bar against every nearer face instead of hiding it at the midpoint restores the A103 bars and raises recall on all three sheets: A103 96.4/92.6, A104 96.6/93.7, A105 92.8/93.0 against the baseline 95.9/93.5, 96.3/95.5, 92.6/93.6. Recall gains 1.0 point in total, precision loses 3.3. The bars the reference omits are the ones that sit inside a solid rail: the polygon clip covers their projection but leaves the millimetre that sticks out, and the projected approximation cannot tell a bar inside the rail from a bar beside it. Dropping them needs a point-in-solid test against the railing B-rep shells, which the decoder does not have. The clip is reverted; the print stays at 98.7/94.2/94.0/95.9/96.3/92.6 recall and 99.1/93.2/96.9/93.5/95.5/93.6 precision.

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