// // Gridded3DSet.java // /* VisAD system for interactive analysis and visualization of numerical data. Copyright (C) 1996 - 2002 Bill Hibbard, Curtis Rueden, Tom Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and Tommy Jasmin. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ package visad; import java.io.*; /** Gridded3DSet represents a finite set of samples of R^3.

*/ public class Gridded3DSet extends GriddedSet { int LengthX, LengthY, LengthZ; float LowX, HiX, LowY, HiY, LowZ, HiZ; /** a 3-D set whose topology is a lengthX x lengthY x lengthZ grid, with null errors, CoordinateSystem and Units are defaults from type */ public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, int lengthZ) throws VisADException { this(type, samples, lengthX, lengthY, lengthZ, null, null, null); } /** a 3-D set whose topology is a lengthX x lengthY x lengthZ grid; samples array is organized float[3][number_of_samples] where lengthX * lengthY * lengthZ = number_of_samples; samples must form a non-degenerate 3-D grid (no bow-tie-shaped grid cubes); the X component increases fastest and the Z component slowest in the second index of samples; coordinate_system and units must be compatible with defaults for type, or may be null; errors may be null */ public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, int lengthZ, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors) throws VisADException { this(type, samples, lengthX, lengthY, lengthZ, coord_sys, units, errors, true, true); } public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, int lengthZ, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors, boolean copy) throws VisADException { this(type, samples, lengthX, lengthY, lengthZ, coord_sys, units, errors, copy, true); } public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, int lengthZ, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors, boolean copy, boolean test) throws VisADException { super(type, samples, make_lengths(lengthX, lengthY, lengthZ), coord_sys, units, errors, copy); LowX = Low[0]; HiX = Hi[0]; LengthX = Lengths[0]; LowY = Low[1]; HiY = Hi[1]; LengthY = Lengths[1]; LowZ = Low[2]; HiZ = Hi[2]; LengthZ = Lengths[2]; if (Samples != null && Lengths[0] > 1 && Lengths[1] > 1 && Lengths[2] > 1) { for (int i=0; i 0; for (int k=0; k 0 != Pos) || (( ( (v101[1]-v100[1])*(v001[2]-v101[2]) // test 2 - (v101[2]-v100[2])*(v001[1]-v101[1]) ) *(v111[0]-v101[0]) ) + ( ( (v101[2]-v100[2])*(v001[0]-v101[0]) - (v101[0]-v100[0])*(v001[2]-v101[2]) ) *(v111[1]-v101[1]) ) + ( ( (v101[0]-v100[0])*(v001[1]-v101[1]) - (v101[1]-v100[1])*(v001[0]-v101[0]) ) *(v111[2]-v101[2]) ) > 0 != Pos) || (( ( (v001[1]-v101[1])*(v000[2]-v001[2]) // test 3 - (v001[2]-v101[2])*(v000[1]-v001[1]) ) *(v011[0]-v001[0]) ) + ( ( (v001[2]-v101[2])*(v000[0]-v001[0]) - (v001[0]-v101[0])*(v000[2]-v001[2]) ) *(v011[1]-v001[1]) ) + ( ( (v001[0]-v101[0])*(v000[1]-v001[1]) - (v001[1]-v101[1])*(v000[0]-v001[0]) ) *(v011[2]-v001[2]) ) > 0 != Pos) || (( ( (v000[1]-v001[1])*(v100[2]-v000[2]) // test 4 - (v000[2]-v001[2])*(v100[1]-v000[1]) ) *(v010[0]-v000[0]) ) + ( ( (v000[2]-v001[2])*(v100[0]-v000[0]) - (v000[0]-v001[0])*(v100[2]-v000[2]) ) *(v010[1]-v000[1]) ) + ( ( (v000[0]-v001[0])*(v100[1]-v000[1]) - (v000[1]-v001[1])*(v100[0]-v000[0]) ) *(v010[2]-v000[2]) ) > 0 != Pos) || (( ( (v110[1]-v111[1])*(v010[2]-v110[2]) // test 5 - (v110[2]-v111[2])*(v010[1]-v110[1]) ) *(v100[0]-v110[0]) ) + ( ( (v110[2]-v111[2])*(v010[0]-v110[0]) - (v110[0]-v111[0])*(v010[2]-v110[2]) ) *(v100[1]-v110[1]) ) + ( ( (v110[0]-v111[0])*(v010[1]-v110[1]) - (v110[1]-v111[1])*(v010[0]-v110[0]) ) *(v100[2]-v110[2]) ) > 0 != Pos) || (( ( (v111[1]-v011[1])*(v110[2]-v111[2]) // test 6 - (v111[2]-v011[2])*(v110[1]-v111[1]) ) *(v101[0]-v111[0]) ) + ( ( (v111[2]-v011[2])*(v110[0]-v111[0]) - (v111[0]-v011[0])*(v110[2]-v111[2]) ) *(v101[1]-v111[1]) ) + ( ( (v111[0]-v011[0])*(v110[1]-v111[1]) - (v111[1]-v011[1])*(v110[0]-v111[0]) ) *(v101[2]-v111[2]) ) > 0 != Pos) || (( ( (v011[1]-v010[1])*(v111[2]-v011[2]) // test 7 - (v011[2]-v010[2])*(v111[1]-v011[1]) ) *(v001[0]-v011[0]) ) + ( ( (v011[2]-v010[2])*(v111[0]-v011[0]) - (v011[0]-v010[0])*(v111[2]-v011[2]) ) *(v001[1]-v011[1]) ) + ( ( (v011[0]-v010[0])*(v111[1]-v011[1]) - (v011[1]-v010[1])*(v111[0]-v011[0]) ) *(v001[2]-v011[2]) ) > 0 != Pos) || (( ( (v010[1]-v110[1])*(v011[2]-v010[2]) // test 8 - (v010[2]-v110[2])*(v011[1]-v010[1]) ) *(v000[0]-v010[0]) ) + ( ( (v010[2]-v110[2])*(v011[0]-v010[0]) - (v010[0]-v110[0])*(v011[2]-v010[2]) ) *(v000[1]-v010[1]) ) + ( ( (v010[0]-v110[0])*(v011[1]-v010[1]) - (v010[1]-v110[1])*(v011[0]-v010[0]) ) *(v000[2]-v010[2]) ) > 0 != Pos)) { throw new SetException("Gridded3DSet: samples do not form " +"a valid grid ("+i+","+j+","+k+")"); } } } } } // end if (test) } } /** a 3-D set with manifold dimension = 2, with null errors, CoordinateSystem and Units are defaults from type */ public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY) throws VisADException { this(type, samples, lengthX, lengthY, null, null, null); } /** a 3-D set with manifold dimension = 2; samples array is organized float[3][number_of_samples] where lengthX * lengthY = number_of_samples; no geometric constraint on samples; the X component increases fastest in the second index of samples; coordinate_system and units must be compatible with defaults for type, or may be null; errors may be null */ public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors) throws VisADException { this(type, samples, lengthX, lengthY, coord_sys, units, errors, true); } public Gridded3DSet(MathType type, float[][] samples, int lengthX, int lengthY, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors, boolean copy) throws VisADException { super(type, samples, Gridded2DSet.make_lengths(lengthX, lengthY), coord_sys, units, errors, copy); LowX = Low[0]; HiX = Hi[0]; LengthX = Lengths[0]; LowY = Low[1]; HiY = Hi[1]; LengthY = Lengths[1]; LowZ = Low[2]; HiZ = Hi[2]; // no Samples consistency test } /** a 3-D set with manifold dimension = 1, with null errors, CoordinateSystem and Units are defaults from type */ public Gridded3DSet(MathType type, float[][] samples, int lengthX) throws VisADException { this(type, samples, lengthX, null, null, null); } /** a 3-D set with manifold dimension = 1; samples array is organized float[3][number_of_samples] where lengthX = number_of_samples; no geometric constraint on samples; coordinate_system and units must be compatible with defaults for type, or may be null; errors may be null */ public Gridded3DSet(MathType type, float[][] samples, int lengthX, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors) throws VisADException { this(type, samples, lengthX, coord_sys, units, errors, true); } public Gridded3DSet(MathType type, float[][] samples, int lengthX, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors, boolean copy) throws VisADException { super(type, samples, Gridded1DSet.make_lengths(lengthX), coord_sys, units, errors, copy); LowX = Low[0]; HiX = Hi[0]; LengthX = Lengths[0]; LowY = Low[1]; HiY = Hi[1]; LowZ = Low[2]; HiZ = Hi[2]; // no Samples consistency test } static int[] make_lengths(int lengthX, int lengthY, int lengthZ) { int[] lens = new int[3]; lens[0] = lengthX; lens[1] = lengthY; lens[2] = lengthZ; return lens; } /** convert an array of 1-D indices to an array of values in R^DomainDimension */ public float[][] indexToValue(int[] index) throws VisADException { int length = index.length; if (Samples == null) { // not used - over-ridden by Linear3DSet.indexToValue int indexX, indexY, indexZ; int k; float[][] grid = new float[ManifoldDimension][length]; for (int i=0; i 1"); } // avoid any ArrayOutOfBounds exceptions by taking the shortest length int length = Math.min(grid[0].length, grid[1].length); float[][] value = new float[3][length]; for (int i=0; i LengthX-0.5) || (gy > LengthY-0.5) ) { value[0][i] = value[1][i] = value[2][i] = Float.NaN; continue; } // calculate closest integer variables int igx = (int) gx; int igy = (int) gy; if (igx < 0) igx = 0; if (igx > LengthX-2) igx = LengthX-2; if (igy < 0) igy = 0; if (igy > LengthY-2) igy = LengthY-2; // set up conversion to 1D Samples array int[][] s = { {LengthX*igy+igx, // (0, 0) LengthX*(igy+1)+igx}, // (0, 1) {LengthX*igy+igx+1, // (1, 0) LengthX*(igy+1)+igx+1} }; // (1, 1) if (gx+gy-igx-igy-1 <= 0) { // point is in LOWER triangle for (int j=0; j<3; j++) { value[j][i] = Samples[j][s[0][0]] + (gx-igx)*(Samples[j][s[1][0]]-Samples[j][s[0][0]]) + (gy-igy)*(Samples[j][s[0][1]]-Samples[j][s[0][0]]); } } else { // point is in UPPER triangle for (int j=0; j<3; j++) { value[j][i] = Samples[j][s[1][1]] + (1+igx-gx)*(Samples[j][s[0][1]]-Samples[j][s[1][1]]) + (1+igy-gy)*(Samples[j][s[1][0]]-Samples[j][s[1][1]]); } } /* for (int j=0; j<3; j++) { if (value[j][i] != value[j][i]) { System.out.println("gridToValue2D: bad Samples j = " + j + " gx, gy = " + gx + " " + gy + " " + s[0][0] + " " + s[0][1] + " " + s[1][0] + " " + s[1][1]); } } */ } return value; } private float[][] gridToValue3D(float[][] grid) throws VisADException { if (Lengths[0] < 2 || Lengths[1] < 2 || Lengths[2] < 2) { throw new SetException("Gridded3DSet.gridToValue: requires all grid " + "dimensions to be > 1"); } // avoid any ArrayOutOfBounds exceptions by taking the shortest length int length = Math.min(grid[0].length, grid[1].length); length = Math.min(length, grid[2].length); float[][] value = new float[3][length]; for (int i=0; i LengthX-0.5) || (gy > LengthY-0.5) || (gz > LengthZ-0.5) ) { value[0][i] = value[1][i] = value[2][i] = Float.NaN; continue; } // calculate closest integer variables int igx, igy, igz; if (gx < 0) igx = 0; else if (gx > LengthX-2) igx = LengthX - 2; else igx = (int) gx; if (gy < 0) igy = 0; else if (gy > LengthY-2) igy = LengthY - 2; else igy = (int) gy; if (gz < 0) igz = 0; else if (gz > LengthZ-2) igz = LengthZ - 2; else igz = (int) gz; // determine tetrahedralization type boolean evencube = ((igx+igy+igz) % 2 == 0); // calculate distances from integer grid point float s, t, u; if (evencube) { s = gx - igx; t = gy - igy; u = gz - igz; } else { s = 1 + igx - gx; t = 1 + igy - gy; u = 1 + igz - gz; } // Define vertices of grid box int zadd = LengthY*LengthX; int base = igz*zadd + igy*LengthX + igx; int ai = base+zadd; // 0, 0, 1 int bi = base+zadd+1; // 1, 0, 1 int ci = base+zadd+LengthX+1; // 1, 1, 1 int di = base+zadd+LengthX; // 0, 1, 1 int ei = base; // 0, 0, 0 int fi = base+1; // 1, 0, 0 int gi = base+LengthX+1; // 1, 1, 0 int hi = base+LengthX; // 0, 1, 0 float[] A = new float[3]; float[] B = new float[3]; float[] C = new float[3]; float[] D = new float[3]; float[] E = new float[3]; float[] F = new float[3]; float[] G = new float[3]; float[] H = new float[3]; if (evencube) { A[0] = Samples[0][ai]; A[1] = Samples[1][ai]; A[2] = Samples[2][ai]; B[0] = Samples[0][bi]; B[1] = Samples[1][bi]; B[2] = Samples[2][bi]; C[0] = Samples[0][ci]; C[1] = Samples[1][ci]; C[2] = Samples[2][ci]; D[0] = Samples[0][di]; D[1] = Samples[1][di]; D[2] = Samples[2][di]; E[0] = Samples[0][ei]; E[1] = Samples[1][ei]; E[2] = Samples[2][ei]; F[0] = Samples[0][fi]; F[1] = Samples[1][fi]; F[2] = Samples[2][fi]; G[0] = Samples[0][gi]; G[1] = Samples[1][gi]; G[2] = Samples[2][gi]; H[0] = Samples[0][hi]; H[1] = Samples[1][hi]; H[2] = Samples[2][hi]; } else { G[0] = Samples[0][ai]; G[1] = Samples[1][ai]; G[2] = Samples[2][ai]; H[0] = Samples[0][bi]; H[1] = Samples[1][bi]; H[2] = Samples[2][bi]; E[0] = Samples[0][ci]; E[1] = Samples[1][ci]; E[2] = Samples[2][ci]; F[0] = Samples[0][di]; F[1] = Samples[1][di]; F[2] = Samples[2][di]; C[0] = Samples[0][ei]; C[1] = Samples[1][ei]; C[2] = Samples[2][ei]; D[0] = Samples[0][fi]; D[1] = Samples[1][fi]; D[2] = Samples[2][fi]; A[0] = Samples[0][gi]; A[1] = Samples[1][gi]; A[2] = Samples[2][gi]; B[0] = Samples[0][hi]; B[1] = Samples[1][hi]; B[2] = Samples[2][hi]; } // These tests determine which tetrahedron the point is in boolean test1 = (1 - s - t - u >= 0); boolean test2 = (s - t + u - 1 >= 0); boolean test3 = (t - s + u - 1 >= 0); boolean test4 = (s + t - u - 1 >= 0); // These cases handle grid coordinates off the grid // (Different tetrahedrons must be chosen accordingly) if ( (gx < 0) || (gx > LengthX-1) || (gy < 0) || (gy > LengthY-1) || (gz < 0) || (gz > LengthZ-1) ) { boolean OX, OY, OZ, MX, MY, MZ, LX, LY, LZ; OX = OY = OZ = MX = MY = MZ = LX = LY = LZ = false; if (igx == 0) OX = true; if (igy == 0) OY = true; if (igz == 0) OZ = true; if (igx == LengthX-2) LX = true; if (igy == LengthY-2) LY = true; if (igz == LengthZ-2) LZ = true; if (!OX && !LX) MX = true; if (!OY && !LY) MY = true; if (!OZ && !LZ) MZ = true; test1 = test2 = test3 = test4 = false; // 26 cases if (evencube) { if (!LX && !LY && !LZ) test1 = true; else if ( (LX && OY && MZ) || (MX && OY && LZ) || (LX && MY && LZ) || (LX && OY && LZ) || (MX && MY && LZ) || (LX && MY && MZ) ) test2 = true; else if ( (OX && LY && MZ) || (OX && MY && LZ) || (MX && LY && LZ) || (OX && LY && LZ) || (MX && LY && MZ) ) test3 = true; else if ( (MX && LY && OZ) || (LX && MY && OZ) || (LX && LY && MZ) || (LX && LY && OZ) ) test4 = true; } else { if (!OX && !OY && !OZ) test1 = true; else if ( (OX && MY && OZ) || (MX && LY && OZ) || (OX && LY && MZ) || (OX && LY && OZ) || (MX && MY && OZ) || (OX && MY && MZ) ) test2 = true; else if ( (LX && MY && OZ) || (MX && OY && OZ) || (LX && OY && MZ) || (LX && OY && OZ) || (MX && OY && MZ) ) test3 = true; else if ( (OX && OY && MZ) || (OX && MY && OZ) || (MX && OY && LZ) || (OX && OY && LZ) ) test4 = true; } } if (test1) { for (int j=0; j<3; j++) { value[j][i] = E[j] + s*(F[j]-E[j]) + t*(H[j]-E[j]) + u*(A[j]-E[j]); } } else if (test2) { for (int j=0; j<3; j++) { value[j][i] = B[j] + (1-s)*(A[j]-B[j]) + t*(C[j]-B[j]) + (1-u)*(F[j]-B[j]); } } else if (test3) { for (int j=0; j<3; j++) { value[j][i] = D[j] + s*(C[j]-D[j]) + (1-t)*(A[j]-D[j]) + (1-u)*(H[j]-D[j]); } } else if (test4) { for (int j=0; j<3; j++) { value[j][i] = G[j] + (1-s)*(H[j]-G[j]) + (1-t)*(F[j]-G[j]) + u*(C[j]-G[j]); } } else { for (int j=0; j<3; j++) { value[j][i] = (H[j]+F[j]+A[j]-C[j])/2 + s*(C[j]+F[j]-H[j]-A[j])/2 + t*(C[j]-F[j]+H[j]-A[j])/2 + u*(C[j]-F[j]-H[j]+A[j])/2; } } } return value; } // WLH 6 Dec 2001 private int gx = -1; private int gy = -1; private int gz = -1; /** transform an array of values in R^DomainDimension to an array of non-integer grid coordinates */ public float[][] valueToGrid(float[][] value) throws VisADException { if (value.length < DomainDimension) { throw new SetException("Gridded3DSet.valueToGrid: value dimension " + value.length + " not equal to Domain dimension " + DomainDimension); } if (ManifoldDimension < 3) { throw new SetException("Gridded3DSet.valueToGrid: ManifoldDimension " + "must be 3"); } if (Lengths[0] < 2 || Lengths[1] < 2 || Lengths[2] < 2) { throw new SetException("Gridded3DSet.valueToGrid: requires all grid " + "dimensions to be > 1"); } // Avoid any ArrayOutOfBounds exceptions by taking the shortest length int length = Math.min(value[0].length, value[1].length); length = Math.min(length, value[2].length); float[][] grid = new float[ManifoldDimension][length]; // (gx, gy, gz) is the current grid box guess /* WLH 6 Dec 2001 int gx = (LengthX-1)/2; int gy = (LengthY-1)/2; int gz = (LengthZ-1)/2; */ // use value from last call as first guess, if reasonable if (gx < 0 || gx >= LengthX || gy < 0 || gy >= LengthY || gz < 0 || gz >= LengthZ) { gx = (LengthX-1)/2; gy = (LengthY-1)/2; gz = (LengthZ-1)/2; } for (int i=0; i 0) == (!evencube)^Pos); test2 = (tval2 == 0) || ((tval2 > 0) == (!evencube)^Pos); test3 = (tval3 == 0) || ((tval3 > 0) == (!evencube)^Pos); // if a test failed go to a new box int updown = (evencube) ? -1 : 1; if (!test1) gy += updown; // UP/DOWN if (!test2) gx += updown; // LEFT/RIGHT if (!test3) gz += updown; // BACK/FORWARD tetnum = 5; // Snap coordinates back onto grid in case they fell off. if (gx < 0) gx = 0; if (gy < 0) gy = 0; if (gz < 0) gz = 0; if (gx > LengthX-2) gx = LengthX-2; if (gy > LengthY-2) gy = LengthY-2; if (gz > LengthZ-2) gz = LengthZ-2; // Detect if the point is off the grid entirely if ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (!test1 || !test2 || !test3) && !offgrid ) { offgrid = true; continue; } // If all tests pass then this is the correct tetrahedron if ( ( (gx == ogx) && (gy == ogy) && (gz == ogz) ) || offgrid) { // solve point float[] M = new float[3]; float[] N = new float[3]; float[] O = new float[3]; float[] P = new float[3]; float[] X = new float[3]; float[] Y = new float[3]; for (int j=0; j<3; j++) { M[j] = (F[j]-E[j])*(A[(j+1)%3]-E[(j+1)%3]) - (F[(j+1)%3]-E[(j+1)%3])*(A[j]-E[j]); N[j] = (H[j]-E[j])*(A[(j+1)%3]-E[(j+1)%3]) - (H[(j+1)%3]-E[(j+1)%3])*(A[j]-E[j]); O[j] = (F[(j+1)%3]-E[(j+1)%3])*(A[(j+2)%3]-E[(j+2)%3]) - (F[(j+2)%3]-E[(j+2)%3])*(A[(j+1)%3]-E[(j+1)%3]); P[j] = (H[(j+1)%3]-E[(j+1)%3])*(A[(j+2)%3]-E[(j+2)%3]) - (H[(j+2)%3]-E[(j+2)%3])*(A[(j+1)%3]-E[(j+1)%3]); X[j] = value[(j+2)%3][i]*(A[(j+1)%3]-E[(j+1)%3]) - value[(j+1)%3][i]*(A[(j+2)%3]-E[(j+2)%3]) + E[(j+1)%3]*A[(j+2)%3] - E[(j+2)%3]*A[(j+1)%3]; Y[j] = value[j][i]*(A[(j+1)%3]-E[(j+1)%3]) - value[(j+1)%3][i]*(A[j]-E[j]) + E[(j+1)%3]*A[j] - E[j]*A[(j+1)%3]; } float s, t, u; // these if statements handle skewed grids float d0 = M[0]*P[0] - N[0]*O[0]; float d1 = M[1]*P[1] - N[1]*O[1]; float d2 = M[2]*P[2] - N[2]*O[2]; float ad0 = Math.abs(d0); float ad1 = Math.abs(d1); float ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { s = (N[0]*X[0] + P[0]*Y[0])/d0; t = -(M[0]*X[0] + O[0]*Y[0])/d0; } else if (ad1 > ad2) { s = (N[1]*X[1] + P[1]*Y[1])/d1; t = -(M[1]*X[1] + O[1]*Y[1])/d1; } else { s = (N[2]*X[2] + P[2]*Y[2])/d2; t = -(M[2]*X[2] + O[2]*Y[2])/d2; } /* WLH 5 April 99 if (M[0]*P[0] != N[0]*O[0]) { s = (N[0]*X[0] + P[0]*Y[0])/(M[0]*P[0] - N[0]*O[0]); t = (M[0]*X[0] + O[0]*Y[0])/(N[0]*O[0] - M[0]*P[0]); } else if (M[1]*P[1] != N[1]*O[1]) { s = (N[1]*X[1] + P[1]*Y[1])/(M[1]*P[1] - N[1]*O[1]); t = (M[1]*X[1] + O[1]*Y[1])/(N[1]*O[1] - M[1]*P[1]); } else { s = (N[2]*X[2] + P[2]*Y[2])/(M[2]*P[2] - N[2]*O[2]); t = (M[2]*X[2] + O[2]*Y[2])/(N[2]*O[2] - M[2]*P[2]); } */ d0 = A[0]-E[0]; d1 = A[1]-E[1]; d2 = A[2]-E[2]; ad0 = Math.abs(d0); ad1 = Math.abs(d1); ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { u = ( value[0][i] - E[0] - s*(F[0]-E[0]) - t*(H[0]-E[0]) ) / d0; } else if (ad1 > ad2) { u = ( value[1][i] - E[1] - s*(F[1]-E[1]) - t*(H[1]-E[1]) ) / d1; } else { u = ( value[2][i] - E[2] - s*(F[2]-E[2]) - t*(H[2]-E[2]) ) / d2; } /* WLH 5 April 99 if (A[0] != E[0]) { u = ( value[0][i] - E[0] - s*(F[0]-E[0]) - t*(H[0]-E[0]) ) / (A[0]-E[0]); } else if (A[1] != E[1]) { u = ( value[1][i] - E[1] - s*(F[1]-E[1]) - t*(H[1]-E[1]) ) / (A[1]-E[1]); } else { u = ( value[2][i] - E[2] - s*(F[2]-E[2]) - t*(H[2]-E[2]) ) / (A[2]-E[2]); } */ if (evencube) { grid[0][i] = gx+s; grid[1][i] = gy+t; grid[2][i] = gz+u; } else { grid[0][i] = gx+1-s; grid[1][i] = gy+1-t; grid[2][i] = gz+1-u; } break; } } else if (tetnum==2) { tval1 = ( (B[1]-C[1])*(F[2]-B[2]) - (B[2]-C[2])*(F[1]-B[1]) ) *(value[0][i]-B[0]) + ( (B[2]-C[2])*(F[0]-B[0]) - (B[0]-C[0])*(F[2]-B[2]) ) *(value[1][i]-B[1]) + ( (B[0]-C[0])*(F[1]-B[1]) - (B[1]-C[1])*(F[0]-B[0]) ) *(value[2][i]-B[2]); tval2 = ( (B[1]-A[1])*(C[2]-B[2]) - (B[2]-A[2])*(C[1]-B[1]) ) *(value[0][i]-B[0]) + ( (B[2]-A[2])*(C[0]-B[0]) - (B[0]-A[0])*(C[2]-B[2]) ) *(value[1][i]-B[1]) + ( (B[0]-A[0])*(C[1]-B[1]) - (B[1]-A[1])*(C[0]-B[0]) ) *(value[2][i]-B[2]); tval3 = ( (B[1]-F[1])*(A[2]-B[2]) - (B[2]-F[2])*(A[1]-B[1]) ) *(value[0][i]-B[0]) + ( (B[2]-F[2])*(A[0]-B[0]) - (B[0]-F[0])*(A[2]-B[2]) ) *(value[1][i]-B[1]) + ( (B[0]-F[0])*(A[1]-B[1]) - (B[1]-F[1])*(A[0]-B[0]) ) *(value[2][i]-B[2]); test1 = (tval1 == 0) || ((tval1 > 0) == (!evencube)^Pos); test2 = (tval2 == 0) || ((tval2 > 0) == (!evencube)^Pos); test3 = (tval3 == 0) || ((tval3 > 0) == (!evencube)^Pos); // if a test failed go to a new box if (!test1 && evencube) gx++; // RIGHT if (!test1 && !evencube) gx--; // LEFT if (!test2 && evencube) gz++; // FORWARD if (!test2 && !evencube) gz--; // BACK if (!test3 && evencube) gy--; // UP if (!test3 && !evencube) gy++; // DOWN tetnum = 5; // Snap coordinates back onto grid in case they fell off if (gx < 0) gx = 0; if (gy < 0) gy = 0; if (gz < 0) gz = 0; if (gx > LengthX-2) gx = LengthX-2; if (gy > LengthY-2) gy = LengthY-2; if (gz > LengthZ-2) gz = LengthZ-2; // Detect if the point is off the grid entirely if ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (!test1 || !test2 || !test3) && !offgrid ) { offgrid = true; continue; } // If all tests pass then this is the correct tetrahedron if ( ( (gx == ogx) && (gy == ogy) && (gz == ogz) ) || offgrid) { // solve point float[] M = new float[3]; float[] N = new float[3]; float[] O = new float[3]; float[] P = new float[3]; float[] X = new float[3]; float[] Y = new float[3]; for (int j=0; j<3; j++) { M[j] = (A[j]-B[j])*(F[(j+1)%3]-B[(j+1)%3]) - (A[(j+1)%3]-B[(j+1)%3])*(F[j]-B[j]); N[j] = (C[j]-B[j])*(F[(j+1)%3]-B[(j+1)%3]) - (C[(j+1)%3]-B[(j+1)%3])*(F[j]-B[j]); O[j] = (A[(j+1)%3]-B[(j+1)%3])*(F[(j+2)%3]-B[(j+2)%3]) - (A[(j+2)%3]-B[(j+2)%3])*(F[(j+1)%3]-B[(j+1)%3]); P[j] = (C[(j+1)%3]-B[(j+1)%3])*(F[(j+2)%3]-B[(j+2)%3]) - (C[(j+2)%3]-B[(j+2)%3])*(F[(j+1)%3]-B[(j+1)%3]); X[j] = value[(j+2)%3][i]*(F[(j+1)%3]-B[(j+1)%3]) - value[(j+1)%3][i]*(F[(j+2)%3]-B[(j+2)%3]) + B[(j+1)%3]*F[(j+2)%3] - B[(j+2)%3]*F[(j+1)%3]; Y[j] = value[j][i]*(F[(j+1)%3]-B[(j+1)%3]) - value[1][i]*(F[j]-B[j]) + B[(j+1)%3]*F[j] - B[j]*F[(j+1)%3]; } float s, t, u; // these if statements handle skewed grids float d0 = M[0]*P[0] - N[0]*O[0]; float d1 = M[1]*P[1] - N[1]*O[1]; float d2 = M[2]*P[2] - N[2]*O[2]; float ad0 = Math.abs(d0); float ad1 = Math.abs(d1); float ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { s = 1 - (N[0]*X[0] + P[0]*Y[0])/d0; t = -(M[0]*X[0] + O[0]*Y[0])/d0; } else if (ad1 > ad2) { s = 1 - (N[1]*X[1] + P[1]*Y[1])/d1; t = -(M[1]*X[1] + O[1]*Y[1])/d1; } else { s = 1 - (N[2]*X[2] + P[2]*Y[2])/d2; t = -(M[2]*X[2] + O[2]*Y[2])/d2; } /* WLH 5 April 99 if (M[0]*P[0] != N[0]*O[0]) { s = 1 - (N[0]*X[0] + P[0]*Y[0])/(M[0]*P[0] - N[0]*O[0]); t = (M[0]*X[0] + O[0]*Y[0])/(N[0]*O[0] - M[0]*P[0]); } else if (M[1]*P[1] != N[1]*O[1]) { s = 1 - (N[1]*X[1] + P[1]*Y[1])/(M[1]*P[1] - N[1]*O[1]); t = (M[1]*X[1] + O[1]*Y[1])/(N[1]*O[1] - M[1]*P[1]); } else { s = 1 - (N[2]*X[2] + P[2]*Y[2])/(M[2]*P[2] - N[2]*O[2]); t = (M[2]*X[2] + O[2]*Y[2])/(N[2]*O[2] - M[2]*P[2]); } */ d0 = F[0]-B[0]; d1 = F[1]-B[1]; d2 = F[2]-B[2]; ad0 = Math.abs(d0); ad1 = Math.abs(d1); ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { u = 1 - ( value[0][i] - B[0] - (1-s)*(A[0]-B[0]) - t*(C[0]-B[0]) ) / d0; } else if (ad1 > ad2) { u = 1 - ( value[1][i] - B[1] - (1-s)*(A[1]-B[1]) - t*(C[1]-B[1]) ) / d1; } else { u = 1 - ( value[2][i] - B[2] - (1-s)*(A[2]-B[2]) - t*(C[2]-B[2]) ) / d2; } /* WLH 5 April 99 if (F[0] != B[0]) { u = 1 - ( value[0][i] - B[0] - (1-s)*(A[0]-B[0]) - t*(C[0]-B[0]) ) / (F[0]-B[0]); } else if (F[1] != B[1]) { u = 1 - ( value[1][i] - B[1] - (1-s)*(A[1]-B[1]) - t*(C[1]-B[1]) ) / (F[1]-B[1]); } else { u = 1 - ( value[2][i] - B[2] - (1-s)*(A[2]-B[2]) - t*(C[2]-B[2]) ) / (F[2]-B[2]); } */ if (evencube) { grid[0][i] = gx+s; grid[1][i] = gy+t; grid[2][i] = gz+u; } else { grid[0][i] = gx+1-s; grid[1][i] = gy+1-t; grid[2][i] = gz+1-u; } break; } } else if (tetnum==3) { tval1 = ( (D[1]-A[1])*(H[2]-D[2]) - (D[2]-A[2])*(H[1]-D[1]) ) *(value[0][i]-D[0]) + ( (D[2]-A[2])*(H[0]-D[0]) - (D[0]-A[0])*(H[2]-D[2]) ) *(value[1][i]-D[1]) + ( (D[0]-A[0])*(H[1]-D[1]) - (D[1]-A[1])*(H[0]-D[0]) ) *(value[2][i]-D[2]); tval2 = ( (D[1]-C[1])*(A[2]-D[2]) - (D[2]-C[2])*(A[1]-D[1]) ) *(value[0][i]-D[0]) + ( (D[2]-C[2])*(A[0]-D[0]) - (D[0]-C[0])*(A[2]-D[2]) ) *(value[1][i]-D[1]) + ( (D[0]-C[0])*(A[1]-D[1]) - (D[1]-C[1])*(A[0]-D[0]) ) *(value[2][i]-D[2]); tval3 = ( (D[1]-H[1])*(C[2]-D[2]) - (D[2]-H[2])*(C[1]-D[1]) ) *(value[0][i]-D[0]) + ( (D[2]-H[2])*(C[0]-D[0]) - (D[0]-H[0])*(C[2]-D[2]) ) *(value[1][i]-D[1]) + ( (D[0]-H[0])*(C[1]-D[1]) - (D[1]-H[1])*(C[0]-D[0]) ) *(value[2][i]-D[2]); test1 = (tval1 == 0) || ((tval1 > 0) == (!evencube)^Pos); test2 = (tval2 == 0) || ((tval2 > 0) == (!evencube)^Pos); test3 = (tval3 == 0) || ((tval3 > 0) == (!evencube)^Pos); // if a test failed go to a new box if (!test1 && evencube) gx--; // LEFT if (!test1 && !evencube) gx++; // RIGHT if (!test2 && evencube) gz++; // FORWARD if (!test2 && !evencube) gz--; // BACK if (!test3 && evencube) gy++; // DOWN if (!test3 && !evencube) gy--; // UP tetnum = 5; // Snap coordinates back onto grid in case they fell off if (gx < 0) gx = 0; if (gy < 0) gy = 0; if (gz < 0) gz = 0; if (gx > LengthX-2) gx = LengthX-2; if (gy > LengthY-2) gy = LengthY-2; if (gz > LengthZ-2) gz = LengthZ-2; // Detect if the point is off the grid entirely if ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (!test1 || !test2 || !test3) && !offgrid ) { offgrid = true; continue; } // If all tests pass then this is the correct tetrahedron if ( ( (gx == ogx) && (gy == ogy) && (gz == ogz) ) || offgrid) { // solve point float[] M = new float[3]; float[] N = new float[3]; float[] O = new float[3]; float[] P = new float[3]; float[] X = new float[3]; float[] Y = new float[3]; for (int j=0; j<3; j++) { M[j] = (C[j]-D[j])*(H[(j+1)%3]-D[(j+1)%3]) - (C[(j+1)%3]-D[(j+1)%3])*(H[j]-D[j]); N[j] = (A[j]-D[j])*(H[(j+1)%3]-D[(j+1)%3]) - (A[(j+1)%3]-D[(j+1)%3])*(H[j]-D[j]); O[j] = (C[(j+1)%3]-D[(j+1)%3])*(H[(j+2)%3]-D[(j+2)%3]) - (C[(j+2)%3]-D[(j+2)%3])*(H[(j+1)%3]-D[(j+1)%3]); P[j] = (A[(j+1)%3]-D[(j+1)%3])*(H[(j+2)%3]-D[(j+2)%3]) - (A[(j+2)%3]-D[(j+2)%3])*(H[(j+1)%3]-D[(j+1)%3]); X[j] = value[(j+2)%3][i]*(H[(j+1)%3]-D[(j+1)%3]) - value[(j+1)%3][i]*(H[(j+2)%3]-D[(j+2)%3]) + D[(j+1)%3]*H[(j+2)%3] - D[(j+2)%3]*H[(j+1)%3]; Y[j] = value[j][i]*(H[(j+1)%3]-D[(j+1)%3]) - value[(j+1)%3][i]*(H[j]-D[j]) + D[(j+1)%3]*H[j] - D[j]*H[(j+1)%3]; } float s, t, u; // these if statements handle skewed grids float d0 = M[0]*P[0] - N[0]*O[0]; float d1 = M[1]*P[1] - N[1]*O[1]; float d2 = M[2]*P[2] - N[2]*O[2]; float ad0 = Math.abs(d0); float ad1 = Math.abs(d1); float ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { s = (N[0]*X[0] + P[0]*Y[0])/d0; t = 1 + (M[0]*X[0] + O[0]*Y[0])/d0; } else if (ad1 > ad2) { s = (N[1]*X[1] + P[1]*Y[1])/d1; t = 1 + (M[1]*X[1] + O[1]*Y[1])/d1; } else { s = (N[2]*X[2] + P[2]*Y[2])/d2; t = 1 + (M[2]*X[2] + O[2]*Y[2])/d2; } /* WLH 5 April 99 if (M[0]*P[0] != N[0]*O[0]) { s = (N[0]*X[0] + P[0]*Y[0])/(M[0]*P[0] - N[0]*O[0]); t = 1 - (M[0]*X[0] + O[0]*Y[0])/(N[0]*O[0] - M[0]*P[0]); } else if (M[1]*P[1] != N[1]*O[1]) { s = (N[1]*X[1] + P[1]*Y[1])/(M[1]*P[1] - N[1]*O[1]); t = 1 - (M[1]*X[1] + O[1]*Y[1])/(N[1]*O[1] - M[1]*P[1]); } else { s = (N[2]*X[2] + P[2]*Y[2])/(M[2]*P[2] - N[2]*O[2]); t = 1 - (M[2]*X[2] + O[2]*Y[2])/(N[2]*O[2] - M[2]*P[2]); } */ d0 = H[0]-D[0]; d1 = H[1]-D[1]; d2 = H[2]-D[2]; ad0 = Math.abs(d0); ad1 = Math.abs(d1); ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { u = 1 - ( value[0][i] - D[0] - s*(C[0]-D[0]) - (1-t)*(A[0]-D[0]) ) / d0; } else if (ad1 > ad2) { u = 1 - ( value[1][i] - D[1] - s*(C[1]-D[1]) - (1-t)*(A[1]-D[1]) ) / d1; } else { u = 1 - ( value[2][i] - D[2] - s*(C[2]-D[2]) - (1-t)*(A[2]-D[2]) ) / d2; } /* WLH 5 April 99 if (H[0] != D[0]) { u = 1 - ( value[0][i] - D[0] - s*(C[0]-D[0]) - (1-t)*(A[0]-D[0]) ) / (H[0]-D[0]); } else if (H[1] != D[1]) { u = 1 - ( value[1][i] - D[1] - s*(C[1]-D[1]) - (1-t)*(A[1]-D[1]) ) / (H[1]-D[1]); } else { u = 1 - ( value[2][i] - D[2] - s*(C[2]-D[2]) - (1-t)*(A[2]-D[2]) ) / (H[2]-D[2]); } */ if (evencube) { grid[0][i] = gx+s; grid[1][i] = gy+t; grid[2][i] = gz+u; } else { grid[0][i] = gx+1-s; grid[1][i] = gy+1-t; grid[2][i] = gz+1-u; } break; } } else if (tetnum==4) { tval1 = ( (G[1]-C[1])*(H[2]-G[2]) - (G[2]-C[2])*(H[1]-G[1]) ) *(value[0][i]-G[0]) + ( (G[2]-C[2])*(H[0]-G[0]) - (G[0]-C[0])*(H[2]-G[2]) ) *(value[1][i]-G[1]) + ( (G[0]-C[0])*(H[1]-G[1]) - (G[1]-C[1])*(H[0]-G[0]) ) *(value[2][i]-G[2]); tval2 = ( (G[1]-F[1])*(C[2]-G[2]) - (G[2]-F[2])*(C[1]-G[1]) ) *(value[0][i]-G[0]) + ( (G[2]-F[2])*(C[0]-G[0]) - (G[0]-F[0])*(C[2]-G[2]) ) *(value[1][i]-G[1]) + ( (G[0]-F[0])*(C[1]-G[1]) - (G[1]-F[1])*(C[0]-G[0]) ) *(value[2][i]-G[2]); tval3 = ( (G[1]-H[1])*(F[2]-G[2]) - (G[2]-H[2])*(F[1]-G[1]) ) *(value[0][i]-G[0]) + ( (G[2]-H[2])*(F[0]-G[0]) - (G[0]-H[0])*(F[2]-G[2]) ) *(value[1][i]-G[1]) + ( (G[0]-H[0])*(F[1]-G[1]) - (G[1]-H[1])*(F[0]-G[0]) ) *(value[2][i]-G[2]); test1 = (tval1 == 0) || ((tval1 > 0) == (!evencube)^Pos); test2 = (tval2 == 0) || ((tval2 > 0) == (!evencube)^Pos); test3 = (tval3 == 0) || ((tval3 > 0) == (!evencube)^Pos); // if a test failed go to a new box if (!test1 && evencube) gy++; // DOWN if (!test1 && !evencube) gy--; // UP if (!test2 && evencube) gx++; // RIGHT if (!test2 && !evencube) gx--; // LEFT if (!test3 && evencube) gz--; // BACK if (!test3 && !evencube) gz++; // FORWARD tetnum = 5; // Snap coordinates back onto grid in case they fell off if (gx < 0) gx = 0; if (gy < 0) gy = 0; if (gz < 0) gz = 0; if (gx > LengthX-2) gx = LengthX-2; if (gy > LengthY-2) gy = LengthY-2; if (gz > LengthZ-2) gz = LengthZ-2; // Detect if the point is off the grid entirely if ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (!test1 || !test2 || !test3) && !offgrid ) { offgrid = true; continue; } // If all tests pass then this is the correct tetrahedron if ( ( (gx == ogx) && (gy == ogy) && (gz == ogz) ) || offgrid) { // solve point float[] M = new float[3]; float[] N = new float[3]; float[] O = new float[3]; float[] P = new float[3]; float[] X = new float[3]; float[] Y = new float[3]; for (int j=0; j<3; j++) { M[j] = (H[j]-G[j])*(C[(j+1)%3]-G[(j+1)%3]) - (H[(j+1)%3]-G[(j+1)%3])*(C[j]-G[j]); N[j] = (F[j]-G[j])*(C[(j+1)%3]-G[(j+1)%3]) - (F[(j+1)%3]-G[(j+1)%3])*(C[j]-G[j]); O[j] = (H[(j+1)%3]-G[(j+1)%3])*(C[(j+2)%3]-G[(j+2)%3]) - (H[(j+2)%3]-G[(j+2)%3])*(C[(j+1)%3]-G[(j+1)%3]); P[j] = (F[(j+1)%3]-G[(j+1)%3])*(C[(j+2)%3]-G[(j+2)%3]) - (F[(j+2)%3]-G[(j+2)%3])*(C[(j+1)%3]-G[(j+1)%3]); X[j] = value[(j+2)%3][i]*(C[(j+1)%3]-G[(j+1)%3]) - value[(j+1)%3][i]*(C[(j+2)%3]-G[(j+2)%3]) + G[(j+1)%3]*C[(j+2)%3] - G[(j+2)%3]*C[(j+1)%3]; Y[j] = value[j][i]*(C[(j+1)%3]-G[(j+1)%3]) - value[(j+1)%3][i]*(C[j]-G[j]) + G[(j+1)%3]*C[j] - G[j]*C[(j+1)%3]; } float s, t, u; // these if statements handle skewed grids float d0 = M[0]*P[0] - N[0]*O[0]; float d1 = M[1]*P[1] - N[1]*O[1]; float d2 = M[2]*P[2] - N[2]*O[2]; float ad0 = Math.abs(d0); float ad1 = Math.abs(d1); float ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { s = 1 - (N[0]*X[0] + P[0]*Y[0])/d0; t = 1 + (M[0]*X[0] + O[0]*Y[0])/d0; } else if (ad1 > ad2) { s = 1 - (N[1]*X[1] + P[1]*Y[1])/d1; t = 1 + (M[1]*X[1] + O[1]*Y[1])/d1; } else { s = 1 - (N[2]*X[2] + P[2]*Y[2])/d2; t = 1 + (M[2]*X[2] + O[2]*Y[2])/d2; } /* WLH 5 April 99 if (M[0]*P[0] != N[0]*O[0]) { s = 1 - (N[0]*X[0] + P[0]*Y[0])/(M[0]*P[0] - N[0]*O[0]); t = 1 - (M[0]*X[0] + O[0]*Y[0])/(N[0]*O[0] - M[0]*P[0]); } else if (M[1]*P[1] != N[1]*O[1]) { s = 1 - (N[1]*X[1] + P[1]*Y[1])/(M[1]*P[1] - N[1]*O[1]); t = 1 - (M[1]*X[1] + O[1]*Y[1])/(N[1]*O[1] - M[1]*P[1]); } else { s = 1 - (N[2]*X[2] + P[2]*Y[2])/(M[2]*P[2] - N[2]*O[2]); t = 1 - (M[2]*X[2] + O[2]*Y[2])/(N[2]*O[2] - M[2]*P[2]); } */ d0 = C[0]-G[0]; d1 = C[1]-G[1]; d2 = C[2]-G[2]; ad0 = Math.abs(d0); ad1 = Math.abs(d1); ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { u = ( value[0][i] - G[0] - (1-s)*(H[0]-G[0]) - (1-t)*(F[0]-G[0]) ) / d0; } else if (ad1 > ad2) { u = ( value[1][i] - G[1] - (1-s)*(H[1]-G[1]) - (1-t)*(F[1]-G[1]) ) / d1; } else { u = ( value[2][i] - G[2] - (1-s)*(H[2]-G[2]) - (1-t)*(F[2]-G[2]) ) / d2; } /* WLH 5 April 99 if (C[0] != G[0]) { u = ( value[0][i] - G[0] - (1-s)*(H[0]-G[0]) - (1-t)*(F[0]-G[0]) ) / (C[0]-G[0]); } else if (C[1] != G[1]) { u = ( value[1][i] - G[1] - (1-s)*(H[1]-G[1]) - (1-t)*(F[1]-G[1]) ) / (C[1]-G[1]); } else { u = ( value[2][i] - G[2] - (1-s)*(H[2]-G[2]) - (1-t)*(F[2]-G[2]) ) / (C[2]-G[2]); } */ if (evencube) { grid[0][i] = gx+s; grid[1][i] = gy+t; grid[2][i] = gz+u; } else { grid[0][i] = gx+1-s; grid[1][i] = gy+1-t; grid[2][i] = gz+1-u; } break; } } else { // tetnum==5 tval1 = ( (F[1]-H[1])*(A[2]-F[2]) - (F[2]-H[2])*(A[1]-F[1]) ) *(value[0][i]-F[0]) + ( (F[2]-H[2])*(A[0]-F[0]) - (F[0]-H[0])*(A[2]-F[2]) ) *(value[1][i]-F[1]) + ( (F[0]-H[0])*(A[1]-F[1]) - (F[1]-H[1])*(A[0]-F[0]) ) *(value[2][i]-F[2]); tval2 = ( (C[1]-F[1])*(A[2]-C[2]) - (C[2]-F[2])*(A[1]-C[1]) ) *(value[0][i]-C[0]) + ( (C[2]-F[2])*(A[0]-C[0]) - (C[0]-F[0])*(A[2]-C[2]) ) *(value[1][i]-C[1]) + ( (C[0]-F[0])*(A[1]-C[1]) - (C[1]-F[1])*(A[0]-C[0]) ) *(value[2][i]-C[2]); tval3 = ( (C[1]-A[1])*(H[2]-C[2]) - (C[2]-A[2])*(H[1]-C[1]) ) *(value[0][i]-C[0]) + ( (C[2]-A[2])*(H[0]-C[0]) - (C[0]-A[0])*(H[2]-C[2]) ) *(value[1][i]-C[1]) + ( (C[0]-A[0])*(H[1]-C[1]) - (C[1]-A[1])*(H[0]-C[0]) ) *(value[2][i]-C[2]); tval4 = ( (F[1]-C[1])*(H[2]-F[2]) - (F[2]-C[2])*(H[1]-F[1]) ) *(value[0][i]-F[0]) + ( (F[2]-C[2])*(H[0]-F[0]) - (F[0]-C[0])*(H[2]-F[2]) ) *(value[1][i]-F[1]) + ( (F[0]-C[0])*(H[1]-F[1]) - (F[1]-C[1])*(H[0]-F[0]) ) *(value[2][i]-F[2]); test1 = (tval1 == 0) || ((tval1 > 0) == (!evencube)^Pos); test2 = (tval2 == 0) || ((tval2 > 0) == (!evencube)^Pos); test3 = (tval3 == 0) || ((tval3 > 0) == (!evencube)^Pos); test4 = (tval4 == 0) || ((tval4 > 0) == (!evencube)^Pos); // if a test failed go to a new tetrahedron if (!test1 && test2 && test3 && test4) tetnum = 1; if (test1 && !test2 && test3 && test4) tetnum = 2; if (test1 && test2 && !test3 && test4) tetnum = 3; if (test1 && test2 && test3 && !test4) tetnum = 4; if ( (!test1 && !test2 && evencube) || (!test3 && !test4 && !evencube) ) gy--; // GO UP if ( (!test1 && !test3 && evencube) || (!test2 && !test4 && !evencube) ) gx--; // GO LEFT if ( (!test1 && !test4 && evencube) || (!test2 && !test3 && !evencube) ) gz--; // GO BACK if ( (!test2 && !test3 && evencube) || (!test1 && !test4 && !evencube) ) gz++; // GO FORWARD if ( (!test2 && !test4 && evencube) || (!test1 && !test3 && !evencube) ) gx++; // GO RIGHT if ( (!test3 && !test4 && evencube) || (!test1 && !test2 && !evencube) ) gy++; // GO DOWN // Snap coordinates back onto grid in case they fell off if (gx < 0) gx = 0; if (gy < 0) gy = 0; if (gz < 0) gz = 0; if (gx > LengthX-2) gx = LengthX-2; if (gy > LengthY-2) gy = LengthY-2; if (gz > LengthZ-2) gz = LengthZ-2; // Detect if the point is off the grid entirely if ( ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (!test1 || !test2 || !test3 || !test4) && (tetnum == 5)) || offgrid) { offgrid = true; boolean OX, OY, OZ, MX, MY, MZ, LX, LY, LZ; OX = OY = OZ = MX = MY = MZ = LX = LY = LZ = false; if (gx == 0) OX = true; if (gy == 0) OY = true; if (gz == 0) OZ = true; if (gx == LengthX-2) LX = true; if (gy == LengthY-2) LY = true; if (gz == LengthZ-2) LZ = true; if (!OX && !LX) MX = true; if (!OY && !LY) MY = true; if (!OZ && !LZ) MZ = true; test1 = test2 = test3 = test4 = false; // 26 cases if (evencube) { if (!LX && !LY && !LZ) tetnum = 1; else if ( (LX && OY && MZ) || (MX && OY && LZ) || (LX && MY && LZ) || (LX && OY && LZ) || (MX && MY && LZ) || (LX && MY && MZ) ) tetnum = 2; else if ( (OX && LY && MZ) || (OX && MY && LZ) || (MX && LY && LZ) || (OX && LY && LZ) || (MX && LY && MZ) ) tetnum = 3; else if ( (MX && LY && OZ) || (LX && MY && OZ) || (LX && LY && MZ) || (LX && LY && OZ) ) tetnum = 4; } else { if (!OX && !OY && !OZ) tetnum = 1; else if ( (OX && MY && OZ) || (MX && LY && OZ) || (OX && LY && MZ) || (OX && LY && OZ) || (MX && MY && OZ) || (OX && MY && MZ) ) tetnum = 2; else if ( (LX && MY && OZ) || (MX && OY && OZ) || (LX && OY && MZ) || (LX && OY && OZ) || (MX && OY && MZ) ) tetnum = 3; else if ( (OX && OY && MZ) || (OX && MY && OZ) || (MX && OY && LZ) || (OX && OY && LZ) ) tetnum = 4; } } // If all tests pass then this is the correct tetrahedron if ( (gx == ogx) && (gy == ogy) && (gz == ogz) && (tetnum == 5) ) { // solve point float[] Q = new float[3]; for (int j=0; j<3; j++) { Q[j] = (H[j] + F[j] + A[j] - C[j])/2; } float[] M = new float[3]; float[] N = new float[3]; float[] O = new float[3]; float[] P = new float[3]; float[] X = new float[3]; float[] Y = new float[3]; for (int j=0; j<3; j++) { M[j] = (F[j]-Q[j])*(A[(j+1)%3]-Q[(j+1)%3]) - (F[(j+1)%3]-Q[(j+1)%3])*(A[j]-Q[j]); N[j] = (H[j]-Q[j])*(A[(j+1)%3]-Q[(j+1)%3]) - (H[(j+1)%3]-Q[(j+1)%3])*(A[j]-Q[j]); O[j] = (F[(j+1)%3]-Q[(j+1)%3])*(A[(j+2)%3]-Q[(j+2)%3]) - (F[(j+2)%3]-Q[(j+2)%3])*(A[(j+1)%3]-Q[(j+1)%3]); P[j] = (H[(j+1)%3]-Q[(j+1)%3])*(A[(j+2)%3]-Q[(j+2)%3]) - (H[(j+2)%3]-Q[(j+2)%3])*(A[(j+1)%3]-Q[(j+1)%3]); X[j] = value[(j+2)%3][i]*(A[(j+1)%3]-Q[(j+1)%3]) - value[(j+1)%3][i]*(A[(j+2)%3]-Q[(j+2)%3]) + Q[(j+1)%3]*A[(j+2)%3] - Q[(j+2)%3]*A[(j+1)%3]; Y[j] = value[j][i]*(A[(j+1)%3]-Q[(j+1)%3]) - value[(j+1)%3][i]*(A[j]-Q[j]) + Q[(j+1)%3]*A[j] - Q[j]*A[(j+1)%3]; } float s, t, u; // these if statements handle skewed grids float d0 = M[0]*P[0] - N[0]*O[0]; float d1 = M[1]*P[1] - N[1]*O[1]; float d2 = M[2]*P[2] - N[2]*O[2]; float ad0 = Math.abs(d0); float ad1 = Math.abs(d1); float ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { s = (N[0]*X[0] + P[0]*Y[0])/d0; t = -(M[0]*X[0] + O[0]*Y[0])/d0; } else if (ad1 > ad2) { s = (N[1]*X[1] + P[1]*Y[1])/d1; t = -(M[1]*X[1] + O[1]*Y[1])/d1; } else { s = (N[2]*X[2] + P[2]*Y[2])/d2; t = -(M[2]*X[2] + O[2]*Y[2])/d2; } /* WLH 3 April 99 if (M[0]*P[0] != N[0]*O[0]) { s = (N[0]*X[0] + P[0]*Y[0])/(M[0]*P[0] - N[0]*O[0]); t = (M[0]*X[0] + O[0]*Y[0])/(N[0]*O[0] - M[0]*P[0]); } else if (M[1]*P[1] != N[1]*O[1]) { s = (N[1]*X[1] + P[1]*Y[1])/(M[1]*P[1] - N[1]*O[1]); t = (M[1]*X[1] + O[1]*Y[1])/(N[1]*O[1] - M[1]*P[1]); } else { s = (N[2]*X[2] + P[2]*Y[2])/(M[2]*P[2] - N[2]*O[2]); t = (M[2]*X[2] + O[2]*Y[2])/(N[2]*O[2] - M[2]*P[2]); } */ d0 = A[0]-Q[0]; d1 = A[1]-Q[1]; d2 = A[2]-Q[2]; ad0 = Math.abs(d0); ad1 = Math.abs(d1); ad2 = Math.abs(d2); if (ad0 > ad1 && ad0 > ad2) { u = ( value[0][i] - Q[0] - s*(F[0]-Q[0]) - t*(H[0]-Q[0]) ) / d0; } else if (ad1 > ad2) { u = ( value[1][i] - Q[1] - s*(F[1]-Q[1]) - t*(H[1]-Q[1]) ) / d1; } else { u = ( value[2][i] - Q[2] - s*(F[2]-Q[2]) - t*(H[2]-Q[2]) ) / d2; } /* WLH 3 April 99 if (A[0] != Q[0]) { u = ( value[0][i] - Q[0] - s*(F[0]-Q[0]) - t*(H[0]-Q[0]) ) / (A[0]-Q[0]); } else if (A[1] != Q[1]) { u = ( value[1][i] - Q[1] - s*(F[1]-Q[1]) - t*(H[1]-Q[1]) ) / (A[1]-Q[1]); } else { u = ( value[2][i] - Q[2] - s*(F[2]-Q[2]) - t*(H[2]-Q[2]) ) / (A[2]-Q[2]); } */ if (evencube) { grid[0][i] = gx+s; grid[1][i] = gy+t; grid[2][i] = gz+u; } else { grid[0][i] = gx+1-s; grid[1][i] = gy+1-t; grid[2][i] = gz+1-u; } break; } } } // allow estimations up to 0.5 boxes outside of defined samples if ( (grid[0][i] <= -0.5) || (grid[0][i] >= LengthX-0.5) || (grid[1][i] <= -0.5) || (grid[1][i] >= LengthY-0.5) || (grid[2][i] <= -0.5) || (grid[2][i] >= LengthZ-0.5) ) { grid[0][i] = grid[1][i] = grid[2][i] = Float.NaN; } } return grid; } /** return basic lines in array[0], fill-ins in array[1] and labels in array[2] */ public VisADGeometryArray[] makeIsoLines(float[] intervals, float lowlimit, float highlimit, float base, float[] fieldValues, byte[][] color_values, boolean[] swap, boolean dash, boolean fill, ScalarMap[] smap) throws VisADException { if (ManifoldDimension != 2) { throw new DisplayException("Gridded3DSet.makeIsoLines: " + "ManifoldDimension must be 2"); } if (intervals == null) return null; int nr = LengthX; int nc = LengthY; float[] g = fieldValues; // these are just estimates // int est = 2 * Length; WLH 14 April 2000 double dest = Math.sqrt((double) Length); int est = (int) (dest * Math.sqrt(dest)); if (est < 1000) est = 1000; int maxv2 = est; int maxv1 = 2 * 2 * maxv2; // maxv3 and maxv4 should be equal int maxv3 = est; int maxv4 = maxv3; /* memory use for temporaries, in bytes (for est = 2 * Length): 12 * color_length * Length + 64 * Length + 48 * Length + = (112 + 12 * color_length) * Length for color_length = 3 this is 148 * Length */ int color_length = (color_values != null) ? color_values.length : 0; byte[][] color_levels1 = null; byte[][] color_levels2 = null; byte[][] color_levels3 = null; if (color_length > 0) { color_levels1 = new byte[color_length][maxv1]; color_levels2 = new byte[color_length][maxv2]; color_levels3 = new byte[color_length][maxv3]; } float[][] vx1 = new float[1][maxv1]; float[][] vy1 = new float[1][maxv1]; float[][] vx2 = new float[1][maxv2]; float[][] vy2 = new float[1][maxv2]; float[][] vx3 = new float[1][maxv3]; float[][] vy3 = new float[1][maxv3]; float[][] vx4 = new float[1][maxv4]; float[][] vy4 = new float[1][maxv4]; int[] numv1 = new int[1]; int[] numv2 = new int[1]; int[] numv3 = new int[1]; int[] numv4 = new int[1]; float[][] tri = new float[2][]; float[][] tri_normals = new float[1][]; byte[][] tri_color = new byte[color_length][]; float[][][] grd_normals = null; byte[][] interval_colors = new byte[color_length][intervals.length]; if (fill) { //- compute normals at grid points float[][] samples = getSamples(false); grd_normals = new float[nc][nr][3]; // calculate normals int k = 0; int k3 = 0; int ki, kj; for (int i=0; i 0) { byte[][] a = new byte[color_length][numv1[0]]; for (int i=0; i 0) { byte[][] a = new byte[color_length][numv2[0]]; for (int i=0; i 0) { byte[][] a = new byte[color_length][numv3[0]]; for (int i=0; i 3) { System.arraycopy(color_temps[3], 0, color_levels[3], 0, nvertex); } // take the garbage out color_temps = null; } if (debug) System.out.println("nvertex= "+nvertex); float[] NxA = new float[npolygons]; float[] NxB = new float[npolygons]; float[] NyA = new float[npolygons]; float[] NyB = new float[npolygons]; float[] NzA = new float[npolygons]; float[] NzB = new float[npolygons]; float[] Pnx = new float[npolygons]; float[] Pny = new float[npolygons]; float[] Pnz = new float[npolygons]; float[] NX = new float[nvertex]; float[] NY = new float[nvertex]; float[] NZ = new float[nvertex]; make_normals( fieldVertices[0], fieldVertices[1], fieldVertices[2], NX, NY, NZ, nvertex, npolygons, Pnx, Pny, Pnz, NxA, NxB, NyA, NyB, NzA, NzB, Pol_f_Vert, Vert_f_Pol); // take the garbage out NxA = NxB = NyA = NyB = NzA = NzB = Pnx = Pny = Pnz = null; float[] normals = new float[3 * nvertex]; int j = 0; for (i=0; i= INVALID_VALUE) ptAUX[ii] = 0x1001; if (Float.isNaN(ptGRID[ii]) ptAUX[ii] = 0x1001; */ // test for missing if (ptGRID[ii] != ptGRID[ii]) ptAUX[ii] = 0x1001; else if (ptGRID[ii] >= isovalue) ptAUX[ii] = 1; else ptAUX[ii] = 0; } /* Vectorized */ for (ii = 0; ii < num_cubes; ii++) { ptFLAG[ii] = ((ptAUX[ pcube[ii] ] ) | (ptAUX[ pcube[ii] + ydim ] << 1) | (ptAUX[ pcube[ii] + 1 ] << 2) | (ptAUX[ pcube[ii] + ydim + 1 ] << 3) | (ptAUX[ pcube[ii] + xdim_x_ydim ] << 4) | (ptAUX[ pcube[ii] + ydim + xdim_x_ydim ] << 5) | (ptAUX[ pcube[ii] + 1 + xdim_x_ydim ] << 6) | (ptAUX[ pcube[ii] + 1 + ydim + xdim_x_ydim ] << 7)); } /* After this Point it is not more used pcube */ /* Analyse Special Cases in FLAG */ ii = npolygons = 0; while ( TRUE ) { for (; ii < num_cubes; ii++) { if ( ((ptFLAG[ii] != 0) && (ptFLAG[ii] != 0xFF)) && ptFLAG[ii] < MAX_FLAG_NUM) break; } if ( ii == num_cubes ) break; bcase = pol_edges[ptFLAG[ii]][0]; if (bcase == 0xE6 || bcase == 0xF9) { iz = ii/num_cubes_xy; ix = (int)((ii - (iz*num_cubes_xy))/num_cubes_y); iy = ii - (iz*num_cubes_xy) - (ix*num_cubes_y); /* == Z+ == */ if ((ptFLAG[ii] & 0xF0) == 0x90 || (ptFLAG[ii] & 0xF0) == 0x60) { cb = (iz < (zdim - 1)) ? ii + num_cubes_xy : -1 ; } /* == Z- == */ else if ((ptFLAG[ii] & 0x0F) == 0x09 || (ptFLAG[ii] & 0x0F) == 0x06) { cb = (iz > 0) ? ii - num_cubes_xy : -1 ; } /* == Y+ == */ else if ((ptFLAG[ii] & 0xCC) == 0x84 || (ptFLAG[ii] & 0xCC) == 0x48) { cb = (iy < (ydim - 1)) ? ii + 1 : -1 ; } /* == Y- == */ else if ((ptFLAG[ii] & 0x33) == 0x21 || (ptFLAG[ii] & 0x33) == 0x12) { cb = (iy > 0) ? ii - 1 : -1 ; } /* == X+ == */ else if ((ptFLAG[ii] & 0xAA) == 0x82 || (ptFLAG[ii] & 0xAA) == 0x28) { cb = (ix < (xdim - 1)) ? ii + num_cubes_y : -1 ; } /* == X- == */ else if ((ptFLAG[ii] & 0x55) == 0x41 || (ptFLAG[ii] & 0x55) == 0x14) { cb = (ix > 0) ? ii - num_cubes_y : -1 ; } /* == Map Special Case == */ if ((cb > -1 && cb < num_cubes) && ptFLAG[cb]<316) /*changed by BEP on 7-20-92*/ { bcase = pol_edges[ptFLAG[cb]][0]; if (bcase == 0x06 || bcase == 0x16 || bcase == 0x19 || bcase == 0x1E || bcase == 0x3C || bcase == 0x69) { ptFLAG[ii] = sp_cases[ptFLAG[ii]]; } } } else if (bcase == 0xE9) { iz = ii/num_cubes_xy; ix = (int)((ii - (iz*num_cubes_xy))/num_cubes_y); iy = ii - (iz*num_cubes_xy) - (ix*num_cubes_y); SF = 0; if (ptFLAG[ii] == 0x6B) SF = SF_6B; else if (ptFLAG[ii] == 0x6D) SF = SF_6D; else if (ptFLAG[ii] == 0x79) SF = SF_79; else if (ptFLAG[ii] == 0x97) SF = SF_97; else if (ptFLAG[ii] == 0x9E) SF = SF_9E; else if (ptFLAG[ii] == 0xB6) SF = SF_B6; else if (ptFLAG[ii] == 0xD6) SF = SF_D6; else if (ptFLAG[ii] == 0xE9) SF = SF_E9; for (jj=0; jj<3; jj++) { if (case_E9[jj+SF] == Zp) { cb = (iz < (zdim - 1)) ? ii + num_cubes_xy : -1 ; } else if (case_E9[jj+SF] == Zn) { cb = (iz > 0) ? ii - num_cubes_xy : -1 ; } else if (case_E9[jj+SF] == Yp) { cb = (iy < (ydim - 1)) ? ii + 1 : -1 ; } else if (case_E9[jj+SF] == Yn) { cb = (iy > 0) ? ii - 1 : -1 ; } else if (case_E9[jj+SF] == Xp) { cb = (ix < (xdim - 1)) ? ii + num_cubes_y : -1 ; } else if (case_E9[jj+SF] == Xn) { cb = (ix > 0) ? ii - num_cubes_y : -1 ; } /* changed: if ((cb > -1 && cb < num_cubes)) to: */ if ((cb > -1 && cb < num_cubes) && ptFLAG[cb]<316) /* changed by BEP on 7-20-92*/ { bcase = pol_edges[ptFLAG[cb]][0]; if (bcase == 0x06 || bcase == 0x16 || bcase == 0x19 || bcase == 0x1E || bcase == 0x3C || bcase == 0x69) { ptFLAG[ii] = sp_cases[ptFLAG[ii]] + case_E9[jj+SF+3]; break; } } } } /* Calculate the Number of Generated Triangles and Polygons */ npolygons += pol_edges[ptFLAG[ii]][1]; ii++; } /* npolygons2 = 2*npolygons; */ return npolygons; } private int isosurf( float isovalue, int[] ptFLAG, int nvertex_estimate, int npolygons, float[] ptGRID, int xdim, int ydim, int zdim, float[][] VX, float[][] VY, float[][] VZ, byte[][] auxValues, byte[][] auxLevels, int[][] Pol_f_Vert, int[] Vert_f_Pol ) throws VisADException { int ix, iy, iz, caseA, above, bellow, front, rear, mm, nn; int ii, jj, kk, ncube, cpl, pvp, pa, ve; int[] calc_edge = new int[13]; int xx, yy, zz; float cp; float vnode0 = 0; float vnode1 = 0; float vnode2 = 0; float vnode3 = 0; float vnode4 = 0; float vnode5 = 0; float vnode6 = 0; float vnode7 = 0; int pt = 0; int n_pol; int aa; int bb; int temp; float nodeDiff; int xdim_x_ydim = xdim*ydim; int nvet; int t; float[][] samples = getSamples(false); int naux = (auxValues != null) ? auxValues.length : 0; if (naux > 0) { if (auxLevels == null || auxLevels.length != naux) { throw new SetException("Gridded3DSet.isosurf: " +"auxLevels length " + auxLevels.length + " doesn't match expected " + naux); } for (int i=0; i 0) ? new byte[naux][nvertex_estimate] : null; bellow = rear = 0; above = front = 1; /* Initialize the Auxiliar Arrays of Pointers */ /* WLH 25 Oct 97 ix = 9 * (npolygons*2 + 50); iy = 7 * npolygons; ii = ix + iy; */ for (jj=0; jj nvertex_estimate) { // allocate more space nvertex_estimate = 2 * (nvet + 12); if (naux > 0) { for (int i=0; i= 16) { aa++; bb -= 16; } } kk >>= 4; pa += 7; } /* end fill_Vert_f_Pol(ncube); */ /* */ /* find_vertex(); */ /* WLH 2 April 99 vnode0 = ptGRID[pt]; vnode1 = ptGRID[pt + ydim]; vnode2 = ptGRID[pt + 1]; vnode3 = ptGRID[pt + ydim + 1]; vnode4 = ptGRID[pt + xdim_x_ydim]; vnode5 = ptGRID[pt + ydim + xdim_x_ydim]; vnode6 = ptGRID[pt + 1 + xdim_x_ydim]; vnode7 = ptGRID[pt + 1 + ydim + xdim_x_ydim]; */ if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0002) != 0) ) { /* cube vertex 0-1 */ if ( (iz != 0) || (iy != 0) ) { calc_edge[1] = P_array[ bellow*xx + ix*ydim + iy ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode1 - vnode0; cp = ( ( isovalue - vnode0 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode0 ) / ( vnode1 - vnode0 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim] + (1.0f-cp) * samples[0][pt]; VY[0][nvet] = (float) cp * samples[1][pt + ydim] + (1.0f-cp) * samples[1][pt]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim] + (1.0f-cp) * samples[2][pt]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim] + (1.0f-cp) * auxValues[j][pt]; */ } calc_edge[1] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0004) != 0) ) { /* cube vertex 0-2 */ if ( (iz != 0) || (ix != 0) ) { calc_edge[2] = P_array[ 2*xx + bellow*yy + iy*xdim + ix ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode2 - vnode0; cp = ( ( isovalue - vnode0 ) / nodeDiff ) + iy; VX[0][nvet] = ix; VY[0][nvet] = cp; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode0 ) / ( vnode2 - vnode0 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1] + (1.0f-cp) * samples[0][pt]; VY[0][nvet] = (float) cp * samples[1][pt + 1] + (1.0f-cp) * samples[1][pt]; VZ[0][nvet] = (float) cp * samples[2][pt + 1] + (1.0f-cp) * samples[2][pt]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1] + (1.0f-cp) * auxValues[j][pt]; */ } calc_edge[2] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0008) != 0) ) { /* cube vertex 0-4 */ if ( (ix != 0) || (iy != 0) ) { calc_edge[3] = P_array[ 2*xx + 2*yy + rear*zz + iy ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode4 - vnode0; cp = ( ( isovalue - vnode0 ) / nodeDiff ) + iz; VX[0][nvet] = ix; VY[0][nvet] = iy; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode0 ) / ( vnode4 - vnode0 ) ); VX[0][nvet] = (float) cp * samples[0][pt + xdim_x_ydim] + (1.0f-cp) * samples[0][pt]; VY[0][nvet] = (float) cp * samples[1][pt + xdim_x_ydim] + (1.0f-cp) * samples[1][pt]; VZ[0][nvet] = (float) cp * samples[2][pt + xdim_x_ydim] + (1.0f-cp) * samples[2][pt]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt]; */ } calc_edge[3] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0010) != 0) ) { /* cube vertex 1-3 */ if ( (iz != 0) ) { calc_edge[4] = P_array[ 2*xx + bellow*yy + iy*xdim + (ix+1) ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode3 - vnode1; cp = ( ( isovalue - vnode1 ) / nodeDiff ) + iy; VX[0][nvet] = ix+1; VY[0][nvet] = cp; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode1 ) / ( vnode3 - vnode1 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + 1] + (1.0f-cp) * samples[0][pt + ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + 1] + (1.0f-cp) * samples[1][pt + ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + 1] + (1.0f-cp) * samples[2][pt + ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + 1] + (1.0f-cp) * auxValues[j][pt + ydim]; */ } calc_edge[4] = nvet; P_array[ 2*xx + bellow*yy + iy*xdim + (ix+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0020) != 0) ) { /* cube vertex 1-5 */ if ( (iy != 0) ) { calc_edge[5] = P_array[ 2*xx + 2*yy + front*zz + iy ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode5 - vnode1; cp = ( ( isovalue - vnode1 ) / nodeDiff ) + iz; VX[0][nvet] = ix+1; VY[0][nvet] = iy; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode1 ) / ( vnode5 - vnode1 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim]; */ } calc_edge[5] = nvet; P_array[ 2*xx + 2*yy + front*zz + iy ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0040) != 0) ) { /* cube vertex 2-3 */ if ( (iz != 0) ) { calc_edge[6] = P_array[ bellow*xx + ix*ydim + (iy+1) ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode3 - vnode2; cp = ( ( isovalue - vnode2 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy+1; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode2 ) / ( vnode3 - vnode2 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + 1] + (1.0f-cp) * samples[0][pt + 1]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + 1] + (1.0f-cp) * samples[1][pt + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + 1] + (1.0f-cp) * samples[2][pt + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + 1] + (1.0f-cp) * auxValues[j][pt + 1]; */ } calc_edge[6] = nvet; P_array[ bellow*xx + ix*ydim + (iy+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0080) != 0) ) { /* cube vertex 2-6 */ if ( (ix != 0) ) { calc_edge[7] = P_array[ 2*xx + 2*yy + rear*zz + (iy+1) ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode6 - vnode2; cp = ( ( isovalue - vnode2 ) / nodeDiff ) + iz; VX[0][nvet] = ix; VY[0][nvet] = iy+1; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode2 ) / ( vnode6 - vnode2 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + 1]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + 1]; */ } calc_edge[7] = nvet; P_array[ 2*xx + 2*yy + rear*zz + (iy+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0100) != 0) ) { /* cube vertex 3-7 */ /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode3; cp = ( ( isovalue - vnode3 ) / nodeDiff ) + iz; VX[0][nvet] = ix+1; VY[0][nvet] = iy+1; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode3 ) / ( vnode7 - vnode3 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim + 1]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim + 1]; */ } calc_edge[8] = nvet; P_array[ 2*xx + 2*yy + front*zz + (iy+1) ] = nvet; nvet++; } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0200) != 0) ) { /* cube vertex 4-5 */ if ( (iy != 0) ) { calc_edge[9] = P_array[ above*xx + ix*ydim + iy ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode5 - vnode4; cp = ( ( isovalue - vnode4 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode4 ) / ( vnode5 - vnode4 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + xdim_x_ydim]; */ } calc_edge[9] = nvet; P_array[ above*xx + ix*ydim + iy ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0400) != 0) ) { /* cube vertex 4-6 */ if ( (ix != 0) ) { calc_edge[10] = P_array[ 2*xx + above*yy + iy*xdim + ix ]; } else { /* WLH 26 Oct 97 nodeDiff = vnode6 - vnode4; cp = ( ( isovalue - vnode4 ) / nodeDiff ) + iy; VX[0][nvet] = ix; VY[0][nvet] = cp; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode4 ) / ( vnode6 - vnode4 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + xdim_x_ydim]; */ } calc_edge[10] = nvet; P_array[ 2*xx + above*yy + iy*xdim + ix ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0800) != 0) ) { /* cube vertex 5-7 */ /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode5; cp = ( ( isovalue - vnode5 ) / nodeDiff ) + iy; VX[0][nvet] = ix+1; VY[0][nvet] = cp; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode5 ) / ( vnode7 - vnode5 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim + xdim_x_ydim]; */ } calc_edge[11] = nvet; P_array[ 2*xx + above*yy + iy*xdim + (ix+1) ] = nvet; nvet++; } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x1000) != 0) ) { /* cube vertex 6-7 */ /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode6; cp = ( ( isovalue - vnode6 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy+1; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode6 ) / ( vnode7 - vnode6 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + 1 + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + 1 + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + 1 + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + 1 + xdim_x_ydim]; */ } calc_edge[12] = nvet; P_array[ above*xx + ix*ydim + (iy+1) ] = nvet; nvet++; } /* end find_vertex(); */ /* update_data_structure(ncube); */ kk = pol_edges[ptFLAG[ncube]][2]; nn = pol_edges[ptFLAG[ncube]][1]; for (ii=0; ii>= 4; pvp += 7; cpl++; } /* end update_data_structure(ncube); */ } else { // !(ptFLAG[ncube] < MAX_FLAG_NUM) /* find_vertex_invalid_cube(ncube); */ ptFLAG[ncube] &= 0x1FF; if ( (ptFLAG[ncube] != 0 & ptFLAG[ncube] != 0xFF) ) { if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0010) != 0) ) /* cube vertex 1-3 */ /* WLH 24 Oct 97 { if (!(iz != 0 ) && vnode3 < INV_VAL && vnode1 < INV_VAL) { if (!(iz != 0 ) && !Float.isNaN(vnode3) && !Float.isNaN(vnode1)) */ // test for not missing { if (!(iz != 0 ) && vnode3 == vnode3 && vnode1 == vnode1) { /* WLH 26 Oct 97 nodeDiff = vnode3 - vnode1; cp = ( ( isovalue - vnode1 ) / nodeDiff ) + iy; VX[0][nvet] = ix+1; VY[0][nvet] = cp; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode1 ) / ( vnode3 - vnode1 ) ); // WLH 4 Aug 2000 - replace Samples by samples VX[0][nvet] = (float) cp * samples[0][pt + ydim + 1] + (1.0f-cp) * samples[0][pt + ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + 1] + (1.0f-cp) * samples[1][pt + ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + 1] + (1.0f-cp) * samples[2][pt + ydim]; // end WLH 4 Aug 2000 - replace Samples by samples for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + 1] + (1.0f-cp) * auxValues[j][pt + ydim]; */ } P_array[ 2*xx + bellow*yy + iy*xdim + (ix+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0020) != 0) ) /* cube vertex 1-5 */ /* WLH 24 Oct 97 { if (!(iy != 0) && vnode5 < INV_VAL && vnode1 < INV_VAL) { if (!(iy != 0) && !Float.isNaN(vnode5) && !Float.isNaN(vnode1)) */ // test for not missing { if (!(iy != 0) && vnode5 == vnode5 && vnode1 == vnode1) { /* WLH 26 Oct 97 nodeDiff = vnode5 - vnode1; cp = ( ( isovalue - vnode1 ) / nodeDiff ) + iz; VX[0][nvet] = ix+1; VY[0][nvet] = iy; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode1 ) / ( vnode5 - vnode1 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim]; */ } P_array[ 2*xx + 2*yy + front*zz + iy ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0040) != 0) ) /* cube vertex 2-3 */ /* WLH 24 Oct 97 { if (!(iz != 0) && vnode3 < INV_VAL && vnode2 < INV_VAL) { if (!(iz != 0) && !Float.isNaN(vnode3) && !Float.isNaN(vnode2)) */ // test for not missing { if (!(iz != 0) && vnode3 == vnode3 && vnode2 == vnode2) { /* WLH 26 Oct 97 nodeDiff = vnode3 - vnode2; cp = ( ( isovalue - vnode2 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy+1; VZ[0][nvet] = iz; */ cp = ( ( isovalue - vnode2 ) / ( vnode3 - vnode2 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + 1] + (1.0f-cp) * samples[0][pt + 1]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + 1] + (1.0f-cp) * samples[1][pt + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + 1] + (1.0f-cp) * samples[2][pt + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + 1] + (1.0f-cp) * auxValues[j][pt + 1]; */ } P_array[ bellow*xx + ix*ydim + (iy+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0080) != 0) ) /* cube vertex 2-6 */ /* WLH 24 Oct 97 { if (!(ix != 0) && vnode6 < INV_VAL && vnode2 < INV_VAL) { if (!(ix != 0) && !Float.isNaN(vnode6) && !Float.isNaN(vnode2)) */ // test for not missing { if (!(ix != 0) && vnode6 == vnode6 && vnode2 == vnode2) { /* WLH 26 Oct 97 nodeDiff = vnode6 - vnode2; cp = ( ( isovalue - vnode2 ) / nodeDiff ) + iz; VX[0][nvet] = ix; VY[0][nvet] = iy+1; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode2 ) / ( vnode6 - vnode2 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + 1]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + 1]; */ } P_array[ 2*xx + 2*yy + rear*zz + (iy+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0100) != 0) ) /* cube vertex 3-7 */ /* WLH 24 Oct 97 { if (vnode7 < INV_VAL && vnode3 < INV_VAL) { if (!Float.isNaN(vnode7) && !Float.isNaN(vnode3)) */ // test for not missing { if (vnode7 == vnode7 && vnode3 == vnode3) { /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode3; cp = ( ( isovalue - vnode3 ) / nodeDiff ) + iz; VX[0][nvet] = ix+1; VY[0][nvet] = iy+1; VZ[0][nvet] = cp; */ cp = ( ( isovalue - vnode3 ) / ( vnode7 - vnode3 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim + 1]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim + 1]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim + 1]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim + 1]; */ } P_array[ 2*xx + 2*yy + front*zz + (iy+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0200) != 0) ) /* cube vertex 4-5 */ /* WLH 24 Oct 97 { if (!(iy != 0) && vnode5 < INV_VAL && vnode4 < INV_VAL) { if (!(iy != 0) && !Float.isNaN(vnode5) && !Float.isNaN(vnode4)) */ // test for not missing { if (!(iy != 0) && vnode5 == vnode5 && vnode4 == vnode4) { /* WLH 26 Oct 97 nodeDiff = vnode5 - vnode4; cp = ( ( isovalue - vnode4 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode4 ) / ( vnode5 - vnode4 ) ); VX[0][nvet] = (float) cp * samples[0][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + xdim_x_ydim]; */ } P_array[ above*xx + ix*ydim + iy ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0400) != 0) ) /* cube vertex 4-6 */ /* WLH 24 Oct 97 { if (!(ix != 0) && vnode6 < INV_VAL && vnode4 < INV_VAL) { if (!(ix != 0) && !Float.isNaN(vnode6) && !Float.isNaN(vnode4)) */ // test for not missing { if (!(ix != 0) && vnode6 == vnode6 && vnode4 == vnode4) { /* WLH 26 Oct 97 nodeDiff = vnode6 - vnode4; cp = ( ( isovalue - vnode4 ) / nodeDiff ) + iy; VX[0][nvet] = ix; VY[0][nvet] = cp; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode4 ) / ( vnode6 - vnode4 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + xdim_x_ydim]; */ } P_array[ 2*xx + above*yy + iy*xdim + ix ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x0800) != 0) ) /* cube vertex 5-7 */ /* WLH 24 Oct 97 { if (vnode7 < INV_VAL && vnode5 < INV_VAL) { if (!Float.isNaN(vnode7) && !Float.isNaN(vnode5)) */ // test for not missing { if (vnode7 == vnode7 && vnode5 == vnode5) { /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode5; cp = ( ( isovalue - vnode5 ) / nodeDiff ) + iy; VX[0][nvet] = ix+1; VY[0][nvet] = cp; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode5 ) / ( vnode7 - vnode5 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + ydim + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + ydim + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + ydim + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + ydim + xdim_x_ydim]; */ } P_array[ 2*xx + above*yy + iy*xdim + (ix+1) ] = nvet; nvet++; } } if ( ((pol_edges[ptFLAG[ncube]][3] & 0x1000) != 0) ) /* cube vertex 6-7 */ /* WLH 24 Oct 97 { if (vnode7 < INV_VAL && vnode6 < INV_VAL) { if (!Float.isNaN(vnode7) && !Float.isNaN(vnode6)) */ // test for not missing { if (vnode7 == vnode7 && vnode6 == vnode6) { /* WLH 26 Oct 97 nodeDiff = vnode7 - vnode6; cp = ( ( isovalue - vnode6 ) / nodeDiff ) + ix; VX[0][nvet] = cp; VY[0][nvet] = iy+1; VZ[0][nvet] = iz+1; */ cp = ( ( isovalue - vnode6 ) / ( vnode7 - vnode6 ) ); VX[0][nvet] = (float) cp * samples[0][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[0][pt + 1 + xdim_x_ydim]; VY[0][nvet] = (float) cp * samples[1][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[1][pt + 1 + xdim_x_ydim]; VZ[0][nvet] = (float) cp * samples[2][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * samples[2][pt + 1 + xdim_x_ydim]; for (int j=0; j 255) ? -1 : ((t < 128) ? t : t - 256) ) ); /* MEM_WLH tempaux[j][nvet] = (float) cp * auxValues[j][pt + 1 + ydim + xdim_x_ydim] + (1.0f-cp) * auxValues[j][pt + 1 + xdim_x_ydim]; */ } P_array[ above*xx + ix*ydim + (iy+1) ] = nvet; nvet++; } } } /* end find_vertex_invalid_cube(ncube); */ } } /* end if (exist_polygon_in_cube(ncube)) */ ncube++; pt++; } /* end for ( iy = 0; iy < ydim - 1; iy++ ) */ /* swap_planes(Z,rear,front); */ caseA = rear; rear = front; front = caseA; pt++; /* end swap_planes(Z,rear,front); */ } /* end for ( ix = 0; ix < xdim - 1; ix++ ) */ /* swap_planes(XY,bellow,above); */ caseA = bellow; bellow = above; above = caseA; pt += ydim; /* end swap_planes(XY,bellow,above); */ } /* end for ( iz = 0; iz < zdim - 1; iz++ ) */ // copy tempaux array into auxLevels array for (int i=0; i EPS_0) ? 1.e-4 : EPS_0); minimum_area = Float.MIN_VALUE; /* Calculate maximum number of vertices per polygon */ k = 6; n = 7*npolygons; while ( TRUE ) { for (i=k+7; i Vert_f_Pol[k]) break; if (i >= n) break; k = i; } max_vert_per_pol = Vert_f_Pol[k]; /* Calculate the Normals vector components for each Polygon */ /*$dir vector */ for ( i=0; i0) { /* check for valid polygon added by BEP 2-13-92 */ NxA[i] = VX[Vert_f_Pol[1+i*7]] - VX[Vert_f_Pol[0+i*7]]; NyA[i] = VY[Vert_f_Pol[1+i*7]] - VY[Vert_f_Pol[0+i*7]]; NzA[i] = VZ[Vert_f_Pol[1+i*7]] - VZ[Vert_f_Pol[0+i*7]]; } } swap_flag = 0; for ( k = 2; k < max_vert_per_pol; k++ ) { if (swap_flag==0) { /*$dir no_recurrence */ /* Vectorized */ for ( i=0; i= 0 ) { NxB[i] = VX[Vert_f_Pol[k+i*7]] - VX[Vert_f_Pol[0+i*7]]; NyB[i] = VY[Vert_f_Pol[k+i*7]] - VY[Vert_f_Pol[0+i*7]]; NzB[i] = VZ[Vert_f_Pol[k+i*7]] - VZ[Vert_f_Pol[0+i*7]]; Pnx[i] = NyA[i]*NzB[i] - NzA[i]*NyB[i]; Pny[i] = NzA[i]*NxB[i] - NxA[i]*NzB[i]; Pnz[i] = NxA[i]*NyB[i] - NyA[i]*NxB[i]; NxA[i] = Pnx[i]*Pnx[i] + Pny[i]*Pny[i] + Pnz[i]*Pnz[i]; if (NxA[i] > minimum_area) { Pnx[i] /= NxA[i]; Pny[i] /= NxA[i]; Pnz[i] /= NxA[i]; } } } } else { /* swap_flag!=0 */ /*$dir no_recurrence */ /* Vectorized */ for ( i=0; i= 0 ) { NxA[i] = VX[Vert_f_Pol[k+i*7]] - VX[Vert_f_Pol[0+i*7]]; NyA[i] = VY[Vert_f_Pol[k+i*7]] - VY[Vert_f_Pol[0+i*7]]; NzA[i] = VZ[Vert_f_Pol[k+i*7]] - VZ[Vert_f_Pol[0+i*7]]; Pnx[i] = NyB[i]*NzA[i] - NzB[i]*NyA[i]; Pny[i] = NzB[i]*NxA[i] - NxB[i]*NzA[i]; Pnz[i] = NxB[i]*NyA[i] - NyB[i]*NxA[i]; NxB[i] = Pnx[i]*Pnx[i] + Pny[i]*Pny[i] + Pnz[i]*Pnz[i]; if (NxB[i] > minimum_area) { Pnx[i] /= NxB[i]; Pny[i] /= NxB[i]; Pnz[i] /= NxB[i]; } } } } /* This Loop be Vectorized */ for ( i=0; i= 0) { iv[0] = Vert_f_Pol[0+i*7]; iv[1] = Vert_f_Pol[(k-1)+i*7]; iv[2] = Vert_f_Pol[k+i*7]; x = Pnx[i]; y = Pny[i]; z = Pnz[i]; // Update the origin vertex NX[iv[0]] += x; NY[iv[0]] += y; NZ[iv[0]] += z; // Update the vertex that defines the first vector NX[iv[1]] += x; NY[iv[1]] += y; NZ[iv[1]] += z; // Update the vertex that defines the second vector NX[iv[2]] += x; NY[iv[2]] += y; NZ[iv[2]] += z; } } swap_flag = ( (swap_flag != 0) ? 0 : 1 ); } /* Normalize the Normals */ for ( i=0; i EPS_0) { NX[i] /= len; NY[i] /= len; NZ[i] /= len; } } } public static int poly_triangle_stripe( int[] vet_pol, int[] Tri_Stripe, int nvertex, int npolygons, int[] Pol_f_Vert, int[] Vert_f_Pol ) throws VisADException { int i, j, k, m, ii, npol, cpol, idx, off, Nvt, vA, vB, ivA, ivB, iST, last_pol; boolean f_line_conection = false; last_pol = 0; npol = 0; iST = 0; ivB = 0; for (i=0; i=0 && Vert_f_Pol[ivB+off]>=0) { i=Vert_f_Pol[ivA+off]*9; k=i+Pol_f_Vert [i+8]; j=Vert_f_Pol[ivB+off]*9; m=j+Pol_f_Vert [j+8]; while (i>0 && j>0 && i= 0) break; } /* insert polygon alone */ if (npol < 0) { /*ptT = NTAB + STAB[Nvt-3];*/ idx = STAB[Nvt-3]; if (iST > 0) { Tri_Stripe[iST] = Tri_Stripe[iST-1]; iST++; Tri_Stripe[iST++] = Vert_f_Pol[NTAB[idx]+off]; } else f_line_conection = true; /* WLH 3-9-95 added */ for (ii=0; ii< ((Nvt < 6) ? Nvt:6); ii++) { Tri_Stripe[iST++] = Vert_f_Pol[NTAB[idx++]+off]; } continue; } if (( (ivB != 0) && ivA==(ivB-1)) || ( !(ivB != 0) && ivA==Nvt-1)) { /* ptT = ITAB + STAB[Nvt-3] + (ivB+1)*Nvt; */ idx = STAB[Nvt-3] + (ivB+1)*Nvt; if (f_line_conection) { Tri_Stripe[iST] = Tri_Stripe[iST-1]; iST++; Tri_Stripe[iST++] = Vert_f_Pol[ITAB[idx-1]+off]; f_line_conection = false; } for (ii=0; ii<((Nvt < 6) ? Nvt:6); ii++) { Tri_Stripe[iST++] = Vert_f_Pol[ITAB[--idx]+off]; } } else { /* ptT = NTAB + STAB[Nvt-3] + (ivB+1)*Nvt; */ idx = STAB[Nvt-3] + (ivB+1)*Nvt; if (f_line_conection) { Tri_Stripe[iST] = Tri_Stripe[iST-1]; iST++; Tri_Stripe[iST++] = Vert_f_Pol[NTAB[idx-1]+off]; f_line_conection = false; } for (ii=0; ii<((Nvt < 6) ? Nvt:6); ii++) { Tri_Stripe[iST++] = Vert_f_Pol[NTAB[--idx]+off]; } } vB = Tri_Stripe[iST-1]; vA = Tri_Stripe[iST-2]; cpol = npol; while (TRUE) { /* get_vertices_of_pol(cpol,Vt,Nvt) { */ Nvt = Vert_f_Pol [(j=cpol*7)+6]; off = j; /* } */ /* update_polygon(cpol) */ vet_pol[cpol] = 0; for (ivA=0; ivA=0 && vB>=0) { i=vA*9; k=i+Pol_f_Vert [i+8]; j=vB*9; m=j+Pol_f_Vert [j+8]; while (i>0 && j>0 && i=0 && vB>=0) { i=vA*9; k=i+Pol_f_Vert [i+8]; j=vB*9; m=j+Pol_f_Vert [j+8]; while (i>0 && j>0 && i gSet3D.LengthX-1) myGrid[0][index] -= 0.1; if (myGrid[1][index] > gSet3D.LengthY-1) myGrid[1][index] -= 0.1; if (myGrid[2][index] > gSet3D.LengthZ-1) myGrid[2][index] -= 0.1; } } } float[][] myValue = gSet3D.gridToValue(myGrid); for (int i=0; i " +((float) Math.round(1000000 *myValue[0][i]) /1000000)+", " +((float) Math.round(1000000 *myValue[1][i]) /1000000)+", " +((float) Math.round(1000000 *myValue[2][i]) /1000000)); } // Test valueToGrid function System.out.println("\nvalueToGrid test:"); float[][] gridTwo = gSet3D.valueToGrid(myValue); for (int i=0; i ("); if (Float.isNaN(gridTwo[0][i])) { System.out.print("NaN, "); } else { System.out.print(((float) Math.round(1000000 *gridTwo[0][i]) /1000000)+", "); } if (Float.isNaN(gridTwo[1][i])) { System.out.print("NaN, "); } else { System.out.print(((float) Math.round(1000000 *gridTwo[1][i]) /1000000)+", "); } if (Float.isNaN(gridTwo[2][i])) { System.out.println("NaN)"); } else { System.out.println(((float) Math.round(1000000 *gridTwo[2][i]) /1000000)+")"); } } System.out.println(); } /* Here's the output with sample file Gridded3D.txt: iris 28% java visad.Gridded3DSet < Gridded3D.txt num_dimensions = 3, num_coords = 27 Lengths = 3 3 3 wedge = 0 1 2 5 4 3 . . . Samples (3 x 3 x 3): #0: 18.629837, 8.529864, 10.997844 #1: 42.923097, 10.123978, 11.198275 . . . #25: 32.343298, 39.600872, 36.238975 #26: 49.919754, 40.119875, 36.018752 gridToValue test: (-0.4, -0.4, -0.4) --> 10.819755, -0.172592, 5.179111 (0.5, -0.4, -0.4) --> 32.683689, 1.262111, 5.359499 . . . (1.5, 2.4, 2.4) --> 43.844996, 48.904708, 40.008508 (2.4, 2.4, 2.4) --> 59.663807, 49.37181, 39.810308 valueToGrid test: 10.819755, -0.172592, 5.179111 --> (-0.4, -0.4, -0.4) 32.683689, 1.262111, 5.359499 --> (0.5, -0.4, -0.4) . . . 43.844996, 48.904708, 40.008508 --> (1.5, 2.4, 2.4) 59.663807, 49.37181, 39.810308 --> (2.4, 2.4, 2.4) iris 29% */ } .