[GraXML-commit] Graphics/JiveEvent/src/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps AMDTDa
Brought to you by:
hrivnac
Update of /cvsroot/graxml/Graphics/JiveEvent/src/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv14005/GeometricModel/Reps Modified Files: TRT.java Added Files: AMDTDataProxy.java ARPCDataProxy.java MDT.java RPC.java Log Message: MDT + RPC added --- NEW FILE: MDT.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.MDTType; // 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; // Atlantis import atlantis.utils.AHashMap; // 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.BoundingSphere; import javax.media.j3d.Appearance; import javax.media.j3d.Material; import javax.media.j3d.LineAttributes; import javax.media.j3d.PointAttributes; import javax.media.j3d.TransparencyAttributes; import javax.media.j3d.LineArray; import javax.media.j3d.PointArray; 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.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>MDTType</code> * JiveEvent Type connected via JAXB * {@link net.hep.atlas.graphics.JiveEvent.JAXB.MDTType} generic JAXB interface. * <p><font color="#880088"> * <pre> * $Log: MDT.java,v $ * Revision 1.1 2008/06/06 13:27:07 hrivnac * MDT + RPC added * * </pre> * </font></p> * @opt attributes * @opt operations * @opt types * @opt visibility * @version $Id: MDT.java,v 1.1 2008/06/06 13:27:07 hrivnac Exp $ * @author <a href="mailto:Jul...@ce...">J.Hrivnac</a> */ public final class MDT 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 MDTType)) { log.error(element + " can't be traversed using " + getClass().getName() + " representation"); return; } // Create container BranchGroup g = new BranchGroup(); use(g, "MDTs", "MDT Container"); set(builder, g, "MDTs"); // Get Type properties MDTType mdt = (MDTType)element; int count = mdt.getCount(); String storeGateKey = mdt.getStoreGateKey(); float[] xs = floats( mdt.getX( ).getValue()); float[] ys = floats( mdt.getY( ).getValue()); float[] zs = floats( mdt.getZ( ).getValue()); float[] lengths = floats( mdt.getLength( ).getValue()); float[] drifts = floats( mdt.getDriftR( ).getValue()); int[] ids = ints( mdt.getId( ).getValue()); int[] barcodes = ints( mdt.getBarcode( ).getValue()); String[] identifiers = strings(mdt.getIdentifier().getValue()); // Get Atlantis proxy to MDT AHashMap p = new AHashMap(10); p.put("numData", count); p.put("storeGateKey", storeGateKey); p.put("x", xs); p.put("y", ys); p.put("z", zs); p.put("length", lengths); p.put("driftR", drifts); p.put("id", ids); p.put("barcode", barcodes); p.put("identifier", identifiers); AMDTDataProxy amdt = new AMDTDataProxy(p); // Draw all MDTs 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; boolean barrel; // Set base Tg _baseTg = tg(); // Determine, how to draw if (count < 50) { asCylinders(true); } else { asLines(true); } // Loop over MDTs for (int i = 0; i < count; i++) { name = "MDT(" + storeGateKey + "/" + 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 MDT r0 = amdt.r()[i]; r1 = amdt.r()[i]; x0 = r0 * cos(amdt.phi()[i]); x1 = r1 * cos(amdt.phi()[i]); y0 = r0 * sin(amdt.phi()[i]); y1 = r1 * sin(amdt.phi()[i]); z0 = amdt.z()[i] - amdt.l()[i] / 2.0; z1 = amdt.z()[i] + amdt.l()[i] / 2.0; if (_asLines) { shape = asLine(x0, y0, z0, x1, y1, z1, color); } else { shape = asCylinder(abs(r1 - r0) + abs(z1 - z0), amdt.d()[i], amdt.phi()[i], (x1 + x0) / 2.0, (y1 + y0) / 2.0, (z1 + z0) / 2.0, true); } // Use MDT shape.setAppearance(appearance); use(shape, name, info); } Interacter.setOutlined(outlinedBckp); } /** Draw one MDT 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 MDT straw. */ // TBD: put into Rep 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 MDT 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 MDT straw. */ // TBD: put into Rep 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; } /** 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. * Default is <code>false</code>. */ public static void asCylinders(boolean cylinders) { _asCylinders = cylinders; _asLines = !cylinders; } /** 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. * Default is <code>false</code>. */ public static void asLines(boolean lines) { _asLines = lines; _asCylinders = !lines; } private static boolean _asCylinders = false; private static boolean _asLines = false; /** 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; 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(MDT.class); } --- NEW FILE: AMDTDataProxy.java --- package net.hep.atlas.graphics.JiveEvent.GeometricModel.Reps; import net.hep.atlas.graphics.JiveEvent.GeometricModel.JiveEventBuilder; // Atlantis import atlantis.event.AMDTData; import atlantis.graphics.ACoord; import atlantis.utils.AHashMap; // Java3D import javax.vecmath.Point2d; // Java import java.util.HashMap; /** GraXML proxy to {@link AMDTData}. * <p><font color="#880088"> * <pre> * $Log: AMDTDataProxy.java,v $ * Revision 1.1 2008/06/06 13:26:54 hrivnac * MDT + RPC added * * </pre> * </font></p> * @opt attributes * @opt operations * @opt types * @opt visibility * @version $Id: AMDTDataProxy.java,v 1.1 2008/06/06 13:26:54 hrivnac Exp $ * @author <a href="mailto:Jul...@ce...">J.Hrivnac</a> */ public class AMDTDataProxy extends AMDTData { /** Constructs a new muon box proxy. * @param p TBD */ public AMDTDataProxy(AHashMap p) { super(p); _r = new double[numDraw]; _z = new double[numDraw]; _d = new double[numDraw]; _l = new double[numDraw]; _phi = new double[numDraw]; for (int i = 0; i < numDraw; i++) { _r[ i] = getSectorRho(sector[i], rho[i], phi[i]); _z[ i] = z[ i]; _d[ i] = driftR[i]; _l[ i] = length[i]; _phi[i] = phi[ i]; } } /** TBD */ public double[] r() { return _r; } /** TBD */ public double[] z() { return _z; } /** TBD */ public double[] d() { return _d; } /** TBD */ public double[] l() { return _l; } /** TBD */ public double[] phi() { return _phi; } private double[] _r; private double[] _z; private double[] _d; private double[] _l; private double[] _phi; } Index: TRT.java =================================================================== RCS file: /cvsroot/graxml/Graphics/JiveEvent/src/net/hep/atlas/graphics/JiveEvent/GeometricModel/Reps/TRT.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TRT.java 28 May 2008 13:16:38 -0000 1.2 --- TRT.java 6 Jun 2008 13:27:13 -0000 1.3 *************** *** 65,68 **** --- 65,71 ---- * <pre> * $Log$ + * Revision 1.3 2008/06/06 13:27:13 hrivnac + * MDT + RPC added + * * Revision 1.2 2008/05/28 13:16:38 hrivnac * TRT improved *************** *** 142,149 **** if (!_asCylinders && !_asLines) { if (count0 < 50) { ! asCylinders(); } else { ! asLines(); } } --- 145,152 ---- if (!_asCylinders && !_asLines) { if (count0 < 50) { ! asCylinders(true); } else { ! asLines(true); } } --- NEW FILE: RPC.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.RPCType; // 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; // Atlantis import atlantis.utils.AHashMap; // 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.BoundingSphere; import javax.media.j3d.Appearance; import javax.media.j3d.Material; import javax.media.j3d.LineAttributes; import javax.media.j3d.PointAttributes; import javax.media.j3d.TransparencyAttributes; import javax.media.j3d.LineArray; import javax.media.j3d.PointArray; 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.Trapezoid; // AWT import java.awt.Color; // Java import static java.lang.Math.toRadians; import static java.lang.Math.log; 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>RPCType</code> * JiveEvent Type connected via JAXB * {@link net.hep.atlas.graphics.JiveEvent.JAXB.RPCType} generic JAXB interface. * <p><font color="#880088"> * <pre> * $Log: RPC.java,v $ * Revision 1.1 2008/06/06 13:27:11 hrivnac * MDT + RPC added * * </pre> * </font></p> * @opt attributes * @opt operations * @opt types * @opt visibility * @version $Id: RPC.java,v 1.1 2008/06/06 13:27:11 hrivnac Exp $ * @author <a href="mailto:Jul...@ce...">J.Hrivnac</a> */ public final class RPC 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 RPCType)) { log.error(element + " can't be traversed using " + getClass().getName() + " representation"); return; } // Create container BranchGroup g = new BranchGroup(); use(g, "RPCs", "RPC Container"); set(builder, g, "RPCs"); // Get Type properties RPCType rpc = (RPCType)element; int count = rpc.getCount(); String storeGateKey = rpc.getStoreGateKey(); float[] xs = floats( rpc.getX( ).getValue()); float[] ys = floats( rpc.getY( ).getValue()); float[] zs = floats( rpc.getZ( ).getValue()); float[] lengths = floats( rpc.getLength( ).getValue()); float[] widths = floats( rpc.getWidth( ).getValue()); int[] ids = ints( rpc.getId( ).getValue()); int[] barcodes = ints( rpc.getBarcode( ).getValue()); String[] identifiers = strings(rpc.getIdentifier().getValue()); // Get Atlantis proxy to RPC AHashMap p = new AHashMap(10); p.put("numData", count); p.put("storeGateKey", storeGateKey); p.put("x", xs); p.put("y", xs); p.put("z", zs); p.put("length", lengths); p.put("width", widths); p.put("id", ids); p.put("barcode", barcodes); p.put("identifier", identifiers); ARPCDataProxy arpc = new ARPCDataProxy(p); // Draw all RPCs 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; boolean barrel; // Set base Tg _baseTg = tg(); // Loop over RPCs for (int i = 0; i < count; i++) { name = "RPC(" + storeGateKey + "/" + 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)); setAppearance(appearance); // Construct RPC shape = asCube(arpc.x()[i], arpc.y()[i], arpc.z()[i], arpc.dx()[i], arpc.dy()[i], arpc.dz()[i]); // Use RPC shape.setAppearance(appearance); use(shape, name, info); } Interacter.setOutlined(outlinedBckp); } /** Draw one RPC hit as a cube {@link Trapezoid}. * @param x The x-coordinate of the hit middle point. * @param y The y-coordinate of the hit middle point. * @param z The z-coordinate of the hit middle point. * @param dx The x-half-length of the hit. * @param dy The y-half-length of the hit. * @param dz The z-half-length of the hit. * @return The {@link Trapezoid} representing the RPC hit. */ // TBD: put into Rep private Shape3D asCube(double x, double y, double z, double dx, double dy, double dz) { Trapezoid cube = new Trapezoid(2 * dx / builder().norm(), 2 * dy / builder().norm(), 2 * dz / builder().norm(), appearance()); Matrix3d m = new Matrix3d(UMATRIX); 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 cube; } /** 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; 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(RPC.class); } --- NEW FILE: ARPCDataProxy.java --- package net.hep.atlas.graphics.JiveEvent.GeometricModel.Reps; import net.hep.atlas.graphics.JiveEvent.GeometricModel.JiveEventBuilder; // Atlantis import atlantis.event.ARPCData; import atlantis.graphics.ACoord; import atlantis.utils.AHashMap; import static atlantis.utils.AMath.PI_BY_8; // Java3D import javax.vecmath.Point2d; // Java import java.util.HashMap; import static java.lang.Math.sin; import static java.lang.Math.cos; /** GraXML proxy to {@link ARPCData}. * <p><font color="#880088"> * <pre> * $Log: ARPCDataProxy.java,v $ * Revision 1.1 2008/06/06 13:26:58 hrivnac * MDT + RPC added * * </pre> * </font></p> * @opt attributes * @opt operations * @opt types * @opt visibility * @version $Id: ARPCDataProxy.java,v 1.1 2008/06/06 13:26:58 hrivnac Exp $ * @author <a href="mailto:Jul...@ce...">J.Hrivnac</a> */ public class ARPCDataProxy extends ARPCData { /** Constructs a new muon box proxy. * @param p TBD */ public ARPCDataProxy(AHashMap p) { super(p); _x = new double[numDraw]; _y = new double[numDraw]; _z = new double[numDraw]; _dx = new double[numDraw]; _dy = new double[numDraw]; _dz = new double[numDraw]; double d; for (int i = 0; i < numDraw; i++) { d = width[i] / 2.0; if (!measuresPhi[i]) { d = length[i] / 2.0; } _x[i ] = rho[i] * cos(phi[ i] ); _y[i ] = rho[i] * sin(phi[ i] ); _dx[i] = d * sin(sector[i] * PI_BY_8); _dy[i] = d * cos(sector[i] * PI_BY_8); _z[i ] = z[i]; _dz[i] = width[i] / 2.0; } } /** TBD */ public double[] x() { return _x; } /** TBD */ public double[] y() { return _y; } /** TBD */ public double[] z() { return _z; } /** TBD */ public double[] dx() { return _dx; } /** TBD */ public double[] dy() { return _dy; } /** TBD */ public double[] dz() { return _dz; } private double[] _x; private double[] _y; private double[] _z; private double[] _dx; private double[] _dy; private double[] _dz; } |