BLCMDextrusion Class Reference

Inheritance diagram for BLCMDextrusion:

BLGroupElement BLElement BLCommand

List of all members.


Detailed Description

BLCMDextrusion implements an extrusion of material, axis along Z.

Public Member Functions

 BLCMDextrusion ()
 Default constructor. Defines the command, args, etc.
virtual ~BLCMDextrusion ()
 Destructor.
 BLCMDextrusion (const BLCMDextrusion &r)
 Copy constructor.
BLElementclone ()
 clone()
G4String commandName ()
 commandName() returns "extrusion".
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the extrusion command.
void setup ()
 setup() will handle the vertices, and determine height and width.
void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for the command.
virtual void construct (G4RotationMatrix *relativeRotation, G4ThreeVector relativePosition, G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition)
 construct() - construct the extrusion
G4double getLength ()
 getLength() returns the length of the extrusion
G4double getWidth ()
 getWidth() returns the width of the extrusion
G4double getHeight ()
 getHeight() returns the height of the extrusion
G4bool isOK ()
 isOK() returns true.
bool isOutside (G4ThreeVector &local, G4double tolerance)
 isOutside() from BLElement.
void generatePoints (int npoints, std::vector< G4ThreeVector > &v)
 generatePoints() from BLElement.
bool isWithin (G4ThreeVector &local, G4double tolerance)
 isWithin() from BLGroupElement.

Private Attributes

G4double length
G4String vertices
G4double scale1
G4double scale2
G4String material
G4String color
G4int kill
G4double maxStep
G4ExtrudedSolid * extrusion
std::vector< G4TwoVector > polygon
G4double height
G4double width

Constructor & Destructor Documentation

BLCMDextrusion::BLCMDextrusion (  ) 

Default constructor. Defines the command, args, etc.

References BLCMDTYPE_ELEMENT, color, extrusion, height, kill, length, material, maxStep, BLCommand::registerCommand(), scale1, scale2, BLCommand::setDescription(), BLCommand::setSynopsis(), vertices, and width.

Referenced by clone(), and command().

00118                                : BLGroupElement(), polygon()
00119 {
00120         // register the commandName(), and its synopsis and description.
00121         registerCommand(BLCMDTYPE_ELEMENT);
00122         setSynopsis("construct a solid extrusion with axis along z");
00123         setDescription("This is a basic interface to G4ExtrudedSolid.\n"
00124                 "A simple polygon in the X-Y plane is extruded along z, "
00125                 "with optional scales in XY at the two ends (which generate "
00126                 "a linear scaling along z).\n\n"
00127                 "The polygon must be simple (no two sides intersect, no two "
00128                 "vertices are equal). The vertices are listed starting from "
00129                 "any vertex and traversing the polygon in either direction "
00130                 "without lifting the pencil from the paper (Geant4 requires "
00131                 "the traversal to be clockwise but this element internally "
00132                 "reverses it if required). For an N-sided polygon give N "
00133                 "vertices -- a side will be added from last to "
00134                 "first to close the polygon; N is determined by "
00135                 "counting the entries in the vertices argument.\n\n"
00136                 "Note that while you cannot make an extrusion with a hole, you "
00137                 "can make such an object in two parts or by placing a "
00138                 "daughter volume in this one.\n\n"
00139                 "Note the position placed is x=0,y=0,z=0, which is centered "
00140                 "along z, but need not be near the center of the polygon in "
00141                 "XY.\n\n"
00142                 "With scale1!=scale2 this is not really an extrusion; by "
00143                 "making one of them 0.001 or so, you can construct a sharp "
00144                 "apex.\n\n"
00145                 "Any x or y value in vertices can be an expression using "
00146                 "double constants and the usual C operators and functions.");
00147 
00148         // provide initial values for fields
00149         length = 0.0;
00150         vertices = "";
00151         scale1 = 1.0;
00152         scale2 = 1.0;
00153         material = "";
00154         color = "1,1,1";
00155         kill = 0;
00156         maxStep = -1;
00157         extrusion = 0;
00158         height = 0.0;
00159         width = 0.0;
00160 }

virtual BLCMDextrusion::~BLCMDextrusion (  )  [inline, virtual]

Destructor.

00056 { }

BLCMDextrusion::BLCMDextrusion ( const BLCMDextrusion r  ) 

Copy constructor.

References color, extrusion, height, kill, length, material, maxStep, scale1, scale2, vertices, and width.

00163                                                       : BLGroupElement(r),
00164                                                         polygon(r.polygon)
00165 {
00166         length = r.length;
00167         vertices = r.vertices;
00168         scale1 = r.scale1;
00169         scale2 = r.scale2;
00170         material = r.material;
00171         color = r.color;
00172         kill = r.kill;
00173         maxStep = r.maxStep;
00174         extrusion = 0;
00175         height = r.height;
00176         width = r.width;
00177 }


Member Function Documentation

BLElement* BLCMDextrusion::clone (  )  [inline, virtual]

clone()

Implements BLElement.

References BLCMDextrusion().

00062 { return new BLCMDextrusion(*this); }

