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

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

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

Destructor.

00057 { }

BLCMDextrusion::BLCMDextrusion ( const BLCMDextrusion r  ) 

Copy constructor.

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

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


Member Function Documentation

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

clone()

Implements BLElement.

References BLCMDextrusion().

00063 { return new BLCMDextrusion(*this); }

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

commandName() returns "extrusion".

Implements BLCommand.

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

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

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

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

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.

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

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.

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

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

getLength() returns the length of the extrusion

Implements BLElement.

References length.

Referenced by construct().

00086 { return length; }

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

getWidth() returns the width of the extrusion

Implements BLElement.

References width.

00089 { return width; }

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

getHeight() returns the height of the extrusion

Implements BLElement.

References height.

00092 { return height; }

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

isOK() returns true.

Implements BLElement.

00095 { return true; }

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

isOutside() from BLElement.

Implements BLElement.

References BLAssert, and extrusion.

00099                 { BLAssert(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.

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

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

isWithin() from BLGroupElement.

Implements BLGroupElement.

References BLAssert, and extrusion.

00113             { BLAssert(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