Package graphmatcher.matcher.shapecontext

Source Code of graphmatcher.matcher.shapecontext.NeighbourHelper

package graphmatcher.matcher.shapecontext;

import graphmatcher.graph.Graph;
import graphmatcher.graph.Vertex;

import java.util.Arrays;
import java.util.Comparator;

public class NeighbourHelper {
 
  public static int[] getNeighbours(int vertexId, final Graph graph) {
    Integer[] vertices = new Integer[graph.vertices().length-1];
    final Vertex vertex = graph.vertices()[vertexId];
    int index=0;
    boolean foundVertex = false;
    for (int i=0; i < graph.vertices().length; i++) {
      if (i==vertexId) {
        continue;
      }
//      if (!vertex.equals(graph.vertices()[i])) {
        vertices[index++]=i;
//      } else {
//        if (foundVertex) {
//          throw new RuntimeException("ung�ltiger Graph: doppelter Knoten");
//        }
//        foundVertex=true;
//      }
    }
    Arrays.sort(vertices, new Comparator<Integer>(){
      public int compare(Integer o1, Integer o2) {
        Vertex v1 = graph.vertices()[o1.intValue()];
        Vertex v2 = graph.vertices()[o2.intValue()];
        double dist1 = Vertex.getDistanceTo(vertex, v1);
        double dist2 = Vertex.getDistanceTo(vertex, v2);
        if (dist1 < dist2) {
          return -1;
        } else if (dist1 > dist2) {
          return 1;
        }
        return 0;
      }
    });
   
   
    int[] result = new int[vertices.length];
    for (int i = 0; i < result.length; i++) {
      result[i] = vertices[i].intValue();
    }
    return result;
  }
}
TOP

Related Classes of graphmatcher.matcher.shapecontext.NeighbourHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.