Esempio n. 1
0
        /*public void saveToCSV(string step)
         * {
         *  var csv = new StringBuilder();
         *
         *  // check if scnes dir exists
         *  if (!Directory.Exists(ProjectConstants.STUDY_DIR))
         *  {
         *      // if not create it
         *      Directory.CreateDirectory(ProjectConstants.STUDY_DIR);
         *  }
         *  string path = ProjectConstants.STUDY_DIR+ "\\PBD_"+ this.m_CsvNameTime +".csv";
         *
         *
         *  //var newLine = string.Format("{0},{1},{2}{3}", PBDManager.Instance.StartTime.ToString(), PBDManager.Instance.EndTime.ToString(), PBDManager.Instance.DurationTime.ToString(), Environment.NewLine);
         *  long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
         *  var newLine = string.Format("{0},{1},{2}{3}", step, now, now - m_CsvNameTime, Environment.NewLine);
         *  csv.Append(newLine);
         *
         *  // File.WriteAllText( path, csv.ToString());
         *  File.AppendAllText(path, csv.ToString());
         * }*/

        public void checkAutomaticallyForAssemblyStep()
        {
            // PDB active?
            if (StateManager.Instance.State == AllEnums.State.RECORD && !m_BlockAssemblyCheck && !m_BlockUntilObjectIsBackAgain)
            {
                long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                if (now - m_LlastWithdrawlTimestampInMillis > 10000) // was last withdrawl at least 10 seconds ago?
                {
                    if (now - m_lastWorkingTimestampInMillis > 3000) //threshold
                    {
                        //did we already take a snapshot of this period
                        if (!m_AlreadyDetectedAssembly)
                        {
                            // user might be waiting for automatically created step
                            // check if something happened
                            AssemblyZone z = AssemblyZoneManager.Instance.createAssemblyZoneFromChanges();

                            if (z != null)
                            {
                                // block assembly until next pick
                                m_BlockAssemblyCheck = true;

                                // create a scene for displaying assemblyzone and add it to workflow
                                Scene.Scene autoScene = new Scene.Scene();
                                autoScene.Add(z.getDrawable(true));
                                AdaptiveScene adaptiveScene = new AdaptiveScene(autoScene, AdaptivityLevel.AdaptivityLevels.FirstOrDefault());
                                EditWorkflowManager.Instance.createStep(AllEnums.PBD_Mode.ASSEMBLY_DONE, adaptiveScene, "Zone-" + z.Id, z.TriggerMessage);
                                AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones.Add(z);
                                m_AlreadyDetectedAssembly = true;

                                // temporarilty display feedback that zone was detected
                                Scene.Scene     feedbackScene = new Scene.Scene();
                                Scene.SceneText text          = new Scene.SceneText(0.5 * KinectManager.Instance.ImageSize.Width, 0.5 * KinectManager.Instance.ImageSize.Height, "Step created", System.Windows.Media.Color.FromRgb(255, 255, 255), 10.0, new System.Windows.Media.FontFamily("Arial"));
                                feedbackScene.Add(text);
                                SceneManager.Instance.TemporaryFeedbackScene = feedbackScene;
                                SceneManager.Instance.DisplayTempFeedback    = true;
                                m_CreatedFeedbackTimestampInMillis           = now;
                            }

                            // create a new snapshot
                            if (!m_IsUserWorking)
                            {
                                AssemblyZoneManager.Instance.createDepthSnapshot();
                            }
                        }
                    }
                }
            }

            // maybe find a better place for this:
            // check if the feedback should still be displayed
            long nower = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            if (nower - m_CreatedFeedbackTimestampInMillis > m_FeedbackShow_Time)
            {
                SceneManager.Instance.DisplayTempFeedback = false;
                SceneManager.Instance.TemporaryFeedbackScene.Clear();
            }
        }
