Example #1
0
        private void write_pt_to_hist(Point_Obj p, Screen_Prob_Map p_m, Subj_Data S, int frame_num)
        {
            int ID = S.get_ID();
            if (((Chart)this.hist_chart_list[ID]).InvokeRequired)
            {
                ChartHistCallback cH = new ChartHistCallback(write_pt_to_hist);
                this.Invoke(cH, new object[] { p, p_m, S, frame_num });
            }
            else
            {
                Chart chart = (Chart)this.hist_chart_list[ID];
                chart.ChartAreas[0].AxisX.Maximum = frame_num; // display points up to current frame

                Chart chart_f2 = (Chart)F2.hist_chart_list[ID];

                int MONITOR_DIM_X = S.get_MONITOR_DIM_X();
                int MONITOR_DIM_Y = S.get_MONITOR_DIM_Y();

                // convert gaze point (world coordinates) => monitor coordinates
                p.set_coord(-p.get_x(), p.get_y() + MONITOR_DIM_Y / 2, p.get_z());

                if (p.get_x() < -MONITOR_DIM_X / 2 || p.get_x() > MONITOR_DIM_X / 2)
                {
                    chart.Series["Series1"].Points.AddXY(frame_num, 0.0F);
                    Console.WriteLine("{0} - Confid Score: {1}", ID, 0.0F);

                    chart_f2.Series[0].Points.AddXY(DateTime.Now.ToLongTimeString(), 0.0F);
                }
                else if (p.get_y() < -MONITOR_DIM_Y / 2 || p.get_y() > MONITOR_DIM_Y / 2)
                {
                    chart.Series["Series1"].Points.AddXY(frame_num, 0.0F);
                    Console.WriteLine("{0} - Confid Score: {1}", ID, 0.0F);

                    chart_f2.Series[0].Points.AddXY(DateTime.Now.ToLongTimeString(), 0.0F);
                }
                else
                {
                    //chart.Series["Series1"].Points.AddXY(frame_num, 0);
                    //double D = p_m.look_up_value(Convert.ToInt32(-p.get_x()), Convert.ToInt32(p.get_y()) + MONITOR_DIM_Y / 2);
                    double D = p_m.look_up_value(Convert.ToInt32(p.get_x()), Convert.ToInt32(p.get_y()));
                    Console.WriteLine("{0} - Confid Score: {1}", ID, D);
                    //Console.WriteLine("Adding Point "+D.ToString());
                    chart.Series["Series1"].Points.AddXY(frame_num, Convert.ToSingle(D));
                    //write_to_msg_box(frame_num.ToString() + " " + D.ToString());

                    chart_f2.Series[0].Points.AddXY(DateTime.Now.ToLongTimeString(), Convert.ToSingle(D));
                }

                if (frame_num > 100)
                {
                    chart.ChartAreas[0].AxisX.Minimum = chart.ChartAreas[0].AxisX.Maximum - 100;
                }

            }
        }
Example #2
0
        public void serve_client(TcpClient client, int ID)
        {
            write_to_msg_box("Client " + Convert.ToString(ID) + " Connected!!\n");
            NetworkStream stream = client.GetStream();
            // Array to store incoming data
            Byte[] bytes = new Byte[PACKET_LENGTH];

            //int MONITOR_DIM_X = 394;
            //int MONITOR_DIM_Y = 288;
            int MONITOR_DIM_X = 513;
            int MONITOR_DIM_Y = 348;
            //int MONITOR_DIM_X = 334;
            //int MONITOR_DIM_Y = 239;

            // Object to store information about subject
            Subj_Data S = new Subj_Data(client, 0, ID, MONITOR_DIM_X, MONITOR_DIM_Y);
            // Object to get confid values based on 2D Gaussian
            Screen_Prob_Map p_m = new Screen_Prob_Map(MONITOR_DIM_X, MONITOR_DIM_Y, 200, 100);
            int i;

            clear_chart(ID);

            try
            {
                while ((i = stream.Read(bytes, 0, PACKET_LENGTH)) != 0)
                {
                    // Convert byte array to float
                    float[] float_array = new float[NUM_FLOATS];
                    Console.Write("\n"+Convert.ToString(ID)+" - ");
                    for (int ii = 0; ii < float_array.Length; ii++)
                    {
                        float_array[ii] = BitConverter.ToSingle(bytes, ii * sizeof(float));
                        if (ii < 11)
                            Console.Write(float_array[ii] + " ");
                    }
                    //Console.Write("\n");

                    Console.Write("\n" + Convert.ToString(ID) + " - ");
                    for (int ii = 256; ii < float_array.Length; ii++)
                    {
                        float_array[ii] = BitConverter.ToSingle(bytes, ii * sizeof(float));
                        if (ii < 267)
                            Console.Write(float_array[ii] + " ");
                    }
                    Console.Write("\n");

                    // Process float array and get estimated gaze point
                    Point_Obj est_gaze_pt = process_float_data(float_array, S);

                    // Log estimated gaze point
                    //S.get_gaze_pts().Add(est_gaze_pt);
                    double confid_score = p_m.look_up_value(Convert.ToInt32(-est_gaze_pt.get_x()), Convert.ToInt32(est_gaze_pt.get_y()) + S.get_MONITOR_DIM_Y()/2 );
                    S.add_to_pt_list(new Gaze_Data_Pt((int)float_array[0], est_gaze_pt, DateTime.Now, Convert.ToSingle(confid_score), S.get_MONITOR_DIM_X(), S.get_MONITOR_DIM_Y() ));
                    //Console.WriteLine("{0} - CONFID_SCORE - in loop - {1}", ID, confid_score);
                    //Console.WriteLine("EST GAZE PT1: {0}", est_gaze_pt);

                    // Check if subject is distracted
                    S = check_if_distract(S, est_gaze_pt);
                    //Console.WriteLine("{0} - NUM DISTRACT FRAMES: {1}", S.get_ID(), S.get_num_frames_distracted());
                    if (S.get_num_frames_distracted() > DISTRACT_WINDOW)
                    {
                        write_to_alert_box(1, S.get_ID());
                    }
                    else
                    {
                        write_to_alert_box(0, S.get_ID());
                    }

                    //write_pt_to_hist(est_gaze_pt, ID, Convert.ToInt32(float_array[0]));

                    //Console.WriteLine("EST GAZE PT2: {0}", est_gaze_pt);
                    write_pt_to_hist(est_gaze_pt, p_m, S, Convert.ToInt32(float_array[0]));

                }

                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client " + Convert.ToString(S.get_ID()) + " Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString());
                all_subj.Add(S);
                mut.ReleaseMutex();

                //File_IO F = new File_IO();
                //F.write_subj_to_file(S);

            }
            catch (Exception EE)
            {
                Console.WriteLine("EXCEPTION: {0}\n", EE.Message);
                //all_subj.Add(S);
                stream.Close();
                client.Close();
                write_to_msg_box("Connection to Client "+Convert.ToString(S.get_ID())+" Closed");

                // Set occupied flag back to 0 (need thread-safe call)
                mut.WaitOne();
                occupied_flags[ID] = 0; // atomic (?)
                write_to_msg_box("CLIENT FLAG ARRAY: " + occupied_flags[0].ToString() + " " + occupied_flags[1].ToString());
                all_subj.Add(S);
                mut.ReleaseMutex();

                //File_IO F = new File_IO();
                //F.write_subj_to_file(S);

            }
            //all_subj.Add(S);

            // Set occupied flag back to 0 (need thread-safe call)
            //mut.WaitOne();
            //occupied_flags[ID] = 0; // atomic (?)
            //mut.ReleaseMutex();
        }