Commit d8fa6464 authored by Andre Bamidele's avatar Andre Bamidele
Browse files

Refactored get object geometry to take inner radius. Refs: #25149

parent f211f36e
......@@ -89,9 +89,9 @@ public:
}
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors, double &myradius,
double &myheight) const override {
m_shape->GetObjectGeom(type, vectors, myradius, myheight);
std::vector<Kernel::V3D> &vectors, double &innerRadius,
double &radius, double &height) const override {
m_shape->GetObjectGeom(type, vectors, innerRadius, radius, height);
}
boost::shared_ptr<GeometryHandler> getGeometryHandler() const override {
return m_shape->getGeometryHandler();
......
......@@ -186,8 +186,8 @@ public:
detail::ShapeInfo::GeometryShape shape() const override;
const detail::ShapeInfo &shapeInfo() const;
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors, double &myradius,
double &myheight) const override;
std::vector<Kernel::V3D> &vectors, double &innerRadius,
double &radius, double &height) const override;
/// Getter for the shape xml
std::string getShapeXML() const;
......
......@@ -78,8 +78,8 @@ public:
virtual detail::ShapeInfo::GeometryShape shape() const = 0;
virtual void GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors,
double &myradius, double &myheight) const = 0;
std::vector<Kernel::V3D> &vectors, double &innerRadius,
double &radius, double &height) const = 0;
// Rendering
virtual void draw() const = 0;
virtual void initDraw() const = 0;
......
......@@ -126,8 +126,8 @@ public:
detail::ShapeInfo::GeometryShape shape() const override;
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors, double &myradius,
double &myheight) const override;
std::vector<Kernel::V3D> &vectors, double &innerRadius,
double &radius, double &height) const override;
/// Read access to mesh object for rendering
size_t numberOfVertices() const;
......
......@@ -70,8 +70,8 @@ public:
const size_t) const override;
detail::ShapeInfo::GeometryShape shape() const override;
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors, double &myradius,
double &myheight) const override;
std::vector<Kernel::V3D> &vectors, double &innerRadius,
double &radius, double &height) const override;
void draw() const override;
void initDraw() const override;
const Kernel::Material &material() const override;
......
......@@ -92,10 +92,8 @@ public:
GeometryShape shape() const;
void getObjectGeometry(GeometryShape &shape, std::vector<Kernel::V3D> &points,
double &innerRadius, double &outerRadius,
double &innerRadius, double &radius,
double &height) const;
void getObjectGeometry(GeometryShape &shape, std::vector<Kernel::V3D> &points,
double &radius, double &height) const;
CuboidGeometry cuboidGeometry() const;
HexahedronGeometry hexahedronGeometry() const;
......
......@@ -388,13 +388,13 @@ boost::shared_ptr<IObject> ObjCompAssembly::createOutline() {
std::string type;
detail::ShapeInfo::GeometryShape otype;
std::vector<Kernel::V3D> vectors;
double radius, height;
double radius, height, innerRadius;
boost::shared_ptr<const IObject> obj = group.front()->shape();
if (!obj) {
throw Kernel::Exception::InstrumentDefinitionError(
"Found ObjComponent without shape");
}
obj->GetObjectGeom(otype, vectors, radius, height);
obj->GetObjectGeom(otype, vectors, innerRadius, radius, height);
if (otype == detail::ShapeInfo::GeometryShape::CUBOID) {
type = "box";
} else if (otype == detail::ShapeInfo::GeometryShape::CYLINDER) {
......
......@@ -1014,12 +1014,12 @@ double CSGObject::triangleSolidAngle(const V3D &observer) const {
}
// If the object is a simple shape use the special methods
double height(0.0), radius(0.0);
double height(0.0), radius(0.0), innerRadius(0.0);
detail::ShapeInfo::GeometryShape type;
std::vector<Mantid::Kernel::V3D> geometry_vectors;
// Maximum of 4 vectors depending on the type
geometry_vectors.reserve(4);
this->GetObjectGeom(type, geometry_vectors, radius, height);
this->GetObjectGeom(type, geometry_vectors, innerRadius, radius, height);
auto nTri = this->numberOfTriangles();
// Cylinders are by far the most frequently used
switch (type) {
......@@ -1113,10 +1113,10 @@ double CSGObject::triangleSolidAngle(const V3D &observer,
// and Cone cases as well.
//
if (nTri == 0) {
double height = 0.0, radius(0.0);
double height = 0.0, radius(0.0), innerRadius;
detail::ShapeInfo::GeometryShape type;
std::vector<Kernel::V3D> vectors;
this->GetObjectGeom(type, vectors, radius, height);
this->GetObjectGeom(type, vectors, innerRadius, radius, height);
switch (type) {
case detail::ShapeInfo::GeometryShape::CUBOID:
for (auto &vector : vectors)
......@@ -1506,8 +1506,9 @@ double CSGObject::volume() const {
detail::ShapeInfo::GeometryShape type;
double height;
double radius;
double innerRadius;
std::vector<Kernel::V3D> vectors;
this->GetObjectGeom(type, vectors, radius, height);
this->GetObjectGeom(type, vectors, innerRadius, radius, height);
switch (type) {
case detail::ShapeInfo::GeometryShape::CUBOID: {
// Here, the volume is calculated by the triangular method.
......@@ -1543,6 +1544,8 @@ double CSGObject::volume() const {
return 4.0 / 3.0 * M_PI * radius * radius * radius;
case detail::ShapeInfo::GeometryShape::CYLINDER:
return M_PI * radius * radius * height;
case detail::ShapeInfo::GeometryShape::HOLLOWCYLINDER:
return M_PI * height * (radius * radius - innerRadius * innerRadius);
default:
// Fall back to Monte Carlo method.
return monteCarloVolume();
......@@ -1774,9 +1777,10 @@ void CSGObject::calcBoundingBoxByGeometry() {
std::vector<Kernel::V3D> vectors;
double radius;
double height;
double innerRadius;
// Will only work for shapes with ShapeInfo
m_handler->GetObjectGeom(type, vectors, radius, height);
m_handler->GetObjectGeom(type, vectors, innerRadius, radius, height);
// Type of shape is given as a simple integer
switch (type) {
case detail::ShapeInfo::GeometryShape::CUBOID: {
......@@ -2022,6 +2026,7 @@ V3D CSGObject::generatePointInObject(PseudoRandomNumberGenerator &rng,
break;
case detail::ShapeInfo::GeometryShape::HOLLOWCYLINDER:
point = RandomPoint::inHollowCylinder(m_handler->shapeInfo(), rng);
break;
case detail::ShapeInfo::GeometryShape::SPHERE:
point = RandomPoint::inSphere(m_handler->shapeInfo(), rng);
break;
......@@ -2067,7 +2072,8 @@ V3D CSGObject::generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
std::vector<Kernel::V3D> shapeVectors;
double radius;
double height;
GetObjectGeom(shape, shapeVectors, radius, height);
double innerRadius;
GetObjectGeom(shape, shapeVectors, innerRadius, radius, height);
switch (shape) {
case detail::ShapeInfo::GeometryShape::CUBOID:
point = RandomPoint::bounded<RandomPoint::inCuboid>(
......@@ -2077,6 +2083,10 @@ V3D CSGObject::generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
point = RandomPoint::bounded<RandomPoint::inCylinder>(
m_handler->shapeInfo(), rng, activeRegion, maxAttempts);
break;
case detail::ShapeInfo::GeometryShape::HOLLOWCYLINDER:
point = RandomPoint::bounded<RandomPoint::inHollowCylinder>(
m_handler->shapeInfo(), rng, activeRegion, maxAttempts);
break;
case detail::ShapeInfo::GeometryShape::SPHERE:
point = RandomPoint::bounded<RandomPoint::inSphere>(
m_handler->shapeInfo(), rng, activeRegion, maxAttempts);
......@@ -2253,11 +2263,12 @@ const detail::ShapeInfo &CSGObject::shapeInfo() const {
*/
void CSGObject::GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors,
double &myradius, double &myheight) const {
double &innerRadius, double &radius,
double &height) const {
type = detail::ShapeInfo::GeometryShape::NOSHAPE;
if (m_handler == nullptr)
return;
m_handler->GetObjectGeom(type, vectors, myradius, myheight);
m_handler->GetObjectGeom(type, vectors, innerRadius, radius, height);
}
/** Getter for the shape xml
......
......@@ -520,14 +520,15 @@ detail::ShapeInfo::GeometryShape MeshObject::shape() const {
*/
void MeshObject::GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors,
double &myradius, double &myheight) const {
double &innerRadius, double &radius,
double &height) const {
// In practice, this outputs type = -1,
// to indicate not a "standard" object (cuboid/cone/cyl/sphere).
// Retained for possible future use.
type = detail::ShapeInfo::GeometryShape::NOSHAPE;
if (m_handler == nullptr)
return;
m_handler->GetObjectGeom(type, vectors, myradius, myheight);
m_handler->GetObjectGeom(type, vectors, innerRadius, radius, height);
}
} // NAMESPACE Geometry
......
......@@ -401,7 +401,7 @@ detail::ShapeInfo::GeometryShape MeshObject2D::shape() const {
}
void MeshObject2D::GetObjectGeom(detail::ShapeInfo::GeometryShape &,
std::vector<Kernel::V3D> &, double &,
std::vector<Kernel::V3D> &, double &, double &,
double &) const {
throw std::runtime_error("Not implemented");
......
......@@ -103,14 +103,6 @@ void GeometryHandler::setGeometryCache(size_t nPts, size_t nFaces,
}
}
void GeometryHandler::GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors,
double &radius, double &height) const {
type = detail::ShapeInfo::GeometryShape::NOSHAPE;
if (m_shapeInfo)
m_shapeInfo->getObjectGeometry(type, vectors, radius, height);
}
void GeometryHandler::GetObjectGeom(detail::ShapeInfo::GeometryShape &type,
std::vector<Kernel::V3D> &vectors,
double &innerRadius, double &radius,
......
......@@ -30,21 +30,12 @@ ShapeInfo::GeometryShape ShapeInfo::shape() const { return m_shape; }
void ShapeInfo::getObjectGeometry(ShapeInfo::GeometryShape &shape,
std::vector<Kernel::V3D> &points,
double &radius, double &height) const {
shape = m_shape;
points = m_points;
radius = m_radius;
height = m_height;
}
void ShapeInfo::getObjectGeometry(ShapeInfo::GeometryShape &shape,
std::vector<Kernel::V3D> &points,
double &innerRadius, double &outerRadius,
double &innerRadius, double &radius,
double &height) const {
shape = m_shape;
points = m_points;
innerRadius = m_innerRadius;
outerRadius = m_radius;
radius = m_radius;
height = m_height;
}
......
......@@ -63,16 +63,16 @@ public:
auto &original = dynamic_cast<CSGObject &>(*original_ptr);
original.setID("sp-1");
ShapeInfo::GeometryShape objType;
double radius(-1.0), height(-1.0);
double radius(-1.0), height(-1.0), innerRadius(0.0);
std::vector<V3D> pts;
auto handler = original.getGeometryHandler();
TS_ASSERT(handler->hasShapeInfo());
original.GetObjectGeom(objType, pts, radius, height);
original.GetObjectGeom(objType, pts, innerRadius, radius, height);
TS_ASSERT_EQUALS(ShapeInfo::GeometryShape::SPHERE, objType);
CSGObject copy(original);
// The copy should be a primitive object with a GeometryHandler
copy.GetObjectGeom(objType, pts, radius, height);
copy.GetObjectGeom(objType, pts, innerRadius, radius, height);
TS_ASSERT_EQUALS("sp-1", copy.id());
auto handlerCopy = copy.getGeometryHandler();
......@@ -89,17 +89,17 @@ public:
auto &original = dynamic_cast<CSGObject &>(*original_ptr);
original.setID("sp-1");
ShapeInfo::GeometryShape objType;
double radius(-1.0), height(-1.0);
double radius(-1.0), height(-1.0), innerRadius(0.0);
std::vector<V3D> pts;
auto handler = original.getGeometryHandler();
TS_ASSERT(handler->hasShapeInfo());
original.GetObjectGeom(objType, pts, radius, height);
original.GetObjectGeom(objType, pts, innerRadius, radius, height);
TS_ASSERT_EQUALS(ShapeInfo::GeometryShape::SPHERE, objType);
CSGObject lhs; // initialize
lhs = original; // assign
// The copy should be a primitive object with a GluGeometryHandler
lhs.GetObjectGeom(objType, pts, radius, height);
lhs.GetObjectGeom(objType, pts, innerRadius, radius, height);
TS_ASSERT_EQUALS("sp-1", lhs.id());
TS_ASSERT_EQUALS(ShapeInfo::GeometryShape::SPHERE, objType);
......
......@@ -350,10 +350,10 @@ public:
void test_GetObjGeom_not_implemented() {
auto mesh = makeSimpleTriangleMesh();
std::vector<V3D> vectors;
double radius, height;
double radius, height, innerRadius;
Mantid::Geometry::detail::ShapeInfo::GeometryShape shape;
TS_ASSERT_THROWS(mesh.GetObjectGeom(shape, vectors, radius, height),
TS_ASSERT_THROWS(mesh.GetObjectGeom(shape, vectors, innerRadius, radius, height),
std::runtime_error &);
}
......
......@@ -367,8 +367,8 @@ public:
detail::ShapeInfo::GeometryShape otype;
std::vector<V3D> vectors;
double radius, height;
shape->GetObjectGeom(otype, vectors, radius, height);
double radius, height, innerRadius;
shape->GetObjectGeom(otype, vectors, innerRadius, radius, height);
TS_ASSERT_EQUALS(otype, detail::ShapeInfo::GeometryShape::CYLINDER);
TS_ASSERT_EQUALS(radius, 0.1);
......
......@@ -141,8 +141,8 @@ public:
detail::ShapeInfo::GeometryShape otype;
std::vector<V3D> vectors;
double radius, height;
shape->GetObjectGeom(otype, vectors, radius, height);
double radius, height, innerRadius;
shape->GetObjectGeom(otype, vectors, innerRadius, radius, height);
TS_ASSERT_EQUALS(otype, detail::ShapeInfo::GeometryShape::CYLINDER);
TS_ASSERT_EQUALS(radius, 0.1);
......
......@@ -135,17 +135,20 @@ public:
double radius = 10;
shapeInfo.setSphere(center, radius);
ShapeInfo::GeometryShape tshape;
std::vector<V3D> tpoints;
double theight;
double tradius;
shapeInfo.getObjectGeometry(tshape, tpoints, tradius, theight);
TS_ASSERT_EQUALS(tradius, radius);
TS_ASSERT(theight == 0);
TS_ASSERT(tpoints.size() == 1);
TS_ASSERT_EQUALS(tpoints[0], center);
TS_ASSERT_EQUALS(tshape, ShapeInfo::GeometryShape::SPHERE);
ShapeInfo::GeometryShape testShape;
std::vector<V3D> testPoints;
double testHeight;
double testRadius;
double testInnerRadius;
shapeInfo.getObjectGeometry(testShape, testPoints, testInnerRadius,
testRadius, testHeight);
TS_ASSERT_EQUALS(testRadius, radius);
TS_ASSERT_EQUALS(testHeight, 0);
TS_ASSERT_EQUALS(testInnerRadius, 0);
TS_ASSERT(testPoints.size() == 1);
TS_ASSERT_EQUALS(testPoints[0], center);
TS_ASSERT_EQUALS(testShape, ShapeInfo::GeometryShape::SPHERE);
}
void testGetObjectGeometryForCylinders() {
......@@ -158,21 +161,21 @@ public:
shapeInfo.setHollowCylinder(centreBottomBase, symmetryAxis, innerRadius,
outerRadius, height);
ShapeInfo::GeometryShape tshape;
std::vector<V3D> tpoints;
double theight;
ShapeInfo::GeometryShape testShape;
std::vector<V3D> testPoints;
double testHeight;
double tinnerRadius;
double touterRadius;
shapeInfo.getObjectGeometry(tshape, tpoints, tinnerRadius, touterRadius,
theight);
shapeInfo.getObjectGeometry(testShape, testPoints, tinnerRadius,
touterRadius, testHeight);
TS_ASSERT_EQUALS(tinnerRadius, innerRadius);
TS_ASSERT_EQUALS(touterRadius, outerRadius);
TS_ASSERT_EQUALS(theight, height);
TS_ASSERT(tpoints.size() == 2);
TS_ASSERT_EQUALS(tpoints[0], centreBottomBase);
TS_ASSERT_EQUALS(tpoints[1], symmetryAxis);
TS_ASSERT_EQUALS(tshape, ShapeInfo::GeometryShape::HOLLOWCYLINDER);
TS_ASSERT_EQUALS(testHeight, height);
TS_ASSERT(testPoints.size() == 2);
TS_ASSERT_EQUALS(testPoints[0], centreBottomBase);
TS_ASSERT_EQUALS(testPoints[1], symmetryAxis);
TS_ASSERT_EQUALS(testShape, ShapeInfo::GeometryShape::HOLLOWCYLINDER);
}
void testCuboidGeometry() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment