-
Notifications
You must be signed in to change notification settings - Fork 15
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
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cea1833
Create IGeometricalRepresentation.cs
alelom df6b688
Prototyping
alelom 7e374b8
Restoring methods deleted in prototyping
alelom 85b1a0d
Reviewed mechanism
alelom 998ebc0
Merge branch 'master' into BHoM_Engine-#1877-RepresentationSystem
alelom ff22cc9
Undoing minor changes
alelom 7ddbe98
Update Visualize.cs
alelom 64b1816
Update Geometry_Engine.csproj
alelom 25e8c31
example
alelom cf78687
changes after chat with @rolyhudson
alelom 57b36bd
Nudging rep prototype forward
rolyhudson f491549
Edit structural visualize method to return colour arrows as Geometric…
rolyhudson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
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 }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
145
Geometry_Engine/Query/GeometricalRepresentation/Vector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.