@@ -41,12 +41,60 @@ public class Converter : Base.Converter
41
41
public Converter ( ) : base ( )
42
42
{
43
43
PreviousVersion = "8.1" ;
44
+ ToNewObject . Add ( "BH.oM.Security.Elements.CameraDevice" , UpgradeCameraDevice ) ;
44
45
}
45
46
46
47
/***************************************************/
47
48
/**** Private Methods ****/
48
49
/***************************************************/
49
50
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
+ }
50
98
51
99
/***************************************************/
52
100
}
0 commit comments