/* Copyright (c) 2010, Chris Want Please see BSD style licence at the end of this file */ class DataModel { Kriging krig=null; IsoSurface surfaces[]=null; IsoSurface invalidSurface=null; CDF dataCDF = null; CDF modelCDF = null; int numSurf = 5; float[] lambda; DataModel() { krig = new OrdinaryKriging(); krig.demo(); //krig = new SimpleKriging(); updateKriging(); } void updateKriging() { krig.interpolate(); krig.out.computeMinMax(); dataCDF = new CDF(krig.kd.value); modelCDF = new CDF(krig.out); updateIsoSurfaces(); } void updateIsoSurfaces() { int i; float val; surfaces = new IsoSurface[numSurf]; for (i=0; i < numSurf; ++i) { val = (2.0*i+1.0) / (2.0 * numSurf); surfaces[i] = new IsoSurface(krig.out, EST); surfaces[i].updateUnit(val); surfaces[i].zUpOn(); surfaces[i].setColor(unitToColor(val)); } if (krig.out.hasInvalid) { invalidSurface = new IsoSurface(krig.out, EST); invalidSurface.updateInvalid(); invalidSurface.zUpOn(); invalidSurface.setColor(color(255, 255, 255)); } else { invalidSurface = null; } } PImage getXYSlice(ScalarField sc, int layer) { int i, j; PImage slice = createImage(sc.xRes, sc.yRes, ARGB); slice.loadPixels(); for (i=0; i < sc.xRes; ++i) { for (j=0; j < sc.yRes; ++j) { color c; if (sc.isInvalid(i, sc.yRes - j - 1, layer)) { c = color(0,0); } else { float unit; unit = sc.getUnit(i, sc.yRes - j - 1, layer); c = unitToColor(unit); } slice.pixels[j*sc.xRes + i] = c; } } slice.updatePixels(); return slice; } PImage getXZSlice(ScalarField sc, int layer) { int i, j; PImage slice = createImage(sc.xRes, sc.zRes, ARGB); slice.loadPixels(); for (i=0; i < sc.xRes; ++i) { for (j=0; j < sc.zRes; ++j) { color c; if (sc.isInvalid(i, layer, sc.zRes - j - 1)) { c = color(0,0); } else { float unit; unit = sc.getUnit(i, layer, sc.zRes - j - 1); c = unitToColor(unit); } slice.pixels[j*sc.xRes + i] = c; } } slice.updatePixels(); return slice; } PImage getYZSlice(ScalarField sc, int layer) { int i, j; PImage slice = createImage(sc.zRes, sc.yRes, ARGB); slice.loadPixels(); for (i=0; i < sc.yRes; ++i) { for (j=0; j < sc.zRes; ++j) { color c; if (sc.isInvalid(layer, sc.yRes - i - 1, j)) { c = color(0,0); } else { float unit; unit = sc.getUnit(layer, sc.yRes - i - 1, j); c = unitToColor(unit); } slice.pixels[i*sc.zRes + j] = c; } } slice.updatePixels(); return slice; } int getNearestCoord(int res, float here, float mn, float mx) { int a; a = round((res - 1) * (here - mn) / (mx - mn)); if (a < 0) a = 0; if (a > (res - 1)) a = res - 1; return a; } int[] getNearestCell(float[] point) { int[] cell = new int[3]; cell[0] = getNearestCoord(krig.out.xRes, point[0], krig.out.xMin, krig.out.xMax); cell[1] = getNearestCoord(krig.out.yRes, point[1], krig.out.yMin, krig.out.yMax); cell[2] = getNearestCoord(krig.out.zRes, point[2], krig.out.zMin, krig.out.zMax); return cell; } void computeLambda(KrigData dat, float x, float y, float z) { lambda = krig.computeLambda(dat, x, y, z); } float[] getLambda() { return lambda; } } /* 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) */