Commit 8ecd3c4f authored by Lamar Moore's avatar Lamar Moore
Browse files

Re #15542 code improvements

parent 81e13248
......@@ -174,6 +174,25 @@ private:
const Poco::XML::Element *pLocElem,
const Poco::XML::Element *pCompElem, IdList &idList);
void createDetectorOrMonitor(Geometry::ICompAssembly *parent,
const Poco::XML::Element *pLocElem,
const Poco::XML::Element *pCompElem,
const std::string &filename,
const Poco::XML::Element *pType, IdList &idList,
const std::string &category);
void createRectangularDetector(Geometry::ICompAssembly *parent,
const Poco::XML::Element *pLocElem,
const Poco::XML::Element *pCompElem,
const std::string &filename,
const Poco::XML::Element *pType);
void createStructuredDetector(Geometry::ICompAssembly *parent,
const Poco::XML::Element *pLocElem,
const Poco::XML::Element *pCompElem,
const std::string &filename,
const Poco::XML::Element *pType);
/// Append \<locations\> in a locations element
void appendLocations(Geometry::ICompAssembly *parent,
const Poco::XML::Element *pLocElems,
......
......@@ -59,6 +59,9 @@ public:
//! Parametrized constructor
RectangularDetector(const RectangularDetector *base, const ParameterMap *map);
///Matches name to Structured Detector
static bool compareName(const std::string& proposedMatch);
/// Create all the detector pixels of this rectangular detector.
void initialize(boost::shared_ptr<Object> shape, int xpixels, double xstart,
double xstep, int ypixels, double ystart, double ystep,
......
......@@ -50,6 +50,9 @@ public:
/// String description of the type of component
std::string type() const override { return "StructuredDetector"; }
///Matches name to Structured Detector
static bool compareName(const std::string& proposedMatch);
//! Empty constructor
StructuredDetector();
......
......@@ -86,18 +86,22 @@ public:
GeometryHandler *createInstance(boost::shared_ptr<Object> obj) override;
GeometryHandler *createInstance(Object *) override;
/// sets the geometry handler for a cuboid
void setCuboid(Kernel::V3D, Kernel::V3D, Kernel::V3D, Kernel::V3D);
void setCuboid(const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &,
const Kernel::V3D &);
/// sets the geometry handler for a hexahedron
void setHexahedron(Kernel::V3D, Kernel::V3D, Kernel::V3D, Kernel::V3D,
Kernel::V3D, Kernel::V3D, Kernel::V3D, Kernel::V3D);
void setHexahedron(const Kernel::V3D &, const Kernel::V3D &,
const Kernel::V3D &, const Kernel::V3D &,
const Kernel::V3D &, const Kernel::V3D &,
const Kernel::V3D &, const Kernel::V3D &);
/// sets the geometry handler for a cone
void setSphere(Kernel::V3D, double);
void setSphere(const Kernel::V3D &, double);
/// sets the geometry handler for a cylinder
void setCylinder(Kernel::V3D, Kernel::V3D, double, double);
void setCylinder(const Kernel::V3D &, const Kernel::V3D &, double, double);
/// sets the geometry handler for a cone
void setCone(Kernel::V3D, Kernel::V3D, double, double);
void setCone(const Kernel::V3D &, const Kernel::V3D &, double, double);
/// sets the geometry handler for a segmented cylinder
void setSegmentedCylinder(Kernel::V3D, Kernel::V3D, double, double);
void setSegmentedCylinder(const Kernel::V3D &, const Kernel::V3D &, double,
double);
void Triangulate() override;
void Render() override;
void Initialize() override;
......
......@@ -9,6 +9,7 @@
#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <boost/regex.hpp>
#include "MantidGeometry/Instrument/RectangularDetectorPixel.h"
namespace {
......@@ -74,6 +75,13 @@ RectangularDetector::RectangularDetector(const std::string &n,
setGeometryHandler(new BitmapGeometryHandler(this));
}
bool RectangularDetector::compareName(const std::string &proposedMatch) {
boost::regex exp("(RectangularDetector)|(rectangularDetector)|(rectangulardetector)|"
"(rectangular_detector)");
return boost::regex_match(proposedMatch, exp);
}
void RectangularDetector::init() {
m_xpixels = m_ypixels = 0;
m_xsize = m_ysize = 0;
......@@ -476,16 +484,12 @@ RectangularDetector::getComponentByName(const std::string &cname,
// and this prevents Bank11 matching Bank 1
const std::string MEMBER_NAME = this->getName() + "(";
// if the component name is too short, just return
if (cname.length() <= MEMBER_NAME.length())
return boost::shared_ptr<const IComponent>();
// check that the searched for name starts with the detector's
// name as they are generated
if (cname.substr(0, MEMBER_NAME.length()).compare(MEMBER_NAME) == 0) {
return CompAssembly::getComponentByName(cname, nlevels);
if (cname.substr(0, MEMBER_NAME.length()).compare(MEMBER_NAME) != 0) {
return boost::shared_ptr<const IComponent>();
} else {
return boost::shared_ptr<const IComponent>();
return CompAssembly::getComponentByName(cname, nlevels);
}
}
......@@ -571,27 +575,21 @@ void RectangularDetector::testIntersectionWithChildren(
//-------------------------------------------------------------------------------------------------
/// Does the point given lie within this object component?
bool RectangularDetector::isValid(const V3D &point) const {
// Avoid compiler warning
(void)point;
bool RectangularDetector::isValid(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"RectangularDetector::isValid() is not implemented.");
}
//-------------------------------------------------------------------------------------------------
/// Does the point given lie on the surface of this object component?
bool RectangularDetector::isOnSide(const V3D &point) const {
// Avoid compiler warning
(void)point;
bool RectangularDetector::isOnSide(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"RectangularDetector::isOnSide() is not implemented.");
}
//-------------------------------------------------------------------------------------------------
/// Checks whether the track given will pass through this Component.
int RectangularDetector::interceptSurface(Track &track) const {
// Avoid compiler warning
(void)track;
int RectangularDetector::interceptSurface(Track &) const {
throw Kernel::Exception::NotImplementedError(
"RectangularDetector::interceptSurface() is not implemented.");
}
......@@ -599,18 +597,14 @@ int RectangularDetector::interceptSurface(Track &track) const {
//-------------------------------------------------------------------------------------------------
/// Finds the approximate solid angle covered by the component when viewed from
/// the point given
double RectangularDetector::solidAngle(const V3D &observer) const {
// Avoid compiler warning
(void)observer;
double RectangularDetector::solidAngle(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"RectangularDetector::solidAngle() is not implemented.");
}
//-------------------------------------------------------------------------------------------------
/// Try to find a point that lies within (or on) the object
int RectangularDetector::getPointInObject(V3D &point) const {
// Avoid compiler warning
(void)point;
int RectangularDetector::getPointInObject(V3D &) const {
throw Kernel::Exception::NotImplementedError(
"RectangularDetector::getPointInObject() is not implemented.");
}
......
......@@ -9,6 +9,7 @@
#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <boost/regex.hpp>
namespace Mantid {
namespace Geometry {
......@@ -50,6 +51,13 @@ StructuredDetector::StructuredDetector(const StructuredDetector *base,
init();
}
bool StructuredDetector::compareName(const std::string &proposedMatch) {
boost::regex exp("(StructuredDetector)|(structuredDetector)|(structureddetector)|"
"(structured_detector)");
return boost::regex_match(proposedMatch, exp);
}
void StructuredDetector::init() {
m_xpixels = 0;
m_ypixels = 0;
......@@ -320,8 +328,6 @@ void StructuredDetector::initialize(int xpixels, int ypixels,
auto maxDetId = idstart;
auto detSize = x.size();
CompAssembly *detAssembly = new CompAssembly(name);
for (auto ix = 0; ix < m_xpixels; ix++) {
// Create an ICompAssembly for each x-column
std::ostringstream oss_col;
......@@ -356,6 +362,56 @@ void StructuredDetector::initialize(int xpixels, int ypixels,
m_maxDetId = maxDetId;
}
boost::shared_ptr<Mantid::Geometry::Object>
streamShape(const std::string &name, double xlb, double xlf, double xrf,
double xrb, double ylb, double ylf, double yrf, double yrb) {
std::ostringstream shapestr;
// Create XML shape used to describe detector pixel
shapestr << "<type name=\"userShape\" >";
shapestr << "<hexahedron id=\"" << name << "\" >";
shapestr << "<left-back-bottom-point x=\"" << xlb << "\""
<< " y=\"" << ylb << "\""
<< " z=\"0\" />";
shapestr << "<left-front-bottom-point x=\"" << xlf << "\""
<< " y=\"" << ylf << "\""
<< " z=\"0\" />";
shapestr << "<right-front-bottom-point x=\"" << xrf << "\""
<< " y=\"" << yrf << "\""
<< " z=\"0\" />";
shapestr << "<right-back-bottom-point x=\"" << xrb << "\""
<< " y=\"" << yrb << "\""
<< " z=\"0\" />";
shapestr << "<left-back-top-point x=\"" << xlb << "\""
<< " y=\"" << ylb << "\""
<< " z=\"0.001\" />";
shapestr << "<left-front-top-point x=\"" << xlf << "\""
<< " y=\"" << ylf << "\""
<< " z=\"0.001\" />";
shapestr << "<right-front-top-point x=\"" << xrf << "\""
<< " y=\"" << yrf << "\""
<< " z=\"0.001\" />";
shapestr << "<right-back-top-point x=\"" << xrb << "\""
<< " y=\"" << yrb << "\""
<< " z=\"0.001\" />";
shapestr << "</hexahedron>";
shapestr << "<bounding-box>";
shapestr << "<x-min val=\"" << std::min(xlf, xlb) << "\" />";
shapestr << "<x-max val=\"" << std::max(xrb, xrf) << "\" />";
shapestr << "<y-min val=\"" << ylb << "\" />";
shapestr << "<y-max val=\"" << yrf << "\" />";
shapestr << "<z-min val=\"0\" />";
shapestr << "<z-max val=\"0.001\" />";
shapestr << "</bounding-box>";
shapestr << "<algebra val=\"" << name << "\" />";
shapestr << "</type>";
Mantid::Geometry::ShapeFactory shapeCreator;
return shapeCreator.createShape(shapestr.str(), false);
}
/** Creates new hexahedral detector pixel at row x column y using the
* detector vertex values.
* @param name :: The Pixel name identifier
......@@ -367,9 +423,7 @@ void StructuredDetector::initialize(int xpixels, int ypixels,
Detector *StructuredDetector::addDetector(CompAssembly *parent,
const std::string &name, int x, int y,
int id) {
auto w = m_xpixels + 1;
std::ostringstream shapestr;
Mantid::Geometry::ShapeFactory shapeCreator;
auto w = m_xpixels + 1;
// Store hexahedral vertices for detector shape
auto xlb = m_xvalues[(y * w) + x];
......@@ -402,47 +456,8 @@ Detector *StructuredDetector::addDetector(CompAssembly *parent,
yrb -= ypos;
ylb -= ypos;
// Create XML shape used to describe detector pixel
shapestr << "<type name=\"userShape\" >";
shapestr << "<hexahedron id=\"" << name << "\" >";
shapestr << "<left-back-bottom-point x=\"" << xlb << "\""
<< " y=\"" << ylb << "\""
<< " z=\"0\" />";
shapestr << "<left-front-bottom-point x=\"" << xlf << "\""
<< " y=\"" << ylf << "\""
<< " z=\"0\" />";
shapestr << "<right-front-bottom-point x=\"" << xrf << "\""
<< " y=\"" << yrf << "\""
<< " z=\"0\" />";
shapestr << "<right-back-bottom-point x=\"" << xrb << "\""
<< " y=\"" << yrb << "\""
<< " z=\"0\" />";
shapestr << "<left-back-top-point x=\"" << xlb << "\""
<< " y=\"" << ylb << "\""
<< " z=\"0.001\" />";
shapestr << "<left-front-top-point x=\"" << xlf << "\""
<< " y=\"" << ylf << "\""
<< " z=\"0.001\" />";
shapestr << "<right-front-top-point x=\"" << xrf << "\""
<< " y=\"" << yrf << "\""
<< " z=\"0.001\" />";
shapestr << "<right-back-top-point x=\"" << xrb << "\""
<< " y=\"" << yrb << "\""
<< " z=\"0.001\" />";
shapestr << "</hexahedron>";
shapestr << "<bounding-box>";
shapestr << "<x-min val=\"" << std::min(xlf, xlb) << "\" />";
shapestr << "<x-max val=\"" << std::max(xrb, xrf) << "\" />";
shapestr << "<y-min val=\"" << ylb << "\" />";
shapestr << "<y-max val=\"" << yrf << "\" />";
shapestr << "<z-min val=\"0\" />";
shapestr << "<z-max val=\"0.001\" />";
shapestr << "</bounding-box>";
shapestr << "<algebra val=\"" << name << "\" />";
shapestr << "</type>";
boost::shared_ptr<Mantid::Geometry::Object> shape =
shapeCreator.createShape(shapestr.str(), false);
streamShape(name, xlb, xlf, xrf, xrb, ylb, ylf, yrf, yrb);
// Create detector
auto detector = new Detector(name, id, shape, parent);
......@@ -486,16 +501,12 @@ StructuredDetector::getComponentByName(const std::string &cname,
// and this prevents Bank11 matching Bank 1
const std::string MEMBER_NAME = this->getName() + "(";
// if the component name is too short, just return
if (cname.length() <= MEMBER_NAME.length())
return boost::shared_ptr<const IComponent>();
// check that the searched for name starts with the detector's
// name as they are generated
if (cname.substr(0, MEMBER_NAME.length()).compare(MEMBER_NAME) == 0) {
return CompAssembly::getComponentByName(cname, nlevels);
if (cname.substr(0, MEMBER_NAME.length()).compare(MEMBER_NAME) != 0) {
return boost::shared_ptr<const IComponent>();
} else {
return boost::shared_ptr<const IComponent>();
return CompAssembly::getComponentByName(cname, nlevels);
}
}
......@@ -507,42 +518,32 @@ StructuredDetector::getComponentByName(const std::string &cname,
//-------------------------------------------------------------------------------------------------
/// Does the point given lie within this object component?
bool StructuredDetector::isValid(const V3D &point) const {
// Avoid compiler warning
(void)point;
bool StructuredDetector::isValid(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"StructuredDetector::isValid() is not implemented.");
}
/// Does the point given lie on the surface of this object component?
bool StructuredDetector::isOnSide(const V3D &point) const {
// Avoid compiler warning
(void)point;
bool StructuredDetector::isOnSide(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"StructuredDetector::isOnSide() is not implemented.");
}
/// Checks whether the track given will pass through this Component.
int StructuredDetector::interceptSurface(Track &track) const {
// Avoid compiler warning
(void)track;
int StructuredDetector::interceptSurface(Track &) const {
throw Kernel::Exception::NotImplementedError(
"StructuredDetector::interceptSurface() is not implemented.");
}
/// Finds the approximate solid angle covered by the component when viewed from
/// the point given
double StructuredDetector::solidAngle(const V3D &observer) const {
// Avoid compiler warning
(void)observer;
double StructuredDetector::solidAngle(const V3D &) const {
throw Kernel::Exception::NotImplementedError(
"StructuredDetector::solidAngle() is not implemented.");
}
/// Try to find a point that lies within (or on) the object
int StructuredDetector::getPointInObject(V3D &point) const {
// Avoid compiler warning
(void)point;
int StructuredDetector::getPointInObject(V3D &) const {
throw Kernel::Exception::NotImplementedError(
"StructuredDetector::getPointInObject() is not implemented.");
}
......@@ -553,27 +554,6 @@ int StructuredDetector::getPointInObject(V3D &point) const {
* @param assemblyBox :: A BoundingBox object that will be overwritten
*/
void StructuredDetector::getBoundingBox(BoundingBox &assemblyBox) const {
/*if (!m_cachedBoundingBox) {
auto w = m_xpixels + 1;
auto x = getXValues();
auto y = getYValues();
double xmin = x[0], xmax = x[0], ymin = y[0], ymax =y[0];
for (int i = 0; i < x.size(); i++)
{
if (x[i] < xmin)
xmin = x[i];
if (x[i] > xmax)
xmax = x[i];
if (y[i] < ymin)
ymin = y[i];
if (y[i] > ymax)
ymax = y[i];
}
m_cachedBoundingBox = new BoundingBox(xmax, ymax, 0.001, xmin, ymin, 0);*/
if (!m_cachedBoundingBox) {
m_cachedBoundingBox = new BoundingBox();
// Get all the corners
......@@ -667,10 +647,8 @@ const boost::shared_ptr<const Object> StructuredDetector::shape() const {
std::string xmlHexahedralShape(xmlShapeStream.str());
Geometry::ShapeFactory shapeCreator;
boost::shared_ptr<Geometry::Object> hexahedralShape =
shapeCreator.createShape(xmlHexahedralShape);
return hexahedralShape;
return shapeCreator.createShape(xmlHexahedralShape);
}
//-------------------------------------------------------------------------------------------------
......
......@@ -1304,7 +1304,7 @@ void ShapeFactory::createGeometryHandler(Poco::XML::Element *pElem,
boost::make_shared<GluGeometryHandler>(Obj);
Obj->setGeometryHandler(handler);
auto corners = parseHexahedron(pElem);
((GluGeometryHandler *)(handler.get()))
dynamic_cast<GluGeometryHandler *>(handler.get())
->setHexahedron(corners.lbb, corners.lfb, corners.rfb, corners.rbb,
corners.lbt, corners.lft, corners.rft, corners.rbt);
} else if (pElem->tagName() == "sphere") {
......
#include "MantidGeometry/Objects/Object.h"
#include "MantidGeometry/Instrument/ObjComponent.h"
#include "MantidGeometry/Objects/Object.h"
#include "MantidGeometry/Rendering/GeometryHandler.h"
#include "MantidGeometry/Rendering/GluGeometryHandler.h"
#include "MantidGeometry/Rendering/GluGeometryRenderer.h"
......@@ -97,21 +97,23 @@ void GluGeometryHandler::GetObjectGeom(int &mytype,
switch (type) {
case CUBOID:
mytype = 1;
vectors.push_back(Point1);
vectors.push_back(Point2);
vectors.push_back(Point3);
vectors.push_back(Point4);
vectors.resize(4);
vectors[0] = Point1;
vectors[1] = Point2;
vectors[2] = Point3;
vectors[3] = Point4;
break;
case HEXAHEDRON:
mytype = 1;
vectors.push_back(Point1);
vectors.push_back(Point2);
vectors.push_back(Point3);
vectors.push_back(Point4);
vectors.push_back(Point5);
vectors.push_back(Point6);
vectors.push_back(Point7);
vectors.push_back(Point8);
vectors.resize(8);
vectors[0] =Point1;
vectors[1] =Point2;
vectors[2] =Point3;
vectors[3] =Point4;
vectors[4] =Point5;
vectors[5] =Point6;
vectors[6] =Point7;
vectors[7] =Point8;
break;
case SPHERE:
mytype = 2;
......@@ -120,22 +122,25 @@ void GluGeometryHandler::GetObjectGeom(int &mytype,
break;
case CYLINDER:
mytype = 3;
vectors.push_back(center);
vectors.push_back(axis);
vectors.resize(2);
vectors[0] = center;
vectors[1] = axis;
myradius = radius;
myheight = height;
break;
case CONE:
mytype = 4;
vectors.push_back(center);
vectors.push_back(axis);
vectors.resize(2);
vectors[0] = center;
vectors[1] = axis;
myradius = radius;
myheight = height;
break;
case SEGMENTED_CYLINDER:
mytype = 5;
vectors.push_back(center);
vectors.push_back(axis);
vectors.reserve(2);
vectors[0] = center;
vectors[1] = axis;
myradius = radius;
myheight = height;
break;
......@@ -150,7 +155,8 @@ void GluGeometryHandler::Initialize() {
}
}
void GluGeometryHandler::setCuboid(V3D p1, V3D p2, V3D p3, V3D p4) {
void GluGeometryHandler::setCuboid(const V3D &p1, const V3D &p2, const V3D &p3,
const V3D &p4) {
type = CUBOID;
Point1 = p1;
Point2 = p2;
......@@ -158,10 +164,10 @@ void GluGeometryHandler::setCuboid(V3D p1, V3D p2, V3D p3, V3D p4) {
Point4 = p4;
}
void GluGeometryHandler::setHexahedron(Kernel::V3D p1, Kernel::V3D p2,
Kernel::V3D p3, Kernel::V3D p4,
Kernel::V3D p5, Kernel::V3D p6,
Kernel::V3D p7, Kernel::V3D p8) {
void GluGeometryHandler::setHexahedron(const V3D &p1, const V3D &p2,
const V3D &p3, const V3D &p4,
const V3D &p5, const V3D &p6,
const V3D &p7, const V3D &p8) {
type = HEXAHEDRON;
Point1 = p1;
Point2 = p2;
......@@ -173,27 +179,29 @@ void GluGeometryHandler::setHexahedron(Kernel::V3D p1, Kernel::V3D p2,
Point8 = p8;
}
void GluGeometryHandler::setSphere(V3D c, double r) {
void GluGeometryHandler::setSphere(const V3D &c, double r) {
type = SPHERE;
center = c;
radius = r;
}
void GluGeometryHandler::setCylinder(V3D c, V3D a, double r, double h) {
void GluGeometryHandler::setCylinder(const V3D &c, const V3D &a, double r,
double h) {
type = CYLINDER;
center = c;
axis = a;
radius = r;
height = h;
}
void GluGeometryHandler::setCone(V3D c, V3D a, double r, double h) {
void GluGeometryHandler::setCone(const V3D &c, const V3D &a, double r,
double h) {
type = CONE;
center = c;
axis = a;
radius = r;
height = h;
}
void GluGeometryHandler::setSegmentedCylinder(V3D c, V3D a, double r,
double h) {
void GluGeometryHandler::setSegmentedCylinder(const V3D &c, const V3D &a,
double r, double h) {
type = SEGMENTED_CYLINDER;
center = c;
axis = a;
......
......@@ -29,21 +29,18 @@ StructuredGeometryHandler::StructuredGeometryHandler()
///< Create an instance of concrete geometry handler for ObjComponent
StructuredGeometryHandler *
StructuredGeometryHandler::createInstance(IObjComponent *comp) {
(void)comp;
StructuredGeometryHandler::createInstance(IObjComponent *) {