#include <BLGroupElement.hh>
Public Member Functions | |
BLGroupElement () | |
Default Constructor. | |
BLGroupElement (const BLGroupElement &r) | |
Copy Constructor for a BLGroupElement. | |
~BLGroupElement () | |
Destructor. | |
void | setName (G4String _name) |
setName() adds this BLGroupElement to mapGroupElement; calls BLElement::setName(). | |
int | getNChildren () |
getNChildren() returns the number of children. | |
virtual void | constructChildren (G4LogicalVolume *parent, G4String parentName, G4RotationMatrix *parentRotation, G4ThreeVector parentPosition) |
constructChildren() will construct the children The enclosing BLGroupElement must already be constructed, so this is normally called at the end of construct(). | |
virtual void | placeChild (BLElement *element, G4RotationMatrix *rot, G4ThreeVector &offset, G4String rename) |
placeChild() will place a child within this GroupElement. The object being placed is rotated wrt the fixed axes of the group's local coordinates. | |
int | testGeometry (int npoints, G4double tolerance, bool visual=false, G4RotationMatrix rotation=G4RotationMatrix(), G4ThreeVector offset=G4ThreeVector()) |
testGeometry() will check that all children are inside this element, and that no children intersect each other. It then calls testGeometry() for any children that are GroupElement-s. npoints is the # of points per child to test. returns the number of errors detected. | |
virtual G4bool | isGroupElement () |
isGroupElement() returns true if this is a BLGroupElement. | |
virtual G4bool | isWithin (G4ThreeVector &local, G4double tolerance)=0 |
isWithin() tests that a point is within this element, or is within tolerance of being inside. local[] is in local coordinates of this element. | |
Static Public Member Functions | |
static BLGroupElement * | find (G4String name) |
find() will find a GroupElement by name | |
Private Member Functions | |
BLGroupElement & | operator= (const BLGroupElement &) |
Private Attributes | |
std::vector< Child > | child |
Static Private Attributes | |
static std::map< G4String, BLGroupElement * > | mapGroupElement |
Friends | |
class | BLGroup |
Classes | |
struct | Child |
BLGroupElement::BLGroupElement | ( | const BLGroupElement & | r | ) | [inline] |
BLGroupElement& BLGroupElement::operator= | ( | const BLGroupElement & | ) | [private] |
void BLGroupElement::setName | ( | G4String | _name | ) | [virtual] |
setName() adds this BLGroupElement to mapGroupElement; calls BLElement::setName().
Reimplemented from BLElement.
References mapGroupElement, and BLElement::setName().
Referenced by BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtorus::command(), BLCMDsphere::command(), BLCMDpolycone::command(), BLGroup::command(), BLCMDgenericbend::command(), BLCMDextrusion::command(), BLCMDbox::command(), BLCMDabsorber::command(), and BLGroup::getWorld().
00027 { 00028 mapGroupElement[_name] = this; 00029 BLElement::setName(_name); 00030 }
int BLGroupElement::getNChildren | ( | ) | [inline] |
getNChildren() returns the number of children.
References child.
Referenced by BLCMDgenericbend::construct(), and BLCMDgenericbend::isOK().
00057 { return child.size(); }
void BLGroupElement::constructChildren | ( | G4LogicalVolume * | parent, | |
G4String | parentName, | |||
G4RotationMatrix * | parentRotation, | |||
G4ThreeVector | parentPosition | |||
) | [virtual] |
constructChildren() will construct the children The enclosing BLGroupElement must already be constructed, so this is normally called at the end of construct().
References child, BLElement::construct(), BLElement::getName(), NO_RENAME(), and BLElement::setName().
Referenced by BLCMDtubs::construct(), BLCMDtrap::construct(), BLCMDtorus::construct(), BLCMDsphere::construct(), BLCMDpolycone::construct(), BLGroup::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDbox::construct(), and BLCMDabsorber::construct().
00041 { 00042 static int level=0; 00043 00044 if(++level > 64) { 00045 G4Exception("BLGroupElement","Nesting > 64",FatalException, ""); 00046 } 00047 00048 int counter = 1; 00049 std::vector<Child>::iterator i; 00050 for(i=child.begin(); i!=child.end(); ++i) { 00051 BLElement *e = i->element; 00052 G4String savename = e->getName(); 00053 G4String pname = parentName; 00054 // handle i->rename 00055 if(i->rename != NO_RENAME) { 00056 if(i->rename.find('+') == 0) { 00057 e->setName(i->rename.substr(1)); 00058 } else { 00059 e->setName(i->rename); 00060 pname = ""; 00061 } 00062 } 00063 // handle '#' in name 00064 G4String::size_type j = e->getName().find('#'); 00065 if(j != e->getName().npos) { 00066 char tmp[32]; 00067 sprintf(tmp,"%d",counter++); 00068 G4String tmpname(e->getName()); 00069 tmpname.replace(j,1,tmp); 00070 e->setName(tmpname); 00071 } 00072 e->construct(&i->rot,i->offset,parent,pname,parentRotation, 00073 parentPosition); 00074 e->setName(savename); 00075 } 00076 00077 --level; 00078 }
void BLGroupElement::placeChild | ( | BLElement * | element, | |
G4RotationMatrix * | rot, | |||
G4ThreeVector & | offset, | |||
G4String | rename | |||
) | [virtual] |
placeChild() will place a child within this GroupElement. The object being placed is rotated wrt the fixed axes of the group's local coordinates.
References child, BLGroupElement::Child::element, BLGroupElement::Child::offset, BLGroupElement::Child::rename, and BLGroupElement::Child::rot.
Referenced by BLCMDplace::command().
00082 { 00083 Child c; 00084 c.element = element; 00085 c.rename = rename; 00086 if(rot) c.rot = *rot; 00087 c.offset = offset; 00088 child.push_back(c); 00089 }
int BLGroupElement::testGeometry | ( | int | npoints, | |
G4double | tolerance, | |||
bool | visual = false , |
|||
G4RotationMatrix | rotation = G4RotationMatrix() , |
|||
G4ThreeVector | offset = G4ThreeVector() | |||
) |
testGeometry() will check that all children are inside this element, and that no children intersect each other. It then calls testGeometry() for any children that are GroupElement-s. npoints is the # of points per child to test. returns the number of errors detected.
References child, BLCommand::commandName(), BLElement::generatePoints(), BLElement::getName(), BLElement::isGroupElement(), BLElement::isOutside(), isWithin(), NO_RENAME(), and testGeometry().
Referenced by BLCMDgeometry::callback(), and testGeometry().
00093 { 00094 // no sense testing an empty group 00095 if(child.size() == 0) return 0; 00096 00097 printf("Testing geometry for children of %s '%s':\n", 00098 commandName().c_str(), getName().c_str()); 00099 00100 int err = 0; 00101 std::vector<G4ThreeVector> points; 00102 G4RotationMatrix inverse=rotation.inverse(); 00103 int icounter = 1; 00104 std::vector<Child>::iterator i; 00105 for(i=child.begin(); i!=child.end(); ++i) { 00106 BLElement *ie = i->element; 00107 G4String iname = ie->getName(); 00108 // handle i->rename 00109 if(i->rename != NO_RENAME) 00110 iname = i->rename; 00111 // handle '#' in iname 00112 G4String::size_type k = iname.find('#'); 00113 if(k != iname.npos) { 00114 char tmp[32]; 00115 sprintf(tmp,"%d",icounter++); 00116 iname.replace(k,1,tmp); 00117 } 00118 ie->generatePoints(npoints,points); 00119 // convert local coords of ie to local coords of this 00120 bool isRotated = !i->rot.isIdentity(); 00121 for(k=0; k<points.size(); ++k) { 00122 if(isRotated) points[k] = i->rot * points[k]; 00123 points[k] += i->offset; 00124 } 00125 G4VVisManager* visMgr = G4VVisManager::GetConcreteInstance(); 00126 if(visual && visMgr) { 00127 for(k=0; k<points.size(); ++k) { 00128 G4ThreeVector pos = points[k]; 00129 pos = inverse * pos + offset; // local->global 00130 G4Circle circle(pos); 00131 circle.SetScreenDiameter(1.0); 00132 circle.SetFillStyle(G4Circle::filled); 00133 G4Colour colour(1.,0.,0.); 00134 G4VisAttributes attribs(colour); 00135 circle.SetVisAttributes(attribs); 00136 visMgr->Draw(circle); 00137 } 00138 } 00139 for(k=0; k<points.size(); ++k) { 00140 if(!isWithin(points[k],tolerance)) { 00141 printf("*** %s '%s' extends outside %s '%s'\n", 00142 ie->commandName().c_str(), 00143 iname.c_str(), 00144 commandName().c_str(), 00145 getName().c_str()); 00146 ++err; 00147 break; 00148 } 00149 } 00150 int jcounter = 1; 00151 std::vector<Child>::iterator j; 00152 for(j=child.begin(); j!=child.end(); ++j) { 00153 if(j == i) continue; 00154 BLElement *je = j->element; 00155 G4String jname = je->getName(); 00156 // handle j->rename 00157 if(j->rename != NO_RENAME) 00158 jname = j->rename; 00159 // handle '#' in jname 00160 G4String::size_type k = jname.find('#'); 00161 if(k != jname.npos) { 00162 char tmp[32]; 00163 sprintf(tmp,"%d",jcounter++); 00164 jname.replace(k,1,tmp); 00165 } 00166 isRotated = !j->rot.isIdentity(); 00167 for(k=0; k<points.size(); ++k) { 00168 G4ThreeVector pt = points[k] - j->offset; 00169 if(isRotated) pt = j->rot.inverse() * pt; 00170 if(!je->isOutside(pt,tolerance)) { 00171 printf("*** %s '%s' intersects %s '%s'\n", 00172 ie->commandName().c_str(), 00173 iname.c_str(), 00174 je->commandName().c_str(), 00175 jname.c_str()); 00176 ++err; 00177 break; 00178 } 00179 } 00180 } 00181 } 00182 for(i=child.begin(); i!=child.end(); ++i) { 00183 BLElement *ie = i->element; 00184 if(!ie->isGroupElement()) continue; 00185 BLGroupElement *ge = (BLGroupElement*)ie; 00186 if(ge) { 00187 G4ThreeVector off = offset + rotation.inverse() * i->offset; 00188 G4RotationMatrix rot = i->rot.inverse() * rotation; 00189 err += ge->testGeometry(npoints,tolerance,visual, 00190 rot,off); 00191 } 00192 } 00193 00194 return err; 00195 }
virtual G4bool BLGroupElement::isGroupElement | ( | ) | [inline, virtual] |
virtual G4bool BLGroupElement::isWithin | ( | G4ThreeVector & | local, | |
G4double | tolerance | |||
) | [pure virtual] |
isWithin() tests that a point is within this element, or is within tolerance of being inside. local[] is in local coordinates of this element.
Implemented in BLGroup, BLCMDabsorber, BLCMDbox, BLCMDextrusion, BLCMDgenericbend, BLCMDpolycone, BLCMDsphere, BLCMDtorus, BLCMDtrap, and BLCMDtubs.
Referenced by testGeometry().
BLGroupElement * BLGroupElement::find | ( | G4String | name | ) | [static] |
find() will find a GroupElement by name
Reimplemented from BLElement.
References mapGroupElement.
Referenced by BLCMDplace::command().
00033 { 00034 return mapGroupElement[_name]; 00035 }
friend class BLGroup [friend] |
std::vector<Child> BLGroupElement::child [private] |
Referenced by constructChildren(), BLGroup::end(), getNChildren(), placeChild(), BLGroup::placeElement(), and testGeometry().
std::map< G4String, BLGroupElement * > BLGroupElement::mapGroupElement [static, private] |