1 package cz.cuni.amis.pogamut.usar2004.samples.AirScanner;
2
3 import cz.cuni.amis.pogamut.base3d.worldview.object.*;
4 import java.awt.*;
5 import java.awt.geom.Line2D;
6 import java.awt.geom.Point2D;
7 import java.awt.geom.Rectangle2D;
8 import java.awt.image.BufferedImage;
9 import java.io.*;
10 import java.nio.ByteBuffer;
11 import java.util.List;
12 import java.util.*;
13 import java.util.logging.Level;
14 import java.util.logging.Logger;
15 import java.util.zip.GZIPOutputStream;
16 import javax.imageio.ImageIO;
17
18 public class ScanPreview extends javax.swing.JFrame
19 {
20 public void runScanPreview()
21 {
22 setTitle("Scan Preview");
23 setVisible(true);
24 }
25
26
27
28
29 public ScanPreview()
30 {
31 initComponents();
32 data = ToolBox.initArray(startSize, startSize);
33 initBlackImage(tmp);
34 }
35 private int dataArrayXLimit;
36 private int dataArrayYLimit;
37 private int offsetX = 0;
38 private int offsetY = 0;
39 private final int extension = 400;
40 private final int extLimit = 100;
41
42
43
44
45
46
47
48
49
50
51 private boolean keepDataArrayGreat(int x, int y)
52 {
53 if(x > dataArrayXLimit)
54 {
55 tmp = ToolBox.resizeImage(tmp, extension, 0, 0, 0);
56 tmpG = tmp.createGraphics();
57 data = ToolBox.resizeArray(data, extension, 0, 0, 0);
58 dataArrayXLimit = tmp.getWidth() - extLimit;
59 return true;
60 }
61 else if(x < tmp.getWidth() - dataArrayXLimit)
62 {
63 tmp = ToolBox.resizeImage(tmp, extension, 0, extension, 0);
64 tmpG = tmp.createGraphics();
65 data = ToolBox.resizeArray(data, extension, 0, extension, 0);
66 dataArrayXLimit = tmp.getWidth() - extLimit;
67 offsetX += extension;
68 translate.x -= extension;
69 return true;
70 }
71 if(y > dataArrayYLimit)
72 {
73 tmp = ToolBox.resizeImage(tmp, 0, extension, 0, 0);
74 tmpG = tmp.createGraphics();
75 data = ToolBox.resizeArray(data, 0, extension, 0, 0);
76 dataArrayYLimit = tmp.getHeight() - extLimit;
77 return true;
78 }
79 else if(y < tmp.getHeight() - dataArrayYLimit)
80 {
81 tmp = ToolBox.resizeImage(tmp, 0, extension, 0, extension);
82 tmpG = tmp.createGraphics();
83 data = ToolBox.resizeArray(data, 0, extension, 0, extension);
84 dataArrayYLimit = tmp.getHeight() - extLimit;
85 offsetY += extension;
86 translate.y -= extension;
87 return true;
88 }
89 return false;
90 }
91
92 private void initBlackImage(BufferedImage tmp)
93 {
94 tmpG.setColor(Color.BLACK);
95 tmpG.fillRect(0, 0, tmp.getWidth(), tmp.getHeight());
96
97 offsetX = tmp.getWidth() / 2;
98 offsetY = tmp.getHeight() / 2;
99 dataArrayXLimit = tmp.getWidth() - extLimit;
100 dataArrayYLimit = tmp.getHeight() - extLimit;
101 this.translate = new Point(this.getWidth() / 2 - offsetX, this.getHeight() / 2 - offsetY);
102 }
103
104
105
106
107
108
109 @SuppressWarnings("unchecked")
110
111 private void initComponents() {
112
113 jLabel1 = new javax.swing.JLabel();
114
115 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
116 setTitle("Scan viewer");
117 setBackground(new java.awt.Color(51, 51, 51));
118 setForeground(java.awt.Color.white);
119 addWindowListener(new java.awt.event.WindowAdapter() {
120 public void windowClosing(java.awt.event.WindowEvent evt) {
121 formWindowClosing(evt);
122 }
123 });
124 addKeyListener(new java.awt.event.KeyAdapter() {
125 public void keyPressed(java.awt.event.KeyEvent evt) {
126 formKeyPressed(evt);
127 }
128 });
129
130 jLabel1.setBackground(new java.awt.Color(255, 255, 255));
131 jLabel1.setText("jLabel1");
132
133 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
134 getContentPane().setLayout(layout);
135 layout.setHorizontalGroup(
136 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addGroup(layout.createSequentialGroup()
138 .addContainerGap(796, Short.MAX_VALUE)
139 .addComponent(jLabel1)
140 .addGap(227, 227, 227))
141 );
142 layout.setVerticalGroup(
143 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addGroup(layout.createSequentialGroup()
145 .addContainerGap()
146 .addComponent(jLabel1)
147 .addContainerGap(717, Short.MAX_VALUE))
148 );
149
150 pack();
151 }
152
153 private void formKeyPressed(java.awt.event.KeyEvent evt)
154 {
155 switch(evt.getKeyCode())
156 {
157 case 37:
158 translate.x += 10;
159 break;
160 case 39:
161 translate.x -= 10;
162 break;
163 case 40:
164 translate.y -= 10;
165 break;
166 case 38:
167 translate.y += 10;
168 break;
169 }
170 }
171
172
173
174
175
176
177 private void formWindowClosing(java.awt.event.WindowEvent evt)
178 {
179 int counter = 0;
180 File directory = new File(System.getProperty("user.home") + "\\Desktop\\USAR_Scans\\");
181 File file;
182 do
183 {
184 if(!directory.exists())
185 {
186 directory.mkdir();
187 }
188 file = new File(System.getProperty("user.home") + "\\Desktop\\USAR_Scans\\img" + ((counter < 10)?"0" + counter:counter) + ".png");
189 counter++;
190 }
191 while(file.exists());
192 saveImage(createImage(file.getAbsolutePath()), file);
193 }
194 private final int border = 20;
195
196
197
198
199
200
201 private int getDataLeftMargin()
202 {
203 for(int i = border; i < data.length; i++)
204 {
205 for(int j = 0; j < data[i].length; j++)
206 {
207 if(data[i][j] != Double.MIN_VALUE)
208 {
209 return i - border;
210 }
211 }
212 }
213 return data.length / 2;
214 }
215
216
217
218
219
220
221 private int getDataRightMargin()
222 {
223 for(int i = data.length - border - 1; i >= 0; i--)
224 {
225 for(int j = 0; j < data[i].length; j++)
226 {
227 if(data[i][j] != Double.MIN_VALUE)
228 {
229 return i + border;
230 }
231 }
232 }
233 return data[0].length / 2;
234 }
235
236
237
238
239
240
241 private int getDataTopMargin()
242 {
243 for(int i = border; i < data[0].length; i++)
244 {
245 for(int j = 0; j < data.length; j++)
246 {
247 if(data[j][i] != Double.MIN_VALUE)
248 {
249 return i - border;
250 }
251 }
252 }
253 return data.length / 2;
254 }
255
256
257
258
259
260
261 private int getDataBottomMargin()
262 {
263 for(int i = data[0].length - border - 1; i >= 0; i--)
264 {
265 for(int j = 0; j < data.length; j++)
266 {
267 if(data[j][i] != Double.MIN_VALUE)
268 {
269 return i + border;
270 }
271 }
272 }
273 return data.length / 2;
274 }
275 private final int infoPanelWidth = 280;
276
277
278
279
280
281
282
283
284
285
286
287 private boolean datFile = false;
288
289
290
291
292
293
294 private BufferedImage createImage(String path)
295 {
296 int left = getDataLeftMargin();
297 int top = getDataTopMargin();
298 int width = Math.max(getDataRightMargin() - left + 1, minWidth);
299 int height = Math.max(getDataBottomMargin() - top + 1, minHeight);
300 tmpG.drawRect(left, top, width - 1, height - 1);
301
302 BufferedImage img = new BufferedImage(width + infoPanelWidth, height, BufferedImage.TYPE_INT_ARGB);
303 Graphics2D g = img.createGraphics();
304 Graphics gr = g.create();
305
306 gr.setColor(Color.BLACK);
307 gr.fillRect(0, 0, img.getWidth(), img.getHeight());
308
309
310
311 ByteBuffer buf = ByteBuffer.allocate((width + 1) * (height + 1) * 8);
312
313
314 double shift = 0 - dMin;
315 double scale = 255 / (shift + dMax / 2);/
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 private void drawHistogram(Graphics2D g)
375 {
376 int max = ToolBox.getMax(histogram);
377
378 g.setPaint(Color.GREEN);
379 Shape rect = new Rectangle2D.Double(9, 9, 257, 102);
380 g.fill(rect);
381 for(int i = 0; i < histogram.length; i++)
382 {
383 int count = histogram[i];
384 drawImageLine(i + 10, 10, i + 10, (double) count * 100 / (double) max + 10, new Color(i, i, i), g);
385 }
386 }
387
388
389
390
391
392
393 private void drawLegend(Graphics g)
394 {
395 Location corner = new Location(20, 140);
396 int spacing = 20;
397 int yOffset = 0;
398 drawStartPose(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
399 drawString(g, "Landing/Recharging Point", (int) corner.x + spacing, (int) corner.y + yOffset);
400 yOffset += 25;
401 drawRechargePoint(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
402 drawString(g, "Recharge Needed Location", (int) corner.x + spacing, (int) corner.y + yOffset);
403 yOffset += 25;
404 drawDiversion(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
405 drawString(g, "Diversion Point", (int) corner.x + spacing, (int) corner.y + yOffset);
406 yOffset += 25;
407 drawHighRisk(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
408 drawString(g, "HighRisk Situation", (int) corner.x + spacing, (int) corner.y + yOffset);
409 yOffset += 25;
410 drawLowRisk(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
411 drawString(g, "LowRisk Situation", (int) corner.x + spacing, (int) corner.y + yOffset);
412 yOffset += 25;
413 drawPathDot(g, Location.ZERO, (int) corner.x, (int) corner.y + yOffset);
414 drawString(g, "Robot Path Point", (int) corner.x + spacing, (int) corner.y + yOffset);
415 yOffset += 25;
416 g.setColor(Color.WHITE);
417 drawData(g, (int) corner.x + spacing, (int) corner.y + yOffset);
418
419 }
420
421
422
423
424
425
426
427
428 private void drawData(Graphics g, int x, int y)
429 {
430 g.setColor(Color.WHITE);
431 for(String line : postInfo.split("\n"))
432 {
433 g.drawString(line, x, y += g.getFontMetrics().getHeight());
434 }
435 }
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 private void drawControlPoints(Graphics g, int offsetX, int offsetY)
454 {
455 for(Location location : robotRechargePoints)
456 {
457 drawRechargePoint(g, location, offsetX, offsetY);
458 }
459 for(Location location : robotDiversions)
460 {
461 drawDiversion(g, location, offsetX, offsetY);
462 }
463 for(Location location : robotStartPoints)
464 {
465 drawStartPose(g, location, offsetX, offsetY);
466 }
467 for(Location location : robotLowRiskPoints)
468 {
469 drawLowRisk(g, location, offsetX, offsetY);
470 }
471 for(Location location : robotHighRiskPoints)
472 {
473 drawHighRisk(g, location, offsetX, offsetY);
474 }
475 }
476
477
478
479
480
481
482
483
484 private void drawRobotPath(Graphics g, int offsetX, int offsetY)
485 {
486 for(Location location : robotPath)
487 {
488 drawPathDot(g, location, offsetX, offsetY);
489 }
490 }
491
492
493
494
495
496
497
498 public void saveImage(BufferedImage img, File outputfile)
499 {
500 try
501 {
502 if(outputfile.createNewFile())
503 {
504 ImageIO.write(img, "png", outputfile);
505 }
506 else
507 {
508 System.out.println("Couldnt creaate file");
509 }
510 }
511 catch(IOException e)
512 {
513 System.out.println(e.getCause());
514 }
515 }
516 private final int minWidth = 200;
517 private final int minHeight = 350;
518 int[] histogram = new int[256];
519 double dMax = Double.MIN_VALUE;
520 double dMin = Double.MAX_VALUE;
521 public Point translate;
522 public Record record;
523 public Record recordPrev;
524 Rotation rot;
525 Rotation rotPrev;
526 Location loc;
527 Location locPrev;
528 int offset = 0;
529 List<Obstacle1> obstacles = new ArrayList<Obstacle1>();
530 List<Location> robotPath = new ArrayList<Location>();
531 List<Location> robotDiversions = new ArrayList<Location>();
532 List<Location> robotRechargePoints = new ArrayList<Location>();
533 List<Location> robotStartPoints = new ArrayList<Location>();
534 List<Location> robotHighRiskPoints = new ArrayList<Location>();
535 List<Location> robotLowRiskPoints = new ArrayList<Location>();
536 Collection<Double> sonars;
537 private String actInfo = "";
538 private String postInfo = "";
539 private final double rangeLimit = 19.9;
540 private final int drawScale = 6;
541 private final int panelWidth = 45 * drawScale;
542
543 private final Point2D pos = new Point((int) (panelWidth / 2), 50);
544 private final List<Double> highRisk = new ArrayList<Double>()
545 {
546
547 {
548 add(0.47d);
549 add(0.61d);
550 add(0.86d);
551 add(1.22d);
552 add(1.5d);
553 add(1.22d);
554 add(0.86d);
555 add(0.61d);
556 add(0.47d);
557 }
558 };
559 private final List<Double> lowRisk = new ArrayList<Double>()
560 {
561
562 {
563 add(1.57d);
564 add(1.91d);
565 add(2.72d);
566 add(3.5d);
567 add(4.5d);
568 add(3.5d);
569 add(2.72d);
570 add(1.91d);
571 add(1.57d);
572 }
573 };
574 private final int startSize = 500;
575 BufferedImage tmp = new BufferedImage(startSize, startSize, BufferedImage.TYPE_INT_ARGB);
576 Graphics2D tmpG = tmp.createGraphics();
577 double[][] data;
578
579
580
581
582
583
584
585
586
587
588 private Color getScanColor(double range, int index)
589 {
590 if(index >= offset + 85 && index <= offset + 95)
591 {
592 return Color.MAGENTA;
593 }
594 else if(range <= rangeLimit)
595 {
596 return Color.BLUE;
597 }
598 else
599 {
600 return Color.RED;
601 }
602 }
603 Image backBuffer;
604
605
606
607
608 private void checkOffscreenImage()
609 {
610 Dimension d = getSize();
611 if(backBuffer == null || backBuffer.getWidth(null) != d.width
612 || backBuffer.getHeight(null) != d.height)
613 {
614 backBuffer = createImage(d.width, d.height);
615 }
616 }
617
618
619
620
621
622
623 @Override
624 public void paint(Graphics sharpGraphics)
625 {
626
627 Dimension d = getSize();
628 checkOffscreenImage();
629 Graphics backGraphics = backBuffer.getGraphics();
630 backGraphics.setColor(getBackground());
631 backGraphics.fillRect(0, 0, d.width, d.height);
632
633 paintSituation(backGraphics);
634
635 sharpGraphics.drawImage(backBuffer, 0, 0, null);
636 }
637
638
639
640
641
642
643
644
645
646
647 private void paintSituation(Graphics g)
648 {
649 if(recordPrev == null)
650 {
651 return;
652 }
653 g.drawImage(tmp, translate.x, translate.y, null);
654
655
656 g.setColor(Color.white);
657 g.fillRect(0, 0, panelWidth, getSize().height);
658
659 drawSonars(g);
660 drawInfo(g, 20, 450);
661
662
663 double angle = 90 + ((record.getFOV() / 2 - rot.roll) * 180 / Math.PI);
664 double anglePrev = 90 + ((record.getFOV() / 2 - rotPrev.roll) * 180 / Math.PI);
665
666 if(Math.abs(angle - anglePrev) > 180)
667 {
668 anglePrev *= -1;
669 }
670
671 for(int i = 0; i < record.getRanges().size(); i++)
672 {
673 double range = record.getRanges().get(i);
674 double rangePrev = recordPrev.getRanges().get(i);
675 double value;
676 if(range < rangeLimit && rangePrev < rangeLimit)
677 {
678 value = (range + rangePrev) / 2;
679 }
680 else if(range < rangeLimit)
681 {
682 value = range;
683 }
684 else
685 {
686 value = rangePrev;
687 }
688
689 issueRay(g, i, range, angle, loc, rot);
690 issueRay(g, i, value, (anglePrev + angle) / 2, getMidPoint(loc, locPrev), getMidTurn(rot, rotPrev));
691 angle -= (record.getFOV() / Math.PI * 180 / record.getRanges().size()) / 2;
692 anglePrev -= (recordPrev.getFOV() / Math.PI * 180 / recordPrev.getRanges().size()) / 2;
693
694 if(i == 0)
695 {
696 continue;
697 }
698
699 angle -= (record.getFOV() / Math.PI * 180 / record.getRanges().size()) / 2;
700 anglePrev -= (recordPrev.getFOV() / Math.PI * 180 / recordPrev.getRanges().size()) / 2;
701
702 range = (record.getRanges().get(i) + record.getRanges().get(i - 1)) / 2;
703 rangePrev = (recordPrev.getRanges().get(i) + recordPrev.getRanges().get(i)) / 2;
704 value = (range + rangePrev) / 2;
705 issueRay(g, i - 1, range, angle, loc, rot);
706 issueRay(g, i - 1, value, (anglePrev + angle) / 2, getMidPoint(loc, locPrev), getMidTurn(rot, rotPrev));
707
708
709
710
711
712
713 }
714
715
716
717 g.setColor(Color.GREEN);
718
719
720
721
722
723
724 }
725
726
727
728
729
730
731
732
733
734
735
736
737
738 public void issueRay(Graphics g, int index, double range, double angle, Location loc, Rotation rot)
739 {
740
741 double x = Math.cos(angle * Math.PI / 180) * range * drawScale;
742 double y = Math.sin(angle * Math.PI / 180) * range * drawScale;
743 double xOffset = Math.sin(rot.pitch) * y;
744 double z = Math.cos(rot.pitch) * y;
745 int height = (int) (loc.z * drawScale - z + 10 * drawScale) * 255 / 20 / (int) drawScale;
746
747
748 Color c = getScanColor(range, index);
749 this.drawLine(g, c, pos.getX(), pos.getY(), (pos.getX() - x), (pos.getY() + y));
750
751
752
753
754
755
756
757
758
759
760
761 height = Math.max(height, 0);
762 height = Math.min(height, 255);
763
764 if(range <= rangeLimit)
765 {
766 this.drawLine(g, new Color(height, height, height), pos.getX() - x, 40 * drawScale, pos.getX() - x, 40 * drawScale - (loc.z * drawScale - z));
767 this.drawPoint(tmpG, new Color(height, height, height),
768 loc.x * drawScale - Math.sin(rot.yaw) * (x) - Math.cos(rot.yaw) * xOffset + offsetX,
769 loc.y * drawScale + Math.cos(rot.yaw) * (x) - Math.sin(rot.yaw) * xOffset + offsetY);
770
771
772
773
774
775
776
777
778 setDataAt(loc.x * drawScale - Math.sin(rot.yaw) * (x) - Math.cos(rot.yaw) * xOffset + offsetX,
779 loc.y * drawScale + Math.cos(rot.yaw) * (x) - Math.sin(rot.yaw) * xOffset + offsetY, loc.z * drawScale - z);
780
781 }
782 }
783
784
785
786
787
788
789
790
791 private Location getMidPoint(Location locA, Location locB)
792 {
793 double x = locA.x + locB.x;
794 double y = locA.y + locB.y;
795 double z = locA.z + locB.z;
796 return new Location(x / 2, y / 2, z / 2);
797 }
798
799
800
801
802
803
804
805
806
807 private double getMidAngle(double value1, double value2)
808 {
809 double val;
810 if(value1 > 6 && value2 < 0.28)
811 {
812 val = (value1 - 2 * Math.PI + value2) / 2;
813 }
814 else if(value2 > 6 && value1 < 0.28)
815 {
816 val = (value2 - 2 * Math.PI + value1) / 2;
817 }
818 else
819 {
820 val = (value1 + value2) / 2;
821 }
822
823 if(val < 0)
824 {
825 val += 2 * Math.PI;
826 }
827 return val;
828 }
829
830
831
832
833
834
835
836
837 private Rotation getMidTurn(Rotation rotA, Rotation rotB)
838 {
839 double pitch = getMidAngle(rotA.pitch, rotB.pitch);
840 double yaw = getMidAngle(rotA.yaw, rotB.yaw);
841 double roll = getMidAngle(rotA.roll, rotB.roll);
842 return new Rotation(pitch, yaw, roll);
843 }
844
845
846
847
848
849
850
851
852 private void drawInfo(Graphics g, int x, int y)
853 {
854 g.setColor(Color.BLACK);
855 for(String line : actInfo.split("\n"))
856 {
857 g.drawString(line, x, y += g.getFontMetrics().getHeight());
858 }
859 }
860
861
862
863
864
865
866
867
868
869 private Color convertToGray(double data, double offset, double scale)
870 {
871 int height = (int) ((offset + data) * scale);
872 height = Math.max(0, height);
873 height = Math.min(255, height);
874 histogram[height]++;
875 return new Color(height, height, height);
876 }
877
878
879
880
881
882
883
884
885
886 private void setDataAt(double x, double y, double data)
887 {
888 if(data > dMax)
889 {
890 dMax = data;
891 }
892 if(data < dMin)
893 {
894 dMin = data;
895 }
896
897
898 if(this.data[(int) x][(int) y] == Double.MIN_VALUE)
899 {
900 this.data[(int) x][(int) y] = data;
901 }
902 else
903 {
904 this.data[(int) x][(int) y] = (this.data[(int) x][(int) y] + data) / 2;
905 }
906 }
907
908
909
910
911
912
913
914
915
916
917 private void drawString(Graphics g, String text, int x, int y)
918 {
919 g.drawChars(text.toCharArray(), 0, text.length(), x, y + g.getFontMetrics().getHeight() / 4);
920 }
921
922
923
924
925
926
927
928
929
930
931 private void drawDiversion(Graphics g, Location diversion, int offsetX, int offsetY)
932 {
933 g.setColor(Color.BLUE);
934 g.fillRect((int) (diversion.x * drawScale + offsetX) - 2, (int) (diversion.y * drawScale + offsetY) - 2, 5, 5);
935 }
936
937
938
939
940
941
942
943
944
945 private void drawStartPose(Graphics g, Location startPose, int offsetX, int offsetY)
946 {
947 g.setColor(Color.MAGENTA);
948 g.drawOval(offsetX + (int) (startPose.x * drawScale) - 10, offsetY + (int) (startPose.y * drawScale) - 10, 20, 20);
949
950
951
952 }
953
954
955
956
957
958
959
960
961
962
963 private void drawRechargePoint(Graphics g, Location rechargePoint, int offsetX, int offsetY)
964 {
965 g.setColor(Color.YELLOW);
966 g.fillRect(offsetX + (int) (rechargePoint.x * drawScale) - 3, offsetY + (int) (rechargePoint.y * drawScale) - 3, 6, 6);
967
968 }
969
970
971
972
973
974
975
976
977
978
979 private void drawLowRisk(Graphics g, Location lowRisk, int offsetX, int offsetY)
980 {
981 g.setColor(Color.orange);
982 g.drawOval(offsetX + (int) (lowRisk.x * drawScale) - 1, offsetY + (int) (lowRisk.y * drawScale) - 1, 3, 3);
983
984 }
985
986
987
988
989
990
991
992
993
994
995 private void drawHighRisk(Graphics g, Location highRisk, int offsetX, int offsetY)
996 {
997 g.setColor(Color.red);
998 g.drawOval(offsetX + (int) (highRisk.x * drawScale) - 2, offsetY + (int) (highRisk.y * drawScale) - 2, 4, 4);
999
1000 }
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010 private void drawPathDot(Graphics g, Location dot, int offsetX, int offsetY)
1011 {
1012 g.setColor(Color.GREEN);
1013 g.fillOval(offsetX + (int) (dot.x * drawScale) - 1, offsetY + (int) (dot.y * drawScale) - 1, 3, 3);
1014
1015 }
1016
1017
1018
1019
1020
1021
1022
1023
1024 private void drawSonars(Graphics g)
1025 {
1026 if(sonars == null)
1027 {
1028 return;
1029 }
1030 int count = 0;
1031 int scale = (panelWidth - 2 * drawScale) / (sonars.size());
1032 for(Double sonar : sonars)
1033 {
1034 if(sonar < highRisk.get(count))
1035 {
1036 g.setColor(Color.red);
1037 }
1038 else if(sonar < lowRisk.get(count))
1039 {
1040 g.setColor(Color.green);
1041 }
1042 else
1043 {
1044 g.setColor(Color.BLUE);
1045 }
1046 g.fillRect(drawScale * 2 + count * scale, 350, scale - 1, (int) (sonar.doubleValue() * drawScale * 2));
1047 count++;
1048 }
1049 }
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061 private void drawImageLine(double x1, double y1, double x2, double y2, Color c, Graphics2D g)
1062 {
1063 Line2D line = new Line2D.Double(x1, y1, x2, y2);
1064 g.setColor(c);
1065 g.draw(line);
1066 }
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078 private void drawLine(Graphics g, Color c, double x1, double y1, double x2, double y2)
1079 {
1080 g.setColor(c);
1081 g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
1082 }
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092 private void drawPoint(Graphics g, Color c, double x, double y)
1093 {
1094 g.setColor(c);
1095 int xn = (int) x - offsetX;
1096 int yn = (int) y - offsetY;
1097 if(keepDataArrayGreat((int) x, (int) y))
1098 {
1099 g.drawLine(xn + offsetX, yn + offsetY, xn + offsetX, yn + offsetY);
1100 }
1101 else
1102 {
1103 g.drawLine((int) x, (int) y, (int) x, (int) y);
1104 }
1105 }
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115 private void addObstacle(double x, double y)
1116 {
1117 for(Obstacle1 obstacle : obstacles)
1118 {
1119 if(obstacle.isWithin(x, y))
1120 {
1121 return;
1122 }
1123 if(!obstacle.canExtend())
1124 {
1125 continue;
1126 }
1127 Obstacle1 newObstacle = obstacle.tryExtend(x, y);
1128 if(newObstacle != null)
1129 {
1130 return;
1131 }
1132 }
1133 obstacles.add(new Obstacle1(x, y));
1134 }
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146 public void setOffset(int offset)
1147 {
1148 this.offset = offset;
1149 }
1150
1151
1152
1153
1154
1155
1156
1157 public void setSonars(Collection<Double> sonars)
1158 {
1159 this.sonars = sonars;
1160 }
1161
1162
1163
1164
1165
1166
1167
1168 public void setDivPoint(Location diversion)
1169 {
1170 robotDiversions.add(diversion);
1171 drawDiversion(tmpG, diversion, offsetX, offsetY);
1172 }
1173
1174
1175
1176
1177
1178
1179 public void setStartLocation(Location start)
1180 {
1181 robotStartPoints.add(start);
1182 drawStartPose(tmpG, start, offsetX, offsetY);
1183 }
1184
1185
1186
1187
1188
1189
1190
1191
1192 public void setRechargeBreakPoint(Location breakPoint)
1193 {
1194 robotRechargePoints.add(breakPoint);
1195 drawRechargePoint(tmpG, breakPoint, offsetX, offsetY);
1196 }
1197
1198
1199
1200
1201
1202
1203
1204 public void setHighRiskPoint(Location highRisk)
1205 {
1206 robotHighRiskPoints.add(highRisk);
1207 drawHighRisk(tmpG, highRisk, offsetX, offsetY);
1208 }
1209
1210
1211
1212
1213
1214
1215
1216 public void setLowRiskPoint(Location lowRisk)
1217 {
1218 robotLowRiskPoints.add(lowRisk);
1219 drawLowRisk(tmpG, lowRisk, offsetX, offsetY);
1220 }
1221
1222
1223
1224
1225
1226
1227
1228 public void setRecord(Record rec)
1229 {
1230 recordPrev = record;
1231 record = rec;
1232 }
1233
1234
1235
1236
1237
1238
1239 public void setPostInfo(String info)
1240 {
1241 this.postInfo = info;
1242 }
1243
1244
1245
1246
1247
1248
1249 public void setDatFile(boolean write)
1250 {
1251 this.datFile = write;
1252 }
1253
1254
1255
1256
1257 public void refreshGraphics()
1258 {
1259 this.update(this.getGraphics());
1260 }
1261
1262
1263
1264
1265
1266
1267
1268
1269 public void setInfo(String text)
1270 {
1271 this.actInfo = text;
1272 }
1273
1274
1275
1276
1277
1278
1279 public void setOrientation(Rotation rot)
1280 {
1281 rotPrev = this.rot;
1282 this.rot = rot;
1283 }
1284 private int everyOther = 0;
1285
1286
1287
1288
1289
1290
1291 public void setLocation(Location loc)
1292 {
1293 locPrev = this.loc;
1294 this.loc = loc;
1295 drawPathDot(tmpG, loc, offsetX, offsetY);
1296 if(everyOther > 10)
1297 {
1298 everyOther = 0;
1299 robotPath.add(loc);
1300 }
1301 else
1302 {
1303 everyOther++;
1304 }
1305 }
1306
1307
1308 private javax.swing.JLabel jLabel1;
1309
1310 }