protected override void OnPaint(PaintEventArgs pe)
        {
            // we draw the Bitmap into the image in
            // the memory

            BackBuffer     = new Bitmap(this.Width, this.Height);
            BufferGraphics = Graphics.FromImage(BackBuffer);

            DrawTemplate(BufferGraphics);
            if (this.blinkCount <= this.maxBlinkCount)
            {
                try
                {
                    if (singleCount == 1)
                    {
                        if (ReplayTrial.timeStampDataQueue.Count > 0)
                        {
                            ObjPositionData posData = ReplayTrial.timeStampDataQueue.Dequeue();
                            ReplayTrial.ObjPosDataPrev = posData;
                        }
                        singleCount++;
                    }

                    DrawBlinkingObjects(BufferGraphics);
                }
                catch (SystemException e)
                {
                    // do nothing
                    // continue to next iteration
                    throw;
                }
            }
            else
            {
                try
                {
                    DrawReplayGraphics(BufferGraphics);
                }
                catch (SystemException)
                {
                    // do nothing
                    // continue to next iteration
                    throw;
                }
            }

            // now we draw the image into the screen
            BufferGraphics.Dispose();
            pe.Graphics.DrawImageUnscaled(BackBuffer, 0, 0);
        }
Example #2
0
        private static void enQueueTimeStampData()
        {
            try
            {
                while (!parser.isEOF())
                {
                    int speed = NORMAL; // default Speed

                    if (SPEED_FACTOR.Equals("NORMAL"))
                    {
                        speed = NORMAL;
                    }
                    else if (SPEED_FACTOR.Equals("SLOW"))
                    {
                        speed = SLOW;
                    }
                    else if (SPEED_FACTOR.Equals("VERYSLOW"))
                    {
                        speed = VERYSLOW;
                    }

                    else if (SPEED_FACTOR.Equals("FAST"))
                    {
                        speed = FAST;
                    }

                    ObjPositionData currentObjPos = null;
                    for (int index = 1; index <= speed && !parser.isEOF(); index++)
                    {
                        currentObjPos = parser.getNextTimeStampData();
                    }
                    if (currentObjPos != null)
                    {
                        timeStampDataQueue.Enqueue(currentObjPos);
                    }
                }
            }
            catch (Exception)
            {
                // do nothing
                throw;
            }

            int tmpCount = timeStampDataQueue.Count;
        }
        //return all objectsposition data for one time stamp
        public ObjPositionData getNextTimeStampData()
        {
            ObjPositionData objPosData = new ObjPositionData();

            if (!reader.EOF)
            {
                reader.ReadToFollowing("Time");
                if (reader.HasAttributes && reader.AttributeCount > 0)
                {
                    int timeStamp = Convert.ToInt32(reader.GetAttribute("stamp"));
                    objPosData.TimeStamp = timeStamp;
                }

                do
                {
                    reader.Read();

                    // reader.ReadToFollowing("obj");
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "obj")
                        {
                            if (reader.HasAttributes && reader.AttributeCount >= 0)
                            {
                                string     name    = reader.GetAttribute("name").ToString();
                                float      x       = Convert.ToSingle(reader.GetAttribute("x"));
                                float      y       = Convert.ToSingle(reader.GetAttribute("y"));
                                ObjectData objdata = new ObjectData();
                                objdata.objName = name;
                                objdata.xPos    = x;
                                objdata.YPos    = y;

                                objPosData.addObjData(objdata);
                            }
                        }
                        else if (reader.Name == "Time")
                        {
                            break;
                        }
                    }
                } while (!(reader.EOF) && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Time"));
            }
            return(objPosData);
        }
