File size: 1,683 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class Gene {
private Point2D direction;
private Point2D pos;
private Color color;
private ArrayList<Point2D> neighbours;
private ArrayList<Double> neighbours_weights;
private Centroid parent;
public Gene(Centroid parent, Point2D pos, Color c, ArrayList<Point2D> neighbours) {
this.pos = pos;
this.color = c;
this.neighbours = neighbours;
this.parent = parent;
}
public void setDirection(Point2D dir) {
this.direction = dir;
}
public Point2D getGene() {
return this.direction;
}
public Color getColor() {
return color;
}
public void setColor(Color c) {
this.color = c;
}
public void addDirection(Point2D dir) {
this.direction = dir;
}
public ArrayList<Double> setNeighboursWeights(ArrayList<Point2D> neighbours, BufferedImage img) {
ArrayList<Double> weights = new ArrayList<>();
for (Point2D p : neighbours) {
Color currC = getColorFromCoords(img, p);
double dist = euclideanDistance(this.color, currC);
}
return weights;
}
public double euclideanDistance(Color c0, Color c1) {
return Math.sqrt((Math.pow(c0.getRed(), 2) - Math.pow(c1.getRed(), 2)) + (Math.pow(c0.getGreen(), 2) - Math.pow(c1.getGreen(), 2)) + (Math.pow(c0.getBlue(), 2) - Math.pow(c1.getBlue(), 2)));
}
public Color getColorFromCoords(BufferedImage img, Point2D pix) {
return new Color(img.getRGB((int) pix.getX(), (int) pix.getY()));
}
}
|