Browse Source

functions in Model extended

Rumei 5 years ago
parent
commit
382ac72383

+ 95 - 17
SketchAssistant/SketchAssistantWPF/MVP_Model.cs

@@ -8,6 +8,7 @@ using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using OptiTrack;
+using System.Runtime.InteropServices;
 
 namespace SketchAssistantWPF
 {
@@ -26,7 +27,6 @@ namespace SketchAssistantWPF
 		/// </summary>
 		//RedrawAssistant redrawAss;
 		OptiTrackConnector connector;
-		OptiTrackConnector.OnFrameReady frameReady;
 
         /***********************/
         /*** CLASS VARIABLES ***/
@@ -37,6 +37,10 @@ namespace SketchAssistantWPF
         /// </summary>
         bool inDrawingMode;
         /// <summary>
+        /// if the program is using OptiTrack
+        /// </summary>
+        bool optiTrackInUse;
+        /// <summary>
         /// Size of deletion area
         /// </summary>
         int deletionRadius = 5;
@@ -49,6 +53,14 @@ 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;
@@ -57,6 +69,10 @@ 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;
@@ -126,6 +142,21 @@ namespace SketchAssistantWPF
             }
         }
 
+        [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
+        private static extern bool SetCursorPos(int X, int Y);
+
+        [DllImport("user32.dll")]
+        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
+
+        public enum MouseEventType : int
+        {
+            LeftDown = 0x02,
+            LeftUp = 0x04,
+            RightDown = 0x08,
+            RightUp = 0x10
+        }
+
+
         /**************************/
         /*** INTERNAL FUNCTIONS ***/
         /**************************/
@@ -337,7 +368,14 @@ namespace SketchAssistantWPF
             inDrawingMode = nowDrawing;
             UpdateUI();
         }
-        
+
+
+        public void ChangeOptiTrack(bool usingOptiTrack)
+        {
+            optiTrackInUse = usingOptiTrack;
+            UpdateUI();
+        }
+
         /// <summary>
         /// Updates the current cursor position of the model.
         /// </summary>
@@ -347,6 +385,15 @@ namespace SketchAssistantWPF
             currentCursorPosition = p;
         }
 
+        /// <summary>
+        /// Updates the current cursor position of the model.
+        /// </summary>
+        /// <param name="p">The new cursor position</param>
+        public void SetCurrentFingerPosition(Point p)
+        {
+            currentFingerPosition = p;
+        }
+
         /// <summary>
         /// Start a new Line, when the Mouse is pressed down.
         /// </summary>
@@ -355,7 +402,14 @@ namespace SketchAssistantWPF
             if (inDrawingMode)
             {
                 currentLine.Clear();
-                currentLine.Add(currentCursorPosition);
+                if (!optiTrackInUse)
+                {
+                    currentLine.Add(currentCursorPosition);
+                }
+                else
+                {
+                    currentLine.Add(currentFingerPosition);
+                }
             }
         }
 
@@ -379,7 +433,6 @@ namespace SketchAssistantWPF
         }
 
         String returnString = null;
