Пример #1
0
        /// <summary>
        /// Initialise convex calculator with strategies of image loading,
        /// convex hull find, output and executes all this actions
        /// </summary>
        /// <param name="openImage">Strategy of image loading</param>
        /// <param name="convexHullScan">Strategy of convex hull find</param>
        /// <param name="output">Strategy of output</param>
        public ConvexHullControl(IOpenImage openImage,
                                 IConvexHullScan convexHullScan, IOutput output = null)
        {
            Contract.Requires(OpenImage != null);
            Contract.Requires(ConvexHullScan != null);

            OpenImage      = openImage ?? throw new ArgumentNullException(nameof(openImage));
            ConvexHullScan = convexHullScan ?? throw new ArgumentNullException(nameof(convexHullScan));
            Output         = output;

            try
            {
                SourcePoints = OpenImage.OpenImage();
                Output?.OutputPoints(SourcePoints);
            }
            catch (Exception e)
            {
                throw new Exception("The image loading failed", e);
            }

            try
            {
                ConvexHull = ConvexHullScan.ConvexHullScan(SourcePoints);
                Output?.OutputHull(ConvexHull);
            }
            catch (Exception e)
            {
                throw new Exception("The convex hull scan failed", e);
            }
        }
Пример #2
0
        /// <summary>
        /// Main method, that activates convex hull scan
        /// File start.bat passes names of input and output files
        /// </summary>
        /// <param name="args">Input png file with black points on white background (if not exists - points will be generated),
        /// Output file (txt file in which will be recorded the points and the convex hull)</param>
        public static void Main(string[] args)
        {
            IOpenImage      open   = GetOpenFileStrategy(args);
            IConvexHullScan scan   = new JarvisMatch();
            IOutput         output = GetOutputStrategy(args);

            Console.WriteLine("Processing started...");

            try
            {
                new ConvexHullControl(open, scan, output);
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error has occured: {e.Message}");
            }

            Console.WriteLine("Processing is over. Press Enter to exit.");
            Console.ReadLine();
        }