예제 #1
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog ofd       = new OpenFileDialog();
            string         formatStr = "TIF files (*.tif)|*.tif|All files (*.*)|*.*";

            /*
             * foreach (string formatMiniStr in Interface.TabPages.myFileDecoder.Formats)
             * {
             *  formatStr += "|" + formatMiniStr.Substring(1, formatMiniStr.Length - 1) +
             *  " files (*" + formatMiniStr + ")|*" + formatMiniStr;
             * }*/

            ofd.Filter           = formatStr;
            ofd.FilterIndex      = 1;
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                TreeNode node = Interface.FileBrowser.CheckForFile(OSStringConverter.GetWinString(ofd.FileName));
                if (node != null)
                {
                    Interface.FileBrowser.Openlabel.Tag = node;
                }
                Interface.FileBrowser.Openlabel.Text = "'" + OSStringConverter.GetWinString(ofd.FileName) + "'";
                Interface.FileBrowser.Openlabel.Text = "";
            }
        }
        private static bool isLibTifCompatible(string dir)
        {
            if (!dir.EndsWith(".tif"))
            {
                return(false);
            }

            using (Tiff tif = Tiff.Open(OSStringConverter.StringToDir(dir), "r"))
            {
                if (tif == null)
                {
                    tif.Close();
                    return(false);
                }

                try
                {
                    tif.SetDirectory((short)(tif.NumberOfDirectories() - 1));
                }
                catch
                {
                    tif.Close();
                    return(false);
                }

                int bitsPerPixel = tif.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();

                tif.Close();
            }

            return(true);
        }
        private static string getLibTifFileDescription(string dir)
        {
            string des = "";

            using (Tiff tif = Tiff.Open(OSStringConverter.StringToDir(dir), "r"))
            {
                if (tif == null)
                {
                    return("");
                }

                tif.SetDirectory(0);
                TiffTag      tag   = (TiffTag)270;
                FieldValue[] value = tif.GetField(tag);

                if (value != null)
                {
                    for (int i = 0; i < value.Length; i++)
                    {
                        des += Encoding.UTF8.GetString(value[i].ToByteArray());
                    }
                }

                tif.Close();
            }

            return(des);
        }
예제 #4
0
        private static void SaveTif_16bitRawData1(TifFileInfo fi, string fileName, ImageAnalyser IA)
        {
            // Register the extender callback
            m_parentExtender = Tiff.SetTagExtender(TagExtender);
            string value = calculateCTTagValue(fi, IA);

            int numberOfPages = fi.imageCount;

            int width           = fi.sizeX;
            int height          = fi.sizeY;
            int samplesPerPixel = 1;
            int bitsPerSample   = fi.bitsPerPixel;

            using (Tiff output = Tiff.Open(OSStringConverter.StringToDir(fileName), "w"))
            {
                for (int page = 0; page < numberOfPages; page++)
                {
                    ushort[][] image = fi.image16bit[page];
                    output.SetField(TiffTag.IMAGELENGTH, height);
                    output.SetField(TiffTag.IMAGEWIDTH, width);
                    output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                    output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                    output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                    output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                    output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                    output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                    output.SetField(TiffTag.COMPRESSION, Compression.NONE);
                    output.SetField(TiffTag.IMAGEDESCRIPTION, ImageDetails());
                    // specify that it's a page within the multipage file
                    output.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
                    // specify the page number
                    output.SetField(TiffTag.PAGENUMBER, page, numberOfPages);

                    if (page == numberOfPages - 1)
                    {
                        // set the custom tag
                        output.SetField(TIFFTAG_CellTool_METADATA, value);
                    }

                    for (int i = 0; i < height; i++)
                    {
                        ushort[] samples = image[i];

                        byte[] buffer = new byte[samples.Length * sizeof(ushort)];
                        Buffer.BlockCopy(samples, 0, buffer, 0, buffer.Length);

                        output.WriteScanline(buffer, i);
                    }

                    output.WriteDirectory();
                }
            }

            // restore previous tag extender
            Tiff.SetTagExtender(m_parentExtender);
        }