G4String BLCMDextrusion::commandName (  )  [inline, virtual]

commandName() returns "extrusion".

Implements BLCommand.

00065 { return "extrusion"; }

int BLCMDextrusion::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the extrusion command.

Implements BLCommand.

References BLCMDextrusion(), BLParam::getDouble(), BLCommand::getMaterial(), BLCommand::handleNamedArgs(), material, maxStep, Param, BLCommand::print(), BLCommand::printError(), BLGroupElement::setName(), and setup().

00180 {
00181         if(argv.size() != 1) {
00182                 printError("extrusion: Invalid command, must have name");
00183                 return -1;
00184         }
00185 
00186         if(argv[0] == "default") {
00187                 return defaultExtrusion.handleNamedArgs(namedArgs);
00188         }
00189 
00190         BLCMDextrusion *t = new BLCMDextrusion(defaultExtrusion);
00191         t->setName(argv[0]);
00192         int retval = t->handleNamedArgs(namedArgs);
00193 
00194         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00195 
00196         t->setup();
00197 
00198         // check material exists
00199         if(t->material.size() > 0) getMaterial(t->material,false);
00200 
00201         t->print(argv[0]);
00202 
00203         return retval;
00204 }

void BLCMDextrusion::setup (  ) 

setup() will handle the vertices, and determine height and width.

References BLCommand::getList(), height, polygon, BLCommand::printError(), scale1, scale2, BLCommand::splitString(), vertices, and width.

Referenced by command().

00223 {
00224         width = 0.0;
00225         height = 0.0;
00226 
00227         // get vertices into polygon[]
00228         polygon.clear();
00229         std::vector<G4String> v=splitString(vertices,";",true);
00230         for(unsigned i=0; i<v.size(); ++i) {
00231                 if(v[i].size() == 0) continue;
00232                 std::vector<G4double> p=getList(v[i],",");
00233                 if(p.size() != 2) {
00234                         printError("Syntax error in vertices");
00235                         polygon.clear();
00236                         break;
00237                 }
00238                 G4TwoVector point(p[0],p[1]);
00239                 polygon.push_back(point);
00240                 if(width < fabs(p[0])) width = fabs(p[0]);
00241                 if(height < fabs(p[1])) height = fabs(p[1]);
00242         }
00243         if(polygon.size() < 3) {
00244                 printError("extrusion: polygon has Fewer than three vertices");
00245                 return;
00246         }
00247 
00248         // Compute the signed area to determine if it is traversed clockwise or 
00249         // ccw; invert the order if ccw because G4ExtrudedSolid requires cw.
00250         // (This is known as the "surveyor's formula".)
00251         double area=0.0;
00252         polygon.push_back(polygon[0]); // extra point for simplicity
00253         for(unsigned i=0; i<polygon.size()-1; ++i) {
00254                 area += polygon[i].x()*polygon[i+1].y() -
00255                         polygon[i+1].x()*polygon[i].y(); // omit the 1/2
00256         }
00257         polygon.pop_back(); // remove extra point
00258         if(area > 0.0) {        // invert the order of the vertices
00259                 std::vector<G4TwoVector> tmp;
00260                 for(unsigned i=0; i<polygon.size(); ++i)
00261                         tmp.push_back(polygon[polygon.size()-1-i]);
00262                 for(unsigned i=0; i<polygon.size(); ++i)
00263                         polygon[i] = tmp[i];
00264         }
00265 
00266         width *= 2 * (scale1>scale2 ? scale1 : scale2);
00267         height *= 2 * (scale1>scale2 ? scale1 : scale2);
00268         return;
00269 }

void BLCMDextrusion::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for the command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), color, kill, length, material, maxStep, scale1, scale2, and vertices.

00207 {
00208         argDouble(length,"length","Length of the extrusion (mm).",1.0,"",false);
00209         argString(vertices,"vertices","List of vertices of the XY polygon "
00210                 "(mm): 'x0,y0;x1,y1;...'; a line from last to first "
00211                 "is added. A 2 mm square is: "
00212                 "'-1,-1;-1,1;1,1;1,-1'",false);
00213         argDouble(scale1,"scale1","The XY scale at the upstream (-z) end (1.0).",1.0,"",false);
00214         argDouble(scale2,"scale2","The XY scale at the downstream (+z) end (1.0).",1.0,"",false);
00215         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)",mm);
00216         argString(material,"material","The material of the extrusion");
00217         argString(color,"color","The color of the extrusion (''=invisible)");
00218         argInt(kill,"kill","Set nonzero to kill every track that enters.");
00219         argString(vertices,"vertexes","Synonym for vertices.",false);
00220 }

void BLCMDextrusion::construct ( G4RotationMatrix *  relativeRotation,
G4ThreeVector  relativePosition,
G4LogicalVolume *  parent,
G4String  parentName,
G4RotationMatrix *  parentRotation,
G4ThreeVector  parentPosition 
) [virtual]

construct() - construct the extrusion

Implements BLElement.

