Mantid
Loading...
Searching...
No Matches
Track.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidGeometry/DllConfig.h"
17
18#include <boost/container/small_vector.hpp>
19
20#include <iosfwd>
21#include <list>
22
23namespace Mantid {
24//----------------------------------------------------------------------
25// Forward Declaration
26//----------------------------------------------------------------------
27namespace Kernel {
28class Logger;
29}
30
31namespace Geometry {
32
39struct MANTID_GEOMETRY_DLL Link {
49 inline Link(const Kernel::V3D &entry, const Kernel::V3D &exit, const double totalDistance, const IObject &obj,
50 const ComponentID compID = nullptr)
51 : entryPoint(entry), exitPoint(exit), distFromStart(totalDistance),
52 distInsideObject(entryPoint.distance(exitPoint)), object(&obj), componentID(compID) {}
54 inline bool operator<(const Link &other) const { return distFromStart < other.distFromStart; }
56 inline bool operator<(const double &other) const { return distFromStart < other; }
57
58 inline bool operator==(const Link &other) const {
59 if (componentID != other.componentID) {
60 return false;
61 }
62
63 if (object != other.object) {
64 return false;
65 }
66
67 // Need a bit wider tolerance than Kernel::Tolerance for comparing exitPoint
68 // Although this is due to very slight numerical changes for some reason.
69 // The entryPoint seems to be identical among duplicated Links, so the
70 // built-in V3D == operator is used in for that case.
71 const double tolerance = 1.0e-5;
72 bool isExitSame = !(std::abs(exitPoint[0] - other.exitPoint[0]) > tolerance ||
73 std::abs(exitPoint[1] - other.exitPoint[1]) > tolerance ||
74 std::abs(exitPoint[2] - other.exitPoint[2]) > tolerance);
75 return isExitSame && (entryPoint == other.entryPoint);
76 }
77
84 const IObject *object;
87};
88
89// calculations should prefer throwing a std::domain_error rather than using
90// INVALID
91enum class TrackDirection { LEAVING = -1, INVALID = 0, ENTERING = 1 };
92
94 return static_cast<int>(left) < static_cast<int>(right);
95}
96
97MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &os, const TrackDirection &direction);
98
117 inline IntersectionPoint(const TrackDirection direction, const Kernel::V3D &end, const double distFromStartOfTrack,
118 const IObject &obj, const ComponentID compID = nullptr)
119 : direction(direction), endPoint(end), distFromStart(distFromStartOfTrack), object(&obj), componentID(compID) {}
120
131 inline bool operator<(const IntersectionPoint &other) const {
132 const double diff = fabs(distFromStart - other.distFromStart);
133 return (diff > Kernel::Tolerance) ? distFromStart < other.distFromStart : direction < other.direction;
134 }
135
136 inline bool operator==(const IntersectionPoint &other) const {
137 if (direction != other.direction) {
138 return false;
139 }
140
141 const double diff = fabs(distFromStart - other.distFromStart);
142 if (diff > Kernel::Tolerance) {
143 return false;
144 }
145
146 return endPoint == other.endPoint;
147 }
148
157};
158
165class MANTID_GEOMETRY_DLL Track {
166public:
167 using LType = boost::container::small_vector<Link, 5>;
168 using PType = boost::container::small_vector<IntersectionPoint, 5>;
169
170public:
172 Track();
174 Track(const Kernel::V3D &startPt, const Kernel::V3D &unitVector);
175 virtual ~Track() = default;
177 void addPoint(const TrackDirection direction, const Kernel::V3D &endPoint, const IObject &obj,
178 const ComponentID compID = nullptr);
180 int addLink(const Kernel::V3D &firstPoint, const Kernel::V3D &secondPoint, const double distanceAlongTrack,
181 const IObject &obj, const ComponentID compID = nullptr);
183 void removeCojoins();
185 void buildLink();
187 void reset(const Kernel::V3D &startPoint, const Kernel::V3D &direction);
189 void clearIntersectionResults();
191 const Kernel::V3D &startPoint() const { return m_line.getOrigin(); }
193 const Kernel::V3D &direction() const { return m_line.getDirect(); }
195 double totalDistInsideObject() const;
197 LType::iterator begin() { return m_links.begin(); }
199 LType::iterator end() { return m_links.end(); }
201 LType::const_iterator begin() const { return m_links.begin(); }
204 LType::const_iterator end() const { return m_links.end(); }
206 LType::const_iterator cbegin() const { return m_links.cbegin(); }
209 LType::const_iterator cend() const { return m_links.cend(); }
211 LType::reference front() { return m_links.front(); }
213 LType::reference back() { return m_links.back(); }
215 LType::const_reference front() const { return m_links.front(); }
217 LType::const_reference back() const { return m_links.back(); }
219 int count() const { return static_cast<int>(m_links.size()); }
221 int surfPointsCount() const { return static_cast<int>(m_surfPoints.size()); }
223 int nonComplete() const;
225 virtual double calculateAttenuation(double lambda) const;
226
227private:
231};
232
233} // NAMESPACE Geometry
234} // NAMESPACE Mantid
const std::vector< double > * lambda
double left
Definition: LineProfile.cpp:80
double right
Definition: LineProfile.cpp:81
#define fabs(x)
Definition: Matrix.cpp:22
double tolerance
double obj
the value of the quadratic function
base class for Geometric IComponent
Definition: IComponent.h:51
IObject : Interface for geometry objects.
Definition: IObject.h:41
Impliments a line.
Definition: Line.h:43
Defines a track as a start point and a direction.
Definition: Track.h:165
LType::reference front()
Returns a reference to the first link.
Definition: Track.h:211
const Kernel::V3D & startPoint() const
Returns the starting point.
Definition: Track.h:191
LType::iterator end()
Returns an interator to one-past-the-end of the set of links.
Definition: Track.h:199
PType m_surfPoints
Intersection points.
Definition: Track.h:230
LType::const_iterator begin() const
Returns an interator to the start of the set of links (const version)
Definition: Track.h:201
boost::container::small_vector< Link, 5 > LType
Definition: Track.h:167
LType::const_reference back() const
Returns a reference to the last link (const version)
Definition: Track.h:217
int surfPointsCount() const
Returns the number of intersection points.
Definition: Track.h:221
LType::const_reference front() const
Returns a reference to the first link (const version)
Definition: Track.h:215
boost::container::small_vector< IntersectionPoint, 5 > PType
Definition: Track.h:168
LType::reference back()
Returns a reference to the last link.
Definition: Track.h:213
int count() const
Returns the number of links.
Definition: Track.h:219
virtual ~Track()=default
const Kernel::V3D & direction() const
Returns the direction as a unit vector.
Definition: Track.h:193
LType::const_iterator end() const
Returns an interator to one-past-the-end of the set of links (const version)
Definition: Track.h:204
LType::const_iterator cbegin() const
Returns an interator to the start of the set of links (const version)
Definition: Track.h:206
LType m_links
Track units.
Definition: Track.h:229
LType::const_iterator cend() const
Returns an interator to one-past-the-end of the set of links (const version)
Definition: Track.h:209
Line m_line
Line object containing origin and direction.
Definition: Track.h:228
LType::iterator begin()
Returns an interator to the start of the set of links.
Definition: Track.h:197
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312
bool operator<(const TrackDirection left, const TrackDirection right)
Definition: Track.h:93
constexpr double Tolerance
Standard tolerance value.
Definition: Tolerance.h:12
Helper class which provides the Collimation Length for SANS instruments.
Stores a point of intersection along a track.
Definition: Track.h:106
TrackDirection direction
Directional flag.
Definition: Track.h:151
Kernel::V3D endPoint
Point.
Definition: Track.h:152
double distFromStart
Total distance from track begin.
Definition: Track.h:153
ComponentID componentID
Unique component ID.
Definition: Track.h:155
const IObject * object
The object that was intersected.
Definition: Track.h:154
bool operator<(const IntersectionPoint &other) const
A IntersectionPoint is less-than another if either (a) the difference in distances is greater than th...
Definition: Track.h:131
bool operator==(const IntersectionPoint &other) const
Definition: Track.h:136
IntersectionPoint(const TrackDirection direction, const Kernel::V3D &end, const double distFromStartOfTrack, const IObject &obj, const ComponentID compID=nullptr)
Constuctor.
Definition: Track.h:117