-
         void InnerMethod(OptiTrack.Frame frame)
         {
             Console.WriteLine(frame.Trackables.Length);
@@ -393,24 +446,49 @@ namespace SketchAssistantWPF
         /// </summary>
         public void Tick()
         {
-			
-            
-            programPresenter.PassOptiTrackMessage(returnString);
-            
-
-            if (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
-            else { previousCursorPosition = currentCursorPosition; }
-            cursorPositions.Enqueue(currentCursorPosition);
+            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 (cursorPositions.Count > 0) { previousCursorPosition = cursorPositions.Dequeue(); }
+                else { previousCursorPosition = currentCursorPosition; }
+                cursorPositions.Enqueue(currentCursorPosition);
+            }
             //Drawing
-            if (inDrawingMode && programPresenter.IsMousePressed())
+            if (inDrawingMode && programPresenter.IsMousePressed() && !optiTrackInUse)
             {
-                currentLine.Add(currentCursorPosition);
-                programPresenter.UpdateCurrentLine(currentLine);
+                if (!optiTrackInUse)
+                {
+                    currentLine.Add(currentCursorPosition);
+                    programPresenter.UpdateCurrentLine(currentLine);
+                }
+                else
+                {
+                    currentLine.Add(currentFingerPosition);
+                    programPresenter.UpdateCurrentLine(currentLine);
+                }
+
             }
             //Deleting
-            if (!inDrawingMode && programPresenter.IsMousePressed())
+            if (!inDrawingMode && programPresenter.IsMousePressed() && !optiTrackInUse)
             {
-                List<Point> uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
+                List<Point> uncheckedPoints;
+                if (!optiTrackInUse)
+                {
+                    uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousCursorPosition, currentCursorPosition);
+                }
+                else
+                {
+                    uncheckedPoints = GeometryCalculator.BresenhamLineAlgorithm(previousFingerPosition, currentFingerPosition);
+                }
+
                 foreach (Point currPoint in uncheckedPoints)
                 {
                     HashSet<int> linesToDelete = CheckDeletionMatrixesAroundPoint(currPoint, deletionRadius);

+ 8 - 0
SketchAssistant/SketchAssistantWPF/MVP_Presenter.cs

@@ -119,6 +119,14 @@ namespace SketchAssistantWPF
             programModel.ChangeState(NowDrawing);
         }
 
+        /// <summary>
+        /// Pass-through function to change the OptiTrack-in-use state of the model
+        /// </summary>
+        public void ChangeOptiTrack(bool usingOptiTrack)
+        {
+            programModel.ChangeOptiTrack(usingOptiTrack);
+        }
+
         /// <summary>
         /// Pass-trough function to undo an action.
         /// </summary>

+ 19 - 0
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -169,6 +169,25 @@
                     </Rectangle.Fill>
                 </Rectangle>
             </Button>
+            <Button 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"/>
+                    </Canvas.RenderTransform>
+                    <Canvas.Resources/>
+                    <!--Unknown tag: sodipodi:namedview-->
+                    <!--Unknown tag: metadata-->
+                    <Canvas Name="layer1">
+                        <Canvas Name="imagebot_3">
+                            <Canvas.RenderTransform>
+                                <MatrixTransform Matrix="0.30985915 0 0 0.23913043 122.08141 350.11087"/>
+                            </Canvas.RenderTransform>
+                            <Path Name="imagebot_5" Fill="#FFFEFEFE" Data="m -368.99 -226.1 v -9 h -4 v -8 h -4 v -8 h -4 v -9 h -5 v -4 h -4 v -8 h 9 v 4 h 4 v 12 h 4 v -54 h 8 v 38 h 4 v -17 h 9 v 17 h 4 v -13 h 8 v 17 h 4 v -13 h 5 v 5 h 4 v 29 h -4 v 12 h -5 v 9 z"/>
+                            <Path Name="imagebot_4" Fill="#FF000000" Data="m -372.99 -222.1 v -13 h -4 v -8 h -4 v -8 h -5 v -9 h -4 v -4 h -4 v -12 h 13 v 4 h 4 v -38 h 4 v -4 h 8 v 4 h 4 v 17 h 9 v 4 h 12 v 4 h 9 v 4 h 4 v 5 h 4 v 29 h -4 v 12 h -4 v 13 z m 37 -4 v -9 h 5 v -12 h 4 v -29 h -4 v -5 h -5 v 13 h -4 v -17 h -8 v 13 h -4 v -17 h -9 v 17 h -4 v -38 h -8 v 54 h -4 v -12 h -4 v -4 h -9 v 8 h 4 v 4 h 5 v 9 h 4 v 8 h 4 v 8 h 4 v 9 z"/>
+                        </Canvas>
+                    </Canvas>
+                </Canvas>
+            </Button>
         </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"/>

+ 12 - 11
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -50,18 +50,9 @@ namespace SketchAssistantWPF
             dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
             ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.Width, (int)LeftCanvas.Height),
                 new Tuple<int, int>((int)RightCanvas.Width, (int)RightCanvas.Height));
-            OptiTrackConnector connector = new OptiTrackConnector();
-            if (connector.Init(@"C:\Users\etri\Desktop\bppp2\optitrack_setup.ttp"))
-            {
-                connector.StartTracking(handleTrackingResult);
-            }
-
+            RightCanvas.Cursor = Cursors.AppStarting;
         }
-
-    private void handleTrackingResult(OptiTrack.Frame frame)
-    {
-            Console.WriteLine(frame.Markers.Length);
-    }
+        
 
     
 
@@ -145,6 +136,16 @@ namespace SketchAssistantWPF
         private void DrawButton_Click(object sender, RoutedEventArgs e)
         {
             ProgramPresenter.ChangeState(true);
+            ProgramPresenter.ChangeOptiTrack(false);
+        }
+
+        /// <summary>
+        /// Changes the state of the program to drawing with OptiTrack
+        /// </summary>
+        private void DrawWithOptiButton_Click(object sender, RoutedEventArgs e)
+        {
+            ProgramPresenter.ChangeState(true);
+            ProgramPresenter.ChangeOptiTrack(true);
         }
 
         /// <summary>