Skip to content

Security_Engine: Camera Field of View bug fix #3266

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

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 11 additions & 7 deletions Security_Engine/Compute/CameraFieldOfView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static PolyCurve CameraFieldOfView(this CameraDevice cameraDevice, List<P
{
if (obstacle.IsContaining(new List<Point> { cameraLocation }, true, distanceTolerance))
{
Base.Compute.RecordWarning("Camera Device is inside obstacle. Null value will be returned.");
return null;
Base.Compute.RecordWarning("Camera Device is inside obstacle that will be skipped.");
continue;
}

foreach (Line obstLine in obstacle.SubParts())
Expand Down Expand Up @@ -129,7 +129,7 @@ public static PolyCurve CameraFieldOfView(this CameraDevice cameraDevice, List<P
//create points chain
List<Point> pointsChain = linesDict.PointsChain(cameraLocation, radius, distanceTolerance);

//create cone
//create camera cone
PolyCurve cameraViewPolyCurve = pointsChain.CameraViewPolyCurve(coneArc, distanceTolerance);

return cameraViewPolyCurve;
Expand Down Expand Up @@ -323,6 +323,9 @@ private static List<Point> PointsChain(this List<Tuple<Line, Polyline>> lineObst
pointsChain = pointsChain.CullDuplicates(tolerance);
pointsChain.Add(cameraLocation);

//reverse points chain to have correct start and end arc angles
pointsChain.Reverse();

return pointsChain;
}

Expand All @@ -345,14 +348,15 @@ private static PolyCurve CameraViewPolyCurve(this List<Point> pointsChain, Arc c
{
double p1Param = coneArc.ParameterAtPoint(pt1, tolerance);
double p2Param = coneArc.ParameterAtPoint(pt2, tolerance);
double p3Param = (p1Param + p2Param) / 2;
Point pt3 = coneArc.PointAtParameter(p3Param);
Arc newArc = BH.Engine.Geometry.Create.Arc(pt1, pt3, pt2, tolerance);
double startAngle = coneArc.EndAngle * p1Param;
double endAngle = coneArc.EndAngle * p2Param;
Arc newArc = Create.Arc(coneArc.CoordinateSystem, coneArc.Radius, startAngle, endAngle);

curves.Add(newArc);
}
else
{
Line line = BH.Engine.Geometry.Create.Line(pt1, pt2);
Line line = Create.Line(pt1, pt2);
curves.Add(line);
}
}
Expand Down
9 changes: 8 additions & 1 deletion Security_Engine/Modify/SimplifyCameraFieldOfView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static PolyCurve SimplifyCameraFieldOfView(this PolyCurve cameraFieldOfVi

//convert to polyline and simplify
List<Line> cameraLines = new List<Line>();

foreach (ICurve curve in cameraFieldOfView.SubParts())
{
if (curve is Line)
Expand All @@ -62,6 +63,7 @@ public static PolyCurve SimplifyCameraFieldOfView(this PolyCurve cameraFieldOfVi
cameraLines.Add(line);
}
}

Polyline cameraPolyline = Geometry.Create.Polyline(cameraLines);
cameraPolyline = cameraPolyline.Simplify(distanceTolerance, angleTolerance);

Expand All @@ -82,12 +84,17 @@ public static PolyCurve SimplifyCameraFieldOfView(this PolyCurve cameraFieldOfVi
double p2Param = coneArc.ParameterAtPoint(endPoint, distanceTolerance);
double p3Param = (p1Param + p2Param) / 2;
Point pt3 = coneArc.PointAtParameter(p3Param);

if (!cameraFieldOfView.IsContaining(new List<Point>() { pt3 }, true, distanceTolerance))
{
simplifiedPolyCurve.Curves.Add(line);
continue;
}
Arc newArc = BH.Engine.Geometry.Create.Arc(startPoint, pt3, endPoint, distanceTolerance);

double startAngle = coneArc.EndAngle * p1Param;
double endAngle = coneArc.EndAngle * p2Param;
Arc newArc = Geometry.Create.Arc(coneArc.CoordinateSystem, coneArc.Radius, startAngle, endAngle);

simplifiedPolyCurve.Curves.Add(newArc);
}
else
Expand Down
11 changes: 7 additions & 4 deletions Security_Engine/Query/ViewCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System.ComponentModel;
using BH.Engine.Geometry;
using BH.oM.Base.Attributes;
using BH.oM.Geometry;
using BH.oM.Security.Elements;
using BH.oM.Base.Attributes;
using System.Collections.Generic;
using BH.Engine.Geometry;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace BH.Engine.Security
{
Expand All @@ -50,6 +50,9 @@ public static PolyCurve ViewCone(this CameraDevice cameraDevice)
double coneArcLength = cameraDevice.HorizontalFieldOfView;
double coneAngle = Math.Asin(coneArcLength / (2 * coneRadius)) * 2;

if (double.IsNaN(coneAngle))
coneAngle = Math.PI;

Vector viewDirection = BH.Engine.Geometry.Create.Vector(cameraLocation, cameraDevice.TargetPosition);
Vector startPointDir = viewDirection.Rotate(-coneAngle / 2, Vector.ZAxis);
Vector endPointDir = viewDirection.Rotate(coneAngle / 2, Vector.ZAxis);
Expand Down