Пример #1
0
        public void Open(string[] originalFilePaths)
        {
            this.originalFilePaths = originalFilePaths;
            string[] cachefilePaths = new string[1];

            MosaicPlugin.AllPlugins["Linear Scale"].Enabled = false;
            MosaicPlugin.AllPlugins["RGB Balance"].Enabled  = false;

            TileReader[] tileReaders = new TileReader[6];

            tileReaders[0] = new MosaicFileReader(originalFilePaths, this);
            tileReaders[1] = new Version2SequenceFileReader(originalFilePaths, this);
            tileReaders[2] = new SequenceFileReader(originalFilePaths, this);
            tileReaders[3] = new RosMosaicSequenceFileReader(originalFilePaths, this);
            tileReaders[4] = new ImageCollectionFileReader(originalFilePaths, this);
            tileReaders[5] = new MultiSequenceFileReader(originalFilePaths, this);

            foreach (TileReader t in tileReaders)
            {
                if (t.CanRead())
                {
                    originalTileReader = tileReader = t;

                    break;
                }
            }

            if (tileReader == null)
            {
                MessageBox.Show("Unknown file type");
                return;
            }

            // Check if there is cache availiable for this file
            if (tileReader.HasCache())
            {
                cachefilePaths[0] = tileReader.GetCacheFilePath();

                if (tileReader.GetType() != typeof(MosaicFileReader))   // create a new reader to read this cache, if we opened a mos file, we already have the reader
                {
                    tileReader = new MosaicFileReader(cachefilePaths, this);
                }
            }

            this.menuStrip.Enabled = false;
            this.toolStrip.Enabled = false;

            ToolStripProgressBar progressbar = (ToolStripProgressBar)this.feedbackStatusStrip.Items[1];

            openThreadController = new ThreadController(this);
            openThreadController.SetThreadCompletedCallback(OpenFileThreadCompleted);
            openThreadController.SetThreadProgressCallback(OpenFileProgressIndicator);
            tileReader.SetThreadController(openThreadController);

            progressbar.Value = 0;
            this.statusStrip.Refresh();

            try
            {
                tileReader.ReadHeader();
            }
            catch (MosaicException e)
            {
                // The cache file failed to be read.
                // Probably as the format has changed. Here we delete the cache file and recall the open function

                if (tileReader.GetType() == typeof(MosaicFileReader))
                {
                    if (originalTileReader.GetType() != typeof(MosaicFileReader))
                    {
                        File.Delete(cachefilePaths[0]);
                        this.Open(originalFilePaths);
                    }
                    else
                    {
                        // The user has tried to open the mos (cache) file directly
                        // We don't know what other files to fall back too so we just error and return.
                        // File.Delete(cachefilePaths[0]);   // DO NOT DELETE THE FILE THEY JUST TRIED TO OPEN!
                        MessageBox.Show("Unable to load file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to read header information correctly. " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                this.menuStrip.Enabled = true;
                this.toolStrip.Enabled = true;
            }

            MosaicWindow.MosaicInfo = new MosaicInfo(tileReader);

            this.tileOverView.CreateOverview();

            this.tileOverView.Location = new Point(25, this.TileView.Bottom - this.tileOverView.Height - 25);

            this.tileOverView.Show();

            // TileLoadInfo should now be ready as we have read the header.
            this.BlendingEnabled    = true;
            this.CorrelationEnabled = true;

            // Threaded Operation
            tileReader.CreateThumbnails();
        }
Пример #2
0
        public void Open(string[] originalFilePaths)
        {
            this.originalFilePaths = originalFilePaths;
            string[] cachefilePaths = new string[1];

            MosaicPlugin.AllPlugins["Linear Scale"].Enabled = false;
            MosaicPlugin.AllPlugins["RGB Balance"].Enabled = false;

            TileReader[] tileReaders = new TileReader[6];

            tileReaders[0] = new MosaicFileReader(originalFilePaths, this);
            tileReaders[1] = new Version2SequenceFileReader(originalFilePaths, this);
            tileReaders[2] = new SequenceFileReader(originalFilePaths, this);
            tileReaders[3] = new RosMosaicSequenceFileReader(originalFilePaths, this);
            tileReaders[4] = new ImageCollectionFileReader(originalFilePaths, this);
            tileReaders[5] = new MultiSequenceFileReader(originalFilePaths, this);

            foreach (TileReader t in tileReaders)
            {
                if (t.CanRead())
                {
                    originalTileReader = tileReader = t;

                    break;
                }
            }

            if(tileReader == null) {
                MessageBox.Show("Unknown file type");
                return;
            }

            // Check if there is cache availiable for this file
            if (tileReader.HasCache())
            {
                cachefilePaths[0] = tileReader.GetCacheFilePath();

                if (tileReader.GetType() != typeof(MosaicFileReader))   // create a new reader to read this cache, if we opened a mos file, we already have the reader
                    tileReader = new MosaicFileReader(cachefilePaths, this);
            }

            this.menuStrip.Enabled = false;
            this.toolStrip.Enabled = false;

            ToolStripProgressBar progressbar = (ToolStripProgressBar)this.feedbackStatusStrip.Items[1];

            openThreadController = new ThreadController(this);
            openThreadController.SetThreadCompletedCallback(OpenFileThreadCompleted);
            openThreadController.SetThreadProgressCallback(OpenFileProgressIndicator);
            tileReader.SetThreadController(openThreadController);

            progressbar.Value = 0;
            this.statusStrip.Refresh();

            try
            {
                tileReader.ReadHeader();
            }
            catch (MosaicException e)
            {
                // The cache file failed to be read.
                // Probably as the format has changed. Here we delete the cache file and recall the open function

                if (tileReader.GetType() == typeof(MosaicFileReader))
                {
                    if (originalTileReader.GetType() != typeof(MosaicFileReader))
                    {
                        File.Delete(cachefilePaths[0]);
                        this.Open(originalFilePaths);
                    }
                    else
                    {
                        // The user has tried to open the mos (cache) file directly
                        // We don't know what other files to fall back too so we just error and return.
                        // File.Delete(cachefilePaths[0]);   // DO NOT DELETE THE FILE THEY JUST TRIED TO OPEN!
                        MessageBox.Show("Unable to load file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to read header information correctly. " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                this.menuStrip.Enabled = true;
                this.toolStrip.Enabled = true;
            }

            MosaicWindow.MosaicInfo = new MosaicInfo(tileReader);

            this.tileOverView.CreateOverview();

            this.tileOverView.Location = new Point(25, this.TileView.Bottom - this.tileOverView.Height - 25);

            this.tileOverView.Show();

            // TileLoadInfo should now be ready as we have read the header.
            this.BlendingEnabled = true;
            this.CorrelationEnabled = true;

            // Threaded Operation
            tileReader.CreateThumbnails();
        }