38 : m_componentInfo(componentInfo), m_detectorInfo(detectorInfo) {
40 std::string errorMsg =
"Cannot create InstrumentRayTracer, instrument has "
41 "no defined source.\n";
42 throw std::invalid_argument(errorMsg);
97 for (
auto const &result : results) {
98 size_t const index = compInfo.
indexOf(result.componentID);
99 if (compInfo.isDetector(
index) && !detInfo.isMonitor(
index))
127 std::deque<size_t> nodeQueue;
130 nodeQueue.emplace_back(compInfo.root());
132 while (!nodeQueue.empty()) {
133 size_t const node = nodeQueue.front();
134 nodeQueue.pop_front();
140 bbox = compInfo.boundingBox(node);
141 std::lock_guard<std::mutex> lock(
m_mutex);
148 if (compInfo.isGridDetector(node)) {
152 for (
auto const child : compInfo.children(node)) {
153 if (!compInfo.children(child).empty())
154 nodeQueue.emplace_back(child);
155 else if (compInfo.hasValidShape(child))
170 V3D const pos = compInfo.position(
index);
174 V3D const scale = compInfo.scaleFactor(
index);
179 unRotate.
rotate(trkStart);
181 unRotate.
rotate(trkDirection);
183 Track probeTrack(trkStart, trkDirection);
184 shape.interceptSurface(probeTrack);
186 for (
auto const &link : probeTrack) {
187 V3D in = link.entryPoint;
191 V3D out = link.exitPoint;
212 V3D const basePoint = compInfo.position(compInfo.detectorIndexAtXYZ(
index, 0, 0, 0));
215 V3D const vertical = compInfo.position(compInfo.detectorIndexAtXYZ(
index, 0, grid.nY - 1, 0)) - basePoint;
218 V3D const horizontal = compInfo.position(compInfo.detectorIndexAtXYZ(
index, grid.nX - 1, 0, 0)) - basePoint;
236 V3D const intersec = beam * tuv[0];
242 auto const xIndex = int(
double(grid.nX - 1) * tuv[1] + 0.5);
243 auto const yIndex = int(
double(grid.nY - 1) * tuv[2] + 0.5);
246 if (xIndex < 0 || yIndex < 0 || xIndex >= grid.nX || yIndex >= grid.nY)
249 size_t const pixel = compInfo.detectorIndexAtXYZ(
index, xIndex, yIndex, 0);
251 testRay.
addLink(intersec, intersec, 0.0, compInfo.shape(pixel),
252 const_cast<IComponent *
>(compInfo.componentID(pixel)));
std::map< DeltaEMode::Type, std::string > index
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
bool doesLineIntersect(const Track &track) const
Does a specified track intersect the bounding box.
ComponentInfo : Provides a component centric view on to the instrument.
Beamline::PixelGridComponent pixelGridComponent(const size_t componentIndex) const
Kernel::V3D sourcePosition() const
static constexpr size_t invalidIndex
Returned by indexOfOrInvalid() for a component ID that is not part of this instrument.
Kernel::V3D samplePosition() const
const Geometry::IObject & shape(const size_t componentIndex) const
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
size_t indexOf(const detid_t id) const
Returns the index of the detector with the given detector ID.
base class for Geometric IComponent
const ComponentInfo & componentInfo() const
ComponentInfo/DetectorInfo for the traced instrument, against which the index returned by getDetector...
Links getResults() const
Get the results of the intersection tests that have been updated since the previous call to trace.
const DetectorInfo & detectorInfo() const
Track m_resultsTrack
Accumulate results in this Track object, aids performance.
InstrumentRayTracer(ComponentInfo const &componentInfo, DetectorInfo const &detectorInfo)
Constructor taking the ComponentInfo/DetectorInfo of the instrument to trace, which must outlive this...
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
ComponentInfo const & m_componentInfo
ComponentInfo of the instrument being traced.
std::mutex m_mutex
Mutex to lock box cache.
boost::unordered_map< size_t, BoundingBox > m_boxCache
Map of component index -> bounding box.
void testIntersectionWithShape(size_t const index, Track &testRay) const
Intersect the track with the shape of a leaf component.
DetectorInfo const & m_detectorInfo
DetectorInfo of the instrument being traced.
void trace(const Kernel::V3D &dir) const
Trace a given track from the instrument source in the given direction and compile a list of results t...
size_t getDetectorResult() const
Get the index of the first non-monitor detector intersected since the previous call to trace,...
void testIntersectionWithGrid(size_t const index, Track &testRay) const
Intersect the track with the first layer of a Rectangular or Grid bank.
void fireRay(Track &testRay) const
Fire the given track at the instrument.
Defines a track as a start point and a direction.
const Kernel::V3D & startPoint() const
Returns the starting point.
int addLink(const Kernel::V3D &firstPoint, const Kernel::V3D &secondPoint, const double distanceAlongTrack, const IObject &obj, const ComponentID compID=nullptr)
Adds a link to the track.
void clearIntersectionResults()
Clear the current set of intersection results.
const Kernel::V3D & direction() const
Returns the direction as a unit vector.
LType::const_iterator cbegin() const
Returns an interator to the start of the set of links (const version)
LType::const_iterator cend() const
Returns an interator to one-past-the-end of the set of links (const version)
void reset(const Kernel::V3D &startPoint, const Kernel::V3D &direction)
Set a starting point and direction.
T Invert()
LU inversion routine.
void setColumn(const size_t nCol, const std::vector< T > &newCol)
void inverse()
Inverse a quaternion (in the sense of rotation inversion)
void rotate(V3D &) const
Rotate a vector.
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
Track::LType Links
Typedef for object intersections.