Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.*;
  3.  
  4. /**
  5. * Extractor.java. Implements feature extraction for collinear points in
  6. * two dimensional data.
  7. *
  8. * @author (dh@auburn.edu)
  9. * @version 2015-10-09
  10. *
  11. */
  12. public class Extractor {
  13.  
  14. /** resolution settings for stdlib drawing. */
  15. private static int HI_RES = 32768;
  16. private static int LO_RES = 32;
  17. ArrayList<Point> points;
  18.  
  19. /**
  20. * Builds an extractor based on the points in the
  21. * file named by filename.
  22. */
  23. public Extractor(String filename) {
  24. Scanner scanner = new Scanner(filename);
  25. int size = scanner.nextInt();
  26. points = new ArrayList<>(size);
  27. while (scanner.hasNext()) {
  28. Point p = new Point(scanner.nextInt(), scanner.nextInt());
  29. points.add(p);
  30. }
  31. }
  32.  
  33. /**
  34. * Builds an extractor based on the points in the
  35. * Collection named by pcoll.
  36. */
  37. public Extractor(Collection<Point> pcoll) {
  38.  
  39. points = new ArrayList<>(pcoll);
  40. points.addAll(pcoll);
  41. }
  42.  
  43. /**
  44. * Returns a sorted set of all line segments of exactly four
  45. * collinear points. Uses a brute-force combinatorial
  46. * strategy. Returns an empty set if there are no qualifying
  47. * line segments.
  48. */
  49. public SortedSet<Line> getLinesBrute() {
  50. TreeSet<Line> lines = new TreeSet<>();
  51.  
  52. if (lines.isEmpty())
  53. {
  54. return null;
  55. }
  56. else {
  57.  
  58. for (int i = 0; i < points.size(); i++) {
  59. for (int j = i + 1; j < points.size(); j++) {
  60. for (int k = j + 1; k < points.size(); k++) {
  61. for (int l = k + 1; l < points.size(); l++) {
  62. boolean isLine = points.get(i).slopeTo(points.get(l)) == points.get(j).slopeTo(points.get(k));
  63. if (isLine) {
  64. ArrayList<Point> collinear = new ArrayList<>(4);
  65. collinear.add(points.get(i));
  66. collinear.add(points.get(j));
  67. collinear.add(points.get(k));
  68. collinear.add(points.get(l));
  69. Line coLine = new Line(collinear);
  70. lines.add(coLine);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. return lines;
  78. }
  79.  
  80. /**
  81. * Returns a sorted set of all line segments of at least four
  82. * collinear points. The line segments are maximal; that is,
  83. * no sub-segments are identified separately. A sort-and-scan
  84. * strategy is used. Returns an empty set if there are no qualifying
  85. * line segments.
  86. */
  87. public SortedSet<Line> getLinesFast() {
  88. TreeSet<Line> lines = new TreeSet<Line>();
  89. Point[] sortp = new Point[points.size()];
  90. Arrays.sort(sortp, sortp[0].SLOPE_ORDER);
  91.  
  92. ArrayList<Point> sortLine = new ArrayList<Point>();
  93.  
  94.  
  95. if (lines.isEmpty())
  96. {
  97. return null;
  98. }
  99. else {
  100.  
  101. }
  102. return lines;
  103. }
  104.  
  105. // Draw all points to a graphics window.
  106. public void drawPoints() {
  107. // optional
  108. }
  109.  
  110. // Draw all identified lines, if any, to a graphics window.
  111. public void drawLines() {
  112. // optional
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement