コード例 #1
0
        /// <summary>
        ///   The main method for calculating results for the face analysis.
        /// </summary>
        /// <remarks>
        ///   The calculated values do not mean anything particular.
        ///   They are just to demonstrate how to process a potentially
        ///   time-demanding analysis in a delegated work-thread.
        /// </remarks>
        /// <param name="data">
        ///   The instance of a Result object to which the results
        ///   will be periodically delivered until we either finish
        ///   the process or are asked to stop.
        /// </param>
        ///
        private void Run(Object data)
        {
            SharedResults results = data as SharedResults;

            double uRange = m_bbox.Max.U - m_bbox.Min.U;
            double vRange = m_bbox.Max.V - m_bbox.Min.V;
            double uStep  = uRange / m_density;
            double vStep  = vRange / m_density;

            for (int u = 0; u <= m_density; u++)
            {
                double uPos = m_bbox.Min.U + (u * uStep);
                double uVal = (double)(u * (m_density - u));

                for (int v = 0; v <= m_density; v++)
                {
                    double vPos = m_bbox.Min.V + (v * vStep);
                    double vVal = (double)(v * (m_density - v));

                    UV     point = new UV(uPos, vPos);
                    double value = Math.Min(uVal, vVal);

                    // We pretend the calculation of values is far more complicated
                    // while what we really do is taking a nap for a few milliseconds

                    Thread.Sleep(100);

                    // If adding the result is not accepted it means the analysis
                    // have been interrupted and we are supposed to get out ASAP

                    if (!results.AddResult(point, value))
                    {
                        return;
                    }
                }
            }  // for
        }