예제 #5
0
 private void Form_DragDropFiles(object sender, DragEventArgs e)
 {
     string[] dirList = e.Data.GetData(DataFormats.FileDrop) as string[];
     foreach (string dir in dirList)
     {
         TreeNode node = Interface.FileBrowser.CheckForFile(OSStringConverter.GetWinString(dir));
         if (node != null)
         {
             Interface.FileBrowser.Openlabel.Tag = node;
         }
         Interface.FileBrowser.Openlabel.Text = "'" + OSStringConverter.GetWinString(dir) + "'";
         Interface.FileBrowser.Openlabel.Text = "";
     }
 }
        private void PlugIns_TakeNames()
        {
            DeveloperToolStripMenuItem.DropDownItems.Clear();

            ToolStripMenuItem InstallPlugInTS = new ToolStripMenuItem();

            InstallPlugInTS.Text   = "Install PlugIn";
            InstallPlugInTS.Click += InstallPlugIn_Click;
            DeveloperToolStripMenuItem.DropDownItems.Add(InstallPlugInTS);

            ToolStripMenuItem UnInstallPlugInTS = new ToolStripMenuItem();

            UnInstallPlugInTS.Text   = "Uninstall PlugIn";
            UnInstallPlugInTS.Click += UnInstallPlugIn_Click;
            DeveloperToolStripMenuItem.DropDownItems.Add(UnInstallPlugInTS);

            DeveloperToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());

            // AddResultsExtractor();

            // string path = Application.StartupPath + "\\PlugIns";
            string path = OSStringConverter.StringToDir(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CellToolPlugIns");


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            foreach (var file in directoryInfo.GetFiles())
            {
                if (file.Name.EndsWith(".CTPlugIn.dll") &&
                    !file.Name.EndsWith("Results_Extractor.CTPlugIn.dll"))
                {
                    string            namePlugIn = file.Name.Replace(".CTPlugIn.dll", "").Replace("_", " ");
                    string            dirPlugIn  = file.FullName;
                    ToolStripMenuItem plugInTS   = new ToolStripMenuItem();
                    plugInTS.Text   = namePlugIn;
                    plugInTS.Tag    = dirPlugIn;
                    plugInTS.Click += PlugInToolStripMenuItem_Click;

                    DeveloperToolStripMenuItem.DropDownItems.Add(plugInTS);
                }
            }
        }
        public void InstallPlugIn(string path)
        {
            path = OSStringConverter.GetWinString(path);
            //background worker
            var bgw = new BackgroundWorker();

            bgw.WorkerReportsProgress = true;
            //Add event for projection here
            bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
            {
                string newPath = OSStringConverter.StringToDir(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CellToolPlugIns\\" +
                    path.Substring(path.LastIndexOf("\\") + 1, path.Length - path.LastIndexOf("\\") - 1));
                if (File.Exists(newPath))
                {
                    ((BackgroundWorker)o).ReportProgress(1);
                }
                else
                {
                    File.Copy(path, newPath, false);
                    ((BackgroundWorker)o).ReportProgress(0);
                }
            });

            bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
            {
                if (a.ProgressPercentage == 0)
                {
                    PlugIns_TakeNames();
                    MessageBox.Show("Plugin installed!");
                }
                else if (a.ProgressPercentage == 1)
                {
                    MessageBox.Show("Plugin already installed!"
                                    );
                }
                IA.FileBrowser.StatusLabel.Text = "Ready";
            });
            //Start background worker
            IA.FileBrowser.StatusLabel.Text = "Installing PlugIn...";
            //start bgw
            bgw.RunWorkerAsync();
        }
예제 #8
0
 private void Form_StartWithFile()
 {
     String[] dirList = Environment.GetCommandLineArgs();
     if (dirList.Length > 0)
     {
         foreach (string dir in dirList)
         {
             if (dir.Length > 5)
             {
                 if (dir.Substring(dir.Length - 4, 4) != ".exe")
                 {
                     TreeNode node = Interface.FileBrowser.CheckForFile(OSStringConverter.GetWinString(dir));
                     if (node != null)
                     {
                         Interface.FileBrowser.Openlabel.Tag = node;
                     }
                     Interface.FileBrowser.Openlabel.Text = "'" + OSStringConverter.GetWinString(dir) + "'";
                     Interface.FileBrowser.Openlabel.Text = "";
                 }
             }
         }
     }
 }
