瀏覽代碼

ready for testing

Rumei 5 年之前
父節點
當前提交
ba9d740392

+ 76 - 70
SketchAssistant/SketchAssistantWPF/MVP_Model.cs

@@ -39,7 +39,7 @@ namespace SketchAssistantWPF
         /// <summary>
         /// if the program is using OptiTrack
         /// </summary>
-        bool optiTrackInUse;
+        public bool optiTrackInUse{ get; private set; }
         /// <summary>
         /// Size of deletion area
         /// </summary>
@@ -53,14 +53,6 @@ namespace SketchAssistantWPF
         /// </summary>
         Point currentCursorPosition;
         /// <summary>
-        /// The Position of the finger in the right picture box
-        /// </summary>
-        Point currentFingerPosition;
-        /// <summary>
-        /// The Previous Cursor Position in the right picture box
-        /// </summary>
-        Point previousFingerPosition;
-        /// <summary>
         /// The Previous Cursor Position in the right picture box
         /// </summary>
         Point previousCursorPosition;
@@ -69,10 +61,6 @@ namespace SketchAssistantWPF
         /// </summary>
         Queue<Point> cursorPositions = new Queue<Point>();
         /// <summary>
-        /// Queue for the cursorPositions
-        /// </summary>
-        Queue<Point> fingerPositions = new Queue<Point>();
-        /// <summary>
         /// Lookup Matrix for checking postions of lines in the image
         /// </summary>
         bool[,] isFilledMatrix;
@@ -113,6 +101,12 @@ namespace SketchAssistantWPF
         /// </summary>
         public bool graphicLoaded { get; set; }
 
+        //TODO: calibrate
+        double OPTITRACK_X_OFFSET = -0.7878;
+        double OPTITRACK_Y_OFFSET = -2.0877;
+        double OPTITRACK_X_SCALE = -1 * ((1.816 / 0.0254 * 96) / (1.816));
+        double OPTITRACK_Y_SCALE = -1 * ((1.360 / 0.0254 * 96) / (1.360));
+
         Image rightImageWithoutOverlay;
 
         List<InternalLine> leftLineList;
@@ -121,8 +115,6 @@ namespace SketchAssistantWPF
 
         List<Point> currentLine = new List<Point>();
 
-
-
         public MVP_Model(MVP_Presenter presenter)
         {
             programPresenter = presenter;
@@ -134,11 +126,13 @@ namespace SketchAssistantWPF
             UpdateUI();
             rightImageSize = new ImageDimension(0, 0);
             leftImageSize = new ImageDimension(0, 0);
-			connector = new OptiTrackConnector();
+            connector = new OptiTrackConnector();
+            armband = new Armband();
+
             if (connector.Init(@"C:\Users\videowall-pc-user\Documents\BP-SketchAssistant\SketchAssistant\optitrack_setup.ttp"))
             {
 
-                connector.StartTracking(InnerMethod);
+                connector.StartTracking(getOptiTrackPosition);
             }
         }
 
@@ -202,7 +196,7 @@ namespace SketchAssistantWPF
         /// </summary>
         private void UpdateUI()
         {
-            programPresenter.UpdateUIState(inDrawingMode, historyOfActions.CanUndo(), historyOfActions.CanRedo(), canvasActive, graphicLoaded);
+            programPresenter.UpdateUIState(inDrawingMode, historyOfActions.CanUndo(), historyOfActions.CanRedo(), canvasActive, graphicLoaded, optiTrackInUse);
         }
 
         /// <summary>
@@ -373,7 +367,6 @@ namespace SketchAssistantWPF
         public void ChangeOptiTrack(bool usingOptiTrack)
         {
             optiTrackInUse = usingOptiTrack;
-            UpdateUI();
         }
 
         /// <summary>
@@ -382,7 +375,7 @@ namespace SketchAssistantWPF
         /// <param name="p">The new cursor position</param>
         public void SetCurrentCursorPosition(Point p)
         {
-            currentCursorPosition = p;
+            if (!optiTrackInUse) currentCursorPosition = p;
         }
 
         /// <summary>
@@ -391,32 +384,34 @@ namespace SketchAssistantWPF
         /// <param name="p">The new cursor position</param>
         public void SetCurrentFingerPosition(Point p)
         {
-            currentFingerPosition = p;
+            Point correctedPoint = ConvertToPixels(p);
+            currentCursorPosition = p;
+        }
+
+        
+        private Point ConvertToPixels(Point p)
+        {
+            double xCoordinate = (p.X - OPTITRACK_X_OFFSET) * OPTITRACK_X_SCALE;
+            double yCoordinate = (p.Y - OPTITRACK_Y_OFFSET) * OPTITRACK_Y_SCALE;
+            return new Point(xCoordinate, yCoordinate);
         }
 
         /// <summary>
         /// Start a new Line, when the Mouse is pressed down.
         /// </summary>
-        public void MouseDown()
+        public void StartNewLine()
         {
             if (inDrawingMode)
             {
                 currentLine.Clear();
-                if (!optiTrackInUse)
-                {
-                    currentLine.Add(currentCursorPosition);
-                }
-                else
-                {
-                    currentLine.Add(currentFingerPosition);
-                }
+                currentLine.Add(currentCursorPosition);
             }
         }
 
         /// <summary>
         /// Finish the current Line, when the pressed Mouse is released.
         /// </summary>
