protected Node(int id, BoundingBox box, Contour contour, int perimeter, int area, int numberOfComponentsPerPixel) { this.id = id; this.edges = new ArrayListExtended<Edge>(0); this.means = new float[numberOfComponentsPerPixel]; this.contour = contour; // merged = true => force to compute costs for the first iteration this.flags = VALID_FLAG | MERGED_FLAG; this.area = area; this.perimeter = perimeter; this.box = box; }
public void addNode(Node nodeToAdd) { this.nodes.add(nodeToAdd); }
public void clearItems() { removeRange(0, size()); } }
public void swapEdges(int firstIndex, int secondIndex) { if (firstIndex < 0 || firstIndex >= this.edges.size()) { throw new IllegalArgumentException("The first index " + firstIndex + " is out of bounds. The maximum index is " + (this.edges.size() - 1)); } if (secondIndex < 0 || secondIndex >= this.edges.size()) { throw new IllegalArgumentException("The second index " + secondIndex + " is out of bounds. The maximum index is " + (this.edges.size() - 1)); } Edge auxEdge = this.edges.set(firstIndex, this.edges.get(secondIndex)); this.edges.set(secondIndex, auxEdge); }
public int removeExpiredNodes() { int nodeCount = this.nodes.size(); int lastIndexToCopy = -1; for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); if (node.isExpired()) { if (lastIndexToCopy == -1) { lastIndexToCopy = i; } node.doClose(); WeakReference<Node> reference = new WeakReference<Node>(node); reference.clear(); } else if (lastIndexToCopy > -1) { this.nodes.set(lastIndexToCopy, node); lastIndexToCopy++; } } if (lastIndexToCopy > - 1 && lastIndexToCopy < nodeCount) { this.nodes.removeItems(lastIndexToCopy, nodeCount); } return this.nodes.size(); }
public void doClose() { int nodeCount = this.nodes.size(); for (int index = 0; index<nodeCount; index++) { Node node = this.nodes.get(index); node.doClose(); WeakReference<Node> reference = new WeakReference<Node>(node); reference.clear(); } this.nodes.clearItems(); // remove all the nodes WeakReference<ArrayListExtended<Node>> reference = new WeakReference<ArrayListExtended<Node>>(this.nodes); reference.clear(); } }
public int removeEdge(Node target) { int edgeCount = this.edges.size(); for (int i = 0; i < edgeCount; i++) { Edge edge = this.edges.get(i); if (edge.getTarget() == target) { // found the edge to the target node this.edges.remove(i); WeakReference<Edge> reference = new WeakReference<Edge>(edge); reference.clear(); return i; } } return -1; // -1 => no edge removed }
public int getEdgeCount() { return this.edges.size(); }
public Edge getEdgeAt(int index) { return this.edges.get(index); }
public void removeItems(int fromIndexInclusive, int toIndexExclusive) { removeRange(fromIndexInclusive, toIndexExclusive); }
public void addNodes(Graph subgraph) { this.nodes.addAll(subgraph.nodes); }
public void doClose() { int edgeCount = this.edges.size(); for (int j = 0; j < edgeCount; j++) { Edge edge = this.edges.get(j); if (this != edge.getTarget()) { // the target node is different edge.getTarget().removeEdge(this); } WeakReference<Edge> reference = new WeakReference<Edge>(edge); reference.clear(); } this.edges.clearItems(); // remove all the edges WeakReference<ArrayListExtended<Edge>> reference = new WeakReference<ArrayListExtended<Edge>>(this.edges); reference.clear(); }
public int getNodeCount() { return this.nodes.size(); }
public Node getNodeAt(int index) { return this.nodes.get(index); }
public Graph(int numberOfNodes) { this.nodes = new ArrayListExtended<>(numberOfNodes); }
public void addEdge(Node target, int boundary) { this.edges.add(new Edge(target, boundary)); }
protected Node(int id, int upperLeftX, int upperLeftY, int numberOfComponentsPerPixel) { this.id = id; this.edges = new ArrayListExtended<Edge>(0); this.means = new float[numberOfComponentsPerPixel]; this.contour = new Contour(); this.contour.pushRight(); this.contour.pushBottom(); this.contour.pushLeft(); this.contour.pushTop(); // merged = true => force to compute costs for the first iteration this.flags = VALID_FLAG | MERGED_FLAG; this.area = 1; this.perimeter = 4; this.box = new BoundingBox(upperLeftX, upperLeftY, 1, 1); }