Commit 82917161 authored by Moore's avatar Moore
Browse files

Re #16106 Added hexahedron bounding box unit test

parent 680a0764
......@@ -897,9 +897,6 @@ std::string
parseHexahedronFromStruct(Hexahedron &hex,
std::map<int, boost::shared_ptr<Surface>> &prim,
int &l_id) {
V3D pointTowardBack = hex.lbb - hex.lfb;
pointTowardBack.normalize();
V3D normal;
// add front face
......
......@@ -786,6 +786,47 @@ public:
TS_ASSERT_DELTA(zmin, -3.0, 0.0001);
}
void testGetBoundingBoxForCuboid() {
Object_sptr cuboid = createUnitCube();
double xmax, ymax, zmax, xmin, ymin, zmin;
xmax = ymax = zmax = 100;
xmin = ymin = zmin = -100;
cuboid->getBoundingBox(xmax, ymax, zmax, xmin, ymin, zmin);
TS_ASSERT_DELTA(xmax, 0.5, 0.0001);
TS_ASSERT_DELTA(ymax, 0.5, 0.0001);
TS_ASSERT_DELTA(zmax, 0.5, 0.0001);
TS_ASSERT_DELTA(xmin, -0.5, 0.0001);
TS_ASSERT_DELTA(ymin, -0.5, 0.0001);
TS_ASSERT_DELTA(zmin, -0.5, 0.0001);
}
void testGetBoundingBoxForHexahedron() {
//For information on how the hexahedron is constructed
//See http://docs.mantidproject.org/nightly/concepts/HowToDefineGeometricShape.html#hexahedron
Hexahedron hex;
hex.lbb = V3D(0, 0, 0);
hex.lfb = V3D(1, 0, 0);
hex.rfb = V3D(1, 1, 0);
hex.rbb = V3D(0, 1, 0);
hex.lbt = V3D(0, 0, 2);
hex.lft = V3D(0.5, 0, 2);
hex.rft = V3D(0.5, 0.5, 2);
hex.rbt = V3D(0, 0.5, 2);
Object_sptr hexahedron = createHexahedron(hex);
auto bb = hexahedron->getBoundingBox();
TS_ASSERT_DELTA(bb.xMax(), 1, 0.0001);
TS_ASSERT_DELTA(bb.yMax(), 1, 0.0001);
TS_ASSERT_DELTA(bb.zMax(), 2, 0.0001);
TS_ASSERT_DELTA(bb.xMin(), 0, 0.0001);
TS_ASSERT_DELTA(bb.yMin(), 0, 0.0001);
TS_ASSERT_DELTA(bb.zMin(), 0, 0.0001);
}
void testdefineBoundingBox()
/**
Test use of defineBoundingBox
......@@ -1162,6 +1203,93 @@ private:
return retVal;
}
Object_sptr createHexahedron(Hexahedron &hex) {
// Create surfaces
std::map<int, boost::shared_ptr<Surface>> HexSurMap;
HexSurMap[1] = boost::make_shared<Plane>();
HexSurMap[2] = boost::make_shared<Plane>();
HexSurMap[3] = boost::make_shared<Plane>();
HexSurMap[4] = boost::make_shared<Plane>();
HexSurMap[5] = boost::make_shared<Plane>();
HexSurMap[6] = boost::make_shared<Plane>();
V3D normal;
// add front face
auto pPlaneFrontCutoff = boost::make_shared<Plane>();
// calculate surface normal
normal = (hex.rfb - hex.lfb).cross_prod(hex.lft - hex.lfb);
// Ensure surfacenormal is pointing in the correct direction
if (normal.scalar_prod(hex.rfb - hex.rbb) < 0)
normal *= -1.0;
pPlaneFrontCutoff->setPlane(hex.lfb, normal);
HexSurMap[1] = pPlaneFrontCutoff;
// add back face
auto pPlaneBackCutoff = boost::make_shared<Plane>();
normal = (hex.rbb - hex.lbb).cross_prod(hex.lbt - hex.lbb);
if (normal.scalar_prod(hex.rfb - hex.rbb) < 0)
normal *= -1.0;
pPlaneBackCutoff->setPlane(hex.lbb, normal);
HexSurMap[2] = pPlaneBackCutoff;
// add left face
auto pPlaneLeftCutoff = boost::make_shared<Plane>();
normal = (hex.lbb - hex.lfb).cross_prod(hex.lft - hex.lfb);
if (normal.scalar_prod(hex.rfb - hex.lfb) < 0)
normal *= -1.0;
pPlaneLeftCutoff->setPlane(hex.lfb, normal);
HexSurMap[3] = pPlaneLeftCutoff;
// add right face
auto pPlaneRightCutoff = boost::make_shared<Plane>();
normal = (hex.rbb - hex.rfb).cross_prod(hex.rft - hex.rfb);
if (normal.scalar_prod(hex.rfb - hex.lfb) < 0)
normal *= -1.0;
pPlaneRightCutoff->setPlane(hex.rfb, normal);
HexSurMap[4] = pPlaneRightCutoff;
// add top face
auto pPlaneTopCutoff = boost::make_shared<Plane>();
normal = (hex.rft - hex.lft).cross_prod(hex.lbt - hex.lft);
if (normal.scalar_prod(hex.rft - hex.rfb) < 0)
normal *= -1.0;
pPlaneTopCutoff->setPlane(hex.lft, normal);
HexSurMap[5] = pPlaneTopCutoff;
// add bottom face
auto pPlaneBottomCutoff = boost::make_shared<Plane>();
normal = (hex.rfb - hex.lfb).cross_prod(hex.lbb - hex.lfb);
if (normal.scalar_prod(hex.rft - hex.rfb) < 0)
normal *= -1.0;
pPlaneBottomCutoff->setPlane(hex.lfb, normal);
HexSurMap[6] = pPlaneBottomCutoff;
// using surface ids: 1-6
HexSurMap[1]->setName(1);
HexSurMap[2]->setName(2);
HexSurMap[3]->setName(3);
HexSurMap[4]->setName(4);
HexSurMap[5]->setName(5);
HexSurMap[6]->setName(6);
std::string ObjHex = "-1 2 3 -4 -5 6";
Object_sptr retVal = Object_sptr(new Object);
//Explicitly setting the GluGeometryHanler hexahedron allows
//for the correct bounding box calculation.
auto handler = boost::make_shared<GluGeometryHandler>(retVal);
handler->setHexahedron(hex.lbb, hex.lfb, hex.rfb, hex.rbb, hex.lbt, hex.lft,
hex.rft, hex.rbt);
retVal->setGeometryHandler(handler);
retVal->setObject(68, ObjHex);
retVal->populate(HexSurMap);
return retVal;
}
};
#endif // MANTID_TESTOBJECT__
Supports Markdown
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