Esempio n. 2
0
        private AllEnums.Direction isMouseOnObj(System.Windows.Point pPoint, AssemblyZone pRect)
        {
            if (pPoint.X >= pRect.X && pPoint.X <= (pRect.X + pRect.Width) &&
                pPoint.Y >= pRect.Y - (BOX_BORDERWIDTH / 2) &&
                pPoint.Y <= pRect.Y + (BOX_BORDERWIDTH / 2))
            {
                return(AllEnums.Direction.NORTH);
            }
            else if (pPoint.X >= pRect.X && pPoint.X <= (pRect.X + pRect.Width) &&
                     pPoint.Y >= pRect.Y + pRect.Height - (BOX_BORDERWIDTH / 2) &&
                     pPoint.Y <= pRect.Y + (BOX_BORDERWIDTH / 2) + pRect.Height)
            {
                return(AllEnums.Direction.SOUTH);
            }
            else if (pPoint.Y >= pRect.Y && pPoint.Y <= (pRect.Y + pRect.Height) &&
                     pPoint.X >= pRect.X - (BOX_BORDERWIDTH / 2) &&
                     pPoint.X <= pRect.X + (BOX_BORDERWIDTH / 2))
            {
                return(AllEnums.Direction.WEST);
            }
            else if (pPoint.Y >= pRect.Y && pPoint.Y <= (pRect.Y + pRect.Height) &&
                     pPoint.X >= pRect.X + pRect.Width - (BOX_BORDERWIDTH / 2) &&
                     pPoint.X <= pRect.X + (BOX_BORDERWIDTH / 2) + pRect.Width)
            {
                return(AllEnums.Direction.EAST);
            }

            return(AllEnums.Direction.NONE);
        }
 public EditAssemblyZoneDialog(AssemblyZone z)
 {
     InitializeComponent();
     m_Zone = z;
     textBoxAssemblyZoneName.Text     = m_Zone.Name;
     inputMatchPercentageOffset.Value = (int)m_Zone.MatchPercentageOffset;
 }
Esempio n. 4
0
        private float calculateCurrentMeanDepth(AssemblyZone pZone)
        {
            Image <Gray, Int32> img = HciLab.Kinect.CameraManager.Instance.DepthImage;
            int  count = 0;
            long sum   = 0;

            for (int x = pZone.X; x < pZone.Width; x++)
            {
                for (int y = pZone.Y; y < pZone.Height; y++)
                {
                    int depthval      = img.Data[y, x, 0];
                    int real_depthval = depthval;

                    if (AdminView.Instance.IsKinectActive)
                    {
                        real_depthval = depthval / KinectManager.SCALE_FACTOR;
                    }

                    if (real_depthval != 0)
                    {
                        sum = sum + real_depthval;
                        count++;
                    }
                }
            }

            if (count == 0)
            {
                return(0);
            }
            else
            {
                return(sum / count);
            }
        }
Esempio n. 5
0
        public void checkQSModeEndConditions(AssemblyZone zone)
        {
            bool allDone = true;

            for (int i = m_CurrentWorkingStepNumber; i < m_CurrentWorkingStepNumber + m_NumQS; i++)
            {
                if (!m_QSFullfilled[i])
                {
                    var step = LoadedWorkflow.WorkingSteps.ElementAt(i);
                    if (step.EndConditionObjectName == ("" + zone.TriggerMessage))
                    {
                        m_QSFullfilled[i] = true;
                        LoadQSModeScene();
                    }
                    else
                    {
                        allDone = false;
                    }
                }
            }
            if (allDone)
            {
                m_QSMode = false;
                NotifyPropertyChanged("QSModeEnabled");
                m_CurrentWorkingStepNumber = m_CurrentWorkingStepNumber + m_NumQS;
                LoadCurrentWorkingStep();
            }
        }
Esempio n. 6
0
        private void MenuItemSetTrigger_Cick(object sender, RoutedEventArgs e)
        {
            Object o = listBoxAssemblyZones.SelectedItem;

            if (m_WorkflowListview.SelectedIndex >= 0 && o is AssemblyZone)
            {
                WorkingStep  selectedWorkingStep  = (WorkingStep)m_WorkflowListview.SelectedItem;
                AssemblyZone selectedAssemblyZone = (AssemblyZone)o;
                //Create new Failstate
                selectedWorkingStep.EndConditionObjectName = selectedAssemblyZone.TriggerMessage;
            }
        }
Esempio n. 7
0
        private void MenuItemCreateErrorTrigger_Cick(object sender, RoutedEventArgs e)
        {
            Object o = listBoxAssemblyZones.SelectedItem;

            if (m_WorkflowListview.SelectedIndex >= 0 && o is AssemblyZone)
            {
                WorkingStep  selectedWorkingStep  = (WorkingStep)m_WorkflowListview.SelectedItem;
                AssemblyZone selectedAssemblyZone = (AssemblyZone)o;
                //Create new Failstate
                selectedWorkingStep.CreateFailState(selectedAssemblyZone.TriggerMessage);
            }
        }
Esempio n. 8
0
        private void buttonAssemblyZoneDetectZone_Click(object sender, RoutedEventArgs e)
        {
            AssemblyZone z = AssemblyZoneManager.Instance.createAssemblyZoneFromChanges();

            if (z != null)
            {
                // Set collection to null to force refresh
                Resources["checkBoxCollection"] = null;
                AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones.Add(z);
                // Refresh checkBoxCollection in XAML
                Resources["checkBoxCollection"] = AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones;
            }
        }
