//
// VisADTriangleStripArray.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 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;

/**
   VisADTriangleStripArray stands in for
   j3d.TriangleStripArray and is Serializable.

*/ public class VisADTriangleStripArray extends VisADGeometryArray { public int[] stripVertexCounts; public static VisADTriangleStripArray merge(VisADTriangleStripArray[] arrays) throws VisADException { if (arrays == null || arrays.length == 0) return null; VisADTriangleStripArray array = new VisADTriangleStripArray(); merge(arrays, array); int n = arrays.length; int nstrips = 0; for (int i=0; i max_length) max_length = lengths[i]; } } // end for (int i=last_i; i= limit_length) { last_i = 0; // start i for each vertex strip for (int i_svc=0; i_svc limit_length); if (test[i]) any_split = true; } // end for (int i=last_i; i= 3) { svcs[svc_index] = accum; svc_index++; } lastcoord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { lastno = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { lastcol = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { lastcol = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { lasttex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum = 1; // reset strip counter; continue; } // lon_axis >= 0 // split line by interpolation float a, b; float coord_first, coord_second; if (lons[i3] < low) { a = lons[i3] - bottom; b = top - lons[i3 + 1]; coord_first = coord_bottom; coord_second = coord_top; } else { a = top - lons[i3]; b = lons[i3 + 1] - bottom; coord_first = coord_top; coord_second = coord_bottom; } float alpha = b / (a + b); alpha = (alpha != alpha || alpha < 0.0f) ? 0.0f : ((1.0f < alpha) ? 1.0f : alpha); float beta = 1.0f - alpha; midcoord_first = new float[] {alpha * coordinates[i] + beta * coordinates[i+3], alpha * coordinates[i+1] + beta * coordinates[i+4], alpha * coordinates[i+2] + beta * coordinates[i+5]}; midcoord_second = new float[] {midcoord_first[0], midcoord_first[1], midcoord_first[2]}; midcoord_first[lon_axis] = coord_first; midcoord_second[lon_axis] = coord_second; if (normals != null) { midno = new float[] {alpha * normals[i] + beta * normals[i+3], alpha * normals[i+1] + beta * normals[i+4], alpha * normals[i+2] + beta * normals[i+5]}; } if (color_length == 3) { midcol = new byte[] {ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j]) + beta * ShadowType.byteToFloat(colors[j+3])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j+1]) + beta * ShadowType.byteToFloat(colors[j+4])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j+2]) + beta * ShadowType.byteToFloat(colors[j+5]))}; } else if (color_length == 4) { midcol = new byte[] {ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j]) + beta * ShadowType.byteToFloat(colors[j+4])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j+1]) + beta * ShadowType.byteToFloat(colors[j+5])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j+2]) + beta * ShadowType.byteToFloat(colors[j+6])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j+3]) + beta * ShadowType.byteToFloat(colors[j+7]))}; } if (texCoords != null) { midtex = new float[] {alpha * texCoords[t] + beta * texCoords[t+2], alpha * texCoords[t+1] + beta * texCoords[t+3]}; } } else { // no split this_split = false; } if (accum > 0 && this_split != last_split && lon_axis >= 0) { // need to compute mid edge from -3 to +3 // split line by interpolation float a, b; float coord_first, coord_second; if (lons[i3 - 1] < low) { a = lons[i3 - 1] - bottom; b = top - lons[i3 + 1]; coord_first = coord_bottom; coord_second = coord_top; } else { a = top - lons[i3 - 1]; b = lons[i3 + 1] - bottom; coord_first = coord_top; coord_second = coord_bottom; } float alpha = b / (a + b); alpha = (alpha != alpha || alpha < 0.0f) ? 0.0f : ((1.0f < alpha) ? 1.0f : alpha); float beta = 1.0f - alpha; sillymidcoord_first = new float[] {alpha * coordinates[i-3] + beta * coordinates[i+3], alpha * coordinates[i-2] + beta * coordinates[i+4], alpha * coordinates[i-1] + beta * coordinates[i+5]}; sillymidcoord_second = new float[] {sillymidcoord_first[0], sillymidcoord_first[1], sillymidcoord_first[2]}; sillymidcoord_first[lon_axis] = coord_first; sillymidcoord_second[lon_axis] = coord_second; if (normals != null) { sillymidno = new float[] {alpha * normals[i-3] + beta * normals[i+3], alpha * normals[i-2] + beta * normals[i+4], alpha * normals[i-1] + beta * normals[i+5]}; } if (color_length == 3) { sillymidcol = new byte[] {ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-3]) + beta * ShadowType.byteToFloat(colors[j+3])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-2]) + beta * ShadowType.byteToFloat(colors[j+4])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-1]) + beta * ShadowType.byteToFloat(colors[j+5]))}; } else if (color_length == 4) { sillymidcol = new byte[] {ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-4]) + beta * ShadowType.byteToFloat(colors[j+4])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-3]) + beta * ShadowType.byteToFloat(colors[j+5])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-2]) + beta * ShadowType.byteToFloat(colors[j+6])), ShadowType.floatToByte( alpha * ShadowType.byteToFloat(colors[j-1]) + beta * ShadowType.byteToFloat(colors[j+7]))}; } if (texCoords != null) { sillymidtex = new float[] {alpha * texCoords[t-2] + beta * texCoords[t+2], alpha * texCoords[t-1] + beta * texCoords[t+3]}; } } if (this_split) { if (accum == 0) { earlycoord = new float[] {midcoord_second[0], midcoord_second[1], midcoord_second[2]}; lastcoord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { earlyno = new float[] {midno[0], midno[1], midno[2]}; lastno = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { earlycol = new byte[] {midcol[0], midcol[1], midcol[2]}; lastcol = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { earlycol = new byte[] {midcol[0], midcol[1], midcol[2], midcol[3]}; lastcol = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { earlytex = new float[] {midtex[0], midtex[1]}; lasttex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum = 2; continue; // don't make any triangles yet, for accum = 0 } // end if (accum == 0) else if (last_split) { // && this_split coord = midcoord_first; no = midno; col = midcol; tex = midtex; accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); // bind off svcs[svc_index] = accum; svc_index++; // accum = 0, but more to come // create a 2-triangle strip // (last_mid_first, i-3, mid_second, i+3) earlycoord = last_midcoord_first; earlyno = last_midno; earlycol = last_midcol; earlytex = last_midtex; lastcoord = new float[] {coordinates[i-3], coordinates[i-2], coordinates[i-1]}; if (normals != null) { lastno = new float[] {normals[i-3], normals[i-2], normals[i-1]}; } if (color_length == 3) { lastcol = new byte[] {colors[j-3], colors[j-2], colors[j-1]}; } else if (color_length == 4) { lastcol = new byte[] {colors[j-4], colors[j-3], colors[j-2], colors[j-1]}; } if (texCoords != null) { lasttex = new float[] {texCoords[t-2], texCoords[t-1]}; } coord = midcoord_second; no = midno; col = midcol; tex = midtex; accum = 3; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); coord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { no = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { col = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { col = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { tex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); } else { // !last_split && accum > 0 && this_split // add (mid_first, i-3, sillymid_first) coord = midcoord_first; no = midno; col = midcol; tex = midtex; accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); coord = new float[] {coordinates[i-3], coordinates[i-2], coordinates[i-1]}; if (normals != null) { no = new float[] {normals[i-3], normals[i-2], normals[i-1]}; } if (color_length == 3) { col = new byte[] {colors[j-3], colors[j-2], colors[j-1]}; } else if (color_length == 4) { col = new byte[] {colors[j-4], colors[j-3], colors[j-2], colors[j-1]}; } if (texCoords != null) { tex = new float[] {texCoords[t-2], texCoords[t-1]}; } accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); coord = sillymidcoord_first; no = sillymidno; col = sillymidcol; tex = sillymidtex; accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); // (accum >= 3) svcs[svc_index] = accum; svc_index++; // accum = 0, but more to come // start a triangle strip // (sillymid_second, mid_second, i+3) earlycoord = sillymidcoord_second; earlyno = sillymidno; earlycol = sillymidcol; earlytex = sillymidtex; lastcoord = midcoord_second; lastno = midno; lastcol = midcol; lasttex = midtex; coord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { no = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { col = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { col = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { tex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum = 3; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); } } else { // !this_split if (accum == 0) { earlycoord = new float[] {coordinates[i], coordinates[i+1], coordinates[i+2]}; lastcoord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { earlyno = new float[] {normals[i], normals[i+1], normals[i+2]}; lastno = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { earlycol = new byte[] {colors[j], colors[j+1], colors[j+2]}; lastcol = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { earlycol = new byte[] {colors[j], colors[j+1], colors[j+2], colors[j+3]}; lastcol = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { earlytex = new float[] {texCoords[t], texCoords[t+1]}; lasttex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum = 2; continue; // don't make any triangles yet, for accum = 0 } // end if (accum == 0) else if (last_split && lon_axis >= 0) { // && !this_split // first, bind off if (accum >= 3) { svcs[svc_index] = accum; svc_index++; } // accum = 0, but more to come // create a lone triangle (i-3, last_mid_first, sillymid_first) earlycoord = new float[] {coordinates[i-3], coordinates[i-2], coordinates[i-1]}; if (normals != null) { earlyno = new float[] {normals[i-3], normals[i-2], normals[i-1]}; } if (color_length == 3) { earlycol = new byte[] {colors[j-3], colors[j-2], colors[j-1]}; } else if (color_length == 4) { earlycol = new byte[] {colors[j-4], colors[j-3], colors[j-2], colors[j-1]}; } if (texCoords != null) { earlytex = new float[] {texCoords[t-2], texCoords[t-1]}; } lastcoord = last_midcoord_first; lastno = last_midno; lastcol = last_midcol; lasttex = last_midtex; coord = sillymidcoord_first; no = sillymidno; col = sillymidcol; tex = sillymidtex; accum = 3; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); // bind off again svcs[svc_index] = accum; svc_index++; // accum = 0, but more to come // create a 2-triangle strip // (last_mid_second, sillymid_second, i, i+3) earlycoord = last_midcoord_second; earlyno = last_midno; earlycol = last_midcol; earlytex = last_midtex; lastcoord = sillymidcoord_second; lastno = sillymidno; lastcol = sillymidcol; lasttex = sillymidtex; coord = new float[] {coordinates[i], coordinates[i+1], coordinates[i+2]}; if (normals != null) { no = new float[] {normals[i], normals[i+1], normals[i+2]}; } if (color_length == 3) { col = new byte[] {colors[j], colors[j+1], colors[j+2]}; } else if (color_length == 4) { col = new byte[] {colors[j], colors[j+1], colors[j+2], colors[j+3]}; } if (texCoords != null) { tex = new float[] {texCoords[t], texCoords[t+1]}; } accum = 3; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); coord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { no = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { col = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { col = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { tex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); } else { // (!last_split || lon_axis < 0) && accum > 0 && !this_split // just add the next point (i+3) if (earlycoord == null) { earlycoord = new float[3]; if (normals != null) { earlyno = new float[3]; } if (color_length > 0) { earlycol = new byte[color_length]; } if (texCoords != null) { earlytex = new float[2]; } } coord = new float[] {coordinates[i+3], coordinates[i+4], coordinates[i+5]}; if (normals != null) { no = new float[] {normals[i+3], normals[i+4], normals[i+5]}; } if (color_length == 3) { col = new byte[] {colors[j+3], colors[j+4], colors[j+5]}; } else if (color_length == 4) { col = new byte[] {colors[j+4], colors[j+5], colors[j+6], colors[j+7]}; } if (texCoords != null) { tex = new float[] {texCoords[t+2], texCoords[t+3]}; } accum++; nextPoint(accum, color_length, coords, nos, cols, texs, coord, no, col, tex, lastcoord, lastno, lastcol, lasttex, earlycoord, earlyno, earlycol, earlytex, kmr); } } // end if no split } // end for (int i=last_i; i= 3) { svcs[svc_index] = accum; svc_index++; } last_i += stripVertexCounts[i_svc] * 3; } // end for (int i_svc=0; i_svc= 3) { int iml = i; int jml = j; int tml = t; if (accum == 3) { iml = i - 6; jml = j - 2 * color_length; tml = t - 4; } int jm = jml; int tm = tml; for (int im=iml; im<=i; im+=3) { coords[k] = coordinates[im]; coords[k+1] = coordinates[im+1]; coords[k+2] = coordinates[im+2]; if (normals != null) { nos[k] = normals[im]; nos[k+1] = normals[im+1]; nos[k+2] = normals[im+2]; } if (colors != null) { cols[m] = colors[jm]; cols[m+1] = colors[jm+1]; cols[m+2] = colors[jm+2]; m += 3; if (color_length == 4) { cols[m++] = colors[jm+3]; } } if (texCoords != null) { texs[r] = texCoords[tm]; texs[r+1] = texCoords[tm+1]; r += 2; } k += 3; jm += color_length; tm += 2; } // end for (im=iml; im<=i; im+=3) } // end if (accum >= 3) } else { // missing coordinates values any_missing = true; if (accum >= 3) { svcs[svc_index] = accum; svc_index++; } accum = 0; // reset strip counter; } j += color_length; t += 2; } // end for (int i=last_i; i= 3) { svcs[svc_index] = accum; svc_index++; } last_i += stripVertexCounts[i_svc] * 3; } // end for (int i_svc=0; i_svc

Ads help maintain this website.