G4ArrowModel.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  15th July 2012
00031 // Model that knows how to draw an arrow.
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   // Make a cylinder slightly shorter than the arrow length so that it
00065   // doesn't stick out of the head.
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   // Limit the radius
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   // Move it a little so that the tail is at z = -halfShaftLength.
00077   fpShaftPolyhedron->Transform(G4Translate3D(0,0,-halfReduction));
00078 
00079   // Locate the head at +halfShaftLength.
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   // Transform to position
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 }

Generated on Mon May 27 17:47:41 2013 for Geant4 by  doxygen 1.4.7