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 simplified 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"
00127                 "Note that while you cannot make an extrusion with a hole, you "
00128                 "can make such an object in two parts.\n\n"
00129                 "Note the position placed is x=0,y=0,z=0, which is centered "
00130                 "along z, but need not be near the center of the polygon in "
00131                 "XY.\n\n"
00132                 "With scale1!=scale2 this is not really an extrusion; by "
00133                 "making one of them 0.001 or so, you can construct a sharp "
00134                 "apex.\n\n"
00135                 "Any x or y value in vertices can be an expression using "
00136                 "double constants and the usual C operators and functions.");
00137 
00138         // provide initial values for fields
00139         length = 0.0;
00140         vertices = "";
00141         scale1 = 1.0;
00142         scale2 = 1.0;
00143         material = "";
00144         color = "1,1,1";
00145         kill = 0;
00146         maxStep = -1;
00147         extrusion = 0;
00148         height = 0.0;
00149         width = 0.0;
00150 }

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.

00153                                                       : BLGroupElement(r),
00154                                                         polygon(r.polygon)
00155 {
00156         length = r.length;
00157         vertices = r.vertices;
00158         scale1 = r.scale1;
00159         scale2 = r.scale2;
00160         material = r.material;
00161         color = r.color;
00162         kill = r.kill;
00163         maxStep = r.maxStep;
00164         extrusion = 0;
00165         height = r.height;
00166         width = r.width;
00167 }


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().

00170 {
00171         if(argv.size() != 1) {
00172                 printError("extrusion: Invalid command, must have name");
00173                 return -1;
00174         }
00175 
00176         if(argv[0] == "default") {
00177                 return defaultExtrusion.handleNamedArgs(namedArgs);
00178         }
00179 
00180         BLCMDextrusion *t = new BLCMDextrusion(defaultExtrusion);
00181         t->setName(argv[0]);
00182         int retval = t->handleNamedArgs(namedArgs);
00183 
00184         if(t->maxStep < 0.0) t->maxStep = Param.getDouble("maxStep");
00185 
00186         t->setup();
00187 
00188         // check material exists
00189         if(t->material.size() > 0) getMaterial(t->material,false);
00190 
00191         t->print(argv[0]);
00192 
00193         return retval;
00194 }

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().

00213 {
00214         width = 0.0;
00215         height = 0.0;
00216 
00217         // get vertices into polygon[]
00218         polygon.clear();
00219         std::vector<G4String> v=splitString(vertices,";",true);
00220         for(unsigned i=0; i<v.size(); ++i) {
00221                 if(v[i].size() == 0) continue;
00222                 std::vector<G4double> p=getList(v[i],",");
00223                 if(p.size() != 2) {
00224                         printError("Syntax error in vertices");
00225                         polygon.clear();
00226                         break;
00227                 }
00228                 G4TwoVector point(p[0],p[1]);
00229                 polygon.push_back(point);
00230                 if(width < fabs(p[0])) width = fabs(p[0]);
00231                 if(height < fabs(p[1])) height = fabs(p[1]);
00232         }
00233         if(polygon.size() > 0 && polygon.size() < 3)
00234                 printError("Fewer than three vertices");
00235 
00236         width *= 2 * (scale1>scale2 ? scale1 : scale2);
00237         height *= 2 * (scale1>scale2 ? scale1 : scale2);
00238         return;
00239 }

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.

00197 {
00198         argDouble(length,"length","Length of the extrusion (mm).",1.0,"",false);
00199         argString(vertices,"vertices","List of vertices of the XY polygon, "
00200                 "clockwise (mm): 'x0,y0;x1,y1;...'; a line from last to first "
00201                 "is added. A 2 mm square is: "
00202                 "'-1,-1;-1,1;1,1;1,-1'",false);
00203         argDouble(scale1,"scale1","The XY scale at the upstream (-z) end (1.0).",1.0,"",false);
00204         argDouble(scale2,"scale2","The XY scale at the downstream (+z) end (1.0).",1.0,"",false);
00205         argDouble(maxStep,"maxStep","The maximum stepsize in the element (mm)",mm);
00206         argString(material,"material","The material of the extrusion");
00207         argString(color,"color","The color of the extrusion (''=invisible)");
00208         argInt(kill,"kill","Set nonzero to kill every track that enters.");
00209         argString(vertices,"vertexes","Synonym for vertices.",false);
00210 }

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.

00247 {
00248         G4String thisname = parentName+getName();
00249 
00250         if(!extrusion) {
00251                 G4TwoVector offset(0.0,0.0);
00252                 extrusion = new G4ExtrudedSolid(thisname+"Extrusion", 
00253                                 polygon,length/2.0,offset,scale1,offset,scale2);
00254         }
00255         G4Material *mat=0;
00256         if(material.size() == 0) 
00257                 mat = parent->GetMaterial();
00258         else
00259                 mat = getMaterial(material);
00260         G4LogicalVolume *lv = new G4LogicalVolume(extrusion,mat, thisname+"LogVol");
00261         lv->SetVisAttributes(getVisAttrib(color));
00262         if(maxStep < 0.0) maxStep = Param.getDouble("maxStep");
00263         lv->SetUserLimits(new G4UserLimits(maxStep));
00264 
00265         // geant4 rotation convention is backwards from g4beamline
00266         G4RotationMatrix *g4rot = 0;
00267         if(relativeRotation)
00268                 g4rot = new G4RotationMatrix(relativeRotation->inverse());
00269 
00270         G4VPhysicalVolume *pv = new G4PVPlacement(g4rot, relativePosition,lv,
00271                                         thisname, parent,false,0);
00272 
00273         if(kill)
00274                 BLManager::getObject()->
00275                         registerSteppingAction(pv,new BLKillTrack(thisname));
00276 
00277         // get globalRotation and globalPosition
00278         G4RotationMatrix *globalRotation = 0;
00279         if(relativeRotation && parentRotation) {
00280                 globalRotation = 
00281                     new G4RotationMatrix(*parentRotation * *relativeRotation);
00282         } else if(relativeRotation) {
00283                 globalRotation = relativeRotation;
00284         } else if(parentRotation) {
00285                 globalRotation = parentRotation;
00286         }
00287         G4ThreeVector globalPosition(relativePosition + parentPosition);
00288         if(parentRotation)
00289                 globalPosition = *parentRotation * relativePosition +
00290                                 parentPosition;
00291 
00292         constructChildren(lv,thisname,globalRotation,globalPosition);
00293 
00294         printf("BLCMDextrusion::Construct %s parent=%s relZ=%.1f globZ=%.1f\n"
00295                         "\tzmin=%.1f zmax=%.1f kill=%d\n",
00296                 thisname.c_str(),parentName.c_str(),relativePosition[2],
00297                 globalPosition[2],
00298                 globalPosition[2]-getLength()/2.0,
00299                 globalPosition[2]+getLength()/2.0,
00300                 kill);
00301 }

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