00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "G4ArrowModel.hh"
00034
00035 #include "G4PhysicalConstants.hh"
00036 #include "G4VGraphicsScene.hh"
00037 #include "G4VisAttributes.hh"
00038 #include "G4Tubs.hh"
00039 #include "G4Polycone.hh"
00040 #include "G4Polyhedron.hh"
00041 #include "G4Vector3D.hh"
00042 #include "G4Point3D.hh"
00043 #include "G4Transform3D.hh"
00044
00045 G4ArrowModel::~G4ArrowModel () {}
00046
00047 G4ArrowModel::G4ArrowModel
00048 (G4double x1, G4double y1, G4double z1,
00049 G4double x2, G4double y2, G4double z2,
00050 G4double width, const G4Colour& colour,
00051 const G4String& description)
00052 {
00053 fType = "G4ArrowModel";
00054 fGlobalTag = fType;
00055 fGlobalDescription = fType + ": " + description;
00056 fExtent = G4VisExtent
00057 (std::min(x1,x2),
00058 std::max(x1,x2),
00059 std::min(y1,y2),
00060 std::max(y1,y2),
00061 std::min(z1,z2),
00062 std::max(z1,z2));
00063
00064
00065
00066 const G4double shaftLength = std::sqrt
00067 (std::pow(x2-x1,2)+std::pow(y2-y1,2)+std::pow(z2-z1,2));
00068 G4double shaftRadius = width/2.;
00069
00070 if (shaftRadius > shaftLength/100.) shaftRadius = shaftLength/100.;
00071 const G4double halfShaftLength = shaftLength/2.;
00072 const G4double halfReduction = 4.*shaftRadius;
00073 const G4double halfLength = halfShaftLength-halfReduction;
00074 G4Tubs shaft("shaft",0.,shaftRadius,halfLength,0.,twopi);
00075 fpShaftPolyhedron = shaft.CreatePolyhedron();
00076
00077 fpShaftPolyhedron->Transform(G4Translate3D(0,0,-halfReduction));
00078
00079
00080 const G4int numRZ = 3;
00081 G4double r[] = {0,4,0};
00082 G4double z[] = {0,-6,-4};
00083 for (G4int i = 0; i < numRZ; i++) {
00084 r[i] *= 2.*shaftRadius;
00085 z[i] = halfShaftLength + z[i] * 2.*shaftRadius;
00086 }
00087 G4Polycone head("head",0,twopi,numRZ,r,z);
00088 fpHeadPolyhedron = head.CreatePolyhedron();
00089
00090
00091 const G4Vector3D arrowDirection = G4Vector3D(x2-x1,y2-y1,z2-z1).unit();
00092 const G4double theta = arrowDirection.theta();
00093 const G4double phi = arrowDirection.phi();
00094 const G4Point3D arrowCentre(0.5*(x1+x2),0.5*(y1+y2),0.5*(z1+z2));
00095 const G4Transform3D tr =
00096 G4Translate3D(arrowCentre) * G4RotateZ3D(phi) * G4RotateY3D(theta);
00097 fpShaftPolyhedron->Transform(tr);
00098 fpHeadPolyhedron->Transform(tr);
00099
00100 G4VisAttributes va;
00101 va.SetColour(colour);
00102 va.SetForceSolid(true);
00103 fpShaftPolyhedron->SetVisAttributes(va);
00104 fpHeadPolyhedron->SetVisAttributes(va);
00105 }
00106
00107 void G4ArrowModel::DescribeYourselfTo (G4VGraphicsScene& sceneHandler)
00108 {
00109 sceneHandler.BeginPrimitives();
00110 sceneHandler.AddPrimitive(*fpShaftPolyhedron);
00111 sceneHandler.AddPrimitive(*fpHeadPolyhedron);
00112 sceneHandler.EndPrimitives();
00113 }