-        public void MouseUp()
+        public void FinishCurrentLine()
         {
             if (inDrawingMode && currentLine.Count > 0)
             {
@@ -432,62 +427,67 @@ namespace SketchAssistantWPF
             UpdateUI();
         }
 
-        String returnString = null;
-        void InnerMethod(OptiTrack.Frame frame)
+        public float optiTrackX;
+        public float optiTrackY;
+        public float optiTrackZ;
+        private bool optiTrackInsideDrawingZone;
+        private double WARNING_ZONE_BOUNDARY= 0.05; //5cm
+        private Armband armband;
+
+        void getOptiTrackPosition(OptiTrack.Frame frame)
         {
-            Console.WriteLine(frame.Trackables.Length);
-            float x = frame.Trackables[0].X;
-            float y = frame.Trackables[0].Y;
-            float z = frame.Trackables[0].Z;
-            returnString = ("X: " + x + "Y: " + y + "Z: " + z);
+            optiTrackX = frame.Trackables[0].X;
+            optiTrackY = frame.Trackables[0].Y;
+            optiTrackZ = frame.Trackables[0].Z;
         }
         /// <summary>
         /// Method to be called every tick. Updates the current Line, or checks for Lines to delete, depending on the drawing mode.
         /// </summary>
         public void Tick()
         {
-            if (optiTrackInUse) // update fingerPositinons
-            {
-                //SetCursorPos(100, 100);
-                //mouse_event((int)MouseEventType.LeftDown, RightCanvas.Cursor.Position.X, Cursor.Position.Y, 0, 0);
-                //mouse_event((int)MouseEventType.LeftUp, Cursor.Position.X, Cursor.Position.Y, 0, 0);
-                if (fingerPositions.Count > 0) { previousFingerPosition = fingerPositions.Dequeue(); }
-                else { previousFingerPosition = currentFingerPosition; }
-                fingerPositions.Enqueue(currentFingerPosition);
-            }
-            else // update cursorPositinons
+            if (optiTrackInUse)
             {
-                if (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
-                else { previousCursorPosition = currentCursorPosition; }
-                cursorPositions.Enqueue(currentCursorPosition);
-            }
-            //Drawing
-            if (inDrawingMode && programPresenter.IsMousePressed())
-            {
-                if (!optiTrackInUse)
+
+                if (CheckInsideDrawingZone(optiTrackZ))
                 {
-                    currentLine.Add(currentCursorPosition);
-                    programPresenter.UpdateCurrentLine(currentLine);
+                    SetCurrentFingerPosition(new Point(optiTrackX, optiTrackY));
+                    if (!optiTrackInsideDrawingZone)
+                    {
+                        optiTrackInsideDrawingZone = true;
+                        StartNewLine();
+                    }
+                    if(optiTrackZ > WARNING_ZONE_BOUNDARY)
+                    {
+                        armband.pushForward();
+                    }
+                    else if(optiTrackZ < -1 * WARNING_ZONE_BOUNDARY)
+                    {
+                        armband.pushBackward();
+                    }
                 }
                 else
                 {
-                    currentLine.Add(currentFingerPosition);
-                    programPresenter.UpdateCurrentLine(currentLine);
+                    if (optiTrackInsideDrawingZone)
+                    {
+                        optiTrackInsideDrawingZone = false;
+                        FinishCurrentLine();
+                    }
                 }
-
+            }
+            if (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
+            else { previousCursorPosition = currentCursorPosition; }
+            cursorPositions.Enqueue(currentCursorPosition);
+            
+            //Drawing
+            if (inDrawingMode && programPresenter.IsMousePressed())
+            {
+                 currentLine.Add(currentCursorPosition);
+                programPresenter.UpdateCurrentLine(currentLine);
             }
             //Deleting
             if (!inDrawingMode && programPresenter.IsMousePressed())
             {
-                List<Point> uncheckedPoints;
-                if (!optiTrackInUse)
-                {
-                    uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
-                }
-                else
-                {
-                    uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousFingerPosition, currentFingerPosition);
-                }
+                List<Point> uncheckedPoints= GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
 
                 foreach (Point currPoint in uncheckedPoints)
                 {
@@ -507,6 +507,12 @@ namespace SketchAssistantWPF
             }
         }
 
+        private bool CheckInsideDrawingZone(float optiTrackZ)
+        {
+            if (Math.Abs(optiTrackZ) > WARNING_ZONE_BOUNDARY * 2) return false;
+            return true;
+        }
+
         /// <summary>
         /// A helper Function that updates the markerRadius & deletionRadius, considering the size of the canvas.
         /// </summary>

+ 33 - 18
SketchAssistant/SketchAssistantWPF/MVP_Presenter.cs

@@ -196,22 +196,26 @@ namespace SketchAssistantWPF
         /// <param name="e">The Mouse event arguments.</param>
         public void MouseEvent(MouseAction mouseAction)
         {
-            switch (mouseAction)
+            if (!programModel.optiTrackInUse)
             {
-                case MouseAction.Click:
-                    programModel.MouseDown();
-                    programModel.Tick();
-                    programModel.MouseUp();
-                    break;
-                case MouseAction.Down:
-                    programModel.MouseDown();
-                    break;
-                case MouseAction.Up:
-                    programModel.MouseUp();
-                    break;
-                default:
-                    break;
+                switch (mouseAction)
+                {
+                    case MouseAction.Click:
+                        programModel.StartNewLine();
+                        programModel.Tick();
+                        programModel.FinishCurrentLine();
+                        break;
+                    case MouseAction.Down:
+                        programModel.StartNewLine();
+                        break;
+                    case MouseAction.Up:
+                        programModel.FinishCurrentLine();
+                        break;
+                    default:
+                        break;
+                }
             }
+           
         }
 
         /************************************/
@@ -305,22 +309,33 @@ namespace SketchAssistantWPF
         /// <param name="canRedo">If actions in the model can be redone</param>
         /// <param name="canvasActive">If the right canvas is active</param>
         /// <param name="graphicLoaded">If an image is loaded in the model</param>
-        public void UpdateUIState(bool inDrawingMode, bool canUndo, bool canRedo, bool canvasActive, bool graphicLoaded)
+        public void UpdateUIState(bool inDrawingMode, bool canUndo, bool canRedo, bool canvasActive, bool graphicLoaded, bool optiTrackInUse)
         {
             Dictionary<String, MainWindow.ButtonState> dict = new Dictionary<String, MainWindow.ButtonState> {
                 {"canvasButton", MainWindow.ButtonState.Enabled }, {"drawButton", MainWindow.ButtonState.Disabled}, {"deleteButton",MainWindow.ButtonState.Disabled },
-                {"undoButton", MainWindow.ButtonState.Disabled },{"redoButton",  MainWindow.ButtonState.Disabled}};
+                {"undoButton", MainWindow.ButtonState.Disabled },{"redoButton",  MainWindow.ButtonState.Disabled}, {"drawWithOptiButton", MainWindow.ButtonState.Disabled}};
 
             if (canvasActive)
             {
                 if (inDrawingMode)
                 {
-                    dict["drawButton"] = MainWindow.ButtonState.Active;
-                    dict["deleteButton"] = MainWindow.ButtonState.Enabled;
+                    if (!optiTrackInUse)
+                    { 
+                        dict["drawButton"] = MainWindow.ButtonState.Active;
+                        dict["drawWithOptiButton"] = MainWindow.ButtonState.Enabled;
+                        dict["deleteButton"] = MainWindow.ButtonState.Enabled;
+                    }
+                    else
+                    {
+                        dict["drawButton"] = MainWindow.ButtonState.Enabled;
+                        dict["drawWithOptiButton"] = MainWindow.ButtonState.Active;
+                        dict["deleteButton"] = MainWindow.ButtonState.Enabled;
+                    }
                 }
                 else
                 {
                     dict["drawButton"] = MainWindow.ButtonState.Enabled;
+                    dict["drawWithOptiButton"] = MainWindow.ButtonState.Enabled;
                     dict["deleteButton"] = MainWindow.ButtonState.Active;
                 }
                 if (canUndo) { dict["undoButton"] = MainWindow.ButtonState.Enabled; }

+ 4 - 3
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -32,6 +32,7 @@
                     <MenuItem Header="New Canvas" Click="CanvasButton_Click"/>
                     <MenuItem Header="Undo" Click="UndoButton_Click"/>
                     <MenuItem Header="Redo" Click="RedoButton_Click"/>
+                    <MenuItem Header="Calibrate OptiTrack" Click="OpenOptiTrackCalibration_Click"/>
                 </MenuItem>
             </Menu>
         </ToolBar>
@@ -169,10 +170,10 @@
                     </Rectangle.Fill>
                 </Rectangle>
             </Button>
-            <Button x:Name="DrawWithOptiButton" ToolTip="Enter Drawing Mode (OptiTrack)" Click="DrawWithOptiButton_Click">
+            <ToggleButton x:Name="DrawWithOptiButton" ToolTip="Enter Drawing Mode (OptiTrack)" Click="DrawWithOptiButton_Click">
                 <Canvas  Name="svg62" Width="30" Height="30">
                     <Canvas.RenderTransform>
-                        <TranslateTransform X="0" Y="-277"/>
+                        <TranslateTransform X="4" Y="-270"/>
                     </Canvas.RenderTransform>
                     <Canvas.Resources/>
                     <!--Unknown tag: sodipodi:namedview-->
@@ -187,7 +188,7 @@
                         </Canvas>
                     </Canvas>
                 </Canvas>
-            </Button>
+            </ToggleButton>
         </ToolBar>
         <Canvas Name="LeftCanvas" Background="SlateGray" Grid.Column="2" Grid.Row="1" Height="auto" Grid.ColumnSpan="2"/>
         <Canvas Name="CanvasSeperator" Grid.Column="4" Grid.Row="1" Background="LightGray"/>

+ 17 - 2
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -135,8 +135,8 @@ namespace SketchAssistantWPF
         /// </summary>
         private void DrawButton_Click(object sender, RoutedEventArgs e)
         {
-            ProgramPresenter.ChangeState(true);
             ProgramPresenter.ChangeOptiTrack(false);
+            ProgramPresenter.ChangeState(true);
         }
 
         /// <summary>
@@ -144,8 +144,8 @@ namespace SketchAssistantWPF
         /// </summary>
         private void DrawWithOptiButton_Click(object sender, RoutedEventArgs e)
         {
-            ProgramPresenter.ChangeState(true);
             ProgramPresenter.ChangeOptiTrack(true);
+            ProgramPresenter.ChangeState(true);
         }
 
         /// <summary>
@@ -245,6 +245,17 @@ namespace SketchAssistantWPF
             ProgramPresenter.ExamplePictureToolStripMenuItemClick();
         }
 
+        /// <summary>
+        /// Button that opens new window for calibration the OptiTrack coordinates to the of the viewing device
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void OpenOptiTrackCalibration_Click(object sender, EventArgs e)
+        {
+            CalibrationWindow calWin = new CalibrationWindow();
+            calWin.Show();
+        }
+
         /*************************/
         /*** PRESENTER -> VIEW ***/
         /*************************/
@@ -424,6 +435,10 @@ namespace SketchAssistantWPF
                 case "redoButton":
                     buttonToChange = RedoButton;
                     break;
+                case "drawWithOptiButton":
+                    buttonToChange = DrawWithOptiButton;
+                    isToggleable = true;
+                    break;
                 default:
                     Console.WriteLine("Invalid Button was given to SetToolStripButton. \nMaybe you forgot to add a case?");
                     return;

+ 9 - 0
SketchAssistant/SketchAssistantWPF/SketchAssistantWPF.csproj

@@ -94,6 +94,7 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="ActionHistory.cs" />
+    <Compile Include="Armband.cs" />
     <Compile Include="CustomCanvas.cs" />
     <Compile Include="DebugData.cs" />
     <Compile Include="FileImporter.cs" />
@@ -163,9 +164,17 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
+    <Content Include="BodyActuator.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="NPTrackingTools.dll">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="TActionManager.dll" />
+    <Content Include="TactorInterface.dll" />
+  </ItemGroup>
+  <ItemGroup>
+    <WCFMetadata Include="Connected Services\" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>