Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facade_Engine: Improved Adjacency Methods and Added CurtainWall Methods #2569

Merged
Merged
29 changes: 17 additions & 12 deletions Facade_Engine/Compute/AdjacentElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ public static partial class Compute
[Input("element", "Element to find adjacencies at.")]
[Input("referenceElements", "Elements to use to find element adjacencies.")]
[Output("adjacentElements", "Adjacents elements to the provided element.")]
public static List<IElement2D> AdjacentElements(this IElement2D element, List<IElement2D> referenceElements)
public static List<IElement2D> AdjacentElements(this IElement2D element, IEnumerable<IElement2D> referenceElements)
{
List<IElement2D> adjacentElements = new List<IElement2D>();

if (element == null || referenceElements == null)
return adjacentElements;
{
Reflection.Compute.RecordWarning("Can not get adjacencies of a null element.");
return null;
}

PolyCurve outline = element.OutlineCurve();

foreach (IElement2D refElem in referenceElements)
{
PolyCurve refOutline = refElem.OutlineCurve();
BH.oM.Reflection.Output<Point, Point> results = outline.CurveProximity(refOutline);
double distance = results.Item1.Distance(results.Item2);
if (distance < Tolerance.Distance)
if (refOutline.IIsAdjacent(outline))
adjacentElements.Add(refElem);
}

Expand All @@ -74,21 +75,22 @@ public static List<IElement2D> AdjacentElements(this IElement2D element, List<IE
[Input("element", "Element to find adjacencies at.")]
[Input("referenceElements", "Elements to use to find element adjacencies.")]
[Output("adjacentElements", "Adjacents elements to the provided element.")]
public static List<IElement2D> AdjacentElements(this IElement1D element, List<IElement2D> referenceElements)
public static List<IElement2D> AdjacentElements(this IElement1D element, IEnumerable<IElement2D> referenceElements)
{
List<IElement2D> adjacentElements = new List<IElement2D>();

if (element == null || referenceElements == null)
return adjacentElements;
{
Reflection.Compute.RecordWarning("Can not get adjacencies of a null element.");
return null;
}

PolyCurve outline = element.ElementCurves().IJoin()[0];

foreach (IElement2D refElem in referenceElements)
{
PolyCurve refOutline = refElem.OutlineCurve();
BH.oM.Reflection.Output<Point, Point> results = refOutline.CurveProximity(outline);
double distance = results.Item1.Distance(results.Item2);
if (distance < Tolerance.Distance)
if (refOutline.IIsAdjacent(outline))
adjacentElements.Add(refElem);
}

Expand All @@ -102,11 +104,14 @@ public static List<IElement2D> AdjacentElements(this IElement1D element, List<IE
[Input("element", "Element to find adjacencies at.")]
[Input("referenceElements", "Elements to use to find element adjacencies.")]
[Output("adjacentElements", "Adjacent elements to the provided element.")]
public static List<IElement1D> AdjacentElements(this IElement1D element, List<IElement1D> referenceElements)
public static List<IElement1D> AdjacentElements(this IElement1D element, IEnumerable<IElement1D> referenceElements)

{
if (element == null || referenceElements == null)
return new List<IElement1D>();
{
Reflection.Compute.RecordWarning("Can not get adjacencies of a null element.");
return null;
}

return referenceElements.Where(x => x.IIsAdjacent(element)).ToList();
}
Expand Down
10 changes: 10 additions & 0 deletions Facade_Engine/Compute/ComponentAreas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public static partial class Compute
[MultiOutput(1, "frameArea", "Adjacent Elements per adjacent edge")]
public static Output<double, double> ComponentAreas(this Opening opening)
{
if (opening == null)
{
Reflection.Compute.RecordWarning("Component areas can not be calculated for a null opening.");
return new Output<double, double>
{
Item1 = double.NaN,
Item2 = double.NaN,
};
}

IGeometry frameGeo = opening.FrameGeometry2D();
double frameArea = 0;

Expand Down
12 changes: 7 additions & 5 deletions Facade_Engine/Compute/EdgeAdjacencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ public static partial class Compute
[Input("tolerance", "Tolerance is the minimum overlap amount required to consider adjacent.")]
[MultiOutput(0, "adjacentEdges", "Adjacent edges.")]
[MultiOutput(1, "adjacentElems", "Adjacent Elements per adjacent edge.")]
public static Output<List<IElement1D>, List<IElement2D>> EdgeAdjacencies(this IElement1D edge, List<IElement2D> elements, double tolerance = Tolerance.Distance)
public static Output<List<IElement1D>, List<IElement2D>> EdgeAdjacencies(this IElement1D edge, IEnumerable<IElement2D> elements, double tolerance = Tolerance.Distance)
{
if (edge == null || elements == null)
{
Reflection.Compute.RecordWarning("Can not get adjacencies of a null element.");
return null;
}

List<IElement1D> adjEdges = new List<IElement1D>();
List<IElement2D> adjElems = new List<IElement2D>();

//List<IElement2D> adjFullElems = AdjacentElements(edge, elems);
PolyCurve edgeGeo = edge.ElementCurves().IJoin()[0];
Vector edgeDir = edge.IGeometry().IEndDir();

foreach (IElement2D elem in elements)
{
List<IElement1D> edges = elem.IOutlineElements1D();
Expand Down
23 changes: 17 additions & 6 deletions Facade_Engine/Compute/FacadeAreasByConstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,36 @@ public static partial class Compute
[MultiOutput(0, "areas", "Total area per each unique Construction. These areas account for decreased areas for openings where frame edges occur.")]
[MultiOutput(1, "constructions", "Construction corresponding to each area value in areas.")]
[MultiOutput(2, "frameArea", "Total frame area.")]
public static Output<List<double>, List <string>, double> FacadeAreasByConstruction(this List<IFacadeObject> elems)
public static Output<List<double>, List <string>, double> FacadeAreasByConstruction(this IEnumerable<IFacadeObject> elems)
{
if (elems.Any(x => x is Panel == false & x is Opening == false))
if(elems == null)
{
Reflection.Compute.RecordWarning("Some of the provided elements are not Openings or Panels. These elements have been ignored.");
BH.Engine.Reflection.Compute.RecordError("Cannot calculate facade areas if the input elements are null.");
return new Output<List<double>, List<string>, double>();
}

List<IFacadeObject> elemList = elems.ToList();
if (elems.Any(x => !(x is Panel) && !(x is Opening) && !(x is CurtainWall)))
Reflection.Compute.RecordWarning("Some of the provided elements are not valid Facade Element Types. These elements have been ignored.");

Dictionary<string, double> areasDict = new Dictionary<string, double>();
double frameArea = 0;

IEnumerable<CurtainWall> cws = elems.OfType<CurtainWall>();
foreach (CurtainWall cw in cws.ToList())
{
List<Opening> cwOpenings = cw.Openings;
elemList.AddRange(cwOpenings);
}

IEnumerable<Panel> panels = elems.OfType<Panel>();

foreach (Panel panel in panels.ToList())
{
List<Opening> panelOpenings = panel.Openings;
elems.AddRange(panelOpenings);
elemList.AddRange(panelOpenings);
}

List<IFacadeObject> uniqueElems = elems.Distinct().ToList();
List<IFacadeObject> uniqueElems = elemList.Distinct().ToList();

foreach (IFacadeObject elem in uniqueElems)
{
Expand Down
6 changes: 6 additions & 0 deletions Facade_Engine/Compute/UValueOpeningCAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public static partial class Compute
[Output("effectiveUValue", "Effective U-value result of opening calculated using CAM.")]
public static OverallUValue UValueOpeningCAM(this Opening opening)
{
if (opening == null)
{
Reflection.Compute.RecordWarning("U Value can not be calculated for a null opening.");
return null;
}

double glassArea = opening.ComponentAreas().Item1;

List<IFragment> glassUValues = opening.GetAllFragments(typeof(UValueGlassCentre));
Expand Down
6 changes: 6 additions & 0 deletions Facade_Engine/Compute/UValueOpeningSAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public static partial class Compute
[Output("effectiveUValue", "Effective U-value result of opening caclulated using SAM.")]
public static OverallUValue UValueOpeningSAM(this Opening opening)
{
if (opening == null)
{
Reflection.Compute.RecordWarning("U Value can not be calculated for a null opening.");
return null;
}

double area = opening.Area();

List<IFragment> uValues = opening.GetAllFragments(typeof(UValueGlassCentre));
Expand Down
19 changes: 13 additions & 6 deletions Facade_Engine/Compute/UniqueAdjacencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ public static partial class Compute
[MultiOutput(2, "uniqueAdjacencyElement1", "The first element of each pair per each unique adjacency.")]
[MultiOutput(3, "uniqueAdjacencyEdge2", "The second edge of each pair per each unique adjacency.")]
[MultiOutput(4, "uniqueAdjacencyElement2", "The second element of each pair per each unique adjacency.")]

public static Output<List<string>, List<List<IElement1D>>, List<List<IElement2D>>, List<List<IElement1D>>, List<List<IElement2D>>> UniqueAdjacencies(List<IElement2D> elems, bool splitHorAndVert = false)
public static Output<List<string>, List<List<IElement1D>>, List<List<IElement2D>>, List<List<IElement1D>>, List<List<IElement2D>>> UniqueAdjacencies(IEnumerable<IElement2D> elems, bool splitHorAndVert = false)
{
if(elems == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot calculate unique adjacencies if the input elements are null.");
return new Output<List<string>, List<List<IElement1D>>, List<List<IElement2D>>, List<List<IElement1D>>, List<List<IElement2D>>>();
}

List<IElement2D> elemsList = elems.ToList();

List<string> adjacencyIDs = new List<string>();
List<List<IElement1D>> adjEdges = new List<List<IElement1D>>();
List<List<IElement2D>> adjElems = new List<List<IElement2D>>();
Expand All @@ -68,13 +75,13 @@ public static Output<List<string>, List<List<IElement1D>>, List<List<IElement2D>
foreach (Panel panel in panels.ToList())
{
List<Opening> panelOpenings = panel.Openings;
elems.AddRange(panelOpenings);
elemsList.AddRange(panelOpenings);
}
List<IElement2D> uniqueElems = elems.Distinct().ToList();
List<IElement2D> uniqueElems = elemsList.Distinct().ToList();

foreach (IElement2D elem in elems)
foreach (IElement2D elem in uniqueElems)
{
List<IElement2D> tempElems = elems.Except(new List<IElement2D> { elem }).ToList();
List<IElement2D> tempElems = uniqueElems.Except(new List<IElement2D> { elem }).ToList();
foreach (IEdge edge in elem.IOutlineElements1D())
{
BH.oM.Reflection.Output<List<IElement1D>, List<IElement2D>> result = edge.EdgeAdjacencies(tempElems);
Expand Down
2 changes: 1 addition & 1 deletion Facade_Engine/Facade_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<Compile Include="Modify\SetOffsetFromFacetoFaceDist.cs" />
<Compile Include="Modify\OffsetVariable.cs" />
<Compile Include="Modify\Transform.cs" />
<Compile Include="Query\AdjacencyId.cs" />
<Compile Include="Query\AdjacencyID.cs" />
<Compile Include="Compute\UniqueAdjacencies.cs" />
<Compile Include="Create\Elements\Opening.cs" />
<Compile Include="Create\Elements\Panel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public static partial class Query
[Input("edges", "Adjacency edges.")]
[Input("elems", "Adjacency elements.")]
[Output("adjacencyID", "The generated name of the adjacency.")]
public static string AdjacencyID(List<IElement1D> edges, List<IElement2D> elems)
public static string AdjacencyID(this List<IElement1D> edges, List<IElement2D> elems)
{
string separator = "_";
List<string> adjIDs = new List<string>();
if (edges.Count != elems.Count)
{
Reflection.Compute.RecordWarning("edge and element list lengths do not match. Each edge should have a corresponding element, please check your inputs.");
Reflection.Compute.RecordWarning("Edge and element list lengths do not match. Each edge should have a corresponding element, please check your inputs.");
return null;
}
else
Expand Down
9 changes: 7 additions & 2 deletions Facade_Engine/Query/FrameGeometry2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public static partial class Query

public static IGeometry FrameGeometry2D(this Opening opening)
{
if (opening == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the Frame Geometry of a null opening.");
return null;
}

PolyCurve extCrv = opening.Geometry();
List<double> widths = new List<double>();

Expand All @@ -59,8 +65,7 @@ public static IGeometry FrameGeometry2D(this Opening opening)
BH.Engine.Reflection.Compute.RecordWarning("This method only works on planar curves. Opening " + opening.BHoM_Guid + " has non-planar curves and will be ignored.");
return null;
}

Plane openingPlane = extCrv.FitPlane();

foreach (FrameEdge edge in opening.Edges)
{
double width = edge.FrameEdgeProperty.WidthIntoOpening();
Expand Down
Loading