public MeasuresEditForm(Filter filter, WeakImage[] references, List<MetricExecBase> metrics)
        {
            InitializeComponent();

            try
            {
                _filter = filter;
                _references = references;
                _originalMetrics = metrics;

                DialogResult = System.Windows.Forms.DialogResult.Cancel;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().FullName, ex.Message);
            }
        }
 /// <summary>
 /// Sets the "output-image", used by the metric function.
 /// </summary>
 /// <param name="img"></param>
 public virtual void SetOutput(WeakImage img)
 {
     output = img;
 }
 /// <summary>
 /// Sets the "input-image", used by the metric function.
 /// </summary>
 /// <param name="img"></param>
 public virtual void SetInput(WeakImage img)
 {
     input = img;
 }
Beispiel #4
0
 /// <summary>
 /// Executed when a filter in a graph finishes measurement.
 /// </summary>
 /// <param name="input">The input of the filter.</param>
 /// <param name="output">The output of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 /// <param name="results">The measures of the filter executed.</param>
 /// <param name="duration">The duration of the execution of the filter.</param>
 protected void filter_f_FilterMeasured(WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, List<MetricResult> results, TimeSpan duration)
 {
     OnFilterMeasured(input, output, filter, configs, results, duration);
 }
 /// <summary>
 /// Called to signal the end of a filter execution.
 /// </summary>
 /// <param name="sender">The BatchFilter sender of the event.</param>
 /// <param name="input">The input of the filter.</param>
 /// <param name="output">The output of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 private void OnFilterExecuted(BatchFilter sender, WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, TimeSpan duration)
 {
     if (null != FilterExecuted)
     {
         FilterExecuted(sender, input, output, filter, configs, duration);
     }
 }
        private void bt_FilterMeasured_threadsafe_(BatchFilter sender, WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, List<MetricResult> measures, TimeSpan duration)
        {
            try
            {
                Monitor.TryEnter(filterMeas_lock, -1);

                ++_executedFiltros;
                lbXofY.Text = string.Format("{0}/{1}", _executedFiltros, _totFiltros);
                progressExec.Value = (int)(Math.Min(1.0, _executedFiltros / (_totFiltros * 1.0)) * progressExec.Maximum);

                if (ckForgetNoMeasures.Checked)
                {
                    // Forget the row
                    if (measures == null || measures.Count == 0)
                        return;
                }

                // Add row to GridResults ...
                _results.Add(new RowResults(filter.Attributes["ShortName"].ToString(), input, output, measures, filter, configs, duration));

                Flush(false, true);

                gridResults.Refresh();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetType().FullName, ex.Message);
            }
            finally
            {
                Monitor.Exit(filterMeas_lock);
            }
        }
 /// <summary>
 /// Defines a metric execution for a filter RowResults.
 /// </summary>
 /// <param name="Item1">The metric function.</param>
 /// <param name="Item2">The metric function.</param>
 /// <param name="Item3">A "reference" image, if needed.</param>
 public RowMetricExecution(
         Metric.MetricDelegate Item1,
         MetricExecutionType Item2, WeakImage Item3)
 {
     this.Item1 = Item1;
     this.Item2 = Item2;
     this.Item3 = Item3;
 }
        public void WeakImagesTestDisposable()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Trace.WriteLine(string.Format("Init: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));

            List<WeakImage> _weaks = new List<WeakImage>();
            List<string> tempFiles = new List<string>();
            foreach (Image i in new Image[] { (Image)Properties.Resources.big_img.Clone() })
            {
                WeakImage w = new WeakImage(i);

                _weaks.Add(w);
                tempFiles.Add(w.Filename);

                long size = (new FileInfo(w.Filename)).Length;

                Assert.AreNotEqual(0, size, "Size of the file {0} is zero!");

                Trace.WriteLine(string.Format("File {0}, size = {1}.", w.Filename, size));

                i.Dispose();
            }

            // Check that every files exists before a collect
            Trace.WriteLine(string.Format("Before Collect: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Trace.WriteLine(string.Format("After Collect: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));

            // Check that every files exists after a collect
            foreach (string file in tempFiles)
            {
                Trace.WriteLine(string.Format("Test if {0} is alive.", file));
                Assert.IsTrue(File.Exists(file), "File {0} was expected to be alive, is dead.", file);
            }

            // Dispose every WeakImage
            foreach (WeakImage weak in _weaks)
            {
                weak.Dispose();
            }

            // Check that every files is deleted
            foreach (string file in tempFiles)
            {
                Trace.WriteLine(string.Format("Test if {0} is dead.", file));
                Assert.IsFalse(File.Exists(file), "File {0} was expected to be dead, is alive.", file);
            }
        }
 /// <summary>
 /// The SetInput method is overrided to leave the attribute untouched.
 /// </summary>
 /// <param name="img"></param>
 public override void SetInput(WeakImage img)
 {
     // SKIP
 }
 /// <summary>
 /// Defines an image inside the batch.
 /// </summary>
 /// <param name="Item1">The image. Images will be persisted using the base64 encoded binary representation of the Image.</param>
 public RowImage(WeakImage Item1)
 {
     this.Item1 = Item1;
 }
 /// <summary>
 /// Metric associable to a node that takes a previously defined 
 /// reference and the output of the filter to calculate the metric after the filter execution.
 /// </summary>
 /// <param name="key">The key of the metric.</param>
 /// <param name="method">The metric function.</param>
 /// <param name="reference">The reference to use in the calculation of the metric.</param>
 public MetricExecReference(string key, Metric.MetricDelegate method, WeakImage reference)
     : base(key, method)
 {
     base.SetInput(reference);
 }
 /// <summary>
 /// Executed when a filter in a graph finishes measurement.
 /// </summary>
 /// <param name="input">The input image of the filter.</param>
 /// <param name="output">The output image of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 /// <param name="measures">The measures of the filter executed.</param>
 private void _graph_FilterMeasured(WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, List<MetricResult> measures, TimeSpan duration)
 {
     OnFilterMeasured(this, input, output, filter, configs, measures, duration);
 }
 /// <summary>
 /// Executed when a filter in a graph finishes execution.
 /// </summary>
 /// <param name="input">The input image of the filter.</param>
 /// <param name="output">The output image of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 private void _graph_FilterExecuted(WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, TimeSpan duration)
 {
     OnFilterExecuted(this, input, output, filter, configs, duration);
 }
Beispiel #14
0
 /// <summary>
 /// Called to signal the end of a filter execution.
 /// </summary>
 /// <param name="input">The input of the filter.</param>
 /// <param name="ouput">The output of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 protected void OnFilterExecuted(WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, TimeSpan duration)
 {
     if (null != FilterExecuted)
         FilterExecuted(input, output, filter, configs, duration);
 }
 /// <summary>
 /// Results of the execution of a filter.
 /// </summary>
 /// <param name="Item1">The name of the filter (for display only).</param>
 /// <param name="Item2">The input image used by the filter.</param>
 /// <param name="Item3">The output of the filter.</param>
 /// <param name="Item4">The list of calculated metrics.</param>
 /// <param name="Item5">The filter used.</param>
 /// <param name="Item6">The filter's configurations.</param>
 public RowResults(string Item1, WeakImage Item2, WeakImage Item3,
         List<MetricResult> Item4, Filter Item5,
         SortedDictionary<string, object> Item6, TimeSpan Item7)
 {
     this.Item1 = Item1;
     this.Item2 = Item2;
     this.Item3 = Item3;
     this.Item4 = Item4;
     this.Item5 = Item5;
     this.Item6 = Item6;
     this.Item7 = Item7;
 }
Beispiel #16
0
 /// <summary>
 /// Called to signal the end of a filter measurement.
 /// </summary>
 /// <param name="input">The input of the filter.</param>
 /// <param name="ouput">The output of the filter.</param>
 /// <param name="filter">The filter executed.</param>
 /// <param name="configs">The configurations used by the filter.</param>
 /// <param name="measures">The measures of the filter executed.</param>
 protected void OnFilterMeasured(WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, List<MetricResult> measures, TimeSpan duration)
 {
     if (null != FilterMeasured)
         FilterMeasured(input, output, filter, configs, measures, duration);
 }
 // MEASURED
 private void bt_FilterMeasured(BatchFilter sender, WeakImage input, WeakImage output, Filter filter, SortedDictionary<string, object> configs, List<MetricResult> measures, TimeSpan duration)
 {
     try
     {
         FilterMeasuredDelegate inv = new FilterMeasuredDelegate(bt_FilterMeasured_threadsafe_);
         this.Invoke(inv, sender, input, output, filter, configs, measures, duration);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.GetType().FullName, ex.Message);
     }
 }
        public void WeakImagesTestCollection()
        {
            List<string> tempFiles = new List<string>();

            // Creation of local scope ...
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                Trace.WriteLine(string.Format("Init: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));

                List<WeakImage> _weaks = new List<WeakImage>();

                foreach (Image i in new Image[] { (Image)Properties.Resources.big_img.Clone() })
                {
                    WeakImage w = new WeakImage(i);

                    _weaks.Add(w);
                    tempFiles.Add(w.Filename);

                    long size = (new FileInfo(w.Filename)).Length;

                    Assert.AreNotEqual(0, size, "Size of the file {0} is zero!");

                    Trace.WriteLine(string.Format("File {0}, size = {1}.", w.Filename, size));

                }

                // Check that every files exists before a collect
                Trace.WriteLine(string.Format("Before Collect: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));
                GC.Collect();
                GC.WaitForPendingFinalizers();
                Trace.WriteLine(string.Format("After Collect: GC.GetTotalMemory = {0}", GC.GetTotalMemory(false)));

                // Check that every files exists after a collect
                foreach (string file in tempFiles)
                {
                    Trace.WriteLine(string.Format("Test if {0} is alive.", file));
                    Assert.IsTrue(File.Exists(file), "File {0} was expected to be alive, is dead.", file);
                }

                // Resets the list.
                // Do not call Dispose directly!!!
                _weaks.Clear(); _weaks = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            //// Force new Collection.
            //// You have to call it n times. DOC!!!
            //for (int i = 0; i < 10; ++i)
            //{
            //    GC.Collect();
            //    GC.WaitForPendingFinalizers();
            //}

            //System.IO.Directory.GetFiles(System.IO.Path.GetTempPath());
            // Wait for pending IO operations ...
            System.Threading.Thread.Sleep(10000);
            // Dummy way to refresh file system
            foreach (string file in tempFiles)
            {
                Trace.WriteLine(string.Format("{0} exists = {1}", file, File.Exists(file)));
            }

            // Check that every files is deleted
            foreach (string file in tempFiles)
            {
                Trace.WriteLine(string.Format("Test if {0} is dead.", file));

                Assert.IsFalse(File.Exists(file), "File {0} was expected to be dead, is alive.", file);
            }
        }
        /// <summary>
        /// Implementation of the execution of the node.
        /// </summary>
        /// <param name="inputs">The input of the node.</param>
        /// <returns>The output of the node.</returns>
        protected override List<WeakImage> Execute_Impl(List<WeakImage> inputs)
        {
            List<WeakImage> outputs = new List<WeakImage>();

            if (null == filter)
            {
                outputs = inputs;
            }
            else
            {
                FilterCore flt = (FilterCore)Activator.CreateInstance(filter.FilterType);
                Image o; WeakImage wo;
                foreach (WeakImage i in inputs)
                {
                    DateTime start = DateTime.Now;

                    o = flt.ApplyFilter((Image)i, configs);

                    DateTime end = DateTime.Now;

                    // _duration is always initialized to TimeSpan.Zero
                    // if the node has a parent, _duration should be initialized
                    // with the duration of the parent
                    if (Parent != null)
                        _duration = Parent.Duration;

                    _duration += (end - start);

                    o.Tag = Facilities.CloneTag((Image)i);
                    Facilities.AddFilterExecution(ref o, flt, configs);

                    wo = new WeakImage(o);
                    outputs.Add(wo);

                    OnFilterExecuted(i, wo, filter, configs, _duration);

                    // Calculate Metrics ** Here **
                    // Raise even without measures
                    List<MetricResult> results = new List<MetricResult>();
                    if (null != measures)
                    {
                        //SortedDictionary<string, double> results = new SortedDictionary<string, double>();
                        foreach (MetricExecBase m in measures)
                        {
                            m.SetInput(i);
                            m.SetOutput(wo);
                            results.Add(new MetricResult(m.Input, m.Key, m.Calculate()));
                        }
                    }

                    OnFilterMeasured(i, wo, filter, configs, results, _duration);
                }
            }

            return outputs;
        }