📄 splitline.java
字号:
* lookups that return nothing will need to know how to get individual cells * @param v vector of Integers * @param sc split cell, initially the root cell * @param pixelSize minimal size of a block in absolute [0,1] size */ private void makePixelRangeRecursive(TreeSet v, SplitCell sc, double pixelSize, int frameNum) { double[] positions = {getAbsoluteValue(sc.min, frameNum),getAbsoluteValue(sc.max, frameNum)}; if (positions[1] - positions[0] <= pixelSize) { v.add(sc); } else { if (sc.kid[0] != -1) makePixelRangeRecursive(v, getSplitCell(sc.kid[0]), pixelSize, frameNum); else v.add(new SplitCell(sc.min, sc.min+1)); if (sc.kid[1] != -1) makePixelRangeRecursive(v, getSplitCell(sc.kid[1]), pixelSize, frameNum); else v.add(new SplitCell(sc.max-1, sc.max)); }// if (sc.kid[0] != -1)// {// sc.// }// // // && sc.kid[1] == -1)// {// }// else// {// int half = getThisRoot(min, max);//(min+max)/2;// double[] positions = {getAbsoluteValue(min),getAbsoluteValue(half),getAbsoluteValue(max)};// // if (false)// { // new way, only larger than a block size is allowed// if (positions[1] - positions[0] <= pixelSize// || positions[2] - positions[1] <= pixelSize) // is this half too small?// v.add(getSplitCell(min, max));//new SplitCell(min-1, max)); // add parent// else// {// makePixelRangeRecursive(v, min, half, pixelSize);// makePixelRangeRecursive(v, half, max, pixelSize); // if false, do nothing// }// }// else// { // old way, smaller than a block is allowed// if (min+1 == half || positions[1] - positions[0] <= pixelSize)// v.add(getSplitCell(min, half));// else// makePixelRangeRecursive(v, min, half, pixelSize);// if (half+1 == max || positions[2] - positions[1] <= pixelSize)// v.add(getSplitCell(half, max));// else// makePixelRangeRecursive(v, half, max, pixelSize);// }// } } /** */ public TreeSet makePixelRanges(int frameNum) { double pixelSize = ad.getPixelSize(horizontal ? AccordionDrawer.X : AccordionDrawer.Y); if (pixelSize < 0) { System.out.println("Error: pixelSize is negative!"); return null; } int min = -1, max = size; TreeSet returnVector = new TreeSet(); if ((max - min) == 1) returnVector.add(new SplitCell(min, max)); else makePixelRangeRecursive(returnVector, getSplitCell(rootIndex), pixelSize, frameNum); // // debug// Iterator iter = returnVector.iterator();// int prevMax = -1;// while (iter.hasNext())// {// SplitCell sc = (SplitCell)iter.next();// double size = sc.getSize(this);// if (size > pixelSize && sc.min + 1 != sc.max) // too small// {// System.out.println("size of splitcell is too large");// }// if (sc.min > prevMax)// {// System.out.println("hole in tree");// }// prevMax = sc.max;// } return returnVector; } public TreeSet makePixelRanges(float pixelDiv) { int frameNum = ad.getFrameNum(); double pixelSize = ad.getPixelSize(horizontal ? AccordionDrawer.X : AccordionDrawer.Y) / pixelDiv; if (pixelSize < 0) { System.out.println("Error: pixelSize is negative!"); return null; } int min = -1, max = size; TreeSet returnVector = new TreeSet(); makePixelRangeRecursive(returnVector, getSplitCell(rootIndex), pixelSize, frameNum); return returnVector; } public void moveLine(int dragIndex, int dragPixelEnd, int staticIndex, int numSteps, Hashtable newToMove) { int frameNum = ad.getFrameNum(); if (dragIndex == staticIndex) return; // huh? int xy = horizontal ? AccordionDrawer.X : AccordionDrawer.Y; if (dragIndex == -1 || dragIndex == size) return; // split is one of the stuck lines int[] range = {-1, dragIndex, staticIndex, size}; double dragEnd = (double)ad.s2w(dragPixelEnd, xy); // shouldn't be able to drag the box out of the periphery range from the borders if (dragEnd < minStuckValue + ad.minContextPeriphery || dragEnd > maxStuckValue - ad.minContextPeriphery) return; double staticEnd = getAbsoluteValue(staticIndex, frameNum); double dragStart = getAbsoluteValue(dragIndex, frameNum); // shouldn't be able to drag the box too small, keep context inside if (Math.abs(dragEnd - dragStart) < ad.minContextInside) return; double[] startValue = {minStuckValue, dragStart, staticEnd, maxStuckValue}; double[] endValue = {minStuckValue, dragEnd, staticEnd, maxStuckValue}; if (dragIndex > staticIndex) { range[1] = staticIndex; endValue[1] = staticEnd; startValue[1] = staticEnd; range[2] = dragIndex; endValue[2] = dragEnd; startValue[2] = dragStart; } int min = 0, max = range.length - 1; while (range[min] == range[min+1]) min++; // at least ignore statics that are while (range[max] == range[max-1]) max--; // on a stuck line resizeRanges(range, startValue, endValue, numSteps, rootIndex, min, max, newToMove); } // given the pixel, return the index splitLine on the minimum side of the gridCell chosen public int getMinIndexForPixelValue(int pixelPosition, int frameNum) { int xy = horizontal ? AccordionDrawer.X : AccordionDrawer.Y; double windowLocation = (double)ad.s2w(pixelPosition, xy); int minIndex = -1, maxIndex = size; int currIndex = rootIndex; double currLocation = getAbsoluteValue(currIndex, frameNum); while (currIndex != maxIndex) { if (windowLocation <= currLocation) { // left maxIndex = currIndex; currIndex = getSplitRoot(minIndex, currIndex, maxIndex, true); //(minIndex + currIndex + 1) / 2; } else { // right minIndex = currIndex; currIndex = getSplitRoot(minIndex, currIndex, maxIndex, false); //(minIndex + currIndex + 1) / 2;// currIndex = (maxIndex + currIndex + 1) / 2; } currLocation = getAbsoluteValue(currIndex, frameNum); }// System.out.println(pixelPosition + " " + minIndex); return minIndex; } public int getRootIndex() { return rootIndex; } // true when max is larger than min, thus this range is big enough to draw // this will assume that smallest non-big enough is when abs[min] == abs[max] (i.e. the same pixel) private boolean rangeSizeBigEnough(int min, int max, double pixelSize, int frameNum) { //System.out.println("indexxx " + min + " " + max + " " + this.size);// double m;// if ( min == -1)// m = getAbsoluteValue(min);// else// m = getAbsoluteValue((min-1)*2);// double mx = getAbsoluteValue((max-1)*2);// //double mx = getAbsoluteValue(max);// // double size = mx - m; double size = getAbsoluteValue(max, frameNum) - getAbsoluteValue(min, frameNum); return size >= pixelSize; } // not called by SJ/TJ anymore // min, mid, max are all indices into split vectors (min should start at -1, max at size or max gridcell index) // recursion is exclusive (i.e. left and right sides don't both need to draw mid, // arbitrary: give mid to the left side) public void drawRange(int min, int max, double pixelSize, int frameNum) {// computePlaceThisFrame((min-1)*2);// computePlaceThisFrame((max-1)*2); computePlaceThisFrame(min, frameNum); computePlaceThisFrame(max, frameNum); if (min+1 == max || !rangeSizeBigEnough(min, max, pixelSize, frameNum)) { //System.out.println("range " + min + " " + max + " " + isHorizontal()); ad.drawRange(min, max); ad.drawDensity(min, max); ad.drawReferenceLine(); } else // recursion { int mid = getThisRoot(min, max); drawRange(min, mid, pixelSize, frameNum); drawRange(mid, max, pixelSize, frameNum); } } // start recursion for drawingRanges, this is just for testing, it's not progressive public void drawAllRanges(int frameNum) { int xy = horizontal ? AccordionDrawer.X : AccordionDrawer.Y; double pixelSize = ad.getPixelSize(xy); System.out.println("Draw all ranges"); drawRange(-1, size, pixelSize, frameNum); } /** * @return */ public boolean isHorizontal() { return horizontal; } public void drawBackground(Color boxColor, int frameNum) { int xy = horizontal ? AccordionDrawer.X : AccordionDrawer.Y; float thecol[] = new float[3]; int level = (int) (Math.log(size) / Math.log(2)); int numRanges = 1; int currHop = (size+1) / 2; int currLevel = level; final int drawDepth = 5; double min[] = new double[2]; double max[] = new double[2]; min[xy^1] = ad.splitLine[xy^1].minStuckValue; max[xy^1] = ad.splitLine[xy^1].maxStuckValue; while (level - currLevel > drawDepth && currHop >= 1) { if (ad.colorgrid || ad.drawBackground) { int gridDepth = ad.gridDepth[xy]; thecol[0] = 1.0f; thecol[1] = 1.0f - ((float) level) / gridDepth; if (numRanges == 1) thecol[2] = 1.0f; else if (currHop > 1) thecol[2] = .5f; else thecol[2] = .0f; } else { if (null == boxColor) return; boxColor.getRGBColorComponents(thecol); } double zplane = ad.colorgrid ? - (level + 2.0) : ad.hiliteplane; GLFunc gl = (GLFunc) ad.getGraphicsStuff(); gl.glColor3f(thecol[0], thecol[1], thecol[2]); gl.glBegin(GLEnum.GL_POLYGON); int currPosition = 0; for (int i = 0; i < numRanges; i++) { currPosition += currHop; min[xy] = max[xy] = getAbsoluteValue(currPosition, frameNum); gl.glVertex3d(min[0], max[1], zplane); gl.glVertex3d(min[0], min[1], zplane); gl.glVertex3d(max[0], min[1], zplane); gl.glVertex3d(max[0], max[1], zplane); } gl.glEnd(); currLevel--; currHop = (currHop + 1) / 2; numRanges *= 2; } // System.out.println("bbox: xmin " + min[0] + " xmax " + max[0] + " ymin " + min[1] + " ymax " + max[1] + " z " + z); // System.out.println(" R " + thecol[0] + " G " + thecol[1] + " B " + thecol[2]); } protected void drawKidsGrid(int frameNum) { int xy = horizontal ? AccordionDrawer.X : AccordionDrawer.Y; int level = (int) (Math.log(size) / Math.log(2)); int numRanges = 1; int currHop = (size + 1) / 2; int currLevel = level; final int drawDepth = 5; double min[] = new double[2]; double max[] = new double[2]; min[xy ^ 1] = ad.splitLine[xy ^ 1].minStuckValue; max[xy ^ 1] = ad.splitLine[xy ^ 1].maxStuckValue; while (level - currLevel > drawDepth && currHop >= 1) { GLFunc gl = (GLFunc) ad.getGraphicsStuff(); float thecol[] = new float[3]; if (ad.biggrid) { thecol[0] = currLevel & 1; thecol[1] = (currLevel & 2) / 2; thecol[2] = (currLevel & 4) / 4; gl.glLineWidth((float) (currLevel + 1.0)); } else { gl.glLineWidth((float) 1.0); thecol[0] = thecol[1] = thecol[2] = .55f; } gl.glColor3f(thecol[0], thecol[1], thecol[2]); gl.glBegin(GLEnum.GL_LINES); int currPosition = 0; for (int i = 0; i < numRanges; i++) { currPosition += currHop; min[xy] = max[xy] = getAbsoluteValue(currPosition, frameNum); gl.glVertex3d(min[xy], min[xy ^ 1], ad.gridplane); gl.glVertex3d(max[xy], max[xy ^ 1], ad.gridplane); } gl.glEnd(); currLevel--; currHop = (currHop + 1) / 2; numRanges *= 2; } } // for testing with small datasets public void drawTicks(int frameNum) { GLFunc gl = (GLFunc) ad.getGraphicsStuff(); gl.glLineWidth(1f); if (horizontal) { // draw vertical tick marks SplitLine Ysplit = ad.getSplitLine(AccordionDrawer.Y); double minStuckY = Ysplit.minStuckValue; gl.glBegin(GLEnum.GL_LINES); for (int i = 0; i < splitCells.length; i++) { double absol = getAbsoluteValue(i, frameNum); gl.glVertex3d(absol, 0, ad.interactionplane); gl.glVertex3d(absol, minStuckY, ad.interactionplane); } gl.glEnd(); } else { // draw horizontal tick marks SplitLine Xsplit = ad.getSplitLine(AccordionDrawer.X); double minStuckX = Xsplit.minStuckValue; gl.glBegin(GLEnum.GL_LINES); for (int i = 0; i < splitCells.length; i++) { double absol = getAbsoluteValue(i, frameNum); gl.glVertex3d(0, absol, ad.interactionplane); gl.glVertex3d(minStuckX, absol, ad.interactionplane); } gl.glEnd(); } } /** * @return */ public int getSize() { return size; } public SplitCell getSplitCell(int min, int max) { if (min == max) return null; if (size == 0) // also: min=-1, max=0 return new SplitCell(-1, 0); // not a real split cell! if (min == -1 && max == size) return splitCells[rootIndex];// if (min == -1)// return splitCells[splitCells[max].kid[0]];// if (max == size)// return splitCells[splitCells[min].kid[1]]; SplitCell parent = splitCells[getThisRoot(min, max)]; if (parent != null && parent.min == min && parent.max == max) return parent; return null; } public SplitCell getSplitCell(int index) { if (index > -1 && index < size) return splitCells[index]; return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -