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

Structure_Engine: Transform methods added for structural elements #2361

Merged
merged 9 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .ci/Datasets/Structure_Engine/Modify/Transform.json

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions Structure_Engine/Modify/Transform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* 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.Engine.Geometry;
using BH.Engine.Spatial;
using BH.oM.Geometry;
using BH.oM.Reflection.Attributes;
using BH.oM.Structure.Elements;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace BH.Engine.Structure
{
public static partial class Modify
{
/***************************************************/
/**** Interface Methods - IElements ****/
/***************************************************/

[Description("Transforms the Node's position and orientation by the transform matrix. Only rigid body transformations are supported.")]
[Input("node", "Node to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified Node with unchanged properties, but transformed position and orientation.")]
public static Node Transform(this Node node, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

Node result = node.GetShallowClone() as Node;
result.Position = result.Position.Transform(transform);
result.Orientation = result.Orientation.Transform(transform);
pawelbaran marked this conversation as resolved.
Show resolved Hide resolved
return result;
}

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

[Description("Transforms the Bar's nodes and rotation by the transform matrix. Only rigid body transformations are supported.")]
[Input("bar", "Bar to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified Bar with unchanged properties, but transformed nodes and rotation.")]
public static Bar Transform(this Bar bar, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

Bar result = bar.GetShallowClone() as Bar;
result.StartNode = result.StartNode.Transform(transform, tolerance);
result.EndNode = result.EndNode.Transform(transform, tolerance);

Vector normalBefore = new Line { Start = bar.StartNode.Position, End = bar.EndNode.Position }.ElementNormal(bar.OrientationAngle);
Vector normalAfter = normalBefore.Transform(transform);
result.OrientationAngle = normalAfter.OrientationAngleLinear(new Line { Start = result.StartNode.Position, End = result.EndNode.Position });

return result;
}

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

[Description("Transforms the RigidLink's primary and secondary nodes by the transform matrix. Only rigid body transformations are supported.")]
[Input("link", "RigidLink to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified RigidLink with unchanged properties, but transformed primary and secondary nodes.")]
public static RigidLink Transform(this RigidLink link, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

RigidLink result = link.GetShallowClone() as RigidLink;
result.PrimaryNode = result.PrimaryNode.Transform(transform, tolerance);
result.SecondaryNodes = result.SecondaryNodes.Select(x => x.Transform(transform, tolerance)).ToList();
return result;
}

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

[Description("Transforms the Edge's location by the transform matrix. Only rigid body transformations are supported.")]
[Input("edge", "Edge to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified Edge with unchanged properties, but transformed location.")]
public static Edge Transform(this Edge edge, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

Edge result = edge.GetShallowClone() as Edge;
result.Curve = result.Curve.ITransform(transform);
return result;
}

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

[Description("Transforms the Opening's edges by the transform matrix. Only rigid body transformations are supported.")]
[Input("opening", "Opening to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified Opening with unchanged properties, but transformed edges.")]
public static Opening Transform(this Opening opening, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

Opening result = opening.GetShallowClone() as Opening;
result.Edges = result.Edges.Select(x => x.Transform(transform, tolerance)).ToList();
return result;
}

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

[Description("Transforms the Panel's edges, openings and orientation angle by the transform matrix. Only rigid body transformations are supported.")]
[Input("panel", "Panel to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified Panel with unchanged properties, but transformed edges, openings and orientation angle.")]
public static Panel Transform(this Panel panel, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

Panel result = panel.GetShallowClone() as Panel;
result.ExternalEdges = result.ExternalEdges.Select(x => x.Transform(transform, tolerance)).ToList();
result.Openings = result.Openings.Select(x => x.Transform(transform, tolerance)).ToList();

Basis orientation = panel.LocalOrientation().Transform(transform);
result.OrientationAngle = orientation.Z.OrientationAngleAreaElement(orientation.X);

return result;
}

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

[Description("Transforms the FEMesh's nodes by the transform matrix. Only rigid body transformations are supported.")]
[Input("mesh", "FEMesh to transform.")]
[Input("transform", "Transform matrix.")]
[Input("tolerance", "Tolerance used in the check whether the input matrix is equivalent to the rigid body transformation.")]
[Output("transformed", "Modified FEMesh with unchanged properties, but transformed nodes.")]
public static FEMesh Transform(this FEMesh mesh, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
return null;
}

FEMesh result = mesh.GetShallowClone() as FEMesh;
result.Nodes = result.Nodes.Select(x => x.Transform(transform, tolerance)).ToList();

List<Basis> orientationsBefore = mesh.LocalOrientations();
result.Faces = new List<FEMeshFace>(mesh.Faces);
for (int i = 0; i < orientationsBefore.Count; i++)
{
result.Faces[i] = result.Faces[i].SetLocalOrientation(result, orientationsBefore[i].Transform(transform).X);
}

return result;
}

/***************************************************/
}
}

1 change: 1 addition & 0 deletions Structure_Engine/Structure_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<Compile Include="Modify\SetMaterial.cs" />
<Compile Include="Modify\SetNormal.cs" />
<Compile Include="Modify\SetStructuralFragment.cs" />
<Compile Include="Modify\Transform.cs" />
<Compile Include="Objects\EqualityComparers\CaseNumberComaprer.cs" />
<Compile Include="Objects\EqualityComparers\Constraint4DOFComparer.cs" />
<Compile Include="Objects\EqualityComparers\Constraint6DOFComparer.cs" />
Expand Down