Example #4
0
        public static void cleanUp()
        {
            ReplayTrial.formSetting.clear();
            if (log != null)
            {
                ReplayTrial.log.Close();
            }

            ReplayTrial.objects.Clear();
            if (parser != null)
            {
                ReplayTrial.parser.close();
            }
            if (posData != null)
            {
                ReplayTrial.posData = null;
            }
            ReplayTrial.timeStampDataQueue.Clear();
        }
        /**
         * Routine being invoked by paintTimer interval to
         * display trial objects along with Gaze position.
         *
         */
        private void DrawReplayGraphics(Graphics g)
        {
            // Obtain objects information and create Bitmaps and write them to memory
            try
            {
                if (ReplayTrial.timeStampDataQueue.Count > 0)
                {
                    ObjPositionData posData = ReplayTrial.timeStampDataQueue.Dequeue();
                    ReplayTrial.ObjPosDataPrev = posData;

                    if (posData != null)
                    {
                        long timeStamp = posData.timeStamp;
                        LinkedList <ObjectData>  objList = posData.getobjList();
                        IEnumerator <ObjectData> itr     = objList.GetEnumerator();
                        while (itr.MoveNext())
                        {
                            ObjectData obj = (ObjectData)itr.Current;

                            string name = obj.objName;
                            if (ReplayTrial.objects.ContainsKey(name))
                            {
                                string objFilePath = (string)ReplayTrial.objects[name];

                                int    xpos   = Convert.ToInt32(obj.xPos);
                                int    ypos   = Convert.ToInt32(obj.yPos);
                                Bitmap objBmp = new Bitmap((String)objFilePath);

                                if (name == "gaze")
                                {
                                    objBmp.MakeTransparent(objBmp.GetPixel(1, 1));
                                    g.DrawImage(objBmp, Convert.ToInt32(obj.xPos), Convert.ToInt32(obj.yPos), objBmp.Width, objBmp.Height);
                                }
                                else
                                {
                                    g.DrawImage(objBmp, Convert.ToInt32(obj.xPos), Convert.ToInt32(obj.yPos), objBmp.Width, objBmp.Height);

                                    if (ReplayTrial.formSetting.isTargetObject(name) && this.markTargetObjectsFlag)
                                    {
                                        int bitmapWidth  = objBmp.Width;
                                        int bitmapHeight = objBmp.Height;
                                        int objXpos      = Convert.ToInt32(obj.xPos);
                                        int objYpos      = Convert.ToInt32(obj.yPos);
                                        g.DrawRectangle(new Pen(this.ForeColor, (float)5.0), objXpos, objYpos, bitmapWidth + 10, bitmapHeight + 10);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }
            catch (System.Xml.XmlException ignore)
            {
                //  continue;
                //  string errorStr = ignore.ToString();
                throw;
            }

            catch (Exception ignore)
            {
                // continue;
                //  string errorStr = ignore.ToString();
                throw;
            }
        }
        private void DrawBlinkingObjects(Graphics g)
        {
            try
            {
                if (ReplayTrial.ObjPosDataPrev != null)
                {
                    ObjPositionData          posData   = ReplayTrial.ObjPosDataPrev;
                    long                     timeStamp = posData.timeStamp;
                    LinkedList <ObjectData>  objList   = posData.getobjList();
                    IEnumerator <ObjectData> itr       = objList.GetEnumerator();
                    while (itr.MoveNext())
                    {
                        ObjectData obj  = (ObjectData)itr.Current;
                        string     name = obj.objName;
                        string     objFilePath;
                        int        xpos = 0;
                        int        ypos = 0;

                        bool isTargetObject = ReplayTrial.formSetting.getTargetObjects().Contains(name);

                        if (ReplayTrial.objects.ContainsKey(name))
                        {
                            objFilePath = (string)ReplayTrial.objects[name];
                            Bitmap objBmp = new Bitmap((String)objFilePath);
                            xpos = Convert.ToInt32(obj.xPos);
                            ypos = Convert.ToInt32(obj.yPos);
                            if (isTargetObject)
                            {
                                if (this.blinkColorOn == 1)
                                {
                                    g.DrawImage(objBmp, Convert.ToInt32(obj.xPos), Convert.ToInt32(obj.yPos), objBmp.Width, objBmp.Height);
                                }
                            }
                            else if (name == "gaze")
                            {
                                objBmp.MakeTransparent(objBmp.GetPixel(1, 1));
                                g.DrawImage(objBmp, Convert.ToInt32(obj.xPos), Convert.ToInt32(obj.yPos), objBmp.Width, objBmp.Height);
                            }
                            else
                            {
                                g.DrawImage(objBmp, Convert.ToInt32(obj.xPos), Convert.ToInt32(obj.yPos), objBmp.Width, objBmp.Height);
                            }
                        }
                    } // end of while
                }     // end  of if
                else
                {
                    g.DrawString("ReplayTrialNew.ObjPosDataPrev is null!!", new Font("Times New Roman", 20), new SolidBrush(Color.Black), 10, 50);
                }
            }// try block ends
            catch (System.Xml.XmlException ignore)
            {
                //  continue;
                throw;
            }

            catch (Exception ignore)
            {
                // continue;
                throw;
            }
        }
Example #7
0
        /**
         * Routine to enqueue Time stamp with Object Position Data from GELog File
         * Gets called from Thread
         */
        public void doWork()
        {
            try
            {
                // retrieve all Object Positions data and enqueue them
                Regex timeStartRegex = new Regex("^TimeStart");
                Regex timeEndRegex   = new Regex("^TimeEnd");
                if (File.Exists(geLogFileName))
                {
                    using (StreamReader sr = new StreamReader(geLogFileName))
                    {
                        // DisplayFileCreation.WriteError("in Object Data worker  thread : doWork method : stream reader opened found");

                        String newLine = null;

                        do
                        {
                            do
                            {
                                newLine = sr.ReadLine();
                            } while (newLine != null && !(timeStartRegex.IsMatch(newLine)));

                            if (newLine == null)
                            {
                                break;
                            }

                            // Split the new line to obtain the timeStamp data
                            String[] timeStampData = Regex.Split(newLine.Trim(), "\\s+");

                            ObjPositionData objPosData = new ObjPositionData();
                            objPosData.timeStamp = Convert.ToInt32(timeStampData[1].Trim());

                            String objDataLine;
                            // here we have a line that has Time Stamp Data
                            // continue to read new Line and Process the line's contents until TimeEnd node is seen
                            objDataLine = sr.ReadLine();
                            while (objDataLine != null && !timeEndRegex.IsMatch(objDataLine))
                            {
                                string[] objData = Regex.Split(objDataLine, "\\s+");

                                ObjectData data    = new ObjectData();
                                String     objname = objData[0].Trim().Substring(0, objData[0].Trim().Length - 1);
                                String     xPos    = objData[1].Trim();
                                String     yPos    = objData[3].Trim();

                                data.objName = objname;
                                data.xPos    = Convert.ToInt32(xPos);
                                data.yPos    = Convert.ToInt32(yPos);

                                objPosData.addObjData(data);
                                //  DisplayFileCreation.WriteError("in Object data  worker  thread : doWork method : " + Convert.ToInt32(xPos));
                                // move on to next line
                                objDataLine = sr.ReadLine();
                            }// end of while loop  -- reading data from a unique TimeStart node
                            if (newLine == null)
                            {
                                break;
                            }
                            DisplayFileCreation.geLogTrialDataQueue.Enqueue(objPosData); // enqueue positions of all objects for the current TimeStamp
                        } while (newLine != null);                                       // move on to next line  until EOF
                    }// end of reading from Stream Reader
                }
                else
                {
                    DisplayFileCreation.WriteError("Aborting processing Trial info .Invalid Input File : " + geLogFileName);
                }
            }

            catch (StackOverflowException e)
            {
                DisplayFileCreation.WriteError(" StackOverflowException : " + e.StackTrace);
            }
            catch (SystemException e)
            {
                DisplayFileCreation.WriteError(" SystemException : " + e.StackTrace);
            }

            catch (ApplicationException e)
            {
                DisplayFileCreation.WriteError(" ApplicationException : " + e.StackTrace);
            }

            catch (Exception) {
                throw;
            }
        }
Example #8
0
        /**
         * Routine to enqueue Gaze position data into a Queue
         */
        public void doWork()
        {
            //local  variable
            ObjPositionData gazePrevData = null;
            float           prevXpos     = 0;
            float           prevYPos     = 0;

            DisplayFileCreation.logData("Gaze  worker  thread : Processing doWork method ");
            if (File.Exists(edfFileName))
            {
                DisplayFileCreation.logData("in gaze  worker  thread : doWork method  : edf  file exists");


                // retrieve all Gaze Position data and enqueue them
                using (StreamReader sr = new StreamReader(edfFileName))
                {
                    // DisplayFileCreation.WriteError("in gaze  worker  thread : doWork method : stream reader  opened");

                    String line;

                    do
                    {
                        line = sr.ReadLine();
                        if (line != null && gazePostionRegex.IsMatch(line))
                        {
                            // here have a line that has gaze position data
                            ObjPositionData gazeData = new ObjPositionData();
                            ObjectData      data     = new ObjectData();

                            String[] split = Regex.Split(line.Trim(), "\\s+");

                            if (split.Length < 3)
                            {
                                continue;
                            }

                            String str1 = split[0];
                            String str2 = split[1];
                            String str3 = split[2];
                            if (str2 == "." || str3 == ".")
                            {
                                String timestampNew = str1;
                                ////if (gazePrevData != null)
                                // {
                                gazePrevData = new ObjPositionData();

                                gazePrevData.TimeStamp = Convert.ToInt32(timestampNew);
                                ObjectData thisData = new ObjectData();
                                thisData.IsTargetObject = 0;
                                thisData.ObjName        = "gaze";
                                thisData.XPos           = prevXpos;
                                thisData.YPos           = prevYPos;
                                gazePrevData.addObjData(thisData);

                                DisplayFileCreation.edfTrialDataQueue.Enqueue(gazePrevData);
                                // }
                                //  * */
                                //   continue;
                            }
                            else
                            {
                                String timestamp = split[0].Trim();
                                String xPos      = split[1].Trim();
                                String yPos      = split[2].Trim();

                                data.objName = "gaze";
                                float xpos = -1;
                                float ypos = -1;
                                try
                                {
                                    xpos = float.Parse(xPos);
                                    ypos = float.Parse(yPos);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                if (xpos == -1 || ypos == -1)
                                {
                                    continue;
                                }
                                else
                                {
                                    data.xPos = xpos;
                                    data.yPos = ypos;
                                    gazeData.addObjData(data);
                                    gazeData.timeStamp = Convert.ToInt32(timestamp);
                                    DisplayFileCreation.edfTrialDataQueue.Enqueue(gazeData);
                                    prevXpos               = xpos;
                                    prevYPos               = ypos;
                                    gazePrevData           = null;
                                    gazePrevData           = new ObjPositionData();
                                    gazePrevData.TimeStamp = gazeData.timeStamp;
                                    LinkedList <ObjectData> list = gazeData.getobjList();
                                    gazePrevData.setObjList(list);
                                }
                                //DisplayFileCreation.WriteError("in gaze  worker  thread : doWork method : " + Convert.ToInt32(timestamp));
                            } // else loop ends
                        }     // end of if loop
                    } while (line != null);
                }             // end of reading from Stream Reader
            }
            else
            {
                DisplayFileCreation.WriteError("ABORTING processing Object Position Data: Invalid input File :" + edfFileName);
            }
        } // end of enqueing Gaze data from EDF File
Example #9
0
        /**
         * Process Trial Related Data.
         */
        public static XmlNode processTrialStart(String geLogFileName, XmlNode DisplayFileStartNode, XmlDocument xmlDoc, String edfFileName)
        {
            XmlNode         trialStartNode     = null;
            long            prevGazeTimeStamp  = 0;
            ObjPositionData gePrevPositionData = null;

            try
            {
                log.WriteLine("Processing Trial Start");
                log.Flush();

                Regex gazePostionRegex = new Regex(@"^(\d+)\s*(\d.*)\s*(\d.*)\s");
                trialStartNode = processSingleNode("TrialStart", DisplayFileStartNode, xmlDoc);

                GazeDataWorker   gazeWorker   = new GazeDataWorker(edfFileName, gazePostionRegex);
                ObjectDataWorker objectWorker = new ObjectDataWorker(geLogFileName);

                ReplayTrial.timeStampDataQueue.Clear();
                geLogTrialDataQueue.Clear();

                Thread gazeWorkerThread   = new Thread(gazeWorker.doWork);
                Thread objectWorkerThread = new Thread(objectWorker.doWork);
                log.WriteLine("created threads");
                log.Flush();
                try
                {
                    gazeWorkerThread.Start();
                    objectWorkerThread.Start();
                    gazeWorkerThread.Join();
                    objectWorkerThread.Join();
                }
                catch (ThreadInterruptedException e)
                {
                    log.WriteLine(" Thread Interrupted Exception " + e.StackTrace);
                }
                catch (ThreadAbortException e)
                {
                    log.WriteLine(" ThreadAbortException : " + e.StackTrace);
                }
                catch (SystemException e)
                {
                    log.WriteLine("SystemException : " + e.StackTrace);
                }

                catch (Exception)
                {
                    log.WriteLine("Exception with Threads");
                }
                log.WriteLine(" threads completed  job");
                log.Flush();

                int edfCount = edfTrialDataQueue.Count;
                int geCount  = geLogTrialDataQueue.Count;

                long relativeDifference = 0;

                long gelogFirstTimeStamp = 0;
                long gazeFirstTimeStamp  = 0;
                if (edfCount > 0)
                {
                    ObjPositionData firstTimeStampData = (ObjPositionData)edfTrialDataQueue.Peek();
                    gazeFirstTimeStamp = firstTimeStampData.timeStamp;
                }


                if (geCount > 0)
                {
                    ObjPositionData geFirstData = (ObjPositionData)geLogTrialDataQueue.Peek();
                    gelogFirstTimeStamp = geFirstData.timeStamp;
                }
                if (gazeFirstTimeStamp != gelogFirstTimeStamp)
                {
                    if (gazeFirstTimeStamp > gelogFirstTimeStamp)
                    {
                        relativeDifference = gazeFirstTimeStamp - gelogFirstTimeStamp;
                    }
                }

                if (edfCount != geCount)
                {
                    log.WriteLine("WARNING : Time Stamps Obtained from EDFFile does not match the number of timeStamps in GELog ");
                    log.WriteLine("WARNING : TimeStamp Count :: edf :" + edfCount + "  , GELog : " + geCount);
                    log.Flush();
                }


                XmlNode timeStartNode   = null;
                long    gePrevTimeStamp = 0;
                int     count           = 0;
                while (edfTrialDataQueue.Count > 0) //&& geLogTrialDataQueue.Count > 0
                {
                    long edfTimeStamp  = -1;
                    long gazeTimeStamp = 0;


                    if (edfTrialDataQueue.Count > 0)
                    {
                        ObjPositionData data = null;
                        do
                        {
                            data         = (ObjPositionData)edfTrialDataQueue.Dequeue();
                            edfTimeStamp = data.timeStamp;
                            if (prevGazeTimeStamp == 0)
                            {
                                prevGazeTimeStamp = edfTimeStamp;
                            }
                        } while ((edfTimeStamp != prevGazeTimeStamp) && (edfTrialDataQueue.Count > 0));

                        // Obtain the Refresh rate and  calculate number of times data would have been recorded.
                        int tmpRefreshRate    = 1;
                        int refreshRateFactor = 1000 / REFRESH_RATE;
                        if ((refreshRateFactor % 2) == 0)
                        {
                            tmpRefreshRate = refreshRateFactor;
                        }
                        else
                        {
                            tmpRefreshRate = refreshRateFactor - 1;
                        }

                        prevGazeTimeStamp = edfTimeStamp + (tmpRefreshRate);
                        timeStartNode     = processSingleNode("Time", "stamp", edfTimeStamp.ToString(), trialStartNode, xmlDoc);
                        LinkedList <ObjectData> gazedataList = data.getobjList();
                        foreach (ObjectData objData in gazedataList)
                        {
                            String name   = objData.objName;
                            String xCoord = objData.xPos.ToString();
                            String yCoord = objData.yPos.ToString();

                            XmlElement objNode = addElement("obj", timeStartNode, xmlDoc);
                            addAttribute("name", name, objNode);
                            addAttribute("x", xCoord, objNode);
                            addAttribute("y", yCoord, objNode);
                            log.WriteLine(" objname : " + name + " , x : " + xCoord + " , Y :" + yCoord);
                            log.Flush();
                        }
                        edfCount--;
                    }

                    log.WriteLine(" dequeing gelog  data ");
                    log.Flush();
                    long            geTimeStamp = -1;
                    ObjPositionData geData      = null;
                    //  for (int index = 0; index < speedControl * 5; index++)
                    //  {
                    if (geLogTrialDataQueue.Count > 0)
                    {
                        long geNewTimeStamp = 0;
                        geData      = (ObjPositionData)geLogTrialDataQueue.Dequeue();
                        geTimeStamp = geData.timeStamp;
                        geCount--;
                    }
                    else if (gePrevPositionData != null)
                    {
                        geData      = gePrevPositionData;
                        geTimeStamp = geData.timeStamp;
                    }

                    if (geData != null)
                    {
                        gePrevPositionData = geData;
                        LinkedList <ObjectData> objdataList = geData.getobjList();
                        foreach (ObjectData objData in objdataList)
                        {
                            String name   = objData.objName;
                            String xCoord = objData.xPos.ToString();
                            String yCoord = objData.yPos.ToString();

                            XmlElement objNode = addElement("obj", timeStartNode, xmlDoc);
                            addAttribute("name", name, objNode);
                            addAttribute("x", xCoord, objNode);
                            addAttribute("y", yCoord, objNode);
                            log.WriteLine(" objname : " + name + " , x : " + xCoord + " , Y :" + yCoord);
                            log.Flush();
                        }
                        count++;
                    }
                } //end of while loop

                geLogTrialDataQueue.Clear();
            }
            catch (Exception e)
            {
                throw new ATLogicException(" Error while processing TrialStart  parameters .   gecount : " + geLogTrialDataQueue.Count + "  , edf  count : " + edfTrialDataQueue.Count);
            }
            return(trialStartNode);
        }