Skip to content

Commit

Permalink
Merge branch 'master' into ifc-representation-instances
Browse files Browse the repository at this point in the history
  • Loading branch information
srudenkoamc authored Nov 29, 2023
2 parents 46acce6 + b905514 commit be7f14d
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 124 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
- `Polyline.TransformAt` returns correct transformations when parameter on domain is provided.
- `IndexedPolycurve` constructor that takes list of `BoundedCurve` now produces `CurveIndices` that share vertices and are withing index range. This means `IndexedPolyline.TransformedPolyline` preserves `CurveIndicies` on new `IndexedPolyline`.
- `BoundedCurve.ToPolyline` now works correctly for `EllipticalArc` class.
- `Ray.Intersects(Topography)` and `Ray.Intersects(Mesh)` would sometimes return a different intersection than the closest one.
- `Ray.Intersects(Topography)` now considers the topography's transform.

### Changed

Expand Down
4 changes: 2 additions & 2 deletions Elements.Serialization.IFC/src/IFCElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ private static IfcDoor ToIfc(this Door door, Guid id, IfcLocalPlacement localPla
localPlacement,
shape,
null,
new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.ClearHeight)),
new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.ClearWidth)),
new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.DoorHeight)),
new IfcPositiveLengthMeasure(new IfcLengthMeasure(door.DoorWidth)),
IfcDoorTypeEnum.DOOR,
door.GetIfcDoorTypeOperation(),
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public GeometricElement ConvertToElement(IfcProduct ifcProduct, RepresentationDa
//var wall = GetWallFromDoor(ifcDoor, allWalls);
var doorWidth = (IfcLengthMeasure)ifcDoor.OverallWidth;
var doorHeight = (IfcLengthMeasure)ifcDoor.OverallHeight;
var doorThickness = Door.DEFAULT_DOOR_THICKNESS;

var result = new Door(doorWidth,
doorHeight,
Door.DOOR_THICKNESS,
doorThickness,
openingSide,
openingType,
transform: repData.Transform,
Expand Down
4 changes: 2 additions & 2 deletions Elements.Serialization.IFC/test/IFCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void Doors()
var wall1 = new StandardWall(wallLine1, 0.2, 3, name: "Wall1");
var wall2 = new StandardWall(wallLine2, 0.2, 2, name: "Wall2");

var door1 = new Door(wallLine1, 0.5, 1.5, 2.0, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
var door2 = new Door(wallLine2, 0.5, 1.5, 1.8, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
var door1 = new Door(wallLine1, 0.5, 1.5, 2.0, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);
var door2 = new Door(wallLine2, 0.5, 1.5, 1.8, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.DoubleSwing);

wall1.AddDoorOpening(door1);
wall2.AddDoorOpening(door2);
Expand Down
169 changes: 86 additions & 83 deletions Elements/src/BIM/Door/Door.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Elements/src/BIM/Door/DoorRepresentationStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Elements
{
static class DoorRepresentationStorage
public static class DoorRepresentationStorage
{
private static readonly Dictionary<string, List<RepresentationInstance>> _doors = new Dictionary<string, List<RepresentationInstance>>();
public static Dictionary<string, List<RepresentationInstance>> Doors => _doors;
Expand Down
19 changes: 13 additions & 6 deletions Elements/src/Geometry/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public Triangle AddTriangle(Triangle t)
public void RemoveTriangle(Triangle face)
{
this.Triangles.Remove(face);
foreach(var vert in face.Vertices) {
foreach (var vert in face.Vertices)
{
vert.Triangles.Remove(face);
}
}
Expand Down Expand Up @@ -450,25 +451,31 @@ public List<Polyline> GetNakedBoundaries()
}

/// <summary>
/// Does the provided ray intersect this mesh mesh?
/// Does the provided ray intersect this mesh?
/// </summary>
/// <param name="ray">The Ray to intersect.</param>
/// <param name="intersection">The location of intersection.</param>
/// <param name="intersection">The location of the closest intersection.</param>
/// <returns>True if an intersection result occurs.
/// False if no intersection occurs.</returns>
public bool Intersects(Ray ray, out Vector3 intersection)
{
var nearbyVertices = GetOctree().GetNearby(ray, _maxTriangleSize).ToList();
var nearbyTriangles = nearbyVertices.SelectMany(v => v.Triangles).Distinct();
intersection = default;
var closest = double.MaxValue;
foreach (var t in nearbyTriangles)
{
if (ray.Intersects(t, out intersection))
if (ray.Intersects(t, out var triangleIntersection))
{
return true;
var d = triangleIntersection.DistanceTo(ray.Origin);
if (d < closest)
{
intersection = triangleIntersection;
closest = d;
}
}
}
return false;
return closest < double.MaxValue;
}

private double SignedVolumeOfTriangle(Triangle t)
Expand Down
10 changes: 9 additions & 1 deletion Elements/src/Geometry/Ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,15 @@ public bool Intersects(Plane plane, out Vector3 result, out double t)
/// False if no intersection occurs.</returns>
public bool Intersects(Topography topo, out Vector3 result)
{
return Intersects(topo.Mesh, out result);
var transform = topo.Transform;
var inverse = transform.Inverted();
var transformedRay = new Ray(inverse.OfPoint(Origin), Direction);
var intersects = transformedRay.Intersects(topo.Mesh, out result);
if (intersects)
{
result = transform.OfPoint(result);
}
return intersects;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Elements/test/DoorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void MakeDoorElement()

var line = new Line(new Vector3(0, 0, 0), new Vector3(10, 10, 0));
var wall = new StandardWall(line, 0.1, 3.0);
var door = new Door(wall.CenterLine, 0.5, 2.0, 2.0, Door.DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.SingleSwing);
var door = new Door(wall.CenterLine, 0.5, 2.0, 2.0, Door.DEFAULT_DOOR_THICKNESS, DoorOpeningSide.LeftHand, DoorOpeningType.SingleSwing);
wall.AddDoorOpening(door);

Assert.Single(wall.Openings);
Expand Down
47 changes: 20 additions & 27 deletions Elements/test/RayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Xunit.Abstractions;
using System.Diagnostics;
using Vertex = Elements.Geometry.Vertex;
using Xunit.Sdk;
using System.Linq;

namespace Elements.Tests
{
Expand Down Expand Up @@ -63,43 +65,34 @@ public void RayIntersectsTopography()
{
this.Name = "RayIntersectTopo";

var elevations = new double[25];
var elevations = new double[100];

int e = 0;
for (var x = 0; x < 5; x++)
for (var x = 0; x < 10; x++)
{
for (var y = 0; y < 5; y++)
for (var y = 0; y < 10; y++)
{
elevations[e] = Math.Sin(((double)x / 5.0) * Math.PI) * 10;
elevations[e] = Math.Sin(((double)x / 10.0) * Math.PI) * 5;
e++;
}
}
var topo = new Topography(Vector3.Origin, 4, elevations);
var topo = new Topography(Vector3.Origin, 10, elevations)
{
Material = new Material("topo", new Color(0.5, 0.5, 0.5, 0.5)),
Transform = new Transform(0, 0, 2)
};
this.Model.AddElement(topo);

var modelPoints = new ModelPoints(new List<Vector3>(), new Material("begin", Colors.Blue));
this.Model.AddElement(modelPoints);
foreach (var t in topo.Mesh.Triangles)
this.Model.AddElements(new Transform().ToModelCurves());
for (int i = 1; i < 9; i++)
{
var c = Center(t);
var o = new Vector3(c.X, c.Y);
modelPoints.Locations.Add(o);

var ray = new Ray(o, Vector3.ZAxis);

Vector3 xsect;
if (ray.Intersects(t, out xsect))
for (int j = 1; j < 9; j++)
{
try
{
var l = new Line(o, xsect);
var ml = new ModelCurve(l);
this.Model.AddElement(ml);
}
catch
{
continue;
}
var newRay = new Ray(new Vector3(i, j, 40), Vector3.ZAxis.Negate());
var intersect = newRay.Intersects(topo, out var result2);
Assert.True(intersect);
var line = new Line(result2, newRay.Origin);
Model.AddElement(new ModelCurve(line, BuiltInMaterials.XAxis));
Assert.True(result2.Z > elevations.Min() + 2 && result2.Z < elevations.Max() + 2);
}
}
}
Expand Down

0 comments on commit be7f14d

Please sign in to comment.