References color, BLGroupElement::constructChildren(), extrusion, BLParam::getDouble(), getLength(), BLCommand::getMaterial(), BLElement::getName(), BLManager::getObject(), BLCommand::getVisAttrib(), kill, length, material, maxStep, Param, polygon, scale1, and scale2.

00277 {
00278         G4String thisname = parentName+getName();
00279 
00280         if(!extrusion) {
00281                 G4TwoVector offset(0.0,0.0);
00282                 extrusion = new G4ExtrudedSolid(thisname+"Extrusion", 
00283                                 polygon,length/2.0,offset,scale1,offset,scale2);
00284         }
00285         G4Material *mat=0;
00286         if(material.size() == 0) 
00287                 mat = parent->GetMaterial();
00288         else
00289                 mat = getMaterial(material);
00290         G4LogicalVolume *lv = new G4LogicalVolume(extrusion,mat, thisname+"LogVol");
00291         lv->SetVisAttributes(getVisAttrib(color));
00292         if(maxStep < 0.0) maxStep = Param.getDouble("maxStep");
00293         lv->SetUserLimits(new G4UserLimits(maxStep));
00294 
00295         // geant4 rotation convention is backwards from g4beamline
00296         G4RotationMatrix *g4rot = 0;
00297         if(relativeRotation)
00298                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00299 
00300         G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition,lv,
00301                                         thisname, parent,false,0);
00302 
00303         if(kill)
00304                 BLManager::getObject()->
00305                         registerSteppingAction(pv,new BLKillTrack(thisname));
00306 
00307         // get globalRotation and globalPosition
00308         G4RotationMatrix *globalRotation = 0;
00309         if(relativeRotation && parentRotation) {
00310                 globalRotation = 
00311                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00312         } else if(relativeRotation) {
00313                 globalRotation = relativeRotation;
00314         } else if(parentRotation) {
00315                 globalRotation = parentRotation;
00316         }
00317         G4ThreeVector globalPosition(relativePosition + parentPosition);
00318         if(parentRotation)
00319                 globalPosition = *parentRotation * relativePosition +
00320                                 parentPosition;
00321 
00322         constructChildren(lv,thisname,globalRotation,globalPosition);
00323 
00324         printf("BLCMDextrusion::Construct %s parent=%s relZ=%.1f globZ=%.1f\n"
00325                         "\tzmin=%.1f zmax=%.1f kill=%d\n",
00326                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00327                 globalPosition[2],
00328                 globalPosition[2]-getLength()/2.0,
00329                 globalPosition[2]+getLength()/2.0,
00330                 kill);
00331 }

G4double BLCMDextrusion::getLength (  )  [inline, virtual]

getLength() returns the length of the extrusion

Implements BLElement.

References length.

Referenced by construct().

00085 { return length; }

G4double BLCMDextrusion::getWidth (  )  [inline, virtual]

getWidth() returns the width of the extrusion

Implements BLElement.

References width.

00088 { return width; }

G4double BLCMDextrusion::getHeight (  )  [inline, virtual]

getHeight() returns the height of the extrusion

Implements BLElement.

References height.

00091 { return height; }

G4bool BLCMDextrusion::isOK (  )  [inline, virtual]

isOK() returns true.

Implements BLElement.

00094 { return true; }

bool BLCMDextrusion::isOutside ( G4ThreeVector &  local,
G4double  tolerance 
) [inline, virtual]

isOutside() from BLElement.

Implements BLElement.

References extrusion.

00098                 { assert(extrusion!=0);  return extrusion->Inside(local) != kInside; }

void BLCMDextrusion::generatePoints ( int  npoints,
std::vector< G4ThreeVector > &  v 
) [inline, virtual]

generatePoints() from BLElement.

Implements BLElement.

References extrusion.

00102                 { v.clear();
00103                   for(int n=0; n<npoints*5; ++n) {
00104                         G4ThreeVector p=extrusion->GetPointOnSurface();
00105                         if(extrusion->Inside(p) == kSurface)
00106                                 v.push_back(p);
00107                   }
00108                 }

bool BLCMDextrusion::isWithin ( G4ThreeVector &  local,
G4double  tolerance 
) [inline, virtual]

isWithin() from BLGroupElement.

Implements BLGroupElement.

References extrusion.

00112             { assert(extrusion!=0);  return extrusion->Inside(local) != kOutside; }


Member Data Documentation

G4double BLCMDextrusion::length [private]

G4String BLCMDextrusion::vertices [private]

G4double BLCMDextrusion::scale1 [private]

G4double BLCMDextrusion::scale2 [private]

G4String BLCMDextrusion::material [private]

G4String BLCMDextrusion::color [private]

G4int BLCMDextrusion::kill [private]

G4double BLCMDextrusion::maxStep [private]

G4ExtrudedSolid* BLCMDextrusion::extrusion [private]

std::vector<G4TwoVector> BLCMDextrusion::polygon [private]

Referenced by construct(), and setup().

G4double BLCMDextrusion::height [private]

Referenced by BLCMDextrusion(), getHeight(), and setup().

G4double BLCMDextrusion::width [private]

Referenced by BLCMDextrusion(), getWidth(), and setup().


The documentation for this class was generated from the following file:
g4beamline