/** * returns a color for a group/order and for a state * * @param order A color order number. This determines the base color (hue). <br> * -2 => Wire <br> * else group index * @param what The goal for this color. <br> * 0 = unselected face. <br> * 1 = selected face. <br> * 2 = unselected internal edge <br> * 3 = selected internal edge <br> * 4 = unselected external edge <br> * 5 = selected external edge <br> * 6 = selected quad <br> */ public float[] getColorForOrder(int order, int what) { // wires have no group if (order == -2) { switch (what) { case 0: return new float[] {0.4f, 0.4f, 0.4f}; case 1: return new float[] {1.0f, 1.0f, 1.0f}; case 2: return new float[] {0.95f, 0.95f, 0.95f}; } } float s, h; float b = 1.0f; Color c = baseColor.get(new Integer(order)); float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); h = hsb[0]; s = hsb[1]; b = hsb[2]; switch (what) { case 0: s = s * 1.0f; break; // unactive face has saturated color case 1: s = s * 0.75f; break; // selected face is whiter case 2: s = s * 0.5f; break; // internal edges case 3: s = s * 0.0f; break; // selected internal edges case 4: s = s * 1.0f; b = b * 0.8f; break; // external edges case 5: s = 0.0f; break; // selected external edges case 6: s = s * 0.3f; break; // selected quad is whiter default: s = s * 1.0f; break; } return Color.getHSBColor(h, s, b).getRGBColorComponents(null); }
protected void makeGroups() { int totalQuads = 0; int totalInternalEdges = 0; int totalExternalEdges = 0; // loop over each group // loop over each group int[] groupID = provider.getDomainIDs(); for (int g = 0; g < groupID.length; ++g) { LOGGER.finest("generating java3d tree for group number " + groupID[g]); // Set of EdgeLine objects. Overlapping edges on the same line are // merged together HashMap<EdgeLine, EdgeLine> externalEdges = new HashMap<EdgeLine, EdgeLine>(); // Same trick for internal edges. HashMap<EdgeLine, EdgeLine> internalEdges = new HashMap<EdgeLine, EdgeLine>(); FDDomain fdDomain = (FDDomain) provider.getDomain(groupID[g]); baseColor.put(new Integer(g), fdDomain.getColor()); Plate[] plates = domainToPlates(fdDomain); if (plates.length == 0) continue; // Create plates for this group FloatBuffer nioCoords = ByteBuffer.allocateDirect(plates.length * 4 * 3 * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); FloatBuffer nioColors = ByteBuffer.allocateDirect(plates.length * 4 * 3 * 4) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); float[] baseColor = getColorForOrder(g, 0); // System.out.println(baseColor[0]+" "+baseColor[1]+" "+baseColor[2]); for (int np = 0; np < plates.length; ++np) { Plate p = plates[np]; // put coordinates nioCoords.put(p.getCoordinates(grid)); // put colors for the 4 vertices nioColors.put(baseColor); nioColors.put(baseColor); nioColors.put(baseColor); nioColors.put(baseColor); // Merge external edges addEdge(externalEdges, getLine(p, 2, p.min1), p.min2, p.max2); addEdge(externalEdges, getLine(p, 2, p.max1), p.min2, p.max2); addEdge(externalEdges, getLine(p, 1, p.min2), p.min1, p.max1); addEdge(externalEdges, getLine(p, 1, p.max2), p.min1, p.max1); // Merge internal edges for (int i = p.min1 + 1; i < p.max1; ++i) addEdge(internalEdges, getLine(p, 2, i), p.min2, p.max2); for (int j = p.min2 + 1; j < p.max2; ++j) addEdge(internalEdges, getLine(p, 1, j), p.min1, p.max1); } // use by reference array of colors => fast to change! QuadArray qa = new NioQuadArray(plates.length * 4, GeometryArray.COORDINATES | GeometryArray.COLOR_3); qa.setCoordRefBuffer(new J3DBuffer(nioCoords)); qa.setColorRefBuffer(new J3DBuffer(nioColors)); qa.setCapability(GeometryArray.ALLOW_COLOR_WRITE); qa.setCapabilityIsFrequent(GeometryArray.ALLOW_COLOR_WRITE); Appearance a = new Appearance(); PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0); pa.setPolygonOffset(1); pa.setPolygonOffsetFactor(1); a.setPolygonAttributes(pa); Shape3D s3d = new Shape3D(qa, a); PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); s3d.setCapability(Node.ALLOW_PICKABLE_READ); s3d.setCapability(Node.ALLOW_PICKABLE_WRITE); s3d.setPickable(true); s3d.setUserData(new BehindShape(s3d, plates, g)); this.addChild(s3d); // Create edge shapes directly, don't make them appear in graph int nInternalEdges = 0; for (Iterator<EdgeLine> it = internalEdges.keySet().iterator(); it.hasNext(); ) { EdgeLine el = it.next(); nInternalEdges += el.getNumberOfEdges(); } if (nInternalEdges > 0) { DoubleBuffer nioInternalEdges = ByteBuffer.allocateDirect(nInternalEdges * 2 * 3 * 8) .order(ByteOrder.nativeOrder()) .asDoubleBuffer(); // create edge coords for (Iterator<EdgeLine> it = internalEdges.keySet().iterator(); it.hasNext(); ) { EdgeLine el = it.next(); nioInternalEdges.put(el.getCoords(grid)); } LineArray la = new NioLineArray(nInternalEdges * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3); la.setCoordRefBuffer(new J3DBuffer(nioInternalEdges)); int colSize = nInternalEdges * 2 * 3; FloatBuffer nioInternalColors = ByteBuffer.allocateDirect(colSize * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); float[] colors = getColorForOrder(g, 2); for (int i = 0; i < colSize; i += 3) nioInternalColors.put(colors); la.setColorRefBuffer(new J3DBuffer(nioInternalColors)); la.setUserData(new int[] {g, 2}); a = new Appearance(); // pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, // PolygonAttributes.CULL_NONE, 0); // pa.setPolygonOffset(4); // pa.setPolygonOffsetFactor(4); // a.setPolygonAttributes(pa); // LineAttributes lat = new LineAttributes(); // lat.setLineAntialiasingEnable(true); // a.setLineAttributes(lat); // RenderingAttributes ra = new RenderingAttributes(); // ra.setAlphaTestFunction(RenderingAttributes.GREATER); // ra.setAlphaTestValue(0.5f); // a.setRenderingAttributes(ra); s3d = new Shape3D(la, a); PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); s3d.setCapability(Node.ALLOW_PICKABLE_READ); s3d.setCapability(Node.ALLOW_PICKABLE_WRITE); s3d.setPickable(false); // by default, see actions s3d.setUserData(this); // this object will handle edges this.addChild(s3d); allEdgeShapes.add(s3d); } // Now, create external edge int nExternalEdges = 0; for (Iterator<EdgeLine> it = externalEdges.keySet().iterator(); it.hasNext(); ) { EdgeLine el = it.next(); nExternalEdges += el.getNumberOfEdges(); } if (nExternalEdges > 0) { DoubleBuffer nioExternalEdges = ByteBuffer.allocateDirect(nExternalEdges * 2 * 3 * 8) .order(ByteOrder.nativeOrder()) .asDoubleBuffer(); // create edge coords for (Iterator<EdgeLine> it = externalEdges.keySet().iterator(); it.hasNext(); ) { EdgeLine el = it.next(); nioExternalEdges.put(el.getCoords(grid)); } LineArray la = new NioLineArray(nExternalEdges * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3); la.setCoordRefBuffer(new J3DBuffer(nioExternalEdges)); int colSize = nExternalEdges * 2 * 3; FloatBuffer nioExternalColors = ByteBuffer.allocateDirect(colSize * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); float[] colors = getColorForOrder(g, 4); for (int i = 0; i < colSize; i += 3) nioExternalColors.put(colors); la.setColorRefBuffer(new J3DBuffer(nioExternalColors)); la.setUserData(new int[] {g, 4}); a = new Appearance(); // pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, // PolygonAttributes.CULL_NONE, 0); // pa.setPolygonOffset(3); // pa.setPolygonOffsetFactor(3); // a.setPolygonAttributes(pa); s3d = new Shape3D(la, a); PickTool.setCapabilities(s3d, PickTool.INTERSECT_FULL); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ); s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); s3d.setCapability(Node.ALLOW_PICKABLE_READ); s3d.setCapability(Node.ALLOW_PICKABLE_WRITE); s3d.setPickable(false); // by default, see actions s3d.setUserData(this); // this object will handle edges this.addChild(s3d); allEdgeShapes.add(s3d); } totalQuads += plates.length; totalInternalEdges += nInternalEdges; totalExternalEdges += nExternalEdges; } System.out.println("Total quads: " + totalQuads); System.out.println("Total Internal Plate edges: " + totalInternalEdges); System.out.println("Total External Plate edges: " + totalExternalEdges); }