Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="Microsoft.Data.Sqlite" Version="10.0.15" />
<PackageVersion Include="SkiaSharp" Version="$(SkiaSharpVersion)" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="$(SkiaSharpVersion)" />
<PackageVersion Include="PclIO.Scene" Version="0.1.2" />
<PackageVersion Include="PclIO.Scene" Version="0.1.3" />
<PackageVersion Include="RvtIO.Scene" Version="0.5.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Built clean-room under the [IOExtend](https://github.com/IOExtend) organization.
- display modes (materials, textures, white, wireframe), viewport background color, grid lines and a global opacity slider;
- saved viewpoints with a viewpoint tour, clash results, a 4D schedule player and linked-file visibility, each shown only when the document has that data.
- Imports binary glTF 2.0 (`.glb`), Wavefront OBJ (`.obj`), and JSON: viewer JSON, IOScene scene files and IOViewer 0.1/0.2 snapshots.
- Displays point clouds with source RGB when available and a top-down minimap. The CLI includes Leica LGSX camera panoramas, FARO FLS colour panoramas and registered sets of E57 camera images. Select a station on the minimap to open its photograph.
- Displays point clouds with source RGB when available and a top-down minimap. The CLI includes Leica LGSx camera panoramas, legacy Leica LGS JPEG XR panoramas on Windows, FARO FLS colour panoramas and registered sets of E57 camera images. Select a station or use **Open photo panorama…** at the bottom of the minimap.

### Mouse and keyboard

Expand Down
9 changes: 8 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ arrow keys to look around, and use the wheel to zoom. Arrows inside the photogra
heading. The minimap remains available while the photo panel is open. The generated HTML embeds the photographs.

Use **Enlarge** to expand a panorama. Pick a minimap size, drag the plan to pan it and use the wheel or the zoom buttons to change its scale.
Use **Intensity** to view the scan points from the panorama's station, shaded by their measured laser signal.
Viewer JSON can carry `PointIntensities` as base64 display-intensity bytes keyed by point geometry id, one byte per vertex.
Zero indicates a missing measurement. A panorama's optional `IntensityJpeg` is used where the measured points are unavailable.
The blue spheres mark camera positions in the 3D view. Click a sphere to open its panorama. Use **Panorama spheres in 3D**
on the minimap to hide or show the spheres. The spheres follow the selected height band and the model's visibility.
The **+** beside the level list starts a level from two clicks in a panorama, lower elevation first. Each elevation comes from the
sampled scan point at that location. Selecting a level filters the map points and stations to that height range. Clear station groups
separated vertically by more than 2 m can create levels automatically. Use **All heights** to return to the full plan. Level ranges
are saved in the browser for that HTML file when local storage is available.

Click a point to select its scan. Orbit and zoom anchor to the point under the cursor. The distance tool snaps to nearby visible
scan points. The **White** display mode and the opacity slider also apply to clouds. Section planes and both
section box modes clip points and meshes together. Wireframe and surface textures apply to meshes.

- Left click selects, Ctrl+click adds or removes, a click on empty space clears the selection.
- Left drag orbits around the point under the cursor; middle or right drag pans; the wheel zooms towards the cursor.
- Shift+left drag selects with a box: left to right selects objects fully inside, right to left selects objects it touches.
Expand All @@ -167,7 +174,7 @@ are saved in the browser for that HTML file when local storage is available.
Esc press handles one action.

In the **Sections** panel, enable **Fill cut faces** to fill the cross-sections of consistently wound, closed meshes.
The fill is visual. Picking and measurement continue to use model triangles. Large models take extra work while
The fill is visual. Picking and measurement continue to use the source geometry. Large models take extra work while
fill is enabled.

Turn a section box around Z with the blue ring or the **Rotation around Z** slider. Face handles resize along the
Expand Down
104 changes: 104 additions & 0 deletions src/IOViewer.Cli/JpegXr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using SkiaSharp;

namespace IOViewer.Cli;

