33 :
Component(base, map), m_children(), m_cachedBoundingBox(nullptr) {}
45 :
Component(
n, reference), m_children(), m_cachedBoundingBox(nullptr) {
78 (*it)->setParent(
this);
110 throw std::runtime_error(
"CompAssembly::add() called for a parametrized CompAssembly.");
129 throw std::runtime_error(
"CompAssembly::addCopy() called for a parametrized CompAssembly.");
150 throw std::runtime_error(
"CompAssembly::addCopy() called for a parametrized CompAssembly.");
168 throw std::runtime_error(
"CompAssembly::remove() called for a parameterized CompAssembly.");
177 throw std::runtime_error(
"Component " + comp->
getName() +
" is not a child of this assembly.");
190 throw std::logic_error(
"Failed to cast base component to CompAssembly");
192 return compAss->nelements();
212 throw std::logic_error(
"Failed to cast base component to CompAssembly");
218 if (i < 0 || i >
static_cast<int>(
m_children.size() - 1)) {
219 throw std::runtime_error(
"CompAssembly::getChild() range not valid");
240 for (
int i = 0; i < this->
nelements(); i++) {
241 std::shared_ptr<IComponent> comp = this->
getChild(i);
243 outVector.emplace_back(comp);
246 std::shared_ptr<ICompAssembly> assemb = std::dynamic_pointer_cast<ICompAssembly>(comp);
248 assemb->getChildren(outVector, recursive);
273 std::shared_ptr<const ICompAssembly> thisNode = std::shared_ptr<const ICompAssembly>(
this,
NoDeleting());
279 size_t cut = cname.find(
'/');
280 if (cut < cname.length()) {
283 std::shared_ptr<const ICompAssembly> asmb = std::dynamic_pointer_cast<const ICompAssembly>(otherNode);
284 return asmb->getComponentByName(cname.substr(cut + 1, std::string::npos), nlevels);
286 return std::shared_ptr<const IComponent>();
291 if (this->
getName() == cname) {
292 return std::dynamic_pointer_cast<const ICompAssembly>(thisNode);
299 std::deque<std::shared_ptr<const ICompAssembly>> nodeQueue{thisNode};
300 const bool limitSearch(nlevels > 0);
301 while (!nodeQueue.empty()) {
303 std::shared_ptr<const ICompAssembly> node = nodeQueue.front();
304 nodeQueue.pop_front();
309 auto parent = node->getParent();
310 while (parent && (this->
getName() != parent->getName())) {
311 parent = parent->getParent();
316 auto rectDet = std::dynamic_pointer_cast<const RectangularDetector>(node);
317 auto structDet = std::dynamic_pointer_cast<const StructuredDetector>(node);
319 if (
bool(rectDet) && (node != thisNode)) {
323 auto child = rectDet->getComponentByName(cname, nlevels);
326 }
else if (
bool(structDet) && (node != thisNode)) {
327 auto child = structDet->getComponentByName(cname, nlevels);
328 if (child !=
nullptr)
332 int nchildren = node->nelements();
333 for (
int i = 0; i < nchildren; ++i) {
334 std::shared_ptr<const IComponent> comp = (*node)[i];
335 if (comp->getName() == cname) {
339 if ((!limitSearch) || (depth + 1 < nlevels)) {
342 std::shared_ptr<const ICompAssembly> compAssembly = std::dynamic_pointer_cast<const ICompAssembly>(comp);
343 if (
bool(compAssembly)) {
344 nodeQueue.emplace_back(compAssembly);
353 return std::shared_ptr<const IComponent>();
373 for (
int i = 0; i < nchildren; ++i) {
376 comp->getBoundingBox(compBox);
377 assemblyBox.
grow(compBox);
389 child->getBoundingBox(compBox);
409 for (
int i = 0; i < nchildren; ++i) {
410 std::shared_ptr<Geometry::IComponent> comp = this->
getChild(i);
411 if (std::dynamic_pointer_cast<ICompAssembly>(comp)) {
412 searchQueue.emplace_back(comp);
415 else if (
auto const *physicalObject =
dynamic_cast<IObjComponent *
>(comp.get())) {
416 physicalObject->interceptSurface(testRay);
431 std::shared_ptr<IComponent> it = (*this)[i];
432 os <<
"Component " << i <<
" : **********\n";
445 std::shared_ptr<IComponent> it = (*this)[i];
447 os <<
"Element " << i <<
" from " <<
nelements() <<
" in the assembly : ";
450 os <<
"Children :******** \n";
453 os << it->getName() <<
'\n';
474 os <<
"************************\n";
475 os <<
"Number of children :" << ass.
nelements() <<
'\n';
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
Class for Assembly of geometric components.
void printChildren(std::ostream &) const override
Print information about all children.
std::shared_ptr< IComponent > operator[](int i) const override
Get a pointer to the ith component in the assembly.
std::vector< IComponent * > m_children
the group of child components
void getChildren(std::vector< IComponent_const_sptr > &outVector, bool recursive) const override
Returns a vector of all children contained.
void printTree(std::ostream &) const override
Print information about all the elements in the tree to a stream Loops through all components in the ...
BoundingBox * m_cachedBoundingBox
A cached bounding box.
void getBoundingBox(BoundingBox &assemblyBox) const override
Get the bounding box for this component and store it in the given argument.
int add(IComponent *) override
Add a component to the assembly.
std::vector< IComponent * >::iterator comp_it
Iterator type.
int addCopy(IComponent *) override
AddCopy method.
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
std::shared_ptr< IComponent > getChild(const int i) const override
Get a pointer to the ith component within the assembly. Easier to use than.
int remove(IComponent *)
Remove a component from the assembly.
void testIntersectionWithChildren(Track &testRay, std::deque< IComponent_const_sptr > &searchQueue) const override
Test the intersection of the ray with the children of the component assembly, for InstrumentRayTracer
CompAssembly()
Empty constructor.
int nelements() const override
Return the number of elements in the assembly.
~CompAssembly() override
Destructor.
CompAssembly & operator=(const CompAssembly &other)
virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override
IComponent * clone() const override
Make a clone of the present component.
BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference=nullptr, const bool excludeMonitors=false) const
Compute the bounding box for the component with componentIndex taking into account all sub components...
ComponentVisitor : Visitor for IComponents.
virtual size_t registerComponentAssembly(const ICompAssembly &assembly)=0
Component is a wrapper for a Component which can modify some of its parameters, e....
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
size_t index() const
Helper for legacy access mode. Returns the index of the component.
void printSelf(std::ostream &) const override
Prints a text representation of itself.
bool hasComponentInfo() const
std::string getName() const override
Get the IComponent name.
const Component * m_base
The base component - this is the unmodified component (without the parameters).
Class for Assembly of geometric components.
virtual int add(IComponent *)=0
Add a component to the assembly.
base class for Geometric IComponent
virtual IComponent * clone() const =0
Return a clone to the current object.
virtual void setParent(IComponent *)=0
Assign a parent IComponent. Previous parent link is lost.
virtual void setName(const std::string &)=0
Set the IComponent name.
virtual std::string getName() const =0
Get the IComponent name.
Object Component class, this class brings together the physical attributes of the component to the po...
static std::shared_ptr< IComponent > create(const std::shared_ptr< const IComponent > &base, const ParameterMap *map)
Create a parameterized component from the given base component and ParameterMap.
Parameter map iterator typedef.
const Geometry::ComponentInfo & componentInfo() const
Only for use by ExperimentInfo. Returns a reference to the ComponentInfo.
Defines a track as a start point and a direction.
This functor is used as the deleter object of a shared_ptr to effectively erase ownership Raw pointer...
std::shared_ptr< IComponent > IComponent_sptr
Typedef of a shared pointer to a IComponent.
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.