23namespace CoplanarChecks {
25 return vertices.size() >= 3;
35 auto v0 = vertices[1] - vertices[0];
37 const static double tolerance_sq = std::pow(1e-9, 2);
39 for (
size_t i = 1; i < vertices.size() - 1; ++i) {
40 auto v1 = vertices[i + 1] - vertices[i];
41 normal = v0.cross_prod(v1);
42 if (normal.norm2() > tolerance_sq) {
57 auto v0 = vertices[0];
58 const auto nx = normal[0];
59 const auto ny = normal[1];
60 const auto nz = normal[2];
61 const auto k = nx * v0.
X() + ny * v0.Y() + nz * v0.Z();
62 const auto denom = normal.
norm();
67 for (
const auto &vertex : vertices) {
68 auto d = (nx * vertex.X() + ny * vertex.Y() + nz * vertex.Z() - k) / denom;
85 throw std::invalid_argument(
"Insufficient vertices to create a plane");
89 if (normal.norm2() == 0) {
91 throw std::invalid_argument(
"All vertices are colinear. This does not define a plane");
95 throw std::invalid_argument(
"Vertices do not define a plane");
110bool getTriangle(
const size_t index,
const std::vector<uint32_t> &triangles,
const std::vector<Kernel::V3D> &vertices,
112 bool triangleExists =
index < triangles.size() / 3;
113 if (triangleExists) {
114 vertex1 = vertices[triangles[3 *
index]];
115 vertex2 = vertices[triangles[3 *
index + 1]];
116 vertex3 = vertices[triangles[3 *
index + 2]];
118 return triangleExists;
136 if (normal.
norm2() == 0) {
149 : m_triangles(
std::move(faces)), m_vertices(
std::move(vertices)), m_material(material) {
158 : m_triangles(
std::move(faces)), m_vertices(
std::move(vertices)), m_material(material) {
168 const auto n_mag = surfaceNormal.
norm();
170 parameters.
a = surfaceNormal.
X() / n_mag;
171 parameters.
b = surfaceNormal.
Y() / n_mag;
172 parameters.
c = surfaceNormal.
Z() / n_mag;
173 parameters.
k = parameters.
a * v0.X() + parameters.
b * v0.Y() + parameters.
c * v0.Z();
174 parameters.
normal = surfaceNormal;
180 m_handler = std::make_shared<GeometryHandler>(*
this);
203 for (
size_t i = 0; i <
m_triangles.size(); i += 3) {
226 const int originalCount = ut.
count();
237 for (
size_t i = 0; i <
m_vertices.size(); i += 3) {
248 return ut.
count() - originalCount;
267 for (
size_t i = 0; i <
m_vertices.size(); i += 3) {
275 std::ostringstream os;
276 os <<
"Unable to find intersection with object with track starting at " << ut.
startPoint() <<
" in direction "
278 throw std::runtime_error(os.str());
308 double solidAngleSum(0);
316 return solidAngleSum;
320 std::vector<Kernel::V3D> scaledVertices;
323 [&scaleFactor](
const auto &vertex) { return vertex * scaleFactor; });
329 return m_vertices.size() == other.m_vertices.size() &&
m_triangles.size() == other.m_triangles.size() &&
351 double &zmin)
const {
363 const size_t )
const {
367 throw std::runtime_error(
"Not implemented.");
372 const size_t )
const {
377 throw std::runtime_error(
"Not implemented");
405 throw std::runtime_error(
"MeshObject2D::shapeInfo() is not implemented");
410 throw std::runtime_error(
"MeshObject2D::GetObjectGeom 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 operator==(const MeshObject2D &other) const
bool isOnSide(const Kernel::V3D &) const override
Determine if point is on the side of the object.
int getPointInObject(Kernel::V3D &point) const override
Try to find a point that lies within (or on) the object.
detail::ShapeInfo::GeometryShape shape() const override
double solidAngle(const Kernel::V3D &observer) const override
Solid angle only considers triangle facing sample.
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
std::vector< double > getVertices() const
const std::string & id() const override
static const double MinThickness
static const std::string Id
Id as static.
size_t numberOfVertices() const
const detail::ShapeInfo & shapeInfo() const override
MeshObject2D * cloneWithMaterial(const Kernel::Material &material) const override
bool isValid(const Kernel::V3D &point) const override
Check if a point is inside.
std::vector< uint32_t > getTriangles() const
int getName() const override
struct Mantid::Geometry::MeshObject2D::PlaneParameters m_planeParameters
static bool pointsCoplanar(const std::vector< Kernel::V3D > &vertices)
Estalish if points are coplanar.
std::vector< uint32_t > m_triangles
Triangles are specified by indices into a list of vertices.
void draw() const override
std::shared_ptr< GeometryHandler > getGeometryHandler() const override
std::vector< Kernel::V3D > m_vertices
Vertices.
BoundingBox m_boundingBox
Bounding box.
const BoundingBox & getBoundingBox() const override
Returns an axis-aligned bounding box that will fit the shape.
Kernel::Material m_material
Material composition.
double distanceToPlane(const Kernel::V3D &point) const
void initialize()
Common initialization.
double distance(const Geometry::Track &ut) const override
Compute the distance to the first point of intersection with the mesh.
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector< Kernel::V3D > &vectors, double &innerRadius, double &radius, double &height) const override
size_t numberOfTriangles() const
int interceptSurface(Geometry::Track &ut) const override
Given a track, fill the track with valid section.
void initDraw() const override
MeshObject2D(std::vector< uint32_t > faces, std::vector< Kernel::V3D > vertices, const Kernel::Material &material)
Constructor.
const Kernel::Material & material() const override
bool hasValidShape() const override
double volume() const override
MeshObject2D * clone() const override
virtual void setMaterial(const Kernel::Material &material) override
boost::optional< Kernel::V3D > generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng, const size_t) const override
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.
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
const std::string & name() const
Returns the name of the material.
Defines a 1D pseudo-random number generator, i.e.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
double norm() const noexcept
constexpr double norm2() const noexcept
Vector length squared.
constexpr double Z() const noexcept
Get z.
bool sufficientPoints(const std::vector< Kernel::V3D > &vertices)
Kernel::V3D validatePointsCoplanar(const std::vector< Kernel::V3D > &vertices)
Establish the surface normal for a set of vertices.
bool allCoplanar(const std::vector< Kernel::V3D > &vertices, const Kernel::V3D &normal)
Establish if all vertices are coplanar.
Kernel::V3D surfaceNormal(const std::vector< Kernel::V3D > &vertices)
Establish the first surface normal.
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.
MANTID_GEOMETRY_DLL bool isOnTriangle(const Kernel::V3D &point, const Kernel::V3D &v1, const Kernel::V3D &v2, const Kernel::V3D &v3)
isOnTriangle
bool MANTID_GEOMETRY_DLL intersection(const ConvexPolygon &P, const ConvexPolygon &Q, ConvexPolygon &out)
Compute the instersection of two convex polygons.