public ProgressRandom(int mb_in, int num_in)
        {
            enclave   = new EnclaveLinkManaged();
            mb        = mb_in;
            num       = num_in;
            uicontext = TaskScheduler.FromCurrentSynchronizationContext();
            callback  = new progress_callback(UpdateProgress);

            InitializeComponent();

            labelTask.Text = String.Format("Generating {0} MB of random data", mb);
        }
 public ServerRequest(string host, int port, string url, string session_name, string session_id, string pn_version, string action, progress_callback onprogress, success_callback onsuccess, error_callback onerror)
 {
     this.action = action;
     this.onprogress = onprogress;
     this.onsuccess = onsuccess;
     this.onerror = onerror;
     try
     {
         download_request = (HttpWebRequest)WebRequest.Create("http://" + host + ":" + port + url);
         download_request.Headers.Add("Cookie: " + session_name + "=" + session_id + "; pnversion=" + pn_version);
         download_request.BeginGetResponse(startReceive, this);
     }
     catch (Exception e)
     {
         failure("Error connecting to http://" + host, e);
         return;
     }
 }
Exemplo n.º 3
0
        public void generate_matches(progress_callback progress)
        {
            calculating = true;

            int match_ind = 0;

            System.Collections.Generic.List <int> cat_ind   = new List <int>();
            System.Collections.Generic.List <int> im_ind    = new List <int>();
            System.Collections.Generic.List <int> cat_ind_2 = new List <int>();
            System.Collections.Generic.List <int> im_ind_2  = new List <int>();

            int arr_length = 0;

            for (int u = 0; u < images.Count - 1; u++)
            {
                for (int v = 0; v < images[u].Count; v++)
                {
                    for (int k = u + 1; k < images.Count; k++)
                    {
                        for (int l = 0; l < images[k].Count; l++)
                        {
                            cat_ind.Add(u);
                            im_ind.Add(v);
                            cat_ind_2.Add(k);
                            im_ind_2.Add(l);
                            arr_length++;
                        }
                    }
                }
            }
            object lock_matching = new object();

            //System.Threading.Tasks.Parallel.For(0, arr_length, (i, loopstate) =>
            for (int i = 0; i < arr_length; i++)
            {
                int     points_count1  = images[cat_ind[i]][im_ind[i]].points_count;
                float[] descriptor1    = images[cat_ind[i]][im_ind[i]].desctriptor;
                bool[]  sign1          = images[cat_ind[i]][im_ind[i]].sign;
                int[]   connection_id1 = images[cat_ind[i]][im_ind[i]].connection_id;
                int     points_count2  = images[cat_ind_2[i]][im_ind_2[i]].points_count;
                float[] descriptor2    = images[cat_ind_2[i]][im_ind_2[i]].desctriptor;
                bool[]  sign2          = images[cat_ind_2[i]][im_ind_2[i]].sign;
                int[]   connection_id2 = images[cat_ind_2[i]][im_ind_2[i]].connection_id;

                //for (int l = 0; l < points_count1; l++)
                System.Threading.Tasks.Parallel.For(0, points_count1, (l, loopstate) =>
                {
                    float best        = 99999999999999;
                    float second_best = 1;;
                    int best_index    = 0;
                    for (int j = 0; j < points_count2; j++)
                    {
                        if (sign1[l] == sign2[j])
                        {
                            float sum = 0;
                            for (int h = 0; h < 64; h++)
                            {
                                sum += (float)Math.Pow((double)(descriptor1[l * 64 + h] - descriptor2[j * 64 + h]), 2.0);
                            }
                            sum = (float)Math.Sqrt((double)sum);
                            if (sum < best)
                            {
                                second_best = best;
                                best        = sum;
                                best_index  = j;
                            }
                        }
                    }
                    if (best < 0.25 && best / second_best < 0.8)
                    {
                        lock (lock_matching)
                        {
                            st_point_cat_index.Add(cat_ind[i]);
                            st_point_im_index.Add(im_ind[i]);
                            st_point_pt_index.Add(l);
                            connection_id1[l] = 0;

                            nd_point_cat_index.Add(cat_ind_2[i]);
                            nd_point_im_index.Add(im_ind_2[i]);
                            nd_point_pt_index.Add(best_index);
                            connection_id2[best_index] = 0;
                            match_ind++;
                        }
                        //match_fitness.Add((float)rand.NextDouble());
                    }
                });
                if (cancel)
                {
                    break;
                }
                System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
                {
                    progress();
                }), System.Windows.Threading.DispatcherPriority.Render);
            }

            /*for (int u = 0; u < images.Count-1; u++)
             * {
             *  for (int v = 0; v < images[u].Count; v++)
             *  {
             *      int points_count1 = images[u][v].points_count;
             *      float []descriptor1 = images[u][v].desctriptor;
             *      bool[] sign1 = images[u][v].sign;
             *      int[] connection_id1 = images[u][v].connection_id;
             *      System.Threading.Tasks.Parallel.For(u+1, images.Count, k =>
             *      {
             *
             *          System.Threading.Tasks.Parallel.For (0, images[k].Count,l=>
             *          {
             *
             *          });
             *
             *      });
             *
             *  }
             * }*/
            this.matches_count = match_ind;
            solved_connection.Clear();
            for (int i = 0; i < matches_count; i++)
            {
                solved_connection.Add(false);
            }
            cancel      = false;
            calculating = false;
        }
Exemplo n.º 4
0
 public ServerRequest(string host, int port, string url, string session_name, string session_id, string pn_version, string action, progress_callback onprogress, success_callback onsuccess, error_callback onerror)
 {
     this.action     = action;
     this.onprogress = onprogress;
     this.onsuccess  = onsuccess;
     this.onerror    = onerror;
     try
     {
         download_request = (HttpWebRequest)WebRequest.Create("http://" + host + ":" + port + url);
         download_request.Headers.Add("Cookie: " + session_name + "=" + session_id + "; pnversion=" + pn_version);
         download_request.BeginGetResponse(startReceive, this);
     }
     catch (Exception e)
     {
         failure("Error connecting to http://" + host, e);
         return;
     }
 }