コード例 #1
0
ファイル: BindableRect.cs プロジェクト: hcilab-um/tPad
 public BindableRect(double x, double y, double width, double height)
 {
     TopLeft = new BindablePoint(x, y);
       TopRight = new BindablePoint(x + width, y);
       BottomLeft = new BindablePoint(x, y + height);
       BottomRight = new BindablePoint(x + width, y + height);
 }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: hcilab-um/tPad
        public Capture(String folderPath, String filePath)
        {
            Folder = folderPath;
              FileName = System.IO.Path.GetFileName(filePath);
              var pieces = FileName.Split(new String[] { "-" }, StringSplitOptions.RemoveEmptyEntries);

              Ticks = long.Parse(pieces[0]);
              Device = (Device)Enum.Parse(typeof(Device), pieces[1]);
              Method = (Method)Enum.Parse(typeof(Method), pieces[2]);
              Size = (Size)Enum.Parse(typeof(Size), pieces[3]);

              TargetCenter = new BindablePoint(-10, -10);
              TargetRectangle = new BindableRect(-50, -50, 100, 100);

              CaptureCenter = new BindablePoint(0, 0);
              CaptureRectangle = new BindableRect(-60, -60, 120, 120);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: hcilab-um/tPad
        private void eTargetCenter_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!isMoving)
            return;

              UpdateLocation(e.GetPosition(iCapture));
              isMoving = false;
              movingPoint = null;
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: hcilab-um/tPad
        private void eTargetCenter_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (CurrentCapture == null)
            return;

              movingPoint = (sender as System.Windows.FrameworkElement).DataContext as BindablePoint;
              isMoving = true;
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: hcilab-um/tPad
 private double Distance(BindablePoint point1, BindablePoint point2)
 {
     return Math.Sqrt(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2));
 }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: hcilab-um/tPad
        private void bGenerate_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            tbOutput.Text = String.Empty;
              foreach (Capture capture in Captures)
              {
            //0- calcute pixel-to-cms ratio
            double pixelLenght = Distance(capture.TargetRectangle.BottomLeft, capture.TargetRectangle.BottomRight);
            double pixelCmRatio = sizes[(int)capture.Size] / pixelLenght;

            //1- calculate off-set
            BindablePoint capturePoint = capture.CaptureCenter.Clone();
            if (capture.Device == Device.Normal && capture.Method == Method.Normal)
              capturePoint = new BindablePoint(0, 0);
            if (capture.Device == Device.tPad)
              capturePoint.Translate(0, TPAD_Y_OFFSET); //due to the angle from where the picture is taken, there is a 12px shift in the capture elements
            double offsetPx = Distance(capture.TargetCenter, capturePoint);
            double offsetCm = offsetPx * pixelCmRatio;
            capture.Offset = offsetCm;

            //2- calculates the angle
            System.Windows.Vector targetVector = new System.Windows.Vector(
              capture.TargetRectangle.BottomLeft.X - capture.TargetRectangle.BottomRight.X,
              capture.TargetRectangle.BottomLeft.Y - capture.TargetRectangle.BottomRight.Y);
            System.Windows.Vector baseVector;
            if (capture.Device == Device.Normal && capture.Method == Method.Normal)
              baseVector = new System.Windows.Vector(1, 0);
            else
              baseVector = new System.Windows.Vector(
            capture.CaptureRectangle.BottomLeft.X - capture.CaptureRectangle.BottomRight.X,
            capture.CaptureRectangle.BottomLeft.Y - capture.CaptureRectangle.BottomRight.Y);
            double angle = Math.Abs(System.Windows.Vector.AngleBetween(baseVector, targetVector));
            if (angle > 90)
              angle = 180 - angle;
            capture.Angle = angle;

            double captureRatio = 0;
            double missRatio = 0;

            if (capture.Method == Method.Clipped)
            {
              //3- calculates the ratio of capture = capture / target
              captureRatio = Area(capture.CaptureRectangle) / Area(capture.TargetRectangle);
              capture.CaptureRatio = captureRatio;

              //4- calculates how much is left out
              BindableRect captureRectangle = capture.CaptureRectangle.Clone();
              if (capture.Device == Device.tPad)
            captureRectangle.Translate(0, TPAD_Y_OFFSET);
              missRatio = AreaMiss(captureRectangle, capture.TargetRectangle) / Area(capture.TargetRectangle);
              capture.MissRatio = missRatio;
            }

            //5- prints out the log
            String log = String.Format("{0:F4};{1:F4};{2:F4};{3:F4}\n", offsetCm, angle, captureRatio, missRatio);
            tbOutput.Text += log;
              }
        }