1 package com.github.celldynamics.quimp.plugin.protanalysis;
2
3 import java.awt.Point;
4 import java.awt.event.ActionEvent;
5 import java.util.Arrays;
6 import java.util.List;
7 import java.util.regex.Matcher;
8 import java.util.regex.Pattern;
9
10 import com.github.celldynamics.quimp.QParamsQconf;
11 import com.github.celldynamics.quimp.filesystem.QconfLoader;
12 import com.github.celldynamics.quimp.plugin.protanalysis.Prot_Analysis.PointHashSet;
13 import com.github.celldynamics.quimp.plugin.qanalysis.STmap;
14
15 import ij.gui.PointRoi;
16 import ij.gui.Roi;
17 import ij.plugin.frame.RoiManager;
18
19
20
21
22
23
24
25 @SuppressWarnings("serial")
26 public class ActionFromRoi extends ProtAnalysisAbstractAction {
27
28
29
30
31
32
33
34
35 public ActionFromRoi(String name, String desc, ProtAnalysisUi ui) {
36 super(name, desc, ui);
37 }
38
39
40
41
42
43
44
45
46 @Override
47 public void actionPerformed(ActionEvent e) {
48 int modifiers = e.getModifiers();
49 PointHashSet points = ui.getModel().selected;
50 points.clear();
51 RoiManager rm = RoiManager.getRoiManager();
52 QconfLoader qconfLoader = ui.getModel().getQconfLoader();
53 STmap[] stMap = ((QParamsQconf) qconfLoader.getQp()).getLoadedDataContainer().getQState();
54 List<Roi> rois = Arrays.asList(rm.getRoisAsArray());
55 int cellNo = 0;
56
57 if ((modifiers & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) {
58 cellNo = options.selActiveCellMap.getValue();
59 logger.debug("CTRL detected. Import all to current cell: " + cellNo);
60 }
61 for (Roi roi : rois) {
62 if (!(roi instanceof PointRoi)) {
63 logger.warn("ROI " + roi.getName() + " is not PointRoi");
64 }
65
66 if ((modifiers & ActionEvent.CTRL_MASK) != ActionEvent.CTRL_MASK) {
67 if (roi.getName().startsWith(ProtAnalysisOptions.roiPrefix)) {
68 cellNo = stripCellNo(roi.getName());
69 if (cellNo > stMap.length) {
70 continue;
71 }
72 if (cellNo < 0) {
73 logger.warn(
74 "Can not obtain cell index from ROI name: " + roi.getName() + " Assume cell 0");
75 cellNo = 0;
76 }
77 }
78 }
79
80 for (Point p : roi) {
81 int tmpIndex = (int) p.getX();
82 int frame = (int) Math.round(
83 p.getY() * (stMap[cellNo].getT() - 1) / stMap[cellNo].getVerticalResolution());
84
85
86
87
88 try {
89 int x = (int) Math.round(stMap[cellNo].getxMap()[frame][tmpIndex]);
90 int y = (int) Math.round(stMap[cellNo].getyMap()[frame][tmpIndex]);
91 logger.trace("name: " + roi.getName() + " point: " + p + " tmpIndex: " + tmpIndex
92 + " frame: " + frame + " cell: " + cellNo + " x: " + x + " y: " + y);
93 PointCoordsimp/plugin/protanalysis/PointCoords.html#PointCoords">PointCoords point = new PointCoords(new Point(x, y), cellNo, frame);
94 points.addRaw(point);
95 } catch (ArrayIndexOutOfBoundsException ex) {
96 logger.error(
97 "Point " + p + " can not be mapped to array (ArrayIndexOutOfBoundsException)");
98 }
99 }
100
101 }
102 updateCurrentView();
103 }
104
105
106
107
108
109
110
111
112 int stripCellNo(String name) {
113
114 String tmp = name.substring(ProtAnalysisOptions.roiPrefix.length());
115 Pattern p = Pattern.compile("^[\\d]*");
116 Matcher m = p.matcher(tmp);
117 if (m.find()) {
118 return Integer.parseInt(m.group(0));
119 }
120 return -1;
121 }
122
123 }