public Edge getEdgeAt(int index) { return this.edges.get(index); }
public Node getNodeAt(int index) { return this.nodes.get(index); }
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 Edge findEdge(Node target) { int edgeCount = this.edges.size(); for (int i = 0; i < edgeCount; i++) { Edge edge = this.edges.get(i); if (edge.getTarget() == target) { return edge; } } return null; }
void resetMergedFlagToAllNodes() { int nodeCount = this.nodes.size(); for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); node.setMerged(false); } }
void setValidFlagToAllNodes() { int nodeCount = this.nodes.size(); for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); node.setValid(true); } }
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 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 final void removeEdgeToUnstableNode() { int edgeCount = this.edges.size(); for (int j = 0; j < edgeCount; j++) { Edge edge = this.edges.get(j); Node nodeNeighbor = edge.getTarget(); int removedEdgeIndex = nodeNeighbor.removeEdge(this); assert (removedEdgeIndex >= 0); } }
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); }
void resetCostUpdatedFlagToAllEdges() { int nodeCount = this.nodes.size(); for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); int edgeCount = node.getEdgeCount(); for (int j=0; j<edgeCount; j++) { Edge edge = node.getEdgeAt(j); edge.setCostUpdated(false); } } }
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 resetCostUpdatedFlagToAllEdges() { int edgeCount = this.edges.size(); for (int i = 0; i < edgeCount; i++) { Edge edge = this.edges.get(i); edge.setCostUpdated(false); Edge toNeigh = edge.getTarget().findEdge(this); toNeigh.setCostUpdated(false); } }
/** * Check the local mutual best fitting. * * @param threshold * @return */ public Node checkLMBF(float threshold) { if (isValid() && this.edges.size() > 0) { Edge firstEdge = this.edges.get(0); if (firstEdge.getCost() < threshold) { Node firstEdgeTarget = firstEdge.getTarget(); if (firstEdgeTarget.isValid()) { Node bestNode = firstEdgeTarget.getEdgeAt(0).getTarget(); if (this == bestNode) { // the same node if (this.id < firstEdgeTarget.id) { return this; } return firstEdgeTarget; } } } } return null; }
public void removeUselessNodes(Int2ObjectMap<Node> borderNodes, ProcessingTile tile) { int nodeCount = this.nodes.size(); for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); BoundingBox box = node.getBox(); if (box.getLeftX() > tile.getImageLeftX() && box.getTopY() > tile.getImageTopY() && box.getRightX() - 1 < tile.getImageRightX() && box.getBottomY() - 1 < tile.getImageBottomY()) { continue; } else if (!borderNodes.containsKey(node.getId())) { node.removeEdgeToUnstableNode(); node.setExpired(true); } } removeExpiredNodes(); }
public void rescaleGraph(ProcessingTile tile, int imageWidth) { BoundingBox region = tile.getRegion(); int nodeCount = this.nodes.size(); for (int i=0; i<nodeCount; i++) { Node node = this.nodes.get(i); // start pixel index of the node (in the tile) int rowNodeTile = node.getId() / region.getWidth(); int colNodeTile = node.getId() % region.getWidth(); // start pixel index of the node (in the image) int rowNodeImg = region.getTopY() + rowNodeTile;// - tile.getTopMargin(); int colNodeImg = region.getLeftX() + colNodeTile;// - tile.getLeftMargin(); // set the node id in the image node.setId(rowNodeImg * imageWidth + colNodeImg); // change also its bounding box BoundingBox box = node.getBox(); box.setLeftX(region.getLeftX() + box.getLeftX());// - tile.getLeftMargin()); box.setTopY(region.getTopY() + box.getTopY());// - tile.getTopMargin()); } }