private void drawMesh(Graphics g) { try { for (Enumeration parts = previewTree.getMesh().elements(); parts.hasMoreElements(); ) { MeshPart m = (MeshPart) parts.nextElement(); if (m.getLevel() == previewTree.getShowLevel()) { g.setColor(thisLevelColor); } else { g.setColor(otherLevelColor); } drawMeshPart(g, m); } } catch (Exception e) { // System.err.println("nummer "+i); e.printStackTrace(); } }
public void paint(Graphics g) { if (previewTree.getMesh() == null) { try { previewTree.remake(); } catch (Exception e) { System.err.println(e); e.printStackTrace(); } return; } Graphics2D g2 = (Graphics2D) g; // turn antialiasing on RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.addRenderingHints(rh); try { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(bgClr); if (perspective == PERSPECTIVE_FRONT) g.fillRect(0, 0, getWidth() - 1, getHeight()); else g.fillRect(0, 0, getWidth(), getHeight() - 1); // g.drawRect(10,10,getWidth()-20,getHeight()-20); initTransform(g); if (draft) previewTree.traverseTree(new StemDrawer(g)); // drawStems(g); else { drawMesh(g); // drawLeaves(g); previewTree.traverseTree(new LeafDrawer(g)); } // DEBUG // Enumeration e = previewTree.allStems(previewTree.getShowLevel()-1); // Stem stem = (Stem)e.nextElement(); // Vector diag = stem.getMaxPoint().sub(stem.getMinPoint()); // Vector orig = stem.getTransformation().getT(); // setOrigin(new Vector(orig.getX(),orig.getY(),0)); // Vector max = stem.getMaxPoint(); // Vector min = stem.getMinPoint(); // // // get greatest distance from orig // double x1 = Math.abs(min.getX())-Math.abs(orig.getX()); // double x2 = Math.abs(max.getX())-Math.abs(orig.getX()); // double x = Math.max(Math.abs(x1),Math.abs(x2)); // double y1 = Math.abs(min.getY())-Math.abs(orig.getY()); // double y2 = Math.abs(max.getY())-Math.abs(orig.getY()); // double y = Math.max(Math.abs(y1),Math.abs(y2)); // // Vector av = max.sub(orig).add(min.sub(orig)); // //av=av.mul(0.5); // //// double dw = Math.sqrt(x*x+y*y)*2; // double dw = Math.sqrt(av.getX()*av.getX()+av.getY()*av.getY())*2; // double minw = -dw/2; // // double dh = diag.getZ(); // double minh = min.getZ(); // // g.setColor(Color.RED); // drawLine(g,orig,min); // drawLine(g,orig,max); // // g.setColor(Color.GREEN); // drawLine(g,orig,orig.add(new Vector(dw/2,dw/2,0))); // // g.setColor(Color.BLUE); // drawLine(g,orig,av.add(orig)); //// drawLine(g,orig,new Vector(dw/4,dw/4,orig.getZ())); // //// g.setColor(Color.BLUE); //// drawLine(g,stem.getTransformation().getT(),stem.getMaxPoint().sub(stem.getMinPoint())); } catch (Exception e) { // do nothing, don't draw } }