Mantid
Loading...
Searching...
No Matches
ComponentHelper.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
14
15#include <memory>
16
18using Kernel::V3D;
19
34 const Mantid::Kernel::V3D &samplePos,
35 const Mantid::Kernel::V3D &detectorPos) {
36 Instrument_sptr instrument = std::make_shared<Instrument>();
37 instrument->setReferenceFrame(
38 std::make_shared<ReferenceFrame>(Mantid::Geometry::Y /*up*/, Mantid::Geometry::X /*along*/, Left, "0,0,0"));
39
40 // A source
41 ObjComponent *source = new ObjComponent("source");
42 source->setPos(sourcePos);
43 source->setShape(createSphere(0.01 /*1cm*/, V3D(0, 0, 0), "1"));
44 instrument->add(source);
45 instrument->markAsSource(source);
46
47 // A sample
48 Component *sample = new Component("some-surface-holder");
49 sample->setPos(samplePos);
50 instrument->add(sample);
51 instrument->markAsSamplePos(sample);
52
53 // A detector
54 Detector *det = new Detector("point-detector", 1 /*detector id*/, nullptr);
55 det->setPos(detectorPos);
56 det->setShape(createSphere(0.01 /*1cm*/, V3D(0, 0, 0), "1"));
57 instrument->add(det);
58 instrument->markAsDetector(det);
59
60 return instrument;
61}
62
64 const std::vector<Kernel::V3D> &vecdetpos,
65 const std::vector<detid_t> &vecdetid) {
66 Instrument_sptr instrument = std::make_shared<Instrument>();
67 instrument->setReferenceFrame(
68 std::make_shared<ReferenceFrame>(Mantid::Geometry::Y /*up*/, Mantid::Geometry::Z /*along*/, Right, "0,0,0"));
69
70 // A source
71 ObjComponent *source = new ObjComponent("source");
72 source->setPos(sourcePos);
73 source->setShape(createSphere(0.01 /*1cm*/, V3D(0, 0, 0), "1"));
74 instrument->add(source);
75 instrument->markAsSource(source);
76
77 // A sample
78 Component *sample = new Component("some-surface-holder");
79 sample->setPos(samplePos);
80 instrument->add(sample);
81 instrument->markAsSamplePos(sample);
82
83 // A detector
84 size_t numdets = vecdetpos.size();
85 for (size_t i = 0; i < numdets; ++i) {
86 Detector *det = new Detector("point-detector", vecdetid[i] /*detector id*/, nullptr);
87 det->setPos(vecdetpos[i]);
88 // FIXME - should be cubi... pixel
89 det->setShape(createSphere(0.01 /*1cm*/, V3D(0, 0, 0), "1"));
90 instrument->add(det);
91 instrument->markAsDetector(det);
92 }
93
94 return instrument;
95}
96
100std::shared_ptr<CSGObject> createSphere(double radius, const V3D &centre, const std::string &id) {
101 ShapeFactory shapeMaker;
102 return shapeMaker.createShape(sphereXML(radius, centre, id));
103}
104
108std::string sphereXML(double radius, const Kernel::V3D &centre, const std::string &id) {
109 std::ostringstream xml;
110 xml << "<sphere id=\"" << id << "\">"
111 << "<centre x=\"" << centre.X() << "\" y=\"" << centre.Y() << "\" z=\"" << centre.Z() << "\" />"
112 << "<radius val=\"" << radius << "\" />"
113 << "</sphere>";
114 return xml.str();
115}
116
117} // namespace Mantid::Geometry::ComponentHelper
double radius
Definition: Rasterize.cpp:31
Component is a wrapper for a Component which can modify some of its parameters, e....
Definition: Component.h:41
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)
Definition: Component.cpp:204
This class represents a detector - i.e.
Definition: Detector.h:30
Object Component class, this class brings together the physical attributes of the component to the po...
Definition: ObjComponent.h:33
void setShape(std::shared_ptr< const IObject > newShape)
Set a new shape on the component void setShape(std::shared_ptr<const IObject> newShape);.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
Class for 3D vectors.
Definition: V3D.h:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
A set of helper functions for dealing with components, i.e.
MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createVirtualInstrument(Kernel::V3D sourcePos, Kernel::V3D samplePos, const std::vector< Kernel::V3D > &vecdetpos, const std::vector< detid_t > &vecdetid)
MANTID_GEOMETRY_DLL std::shared_ptr< Geometry::CSGObject > createSphere(double radius, const Kernel::V3D &centre, const std::string &id)
Create a sphere object.
MANTID_GEOMETRY_DLL Geometry::Instrument_sptr createMinimalInstrument(const Mantid::Kernel::V3D &sourcePos, const Mantid::Kernel::V3D &samplePos, const Mantid::Kernel::V3D &detectorPos)
createOneDetectorInstrument, creates the most simple possible definition of an instrument in which we...
MANTID_GEOMETRY_DLL std::string sphereXML(double radius, const Kernel::V3D &centre, const std::string &id)
Return the XML for a sphere.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.