// // ShadowFunctionOrSetTypeJ3D.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.java3d; import visad.*; import visad.util.ThreadManager; import javax.media.j3d.*; import java.util.ArrayList; import java.util.List; import java.util.Vector; import java.rmi.*; import java.awt.image.*; /** The ShadowFunctionOrSetTypeJ3D is an abstract parent for ShadowFunctionTypeJ3D and ShadowSetTypeJ3D.then return **/ public class ShadowFunctionOrSetTypeJ3D extends ShadowTypeJ3D { ShadowRealTupleTypeJ3D Domain; ShadowTypeJ3D Range; // null for ShadowSetTypeJ3D private Vector AccumulationVector = new Vector(); boolean post = false; boolean doTrajectory = false; boolean isAnimation1d = false; int domainLength = 0; Set anim1DdomainSet; Set domainSet; double trajVisibilityTimeWindow; FlowControl flowCntrl = null; ScalarMap flowMap = null; TrajectoryParams trajParams; ScalarMap altitudeToDisplayZ; List
branches = null; Switch swit = null; Switch switB = null; TrajectoryAVHandlerJ3D avHandler = null; public ShadowFunctionOrSetTypeJ3D(MathType t, DataDisplayLink link, ShadowType parent) throws VisADException, RemoteException { super(t, link, parent); if (this instanceof ShadowFunctionTypeJ3D) { Domain = (ShadowRealTupleTypeJ3D) ((FunctionType) Type).getDomain().buildShadowType(link, this); Range = (ShadowTypeJ3D) ((FunctionType) Type).getRange().buildShadowType(link, this); adaptedShadowType = new ShadowFunctionType(t, link, getAdaptedParent(parent), (ShadowRealTupleType) Domain.getAdaptedShadowType(), Range.getAdaptedShadowType()); } else { Domain = (ShadowRealTupleTypeJ3D) ((SetType) Type).getDomain().buildShadowType(Link, this); Range = null; adaptedShadowType = new ShadowSetType(t, link, getAdaptedParent(parent), (ShadowRealTupleType) Domain.getAdaptedShadowType()); } } public ShadowRealTupleTypeJ3D getDomain() { return Domain; } public ShadowTypeJ3D getRange() { return Range; } /** clear AccumulationVector */ public void preProcess() throws VisADException { AccumulationVector.removeAllElements(); if (this instanceof ShadowFunctionTypeJ3D) { Range.preProcess(); } } /** transform data into a Java3D scene graph; add generated scene graph components as children of group; value_array are inherited valueArray values; default_values are defaults for each display.DisplayRealTypeVector; return true if need post-process */ public boolean doTransform(Object group, Data data, final float[] value_array, final float[] default_values, final DataRenderer renderer) throws VisADException, RemoteException { boolean isTerminal = adaptedShadowType.getIsTerminal(); ScalarMap timeMap = null; // used in the animation case to get control DataDisplayLink[] link_s = renderer.getLinks(); DataDisplayLink link = link_s[0]; Vector scalarMaps = link.getSelectedMapVector(); // only determine if it's an animation if non-terminal. isTerminal will // only be determined if there are scalar maps - defaults to false if (!isTerminal && !scalarMaps.isEmpty()) { // determine if it's an animation MathType mtype = data.getType(); if (mtype instanceof FunctionType) { int ani_map_idx = 0; FunctionType function = (FunctionType) mtype; RealTupleType functionD = function.getDomain(); for (int kk = 0; kk < scalarMaps.size(); kk++) { ScalarMap scalarMap = (ScalarMap) scalarMaps.elementAt(kk); String scalar_name = scalarMap.getScalarName(); if (scalar_name.equals(((RealType) functionD.getComponent(0)).getName())) { if (((scalarMap.getDisplayScalar()).equals(Display.Animation)) && (functionD.getDimension() == 1)) { isAnimation1d = true; ani_map_idx = kk; } } } // animation domain timeMap = (ScalarMap) scalarMaps.elementAt(ani_map_idx); } // check for trajectory for (int kk=0; kk (); for (int i=0; i DisplayImplJ3D.TEXTURE_NPOT data_width, otherwise return the minimum power of two greater * thandata_width. * @see DisplayImplJ3D#TEXTURE_NPOT */ public int textureWidth(int data_width) { if (DisplayImplJ3D.TEXTURE_NPOT) return data_width; // must be a power of 2 in Java3D int texture_width = 1; while (texture_width < data_width) texture_width *= 2; return texture_width; } /** * Get the possibly adjusted texture height. * @param data_height The initial texture height. * @return IfDisplayImplJ3D.TEXTURE_NPOTthen return *data_height, otherwise return the minimum power of two greater * thandata_height. * @see DisplayImplJ3D#TEXTURE_NPOT */ public int textureHeight(int data_height) { if (DisplayImplJ3D.TEXTURE_NPOT) return data_height; // must be a power of 2 in Java3D int texture_height = 1; while (texture_height < data_height) texture_height *= 2; return texture_height; } /** * Get the possibly adjusted texture depth. * @param data_depth The initial texture depth. * @return IfDisplayImplJ3D.TEXTURE_NPOTthen return *data_depth, otherwise return the minimum power of two greater * thandata_depth. * @see DisplayImplJ3D#TEXTURE_NPOT */ public int textureDepth(int data_depth) { if (DisplayImplJ3D.TEXTURE_NPOT) return data_depth; // must be a power of 2 in Java3D int texture_depth = 1; while (texture_depth < data_depth) texture_depth *= 2; return texture_depth; } public void adjustZ(float[] coordinates) { if (display.getDisplayRenderer().getMode2D()) { for (int i=2; i0) { ((Group) group).setChild(branch, 0); } else { ((Group) group).addChild(branch); } if (tile != null) { tile.setImageComponent(image2d); } } public void texture3DToGroup(Object group, VisADGeometryArray arrayX, VisADGeometryArray arrayY, VisADGeometryArray arrayZ, VisADGeometryArray arrayXrev, VisADGeometryArray arrayYrev, VisADGeometryArray arrayZrev, BufferedImage[] images, GraphicsModeControl mode, float constant_alpha, float[] constant_color, int texture_width, int texture_height, int texture_depth, DataRenderer renderer) throws VisADException { GeometryArray geometryX = display.makeGeometry(arrayX); GeometryArray geometryY = display.makeGeometry(arrayY); GeometryArray geometryZ = display.makeGeometry(arrayZ); GeometryArray geometryXrev = display.makeGeometry(arrayXrev); GeometryArray geometryYrev = display.makeGeometry(arrayYrev); GeometryArray geometryZrev = display.makeGeometry(arrayZrev); // System.out.println("texture geometry"); // create basic Appearance TransparencyAttributes c_alpha = null; if (constant_alpha == 1.0f) { // constant opaque alpha = NONE c_alpha = null; } else if (constant_alpha == constant_alpha) { // c_alpha = new TransparencyAttributes(mode.getTransparencyMode(), c_alpha = new TransparencyAttributes(TransparencyAttributes.BLENDED, constant_alpha); } else { c_alpha = new TransparencyAttributes(); c_alpha.setTransparencyMode(TransparencyAttributes.BLENDED); } ColoringAttributes c_color = null; if (constant_color != null && constant_color.length == 3) { c_color = new ColoringAttributes(); c_color.setColor(constant_color[0], constant_color[1], constant_color[2]); } Appearance appearance = makeAppearance(mode, c_alpha, null, geometryX, true); // create TextureAttributes TextureAttributes texture_attributes = new TextureAttributes(); // texture_attributes.setTextureMode(TextureAttributes.REPLACE); texture_attributes.setTextureMode(TextureAttributes.MODULATE); texture_attributes.setPerspectiveCorrectionMode( TextureAttributes.NICEST); appearance.setTextureAttributes(texture_attributes); // create Texture2D // TextureLoader uses 1st argument = 1 /* System.out.println("Texture.BASE_LEVEL = " + Texture.BASE_LEVEL); // 1 System.out.println("Texture.RGBA = " + Texture.RGBA); // 6 */ Texture3D texture = new Texture3D(Texture.BASE_LEVEL, Texture.RGBA, texture_width, texture_height, texture_depth); texture.setCapability(Texture.ALLOW_IMAGE_READ); ImageComponent3D image3d = new ImageComponent3D(ImageComponent.FORMAT_RGBA, texture_width, texture_height, texture_depth); image3d.setCapability(ImageComponent.ALLOW_IMAGE_READ); for (int i=0; i 0) { ((Group) group).setChild(branch, 0); } else { ((Group) group).addChild(branch); } ProjectionControlJ3D control = (ProjectionControlJ3D) display.getProjectionControl(); control.addPair(swit, renderer); } public void textureStackToGroup(Object group, VisADGeometryArray arrayX, VisADGeometryArray arrayY, VisADGeometryArray arrayZ, VisADGeometryArray arrayXrev, VisADGeometryArray arrayYrev, VisADGeometryArray arrayZrev, BufferedImage[] imagesX, BufferedImage[] imagesY, BufferedImage[] imagesZ, GraphicsModeControl mode, float constant_alpha, float[] constant_color, int texture_width, int texture_height, int texture_depth, DataRenderer renderer) throws VisADException { GeometryArray[] geometryX = makeGeometrys(arrayX); GeometryArray[] geometryY = makeGeometrys(arrayY); GeometryArray[] geometryZ = makeGeometrys(arrayZ); /* not needed ?? GeometryArray[] geometryXrev = makeGeometrys(arrayXrev); GeometryArray[] geometryYrev = makeGeometrys(arrayYrev); GeometryArray[] geometryZrev = makeGeometrys(arrayZrev); */ int nx = arrayX.coordinates.length; boolean flipX = (arrayX.coordinates[0] > arrayX.coordinates[nx-3]); int ny = arrayY.coordinates.length; boolean flipY = (arrayY.coordinates[1] > arrayY.coordinates[ny-2]); int nz = arrayZ.coordinates.length; boolean flipZ = (arrayZ.coordinates[2] > arrayZ.coordinates[nz-1]); // System.out.println("flipX = " + flipX + " flipY = " + flipY + // " flipZ = " + flipZ); // create Attributes for Appearances TransparencyAttributes c_alpha = null; if (constant_alpha == 1.0f) { // constant opaque alpha = NONE c_alpha = null; } else if (constant_alpha == constant_alpha) { // c_alpha = new TransparencyAttributes(mode.getTransparencyMode(), c_alpha = new TransparencyAttributes(TransparencyAttributes.BLENDED, constant_alpha); } else { c_alpha = new TransparencyAttributes(); c_alpha.setTransparencyMode(TransparencyAttributes.BLENDED); } ColoringAttributes c_color = null; if (constant_color != null && constant_color.length == 3) { c_color = new ColoringAttributes(); c_color.setColor(constant_color[0], constant_color[1], constant_color[2]); } TextureAttributes texture_attributes = new TextureAttributes(); // WLH 17 March 2000 // texture_attributes.setTextureMode(TextureAttributes.MODULATE); texture_attributes.setTextureMode(TextureAttributes.REPLACE); texture_attributes.setPerspectiveCorrectionMode( TextureAttributes.NICEST); int transparencyMode = mode.getTransparencyMode(); OrderedGroup branchX = new OrderedGroup(); branchX.setCapability(Group.ALLOW_CHILDREN_READ); int data_depth = geometryX.length; Shape3D[] shapeX = new Shape3D[data_depth]; for (int ii=0; ii =0; ii--) { int i = flipX ? data_depth-1-ii : ii; int width = imagesX[i].getWidth(); int height = imagesX[i].getHeight(); Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, width, height); texture.setCapability(Texture.ALLOW_IMAGE_READ); ImageComponent2D image2d = new ImageComponent2D(ImageComponent.FORMAT_RGBA, imagesX[i]); image2d.setCapability(ImageComponent.ALLOW_IMAGE_READ); texture.setImage(0, image2d); Appearance appearance = makeAppearance(mode, c_alpha, null, geometryX[i], true); appearance.setTextureAttributes(texture_attributes); // WLH 17 March 2000 if (transparencyMode == TransparencyAttributes.FASTEST) { texture.setMinFilter(Texture.BASE_LEVEL_POINT); texture.setMagFilter(Texture.BASE_LEVEL_POINT); } else { texture.setBoundaryModeS(Texture.CLAMP); texture.setBoundaryModeT(Texture.CLAMP); texture.setMinFilter(Texture.BASE_LEVEL_LINEAR); texture.setMagFilter(Texture.BASE_LEVEL_LINEAR); } texture.setEnable(true); appearance.setTexture(texture); appearance.setCapability(Appearance.ALLOW_TEXTURE_READ); shapeX[i] = new Shape3D(geometryX[i], appearance); shapeX[i].setCapability(Shape3D.ALLOW_GEOMETRY_READ); shapeX[i].setCapability(Shape3D.ALLOW_APPEARANCE_READ); branchXrev.addChild(shapeX[i]); } shapeX = null; OrderedGroup branchY = new OrderedGroup(); branchY.setCapability(Group.ALLOW_CHILDREN_READ); int data_height = geometryY.length; Shape3D[] shapeY = new Shape3D[data_height]; for (int ii=0; ii =0; ii--) { int i = flipY ? data_height-1-ii : ii; int width = imagesY[i].getWidth(); int height = imagesY[i].getHeight(); Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, width, height); texture.setCapability(Texture.ALLOW_IMAGE_READ); // flip texture on Y axis ImageComponent2D image2d = new ImageComponent2D(ImageComponent.FORMAT_RGBA, imagesY[i]); image2d.setCapability(ImageComponent.ALLOW_IMAGE_READ); texture.setImage(0, image2d); Appearance appearance = makeAppearance(mode, c_alpha, null, geometryY[i], true); appearance.setTextureAttributes(texture_attributes); // WLH 17 March 2000 if (transparencyMode == TransparencyAttributes.FASTEST) { texture.setMinFilter(Texture.BASE_LEVEL_POINT); texture.setMagFilter(Texture.BASE_LEVEL_POINT); } else { texture.setBoundaryModeS(Texture.CLAMP); texture.setBoundaryModeT(Texture.CLAMP); texture.setMinFilter(Texture.BASE_LEVEL_LINEAR); texture.setMagFilter(Texture.BASE_LEVEL_LINEAR); } texture.setEnable(true); appearance.setTexture(texture); appearance.setCapability(Appearance.ALLOW_TEXTURE_READ); shapeY[i] = new Shape3D(geometryY[i], appearance); shapeY[i].setCapability(Shape3D.ALLOW_GEOMETRY_READ); shapeY[i].setCapability(Shape3D.ALLOW_APPEARANCE_READ); branchYrev.addChild(shapeY[i]); } shapeY = null; OrderedGroup branchZ = new OrderedGroup(); branchZ.setCapability(Group.ALLOW_CHILDREN_READ); int data_width = geometryZ.length; Shape3D[] shapeZ = new Shape3D[data_width]; for (int ii=0; ii =0; ii--) { int i = flipZ ? data_width-1-ii : ii; int width = imagesZ[i].getWidth(); int height = imagesZ[i].getHeight(); Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, width, height); texture.setCapability(Texture.ALLOW_IMAGE_READ); ImageComponent2D image2d = new ImageComponent2D(ImageComponent.FORMAT_RGBA, imagesZ[i]); image2d.setCapability(ImageComponent.ALLOW_IMAGE_READ); texture.setImage(0, image2d); Appearance appearance = makeAppearance(mode, c_alpha, null, geometryZ[i], true); appearance.setTextureAttributes(texture_attributes); // WLH 17 March 2000 if (transparencyMode == TransparencyAttributes.FASTEST) { texture.setMinFilter(Texture.BASE_LEVEL_POINT); texture.setMagFilter(Texture.BASE_LEVEL_POINT); } else { texture.setBoundaryModeS(Texture.CLAMP); texture.setBoundaryModeT(Texture.CLAMP); texture.setMinFilter(Texture.BASE_LEVEL_LINEAR); texture.setMagFilter(Texture.BASE_LEVEL_LINEAR); } texture.setEnable(true); appearance.setTexture(texture); appearance.setCapability(Appearance.ALLOW_TEXTURE_READ); shapeZ[i] = new Shape3D(geometryZ[i], appearance); shapeZ[i].setCapability(Shape3D.ALLOW_GEOMETRY_READ); shapeZ[i].setCapability(Shape3D.ALLOW_APPEARANCE_READ); branchZrev.addChild(shapeZ[i]); } shapeZ = null; Switch swit = (Switch) makeSwitch(); swit.addChild(branchX); swit.addChild(branchY); swit.addChild(branchZ); swit.addChild(branchXrev); swit.addChild(branchYrev); swit.addChild(branchZrev); // WLH 6 April 2000 // ((Group) group).addChild(swit); BranchGroup branch = new BranchGroup(); branch.setCapability(BranchGroup.ALLOW_DETACH); branch.setCapability(BranchGroup.ALLOW_CHILDREN_READ); branch.addChild(swit); if (((Group) group).numChildren() > 0) { ((Group) group).setChild(branch, 0); } else { ((Group) group).addChild(branch); } ProjectionControlJ3D control = (ProjectionControlJ3D) display.getProjectionControl(); control.addPair(swit, renderer); } /* GeometryArray[] makeGeometrys(VisADGeometryArray array) throws VisADException { int count = array.vertexCount; int depth = count / 4; int color_length = array.colors.length / count; int tex_length = array.texCoords.length / count; GeometryArray[] geometrys = new GeometryArray[depth]; for (int d=0; d flowInfoList = Range.getAdaptedShadowType().getFlowInfo(); int dataDomainLength = anim1DdomainSet.getLength(); boolean trcrEnabled = trajParams.getMarkerEnabled(); int trajForm = trajParams.getTrajectoryForm(); boolean autoSizeTrcr = true; float trcrSize = trajParams.getMarkerSize(); double trajRefreshInterval = trajParams.getTrajRefreshInterval(); int direction = trajParams.getDirection(); DataRenderer renderer = getLink().getRenderer(); ProjectionControl pCntrl = renderer.getDisplay().getProjectionControl(); MouseBehavior mouseBehav = renderer.getDisplay().getMouseBehavior(); FixGeomSizeAppearance listener = null; double[] times = TrajectoryManager.getTimes((Gridded1DSet)anim1DdomainSet); double[] timeSteps = TrajectoryManager.getTimeSteps((Gridded1DSet)anim1DdomainSet); TrajectoryManager trajMan = new TrajectoryManager(renderer, trajParams, flowInfoList, dataDomainLength, times[0], altitudeToDisplayZ); trcrEnabled = (trcrEnabled && (trajForm == TrajectoryManager.LINE)) && trajForm != TrajectoryManager.POINT; if (autoSizeTrcr && trcrEnabled) { listener = new FixGeomSizeAppearanceJ3D(pCntrl, this, mouseBehav); trajMan.setListener(pCntrl, listener, flowCntrl); listener.lock(); } double[] dspScale = TrajectoryManager.getScale(mouseBehav, pCntrl); // current dispaly scale double scale = dspScale[0]; trajMan.initCleanUp(flowMap, flowCntrl, pCntrl, display); double trcrSizeRatio = 1; double timeAccum = 0; VisADGeometryArray array = null; VisADGeometryArray trcrArray = null; VisADGeometryArray[] auxArray = new VisADGeometryArray[1]; ArrayList achrArrays = null; for (int k=0; k 0) { achrArrays = new ArrayList (); trcrArray = trajMan.makeTracerGeometry(achrArrays, direction, trcrSize, dspScale, true); trcrArray = TrajectoryManager.scaleGeometry(trcrArray, achrArrays, (float)(1.0/scale)); } GraphicsModeControl mode = (GraphicsModeControl) info.mode.clone(); // something weird with this, everything being removed ? //array = (VisADLineArray) array.removeMissing(); if ((k==0) || (timeAccum >= trajRefreshInterval)) { // for non steady state trajectories (refresh frequency) avHandler.setNoneVisibleIndex(i); timeAccum = 0.0; } timeAccum += timeSteps[i]; if (trcrEnabled) { Object group = switB.getChild(i); BranchGroup trcrBG = addToDetachableGroup(group, trcrArray, mode, info.constant_alpha, info.constant_color); if (listener != null && trcrArray != null) { listener.add(trcrBG, trcrArray, achrArrays, mode, info.constant_alpha, info.constant_color); } } BranchGroup branch = (BranchGroup) branches.get(i); addToGroup(branch, array, mode, info.constant_alpha, info.constant_color); BranchGroup node = (BranchGroup) swit.getChild(i); node.addChild(branch); if (auxArray[0] != null) { BranchGroup auxBrnch = (BranchGroup) makeBranch(); addToGroup(auxBrnch, auxArray[0], mode, info.constant_alpha, info.constant_color); ((BranchGroup)switB.getChild(i)).addChild(auxBrnch); } } //--- domain length (time steps) outer time loop ------------------------- if (listener != null) { if (listener.isLocked()) { listener.update(); listener.unlock(); } } } }
Ads help maintain this website.