//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);
        }
예제 #2
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;
            }
        }
예제 #3
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