[GraXML-commit] Graphics/JiveEvent/src/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps TRT.ja
Brought to you by:
hrivnac
From: Julius H. <hr...@us...> - 2008-05-28 09:45:02
|
Update of /cvsroot/graxml/Graphics/JiveEvent/src/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv7493/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps Added Files: TRT.java Log Message: TRT added --- NEW FILE: TRT.java --- package net.hep.atlas.graphics.JiveEvent.GeometricModel.Reps; import net.hep.atlas.graphics.JiveEvent.GeometricModel.JiveEventBuilder; import net.hep.atlas.graphics.JiveEvent.GeometricModel.JiveRep; // Generic Model import net.hep.atlas.graphics.JiveEvent.JAXB.TRTType; import net.hep.atlas.graphics.JiveEvent.JAXB.SubType; import net.hep.atlas.graphics.JiveEvent.JAXB.PhiType; import net.hep.atlas.graphics.JiveEvent.JAXB.RhozType; import net.hep.atlas.graphics.JiveEvent.JAXB.DriftRType; import net.hep.atlas.graphics.JiveEvent.JAXB.ThresholdType; // GraXML import net.hep.graphics.GraXML.BuildOptions; import net.hep.graphics.GraXML.GlobalOptions; import net.hep.graphics.GraXML.MasterBuilder; import net.hep.graphics.GraXML.Java3DExtensions.Interactivity.Interacter; import net.hep.graphics.GraXML.Disconnecter.DetachableConnection; import net.hep.graphics.GraXML.Java3DExtensions.BillboardGroup; // Java3D import javax.media.j3d.Shape3D; import javax.media.j3d.Group; import javax.media.j3d.BranchGroup; import javax.media.j3d.TransformGroup; import javax.media.j3d.Transform3D; import javax.media.j3d.Appearance; import javax.media.j3d.Material; import javax.media.j3d.LineAttributes; import javax.media.j3d.TransparencyAttributes; import javax.media.j3d.LineArray; import javax.media.j3d.GeometryArray; import javax.vecmath.Matrix3d; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.Vector3f; import javax.vecmath.Point3f; import javax.vecmath.Color3f; // FreeHEP import org.freehep.j3d.ConeSegment; // AWT import java.awt.Color; // Java import static java.lang.Math.toRadians; import static java.lang.Math.log; import static java.lang.Math.exp; import static java.lang.Math.abs; import static java.lang.Math.sqrt; import static java.lang.Math.sin; import static java.lang.Math.cos; import static java.lang.Math.signum; import static java.lang.Math.PI; // Log4J import org.apache.log4j.Logger; /** GraXML representation of <code>TRTType</code> * JiveEvent Type connected via JAXB * {@link net.hep.atlas.graphics.JiveEvent.JAXB.TRTType} generic JAXB interface. * <p><font color="#880088"> * <pre> * $Log: TRT.java,v $ * Revision 1.1 2008/05/28 09:45:03 hrivnac * TRT added * * </pre> * </font></p> * @opt attributes * @opt operations * @opt types * @opt visibility * @version $Id: TRT.java,v 1.1 2008/05/28 09:45:03 hrivnac Exp $ * @author <a href="mailto:Jul...@ce...">J.Hrivnac</a> */ public final class TRT extends JiveRep { public final void traverse(MasterBuilder builder, Object element, Group tg, String parent) { // Set values set(builder, tg, parent); // Verify element type if (! (element instanceof TRTType)) { log.error(element + " can't be traversed using " + getClass().getName() + " representation"); return; } // Create container BranchGroup g = new BranchGroup(); use(g, "TRTs", "TRT Container"); set(builder, g, "TRTs"); // Get Type properties TRTType trt = (TRTType)element; int count = trt.getCount(); String storeGateKey = trt.getStoreGateKey(); SubType sub = trt.getSub(); PhiType phi = trt.getPhi(); RhozType rhoz = trt.getRhoz(); DriftRType drift = trt.getDriftR(); ThresholdType threshold = trt.getThreshold(); int[] subs = ints( sub.getValue()); float[] phis = floats(phi.getValue()); float[] rhozs = floats(rhoz.getValue()); float[] drifts = floats(drift.getValue()); float[] thrasholds = floats(threshold.getValue()); // Draw all TRTs String name; String info; boolean outlinedBckp = Interacter.outlined(); Interacter.setOutlined(false); Shape3D shape; Appearance appearance; Material material; Color3f color; double x0; double y0; double z0; double r0; double x1; double y1; double z1; double r1; // Set base Tg _baseTg = tg(); // Determine, how to draw if (!_asCylinders && !_asLines) { if (count < 50) { _asCylinders = true; } else { _asLines = true; } } // Loop over TRTs for (int i = 0; i < count; i++) { name = "TRT(" + storeGateKey + "/" + subs[i] + "/" + i + ")"; info = name; color = color(i); // ColorList is set => get Appearance from Color if (color == null) { color = new Color3f(); appearance = builder().appearance(name, name); material = appearance.getMaterial(); material.getSpecularColor(color); } // ColorList is not set => get Color from Appearance else { appearance = new Appearance(); appearance.setMaterial(new Material(color, color, color, color, 1f)); } appearance. setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f)); appearance.setLineAttributes(new LineAttributes(lineWidth(), LineAttributes.PATTERN_SOLID, GlobalOptions.quality() > 5)); setAppearance(appearance); // Construct TRT // - endcap if (subs[i] == 0 || subs[i] == 3) { z0 = rhozs[i]; z1 = rhozs[i]; r0 = (abs(rhozs[i]) > 280 ? 48 : 64); r1 = 103; } // - barrel else { z0 = (rhozs[i] < 62 ? 40 : 0.35); z1 = 74.2; r0 = rhozs[i]; r1 = rhozs[i]; if (subs[i] == 1) { z0 = -z0; z1 = -z1; } } x0 = r0 * cos(phis[i]); y0 = r0 * sin(phis[i]); x1 = r1 * cos(phis[i]); y1 = r1 * sin(phis[i]); if (_asLines) { shape = asLine(x0, y0, z0, x1, y1, z1, color); } if (_asCylinders) { if (subs[i] == 0 || subs[i] == 3) { shape = asCylinder(abs(r1 - r0) + abs(z1 - z0), drifts[i], phis[i], (x1 + x0) / 2.0, (y1 + y0) / 2.0, (z1 + z0) / 2.0, false); } else { shape = asCylinder(abs(r1 - r0) + abs(z1 - z0), drifts[i], phis[i], (x1 + x0) / 2.0, (y1 + y0) / 2.0, (z1 + z0) / 2.0, true); } } // Use TRT shape.setAppearance(appearance); use(shape, name, info); } Interacter.setOutlined(outlinedBckp); } /** Draw one TRT straw as a {@link LineArray}. * @param x0 The x-coordinate of the straw near end. * @param y0 The y-coordinate of the straw near end. * @param z0 The z-coordinate of the straw near end. * @param x1 The x-coordinate of the straw far end. * @param y1 The y-coordinate of the straw far end. * @param z1 The z-coordinate of the straw far end. * @param color The straw color. * @return The {@link ConeSegment} {@link Shape3D} representing the TRT straw. */ private Shape3D asLine(double x0, double y0, double z0, double x1, double y1, double z1, Color3f color) { Shape3D shape = new Shape3D(); LineArray lineArray = new LineArray(2, GeometryArray.COORDINATES| GeometryArray.COLOR_3| GeometryArray.NORMALS); lineArray.setCoordinate(0, new Point3d(x0 / builder().norm(), y0 / builder().norm(), z0 / builder().norm())); lineArray.setCoordinate(1, new Point3d(x1 / builder().norm(), y1 / builder().norm(), z1 / builder().norm())); lineArray.setColor(0, color); lineArray.setColor(1, color); lineArray.setNormal(0, new Vector3f(0, 0, 0)); lineArray.setNormal(1, new Vector3f(0, 0, 0)); shape.addGeometry(lineArray); return shape; } /** Draw one TRT straw as a cylindric {@link ConeSegment}. * @param l The straw length * @param r The straw diameter (drift length). * @param phi The straw phi place. * @param x The x-coordinate of the straw middle point. * @param y The y-coordinate of the straw middle point. * @param z The z-coordinate of the straw middle point. * @param barrel Whether it is barrel straw. * @return The {@link ConeSegment} representing the TRT straw. */ private Shape3D asCylinder(double l, double r, double phi, double x, double y, double z, boolean barrel) { ConeSegment cone = new ConeSegment(r / builder().norm(), l / builder().norm(), BuildOptions.granularity() / 2, appearance()); Matrix3d m = new Matrix3d(UMATRIX); Matrix3d m0 = new Matrix3d(UMATRIX); m0.rotZ(phi + (float)(PI / 2f)); m.mul(m0); if (!barrel) { m0 = new Matrix3d(UMATRIX); m0.rotX(PI / 2f); m.mul(m0); } TransformGroup it = new TransformGroup(new Transform3D(m, new Vector3d(x / builder().norm(), y / builder().norm(), z / builder().norm()), 1)); setTg(_baseTg); tg().addChild(it); setTg(it); return cone; } /** Set {@link Color}s to be used for line segments. * @param colorMap The array of {@link Color}s. * @param colorList The array of {@link Color}s indexes. */ public static void setColors(Color[] colorMap, int[] colorList) { _colorMap = colorMap; _colorList = colorList; } /** Give {@link Color3f} to be used for <em>i</em>s line segments. * @param i The line segment number. * @return The {@link Color3f} o be used for <em>i</em>s line segment, * <em>null</em> is colormap is not set. */ protected Color3f color(int i) { if (_colorList == null) { return null; } return new Color3f(_colorMap[_colorList[i]]); } private static Color[] _colorMap; private static int[] _colorList; /** Give width of line segments, * the default is <code>2</code>. * @return The width of line segments. */ public int lineWidth() { return _lineWidth; } /** Set width of line segments, * the default is <code>2</code>. * @param lineWidth The width of line segments. */ public static void setLineWidth(int lineWidth) { _lineWidth = lineWidth; } private static int _lineWidth = 2; /** Set cylinder representation of straws. * If neither cylinder nor line is set, the representation is chosen * according to number of straws: cylinders are created for number * of straws smaller then 50. */ public static void asCylinders() { _asCylinders = true; _asLines = false; } /** Set line representation of straws. * If neither cylinder nor line is set, the representation is chosen * according to number of straws: cylinders are created for number * of straws smaller then 50. */ public static void asLines() { _asCylinders = false; _asLines = true; } private static booloean _asCylinders = false; private static boolean _asLines = false; private Group _baseTg; private static final Matrix3d UMATRIX = new Matrix3d(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); /** Logging . */ private static Logger log = Logger.getLogger(TRT.class); } |