5 modified files
GeomConverter/src/org/lcsim/detector/solids
diff -u -r1.3 -r1.4
--- Box.java 13 Nov 2007 21:04:50 -0000 1.3
+++ Box.java 14 Nov 2007 19:34:51 -0000 1.4
@@ -13,11 +13,14 @@
*
* @author Tim Nelson <[log in to unmask]>
* @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: Box.java,v 1.3 2007/11/13 21:04:50 tknelson Exp $
+ * @version $Id: Box.java,v 1.4 2007/11/14 19:34:51 tknelson Exp $
*/
public class Box
extends AbstractSolid implements IPolyhedron
{
+
+ private final static int[] _HEPREP_VERTEX_ORDERING = {2,3,1,0,6,7,5,4};
+
double xHalf, yHalf, zHalf;
public Box(String name, double halfX, double halfY, double halfZ)
@@ -42,34 +45,9 @@
{
return zHalf;
}
-
- /*
- public boolean isInside(Hep3Vector point)
- {
- return ( Math.abs(point.x()) < xHalf &&
- Math.abs(point.y()) < yHalf &&
- Math.abs(point.z()) < zHalf );
- }
- */
-
-
-// public Inside inside(Hep3Vector p)
-// {
-// Inside inside_old = inside_old(p);
-// Inside inside_new = inside_new(p);
-//
-// if (inside_new != inside_old)
-// {
-// System.out.println("\n"+"Point at: "+p);
-// System.out.println("Box dimensions: ("+xHalf+", "+yHalf+", "+zHalf+")");
-// System.out.println("inside_old says: "+inside_old);
-// System.out.println("inside_old says: "+inside_new);
-// }
-// return inside_new;
-// }
-
+
public Inside inside(Hep3Vector p)
- {
+ {
Point3D point = new Point3D(p);
boolean inside = true;
@@ -83,39 +61,18 @@
else return Inside.OUTSIDE;
}
-// public Inside inside_old(Hep3Vector p)
-// {
-// Inside in = Inside.OUTSIDE ;
-//
-// if (abs(p.x()) <= xHalf - TOLERANCE*0.5 )
-// {
-// if (abs(p.y()) <= yHalf - TOLERANCE*0.5 )
-// {
-// if (abs(p.z()) <= zHalf - TOLERANCE*0.5 ) in = Inside.INSIDE;
-// else if (abs(p.z()) <= zHalf + TOLERANCE*0.5 ) in = Inside.SURFACE;
-// }
-// else if (abs(p.y()) <= yHalf + TOLERANCE*0.5 )
-// {
-// if (abs(p.z()) <= zHalf + TOLERANCE*0.5 ) in = Inside.SURFACE;
-// }
-// }
-// else if (abs(p.x()) <= xHalf + TOLERANCE*0.5 )
-// {
-// if (abs(p.y()) <= yHalf + TOLERANCE*0.5 )
-// {
-// if (abs(p.z()) <= zHalf + TOLERANCE*0.5) in = Inside.SURFACE;
-// }
-// }
-// return in;
-// }
-
-
public double getCubicVolume()
{
return 8 * (getXHalfLength() * getYHalfLength() * getZHalfLength());
}
// Implementation of IPolyhedron
+
+ public int[] getHepRepVertexOrdering()
+ {
+ return _HEPREP_VERTEX_ORDERING;
+ }
+
public List<Polygon3D> getFaces()
{
List<Polygon3D> faces = new ArrayList<Polygon3D>();
@@ -193,11 +150,11 @@
public List<Point3D> getVertices()
{
List<Point3D> vertices = new ArrayList<Point3D>();
- for (int ix = -1; ix <=+1; ix += 2)
+ for (int iz = -1; iz <=+1; iz += 2)
{
for (int iy = -1; iy <=+1; iy += 2)
{
- for (int iz = -1; iz <=+1; iz += 2)
+ for (int ix = -1; ix <=+1; ix += 2)
{
vertices.add(new Point3D(ix*xHalf,iy*yHalf,iz*zHalf));
}
GeomConverter/src/org/lcsim/detector/solids
diff -u -r1.1 -r1.2
--- IPolyhedron.java 13 Nov 2007 21:04:50 -0000 1.1
+++ IPolyhedron.java 14 Nov 2007 19:34:51 -0000 1.2
@@ -20,4 +20,5 @@
public List<Polygon3D> getFaces();
public List<LineSegment3D> getEdges();
public List<Point3D> getVertices();
+ public int[] getHepRepVertexOrdering();
}
GeomConverter/src/org/lcsim/detector/solids
diff -u -r1.5 -r1.6
--- Trd.java 13 Nov 2007 21:04:50 -0000 1.5
+++ Trd.java 14 Nov 2007 19:34:51 -0000 1.6
@@ -14,11 +14,15 @@
* <a href="http://www.lcsim.org/software/geant4/doxygen/html/classG4Trd.html">G4Trd class</a>.
*
* @author Jeremy McCormick
- * @version $Id: Trd.java,v 1.5 2007/11/13 21:04:50 tknelson Exp $
+ * @author Tim Nelson (modified to use standard geometry objects and operations)
+ * @version $Id: Trd.java,v 1.6 2007/11/14 19:34:51 tknelson Exp $
*/
public class Trd
extends AbstractSolid implements IPolyhedron
{
+
+ private final static int[] _HEPREP_VERTEX_ORDERING = {2,3,1,0,6,7,5,4};
+
double dx1,dx2,dy1,dy2,dz;
double volume;
private static final double tolerance=1E-9;
@@ -66,65 +70,6 @@
else return Inside.OUTSIDE;
}
-
-
-// public Inside inside(Hep3Vector p)
-// {
-// Inside in=OUTSIDE;
-// double x,y,zbase1,zbase2;
-//
-// if (abs(p.z())<=dz-tolerance/2)
-// {
-// zbase1=p.z()+dz; // Dist from -ve z plane
-// zbase2=dz-p.z(); // Dist from +ve z plane
-//
-// // Check whether inside x tolerance
-// //
-// x=0.5*(dx2*zbase1+dx1*zbase2)/dz - tolerance/2;
-// if (abs(p.x())<=x)
-// {
-// y=0.5*((dy2*zbase1+dy1*zbase2))/dz - tolerance/2;
-// if (abs(p.y())<=y)
-// {
-// in=Inside.INSIDE;
-// }
-// else if (abs(p.y())<=y+tolerance)
-// {
-// in=SURFACE;
-// }
-// }
-// else if (abs(p.x())<=x+tolerance)
-// {
-// // y = y half width of shape at z of point + tolerant boundary
-// //
-// y=0.5*((dy2*zbase1+dy1*zbase2))/dz + tolerance/2;
-// if (abs(p.y())<=y)
-// {
-// in=SURFACE;
-// }
-// }
-// }
-// else if (abs(p.z())<=dz+tolerance/2)
-// {
-// // Only need to check outer tolerant boundaries
-// //
-// zbase1=p.z()+dz; // Dist from -ve z plane
-// zbase2=dz-p.z(); // Dist from +ve z plane
-//
-// // x = x half width of shape at z of point plus tolerance
-// //
-// x=0.5*(dx2*zbase1+dx1*zbase2)/dz + tolerance/2;
-// if (abs(p.x())<=x)
-// {
-// // y = y half width of shape at z of point
-// //
-// y=0.5*((dy2*zbase1+dy1*zbase2))/dz + tolerance/2;
-// if (abs(p.y())<=y) in=SURFACE;
-// }
-// }
-// return in;
-// }
-
public double getXHalfLength1()
{
return dx1;
@@ -151,6 +96,11 @@
}
// Implementation of IPolyhedron
+ public int[] getHepRepVertexOrdering()
+ {
+ return _HEPREP_VERTEX_ORDERING;
+ }
+
public List<Polygon3D> getFaces()
{
List<Polygon3D> faces = new ArrayList<Polygon3D>();
@@ -225,25 +175,4 @@
return points;
}
-// /**
-// * Get an array containing the 8 corner points of this trapezoid.
-// */
-// public Hep3Vector[] getPoints()
-// {
-// Hep3Vector points[] = new Hep3Vector[8];
-//
-// points[0] = new BasicHep3Vector(-dx2,-dy1,dz);
-// points[1] = new BasicHep3Vector(-dx2,dy1,dz);
-// points[2] = new BasicHep3Vector(dx2,dy1,dz);
-// points[3] = new BasicHep3Vector(dx2,-dy1,dz);
-//
-// points[4] = new BasicHep3Vector(-dx1,-dy2,-dz);
-// points[5] = new BasicHep3Vector(-dx1,dy2,-dz);
-// points[6] = new BasicHep3Vector(dx1,dy2,-dz);
-// points[7] = new BasicHep3Vector(dx1,-dy2,-dz);
-//
-// return points;
-// }
-
-
}
\ No newline at end of file
GeomConverter/src/org/lcsim/detector/solids
diff -u -r1.6 -r1.7
--- Trap.java 13 Nov 2007 21:04:50 -0000 1.6
+++ Trap.java 14 Nov 2007 19:34:51 -0000 1.7
@@ -23,12 +23,15 @@
*
* @author Jeremy McCormick
* @author Tim Nelson (modified to use standard geometry objects and operations)
- * @version $Id: Trap.java,v 1.6 2007/11/13 21:04:50 tknelson Exp $
+ * @version $Id: Trap.java,v 1.7 2007/11/14 19:34:51 tknelson Exp $
*/
public class Trap
extends AbstractSolid implements IPolyhedron
{
+
+ private final static int[] _HEPREP_VERTEX_ORDERING = {2,3,1,0,6,7,5,4};
+
double dz;
double TthetaCphi;
double TthetaSphi;
@@ -47,20 +50,6 @@
double cubicVolume;
-// TrapSidePlane planes[] = new TrapSidePlane[4];
-
-// Hep3Vector points[];
-
-// public static final double COPLANAR_TOLERANCE = 1E-4;
-
-// public class TrapSidePlane
-// {
-// public double a;
-// public double b;
-// public double c;
-// public double d;
-// }
-
public Trap(
String name,
double dz,
@@ -98,8 +87,6 @@
this.alpha1 = alp1;
this.alpha2 = alp2;
-
-// makePlanes();
}
else
{
@@ -198,6 +185,13 @@
}
// Implementation of IPolyhedron
+
+ public int[] getHepRepVertexOrdering()
+ {
+ return _HEPREP_VERTEX_ORDERING;
+ }
+
+
public List<Polygon3D> getFaces()
{
List<Polygon3D> faces = new ArrayList<Polygon3D>();
@@ -268,172 +262,6 @@
points.add(new Point3D(+dz*TthetaCphi+dy2*Talpha2+dx4,+dz*TthetaSphi+dy2,+dz));
return points;
}
-
-// private boolean makePlanes()
-// {
-// boolean good = true;
-//
-// Hep3Vector pt[] = getPoints();
-//
-// // Bottom side with normal approx. -Y
-// //
-// planes[0]=makePlane(pt[0],pt[4],pt[5],pt[1]) ;
-// if (planes[0]==null)
-// {
-// throw new RuntimeException("Face at ~-Y not planar.");
-// }
-//
-// // Top side with normal approx. +Y
-// //
-// planes[1]=makePlane(pt[2],pt[3],pt[7],pt[6]);
-// if (planes[1]==null)
-// {
-// throw new RuntimeException("Face at ~+Y not planar.");
-// }
-//
-// // Front side with normal approx. -X
-// //
-// planes[2]=makePlane(pt[0],pt[2],pt[6],pt[4]);
-// if (planes[2]==null)
-// {
-// throw new RuntimeException("Face at ~-X not planar.");
-// }
-//
-// // Back side iwth normal approx. +X
-// //
-// planes[3]= makePlane(pt[1],pt[5],pt[7],pt[3]);
-// if (planes[3]==null)
-// {
-// throw new RuntimeException("Face at ~+X not planar");
-// }
-//
-// return good;
-// }
-//
-// private TrapSidePlane makePlane(
-// Hep3Vector p1,
-// Hep3Vector p2,
-// Hep3Vector p3,
-// Hep3Vector p4)
-// {
-// double a, b, c, s;
-// Hep3Vector v12, v13, v14, Vcross;
-// TrapSidePlane plane = new TrapSidePlane();
-//
-// boolean good=false;
-//
-// v12 = sub(p2,p1);
-// v13 = sub(p3,p1);
-// v14 = sub(p4,p1);
-// Vcross = cross(v12,v13);
-//
-// if (abs(dot(Vcross,v14)/(Vcross.magnitude()*v14.magnitude())) > COPLANAR_TOLERANCE)
-// {
-// good = false;
-// }
-// else
-// {
-// // a,b,c correspond to the x/y/z components of the
-// // normal vector to the plane
-//
-// // a = (p2.y()-p1.y())*(p1.z()+p2.z())+(p3.y()-p2.y())*(p2.z()+p3.z());
-// // a += (p4.y()-p3.y())*(p3.z()+p4.z())+(p1.y()-p4.y())*(p4.z()+p1.z()); // ?
-// // b = (p2.z()-p1.z())*(p1.x()+p2.x())+(p3.z()-p2.z())*(p2.x()+p3.x());
-// // b += (p4.z()-p3.z())*(p3.x()+p4.x())+(p1.z()-p4.z())*(p4.x()+p1.x()); // ?
-// // c = (p2.x()-p1.x())*(p1.y()+p2.y())+(p3.x()-p2.x())*(p2.y()+p3.y());
-// // c += (p4.x()-p3.x())*(p3.y()+p4.y())+(p1.x()-p4.x())*(p4.y()+p1.y()); // ?
-//
-// // Let create diagonals 4-2 and 3-1 than (4-2)x(3-1) provides
-// // vector perpendicular to the plane directed to outside !!!
-// // and a,b,c, = f(1,2,3,4) external relative to trap normal
-//
-// a = +(p4.y() - p2.y())*(p3.z() - p1.z())
-// - (p3.y() - p1.y())*(p4.z() - p2.z());
-//
-// b = -(p4.x() - p2.x())*(p3.z() - p1.z())
-// + (p3.x() - p1.x())*(p4.z() - p2.z());
-//
-// c = +(p4.x() - p2.x())*(p3.y() - p1.y())
-// - (p3.x() - p1.x())*(p4.y() - p2.y());
-//
-// s = sqrt( a*a + b*b + c*c ); // so now vector plane.(a,b,c) is unit
-//
-// if( s > 0 )
-// {
-// plane.a = a/s;
-// plane.b = b/s;
-// plane.c = c/s;
-// }
-// else
-// {
-// throw new RuntimeException();
-// //G4cerr << "ERROR - G4Trap()::MakePlane(): " << GetName() << G4endl;
-// //G4Exception("G4Trap::MakePlanes()", "InvalidSetup", FatalException,
-// // "Invalid parameters: norm.mod() <= 0") ;
-// }
-// // Calculate D: p1 in in plane so D=-n.p1.Vect()
-//
-// plane.d = -( plane.a*p1.x() + plane.b*p1.y() + plane.c*p1.z() );
-//
-// good = true;
-// }
-//
-// if (good == false)
-// {
-// plane = null;
-// }
-//
-// return plane;
-// }
-
-// public Inside inside(Hep3Vector p)
-// {
-// Inside in;
-// double Dist;
-// int i;
-// if ( abs(p.z()) <= dz-TOLERANCE*0.5)
-// {
-// in = INSIDE;
-//
-// for ( i = 0;i < 4;i++ )
-// {
-// Dist = planes[i].a*p.x() + planes[i].b*p.y()
-// +planes[i].c*p.z() + planes[i].d;
-//
-// if (Dist > TOLERANCE*0.5) return in = OUTSIDE;
-// else if (Dist > -TOLERANCE*0.5) in = SURFACE;
-//
-// }
-// }
-// else if (abs(p.z()) <= dz+TOLERANCE*0.5)
-// {
-// in = SURFACE;
-//
-// for ( i = 0; i < 4; i++ )
-// {
-// Dist = planes[i].a*p.x() + planes[i].b*p.y()
-// +planes[i].c*p.z() + planes[i].d;
-//
-// if (Dist > TOLERANCE*0.5) return in = OUTSIDE;
-// }
-// }
-// else in = OUTSIDE;
-//
-// return in;
-// }
-
-// public Hep3Vector[] getPoints()
-// {
-// Hep3Vector points[] = new Hep3Vector[8];
-// points[0] = new BasicHep3Vector(-dz*TthetaCphi-dy1*Talpha1-dx1,-dz*TthetaSphi-dy1,-dz);
-// points[1] = new BasicHep3Vector(-dz*TthetaCphi-dy1*Talpha1+dx1,-dz*TthetaSphi-dy1,-dz);
-// points[2] = new BasicHep3Vector(-dz*TthetaCphi+dy1*Talpha1-dx2,-dz*TthetaSphi+dy1,-dz);
-// points[3] = new BasicHep3Vector(-dz*TthetaCphi+dy1*Talpha1+dx2,-dz*TthetaSphi+dy1,-dz);
-// points[4] = new BasicHep3Vector(+dz*TthetaCphi-dy2*Talpha2-dx3,+dz*TthetaSphi-dy2,+dz);
-// points[5] = new BasicHep3Vector(+dz*TthetaCphi-dy2*Talpha2+dx3,+dz*TthetaSphi-dy2,+dz);
-// points[6] = new BasicHep3Vector(+dz*TthetaCphi+dy2*Talpha2-dx4,+dz*TthetaSphi+dy2,+dz);
-// points[7] = new BasicHep3Vector(+dz*TthetaCphi+dy2*Talpha2+dx4,+dz*TthetaSphi+dy2,+dz);
-// return points;
-// }
+
}
\ No newline at end of file
GeomConverter/src/org/lcsim/detector/converter/heprep
diff -u -r1.11 -r1.12
--- DetectorElementToHepRepConverter.java 13 Nov 2007 21:04:53 -0000 1.11
+++ DetectorElementToHepRepConverter.java 14 Nov 2007 19:34:51 -0000 1.12
@@ -19,16 +19,13 @@
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IGeometryInfo;
import org.lcsim.detector.solids.Box;
+import org.lcsim.detector.solids.IPolyhedron;
import org.lcsim.detector.solids.ISolid;
import org.lcsim.detector.solids.Point3D;
-import org.lcsim.detector.solids.Trap;
-import org.lcsim.detector.solids.Trd;
import org.lcsim.detector.solids.Tube;
public class DetectorElementToHepRepConverter
-{
- public final static int TRAP_POINT_ORDER[] = {2,3,1,0,6,7,5,4};
-
+{
public static void convert(IDetectorElement detelem, HepRepFactory factory, HepRep heprep, boolean recurse)
{
HepRepInstanceTree instanceTree = heprep.getInstanceTreeTop("Detector","1.0");
@@ -39,9 +36,9 @@
IGeometryInfo geo = detelem.getGeometry();
ISolid solid = geo.getLogicalVolume().getSolid();
- if ( solid instanceof Box )
+ if ( solid instanceof IPolyhedron )
{
- Box box = (Box)geo.getLogicalVolume().getSolid();
+ IPolyhedron polyhedron = (IPolyhedron)geo.getLogicalVolume().getSolid();
HepRepType ec = typeTree.getType("Barrel");
HepRepType type = factory.createHepRepType(ec, detelem.getName());
@@ -49,44 +46,17 @@
type.addAttValue("drawAs","Prism");
HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
+
+ List<Point3D> points = polyhedron.getVertices();
+ int[] point_ordering = polyhedron.getHepRepVertexOrdering();
- Hep3Vector points[] = new BasicHep3Vector[8];
-
- double x1 = box.getXHalfLength();
- double x2 = -box.getXHalfLength();
-
- double y1 = box.getYHalfLength();
- double y2 = -box.getYHalfLength();
-
- double z1 = box.getZHalfLength();
- double z2 = -box.getZHalfLength();
-
- points[0] = new BasicHep3Vector(x1,y1,z1);
- points[1] = new BasicHep3Vector(x1,y2,z1);
- points[2] = new BasicHep3Vector(x2,y2,z1);
- points[3] = new BasicHep3Vector(x2,y1,z1);
- points[4] = new BasicHep3Vector(x1,y1,z2);
- points[5] = new BasicHep3Vector(x1,y2,z2);
- points[6] = new BasicHep3Vector(x2,y2,z2);
- points[7] = new BasicHep3Vector(x2,y1,z2);
-
- for (int i=0; i<points.length; i++)
+ for (int i=0; i<point_ordering.length; i++)
{
- Hep3Vector vec = geo.transformLocalToGlobal(points[i]);
- points[i] = vec;
- }
-
- for (int i=0; i<points.length; i++)
- {
- Hep3Vector vec = points[i];
- factory.createHepRepPoint(
- instance,
- vec.x(),
- vec.y(),
- vec.z()
- );
+ Hep3Vector p = geo.transformLocalToGlobal(points.get(point_ordering[i]));
+ factory.createHepRepPoint(instance,p.x(),p.y(),p.z());
}
}
+
else if ( solid instanceof Tube )
{
Tube tube = (Tube)geo.getLogicalVolume().getSolid();
@@ -115,56 +85,7 @@
factory.createHepRepPoint(instance2,point1.x(),point1.y(),point1.z());
factory.createHepRepPoint(instance2,point2.x(),point2.y(),point2.z());
}
- else if ( solid instanceof Trd )
- {
- Trd trd = (Trd)geo.getLogicalVolume().getSolid();
-
- HepRepType ec = typeTree.getType("Barrel");
- HepRepType type = factory.createHepRepType(ec, detelem.getName());
- type.addAttValue("drawAs","Prism");
-
- HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
-
- List<Point3D> points = trd.getVertices();
-
- for (int i=0; i<TRAP_POINT_ORDER.length; i++)
- {
- Hep3Vector p = geo.transformLocalToGlobal(points.get(TRAP_POINT_ORDER[i]));
- factory.createHepRepPoint(instance,p.x(),p.y(),p.z());
- }
-
-// Hep3Vector points[] = trd.getVertices();
-//
-// for (int i=0; i<points.length; i++)
-// {
-// Hep3Vector p = geo.transformLocalToGlobal(points[i]);
-// factory.createHepRepPoint(
-// instance,
-// p.x(),
-// p.y(),
-// p.z()
-// );
-// }
-
- }
- else if (solid instanceof Trap)
- {
- Trap trap = (Trap)solid;
-
- HepRepType ec = typeTree.getType("Barrel");
- HepRepType type = factory.createHepRepType(ec, detelem.getName());
- type.addAttValue("drawAs","Prism");
-
- HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
-
- List<Point3D> points = trap.getVertices();
-
- for (int i=0; i<TRAP_POINT_ORDER.length; i++)
- {
- Hep3Vector p = geo.transformLocalToGlobal(points.get(TRAP_POINT_ORDER[i]));
- factory.createHepRepPoint(instance,p.x(),p.y(),p.z());
- }
- }
+
}
if ( detelem.hasChildren() )
{
CVSspam 0.2.8