private static void TestGeometricMedian() { // square with centre at (1, 1) // List<Point> points = new List<Point>(); //points.Add(new Point(0, 0)); //points.Add(new Point(0, 2)); //points.Add(new Point(2, 2)); //points.Add(new Point(2, 0)); // line with centre at 3, 3 List <Point> points = new List <Point>(); points.Add(new Point(1, 1)); points.Add(new Point(2, 2)); points.Add(new Point(3, 3)); points.Add(new Point(4, 4)); points.Add(new Point(5, 5)); // Bunch of points. //List<Point> points = new Point[1000]; //for(int i = 0; i < 1000; i++){ // points.Add(new Point(i*2, i*3)); //} RawToFixationConverter converter = new RawToFixationConverter(null); Point median = converter.GeometricMedian(points); Console.WriteLine("Median was: X:" + median.x + " Y:" + median.y); }
private static void TestConverter() { /* * // line with centre at 3, 3 * List<GazePoint> gazePoints = new List<GazePoint>(); * gazePoints.Add(new GazePoint(1, 1, 1)); * gazePoints.Add(new GazePoint(0.8f, 0.8f, 2)); * gazePoints.Add(new GazePoint(0.9f, 0.9f, 3)); * gazePoints.Add(new GazePoint(1.1f, 1.1f, 4)); * gazePoints.Add(new GazePoint(10, 10, 5)); * gazePoints.Add(new GazePoint(9.8f, 9.8f, 6)); * gazePoints.Add(new GazePoint(9.9f, 9.9f, 7)); * gazePoints.Add(new GazePoint(11, 11, 8)); * gazePoints.Add(new GazePoint(30, 30, 9)); * gazePoints.Add(new GazePoint(31f, 31f, 10)); * gazePoints.Add(new GazePoint(29f, 29f, 11)); * gazePoints.Add(new GazePoint(25f, 25f, 12)); * gazePoints.Add(new GazePoint(50, 50, 13)); * gazePoints.Add(new GazePoint(51f, 51f, 14)); * gazePoints.Add(new GazePoint(49f, 49f, 15)); * gazePoints.Add(new GazePoint(50.5f, 50.5f, 16)); */ System.IO.FileStream stream = new System.IO.FileStream("gazePoints.xml", System.IO.FileMode.Open); List <GazePoint> gazePoints = serialiser.Deserialize(stream) as List <GazePoint>; RawToFixationConverter converter = new RawToFixationConverter(gazePoints); List <Fixation> fixations = converter.CalculateFixations(4, 5, 25, 0); }
private void showTimeButton_Click(object sender, RoutedEventArgs e) { double totalTime = 0; string outputMessage = ""; // Foreach data file loaded we need to get the gazepoints and then convert them to fixations, then we can slice them. foreach (Data dataFile in dataFileList.Items) { string filename = dataFile.fileName; System.IO.FileStream readFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); this.gazePoints = this.serialiser.Deserialize(readFileStream) as List <GazePoint>; readFileStream.Close(); RawToFixationConverter converter = new RawToFixationConverter(gazePoints); List <Fixation> fixations = converter.CalculateFixations((int)windowSize, (float)peakThreshold, (float)radius, 15000); // Clip 15 seconds of data on either side when generating the data. double fileTime = fixations[fixations.Count - 1].endTime - fixations[0].startTime; totalTime += fileTime; outputMessage += String.Format("{0} was {1} seconds long.\n", filename, fileTime / 1000); } outputMessage += String.Format("Total time: {0} minutes.\n", (totalTime / 1000) / 60); MessageBox.Show(outputMessage); }
// Need to return an array of List<Fixation>, and then calculate all features for each // element (slice) of the fixations. // We can either slice by: number of fixations or time period /* * private List<Slice> SliceFixations(List<Fixation> allFixations, int numberOfFixations) { * // go through the array, keeping tracking of teh current count and adding each fixation to the current slide * // when reach numberOfFixations, add current slice to array, then start a new slice * * List<Slice> slices = new List<Slice>(); * List<Fixation> currentSliceFixations = new List<Fixation>(); * RawToFixationConverter converter = new RawToFixationConverter(); * * int count = 0; * * foreach(Fixation fixation in allFixations) { * * count++; * currentSliceFixations.Add(fixation); * * if(count >= numberOfFixations) { * Slice slice = new Slice(); * * slice.fixations = currentSliceFixations; * slice.saccades = converter.GenerateSaccades(currentSliceFixations); * * slices.Add(slice); * currentSliceFixations = new List<Fixation>(); * } * } * * return slices; * } */ // number of slices = total time for fixations in ms / (timePeriod / 2) private List <Slice> SliceFixations(List <Fixation> allFixations, double timePeriod, double step) { List <Slice> slices = new List <Slice>(); RawToFixationConverter converter = new RawToFixationConverter(); double windowStep = step; // This is window step size. // increment some counter by halfTimePeriod until it is < length of all fixations - a single time period Fixation finalFixation = allFixations.Last(); for (double start = 0; start < finalFixation.endTime - timePeriod; start += windowStep) { double windowStart = start; double windowEnd = start + timePeriod; // Get the fixations within this window List <Fixation> fixationsInWindow = GetFixationsInTimePeriod(windowStart, windowEnd, allFixations); // As long as there was at least 3 fixation in that window if (fixationsInWindow.Count > 3) { // Create a new slice with those fixations. Slice slice = new Slice(); slice.fixations = fixationsInWindow; slice.saccades = converter.GenerateSaccades(fixationsInWindow); slices.Add(slice); } } return(slices); }
// Fixations private void DrawFixations() { RawToFixationConverter converter = new RawToFixationConverter(gazePoints); List <Fixation> fixations = converter.CalculateFixations(currentWindowSize, (float)peakThreshold, (float)radius, 0); // don't clip any gazepoints when simply drawing List <Saccade> saccades = converter.GenerateSaccades(fixations); calculatedSaccades = saccades; calculatedFixations = fixations; foreach (Fixation fixation in fixations) { double lengthOfFixation = fixation.endTime - fixation.startTime; double seconds = lengthOfFixation / 1000; System.Windows.Media.SolidColorBrush brush = VSLocationBrushes[fixation.location]; DrawCircle(fixation.x, fixation.y, brush, fixationCircleSize, CircleType.FixationCircle); DrawLabel(seconds.ToString(), fixation.x + fixationCircleSize, fixation.y, brush); } }
private void generateButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog(); saveFileDialog.DefaultExt = ".csv"; Nullable <bool> result = saveFileDialog.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Want to generate instances for all of the selected slice times. foreach (int sliceTime in GetSliceLengths()) { // Get the name the user gave the file. string saveFileName = saveFileDialog.FileName; bool includeNames = true; // Add the slice time to the end of the filename. (We generate as many files as the needed with <saveFileName>_sliceTime.csv as the filename) string instancesFilename = saveFileName.Insert(saveFileName.Length - 4, String.Format("_instances_{0}s", sliceTime)); Console.WriteLine(sliceTime); Console.WriteLine(instancesFilename); /* * string testFileName = saveFileName.Insert(saveFileName.Length - 4, String.Format("_test_{0}s", sliceTime)); * Console.WriteLine(sliceTime); * Console.WriteLine(testFileName); */ // Setup the file stream writers. System.IO.FileStream trainFileStream = new System.IO.FileStream(instancesFilename, System.IO.FileMode.Append); StreamWriter trainFileWriter = new StreamWriter(trainFileStream); // Setup the file stream writers. /* * System.IO.FileStream testFileStream = new System.IO.FileStream(testFileName, System.IO.FileMode.Append); * StreamWriter testfileWriter = new StreamWriter(testFileStream); */ // Write the column names to the top if (includeNames) { WriteColumnNames(trainFileWriter, extractors); //WriteColumnNames(testfileWriter, extractors); } // We have the fileName to save the instances to, generate all the instances and then save them to the file at this location. // Foreach data file loaded we need to get the gazepoints and then convert them to fixations, then we can slice them. foreach (Data dataFile in dataFileList.Items) { string filename = dataFile.fileName; System.IO.FileStream readFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); this.gazePoints = this.serialiser.Deserialize(readFileStream) as List <GazePoint>; readFileStream.Close(); RawToFixationConverter converter = new RawToFixationConverter(gazePoints); List <Fixation> fixations = converter.CalculateFixations((int)windowSize, (float)peakThreshold, (float)radius, 15000); // Clip 15 seconds of data on either side when generating the data. //int seed = 0; //double testPercentage = 0.3; List <Slice> slices = SliceFixations(fixations, sliceTime * 1000, 1000); // convert sliceTime to milliseconds, set a window step size of 1000, therefore minimum window size is 1000. //Tuple<List<Slice>, List<Slice>> trainTest = SplitSlicesIntoTrainAndTest(slices, seed, testPercentage); //List<Slice> trainSlices = trainTest.Item1; //List<Slice> testSlices = trainTest.Item2; WriteInstacesForSlicesToFile(slices, sliceTime, trainFileWriter, dataFile.className); //WriteInstacesForSlicesToFile(testSlices, sliceTime, testfileWriter, dataFile.className); } trainFileWriter.Close(); //testfileWriter.Close(); } } }