Skip to content
Open
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
10 changes: 8 additions & 2 deletions CadRevealComposer.Tests/BoundingBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ namespace CadRevealComposer.Tests;

using System.Drawing;
using System.Numerics;
using Primitives;
using Tessellation;

public class BoundingBoxTests
{
Expand Down Expand Up @@ -68,4 +66,12 @@ public void Extents_ReturnsSizeInAllDimensions()
var extents = new Vector3(3, 3, 3);
Assert.That(boundingBox.Extents, Is.EqualTo(extents));
}

[Test]
public void Volume_CalculatesCorrectVolume()
{
var boundingBox = new BoundingBox(new Vector3(1, 2, 3), new Vector3(4, 6, 8));
const float expectedVolume = 3 * 4 * 5; // Extents.X * Extents.Y * Extents.Z
Assert.That(boundingBox.Volume, Is.EqualTo(expectedVolume));
}
}
7 changes: 6 additions & 1 deletion CadRevealComposer/CadRevealNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace CadRevealComposer;
using System.Numerics;
using Primitives;
using ProtoBuf;
using Tessellation;
using Utils;

[ProtoContract(SkipConstructor = true)]
Expand All @@ -29,6 +28,12 @@ public record BoundingBox([property: ProtoMember(1)] Vector3 Min, [property: Pro
/// </summary>
public Vector3 Extents => (Max - Min);

/// <summary>
/// The Volume of the bounding box
/// Expressed as Extents.X * Extents.Y * Extents.Z
/// </summary>
public float Volume => Extents.X * Extents.Y * Extents.Z;

/// <summary>
/// Combine two bounds
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class PrioritySplittingUtils
/// <summary>
/// These disciplines have limited amount of data and high highlighting value.
/// </summary>
private static readonly string[] PrioritizedDisciplines = ["PIPE", "ELEC", "SAFE", "INST", "TELE"];
private static readonly string[] PrioritizedDisciplines = ["PIPE", "ELEC", "SAFE", "INST", "TELE", "MECH"];

public static void SetPriorityForPrioritySplittingWithMutation(IReadOnlyList<CadRevealNode> nodes)
{
Expand Down Expand Up @@ -48,10 +48,30 @@ private static void SetPriorityOnNodesAndChildren(IEnumerable<CadRevealNode> nod
{
foreach (var node in nodes)
{
var allChildren = CadRevealNode.GetAllNodesFlat(node);
foreach (var child in allChildren)
var allChildren = CadRevealNode.GetAllNodesFlat(node).ToList();

if (node.Attributes["Discipline"] == "MECH" && allChildren.Count > 10)
{
// This code assumes the nodes that get here are "Tag" nodes.
// Prioritize the largest geometries, to avoid the priority sector being too large
var geometriesToPrioritize = allChildren
.SelectMany(childNode => childNode.Geometries.Select(primitive => (childNode, primitive)))
.OrderByDescending(nx => nx.primitive.AxisAlignedBoundingBox.Volume) // Volume here is arbitrary. It will prioritize diagonal "beams". But may be better than just "Diagonal"?
.Take((int)Math.Clamp(allChildren.Count * 0.4f, min: 5, max: 100)); // Arbitrary values

foreach ((CadRevealNode childNode, APrimitive primitive) in geometriesToPrioritize)
{
childNode.Geometries = childNode
.Geometries.Select(g => g == primitive ? g with { Priority = 1 } : g)
.ToArray();
}
}
else
{
child.Geometries = child.Geometries.Select(g => g with { Priority = 1 }).ToArray();
foreach (var child in allChildren)
{
child.Geometries = child.Geometries.Select(g => g with { Priority = 1 }).ToArray();
}
}
}
}
Expand Down
Loading