/* Copyright (c) 2010, Chris Want Please see BSD style licence at the end of this file */ class SliceElement extends ImagePlacementElement { SliceElement(float x, float y, float w, float h) { super(x, y, w, h); } SliceElement(float x, float y, float w, float h, PImage pi) { super(x, y, w, h, pi); } void draw(PGraphics out) { if (redraw) { out.fill(0); out.stroke(204); out.rectMode(CORNER); out.rect(getX(x), getY(y), w-1, h-1); super.draw(out); } redraw = false; } } class SlicePanel extends GraphicsPlacementElement { ImagePlacementElement sliceXY=null, sliceXZ=null, sliceYZ=null; DataModel data; ControlModel control; PFont font; int fontSize; int w_xy, w_xz, w_yz, h_xy, h_xz, h_yz; int x_xy, x_xz, x_yz, y_xy, y_xz, y_yz; int spacing_x = 50; int spacing_y = 50; SlicePanel(DataModel data, ControlModel control, PFont font, float x, float y, float w, float h) { super(x, y, w, h, P2D); this.data = data; this.control = control; this.fontSize = 10; this.font = loadFont("Verdana-10.vlw"); initPanel(data.krig.out, EST); flagRedraw(); } void initPanel(ScalarField sc, int arr) { float w_x, w_y, w_z, c_y, c_z; float aspect_x, aspect_y; w_x = sc.xMax-sc.xMin; w_y = sc.yMax-sc.yMin; if (sc.zRes == 1) { w_z = 0.0; } else { w_z = sc.zMax-sc.zMin; } aspect_x = (w_x + w_z) / (w_y + w_z); if (aspect_x > 1.0) { aspect_y = 1.0 / aspect_x; aspect_x = 1.0; } else { aspect_y = 1.0; } w_xy = (int) round((w - spacing_x) * w_x * aspect_x / (w_x + w_z)); h_xy = (int) round((h - spacing_y) * w_y * aspect_y / (w_y + w_z)); w_xz = w_xy; h_xz = (int) round((h - spacing_y) * w_z * aspect_y / (w_y + w_z)); w_yz = h_xz; h_yz = h_xy; x_yz = (int) round(getX( (w - spacing_x - w_yz - w_xy) / 2.0 )); y_yz = (int) round(getY( (h - spacing_y - h_xy - h_xz) / 2.0 )); x_xy = x_yz + w_yz + spacing_x; y_xy = y_yz; x_xz = x_yz + w_yz + spacing_x; y_xz = y_yz + h_yz + spacing_y; sliceXY = new SliceElement(x_xy, y_xy, w_xy, h_xy, control.getXYSlice()); sliceXY.setParent(this); if (sc.zRes > 1) { sliceXZ = new SliceElement(x_xz, y_xz, w_xz, h_xz, control.getXZSlice()); sliceXZ.setParent(this); sliceYZ = new SliceElement(x_yz, y_yz, w_yz, h_yz, control.getYZSlice()); sliceYZ.setParent(this); } else { sliceXZ = null; sliceYZ = null; } } void draw(PGraphics out) { boolean modified=false; pi.beginDraw(); pi.textMode(SCREEN); if (redraw) { float w1, w2; String s1, s2; //pi.translate(-x, -y); pi.fill(0,0,0); pi.rect(0, 0, w, h); sliceXY.draw(pi); if (data.krig.out.zRes > 1) { sliceXZ.draw(pi); sliceYZ.draw(pi); } NumberFormat numFormat; numFormat = new DecimalFormat("#.00"); pi.textFont(font, fontSize); pi.textMode(SCREEN); s1 = numFormat.format(data.krig.out.xMin); s2 = numFormat.format(data.krig.out.xMax); w1 = pi.textWidth(s1); w2 = pi.textWidth(s2); pi.stroke(96); pi.line(x_yz+w_yz+1, y_yz, x_xy-2, y_yz); // yMax line pi.line(x_yz+w_yz+1, y_yz+h_yz-1, x_xy-2, y_yz+h_yz-1); // yMin line pi.line(x_xy, y_xy+h_xy+1, x_xz, y_xz-2); // xMin line pi.line(x_xy+w_xy-1, y_xy+h_xy+1, x_xz+w_xz-1, y_xz-2); // xMax line if (data.krig.out.zRes > 1) { pi.line(x_yz, y_yz+h_yz+1, x_xz, y_xz+h_xz); // zMin line pi.line(x_yz+w_yz, y_yz+h_yz+1, x_xz-1, y_xz); // zMax line } // X axis arrow pi.fill(96); pi.stroke(96); pi.line(x_xy+w1+9, y_xy+h_xy+spacing_y/2, x_xy+w_xy/2-7, y_xy+h_xy+spacing_y/2); pi.line(x_xy+w_xy/2+7, y_xy+h_xy+spacing_y/2, x_xy+w_xy-w2-9, y_xy+h_xy+spacing_y/2); pi.noStroke(); pi.triangle(x_xy+w_xy-w2-9, y_xy+h_xy+spacing_y/2, x_xy+w_xy-w2-14, y_xy+h_xy+spacing_y/2-5, x_xy+w_xy-w2-14, y_xy+h_xy+spacing_y/2+5); // Y axis arrow pi.fill(96); pi.stroke(96); pi.line(x_yz+w_yz+spacing_x/2, y_yz+fontSize+5, x_yz+w_yz+spacing_x/2, y_yz+h_yz/2-fontSize/2-5); pi.line(x_yz+w_yz+spacing_x/2, y_yz+h_yz/2+fontSize/2+5, x_yz+w_yz+spacing_x/2, y_yz+h_yz-fontSize-5); pi.noStroke(); pi.triangle(x_yz+w_yz+spacing_x/2, y_yz+fontSize+5, x_yz+w_yz+spacing_x/2-5, y_yz+fontSize+10, x_yz+w_yz+spacing_x/2+5, y_yz+fontSize+10); pi.fill(255); pi.textAlign(LEFT, CENTER); pi.text(s1, x_xy+4, y_xy+h_xy+spacing_y/2); // xMin pi.textAlign(CENTER, CENTER); pi.text("X", x_xy+w_xy/2, y_xy+h_xy+spacing_y/2); // X label pi.textAlign(RIGHT, CENTER); pi.text(s2, x_xy+w_xy-4, y_xy+h_xy+spacing_y/2); // xMax pi.fill(255); pi.textAlign(CENTER, TOP); pi.text(numFormat.format(data.krig.out.yMax), x_xy-spacing_x/2, y_xy+2); pi.textAlign(CENTER, CENTER); pi.text("Y", x_xy-spacing_x/2, y_xy+h_xy/2); pi.textAlign(CENTER, BOTTOM); pi.text(numFormat.format(data.krig.out.yMin), x_xy-spacing_x/2, y_xy+h_xy-1); if (data.krig.out.zRes > 1) { pi.fill(255); pi.textAlign(LEFT, TOP); pi.text(numFormat.format(data.krig.out.zMax), x_yz+w_yz, y_yz+h_yz+2); pi.textAlign(CENTER, CENTER); pi.text("Z", x_yz+w_yz*.75+spacing_x/2, y_yz+h_yz+w_yz*.25+spacing_y/2); pi.textAlign(RIGHT, BOTTOM); pi.text(numFormat.format(data.krig.out.zMin), x_xz-2, y_xz+h_xz); } else { pi.fill(255); pi.textAlign(CENTER, BOTTOM); pi.text("Z=", x_xy-spacing_x/2, y_xy+h_xy+spacing_y/2-2); pi.textAlign(CENTER, TOP); pi.text(numFormat.format(data.krig.out.zMin), x_xy-spacing_x/2, y_xy+h_xy+spacing_y/2+2); } super.draw(out); modified = true; redraw=false; } if (control.updateProbe()) { //data.scene.setUpdateView(true); drawMouse(pi); flagRedraw(); modified = true; } pi.endDraw(); if (modified) out.image(pi, x, y); } void drawMouse(PGraphics out) { out.fill(255,255,0); out.stroke(0,0,0); out.ellipseMode(CENTER); out.ellipse(mouseX - getScreenX(0), mouseY - getScreenY(0), 5, 5); } void flagRedraw() { super.flagRedraw(); sliceXY.flagRedraw(); if (sliceXZ!=null) sliceXZ.flagRedraw(); if (sliceYZ!=null) sliceYZ.flagRedraw(); } void mousePressed() { if (mouseOver()) { control.clicked = control.probe; control.updateLambdas(); } } void updateState() { initPanel(data.krig.out, EST); flagRedraw(); } } /* Copyright (c) 2010, Chris Want, Research Support Group, AICT, University of Alberta. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Contributors: Chris Want (University of Alberta) */