/* * Chart.SetSeriesColor(chanel,roiID, index, color.HTML) -> change the color of the series * Chart.SetSeriesChecked(chanel,roiID, index, bool) -> enable/disable */ private int GetChanel(ROI roi) { //find selected image TifFileInfo fi = null; try { fi = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI; } catch { return(-1); } if (fi == null) { return(-1); } if (fi.roiList == null) { return(-1); } for (int i = 0; i < fi.roiList.Length; i++) { if (fi.roiList[i] != null && fi.roiList[i].IndexOf(roi) > -1) { return(i); } } return(-1); }
public string roi_getAllInfo() { ROI roi = this; string val = "{"; val += roi.Shape.ToString() + "\n"; val += roi.Type.ToString() + "\n"; val += roi.Width.ToString() + "\n"; val += roi.Height.ToString() + "\n"; val += roi.Stack.ToString() + "\n"; val += roi.D.ToString() + "\n"; val += roi.FromT.ToString() + "\n"; val += roi.ToT.ToString() + "\n"; val += roi.FromZ.ToString() + "\n"; val += roi.ToZ.ToString() + "\n"; val += BiggestW.ToString() + "\n"; val += BiggestH.ToString() + "\n"; val += ReturnBiggest.ToString() + "\n"; val += turnOnStackRoi.ToString() + "\n"; val += GetColors() + "\n"; val += GetChartUseIndex() + "\n"; val += "Comment=" + Comment + "\n"; val += roi_getAllLocation(); val += "}"; return(val); }
private static ROI CreateFromHistory(int RoiID, string val, TifFileInfo fi) { val = val.Remove(val.Length - 1, 1).Remove(0, 1); string[] vals = val.Split(new string[] { "\n" }, StringSplitOptions.None); int shape = int.Parse(vals[0]); int type = int.Parse(vals[1]); int W = int.Parse(vals[2]); int H = int.Parse(vals[3]); int stack = int.Parse(vals[4]); int d = int.Parse(vals[5]); int FromT = int.Parse(vals[6]); int ToT = int.Parse(vals[7]); int FromZ = int.Parse(vals[8]); int ToZ = int.Parse(vals[9]); int BiggestW = int.Parse(vals[10]); int BiggestH = int.Parse(vals[11]); bool ReturnBiggest = bool.Parse(vals[12]); bool turnOnStackRoi = bool.Parse(vals[13]); int i = 14; ROI current = new ROI(RoiID, fi.imageCount, shape, type, turnOnStackRoi); current.Width = W; current.Height = H; current.Stack = stack; current.D = d; current.FromT = FromT; current.ToT = ToT; current.FromZ = FromZ; current.ToZ = ToZ; current.biggestH = BiggestH; current.biggestW = BiggestW; current.returnBiggest = ReturnBiggest; if (vals.Length > 15) { try { i++; i++; } catch { } } if (vals.Length > 16) { if (vals[i].StartsWith("Comment=")) { current.Comment = vals[i].Replace("Comment=", ""); i++; } } setLocationFromHistory(current, vals, i); return(current); }
private static void setLocationFromHistory(ROI roi, string[] vals, int n) { Point[][] points = new Point[vals.Length - n][]; for (int i = n, frame = 0; i < vals.Length; i++, frame++) { string[] row = vals[i].Split(new string[] { "\t" }, StringSplitOptions.None); List <Point> rowFinal = new List <Point>(); if (row.Length > 1) { for (int x = 0, y = 1; y < row.Length; x += 2, y += 2) { rowFinal.Add(new Point(int.Parse(row[x]), int.Parse(row[y]))); } } points[frame] = rowFinal.ToArray(); } roi.SetLocationAll(points); }
private static void roi_new(string val, TifFileInfo fi) { string[] vals = val.Substring(8, val.Length - 9).Split(new string[] { "," }, StringSplitOptions.None); int chanel = Convert.ToInt32(vals[0]); int RoiID = Convert.ToInt32(vals[1]); string RoiInfo = vals[2]; ROI current = CreateFromHistory(RoiID, RoiInfo, fi); if (fi.roiList[chanel] == null) { fi.roiList[chanel] = new List <ROI>(); } fi.roiList[chanel].Add(current); if (fi.ROICounter <= RoiID) { fi.ROICounter = RoiID + 1; } }
private string roi_getAllLocation() { ROI roi = this; Point[][] loc = roi.GetLocationAll(); string[] vals = new string[loc.Length]; //foreach (Point[] pList in loc) Parallel.For(0, loc.Length, i => { Point[] pList = loc[i]; if (pList != null) { foreach (Point p in pList) { vals[i] += p.X.ToString() + "\t" + p.Y.ToString() + "\t"; } } }); return(string.Join("\n", vals)); }
public ROI Duplicate() { ROI newRoi = new ROI(ID, 1, shape, type, turnOnStackRoi); newRoi.Comment = Comment; newRoi.W = W; newRoi.H = H; newRoi.Stack = stack; newRoi.D = d; newRoi.firstTFrame = firstTFrame; newRoi.lastTFrame = lastTFrame; newRoi.firstZFrame = firstZFrame; newRoi.lastZFrame = lastZFrame; newRoi.SetLocationAll(this.GetLocationAll()); return(newRoi); }
private void Node_DoubleClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode n = e.Node; if (n == null || n.Tag == null) { return; } tv.SelectedNode = e.Node; ROI roi = (ROI)n.Tag; if (roi == null) { return; } if (n.Text.IndexOf("Layer") > -1) { int ind = int.Parse(n.Text.Substring(n.Text.LastIndexOf("r") + 1, n.Text.Length - n.Text.LastIndexOf("r") - 1)) - 1; roi.expanded[ind] = !roi.expanded[ind]; } }
private ROI CellToolDKtoROI(CellToolDK.ROI roi) { ROI newRoi = new ROI(roi.getID, 1, roi.Shape, roi.Type, roi.turnOnStackRoi); newRoi.Checked = roi.Checked; newRoi.Comment = roi.Comment; newRoi.Width = roi.Width; newRoi.Height = roi.Height; newRoi.Stack = roi.Stack; newRoi.D = roi.D; newRoi.FromT = roi.FromT; newRoi.ToT = roi.ToT; newRoi.FromZ = roi.FromZ; newRoi.ToZ = roi.ToZ; newRoi.SetLocationAll(roi.GetLocationAll()); return(newRoi); }
public double Calculate(int c, int row, ROI roi, List <ROI> roiList, TifFileInfo fi, int position = 0) { { #region parameters ROI curRoi; int curPosition, curRow; for (int i = 0; i < parameters.Count; i++) { if (parameters[i][1] != "") { int ind = int.Parse(parameters[i][1]); if (!(roiList.Count > ind)) { return(0); } curRoi = roiList[ind]; } else { curRoi = roi; } if (parameters[i][3] != "") { curRow = int.Parse(parameters[i][3]) * fi.sizeC + c; if (curRoi.Results == null || !(curRoi.Results.Length > curRow)) { return(0); } } else { curRow = row; } if (parameters[i][2] != "" && parameters[i][2] != "0") { curPosition = int.Parse(parameters[i][2]) * 4; int boolInd = 1 + (int.Parse(parameters[i][2]) - 1) * 4; double val1 = 0; int fact = 0; if (curRoi.Shape == 0 || curRoi.Shape == 1) { for (int i1 = curPosition + int.Parse(parameters[i][0]); i1 < curPosition + 16; i1 += 4) { if (curRoi.ChartUseIndex.Length > boolInd && curRoi.ChartUseIndex[boolInd] == true) { if (i1 < curRoi.Results[curRow].Length) { if (parameters[i][0] == "1" || parameters[i][0] == "0") { val1 += curRoi.Results[curRow][i1]; } else if (parameters[i][0] == "3" && val1 < curRoi.Results[curRow][i1]) { val1 = curRoi.Results[curRow][i1]; } else if (parameters[i][0] == "2" && (val1 == 0 || val1 > curRoi.Results[curRow][i1])) { val1 = curRoi.Results[curRow][i1]; } } fact++; } if (!(curRoi.ChartUseIndex.Length > boolInd)) { return(0); } boolInd++; } } if (fact > 0 && parameters[i][0] == "1") { val1 /= fact; } e.Parameters[parameters[i][4]] = val1; } else if (parameters[i][2] != "" && parameters[i][2] == "0") { curPosition = int.Parse(parameters[i][0]); if (curPosition < curRoi.Results[curRow].Length) { e.Parameters[parameters[i][4]] = curRoi.Results[curRow][curPosition]; } else { return(0); } } else { curPosition = position + int.Parse(parameters[i][0]); if (curPosition < curRoi.Results[curRow].Length) { e.Parameters[parameters[i][4]] = curRoi.Results[curRow][curPosition]; } else { return(0); } } } #endregion parameters double val = 0; //double.TryParse((new Expression("10.01+10").Evaluate()).ToString(),out val); double.TryParse((e.Evaluate()).ToString(), out val); return(val); } }
public string ErrorCheck(int c, ROI roi, List <ROI> roiList, TifFileInfo fi, int position = 0) { { #region parameters ROI curRoi; int curPosition, curRow; for (int i = 0; i < parameters.Count; i++) { if (parameters[i][1] != "") { int ind = int.Parse(parameters[i][1]); if (!(roiList.Count > ind)) { return("There is no roi " + (ind + 1).ToString()); } curRoi = roiList[ind]; } else { curRoi = roi; } if (parameters[i][3] != "") { curRow = int.Parse(parameters[i][3]) * fi.sizeC + c; if (curRoi.Results == null || !(curRoi.Results.Length > curRow)) { return("Row " + curRow.ToString() + "is not avaliable in roi:\n" + curRoi.Text); } } else { curRow = 0; } if (parameters[i][2] != "" && parameters[i][2] != "0") { curPosition = int.Parse(parameters[i][2]) * 4; int boolInd = 1 + (int.Parse(parameters[i][2]) - 1) * 4; if (curRoi.Shape == 0 || curRoi.Shape == 1) { for (int i1 = curPosition + int.Parse(parameters[i][0]); i1 < curPosition + 16; i1 += 4) { if (!(curRoi.ChartUseIndex.Length > boolInd)) { return("Missing Layer: " + curRoi.Text); } boolInd++; } } } else if (parameters[i][2] != "" && parameters[i][2] == "0") { curPosition = int.Parse(parameters[i][0]); if (!(curPosition < curRoi.Results[curRow].Length)) { return(""); } } else { curPosition = position + int.Parse(parameters[i][0]); if (!(curPosition < curRoi.Results[curRow].Length)) { return(""); } } } #endregion parameters return(""); } }
private void AsignColorToRoi(ROI roi, List <ROI> roiList) { if (roi.expanded == null) { roi.expanded = new bool[roi.Stack]; for (int i = 0; i < roi.expanded.Length; i++) { roi.expanded[i] = true; } } else if (roi.expanded.Length < roi.Stack) { bool[] b = new bool[roi.Stack]; for (int i = 0; i < b.Length; i++) { b[i] = true; } Array.Copy(roi.expanded, b, roi.expanded.Length); roi.expanded = b; } else if (roi.expanded.Length > roi.Stack) { bool[] b = new bool[roi.Stack]; Array.Copy(roi.expanded, b, roi.Stack); roi.expanded = b; } if (roi.colors != null && roi.colors.Length == 1 + roi.Stack && roi.ChartUseIndex != null && roi.ChartUseIndex.Length == 1 + roi.Stack * 4) { return; } if (roi.colors == null) { roi.colors = new Color[1 + roi.Stack]; } if (roi.ChartUseIndex == null) { roi.ChartUseIndex = new bool[1 + roi.Stack * 4]; } if (roi.colors.Length == 1 + roi.Stack) { for (int i = 0; i < roi.colors.Length; i++) { roi.colors[i] = FindColor(roiList); } } else if (roi.colors.Length < 1 + roi.Stack) { List <Color> cols = new List <Color>(); foreach (Color col in roi.colors) { cols.Add(col); } for (int i = cols.Count - 1; i < 1 + roi.Stack; i++) { cols.Add(FindColor(roiList)); roi.colors = cols.ToArray(); } } else if (roi.colors.Length > 1 + roi.Stack) { Color[] cols = new Color[1 + roi.Stack]; Array.Copy(roi.colors, cols, 1 + roi.Stack); roi.colors = cols; } if (roi.ChartUseIndex.Length == 1 + roi.Stack * 4) { for (int i = 0; i < roi.ChartUseIndex.Length; i++) { roi.ChartUseIndex[i] = true; } } else if (roi.ChartUseIndex.Length < 1 + roi.Stack * 4) { List <bool> ChartUseIndex = new List <bool>(); foreach (bool b in roi.ChartUseIndex) { ChartUseIndex.Add(b); } for (int i = ChartUseIndex.Count - 1; i < 1 + roi.Stack * 4; i++) { ChartUseIndex.Add(true); } roi.ChartUseIndex = ChartUseIndex.ToArray(); } else if (roi.ChartUseIndex.Length > 1 + roi.Stack * 4) { bool[] b = new bool[1 + roi.Stack * 4]; Array.Copy(roi.ChartUseIndex, b, b.Length); roi.ChartUseIndex = b; } }
private void node_Check(object sender, TreeViewEventArgs e) { TreeNode n = e.Node; if (n == null) { return; } if (!suppressCheck) { suppressCheck = true; tv.SelectedNode = e.Node; ROI roi = (ROI)n.Tag; if (roi == null) { TreeNode parent = n.Parent; roi = (ROI)parent.Tag; int ind = 1 + 4 * (int.Parse(parent.Text.Substring(parent.Text.LastIndexOf("r") + 1 , parent.Text.Length - parent.Text.LastIndexOf("r") - 1)) - 1) + parent.Nodes.IndexOf(n); IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); roi.ChartUseIndex[ind] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); } else if (n.Text.IndexOf("Layer") > -1) { int ind = 1 + 4 * (int.Parse(n.Text.Substring(n.Text.LastIndexOf("r") + 1, n.Text.Length - n.Text.LastIndexOf("r") - 1)) - 1); IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); roi.ChartUseIndex[ind] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); ind++; IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); roi.ChartUseIndex[ind] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); ind++; IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); roi.ChartUseIndex[ind] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); ind++; IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); roi.ChartUseIndex[ind] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + roi.ChartUseIndex[ind].ToString() + ")"); ind++; } else { IA.AddToHistoryOld("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + ",0," + roi.ChartUseIndex[0].ToString() + ")"); roi.ChartUseIndex[0] = n.Checked; IA.AddToHistoryNew("Chart.SetSeriesChecked(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + ",0," + roi.ChartUseIndex[0].ToString() + ")"); } IA.ReloadImages(); suppressCheck = false; } }
private void Node_Click(object sender, TreeNodeMouseClickEventArgs e) { if (MouseButtons.Right != e.Button) { return; } tv.SelectedNode = e.Node; TreeNode n = e.Node; if (n == null || n.Tag == null) { return; } ROI roi = (ROI)n.Tag; if (roi == null) { roi = (ROI)n.Parent.Tag; } int ind = 0; if (n.Text.IndexOf("Layer") > -1) { ind = int.Parse(n.Text.Substring(n.Text.LastIndexOf("r") + 1, n.Text.Length - n.Text.LastIndexOf("r") - 1)); } //ColorBrowser ColorDialog colorDialog1 = new ColorDialog(); colorDialog1.AllowFullOpen = true; colorDialog1.AnyColor = true; colorDialog1.FullOpen = true; colorDialog1.Color = roi.colors[ind]; //set Custom Colors if (IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex] != "@") { List <int> colorsList = new List <int>(); foreach (string j in IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex] .Split(new[] { "\t" }, StringSplitOptions.None)) { colorsList.Add(int.Parse(j)); } colorDialog1.CustomColors = colorsList.ToArray(); } // Show the color dialog. DialogResult result = colorDialog1.ShowDialog(); //Copy Custom Colors int[] colors = (int[])colorDialog1.CustomColors.Clone(); string txt = "@"; if (colors.Length > 0) { txt = colors[0].ToString(); for (int j = 1; j < colors.Length; j++) { txt += "\t" + colors[j].ToString(); } } IA.settings.CustomColors[IA.FileBrowser.ActiveAccountIndex] = txt; IA.settings.Save(); if (result == DialogResult.OK) { IA.AddToHistoryOld("Chart.SetSeriesColor(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + ColorTranslator.ToHtml(roi.colors[ind]) + ")"); roi.colors[ind] = colorDialog1.Color; IA.AddToHistoryNew("Chart.SetSeriesColor(" + GetChanel(roi).ToString() + "," + roi.getID.ToString() + "," + ind.ToString() + "," + ColorTranslator.ToHtml(colorDialog1.Color) + ")"); foreach (Color col in RefColors) { if (colorDialog1.Color == col) { IA.ReloadImages(); return; } } RefColors.Add(colorDialog1.Color); createImagesFortTV(colorDialog1.Color); IA.ReloadImages(); } }
private void CellToolDKtoFI(CellToolDK.TifFileInfo fi, TifFileInfo oldFI) { if (fi == null) { oldFI = null; return; } TifFileInfo newFI = oldFI; newFI.zoom = fi.zoom; newFI.Xposition = fi.Xposition; newFI.Yposition = fi.Yposition; //Chart newFI.xAxisTB = fi.xAxisTB; newFI.yAxisTB = fi.yAxisTB; //Tracking newFI.tracking_MaxSize = fi.tracking_MaxSize; newFI.tracking_MinSize = fi.tracking_MinSize; newFI.tracking_Speed = fi.tracking_Speed; /// <summary> /// Segmentation /// </summary> //filter history newFI.FilterHistory = fi.FilterHistory; //controls newFI.DataSourceInd = fi.DataSourceInd; newFI.SegmentationProtocol = fi.SegmentationProtocol; newFI.SegmentationCBoxIndex = fi.SegmentationCBoxIndex; newFI.thresholdsCBoxIndex = fi.thresholdsCBoxIndex; newFI.sumHistogramChecked = fi.sumHistogramChecked; //spotdetector controls newFI.SpotThresh = fi.SpotThresh; newFI.SpotColor = fi.SpotColor; newFI.RefSpotColor = fi.RefSpotColor; newFI.SelectedSpotThresh = fi.SelectedSpotThresh; newFI.typeSpotThresh = fi.typeSpotThresh; newFI.SpotTailType = fi.SpotTailType; newFI.spotSensitivity = fi.spotSensitivity; //specific values newFI.thresholds = fi.thresholds; newFI.thresholdValues = fi.thresholdValues; newFI.thresholdColors = fi.thresholdColors; newFI.RefThresholdColors = fi.RefThresholdColors; //BandC newFI.autoDetectBandC = fi.autoDetectBandC; newFI.applyToAllBandC = fi.applyToAllBandC; // newFI.selectedPictureBoxColumn = fi.selectedPictureBoxColumn; //History newFI.History = fi.History; newFI.HistoryPlace = fi.HistoryPlace; newFI.undo = fi.undo; newFI.redo = fi.redo; newFI.delHist = fi.delHist; //info var newFI.frame = fi.frame; newFI.zValue = fi.zValue; newFI.cValue = fi.cValue; newFI.original = fi.original; //Not available newFI.loaded = fi.loaded; newFI.available = fi.available; newFI.selected = fi.selected; newFI.openedImages = fi.openedImages; //tif image newFI.image8bit = fi.image8bit; newFI.image16bit = fi.image16bit; newFI.image8bitFilter = fi.image8bitFilter; newFI.image16bitFilter = fi.image16bitFilter; //tif tags newFI.Dir = fi.Dir; newFI.seriesCount = fi.seriesCount; newFI.imageCount = fi.imageCount; newFI.sizeX = fi.sizeX; newFI.sizeY = fi.sizeY; newFI.sizeZ = fi.sizeZ; newFI.umZ = fi.umZ; newFI.umXY = fi.umXY; newFI.sizeC = fi.sizeC; newFI.sizeT = fi.sizeT; newFI.bitsPerPixel = fi.bitsPerPixel; newFI.dimensionOrder = fi.dimensionOrder; newFI.pixelType = fi.pixelType; newFI.FalseColored = fi.FalseColored; newFI.isIndexed = fi.isIndexed; newFI.MetadataComplete = fi.MetadataComplete; newFI.DatasetStructureDescription = fi.DatasetStructureDescription; newFI.LutList = fi.LutList; newFI.TimeSteps = fi.TimeSteps; newFI.Micropoint = fi.Micropoint; //Metadata protocol info newFI.FileDescription = fi.FileDescription; newFI.xCompensation = fi.xCompensation; newFI.yCompensation = fi.yCompensation; //properties newFI.histogramArray = fi.histogramArray; newFI.MinBrightness = fi.MinBrightness; newFI.MaxBrightness = fi.MaxBrightness; newFI.adjustedLUT = fi.adjustedLUT; //RoiManager newFI.roiList = new List <ROI> [fi.roiList.Length]; for (int c = 0; c < fi.roiList.Length; c++) { if (fi.roiList[c] != null) { newFI.roiList[c] = new List <ROI>(); foreach (CellToolDK.ROI roi in fi.roiList[c]) { ROI newROI = CellToolDKtoROI(roi); newFI.roiList[c].Add(newROI); RoiMeasure.Measure(newROI, newFI, c, IA); } } } newFI.ROICounter = fi.ROICounter; }