Commit in GeomConverter/test/org/lcsim/detector on MAIN
ShapeRotateTest.java+160added 1.1


GeomConverter/test/org/lcsim/detector
ShapeRotateTest.java added at 1.1
diff -N ShapeRotateTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ShapeRotateTest.java	27 Mar 2007 20:41:27 -0000	1.1
@@ -0,0 +1,160 @@
+package org.lcsim.detector;
+
+import static org.lcsim.units.clhep.SystemOfUnits.m;
+import hep.graphics.heprep.HepRep;
+import hep.graphics.heprep.HepRepFactory;
+import hep.graphics.heprep.HepRepInstanceTree;
+import hep.graphics.heprep.HepRepTreeID;
+import hep.graphics.heprep.HepRepType;
+import hep.graphics.heprep.HepRepTypeTree;
+import hep.graphics.heprep.HepRepWriter;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+
+import java.io.FileOutputStream;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.lcsim.detector.converter.heprep.DetectorElementToHepRepConverter;
+import org.lcsim.detector.material.IMaterial;
+import org.lcsim.detector.material.MaterialElement;
+import org.lcsim.detector.solids.Box;
+
+public class ShapeRotateTest 
+extends TestCase
+{
+    private static IMaterial dummymat = new MaterialElement("dummymat",1,1,1.0);
+    private IPhysicalVolumeNavigator nav;
+    
+    public ShapeRotateTest(String name)
+    {
+        super(name);
+    }
+
+    public static junit.framework.Test suite()
+    {
+        return new TestSuite(ShapeRotateTest.class);
+    }
+    
+    public void testShapeRotate()
+    {
+        System.out.println("testShapeRotate");
+        
+        Hep3Vector point = new BasicHep3Vector(0,0,-10);
+        IPhysicalVolumePath path = nav.getPath(point);
+        
+        System.out.println(point + " " + path.toString());
+        
+        point = new BasicHep3Vector(0,0,10);
+        path = nav.getPath(point);
+        
+        System.out.println(point + " " + path.toString());
+    }
+    
+    public class TestDE
+    extends DetectorElement
+    {
+        TestDE(String name, IDetectorElement parent, String path)
+        {
+            super(name, parent, path);
+        }        
+    }
+    
+    public void setUp()
+    {
+        IPhysicalVolume world = createWorld();
+        nav = new PhysicalVolumeNavigator("default",world);
+        
+        Box box = new Box("testbox",50,50,50);
+        ILogicalVolume lv1 = new LogicalVolume("test",box,dummymat);
+        Rotation3D rot = new Rotation3D();
+        rot.setPassiveXYZ(Math.PI/2, 0, 0);
+        new PhysicalVolume(
+                new Transform3D(rot),
+                "testbox1",
+                lv1,
+                world.getLogicalVolume(),
+                0);
+        
+        IDetectorElement box1 = new TestDE("testbox1",null,"/testbox1");
+        
+        box = new Box("testbox2",10,10,10);
+        LogicalVolume lv2 = new LogicalVolume("test2",box,dummymat);
+        new PhysicalVolume(
+                new Transform3D(new BasicHep3Vector(0,0,10)),
+                "testbox2",
+                lv2,
+                lv1,
+                1);                
+        
+        new TestDE("testbox2",box1,"/testbox1/testbox2");
+        
+        try {
+            writeHepRep("ShapeRotateTest.heprep");
+        }
+        catch ( Throwable x )
+        {
+            throw new RuntimeException(x);
+        }
+    }
+    
+    private void writeHepRep(String filepath) throws Exception
+    {
+        HepRepFactory factory = HepRepFactory.create();
+        HepRep root = factory.createHepRep();        
+        
+        HepRepTreeID treeID = factory.createHepRepTreeID("DetectorType", "1.0");
+        HepRepTypeTree typeTree = factory.createHepRepTypeTree(treeID);
+        root.addTypeTree(typeTree);
+
+        HepRepInstanceTree instanceTree = factory.createHepRepInstanceTree("Detector", "1.0", typeTree);
+        root.addInstanceTree(instanceTree);
+
+        String detectorLayer = "Detector";
+        root.addLayer(detectorLayer);
+
+        HepRepType barrel = factory.createHepRepType(typeTree, "Barrel");
+        barrel.addAttValue("layer", detectorLayer);
+        HepRepType endcap = factory.createHepRepType(typeTree, "Endcap");
+        endcap.addAttValue("layer", detectorLayer);
+                
+        DetectorElementToHepRepConverter cnv = 
+            new DetectorElementToHepRepConverter();
+        
+        for (IDetectorElement de : DetectorElementStore.getInstance())
+        {
+            cnv.convert(de, factory, root);
+        }
+        
+        HepRepWriter writer = 
+            HepRepFactory.create().createHepRepWriter(new FileOutputStream(filepath),false,false);
+        writer.write(root,"test");
+        writer.close();
+    }
+    
+    public final IPhysicalVolume createWorld()
+    {       
+        Box boxWorld = new Box(
+                "world_box",
+                10.0*m,
+                10.0*m,
+                10.0*m);
+        
+        LogicalVolume lvWorld = 
+            new LogicalVolume(
+                    "world",
+                    boxWorld,
+                    dummymat);
+        
+        IPhysicalVolume pvTop = 
+            new PhysicalVolume(
+                    null,
+                    "world",
+                    lvWorld,
+                    null,
+                    0);
+        
+        return pvTop;
+    }      
+}
\ No newline at end of file
CVSspam 0.2.8