Esempio n. 9
0
        private void MenuItem_EditCustomScene(object sender, RoutedEventArgs e)
        {
            var selectedItem = m_ListBoxAssemblyZoneWuerfel.SelectedItem;

            if (selectedItem is AssemblyZone)
            {
                AssemblyZone b = (AssemblyZone)selectedItem;

                // call editor

                if (b != null)
                {
                    SceneItem item;
                    if (b.CustomScene == null)
                    {
                        item        = b.getDrawable(false);
                        item.Touchy = true;
                        SceneEditorDialog dlg;

                        // set Editor Mode
                        StateManager.Instance.SetNewState(this, HciLab.motionEAP.InterfacesAndDataModel.AllEnums.State.EDIT);

                        SceneManager.Instance.CurrentScene.Clear();
                        SceneManager.Instance.CurrentScene.Add(item);
                        dlg = new SceneEditorDialog(b);
                        dlg.Show();
                    }
                    else
                    {
                        SceneEditorDialog dlg;

                        // set Editor Mode
                        StateManager.Instance.SetNewState(this, HciLab.motionEAP.InterfacesAndDataModel.AllEnums.State.EDIT);

                        SceneManager.Instance.CurrentScene.Clear();
                        if (b.CustomScene is Scene.Scene)
                        {
                            Scene.Scene scene = (Scene.Scene)b.CustomScene;
                            foreach (SceneItem itemIter in scene.Items)
                            {
                                itemIter.Touchy = true;
                            }

                            SceneManager.Instance.CurrentScene = scene;
                            dlg = new SceneEditorDialog(b);
                            dlg.Show();
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private float getPercentageMatchingDepthArray(AssemblyZone pZone)
        {
            int LowerTolerance = SettingsManager.Instance.Settings.AssemblyZonesInputMatchTolerance;
            int UpperTolerance = SettingsManager.Instance.Settings.AssemblyZonesInputMatchTolerance;

            Image <Gray, Int32> img = HciLab.Kinect.CameraManager.Instance.DepthImage;

            if (pZone.DepthArray.GetLength(0) != pZone.Width || pZone.DepthArray.GetLength(1) != pZone.Height)
            {
                return(-1.0f);
            }

            int sum    = 0;
            int within = 0;

            for (int x = pZone.X; x < pZone.X + pZone.Width; x++)
            {
                for (int y = pZone.Y; y < pZone.Y + pZone.Height; y++)
                {
                    int depthval = img.Data[y, x, 0];
                    int matchval = pZone.DepthArray[x - pZone.X, y - pZone.Y];

                    int real_depth    = depthval;
                    int real_matchval = matchval;

                    if (AdminView.Instance.IsKinectActive)
                    {
                        real_depth    = depthval / KinectManager.SCALE_FACTOR;
                        real_matchval = matchval / KinectManager.SCALE_FACTOR;
                    }

                    if (real_matchval != 0 && real_depth != 0 && (!pZone.UseDepthmask || pZone.DepthMask[x - pZone.X, y - pZone.Y]))
                    //Skip zero values (== invalid values) // skip depth mask values
                    {
                        sum = sum + 1;
                        if ((real_depth < (real_matchval + UpperTolerance)) && (real_depth > (real_matchval - LowerTolerance)))
                        {
                            within = within + 1;
                        }
                    }
                }
            }
            float percentage = 0.0f;

            if (sum != 0)
            {
                percentage = ((float)within) / ((float)sum);
            }
            return(percentage);
        }
Esempio n. 11
0
 private void initializeDrag(System.Windows.Point p)
 {
     foreach (AssemblyZone b in AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones)
     {
         if (b.IsSelected)
         {
             m_DragMode = isMouseOnObj(p, b);
             if (m_DragMode != AllEnums.Direction.NONE)
             {
                 m_DraggedObj  = b;
                 m_DragEnabled = true;
                 return;
             }
         }
     }
     m_DragEnabled = false;
 }
Esempio n. 12
0
        /// <summary>
        /// Listener which handles the deletion of one or multiple selected assemblyzones
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_DeleteSelectedAssemblyZone(object sender, RoutedEventArgs e)
        {
            // Get list with selected items. This list contains only elements which are selected
            IList selectedItems         = m_ListBoxAssemblyZoneWuerfel.SelectedItems;
            int   amountOfSelectedItems = selectedItems.Count;

            for (int i = 0; i < amountOfSelectedItems; i++)
            {
                if (selectedItems.Count > 0)
                {
                    if (m_ListBoxAssemblyZoneWuerfel.Items.Contains(selectedItems[0]))
                    {
                        AssemblyZone b = (AssemblyZone)selectedItems[0];
                        AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones.Remove(b);
                    }
                }
            }
        }
Esempio n. 13
0
        private void MenuItem_EditSelectedAssemblyZone(object sender, RoutedEventArgs e)
        {
            var selectedItem = m_ListBoxAssemblyZoneWuerfel.SelectedItem;

            if (selectedItem is AssemblyZone)
            {
                AssemblyZone b = (AssemblyZone)selectedItem;

                EditAssemblyZoneDialog dlg = new EditAssemblyZoneDialog(b);
                dlg.ShowDialog(); // blocking
                if (dlg.wasOkay())
                {
                    Resources["checkBoxCollection"] = null;
                    AssemblyZone editedAssemblyZone = dlg.EditedAssemblyZone;
                    AssemblyZoneManager.Instance.updateCurrentAssemblyZone(editedAssemblyZone);
                    Resources["checkBoxCollection"] = AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Manual create a new AssemblyZone by clicking on to the GUI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createANewObj(object sender, MouseButtonEventArgs e)
        {
            Image <Gray, Int32> img = HciLab.Kinect.CameraManager.Instance.DepthImage;

            if (img != null)
            {
                // define a new zone
                AssemblyZone z = AssemblyZoneManager.Instance.createAssemblyZoneFromFactory();
                z.X = (int)e.GetPosition(m_Image).X;
                z.Y = (int)e.GetPosition(m_Image).Y;

                z.Z = img.Data[z.Y, z.X, 0];
                if (z.Z == 0)
                {
                    AssemblyZoneManager.Instance.decreaseIDByOne();
                    return;
                }

                // check if box is bigger than depth frame
                if (MANUAL_ZONE_WIDTH + z.X < img.Width)
                {
                    z.Width = MANUAL_ZONE_WIDTH;
                }
                else
                {
                    z.Width = img.Width - z.X;
                }

                if (MANUAL_ZONE_HEIGHT + z.Y < img.Height)
                {
                    z.Height = MANUAL_ZONE_HEIGHT;
                }
                else
                {
                    z.Height = img.Height - z.Y;
                }

                z.DepthArray = AssemblyZoneManager.getDepthArrayFromAssemblyZone(z);
                Resources["checkBoxCollection"] = null;
                AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones.Add(z);
                Resources["checkBoxCollection"] = AssemblyZoneManager.Instance.CurrentLayout.AssemblyZones;
            }
        }
Esempio n. 15
0
        private void createAssemblyButton_Click(object sender, RoutedEventArgs e)
        {
            Object o = listBoxAssemblyZones.SelectedItem;

            if (o != null)
            {
                if (o is AssemblyZone)
                {
                    AssemblyZone z = (AssemblyZone)o;

                    AdaptiveScene easyScene   = new AdaptiveScene(EditWorkflowManager.Instance.getAssemblyZoneAutoScene(z), AdaptivityLevel.AdaptivityLevels.First());
                    AdaptiveScene mediumScene = new AdaptiveScene(EditWorkflowManager.Instance.getAssemblyZoneAutoScene(z), AdaptivityLevel.AdaptivityLevels.ElementAt(1));

                    var adaptiveScenes = new List <AdaptiveScene> {
                        easyScene, mediumScene
                    };

                    EditWorkflowManager.Instance.createStep(HciLab.motionEAP.InterfacesAndDataModel.AllEnums.PBD_Mode.ASSEMBLY_DONE, adaptiveScenes, "Zone-" + z.Id, z.TriggerMessage);
                }
            }
        }
Esempio n. 16
0
        public void checkEndConditionspublic(AssemblyZone zone)
        {
            if (m_LoadedWorkflow != null)
            {
                if (m_CurrentWorkingStepNumber < m_LoadedWorkflow.WorkingSteps.Count)
                {
                    if (m_QSMode)
                    {
                        checkQSModeEndConditions(zone);
                    }
                    else
                    {
                        WorkingStep step = m_LoadedWorkflow.WorkingSteps.ElementAt(m_CurrentWorkingStepNumber);
                        if (step.EndConditionObjectName == ("" + zone.TriggerMessage))
                        {
                            // trigger next step
                            NextWorkingStep(AllEnums.WorkingStepEndConditionTrigger.ASSEMBLY_ZONE);
                        }
                        int i = 0;
                        while (step.HasFailstate(i))
                        {
                            if (step.GetFailState(i).CheckForFail(zone.TriggerMessage))
                            {
                                // trigger FailEvent
                                OnFailStateOccured(step.GetFailState(i));
                                // Show Error Scene
                                SceneManager.Instance.CurrentScene = step.GetFailStateScene(i);

                                m_AssemblyErrors++;
                            }
                            i++;
                        }
                    }
                }
            }
        }