The function "OpenOME" opens a bioimage file, with options to specify the series, whether to display it in a tab, whether to add it to existing images, whether to tile the image, and the tile size.
The function "OpenOME" opens a bioimage file, with options to specify the series, whether to
7457 {
7458 if (file == null || file == "")
7459 throw new InvalidDataException("File is empty or null");
7460
7461 do
7462 {
7463 Thread.Sleep(10);
7464 } while (!initialized);
7465 Console.WriteLine("OpenOME " + file);
7466 reader = new ImageReader();
7467 if (tileSizeX == 0)
7468 tileSizeX = 1920;
7469 if (tileSizeY == 0)
7470 tileSizeY = 1080;
7471 progFile = file;
7472 BioImage b = new BioImage(file);
7473 b.Type = ImageType.stack;
7474 b.Loading = true;
7475 if (b.meta == null)
7476 b.meta = service.createOMEXMLMetadata();
7477 string f = file.Replace("\\", "/");
7478 string cf = reader.getCurrentFile();
7479 if (cf != null)
7480 cf = cf.Replace("\\", "/");
7481 if (cf != f)
7482 {
7483 reader.close();
7484 reader.setMetadataStore(b.meta);
7485 try
7486 {
7487 Status = "Opening file " + b.Filename;
7488 reader.setId(f);
7489 }
7490 catch (Exception e)
7491 {
7492 Console.WriteLine(e.Message);
7493 return null;
7494 }
7495 }
7496
7497
7498 reader.setSeries(serie);
7499 int RGBChannelCount = reader.getRGBChannelCount();
7500
7501
7502 PixelFormat PixelFormat;
7503 try
7504 {
7505 PixelFormat =
GetPixelFormat(RGBChannelCount, b.meta.getPixelsType(serie));
7506 }
7507 catch (Exception)
7508 {
7509 PixelFormat =
GetPixelFormat(RGBChannelCount, reader.getBitsPerPixel());
7510 }
7511
7512 b.id = file;
7513 b.file = file;
7514 int SizeX, SizeY;
7515 SizeX = reader.getSizeX();
7516 SizeY = reader.getSizeY();
7517 int SizeZ = reader.getSizeZ();
7518 b.sizeC = reader.getSizeC();
7519 b.sizeZ = reader.getSizeZ();
7520 b.sizeT = reader.getSizeT();
7521 b.littleEndian = reader.isLittleEndian();
7522 b.seriesCount = reader.getSeriesCount();
7523 b.imagesPerSeries = reader.getImageCount();
7524 b.imRead = reader;
7525 List<Resolution> ress = new List<Resolution>();
7526 if (PixelFormat == PixelFormat.Format8bppIndexed || PixelFormat == PixelFormat.Format24bppRgb || PixelFormat == PixelFormat.Format32bppArgb)
7527 b.bitsPerPixel = 8;
7528 else
7529 b.bitsPerPixel = 16;
7530 b.series = serie;
7531 string order = reader.getDimensionOrder();
7532 if (vips)
7534
7535 int i = 0;
7536 int sumSamples = 0;
7537 while (true)
7538 {
7539 Status = "Reading channels.";
7540 bool def = false;
7541 try
7542 {
7543 int s = b.meta.getChannelSamplesPerPixel(serie, i).getNumberValue().intValue();
7544 Channel ch = new Channel(i, b.bitsPerPixel, s);
7545 if (b.meta.getChannelSamplesPerPixel(serie, i) != null)
7546 {
7547 ch.SamplesPerPixel = s;
7548 sumSamples += s;
7549 def = true;
7550 b.Channels.Add(ch);
7551 }
7552 if (i == 0)
7553 {
7554 b.rgbChannels[0] = 0;
7555 }
7556 else
7557 if (i == 1)
7558 {
7559 b.rgbChannels[1] = 1;
7560 }
7561 else
7562 if (i == 2)
7563 {
7564 b.rgbChannels[2] = 2;
7565 }
7566
7567 if (!def)
7568 break;
7569 if (b.meta.getChannelName(serie, i) != null)
7570 ch.Name = b.meta.getChannelName(serie, i);
7571 if (b.meta.getChannelAcquisitionMode(serie, i) != null)
7572 ch.AcquisitionMode = b.meta.getChannelAcquisitionMode(serie, i).ToString();
7573 if (b.meta.getChannelID(serie, i) != null)
7574 ch.info.ID = b.meta.getChannelID(serie, i);
7575 if (b.meta.getChannelFluor(serie, i) != null)
7576 ch.Fluor = b.meta.getChannelFluor(serie, i);
7577 if (b.meta.getChannelColor(serie, i) != null)
7578 {
7579 BioFormats::ome.xml.model.primitives.Color cc = b.meta.getChannelColor(serie, i);
7580 ch.Color = Color.FromArgb(cc.getRed(), cc.getGreen(), cc.getBlue());
7581 }
7582 if (b.meta.getChannelIlluminationType(serie, i) != null)
7583 ch.IlluminationType = b.meta.getChannelIlluminationType(serie, i).ToString();
7584 if (b.meta.getChannelContrastMethod(serie, i) != null)
7585 ch.ContrastMethod = b.meta.getChannelContrastMethod(serie, i).ToString();
7586 if (b.meta.getChannelEmissionWavelength(serie, i) != null)
7587 ch.Emission = b.meta.getChannelEmissionWavelength(serie, i).value().intValue();
7588 if (b.meta.getChannelExcitationWavelength(serie, i) != null)
7589 ch.Excitation = b.meta.getChannelExcitationWavelength(serie, i).value().intValue();
7590 if (b.meta.getLightEmittingDiodePower(serie, i) != null)
7591 ch.LightSourceIntensity = b.meta.getLightEmittingDiodePower(serie, i).value().doubleValue();
7592 if (b.meta.getLightEmittingDiodeID(serie, i) != null)
7593 ch.DiodeName = b.meta.getLightEmittingDiodeID(serie, i);
7594 if (b.meta.getChannelLightSourceSettingsAttenuation(serie, i) != null)
7595 ch.LightSourceAttenuation = b.meta.getChannelLightSourceSettingsAttenuation(serie, i).toString();
7596
7597
7598 }
7599 catch (Exception e)
7600 {
7601 Console.WriteLine(e.Message);
7602 if (!def)
7603 break;
7604 }
7605 i++;
7606 }
7607 try
7608 {
7609 if (b.meta.getObjectiveNominalMagnification(serie, 0) != null)
7610 {
7611 b.Magnification = b.meta.getObjectiveNominalMagnification(serie, 0).intValue();
7612 }
7613 }
7614 catch (Exception e)
7615 {
7616 Console.WriteLine(e.Message);
7617 }
7618
7619
7620 if (b.Channels.Count == 0)
7621 {
7622 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
7623 }
7624 try
7625 {
7626 Status = "Reading wells.";
7627 int wells = b.meta.getWellCount(0);
7628 if (wells > 0)
7629 {
7630 b.Type = ImageType.well;
7631 b.Plate = new WellPlate(b);
7632 tile = false;
7633 }
7634 }
7635 catch (Exception e)
7636 {
7637
7638 Console.WriteLine(e.Message);
7639 }
7640 if (reader.getResolutionCount() > 0)
7641 ress.AddRange(GetResolutions(b));
7642 Console.WriteLine("Done reading resolutions.");
7643 reader.setSeries(serie);
7644
7645 int pyramidCount = 0;
7646 int pyramidResolutions = 0;
7647 List<Tuple<int, int>> prs = new List<Tuple<int, int>>();
7648 Console.WriteLine("Determining pyramidal levels.");
7649
7650
7651 if (ress.Count > 1 && b.Type != ImageType.well)
7652 {
7653 if (ress[0].SizeX > ress[1].SizeX)
7654 {
7655 b.Type = ImageType.pyramidal;
7656 tile = true;
7657
7658 int? sr = null;
7659 for (int r = 0; r < ress.Count - 1; r++)
7660 {
7661 if (ress[r].SizeX > ress[r + 1].SizeX && ress[r].PixelFormat == ress[r + 1].PixelFormat)
7662 {
7663 if (sr == null)
7664 {
7665 sr = r;
7666 prs.Add(new Tuple<int, int>(r, 0));
7667 }
7668 }
7669 else
7670 {
7671 if (ress[prs[prs.Count - 1].Item1].PixelFormat == ress[r].PixelFormat)
7672 prs[prs.Count - 1] = new Tuple<int, int>(prs[prs.Count - 1].Item1, r);
7673 sr = null;
7674 }
7675 }
7676 pyramidCount = prs.Count;
7677 for (int p = 0; p < prs.Count; p++)
7678 {
7679 pyramidResolutions += (prs[p].Item2 - prs[p].Item1) + 1;
7680 }
7681 if (prs[serie].Item2 == 0)
7682 {
7683 prs[serie] = new Tuple<int, int>(prs[serie].Item1, b.seriesCount - 1);
7684 }
7685 }
7686 }
7687 if (b.Type == ImageType.pyramidal)
7688 {
7689 Console.WriteLine("Determining Label and Macro resolutions.");
7690 for (int p = 0; p < prs.Count; p++)
7691 {
7692 for (int r = prs[p].Item1; r < prs[p].Item2 + 1; r++)
7693 {
7694 b.Resolutions.Add(ress[r]);
7695 }
7696 }
7697
7698 if (ress.Count > b.Resolutions.Count)
7699 {
7700 b.LabelResolution = ress.Count - 1;
7701 b.Resolutions.Add(ress[ress.Count - 1]);
7702 b.MacroResolution = ress.Count - 2;
7703 b.Resolutions.Add(ress[ress.Count - 2]);
7704 }
7705 }
7706 if (b.Resolutions.Count == 0)
7707 b.Resolutions.AddRange(ress);
7708 try
7709 {
7710 string s = b.meta.getStageLabelName(serie);
7711 if (s != null)
7712 {
7713 b.StageSizeX = b.meta.getStageLabelX(serie).value().doubleValue();
7714 b.StageSizeY = b.meta.getStageLabelY(serie).value().doubleValue();
7715 b.StageSizeZ = b.meta.getStageLabelZ(serie).value().doubleValue();
7716 }
7717 }
7718 catch (Exception e)
7719 {
7720 Console.WriteLine("No Stage Cooordinates");
7721 }
7722
7723 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.PhysicalSizeX * SizeX, b.PhysicalSizeY * SizeY, b.PhysicalSizeZ * SizeZ));
7724 int rc = b.meta.getROICount();
7725 for (int im = 0; im < rc; im++)
7726 {
7727 string roiID = b.meta.getROIID(im);
7728 string roiName = b.meta.getROIName(im);
7729 ZCT co = new ZCT(0, 0, 0);
7730 int scount = 1;
7731 try
7732 {
7733 scount = b.meta.getShapeCount(im);
7734 }
7735 catch (Exception e)
7736 {
7737 Console.WriteLine(e.Message.ToString());
7738 }
7739 for (int sc = 0; sc < scount; sc++)
7740 {
7741 Status =
"Reading ROI " + (sc + 1).
ToString() +
"/" + scount;
7742 string typ = b.meta.getShapeType(im, sc);
7743 ROI an = new ROI();
7744 an.roiID = roiID;
7745 an.roiName = roiName;
7746 an.shapeIndex = sc;
7747 if (typ == "Point")
7748 {
7749 an.type = ROI.Type.Point;
7750 an.id = b.meta.getPointID(im, sc);
7751 double dx = b.meta.getPointX(im, sc).doubleValue();
7752 double dy = b.meta.getPointY(im, sc).doubleValue();
7753 an.AddPoint(b.ToStageSpace(new PointD(dx, dy)));
7754 an.coord = new ZCT();
7755 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPointTheZ(im, sc);
7756 if (nz != null)
7757 an.coord.Z = nz.getNumberValue().intValue();
7758 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPointTheC(im, sc);
7759 if (nc != null)
7760 an.coord.C = nc.getNumberValue().intValue();
7761 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPointTheT(im, sc);
7762 if (nt != null)
7763 an.coord.T = nt.getNumberValue().intValue();
7764 an.Text = b.meta.getPointText(im, sc);
7765 BioFormats::ome.units.quantity.Length fl = b.meta.getPointFontSize(im, sc);
7766 if (fl != null)
7767 an.fontSize = fl.value().intValue();
7768 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getPointFontFamily(im, sc);
7769 if (ff != null)
7770 an.family = ff.name();
7771 BioFormats::ome.xml.model.primitives.Color col = b.meta.getPointStrokeColor(im, sc);
7772 if (col != null)
7773 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7774 BioFormats::ome.units.quantity.Length fw = b.meta.getPointStrokeWidth(im, sc);
7775 if (fw != null)
7776 an.strokeWidth = (float)fw.value().floatValue();
7777 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getPointStrokeColor(im, sc);
7778 if (colf != null)
7779 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7780 }
7781 else
7782 if (typ == "Line")
7783 {
7784 an.type = ROI.Type.Line;
7785 an.id = b.meta.getLineID(im, sc);
7786 double px1 = b.meta.getLineX1(im, sc).doubleValue();
7787 double py1 = b.meta.getLineY1(im, sc).doubleValue();
7788 double px2 = b.meta.getLineX2(im, sc).doubleValue();
7789 double py2 = b.meta.getLineY2(im, sc).doubleValue();
7790 an.AddPoint(b.ToStageSpace(new PointD(px1, py1)));
7791 an.AddPoint(b.ToStageSpace(new PointD(px2, py2)));
7792 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLineTheZ(im, sc);
7793 if (nz != null)
7794 co.Z = nz.getNumberValue().intValue();
7795 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLineTheC(im, sc);
7796 if (nc != null)
7797 co.C = nc.getNumberValue().intValue();
7798 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLineTheT(im, sc);
7799 if (nt != null)
7800 co.T = nt.getNumberValue().intValue();
7801 an.coord = co;
7802 an.Text = b.meta.getLineText(im, sc);
7803 BioFormats::ome.units.quantity.Length fl = b.meta.getLineFontSize(im, sc);
7804 if (fl != null)
7805 an.fontSize = fl.value().intValue();
7806 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getLineFontFamily(im, sc);
7807 if (ff != null)
7808 an.family = ff.name();
7809 BioFormats::ome.xml.model.primitives.Color col = b.meta.getLineStrokeColor(im, sc);
7810 if (col != null)
7811 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7812 BioFormats::ome.units.quantity.Length fw = b.meta.getLineStrokeWidth(im, sc);
7813 if (fw != null)
7814 an.strokeWidth = (float)fw.value().floatValue();
7815 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getLineFillColor(im, sc);
7816 if (colf != null)
7817 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7818 }
7819 else
7820 if (typ == "Rectangle")
7821 {
7822 an.type = ROI.Type.Rectangle;
7823 an.id = b.meta.getRectangleID(im, sc);
7824 double px = b.meta.getRectangleX(im, sc).doubleValue();
7825 double py = b.meta.getRectangleY(im, sc).doubleValue();
7826 double pw = b.meta.getRectangleWidth(im, sc).doubleValue();
7827 double ph = b.meta.getRectangleHeight(im, sc).doubleValue();
7828 an.Rect = b.ToStageSpace(new RectangleD(px, py, pw, ph));
7829 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getRectangleTheZ(im, sc);
7830 if (nz != null)
7831 co.Z = nz.getNumberValue().intValue();
7832 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getRectangleTheC(im, sc);
7833 if (nc != null)
7834 co.C = nc.getNumberValue().intValue();
7835 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getRectangleTheT(im, sc);
7836 if (nt != null)
7837 co.T = nt.getNumberValue().intValue();
7838 an.coord = co;
7839
7840 an.Text = b.meta.getRectangleText(im, sc);
7841 BioFormats::ome.units.quantity.Length fl = b.meta.getRectangleFontSize(im, sc);
7842 if (fl != null)
7843 an.fontSize = fl.value().intValue();
7844 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getRectangleFontFamily(im, sc);
7845 if (ff != null)
7846 an.family = ff.name();
7847 BioFormats::ome.xml.model.primitives.Color col = b.meta.getRectangleStrokeColor(im, sc);
7848 if (col != null)
7849 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7850 BioFormats::ome.units.quantity.Length fw = b.meta.getRectangleStrokeWidth(im, sc);
7851 if (fw != null)
7852 an.strokeWidth = (float)fw.value().floatValue();
7853 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getRectangleFillColor(im, sc);
7854 if (colf != null)
7855 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7856 BioFormats::ome.xml.model.enums.FillRule fr = b.meta.getRectangleFillRule(im, sc);
7857
7858 }
7859 else
7860 if (typ == "Ellipse")
7861 {
7862 an.type = ROI.Type.Ellipse;
7863 an.id = b.meta.getEllipseID(im, sc);
7864 double px = b.meta.getEllipseX(im, sc).doubleValue();
7865 double py = b.meta.getEllipseY(im, sc).doubleValue();
7866 double ew = b.meta.getEllipseRadiusX(im, sc).doubleValue();
7867 double eh = b.meta.getEllipseRadiusY(im, sc).doubleValue();
7868
7869 double w = ew * 2;
7870 double h = eh * 2;
7871 double x = px - ew;
7872 double y = py - eh;
7873 an.Rect = b.ToStageSpace(new RectangleD(x, y, w, h));
7874 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getEllipseTheZ(im, sc);
7875 if (nz != null)
7876 co.Z = nz.getNumberValue().intValue();
7877 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getEllipseTheC(im, sc);
7878 if (nc != null)
7879 co.C = nc.getNumberValue().intValue();
7880 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getEllipseTheT(im, sc);
7881 if (nt != null)
7882 co.T = nt.getNumberValue().intValue();
7883 an.coord = co;
7884 an.Text = b.meta.getEllipseText(im, sc);
7885 BioFormats::ome.units.quantity.Length fl = b.meta.getEllipseFontSize(im, sc);
7886 if (fl != null)
7887 an.fontSize = fl.value().intValue();
7888 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getEllipseFontFamily(im, sc);
7889 if (ff != null)
7890 an.family = ff.name();
7891 BioFormats::ome.xml.model.primitives.Color col = b.meta.getEllipseStrokeColor(im, sc);
7892 if (col != null)
7893 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7894 BioFormats::ome.units.quantity.Length fw = b.meta.getEllipseStrokeWidth(im, sc);
7895 if (fw != null)
7896 an.strokeWidth = (float)fw.value().floatValue();
7897 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getEllipseFillColor(im, sc);
7898 if (colf != null)
7899 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7900 }
7901 else
7902 if (typ == "Polygon")
7903 {
7904 an.type = ROI.Type.Polygon;
7905 an.id = b.meta.getPolygonID(im, sc);
7906 an.closed = true;
7907 string pxs = b.meta.getPolygonPoints(im, sc);
7908 PointD[] pts = an.stringToPoints(pxs);
7909 pts = b.ToStageSpace(pts);
7910 if (pts.Length > 100)
7911 {
7912 an.type = ROI.Type.Freeform;
7913 }
7914 an.AddPoints(pts);
7915 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolygonTheZ(im, sc);
7916 if (nz != null)
7917 co.Z = nz.getNumberValue().intValue();
7918 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolygonTheC(im, sc);
7919 if (nc != null)
7920 co.C = nc.getNumberValue().intValue();
7921 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolygonTheT(im, sc);
7922 if (nt != null)
7923 co.T = nt.getNumberValue().intValue();
7924 an.coord = co;
7925 an.Text = b.meta.getPolygonText(im, sc);
7926 BioFormats::ome.units.quantity.Length fl = b.meta.getPolygonFontSize(im, sc);
7927 if (fl != null)
7928 an.fontSize = fl.value().intValue();
7929 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getPolygonFontFamily(im, sc);
7930 if (ff != null)
7931 an.family = ff.name();
7932 BioFormats::ome.xml.model.primitives.Color col = b.meta.getPolygonStrokeColor(im, sc);
7933 if (col != null)
7934 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7935 BioFormats::ome.units.quantity.Length fw = b.meta.getPolygonStrokeWidth(im, sc);
7936 if (fw != null)
7937 an.strokeWidth = (float)fw.value().floatValue();
7938 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getPolygonFillColor(im, sc);
7939 if (colf != null)
7940 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7941 }
7942 else
7943 if (typ == "Polyline")
7944 {
7945 an.type = ROI.Type.Polyline;
7946 an.id = b.meta.getPolylineID(im, sc);
7947 string pxs = b.meta.getPolylinePoints(im, sc);
7948 PointD[] pts = an.stringToPoints(pxs);
7949 for (int pi = 0; pi < pts.Length; pi++)
7950 {
7951 pts[pi] = b.ToStageSpace(pts[pi]);
7952 }
7953 an.AddPoints(an.stringToPoints(pxs));
7954 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolylineTheZ(im, sc);
7955 if (nz != null)
7956 co.Z = nz.getNumberValue().intValue();
7957 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolylineTheC(im, sc);
7958 if (nc != null)
7959 co.C = nc.getNumberValue().intValue();
7960 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolylineTheT(im, sc);
7961 if (nt != null)
7962 co.T = nt.getNumberValue().intValue();
7963 an.coord = co;
7964 an.Text = b.meta.getPolylineText(im, sc);
7965 BioFormats::ome.units.quantity.Length fl = b.meta.getPolylineFontSize(im, sc);
7966 if (fl != null)
7967 an.fontSize = fl.value().intValue();
7968 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getPolylineFontFamily(im, sc);
7969 if (ff != null)
7970 an.family = ff.name();
7971 BioFormats::ome.xml.model.primitives.Color col = b.meta.getPolylineStrokeColor(im, sc);
7972 if (col != null)
7973 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7974 BioFormats::ome.units.quantity.Length fw = b.meta.getPolylineStrokeWidth(im, sc);
7975 if (fw != null)
7976 an.strokeWidth = (float)fw.value().floatValue();
7977 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getPolylineFillColor(im, sc);
7978 if (colf != null)
7979 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7980 }
7981 else
7982 if (typ == "Label")
7983 {
7984 an.type = ROI.Type.Label;
7985 an.id = b.meta.getLabelID(im, sc);
7986
7987 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLabelTheZ(im, sc);
7988 if (nz != null)
7989 co.Z = nz.getNumberValue().intValue();
7990 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLabelTheC(im, sc);
7991 if (nc != null)
7992 co.C = nc.getNumberValue().intValue();
7993 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLabelTheT(im, sc);
7994 if (nt != null)
7995 co.T = nt.getNumberValue().intValue();
7996 an.coord = co;
7997
7998 BioFormats::ome.units.quantity.Length fl = b.meta.getLabelFontSize(im, sc);
7999 if (fl != null)
8000 an.fontSize = fl.value().intValue();
8001 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getLabelFontFamily(im, sc);
8002 if (ff != null)
8003 an.family = ff.name();
8004 BioFormats::ome.xml.model.primitives.Color col = b.meta.getLabelStrokeColor(im, sc);
8005 if (col != null)
8006 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
8007 BioFormats::ome.units.quantity.Length fw = b.meta.getLabelStrokeWidth(im, sc);
8008 if (fw != null)
8009 an.strokeWidth = (float)fw.value().floatValue();
8010 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getLabelFillColor(im, sc);
8011 if (colf != null)
8012 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
8013 PointD p = new PointD(b.meta.getLabelX(im, sc).doubleValue(), b.meta.getLabelY(im, sc).doubleValue());
8014 an.AddPoint(b.ToStageSpace(p));
8015 an.Text = b.meta.getLabelText(im, sc);
8016 }
8017 else
8018 if (typ == "Mask")
8019 {
8020 byte[] bts = b.meta.getMaskBinData(im, sc);
8021 bool end = b.meta.getMaskBinDataBigEndian(im, sc).booleanValue();
8022 double h = b.meta.getMaskHeight(im, sc).doubleValue();
8023 double w = b.meta.getMaskWidth(im, sc).doubleValue();
8024 double x = b.meta.getMaskX(im, sc).doubleValue();
8025 double y = b.meta.getMaskY(im, sc).doubleValue();
8026 an = ROI.CreateMask(co, bts, (int)Math.Round(w / b.PhysicalSizeX), (int)Math.Round(h / b.PhysicalSizeY), new PointD(x * b.PhysicalSizeX, y * b.PhysicalSizeY), b.PhysicalSizeX, b.PhysicalSizeY);
8027 an.Text = b.meta.getMaskText(im, sc);
8028 an.id = b.meta.getMaskID(im, sc);
8029 an.Rect = new RectangleD(an.X, an.Y, an.W, an.H);
8030 BioFormats::ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getMaskTheZ(im, sc);
8031 if (nz != null)
8032 co.Z = nz.getNumberValue().intValue();
8033 BioFormats::ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getMaskTheC(im, sc);
8034 if (nc != null)
8035 co.C = nc.getNumberValue().intValue();
8036 BioFormats::ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getMaskTheT(im, sc);
8037 if (nt != null)
8038 co.T = nt.getNumberValue().intValue();
8039 an.coord = co;
8040
8041 BioFormats::ome.units.quantity.Length fl = b.meta.getMaskFontSize(im, sc);
8042 if (fl != null)
8043 an.fontSize = fl.value().intValue();
8044 BioFormats::ome.xml.model.enums.FontFamily ff = b.meta.getMaskFontFamily(im, sc);
8045 if (ff != null)
8046 an.family = ff.name();
8047 BioFormats::ome.xml.model.primitives.Color col = b.meta.getMaskStrokeColor(im, sc);
8048 if (col != null)
8049 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
8050 BioFormats::ome.units.quantity.Length fw = b.meta.getMaskStrokeWidth(im, sc);
8051 if (fw != null)
8052 an.strokeWidth = (float)fw.value().floatValue();
8053 BioFormats::ome.xml.model.primitives.Color colf = b.meta.getMaskFillColor(im, sc);
8054 if (colf != null)
8055 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
8056 }
8057 b.Annotations.Add(an);
8058 }
8059 }
8060
8061 List<string> serFiles = new List<string>();
8062 serFiles.AddRange(reader.getSeriesUsedFiles());
8063
8064 b.Buffers = new List<Bitmap>();
8065 if (b.Type == ImageType.pyramidal)
8066 {
8067
8068 try
8069 {
8070
8071 string st = OpenSlideImage.DetectVendor(file);
8072 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
8073 {
8074 Status = "Opening file with OpenSlide.";
8075 b.openSlideImage = OpenSlideImage.Open(file);
8076 b.openslideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file, true);
8077 }
8078 else
8079 {
8080 Status = "Opening file with BioFormats.";
8081 b.slideBase = new SlideBase(b, SlideImage.Open(b));
8082 }
8083 }
8084 catch (Exception e)
8085 {
8086 Console.WriteLine(e.Message.ToString());
8087 b.slideBase = new SlideBase(b, SlideImage.Open(b));
8088 }
8089 tile = true;
8090 }
8091
8092 int pages = reader.getImageCount();
8093 bool inter = reader.isInterleaved();
8094 int z = 0;
8095 int c = 0;
8096 int t = 0;
8097 if (!tile)
8098 {
8099 Status = "Reading image planes.";
8100 try
8101 {
8102 for (int p = 0; p < pages; p++)
8103 {
8104 Progress = ((float)p / (float)pages) * 100;
8105 Bitmap bf;
8106 byte[] bytes = reader.openBytes(p);
8107 bf = new Bitmap(file, SizeX, SizeY, PixelFormat, bytes, new ZCT(z, c, t), p, null, b.littleEndian, inter);
8108 b.Buffers.Add(bf);
8109 }
8110 }
8111 catch (Exception ex)
8112 {
8113 Console.WriteLine(ex.Message);
8114 }
8115
8116 }
8117 else
8118 {
8119 Status = "Reading tiles.";
8120 b.imRead = reader;
8121 for (int p = 0; p < pages; p++)
8122 {
8123 Progress = ((float)p / (float)pages) * 100;
8124 b.Buffers.Add(
GetTile(b, p, b.Level, tilex, tiley, tileSizeX, tileSizeY));
8125 }
8126 }
8127 int pls;
8128 try
8129 {
8130 pls = b.meta.getPlaneCount(serie);
8131 }
8132 catch (Exception)
8133 {
8134 pls = 0;
8135 }
8136 if (pls == b.Buffers.Count)
8137 for (int bi = 0; bi < b.Buffers.Count; bi++)
8138 {
8139 Plane pl = new Plane();
8140 pl.Coordinate = new ZCT();
8141 double px = 0; double py = 0; double pz = 0;
8142 if (b.meta.getPlanePositionX(serie, bi) != null)
8143 px = b.meta.getPlanePositionX(serie, bi).value().doubleValue();
8144 if (b.meta.getPlanePositionY(serie, bi) != null)
8145 py = b.meta.getPlanePositionY(serie, bi).value().doubleValue();
8146 if (b.meta.getPlanePositionZ(serie, bi) != null)
8147 pz = b.meta.getPlanePositionZ(serie, bi).value().doubleValue();
8148 pl.Location = new AForge.Point3D(px, py, pz);
8149 int cc = 0; int zc = 0; int tc = 0;
8150 if (b.meta.getPlaneTheC(serie, bi) != null)
8151 cc = b.meta.getPlaneTheC(serie, bi).getNumberValue().intValue();
8152 if (b.meta.getPlaneTheZ(serie, bi) != null)
8153 zc = b.meta.getPlaneTheZ(serie, bi).getNumberValue().intValue();
8154 if (b.meta.getPlaneTheT(serie, bi) != null)
8155 tc = b.meta.getPlaneTheT(serie, bi).getNumberValue().intValue();
8156 pl.Coordinate = new ZCT(zc, cc, tc);
8157 if (b.meta.getPlaneDeltaT(serie, bi) != null)
8158 pl.Delta = b.meta.getPlaneDeltaT(serie, bi).value().doubleValue();
8159 if (b.meta.getPlaneExposureTime(serie, bi) != null)
8160 pl.Exposure = b.meta.getPlaneExposureTime(serie, bi).value().doubleValue();
8161 b.Buffers[bi].Plane = pl;
8162 }
8163
8164 if (RGBChannelCount >= 3)
8165 {
8166 b.sizeC = sumSamples / b.Channels[0].SamplesPerPixel;
8167 }
8168 string ord = reader.getDimensionOrder();
8169 if (ord == "XYZCT")
8170 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, Order.ZCT);
8171 else if (ord == "XYCZT")
8172 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, Order.CZT);
8173 else if (ord == "XYTCZ")
8174 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, Order.TCZ);
8176 if (b.bitsPerPixel > 8)
8177 b.StackThreshold(true);
8178 else
8179 b.StackThreshold(false);
8180 try
8181 {
8182 if (b.Type == ImageType.stack)
8183 reader.close();
8184 if (addToImages)
8185 Images.AddImage(b);
8186 }
8187 catch (Exception e)
8188 {
8189 Console.WriteLine(e.Message);
8190 }
8191 b.Loading = false;
8192 Recorder.Record(
BioLib.
Recorder.GetCurrentMethodInfo(),
false, file, serie, tab, addToImages, tile, tilex, tiley, tileSizeX, tileSizeY);
8193 return b;
8194 }
override string ToString()
This function returns the filename of the object, and the location of the object in the 3D space.