Skip to content

Commit 85442e9

Browse files
authored
Add CameraDevice custom versioning (#299)
2 parents 58a6654 + 9a80395 commit 85442e9

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

BHoMUpgrader82/Converter.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,60 @@ public class Converter : Base.Converter
4141
public Converter() : base()
4242
{
4343
PreviousVersion = "8.1";
44+
ToNewObject.Add("BH.oM.Security.Elements.CameraDevice", UpgradeCameraDevice);
4445
}
4546

4647
/***************************************************/
4748
/**** Private Methods ****/
4849
/***************************************************/
4950

51+
private static Dictionary<string, object> UpgradeCameraDevice(Dictionary<string, object> oldVersion)
52+
{
53+
Dictionary<string, object> newVersion = new Dictionary<string, object>();
54+
newVersion["_t"] = "BH.oM.Security.Elements.CameraDevice";
55+
newVersion["EyePosition"] = oldVersion["EyePosition"];
56+
newVersion["TargetPosition"] = oldVersion["TargetPosition"];
57+
newVersion["Mounting"] = oldVersion["Mounting"];
58+
newVersion["Type"] = oldVersion["Type"];
59+
newVersion["Megapixels"] = oldVersion["Megapixels"];
60+
61+
if (oldVersion.ContainsKey("HorizontalFieldOfView"))
62+
{
63+
double hfov = (double)oldVersion["HorizontalFieldOfView"];
64+
double distance = double.NaN;
65+
66+
if (oldVersion.ContainsKey("EyePosition") && oldVersion.ContainsKey("TargetPosition"))
67+
{
68+
var ptA = oldVersion["EyePosition"] as Dictionary<string, object>;
69+
var ptB = oldVersion["TargetPosition"] as Dictionary<string, object>;
70+
if (ptA != null && ptB != null)
71+
distance = DistanceBetweenPoints(ptA, ptB);
72+
}
73+
74+
double angle = 2 * Math.Atan(hfov / 2 / distance);
75+
newVersion["Angle"] = angle;
76+
}
77+
78+
return newVersion;
79+
}
80+
81+
/***************************************************/
82+
83+
private static double DistanceBetweenPoints(Dictionary<string, object> pt1, Dictionary<string, object> pt2)
84+
{
85+
double x1 = Convert.ToDouble(pt1["X"]);
86+
double y1 = Convert.ToDouble(pt1["Y"]);
87+
double z1 = Convert.ToDouble(pt1["Z"]);
88+
double x2 = Convert.ToDouble(pt2["X"]);
89+
double y2 = Convert.ToDouble(pt2["Y"]);
90+
double z2 = Convert.ToDouble(pt2["Z"]);
91+
92+
return Math.Sqrt(
93+
Math.Pow(x2 - x1, 2) +
94+
Math.Pow(y2 - y1, 2) +
95+
Math.Pow(z2 - z1, 2)
96+
);
97+
}
5098

5199
/***************************************************/
52100
}

0 commit comments

Comments
 (0)