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

BHoM_Engine: Design the representation system #2288

Closed
wants to merge 12 commits into from
6 changes: 6 additions & 0 deletions Geometry_Engine/Geometry_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -149,6 +150,10 @@
<Compile Include="Query\Cells.cs" />
<Compile Include="Query\Centroid.cs" />
<Compile Include="Query\ClosestPoints.cs" />
<Compile Include="Query\GeometricalRepresentation\Curve.cs" />
<Compile Include="Query\GeometricalRepresentation\Point.cs" />
<Compile Include="Query\GeometricalRepresentation\Vector.cs" />
<Compile Include="Query\IGeometricalRepresentation.cs" />
<Compile Include="Query\PrincipalCurvatureAtParameter.cs" />
<Compile Include="Query\CurveIntersections.cs" />
<Compile Include="Compute\CurveProximity.cs" />
Expand Down Expand Up @@ -265,6 +270,7 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
51 changes: 51 additions & 0 deletions Geometry_Engine/Query/GeometricalRepresentation/Curve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Geometry;
using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns the geometrical representation of the curve, which is a Pipe.")] // the pipe radius corresponds to how big the Curve is when represented.
public static GeometricalRepresentation Representation(this ICurve curve, ElementRepresentationOptions options = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following comments here also: https://github.com/BHoM/BHoM/pull/1179/files
Might separate the two problems of Colouring/Rendering/Text etc. as a Graphics question.
And the Geometry question of - do you want to return 1D, 2D or 3D to represent the object.

A simple approach could then be to have for IElements - a common method which returns 3D geometry. Unifying Extrude methods etc.
The parent method could then also check inside Fragments as a fall back - for the case where user wants to store solid geometry representation.

Will be good to focus on this a primary example as immediately useful.

{
options = options ?? new ElementRepresentationOptions();

double radius = 0.01 * options.Scale;
bool capped = options.Cap1DElements;

Pipe pipe = BH.Engine.Geometry.Create.Pipe(curve, radius, capped);

return new GeometricalRepresentation() { Geometry = pipe, Colour = options.Colour };
}
}
}
49 changes: 49 additions & 0 deletions Geometry_Engine/Query/GeometricalRepresentation/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Geometry;
using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Returns the geometrical representation of the point, which is a Sphere.")] // in the future, we might want an option to choose between sphere / box.
public static GeometricalRepresentation Representation(this Point point, ElementRepresentationOptions options = null)
alelom marked this conversation as resolved.
Show resolved Hide resolved
{
options = options ?? new ElementRepresentationOptions();

double radius = 0.15 * options.Scale;
Sphere sphere = BH.Engine.Geometry.Create.Sphere(point, radius);

return new GeometricalRepresentation() { Geometry = sphere, Colour = options.Colour };
}
}
}
145 changes: 145 additions & 0 deletions Geometry_Engine/Query/GeometricalRepresentation/Vector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Geometry;
using BH.oM.Reflection.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

//public static GeometricalRepresentation Representation(Vector v, VectorRepresentationOptions vectOpts)
//{
// List<ICurve> arrow = new List<ICurve>();

// Point pt = vectOpts.BasePoint;

// pt = pt + v * vectOpts.Shift;
// Point end = pt + v;

// arrow.Add(Create.Line(pt, end));

// double length = v.Length();

// Vector norm = v / length;

// Vector v1 = Vector.XAxis;

// double dot = v1.DotProduct(norm);

// if (Math.Abs(1 - Math.Abs(dot)) < Tolerance.Angle)
// {
// v1 = Vector.YAxis;
// dot = v1.DotProduct(norm);
// }

// v1 = (v1 - dot * norm).Normalise();

// Vector v2 = v1.CrossProduct(norm).Normalise();

// v1 /= 2;
// v2 /= 2;

// double factor = length / 10;

// int m = 0;

// while (m < 1)
// {
// arrow.Add(Engine.Geometry.Create.Line(pt, (v1 + norm) * factor));
// arrow.Add(Engine.Geometry.Create.Line(pt, (-v1 + norm) * factor));
// arrow.Add(Engine.Geometry.Create.Line(pt, (v2 + norm) * factor));
// arrow.Add(Engine.Geometry.Create.Line(pt, (-v2 + norm) * factor));

// pt = pt + norm * factor;
// m++;
// }

// CompositeGeometry compositeGeometry = new CompositeGeometry() { Elements = arrow.OfType<IGeometry>().ToList() };
// GeometricalRepresentation repr = new GeometricalRepresentation() { Geometry = compositeGeometry };
// return repr;
//}

/***************************************************/

private static GeometricalRepresentation ArcArrow(Point pt, Vector v)
{
List<ICurve> arrow = new List<ICurve>();

double length = v.Length();

Vector cross;
if (v.IsParallel(Vector.ZAxis) == 0)
cross = Vector.ZAxis;
else
cross = Vector.YAxis;

Vector yAxis = v.CrossProduct(cross);
Vector xAxis = yAxis.CrossProduct(v);

double pi4over3 = Math.PI * 4 / 3;
Arc arc = Engine.Geometry.Create.Arc(Engine.Geometry.Create.CartesianCoordinateSystem(pt, xAxis, yAxis), length / pi4over3, 0, pi4over3);

arrow.Add(arc);

Vector tan = -arc.EndDir();

Vector v1 = Vector.XAxis;

double dot = v1.DotProduct(tan);

if (Math.Abs(1 - dot) < Tolerance.Angle)
{
v1 = Vector.YAxis;
dot = v1.DotProduct(tan);
}

v1 = (v1 - dot * tan).Normalise();

Vector v2 = v1.CrossProduct(tan).Normalise();

v1 /= 2;
v2 /= 2;

double factor = length / 10;

pt = arc.EndPoint();

arrow.Add(Engine.Geometry.Create.Line(pt, (v1 + tan) * factor));
arrow.Add(Engine.Geometry.Create.Line(pt, (-v1 + tan) * factor));
arrow.Add(Engine.Geometry.Create.Line(pt, (v2 + tan) * factor));
arrow.Add(Engine.Geometry.Create.Line(pt, (-v2 + tan) * factor));

CompositeGeometry compositeGeometry = new CompositeGeometry() { Elements = arrow.OfType<IGeometry>().ToList() };
GeometricalRepresentation repr = new GeometricalRepresentation() { Geometry = compositeGeometry };
return repr;
}
}
}
72 changes: 72 additions & 0 deletions Geometry_Engine/Query/IGeometricalRepresentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base;
using BH.oM.Dimensional;
using BH.oM.Geometry;
using BH.oM.Geometry.SettingOut;
using System.ComponentModel;

namespace BH.Engine.Geometry
{
public static partial class Query
{
/***************************************************/
/**** Interface Methods ****/
/***************************************************/

public static IRepresentation IRepresentation(this IObject iObj)
{
return Representation(iObj as dynamic);
}

/***************************************************/
/**** Private methods - fallback ****/
/***************************************************/

private static IRepresentation Representation(IObject iObj)
{
IRepresentation repr = iObj as IRepresentation;
if (repr != null)
return repr;

repr = Reflection.Compute.RunExtensionMethod(iObj, "Representation") as IRepresentation;

if (repr != null) // object has a Representation method.
return repr;

GeometricalRepresentation geomRepr = new GeometricalRepresentation();

IGeometry geom = iObj as IGeometry;

if (geom != null) // it's a geometrical object that does not have a Representation method.
geomRepr.Geometry = geom;

else // it's a generic object that does not have a Representation method.
geom = BH.Engine.Base.Query.IGeometry(iObj as BHoMObject);

return geomRepr;
}
}
}


Loading