Skip to content

Commit d6399b4

Browse files
committed
output file function: DONE
1 parent ca36887 commit d6399b4

11 files changed

Lines changed: 183 additions & 99 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
- [x] load imglist -> disable load img button
1010
- [x] one click after load -> disable load annotation button
1111
- [x] load annotation -> disable load annotatino button
12-
- [ ] output file function
12+
- [x] output file function

src/hk/microos/data/Ellipse.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Ellipse {
77
private ArrayList<Point_> keyPts = new ArrayList<>(); // 3 key points + 1
88
// center
99
public double major, minor, angle, x, y; // half mj mi
10-
10+
public double offsetX=0, offsetY=0;
1111
public Ellipse(ArrayList<Double> v) {
1212
this.major = v.get(0);
1313
this.minor = v.get(1);
@@ -48,7 +48,10 @@ public Ellipse(Point_ mjA, Point_ mjB, Point_ miC) {
4848
keyPts.add(miC);
4949
keyPts.add(new Point_(this.x, this.y));
5050
}
51-
51+
public void setOffsetForTableDisplay(double ofx, double ofy){
52+
this.offsetX = ofx;
53+
this.offsetY = ofy;
54+
}
5255
public ArrayList<Point_> getKeyPoints() {
5356
return keyPts;
5457
}
@@ -85,10 +88,15 @@ public String toRowFormatString() {
8588
strs[0] = String.format(fmt, this.major);
8689
strs[1] = String.format(fmt, this.minor);
8790
strs[2] = String.format(fmt, this.angle);
88-
strs[3] = String.format(fmt, this.x);
89-
strs[4] = String.format(fmt, this.y);
91+
strs[3] = String.format(fmt, this.x-offsetX);
92+
strs[4] = String.format(fmt, this.y-offsetY);
9093

9194
return String.join(",", strs);
9295
}
96+
public String toOutputFormatString(){
97+
//major minor angle x y 1
98+
String fmt = "%.6f %.6f %.6f %.6f %.6f 1";
99+
return String.format(fmt,this.major, this.minor, this.angle, this.x, this.y);
100+
}
93101

94102
}

src/hk/microos/data/Flags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hk.microos.data;
22

33
public class Flags {
4-
public static boolean GLOABAL_DEBUG = true;
4+
public static boolean GLOABAL_DEBUG = false;
55
public static boolean FUNC_INVOKE_PRINT = true;
66
public static double minStroke = 2;
77
public static double maxStroke = 5;

src/hk/microos/data/LinearLine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public double calY(double X){
3737
public double calX(double Y){
3838
return (Y-this.b)/this.k;
3939
}
40-
public Point_ projectOnLine(double x0, double y0, int minX, int minY, int maxX, int maxY){
40+
public Point_ projectOnLine(double x0, double y0, double minX, double minY, double maxX, double maxY){
4141
if(this.vertical){
4242
return new Point_(this.b, y0);
4343
}

src/hk/microos/data/MyImage.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.ArrayList;
66

77
import hk.microos.tools.ImageTool;
8+
import hk.microos.tools.UniversalTool;
89

910
public class MyImage {
1011
private String path;
@@ -38,8 +39,8 @@ public void setElpsFromString(String s) {
3839
}
3940

4041
public BufferedImage getImage() {
41-
42-
return bi == null ? ImageTool.openImage(new File(path)) : bi;
42+
bi = bi == null ? ImageTool.openImage(new File(path)) : bi;
43+
return bi;
4344
}
4445

4546
public void addElps(Ellipse e) {
@@ -86,7 +87,33 @@ public ArrayList<String> getAllElpsesStrings() {
8687

8788
return strs;
8889
}
89-
90+
public String getOutputString(boolean withBoth){
91+
//imgPath
92+
//detNum
93+
//coord1 1
94+
//coord2 1
95+
//...
96+
97+
ArrayList<Ellipse> elpse4Output = new ArrayList<>();
98+
if(withBoth && elpsesStatic!=null){
99+
elpse4Output.addAll(elpsesStatic);
100+
}
101+
elpse4Output.addAll(elpses);
102+
if(elpse4Output.size() == 0) return "";
103+
StringBuilder sb = new StringBuilder();
104+
sb.append(path+"\n");
105+
sb.append(elpse4Output.size()+"\n");
106+
double[] offset = UniversalTool.getOffset(this);
107+
for(Ellipse e : elpse4Output){
108+
e = e.offset(-offset[0], -offset[1]);
109+
sb.append(e.toOutputFormatString()+"\n");
110+
}
111+
return sb.toString();
112+
113+
114+
115+
116+
}
90117
public String getPath() {
91118
return this.path;
92119
}

src/hk/microos/data/Point_.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,16 @@ public Point_(float x,float y){
1717
public String toString(){
1818
return "("+this.x+", "+this.y+")";
1919
}
20+
// public Point_ add(double x, double y){
21+
// return new Point_(this.x + x, this.y + y);
22+
// }
23+
// public Point_ add(Point_ p){
24+
// return new Point_(this.x + p.x, this.y + p.y);
25+
// }
26+
// public Point_ minus(double x, double y){
27+
// return new Point_(this.x - x, this.y - y);
28+
// }
29+
// public Point_ minu(Point_ p){
30+
// return new Point_(this.x - p.x, this.y - p.y);
31+
// }
2032
}

src/hk/microos/frames/MainFrame.java

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.awt.event.MouseMotionAdapter;
4242
import java.awt.image.BufferedImage;
4343
import java.io.File;
44+
import java.nio.file.PathMatcher;
4445
import java.util.ArrayList;
4546
import java.util.HashMap;
4647

@@ -69,7 +70,7 @@ public class MainFrame extends JFrame {
6970

7071
private int leftTableSelectedRow = -1;
7172
private HashMap<String, MyImage> pathImgPair = null;
72-
private HashMap<String, ArrayList<Ellipse>> pathElpsesPair = null;
73+
private HashMap<String, ArrayList<Ellipse>> pathStaticElpsesPair = null;
7374
private JButton btnReadAnnotations;
7475
private String annotContentPrefix = null;
7576
private String annotContentSuffix = null;
@@ -85,13 +86,13 @@ public void run() {
8586
MainFrame frame = new MainFrame();
8687
// frame.recordedOpenPath =
8788
// System.getProperty("user.home")+"/Desktop";
88-
frame.recordedImgPath =
89-
"/Users/microos/Downloads/originalPics/imgPath.txt";
89+
// frame.recordedImgPath =
90+
// "/Users/microos/Downloads/originalPics/imgPath.txt";
9091

9192
// frame.recordedAnnotPath = System.getProperty("user.home")
9293
// + "/Desktop";
93-
frame.recordedAnnotPath =
94-
"/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt";
94+
// frame.recordedAnnotPath =
95+
// "/Users/microos/Downloads/FDDB-folds/FDDB-fold-05-ellipseList.txt";
9596
frame.setVisible(true);
9697
} catch (Exception e) {
9798
e.printStackTrace();
@@ -243,7 +244,7 @@ void leftTableOnClick(ListSelectionEvent e) {
243244
return;
244245
int id = (int) imgListTH.getValueAt(leftTableSelectedRow, 0);
245246
String path = imgListTH.getBehindRowDataAt(leftTableSelectedRow);
246-
MyImage mim = getMyImageFromPathImgPair(path);
247+
MyImage mim = UniversalTool.getMyImageFromPathImgPair(path,pathImgPair);
247248
boolean changed = imagePanel.setCurrentImage(mim);
248249
// display coords on the right
249250
setRightPanelCoords(mim);
@@ -274,8 +275,8 @@ void setRightPanelCoords(MyImage mim) {
274275
// 1 load static ellipse into the table
275276
// when pathElpsesPair set and
276277
ArrayList<Ellipse> staticElps;
277-
if (pathElpsesPair != null) {
278-
staticElps = pathElpsesPair.get(mim.getPath());
278+
if (pathStaticElpsesPair != null) {
279+
staticElps = pathStaticElpsesPair.get(mim.getPath());
279280
mim.setElpsesStatic(staticElps);
280281
}
281282

@@ -317,14 +318,11 @@ void loadImageList() {
317318
String.format("\"%s\" \ncannot be properly read.", f.getAbsolutePath()).toString(),
318319
"Reading failed", JOptionPane.WARNING_MESSAGE);
319320
} else {
320-
// read successes
321-
// load Images to table
322-
// reset
323-
// pathImgPair = null;
324-
// leftTableSelectedRow = -1;
325-
// imagePanel.reset();
326321

327322
pathImgPair = IOTool.filterImageList(imgList, this);
323+
if(pathImgPair.size() == 0){
324+
return;
325+
}
328326
fillImageNameTable();
329327
leftTableSelectedRow = 0;
330328
imgListTH.setSelectedRow(leftTableSelectedRow);
@@ -370,19 +368,21 @@ void loadAnnotList() {
370368
JOptionPane.showMessageDialog(this,
371369
String.format("\"%s\" \nis not a txt file.", f.getAbsolutePath()).toString(), "Not a txt file",
372370
JOptionPane.WARNING_MESSAGE);
371+
annotContentPrefix = annotContentSuffix = null;
373372
} else {
374373
// read
375374
boolean noError = true;
376375
String errMessage = "";
377376
try {
378-
pathElpsesPair = IOTool.readAnnotationFile(f, annotContentPrefix, annotContentSuffix);
377+
pathStaticElpsesPair = IOTool.readAnnotationFile(f, annotContentPrefix, annotContentSuffix);
379378
} catch (Exception e) {
380-
pathElpsesPair = null;
379+
pathStaticElpsesPair = null;
381380
noError = false;
382381
errMessage = e.getMessage();
383382
}
384383

385384
if (noError == false) {
385+
annotContentPrefix = annotContentSuffix = null;
386386
// parse failed
387387
JOptionPane
388388
.showMessageDialog(this,
@@ -394,10 +394,10 @@ void loadAnnotList() {
394394
//
395395
// // put these annotations to mImg.ellispe_static
396396
for (String p : pathImgPair.keySet()) {
397-
ArrayList<Ellipse> elpses = pathElpsesPair.get(p);
397+
ArrayList<Ellipse> elpses = pathStaticElpsesPair.get(p);
398398
if (elpses != null) {// annotation list contains this
399399
// image's annotations
400-
MyImage mim = getMyImageFromPathImgPair(p);
400+
MyImage mim = UniversalTool.getMyImageFromPathImgPair(p, pathImgPair);
401401
mim.setElpsesStatic(elpses);
402402
// update mark nums
403403
} else {
@@ -415,6 +415,8 @@ void loadAnnotList() {
415415

416416
}
417417
}
418+
}else{
419+
annotContentPrefix = annotContentSuffix = null;
418420
}
419421
}
420422

@@ -444,9 +446,9 @@ void testSetBackgroundImage() {
444446
}
445447

446448
public void marksLoadAnnotationUpdate() {
447-
if (pathElpsesPair == null)
449+
if (pathStaticElpsesPair == null)
448450
return;
449-
for (String p : pathElpsesPair.keySet()) {
451+
for (String p : pathStaticElpsesPair.keySet()) {
450452
int idx = imgListTH.getRowIndexOfValue(p);
451453
MyImage mim = pathImgPair.get(p);
452454
if (idx != -1 && mim != null) {
@@ -476,16 +478,8 @@ public void freezeReadImageListBtn(){
476478
public void freezeReadAnnotationBtn(){
477479
this.btnReadAnnotations.setEnabled(false);
478480
}
479-
MyImage getMyImageFromPathImgPair(String path) {
480-
MyImage img = pathImgPair.get(path);
481-
if (img == null) {
482-
File f = new File(path);
483-
img = new MyImage(f);
484-
pathImgPair.put(path, img);
485-
return img;
486-
} else {
487-
return img;
488-
}
481+
public HashMap<String, MyImage> getPathImgPair(){
482+
return pathImgPair;
489483
}
490484
void outputAnnotations(){
491485
if(pathImgPair == null){
@@ -497,43 +491,16 @@ void outputAnnotations(){
497491
}
498492
//open a chooser
499493
//make it a .txt file
500-
//output only the new Ellipse
494+
// ask: output only the new Ellipse or both new and static
501495

502496
JFileChooser fc = new JFileChooser(recordedSavePath);
503497
// fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
504498
int res = fc.showOpenDialog(this);
505499
if (res == JFileChooser.APPROVE_OPTION) {
506500
File f = fc.getSelectedFile();
507501
recordedImgPath = f.getParent();
508-
if (!IOTool.isTextFile(f)) {
509-
// not a readable text file
510-
JOptionPane.showMessageDialog(this,
511-
String.format("\"%s\" \nis not a txt file.", f.getAbsolutePath()).toString(), "Not a txt file",
512-
JOptionPane.WARNING_MESSAGE);
513-
} else {
514-
// read
515-
ArrayList<String> imgList = IOTool.readText(f);
516-
if (imgList == null) {
517-
// read failed
518-
JOptionPane.showMessageDialog(this,
519-
String.format("\"%s\" \ncannot be properly read.", f.getAbsolutePath()).toString(),
520-
"Reading failed", JOptionPane.WARNING_MESSAGE);
521-
} else {
522-
// read successes
523-
// load Images to table
524-
// reset
525-
// pathImgPair = null;
526-
// leftTableSelectedRow = -1;
527-
// imagePanel.reset();
528-
529-
pathImgPair = IOTool.filterImageList(imgList, this);
530-
fillImageNameTable();
531-
leftTableSelectedRow = 0;
532-
imgListTH.setSelectedRow(leftTableSelectedRow);
533-
freezeReadImageListBtn();
534-
535-
}
536-
}
502+
IOTool.outputEllipse(pathImgPair, f.getAbsolutePath(),pathStaticElpsesPair != null,this);
503+
537504
}
538505
}
539506
}

0 commit comments

Comments
 (0)