Container.h 4.66 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2016 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9

#include "MantidGeometry/DllConfig.h"
10
11
12
#include "MantidGeometry/Objects/IObject.h"
#include "MantidKernel/Material.h"
#include "MantidKernel/V3D.h"
13
#include <unordered_map>
14
15
16
17
18

namespace Mantid {
namespace Geometry {

/**
Martyn Gigg's avatar
Martyn Gigg committed
19
  Models a Container is used to hold a sample in the beam. It gets most
20
  of its functionality from wrapped Geometry::IObject but can also hold a
21
  definition of what the sample geometry itself would be. If the sample shape
22
  definition is set then we term this a constrained sample geometry.
23
*/
24
class MANTID_GEOMETRY_DLL Container final : public IObject {
25
public:
26
  using ShapeArgs = std::unordered_map<std::string, double>;
27

28
29
  Container();
  Container(IObject_sptr shape);
30
  Container(const Container &container);
Peterson, Peter's avatar
Peterson, Peter committed
31
  Container(const std::string &xml);
32

33
34
  bool hasCustomizableSampleShape() const;
  bool hasFixedSampleShape() const;
35
  IObject_sptr createSampleShape(const ShapeArgs &args) const;
36
  IObject_sptr getSampleShape() const;
37

38
  void setSampleShape(const std::string &sampleShapeXML);
39
  void setSampleShape(IObject_sptr sampleShape) { m_sampleShape = std::move(sampleShape); };
40

41
  const IObject &getShape() const { return *m_shape; }
42

43
44
  bool isValid(const Kernel::V3D &p) const override { return m_shape->isValid(p); }
  bool isOnSide(const Kernel::V3D &p) const override { return m_shape->isOnSide(p); }
45
  bool hasValidShape() const override { return m_shape->hasValidShape(); }
46

47
48
  IObject *clone() const override { return new Container(*this); }

Karl Palmen's avatar
Karl Palmen committed
49
50
51
52
  IObject *cloneWithMaterial(const Kernel::Material &material) const override {
    return m_shape->cloneWithMaterial(material);
  }

53
54
  int getName() const override { return m_shape->getName(); }

55
56
57
58
  int interceptSurface(Geometry::Track &t) const override { return m_shape->interceptSurface(t); }
  double distance(const Geometry::Track &t) const override { return m_shape->distance(t); }
  double solidAngle(const Kernel::V3D &observer) const override { return m_shape->solidAngle(observer); }
  double solidAngle(const Kernel::V3D &observer, const Kernel::V3D &scaleFactor) const override {
59
60
61
    return m_shape->solidAngle(observer, scaleFactor);
  }
  double volume() const override { return m_shape->volume(); }
62
63
64
  const BoundingBox &getBoundingBox() const override { return m_shape->getBoundingBox(); }
  void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
                      double &zmin) const override {
65
66
    m_shape->getBoundingBox(xmax, ymax, zmax, xmin, ymin, zmin);
  }
67

68
69
70
  int getPointInObject(Kernel::V3D &point) const override { return m_shape->getPointInObject(point); }
  boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
                                                     const size_t i) const override {
Danny Hindson's avatar
Danny Hindson committed
71
    return m_shape->generatePointInObject(rng, i);
72
  }
73
74
  boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
                                                     const BoundingBox &activeRegion, const size_t i) const override {
Danny Hindson's avatar
Danny Hindson committed
75
    return m_shape->generatePointInObject(rng, activeRegion, i);
76
  }
77

78
  detail::ShapeInfo::GeometryShape shape() const override { return m_shape->shape(); }
79

80
  const detail::ShapeInfo &shapeInfo() const override { return m_shape->shapeInfo(); }
81

82
  void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
83
84
                     double &radius, double &height) const override {
    m_shape->GetObjectGeom(type, vectors, innerRadius, radius, height);
85
  }
86
  std::shared_ptr<GeometryHandler> getGeometryHandler() const override { return m_shape->getGeometryHandler(); }
87
88
89
90

  void draw() const override { m_shape->draw(); }
  void initDraw() const override { m_shape->initDraw(); }

91
92
  const Kernel::Material &material() const override { return m_shape->material(); }
  virtual void setMaterial(const Kernel::Material &material) override { m_shape->setMaterial(material); };
93
  void setID(const std::string &id) override;
94
  const std::string &id() const override { return m_shape->id(); }
95

96
private:
97
  IObject_sptr m_shape;
98
  std::string m_sampleShapeXML;
99
  IObject_sptr m_sampleShape = nullptr;
100
101
};

102
/// Typdef for a shared pointer
103
using Container_sptr = std::shared_ptr<Container>;
104
/// Typdef for a shared pointer to a const object
105
using Container_const_sptr = std::shared_ptr<const Container>;
106

107
108
} // namespace Geometry
} // namespace Mantid