/* Copyright (c) 2010, Chris Want Please see BSD style licence at the end of this file */ class ScalarField extends Field { int xRes, yRes, zRes; int numScalars=1; int activeScalars=0; float[][][][] data; float[] scalMin, scalMax; boolean hasInvalid; float[] invalid=null; ScalarField() { } ScalarField(float[][][] data, int xRes, int yRes, int zRes) { this(data, xRes, yRes, zRes, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } ScalarField(float[][][] data, int xRes, int yRes, int zRes, float xMin, float xMax, float yMin, float yMax, float zMin, float zMax) { numScalars = 1; activeScalars = 0; this.data = new float[numScalars][][][]; setData(data); this.xRes = xRes; this.yRes = yRes; this.zRes = zRes; this.xMin = xMin; this.yMin = yMin; this.zMin = zMin; this.xMax = xMax; this.yMax = yMax; this.zMax = zMax; this.hasInvalid=false; computeMinMax(); } ScalarField(int numScalars, int xRes, int yRes, int zRes, float xMin, float xMax, float yMin, float yMax, float zMin, float zMax) { this.numScalars = numScalars; this.xRes = xRes; this.yRes = yRes; this.zRes = zRes; this.xMin = xMin; this.yMin = yMin; this.zMin = zMin; this.xMax = xMax; this.yMax = yMax; this.zMax = zMax; this.hasInvalid=false; } ScalarField(String filename) { BufferedReader reader; String line; float value; numScalars = 1; activeScalars = 0; this.data = new float[numScalars][][][]; xRes = 201; yRes = 201; zRes = 201; xMin = yMin = zMin = -1.0; xMax = yMax = zMax = -1.0; data[activeScalars] = new float[zRes][yRes][xRes]; reader = createReader(filename); try { // Throw out first two lines line = reader.readLine(); line = reader.readLine(); for (int k=0; k scalMax[arr]) { scalMin[arr] = scalMax[arr] = value; } else { if (value < scalMin[arr]) { scalMin[arr] = value; } else if (value > scalMax[arr]) { scalMax[arr] = value; } } } } } } } void computeMinMax() { float value; boolean isInvalid; if (hasInvalid==false) { computeMinMaxValid(); return; } scalMin = new float[numScalars]; scalMax = new float[numScalars]; for (int arr=0; arr < numScalars; ++arr) { scalMin[arr] = 1.0; scalMax[arr] = -1.0; for (int k=0; k scalMax[arr]) { scalMin[arr] = scalMax[arr] = value; } else { if (value < scalMin[arr]) { scalMin[arr] = value; } else if (value > scalMax[arr]) { scalMax[arr] = value; } } } } } } } float getScalMin(int arr) { return scalMin[arr]; } float getScalMin() { return getScalMin(activeScalars); } float getScalMax(int arr) { return scalMax[arr]; } float getScalMax() { return getScalMax(activeScalars); } float getUnit(int arr, int i, int j, int k) { return ((data[arr][i][j][k] - scalMin[arr]) / (scalMax[arr] - scalMin[arr])); } float getUnit(int i, int j, int k) { return getUnit(activeScalars, i, j, k); } float getX(int i) { if (xRes == 1) return xMin; return ( (xMin*(xRes-1-i) + xMax*i) / (xRes - 1)); } float getY(int i) { if (yRes == 1) return yMin; return ( (yMin*(yRes-1-i) + yMax*i) / (yRes - 1)); } float getZ(int i) { if (zRes == 1) return zMin; return ( (zMin*(zRes-1-i) + zMax*i) / (zRes - 1)); } void destroy() { data = null; } } /* 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) */