Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Sample.h 4.77 KiB
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

//-----------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidGeometry/Objects/CSGObject.h"
#include "MantidKernel/V3D.h"

namespace Mantid {
//-----------------------------------------------------------------------------
// Geometry forward declarations
//------------------------------------------------------------------------------
namespace Geometry {
class CrystalStructure;
class OrientedLattice;
class SampleEnvironment;
} // namespace Geometry

namespace API {

/**
  This class stores information about the sample used in particular
  run. It is a type of ObjComponent meaning it has a shape, a position
  and a material.
*/
class MANTID_API_DLL Sample {
public:
  Sample();
  Sample(const Sample &copy);
  ~Sample();
  Sample &operator=(const Sample &rhs);

  void saveNexus(::NeXus::File *file, const std::string &group) const;
  int loadNexus(::NeXus::File *file, const std::string &group);

  /// index operator for accessing multiple samples
  Sample &operator[](const int index);
  /// the number of samples
  std::size_t size() const;
  /// Adds a sample to the list
  void addSample(const boost::shared_ptr<Sample> &childSample);

  /// Returns the name of the sample
  const std::string &getName() const;
  /// Set the name of the sample
  void setName(const std::string &name);
  /// Return the sample shape
  const Geometry::IObject &getShape() const;
  /// Update the shape of the object
  void setShape(const Geometry::IObject_sptr &shape);

  /** @name Material properties.*/
  //@{
  /// Return the material (convenience method)
  const Kernel::Material &getMaterial() const;
  //@}

  /** @name Access the environment information */
  //@{
  bool hasEnvironment() const;
  /// Get a reference to the sample's environment
  const Geometry::SampleEnvironment &getEnvironment() const;
  /// Set the environment used to contain the sample
  void setEnvironment(std::unique_ptr<Geometry::SampleEnvironment> env);
  //@}

  /** @name Access the sample's lattice structure and orientation */
  //@{
  /// Get a reference to the sample's OrientedLattice
  const Geometry::OrientedLattice &getOrientedLattice() const;
  /// Get a reference to the sample's OrientedLattice
  Geometry::OrientedLattice &getOrientedLattice();
  /// Set the pointer to OrientedLattice defining the sample's lattice and
  /// orientation
  void setOrientedLattice(std::unique_ptr<Geometry::OrientedLattice> lattice);
  bool hasOrientedLattice() const;
  //@}

  /** @name Access the sample's crystal structure */
  //@{
  const Geometry::CrystalStructure &getCrystalStructure() const;
  void
  setCrystalStructure(const Geometry::CrystalStructure &newCrystalStructure);
  bool hasCrystalStructure() const;
  void clearCrystalStructure();
  //@}

  // Required for SANS work until we define a proper
  // sample object from the raw file information
  /**@name Legacy functions */
  //@{
  /// Sets the geometry flag
  void setGeometryFlag(int geom_id);
  /// Returns the geometry flag
  int getGeometryFlag() const;
  /// Sets the thickness
  void setThickness(double thick);
  /// Returns the thickness
  double getThickness() const;
  /// Sets the height
  void setHeight(double height);
  /// Returns the height
  double getHeight() const;
  /// Sets the width
  void setWidth(double width);
  /// Returns the width
  double getWidth() const;
  //@}
  /// Delete the oriented lattice
  void clearOrientedLattice();

  bool operator==(const Sample &other) const;
  bool operator!=(const Sample &other) const;

private:
  /// The sample name
  std::string m_name;
  /// The sample shape object
  Geometry::IObject_sptr m_shape;
  /// An owned pointer to the SampleEnvironment object
  boost::shared_ptr<Geometry::SampleEnvironment> m_environment;
  /// Pointer to the OrientedLattice of the sample, NULL if not set.
  std::unique_ptr<Geometry::OrientedLattice> m_lattice;

  /// CrystalStructure of the sample
  std::unique_ptr<Geometry::CrystalStructure> m_crystalStructure;

  /// Vector of child samples
  std::vector<boost::shared_ptr<Sample>> m_samples;

  /// The sample geometry flag
  int m_geom_id;
  /// The sample thickness from the SPB_STRUCT in the raw file
  double m_thick;
  /// The sample height from the SPB_STRUCT in the raw file
  double m_height;
  /// The sample width from the SPB_STRUCT in the raw file
  double m_width;
};

} // namespace API
} // namespace Mantid