33 :
Component(base, map), m_children(), m_cachedBoundingBox(nullptr) {}
45 :
Component(
n, reference), m_children(), m_cachedBoundingBox(nullptr) {
68 (*it)->setParent(
this);
100 throw std::runtime_error(
"CompAssembly::add() called for a parametrized CompAssembly.");
119 throw std::runtime_error(
"CompAssembly::addCopy() called for a parametrized CompAssembly.");
140 throw std::runtime_error(
"CompAssembly::addCopy() called for a parametrized CompAssembly.");
158 throw std::runtime_error(
"CompAssembly::remove() called for a parameterized CompAssembly.");
167 throw std::runtime_error(
"Component " + comp->
getName() +
" is not a child of this assembly.");
180 throw std::logic_error(
"Failed to cast base component to CompAssembly");
182 return compAss->nelements();
202 throw std::logic_error(
"Failed to cast base component to CompAssembly");
208 if (i < 0 || i >
static_cast<int>(
m_children.size() - 1)) {
209 throw std::runtime_error(
"CompAssembly::getChild() range not valid");
230 for (
int i = 0; i < this->
nelements(); i++) {
231 std::shared_ptr<IComponent> comp = this->
getChild(i);
233 outVector.emplace_back(comp);
236 std::shared_ptr<ICompAssembly> assemb = std::dynamic_pointer_cast<ICompAssembly>(comp);
238 assemb->getChildren(outVector, recursive);
263 std::shared_ptr<const ICompAssembly> thisNode = std::shared_ptr<const ICompAssembly>(
this,
NoDeleting());
269 size_t cut = cname.find(
'/');
270 if (cut < cname.length()) {
273 std::shared_ptr<const ICompAssembly> asmb = std::dynamic_pointer_cast<const ICompAssembly>(otherNode);
274 return asmb->getComponentByName(cname.substr(cut + 1, std::string::npos), nlevels);
276 return std::shared_ptr<const IComponent>();
281 if (this->
getName() == cname) {
282 return std::dynamic_pointer_cast<const ICompAssembly>(thisNode);
289 std::deque<std::shared_ptr<const ICompAssembly>> nodeQueue{thisNode};
290 const bool limitSearch(nlevels > 0);
291 while (!nodeQueue.empty()) {
293 std::shared_ptr<const ICompAssembly> node = nodeQueue.front();
294 nodeQueue.pop_front();
299 auto parent = node->getParent();
300 while (parent && (this->
getName() != parent->getName())) {
301 parent = parent->getParent();
306 auto rectDet = std::dynamic_pointer_cast<const RectangularDetector>(node);
307 auto structDet = std::dynamic_pointer_cast<const StructuredDetector>(node);
309 if (
bool(rectDet) && (node != thisNode)) {
313 auto child = rectDet->getComponentByName(cname, nlevels);
316 }
else if (
bool(structDet) && (node != thisNode)) {
317 auto child = rectDet->getComponentByName(cname, nlevels);
318 if (child !=
nullptr)
322 int nchildren = node->nelements();
323 for (
int i = 0; i < nchildren; ++i) {
324 std::shared_ptr<const IComponent> comp = (*node)[i];
325 if (comp->getName() == cname) {
329 if ((!limitSearch) || (depth + 1 < nlevels)) {
332 std::shared_ptr<const ICompAssembly> compAssembly = std::dynamic_pointer_cast<const ICompAssembly>(comp);
333 if (
bool(compAssembly)) {
334 nodeQueue.emplace_back(compAssembly);
343 return std::shared_ptr<const IComponent>();
363 for (
int i = 0; i < nchildren; ++i) {
366 comp->getBoundingBox(compBox);
367 assemblyBox.
grow(compBox);
379 child->getBoundingBox(compBox);
399 for (
int i = 0; i < nchildren; ++i) {
400 std::shared_ptr<Geometry::IComponent> comp = this->
getChild(i);
401 if (std::dynamic_pointer_cast<ICompAssembly>(comp)) {
402 searchQueue.emplace_back(comp);
405 else if (
auto *physicalObject =
dynamic_cast<IObjComponent *
>(comp.get())) {
406 physicalObject->interceptSurface(testRay);
421 std::shared_ptr<IComponent> it = (*this)[i];
422 os <<
"Component " << i <<
" : **********\n";
435 std::shared_ptr<IComponent> it = (*this)[i];
437 os <<
"Element " << i <<
" from " <<
nelements() <<
" in the assembly : ";
440 os <<
"Children :******** \n";
443 os << it->getName() <<
'\n';
500 os <<
"************************\n";
501 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.
Kernel::V3D getPos() const override
Gets the absolute position of the Parametrized CompAssembly This attempts to read the cached position...
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
Kernel::Quat getRotation() const override
Gets the absolute position of the Parametrized CompAssembly This attempts to read the cached position...
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
Kernel::V3D getPos() const override
Get the position of the IComponent. Tree structure is traverse through the.
std::string getName() const override
Get the IComponent name.
const Component * m_base
The base component - this is the unmodified component (without the parameters).
Kernel::Quat getRotation() const override
Get the absolute orientation of the IComponent.
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...
Void deleter for shared pointers.
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.
bool getCachedRotation(const IComponent *comp, Kernel::Quat &rotation) const
Attempts to retrieve a rotation from the rotation cache.
bool getCachedLocation(const IComponent *comp, Kernel::V3D &location) const
Attempts to retrieve a location from the location cache.
void setCachedLocation(const IComponent *comp, const Kernel::V3D &location) const
Sets a cached location on the location cache.
void setCachedRotation(const IComponent *comp, const Kernel::Quat &rotation) const
Sets a cached rotation on the rotation cache.
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.
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.