public AnnotFloorPlan(FloorPlan fp, int ratio, int actualW, int actualH) { em = DatabaseService.getEntityManager(); floorPlan = fp; deadPoints = new HashSet<DeadPoint>(); this.ratio = ratio; this.actualW = actualW; this.actualH = actualH; // Width and height of each cell // unitW = fp.getWidth() * ratio / 100; // unitH = fp.getHeight() * ratio / 100; // Calc the number of rows and columns needed // rowCount = fp.getHeight() / unitH + 1; // colCount = fp.getWidth() / unitW + 1; rowCount = 50; colCount = 75; unitW = (int) Math.ceil(fp.getWidth() / colCount); unitH = (int) Math.ceil(fp.getHeight() / rowCount); cellContainer = new Cell[rowCount][colCount]; // init the graph g = new SimpleWeightedGraph<Cell, WeightedEdge>(WeightedEdge.class); initGraph(); }
public void updateConfig(int ratio, int actualW, int actualH) { this.ratio = ratio; this.actualH = actualH; this.actualW = actualW; // Re-generate graph // Width and height of each cell unitW = floorPlan.getWidth() * ratio / 100; unitH = floorPlan.getHeight() * ratio / 100; // Calc the number of rows and columns needed rowCount = floorPlan.getHeight() / unitH + 1; colCount = floorPlan.getWidth() / unitW + 1; // init the graph g = new SimpleWeightedGraph<Cell, WeightedEdge>(WeightedEdge.class); updateGraph(); }
/** * The coordinate is the top left corner * * @param xm x position in meters * @param ym y position in meters * @return [0] contains row; [1] contains col */ public int[] getNodePosition(double xm, double ym) { int pxW = floorPlan.getWidth(), pxH = floorPlan.getHeight(), pxX, pxY; double widthRatio = pxW / actualW, heightRatio = pxH / actualH; pxX = (int) Math.round(xm * widthRatio); pxY = (int) Math.round(ym * heightRatio); int pos[] = new int[2]; pos[0] = pxY / unitH; pos[1] = pxX / unitW; return pos; }