예제 #9
0
        public void Save(ImageAnalyser IA)
        {
            TifFileInfo tifFI = this.tifFI;

            if (tifFI != null)
            {
                if (!tifFI.available)
                {
                    MessageBox.Show("Image is not avaliable!\nTry again later.");
                    return;
                }

                string dir = tifFI.Dir;
                //background worker
                var bgw = new BackgroundWorker();
                bgw.WorkerReportsProgress = true;
                //Add handlers to the backgroundworker
                //Reports when is finished

                bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
                {
                    //check is the directory exist
                    if (dir.IndexOf("\\") > -1)
                    {
                        string checkDir = dir.Substring(0, dir.LastIndexOf("\\"));
                        checkDir        = OSStringConverter.StringToDir(checkDir);
                        if (!System.IO.Directory.Exists(checkDir))
                        {
                            System.IO.Directory.CreateDirectory(checkDir);
                        }
                    }
                    //save file
                    FileEncoder.SaveTif(tifFI, dir, IA);
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                });

                bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
                {
                    if (a.ProgressPercentage == 0)
                    {
                        Saved = true;
                        if (tifFI != null)
                        {
                            tifFI.available = true;
                        }
                        IA.FileBrowser.StatusLabel.Text = "Ready";
                    }
                });

                //Start background worker
                tifFI.available = false;
                IA.FileBrowser.StatusLabel.Text = "Saving Tif Image...";

                IA.EnabletrackBars(false);
                bgw.RunWorkerAsync();
                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }

                IA.EnabletrackBars(true);
            }
            else if (ResultsExtractor != null)
            {
                //check is the directory exist
                if (dir.IndexOf("\\") > -1)
                {
                    string checkDir = dir.Substring(0, dir.LastIndexOf("\\"));
                    checkDir = OSStringConverter.StringToDir(checkDir);
                    if (!System.IO.Directory.Exists(checkDir))
                    {
                        System.IO.Directory.CreateDirectory(checkDir);
                    }
                }

                var bgw = ResultsExtractor.FileSaver.SaveCTDataFile(
                    (Cell_Tool_3.ResultsExtractor.MyForm)
                    this.ResultsExtractor.myPanel, dir);

                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }
            }
        }
        public static bool OpenFile(List <TabPage> Collection, string path, TabPage tp, ImageAnalyser IA, ToolStripStatusLabel StatusLabel)
        {
            StatusLabel.Text = "Reading Metadata...";

            // read metadata using ImageReader

            loci.formats.ImageReader FirstReader = new loci.formats.ImageReader();

            try
            {
                FirstReader.setId(OSStringConverter.StringToDir(path));
            }
            catch
            {
                FirstReader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }

            bool isRGB = FirstReader.isRGB();

            //check is it rgb colored
            loci.formats.ChannelSeparator reader = loci.formats.ChannelSeparator.makeChannelSeparator(FirstReader);
            FirstReader = null;

            TifFileInfo fi = tp.tifFI;

            fi.seriesCount = reader.getSeriesCount();
            //Select which series to open!!!!!
            int ser = SelectSeries(reader, IA.TabPages.FileBrowser.StatusLabel);

            if (ser == -1)
            {
                fi = null;
                reader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }
            else
            {
                reader.setSeries(ser);
            }
            //Check file bits per pixel - currently supported: 8 bit GrayScale, 16 bit GrayScale
            fi.bitsPerPixel = reader.getBitsPerPixel();
            if (fi.bitsPerPixel <= 8)
            {
                fi.bitsPerPixel = 8;
            }
            else if (fi.bitsPerPixel <= 16)
            {
                fi.bitsPerPixel = 16;
            }
            else
            {
                fi = null;
                reader.close();
                StatusLabel.Text = "Ready";
                return(false);
            }
            //Check is the metadata complieted and return message if not

            /*
             * if (reader.isMetadataComplete() == false)
             * {
             *  MessageBox.Show("Metadata is not complete!");
             * }
             */
            //read tags

            fi.imageCount = reader.getImageCount();
            fi.sizeX      = reader.getSizeX();
            fi.sizeY      = reader.getSizeY();
            fi.sizeZ      = reader.getSizeZ();
            fi.sizeC      = reader.getSizeC();
            fi.sizeT      = reader.getSizeT();
            //fi.dimensionOrder = reader.getDimensionOrder();
            fi.dimensionOrder              = "XYCZT";
            fi.umZ                         = 0;
            fi.umXY                        = 0;
            fi.pixelType                   = reader.getPixelType();
            fi.FalseColored                = reader.isFalseColor();
            fi.isIndexed                   = reader.isIndexed();
            fi.MetadataComplete            = reader.isMetadataComplete();
            fi.DatasetStructureDescription = reader.getDatasetStructureDescription();
            string description = getLibTifFileDescription(path);

            fi.FileDescription = string.Join("\n", new string[] { "-----------------", "CoreMetadata:\n", reader.getCoreMetadataList().ToString(),
                                                                  "-----------------", "GlobalMetadata:\n", reader.getGlobalMetadata().ToString(),
                                                                  "-----------------", "SeriesMetadata:\n", reader.getSeriesMetadata().ToString(),
                                                                  "-----------------", "FileDescription:\n", description });
            //Apply def settings
            fi.Dir       = path;
            fi.xAxisTB   = IA.chart.Properties.xAxisTB.SelectedIndex;
            fi.yAxisTB   = IA.chart.Properties.yAxisTB.SelectedIndex;
            fi.available = false;
            fi.original  = false;
            //Create LUT table
            if (isRGB)
            {
                fi.LutList = new List <Color>()
                {
                    Color.FromArgb(255, 255, 0, 0),
                    Color.FromArgb(255, 0, 255, 0),
                    Color.FromArgb(255, 0, 0, 255)
                };
            }
            else
            {
                fi.LutList = new List <Color>();
                for (int i = 0; i < fi.sizeC; i++)
                {
                    fi.LutList.Add(Color.White);
                }
            }
            //Create time steps table
            fi.TimeSteps = new List <double>();
            fi.TimeSteps.Add(fi.imageCount + 1);
            fi.TimeSteps.Add(1);

            //If its IQ3 format or Dragonflye - try to read the colors and the timesteps
            TryAndorDecoders(fi, description);

            if (fi.sizeC == 0)
            {
                fi.sizeC = 1;
            }
            if (fi.sizeZ == 0)
            {
                fi.sizeZ = 1;
            }
            if (fi.sizeT == 0)
            {
                fi.sizeT = 1;
            }

            #region Segmentation variables
            fi.SegmentationCBoxIndex = new int[fi.sizeC];
            fi.SegmentationProtocol  = new int[fi.sizeC];
            fi.thresholdsCBoxIndex   = new int[fi.sizeC];
            fi.sumHistogramChecked   = new bool[fi.sizeC];
            fi.thresholdValues       = new int[fi.sizeC][];
            fi.thresholdColors       = new Color[fi.sizeC][];
            fi.RefThresholdColors    = new Color[fi.sizeC][];
            fi.thresholds            = new int[fi.sizeC];
            fi.SpotColor             = new Color[fi.sizeC];
            fi.RefSpotColor          = new Color[fi.sizeC];
            fi.SelectedSpotThresh    = new int[fi.sizeC];
            fi.SpotThresh            = new int[fi.sizeC];
            fi.typeSpotThresh        = new int[fi.sizeC];
            fi.SpotTailType          = new string[fi.sizeC];
            fi.spotSensitivity       = new int[fi.sizeC];
            fi.roiList          = new List <ROI> [fi.sizeC];
            fi.tracking_MaxSize = new int[fi.sizeC];
            fi.tracking_MinSize = new int[fi.sizeC];
            fi.tracking_Speed   = new int[fi.sizeC];
            for (int i = 0; i < fi.sizeC; i++)
            {
                fi.sumHistogramChecked[i] = false;
                fi.thresholdValues[i]     = new int[5];
                fi.thresholdColors[i]     = new Color[]
                { Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent };
                fi.RefThresholdColors[i] = new Color[]
                { Color.Black, Color.Orange, Color.Green, Color.Blue, Color.Magenta };
                fi.SpotColor[i]        = Color.Red;
                fi.RefSpotColor[i]     = Color.Red;
                fi.SpotTailType[i]     = "<";
                fi.spotSensitivity[i]  = 100;
                fi.tracking_MaxSize[i] = 10000;
                fi.tracking_MinSize[i] = 5;
                fi.tracking_Speed[i]   = 5;
            }
            #endregion Segmentation variables

            //background worker
            var bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress = true;
            bool loaded = false;
            //Add handlers to the backgroundworker
            bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
            {
                //prepare array and read file
                if (isLibTifCompatible(path) && !isRGB)
                {
                    int[] dimOrder = GetFrameIndexes(reader, fi);
                    Tiff image     = Tiff.Open(OSStringConverter.StringToDir(path), "r");
                    //prepare array and read file
                    int midFrame = fi.sizeC * fi.sizeZ;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[image.NumberOfDirectories()][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image8bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;

                    case 16:
                        fi.image16bit = new ushort[image.NumberOfDirectories()][][];
                        for (int i = 0; i < midFrame; i++)
                        {
                            if (i >= fi.imageCount)
                            {
                                break;
                            }
                            IA.TabPages.myFileDecoder.Image16bit_readFrame(i, image, fi, dimOrder);
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //parallel readers
                    IA.TabPages.myFileDecoder.ImageReader_BGW(Collection, image, fi, IA, path, dimOrder);
                    //report progress
                    dimOrder = null;
                    image.Close();

                    ((BackgroundWorker)o).ReportProgress(1);
                }
                else
                {
                    //Read the first T
                    byte[] buf;
                    switch (fi.bitsPerPixel)
                    {
                    case 8:
                        fi.image8bit = new byte[fi.imageCount][][];

                        buf = new byte[fi.sizeX * fi.sizeY];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image8bit[i] = Image8bit_readFrame(
                                    reader.openBytes(
                                        reader.getIndex(z, c, 0), buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }

                        break;

                    case 16:
                        fi.image16bit = new ushort[fi.imageCount][][];
                        buf           = new byte[fi.sizeX * fi.sizeY * 2];

                        for (int z = 0, i = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                fi.image16bit[i] = Image16bit_readFrame(
                                    reader.openBytes(
                                        reader.getIndex(z, c, 0), buf),
                                    fi.sizeX, fi.sizeY);

                                //fi.LutList[c] = ReadLut(reader);
                            }
                        }
                        break;
                    }
                    loaded = true;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                    //Read the rest T
                    byte[][] bigBuf = new byte[fi.imageCount][];

                    int ZCcount = fi.sizeC * fi.sizeZ;

                    for (int t = 1, i = ZCcount; t < fi.sizeT; t++)
                    {
                        for (int z = 0; z < fi.sizeZ; z++)
                        {
                            for (int c = 0; c < fi.sizeC; c++, i++)
                            {
                                if (fi.image8bit != null || fi.image16bit != null)
                                {
                                    bigBuf[i] = reader.openBytes(reader.getIndex(z, c, t));
                                }
                            }
                        }
                    }
                    //Format the arrays for CellTool
                    Parallel.For(ZCcount, fi.imageCount, (int i) =>
                    {
                        try
                        {
                            switch (fi.bitsPerPixel)
                            {
                            case 8:
                                if (fi.image8bit != null)
                                {
                                    fi.image8bit[i] = Image8bit_readFrame(bigBuf[i],
                                                                          fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;

                            case 16:
                                if (fi.image16bit != null)
                                {
                                    fi.image16bit[i] = Image16bit_readFrame(bigBuf[i],
                                                                            fi.sizeX, fi.sizeY);
                                }
                                bigBuf[i] = null;
                                break;
                            }
                        }
                        catch { }
                    });
                    bigBuf = null;
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(1);
                }
            });
            bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
            {
                if (a.ProgressPercentage == 0)
                {
                    fi.openedImages = fi.sizeC * fi.sizeZ;
                    try
                    {
                        IA.ReloadImages();
                    }
                    catch { }
                }
                else if (a.ProgressPercentage == 1)
                {
                    //dispose the reader
                    reader.close();
                    reader = null;
                    //mark as loaded
                    fi.openedImages = fi.imageCount;
                    fi.available    = true;
                    fi.loaded       = true;

                    IA.TabPages.myFileDecoder.CalculateAllRois(fi);

                    IA.ReloadImages();
                    bool check = true;
                    foreach (TabPage tp1 in Collection)
                    {
                        if (tp1.tifFI != null && tp1.tifFI.available == false)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check == true)
                    {
                        IA.TabPages.myFileDecoder.loadingTimer.Stop();
                        StatusLabel.Text = "Ready";
                    }

                    if (IA.Segmentation.AutoSetUp.LibTB.SelectedIndex > 0 &&
                        IA.Segmentation.AutoSetUp.ApplyToNewCheckB.Checked &&
                        MessageBox.Show("Do you want to open the image with the following protocol:\n" +
                                        IA.Segmentation.AutoSetUp.LibTB.Text,
                                        "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        IA.Segmentation.AutoSetUp.ApplyCT3Tags(IA.Segmentation.AutoSetUp.protocols[
                                                                   IA.Segmentation.AutoSetUp.LibTB.SelectedIndex].Split(
                                                                   new string[] { ";\n" }, StringSplitOptions.None), fi);
                    }
                }
            });

            //Start background worker
            StatusLabel.Text = "Reading Image...";
            //Clear OldImage
            IA.IDrawer.ClearImage();

            //start bgw
            bgw.RunWorkerAsync();
            //add taskbar
            tp.tifFI.tpTaskbar.Initialize(IA.TabPages.ImageMainPanel, IA, fi);

            try
            {
                if (loaded == true)
                {
                    IA.ReloadImages();
                }
            }
            catch { }
            //out put
            return(true);
        }
예제 #11
0
        private static void SaveTif_8bitRawData(TifFileInfo fi, string fileName, ImageAnalyser IA)
        {
            // Register the extender callback
            m_parentExtender = Tiff.SetTagExtender(TagExtender);
            string value = calculateCTTagValue(fi, IA);

            int numberOfPages = fi.imageCount;

            int width           = fi.sizeX;
            int height          = fi.sizeY;
            int samplesPerPixel = 1;
            int bitsPerSample   = fi.bitsPerPixel;

            //check the size of the image and start the writer
            int writersCount = NumberOfTiffWriters(fi);

            if (writersCount == 1)
            {
                using (Tiff output = Tiff.Open(OSStringConverter.StringToDir(fileName), "w"))
                {
                    for (int page = 0; page < numberOfPages; page++)
                    {
                        byte[][] firstPageBuffer = fi.image8bit[page];
                        output.SetField(TiffTag.IMAGELENGTH, height);
                        output.SetField(TiffTag.IMAGEWIDTH, width);
                        output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                        output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                        output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                        output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                        output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                        output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                        output.SetField(TiffTag.COMPRESSION, Compression.NONE);
                        output.SetField(TiffTag.IMAGEDESCRIPTION, ImageDetails());
                        // specify that it's a page within the multipage file
                        output.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
                        // specify the page number
                        output.SetField(TiffTag.PAGENUMBER, page, numberOfPages);

                        if (page == numberOfPages - 1)
                        {
                            // set the custom tag
                            output.SetField(TIFFTAG_CellTool_METADATA, value);
                        }
                        for (int j = 0; j < height; ++j)
                        {
                            output.WriteScanline(firstPageBuffer[j], j);
                        }

                        output.WriteDirectory();
                    }
                }
            }
            else
            {
                string newFileName = CheckForFileChain(fileName);               //Remove time chain suffix
                newFileName = newFileName.Substring(0, newFileName.Length - 4); //remove .tif extension

                int pageMaxPerWriter = NumberOfFramesPerPart(fi);               //get maximal pages per writer

                fi.Dir = FileChain_GetName(0, newFileName);                     //set the filename to the first file from the chain

                Parallel.For(0, writersCount, (ind) =>
                {
                    int start = ind * pageMaxPerWriter;
                    int stop  = start + pageMaxPerWriter;
                    using (Tiff output = Tiff.Open(OSStringConverter.StringToDir(
                                                       FileChain_GetName(ind, newFileName)), "w"))
                    {
                        for (int page = 0; start < numberOfPages && start < stop; page++, start++)
                        {
                            byte[][] firstPageBuffer = fi.image8bit[start];
                            output.SetField(TiffTag.IMAGELENGTH, height);
                            output.SetField(TiffTag.IMAGEWIDTH, width);
                            output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                            output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                            output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                            output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                            output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                            output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                            output.SetField(TiffTag.COMPRESSION, Compression.NONE);
                            output.SetField(TiffTag.IMAGEDESCRIPTION, ImageDetails());
                            // specify that it's a page within the multipage file
                            output.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
                            // specify the page number
                            output.SetField(TiffTag.PAGENUMBER, page, pageMaxPerWriter);

                            if (start == numberOfPages - 1 || start == stop - 1)
                            {
                                // set the custom tag
                                output.SetField(TIFFTAG_CellTool_METADATA, value);
                            }
                            for (int j = 0; j < height; ++j)
                            {
                                output.WriteScanline(firstPageBuffer[j], j);
                            }

                            output.WriteDirectory();
                        }
                    }
                });
            }
            // restore previous tag extender
            Tiff.SetTagExtender(m_parentExtender);
        }
        private void UnInstallPlugIn_Click(object sender, EventArgs e)
        {
            Form msgForm = new Form();

            msgForm.Height = 600;
            msgForm.Width  = 600;
            msgForm.Icon   = Properties.Resources.CT_done;
            msgForm.Text   = "Uninstall PlugIns";

            TreeView rtb = new TreeView();

            rtb.CheckBoxes = true;
            rtb.ShowLines  = false;
            rtb.Dock       = DockStyle.Fill;
            //Fill the box with names
            string path = OSStringConverter.StringToDir(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CellToolPlugIns");
            bool unisntalled = false;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            foreach (var file in directoryInfo.GetFiles())
            {
                if (file.Name.EndsWith(".CTPlugIn.dll") &&
                    !file.Name.EndsWith("Results_Extractor.CTPlugIn.dll"))
                {
                    string   namePlugIn = file.Name.Replace(".CTPlugIn.dll", "").Replace("_", " ");
                    string   dirPlugIn  = file.FullName;
                    TreeNode n          = new TreeNode(namePlugIn);
                    n.Checked = false;
                    n.Tag     = dirPlugIn;
                    rtb.Nodes.Add(n);
                }
            }
            //end filling
            msgForm.Controls.Add(rtb);

            Panel okBox = new Panel();

            okBox.Height = 40;
            okBox.Dock   = DockStyle.Bottom;
            msgForm.Controls.Add(okBox);

            Button okBtn = new Button();

            okBtn.Text      = "Uninstall";
            okBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
            okBtn.ForeColor = System.Drawing.Color.Black;
            okBtn.Location  = new System.Drawing.Point(20, 10);
            okBtn.Anchor    = AnchorStyles.Top | AnchorStyles.Left;
            okBox.Controls.Add(okBtn);

            Button cancelBtn = new Button();

            cancelBtn.Text      = "Cancel";
            cancelBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
            cancelBtn.Location  = new System.Drawing.Point(msgForm.Width - cancelBtn.Width - 40, 10);
            cancelBtn.ForeColor = System.Drawing.Color.Black;
            cancelBtn.Anchor    = AnchorStyles.Top | AnchorStyles.Right;
            okBox.Controls.Add(cancelBtn);

            okBtn.Click += new EventHandler(delegate(object o, EventArgs a)
            {
                foreach (TreeNode n in rtb.Nodes)
                {
                    if (n.Checked && File.Exists((string)n.Tag))
                    {
                        try
                        {
                            File.Delete((string)n.Tag);
                            unisntalled = true;
                        }
                        catch
                        {
                            MessageBox.Show(
                                "To uninstall the PlugIn, restart the program and try again!");
                        }
                    }
                }

                msgForm.Close();
            });

            cancelBtn.Click += new EventHandler(delegate(object o, EventArgs a)
            {
                msgForm.Close();
            });

            // Linux change
            IA.FileBrowser.StatusLabel.Text = "Dialog open";
            msgForm.ShowDialog();
            IA.FileBrowser.StatusLabel.Text = "Ready";

            if (unisntalled)
            {
                PlugIns_TakeNames();
                MessageBox.Show("Selected plugins are uninstalled.");
            }
            msgForm.Dispose();
        }