Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.*;
- /**
- * Extractor.java. Implements feature extraction for collinear points in
- * two dimensional data.
- *
- * @author (dh@auburn.edu)
- * @version 2015-10-09
- *
- */
- public class Extractor {
- /** resolution settings for stdlib drawing. */
- private static int HI_RES = 32768;
- private static int LO_RES = 32;
- ArrayList<Point> points;
- /**
- * Builds an extractor based on the points in the
- * file named by filename.
- */
- public Extractor(String filename) {
- Scanner scanner = new Scanner(filename);
- int size = scanner.nextInt();
- points = new ArrayList<>(size);
- while (scanner.hasNext()) {
- Point p = new Point(scanner.nextInt(), scanner.nextInt());
- points.add(p);
- }
- }
- /**
- * Builds an extractor based on the points in the
- * Collection named by pcoll.
- */
- public Extractor(Collection<Point> pcoll) {
- points = new ArrayList<>(pcoll);
- points.addAll(pcoll);
- }
- /**
- * Returns a sorted set of all line segments of exactly four
- * collinear points. Uses a brute-force combinatorial
- * strategy. Returns an empty set if there are no qualifying
- * line segments.
- */
- public SortedSet<Line> getLinesBrute() {
- TreeSet<Line> lines = new TreeSet<>();
- if (lines.isEmpty())
- {
- return null;
- }
- else {
- for (int i = 0; i < points.size(); i++) {
- for (int j = i + 1; j < points.size(); j++) {
- for (int k = j + 1; k < points.size(); k++) {
- for (int l = k + 1; l < points.size(); l++) {
- boolean isLine = points.get(i).slopeTo(points.get(l)) == points.get(j).slopeTo(points.get(k));
- if (isLine) {
- ArrayList<Point> collinear = new ArrayList<>(4);
- collinear.add(points.get(i));
- collinear.add(points.get(j));
- collinear.add(points.get(k));
- collinear.add(points.get(l));
- Line coLine = new Line(collinear);
- lines.add(coLine);
- }
- }
- }
- }
- }
- }
- return lines;
- }
- /**
- * Returns a sorted set of all line segments of at least four
- * collinear points. The line segments are maximal; that is,
- * no sub-segments are identified separately. A sort-and-scan
- * strategy is used. Returns an empty set if there are no qualifying
- * line segments.
- */
- public SortedSet<Line> getLinesFast() {
- TreeSet<Line> lines = new TreeSet<Line>();
- Point[] sortp = new Point[points.size()];
- Arrays.sort(sortp, sortp[0].SLOPE_ORDER);
- ArrayList<Point> sortLine = new ArrayList<Point>();
- if (lines.isEmpty())
- {
- return null;
- }
- else {
- }
- return lines;
- }
- // Draw all points to a graphics window.
- public void drawPoints() {
- // optional
- }
- // Draw all identified lines, if any, to a graphics window.
- public void drawLines() {
- // optional
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement