24 : m_boundingBox(), m_id(
"MeshObject"), m_triangles(
std::move(faces)), m_vertices(
std::move(vertices)),
25 m_material(material) {
32 : m_boundingBox(), m_id(
"MeshObject"), m_triangles(
std::move(faces)), m_vertices(
std::move(vertices)),
33 m_material(material) {
42 m_handler = std::make_shared<GeometryHandler>(*
this);
79 std::vector<Kernel::V3D> intersectionPoints;
80 std::vector<TrackDirection> entryExitFlags;
84 if (intersectionPoints.empty()) {
89 const auto it = std::find_if(
90 intersectionPoints.cbegin(), intersectionPoints.cend(),
91 [
this, &point](
const auto &intersectionPoint) { return point.distance(intersectionPoint) < M_TOLERANCE; });
92 if (it != intersectionPoints.cend())
96 double nearestPointDistance = point.
distance(intersectionPoints[0]);
97 size_t nearestPointIndex = 0;
98 for (
size_t i = 1; i < intersectionPoints.size(); ++i) {
99 if (point.
distance(intersectionPoints[i]) < nearestPointDistance) {
100 nearestPointDistance = point.
distance(intersectionPoints[i]);
101 nearestPointIndex = i;
123 for (
const auto &direction : directions) {
124 std::vector<Kernel::V3D> intersectionPoints;
125 std::vector<TrackDirection> entryExitFlags;
129 if (intersectionPoints.empty()) {
133 const auto it = std::find_if(
134 intersectionPoints.cbegin(), intersectionPoints.cend(),
135 [
this, &point](
const auto &intersectionPoint) { return point.distance(intersectionPoint) < M_TOLERANCE; });
136 if (it != intersectionPoints.cend())
148 int originalCount = UT.
count();
154 std::vector<Kernel::V3D> intersectionPoints;
155 std::vector<TrackDirection> entryExit;
158 if (intersectionPoints.empty())
162 for (
size_t i = 0; i < intersectionPoints.size(); ++i) {
163 UT.
addPoint(entryExit[i], intersectionPoints[i], *
this);
167 return UT.
count() - originalCount;
179 for (
size_t i = 0;
getTriangle(i, vertex1, vertex2, vertex3); ++i) {
185 std::ostringstream os;
186 os <<
"Unable to find intersection with object with track starting at " << track.
startPoint() <<
" in direction "
188 throw std::runtime_error(os.str());
199 std::vector<Kernel::V3D> &intersectionPoints,
200 std::vector<TrackDirection> &entryExitFlags)
const {
204 for (
size_t i = 0;
getTriangle(i, vertex1, vertex2, vertex3); ++i) {
207 entryExitFlags.emplace_back(entryExit);
224 if (triangleExists) {
229 return triangleExists;
244 const int flagA =
isValid(testA);
245 const int flagB =
isValid(testB);
246 if (!(flagA ^ flagB))
248 return (flagA) ? -1 : 1;
264 double &zmin)
const {
274 double solidAngleSum(0), solidAngleNegativeSum(0);
276 for (
size_t i = 0; this->
getTriangle(i, vertex1, vertex2, vertex3); ++i) {
281 solidAngleNegativeSum += sa;
291 return 0.5 * (solidAngleSum - solidAngleNegativeSum);
302 std::vector<Kernel::V3D> scaledVertices;
305 [&scaleFactor](
const auto &vertex) { return scaleFactor * vertex; });
321 double cX = 0.5 * (bb.
xMax() + bb.
xMin());
322 double cY = 0.5 * (bb.
yMax() + bb.
yMin());
323 double cZ = 0.5 * (bb.
zMax() + bb.
zMin());
326 double volumeTimesSix(0.0);
329 for (
size_t i = 0;
getTriangle(i, vertex1, vertex2, vertex3); ++i) {
336 return volumeTimesSix / 6.0;
378 const size_t maxAttempts)
const {
381 throw std::runtime_error(
"Object::generatePointInObject() - Invalid "
382 "bounding box. Cannot generate new point.");
399 const size_t maxAttempts)
const {
422 point = tr.
cbegin()->entryPoint;
478 [&rotationMatrix](
auto &vertex) { vertex.rotate(rotationMatrix); });
487 [&translationVector](
const auto &vertex) { return vertex + translationVector; });
496 [&scaleFactor](
const auto &vertex) { return vertex * scaleFactor; });
506 throw "Transformation matrix must be 4 x 4";
512 std::vector<double> vertexin(4);
513 vertexin[0] = vertex.X();
514 vertexin[1] = vertex.Y();
515 vertexin[2] = vertex.Z();
517 std::vector<double> vertexout(4);
519 Kernel::V3D newvertex(vertexout[0], vertexout[1], vertexout[2]);
559 throw std::runtime_error(
"MeshObject::shapeInfo() is not implemented");
std::map< DeltaEMode::Type, std::string > index
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
bool isPointInside(const Kernel::V3D &point) const
Is the given point within the bounding box?
double xMax() const
Return the maximum value of X.
bool isNonNull() const
Is the box considered valid. Convenience for !isNull()
double zMin() const
Return the minimum value of Z.
double zMax() const
Return the maximum value of Z.
double yMax() const
Return the maximum value of Y.
double xMin() const
Return the minimum value of X.
bool doesLineIntersect(const Track &track) const
Does a specified track intersect the bounding box.
Kernel::V3D centrePoint() const
Returns the centre of the bounding box.
double yMin() const
Return the minimum value of Y.
Kernel::Material m_material
material composition
boost::optional< Kernel::V3D > generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng, const size_t) const override
Select a random point within the object.
void translate(const Kernel::V3D &)
Translate the mesh according to the supplied x, y, z vector.
double solidAngle(const Kernel::V3D &observer) const override
Find solid angle of object wrt the observer.
int getPointInObject(Kernel::V3D &point) const override
Try to find a point that lies within (or on) the object.
size_t numberOfTriangles() const
Output functions for rendering, may also be used internally.
int interceptSurface(Geometry::Track &) const override
Given a track, fill the track with valid section.
const detail::ShapeInfo & shapeInfo() const override
std::vector< double > getVertices() const
get vertices
detail::ShapeInfo::GeometryShape shape() const override
std::vector< Kernel::V3D > m_vertices
bool hasValidShape() const override
Return whether this object has a valid shape.
bool isValid(const Kernel::V3D &) const override
Check if a point is inside.
void setMaterial(const Kernel::Material &material) override
void draw() const override
Draws the Object using geometry handler, If the handler is not set then this function does nothing.
MeshObject(std::vector< uint32_t > faces, std::vector< Kernel::V3D > vertices, const Kernel::Material &material)
Constructor.
const BoundingBox & getBoundingBox() const override
Return cached value of axis-aligned bounding box.
void getIntersections(const Kernel::V3D &start, const Kernel::V3D &direction, std::vector< Kernel::V3D > &intersectionPoints, std::vector< Mantid::Geometry::TrackDirection > &entryExitFlags) const
Get intersections.
std::vector< uint32_t > getTriangles() const
get faces
const std::vector< Kernel::V3D > & getV3Ds() const
get vertices in V3D form
double volume() const override
Calculates the volume of this object.
std::vector< uint32_t > m_triangles
Contents Triangles are specified by indices into a list of vertices.
void scale(const double scaleFactor)
Scale the mesh according to the supplied scale factor.
bool searchForObject(Kernel::V3D &point) const
Search object for valid point.
void initDraw() const override
Initializes/prepares the object to be rendered, this will generate geometry for object,...
size_t numberOfVertices() const
Read access to mesh object for rendering.
void updateGeometryHandler()
Updates the geometry handler if needed.
const Kernel::Material & material() const override
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
std::shared_ptr< GeometryHandler > getGeometryHandler() const override
Returns the geometry handler.
void multiply(const Kernel::Matrix< double > &)
Transform the mesh (scale, translate, rotate) according to the supplied transformation matrix.
bool getTriangle(const size_t index, Kernel::V3D &v1, Kernel::V3D &v2, Kernel::V3D &v3) const
Get triangle.
void rotate(const Kernel::Matrix< double > &)
Rotate the mesh according to the supplied rotation matrix.
int calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const
Calculate if a point PT is a valid point on the track.
BoundingBox m_boundingBox
Cache for object's bounding box.
bool isOnSide(const Kernel::V3D &) const override
Determines wither point is on the surface.
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector< Kernel::V3D > &vectors, double &innerRadius, double &radius, double &height) const override
get info on standard shapes (none for Mesh Object)
void setGeometryHandler(const std::shared_ptr< GeometryHandler > &h)
Set Geometry Handler.
double distance(const Track &track) const override
Compute the distance to the first point of intersection with the surface.
Defines a track as a start point and a direction.
const Kernel::V3D & startPoint() const
Returns the starting point.
void addPoint(const TrackDirection direction, const Kernel::V3D &endPoint, const IObject &obj, const ComponentID compID=nullptr)
Adds a point of intersection to the track.
void buildLink()
Construct links between added points.
int count() const
Returns the number of links.
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)
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
void multiplyPoint(const std::vector< T > &in, std::vector< T > &out) const
Multiply M*Vec.
size_t numRows() const
Return the number of rows in the matrix.
size_t numCols() const
Return the number of columns in the matrix.
Defines a 1D pseudo-random number generator, i.e.
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
MANTID_GEOMETRY_DLL bool rayIntersectsTriangle(const Kernel::V3D &start, const Kernel::V3D &direction, const Kernel::V3D &v1, const Kernel::V3D &v2, const Kernel::V3D &v3, Kernel::V3D &intersection, TrackDirection &entryExit)
Get intersection points and their in out directions on the given ray.
MANTID_GEOMETRY_DLL void checkVertexLimit(size_t nVertices)
MANTID_GEOMETRY_DLL std::vector< double > getVertices(const std::vector< Kernel::V3D > &vertices)
getVertices converts vector Kernel::V3D to vector doubles.
MANTID_GEOMETRY_DLL double getTriangleSolidAngle(const Kernel::V3D &a, const Kernel::V3D &b, const Kernel::V3D &c, const Kernel::V3D &observer)
Find the solid angle of a triangle defined by vectors a,b,c from point "observer".
MANTID_GEOMETRY_DLL const BoundingBox & getBoundingBox(const std::vector< Kernel::V3D > &vertices, BoundingBox &cacheBB)
Takes input vertices and calculates bounding box.
boost::optional< Kernel::V3D > bounded(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng, const BoundingBox &box, size_t maxAttempts)
Return a random point in a known shape restricted by a bounding box.
bool MANTID_GEOMETRY_DLL intersection(const ConvexPolygon &P, const ConvexPolygon &Q, ConvexPolygon &out)
Compute the instersection of two convex polygons.
constexpr double Tolerance
Standard tolerance value.