public MosaicInfo(TileReader reader) { this.reader = reader; this.ScaleMinIntensity = reader.LoadInfo.TotalMinIntensity; this.ScaleMaxIntensity = reader.LoadInfo.TotalMaxIntensity; this.IsCorrelated = reader.LoadInfo.IsCorrelated; this.IsCompositeRGB = reader.LoadInfo.IsCompositeRGB; }
public void OpenFileThreadCompleted(object sender, string updateText, bool aborted) { TileReader reader = (TileReader)sender; ToolStripProgressBar progressbar = (ToolStripProgressBar)this.feedbackStatusStrip.Items[1]; // Try to read cache string cacheFilePath = tileReader.GetCacheFilePath(); if (tileReader.FailedToReadFormat && reader.GetType() == typeof(MosaicFileReader)) { // The cache file failed to be read. // Probably as the format is corrupt try { File.Delete(tileReader.GetCacheFilePath()); tileReader.Dispose(); this.Open(this.originalFilePaths); } catch (Exception e) { MessageBox.Show(e.Message); } } this.menuStrip.Enabled = true; this.toolStrip.Enabled = true; tileReader.ReadMetaData(); tileReader.Dispose(); this.statusStrip.Items[0].Text = String.Format(CultureInfo.CurrentCulture, "Total Size {0} x {1}", MosaicWindow.MosaicInfo.TotalWidth, MosaicWindow.MosaicInfo.TotalHeight); this.feedbackStatusStrip.Items[0].Text = ""; this.imageView.ImageSize = new Size(MosaicInfo.TotalWidth, MosaicInfo.TotalHeight); this.imageView.Clear(); this.imageView.LoadMosaicInfo(MosaicWindow.MosaicInfo); // set the window title this.Text = MosaicWindow.MosaicInfo.Prefix + " - Mosaic"; // Send a scroll message to update the display. this.imageView.SetAutoScrollPosition(new Point(0, 0)); this.menuStrip.Enabled = true; this.toolStrip.Enabled = true; MosaicPlugin.AllPlugins["Linear Scale"].Enabled = true; MosaicPlugin.AllPlugins["RGB Balance"].Enabled = true; progressbar.Value = 0; this.feedbackStatusStrip.Items[0].Text = ""; OnMosaicLoaded(new MosaicWindowEventArgs(MosaicWindow.MosaicInfo)); }
// Calls CaseInsensitiveComparer.Compare with the parameters reversed. public int Compare(System.IO.FileInfo x, System.IO.FileInfo y) { string val1_str = TileReader.ExtractTileNumber(this.prefix, x).ToString(); string val2_str = TileReader.ExtractTileNumber(this.prefix, y).ToString(); int val1 = Convert.ToInt32(val1_str); int val2 = Convert.ToInt32(val2_str); return(val1.CompareTo(val2)); }
protected bool IsTileFilenameValid(string prefix, FileInfo fileinfo) { if (!this.AllowedExtensions.Contains(fileinfo.Extension)) { return(false); } Regex re = TileReader.GetTileFilenameRegEx(prefix, fileinfo); return(re.IsMatch(fileinfo.ToString())); }
// Calls CaseInsensitiveComparer.Compare with the parameters reversed. public int Compare(Object x, Object y) { FileInfo a = (FileInfo)x; FileInfo b = (FileInfo)y; string val1_str = TileReader.ExtractTileNumber(this.prefix, a).ToString(); string val2_str = TileReader.ExtractTileNumber(this.prefix, b).ToString(); int val1 = Convert.ToInt32(val1_str); int val2 = Convert.ToInt32(val2_str); return(val1.CompareTo(val2)); }
static internal int ExtractTileNumber(string prefix, System.IO.FileInfo info) { Regex re = TileReader.GetTileFilenameRegEx(prefix, info); Match match = re.Match(info.ToString()); // 2 because match.Groups[0] is entire match if (match.Groups.Count != 2) { return(-1); } return(Convert.ToInt32(match.Groups[1].Captures[0].Value)); }
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(); }