blob: 2577fa2908343c0bf20400edfa0ffda3ba7e82cc [file] [log] [blame]
danielp4a35a7a2013-02-20 20:45:39 +00001/**
2 *
3 */
4package org.frc971;
5
6/**
7 * @author daniel
8 *
9 */
10
danielp54e997e2013-02-21 01:54:23 +000011import java.io.File;
12import java.io.IOException;
13
14import java.util.logging.Logger;
15
danielp4a35a7a2013-02-20 20:45:39 +000016import javax.imageio.ImageIO;
17
18import edu.wpi.first.wpijavacv.WPIColorImage;
19
danielp64c4e052013-02-23 07:21:41 +000020/** Get debug images for Java camera processor. */
danielp4a35a7a2013-02-20 20:45:39 +000021public class TestImageGetter {
danielp54e997e2013-02-21 01:54:23 +000022
danielp4a35a7a2013-02-20 20:45:39 +000023 private String path_to_images;
danielp54e997e2013-02-21 01:54:23 +000024
25 private final static Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
26
danielp64c4e052013-02-23 07:21:41 +000027 /** The names of our debugging images, without paths.
28 * The GetNext method should be used to get the first
29 * image, and not GetCurrent. */
danielp4a35a7a2013-02-20 20:45:39 +000030 final static String[] images = {"45in_DoubleGreen.jpg",
31 "57inLargeTarget_DoubleGreenBK.jpg",
32 "FullField_DoubleGreenBK3.jpg",
33 "FullField_SmallGreen.jpg",
34 "HybridLine_DoubleGreenBK2.jpg",
35 "HybridLine_DoubleGreenBK3.jpg",
36 "HybridLine_DoubleGreenBK4.jpg",
37 "HybridLine_SmallGreen2.jpg",
38 "HybridLine_SmallGreen3.jpg",
39 "HybridLine_SmallGreen4.jpg",
40 "Midfield_DoubleGreenBK2.jpg",
41 "Midfield_SmallGreen2.jpg",
42 "Midfield_SmallGreen3.jpg",
43 "Midfield_SmallGreen4.jpg",
44 "OppLine_DoubleGreenBK2.jpg",
45 "OppLine_SmallGreen2.jpg",
46 "PyramidRight_DoubleGreenBK2.jpg",
47 "PyramidRight_SmallGreen2.jpg"
48 };
49
50 private int image_index = -1;
51
52 private WPIColorImage current_image = null;
53
danielp64c4e052013-02-23 07:21:41 +000054 /** Helper method to concatenate paths, similar to Python's os.path.join(). */
danielp4a35a7a2013-02-20 20:45:39 +000055 private String cocatenate_paths(String path1, String path2) {
56 if (path1.charAt(path1.length() - 1) == '/')
57 return path1 + path2;
58 else
59 return path1 + "/" + path2;
60 }
danielp64c4e052013-02-23 07:21:41 +000061
danielp3c598e52013-02-24 06:12:54 +000062 /** Gets the name to display at the top of the image window. */
63 public String GetName() {
64 return images[image_index];
65 }
66
danielp64c4e052013-02-23 07:21:41 +000067 /** Constructor
68 *
69 * @param path_to_images is the path to the directory where our images are.
70 */
danielp4a35a7a2013-02-20 20:45:39 +000071 public TestImageGetter(String path_to_images) {
72 this.path_to_images = path_to_images;
73 }
danielp64c4e052013-02-23 07:21:41 +000074
75 /** Gets the next debugging image.
76 *
77 * @return Returns a WPIColorImage.
78 */
danielp4a35a7a2013-02-20 20:45:39 +000079 public WPIColorImage GetNext() {
80 image_index++;
81 if (image_index < images.length) {
82 String image_to_get = images[image_index];
83 try {
84 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
85 return current_image;
86 }
87 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +000088 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +000089 return null;
90 }
91 }
92 else
93 image_index--;
94 return null;
95 }
danielp64c4e052013-02-23 07:21:41 +000096
97 /** Gets the previous debugging image.
98 *
99 * @return Returns a WPIColorImage.
100 */
danielp4a35a7a2013-02-20 20:45:39 +0000101 public WPIColorImage GetPrev() {
102 image_index--;
103 if (image_index >= 0) {
104 String image_to_get = images[image_index];
105 try {
106 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
107 return current_image;
108 }
109 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +0000110 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +0000111 return null;
112 }
113 }
114 else
115 image_index++;
116 return null;
117 }
danielp64c4e052013-02-23 07:21:41 +0000118
119 /** Gets the current debugging image. This is vestigial, it is not longer used.
120 *
121 * @return Returns a WPIColorImage
122 */
danielp4a35a7a2013-02-20 20:45:39 +0000123 public WPIColorImage GetCurrent() {
124 return current_image;
125 }
126}