[SupportedOSPlatform("windows")]
internal static class JpegXr
{
private static readonly Guid DecoderClass = new("a26cec36-234c-4950-ae16-e34aace71d0d");
private static readonly Guid Bgr24 = new("6fddc324-4e03-4bfe-b185-3d77768dc90c");
private static readonly Guid Gray8 = new("6fddc324-4e03-4bfe-b185-3d77768dc908");
private const int ChangedApartment = unchecked((int)0x80010106);

internal static SKBitmap Decode(byte[] image, int maxSide)
{
int apartment = CoInitializeEx(0, 0);
if (apartment != ChangedApartment) Marshal.ThrowExceptionForHR(apartment);
nint stream = 0;
Decoder? decoder = null;
BitmapFrame? frame = null;
try
{
stream = SHCreateMemStream(image, image.Length);
if (stream == 0) throw new InvalidDataException("Could not open the JPEG XR memory stream.");
Guid iid = typeof(Decoder).GUID;
Marshal.ThrowExceptionForHR(CoCreateInstance(in DecoderClass, 0, 1, in iid, out decoder));
decoder.Initialize(stream, 0);
decoder.GetFrame(0, out frame);
frame.GetSize(out uint width, out uint height);
frame.GetPixelFormat(out Guid format);
if (width < 2 || width != height || width > maxSide || (ulong)width * height > 32 * 1024 * 1024)
throw new InvalidDataException("Invalid JPEG XR panorama face dimensions.");
if (format != Bgr24 && format != Gray8)
throw new InvalidDataException("The JPEG XR panorama face must carry 24-bit BGR or 8-bit grayscale.");

int size = (int)width;
int stride = format == Gray8 ? size : 3 * size;
var bytes = new byte[stride * size];
frame.CopyPixels(0, stride, bytes.Length, bytes);
var pixels = new SKColor[size * size];
if (format == Gray8)
{
for (int i = 0; i < pixels.Length; i++) pixels[i] = new SKColor(bytes[i], bytes[i], bytes[i]);
}
else
{
for (int i = 0; i < pixels.Length; i++)
pixels[i] = new SKColor(bytes[3 * i + 2], bytes[3 * i + 1], bytes[3 * i]);
}
return new SKBitmap(size, size) { Pixels = pixels };
}
catch (COMException ex)
{
throw new InvalidDataException("The Windows JPEG XR decoder could not read the panorama face.", ex);
}
finally
{
if (frame != null) Marshal.ReleaseComObject(frame);
if (decoder != null) Marshal.ReleaseComObject(decoder);
if (stream != 0) Marshal.Release(stream);
if (apartment >= 0) CoUninitialize();
}
}

[DllImport("ole32.dll", ExactSpelling = true)]
private static extern int CoInitializeEx(nint reserved, int apartment);

[DllImport("ole32.dll", ExactSpelling = true)]
private static extern void CoUninitialize();

[DllImport("ole32.dll", ExactSpelling = true)]
private static extern int CoCreateInstance(in Guid clsid, nint outer, int context, in Guid iid,
[MarshalAs(UnmanagedType.Interface)] out Decoder decoder);

[DllImport("shlwapi.dll", ExactSpelling = true)]
private static extern nint SHCreateMemStream(byte[] data, int size);

[ComImport, Guid("9edde9e7-8dee-47ea-99df-e6faf2ed44bf"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface Decoder
{
void QueryCapability(nint stream, out uint capability);
void Initialize(nint stream, int cacheOptions);
void GetContainerFormat(out Guid format);
void GetDecoderInfo(out nint info);
void CopyPalette(nint palette);
void GetMetadataQueryReader(out nint reader);
void GetPreview(out nint preview);
void GetColorContexts(uint count, nint contexts, out uint actual);
void GetThumbnail(out nint thumbnail);
void GetFrameCount(out uint count);
void GetFrame(uint index, out BitmapFrame frame);
}

[ComImport, Guid("3b16811b-6a43-4ec9-a813-3d930c13b940"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface BitmapFrame
{
void GetSize(out uint width, out uint height);
void GetPixelFormat(out Guid format);
void GetResolution(out double dpiX, out double dpiY);
void CopyPalette(nint palette);
void CopyPixels(nint rectangle, int stride, int size, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] bytes);
}
}
10 changes: 10 additions & 0 deletions src/IOViewer.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ private static ViewerDocument FromPcl(string path, out IReadOnlyList<SceneDiagno
bool showIntensity = cloud.Kind is PclFileKind.LeicaLgsx or PclFileKind.LeicaLgs;
var captured = new Dictionary<int, List<byte>>();
var colored = new HashSet<int>();
var capturedIntensities = new Dictionary<int, List<byte>>();
var withIntensity = new HashSet<int>();
var sceneOptions = new PclSceneOptions
{
SubsampleStep = step,
Expand All @@ -397,6 +399,8 @@ private static ViewerDocument FromPcl(string path, out IReadOnlyList<SceneDiagno
diagnostics = messages;
var viewer = FromScene(path, result.Document, diagnostics);
foreach (int geometry in colored) viewer.PointColors.Add(geometry, captured[geometry].ToArray());
foreach (int geometry in withIntensity)
viewer.PointIntensities.Add(geometry, capturedIntensities[geometry].ToArray());
messages.RemoveAll(diagnostic => diagnostic.Code == "colours-dropped");
ScanPhotographs.Add(cloud, viewer, messages);
return viewer;
Expand All @@ -409,6 +413,12 @@ void CaptureColor(int geometry, PclPoint point)
bytes.Add(color.R);
bytes.Add(color.G);
bytes.Add(color.B);
if (!showIntensity) return;
if (!capturedIntensities.TryGetValue(geometry, out var levels)) capturedIntensities[geometry] = levels = [];
byte intensity = point.Intensity is float signal && float.IsFinite(signal)
? (byte)(1 + MathF.Round(254 * MathF.Sqrt(Math.Clamp(signal, 0, 1)))) : (byte)0;
if (intensity != 0) withIntensity.Add(geometry);
levels.Add(intensity);
}
}

Expand Down
Loading