Skip to content
Snippets Groups Projects
InstrumentBuilder.h 3.94 KiB
Newer Older
#ifndef MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H
#define MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H
Owen Arnold's avatar
Owen Arnold committed
#include "MantidGeometry/IDTypes.h"
#include "MantidGeometry/Objects/IObject.h"
Lamar Moore's avatar
Lamar Moore committed
#include "MantidNexusGeometry/DllConfig.h"
#include "MantidNexusGeometry/TubeBuilder.h"
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <memory>
Lamar Moore's avatar
Lamar Moore committed
#include <string>
Owen Arnold's avatar
Owen Arnold committed
namespace Mantid {
namespace Geometry {
class Instrument;
class IComponent;
class ICompAssembly;
Owen Arnold's avatar
Owen Arnold committed
} // namespace Geometry
Owen Arnold's avatar
Owen Arnold committed
namespace NexusGeometry {
/** InstrumentBuilder : Builder for wrapping the creating of a Mantid
  Instrument. Provides some useful abstractions over the full-blown Instrument
  interface

  Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
  National Laboratory & European Spallation Source

  This file is part of Mantid.

  Mantid is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  Mantid is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

  File change history is stored at: <https://github.com/mantidproject/mantid>
  Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_NEXUSGEOMETRY_DLL InstrumentBuilder {
Owen Arnold's avatar
Owen Arnold committed
public:
  /// Constructor creates the instrument
  explicit InstrumentBuilder(const std::string &instrumentName);
Owen Arnold's avatar
Owen Arnold committed
  InstrumentBuilder(const InstrumentBuilder &) = delete;
  InstrumentBuilder &operator=(const InstrumentBuilder &) = delete;
Owen Arnold's avatar
Owen Arnold committed
  /// Adds component to instrument
Owen Arnold's avatar
Owen Arnold committed
  Geometry::IComponent *addComponent(const std::string &compName,
                                     const Eigen::Vector3d &position);
Lamar Moore's avatar
Lamar Moore committed
  /// Adds tubes (ObjComponentAssemblies) to the last registered bank
  void addTubes(const std::string &bankName,
                const std::vector<detail::TubeBuilder> &tubes,
                boost::shared_ptr<const Mantid::Geometry::IObject> pixelShape);
  /// Adds detector to the root (instrument)
  void addDetectorToInstrument(
Owen Arnold's avatar
Owen Arnold committed
      const std::string &detName, detid_t detId,
      const Eigen::Vector3d &position,
      boost::shared_ptr<const Mantid::Geometry::IObject> &shape);
  /// Adds detector to the last registered bank
  void addDetectorToLastBank(
Owen Arnold's avatar
Owen Arnold committed
      const std::string &detName, detid_t detId,
      const Eigen::Vector3d &relativeOffset,
      boost::shared_ptr<const Mantid::Geometry::IObject> shape);
Owen Arnold's avatar
Owen Arnold committed
  /// Adds detector to instrument
Owen Arnold's avatar
Owen Arnold committed
  void addMonitor(const std::string &detName, detid_t detId,
                  const Eigen::Vector3d &position,
                  boost::shared_ptr<const Mantid::Geometry::IObject> &shape);
Owen Arnold's avatar
Owen Arnold committed
  /// Add sample
Owen Arnold's avatar
Owen Arnold committed
  void addSample(const std::string &sampleName,
                 const Eigen::Vector3d &position);
Owen Arnold's avatar
Owen Arnold committed
  /// Add source
Owen Arnold's avatar
Owen Arnold committed
  void addSource(const std::string &sourceName,
                 const Eigen::Vector3d &position);

  void addBank(const std::string &localName, const Eigen::Vector3d &position,
               const Eigen::Quaterniond &rotation);

Owen Arnold's avatar
Owen Arnold committed
  /// Returns underlying instrument
  std::unique_ptr<const Geometry::Instrument> createInstrument();
Owen Arnold's avatar
Owen Arnold committed

private:
Lamar Moore's avatar
Lamar Moore committed
  /// Add a single tube to the last registed bank
  void doAddTube(const std::string &compName, const detail::TubeBuilder &tube,
                 boost::shared_ptr<const Mantid::Geometry::IObject> pixelShape);
  /// Sorts detectors
  void sortDetectors() const;
  /// product
  std::unique_ptr<Geometry::Instrument> m_instrument;
  /// Last bank added. The instrument is the owner of the bank.
  Geometry::ICompAssembly *m_lastBank = nullptr;
Owen Arnold's avatar
Owen Arnold committed
} // namespace NexusGeometry
} // namespace Mantid
#endif // MANTIDNEXUSGEOMETRY_INSTRUMENTBUILDER_H