Mantid
Loading...
Searching...
No Matches
Cluster.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 +
9
10namespace {
11using VecElements = std::vector<Mantid::Crystal::DisjointElement>;
12}
13
14namespace Mantid::Crystal {
15
20Cluster::Cluster(const size_t &label) : m_originalLabel(label), m_rootCluster(this) { m_indexes.reserve(1000); }
21
26size_t Cluster::getLabel() const {
27 if (m_rootCluster != this) {
28 return m_rootCluster->getLabel();
29 }
30
31 return m_originalLabel;
32}
33
39
45size_t Cluster::size() const { return m_indexes.size(); }
46
51void Cluster::addIndex(const size_t &index) { m_indexes.emplace_back(index); }
52
58 const size_t label = this->getLabel();
59 for (auto index : m_indexes) {
60 ws->setSignalAt(index, static_cast<Mantid::signal_t>(label));
61 ws->setErrorSquaredAt(index, 0);
62 }
63}
64
71 double errorIntSQ = 0;
72 double sigInt = 0;
73 // Integrate accross indexes owned by this workspace.
74 for (auto index : m_indexes) {
75 sigInt += ws->getSignalAt(index);
76 double errorSQ = ws->getErrorAt(index);
77 errorSQ *= errorSQ;
78 errorIntSQ += errorSQ;
79 }
80 return ClusterIntegratedValues(sigInt, errorIntSQ);
81}
82
88 if (!m_indexes.empty()) {
89 size_t parentIndex = m_rootCluster->getRepresentitiveIndex();
90
91 for (size_t i = 1; i < m_indexes.size(); ++i) {
92 disjointSet[m_indexes[i]].unionWith(disjointSet[parentIndex].getParent());
93 }
94 }
95}
96
101size_t Cluster::getRepresentitiveIndex() const { return m_indexes.front(); }
102
107void Cluster::setRootCluster(ICluster const *root) { m_rootCluster = root; }
108
114bool Cluster::operator==(const Cluster &other) const { return getLabel() == other.getLabel(); }
115
121bool Cluster::containsLabel(const size_t &label) const { return (label == this->getLabel()); }
122
123} // namespace Mantid::Crystal
Cluster : Image cluster used by connected component labeling.
Definition: Cluster.h:22
void addIndex(const size_t &index) override
Track a linear IMDHistoWorkspace index that belongs to the cluster.
Definition: Cluster.cpp:51
Cluster(const size_t &label)
Constructor.
Definition: Cluster.cpp:20
bool containsLabel(const size_t &label) const override
Does the cluster contain the label.
Definition: Cluster.cpp:121
size_t getRepresentitiveIndex() const override
Get a representative index of the cluster.
Definition: Cluster.cpp:101
size_t m_originalLabel
original label on cluster
Definition: Cluster.h:67
bool operator==(const Cluster &other) const
Overloaded equals.
Definition: Cluster.cpp:114
std::vector< size_t > m_indexes
indexes belonging to cluster. This is how we track cluster objects.
Definition: Cluster.h:69
size_t getOriginalLabel() const override
Get the original label.
Definition: Cluster.cpp:38
void toUniformMinimum(std::vector< DisjointElement > &disjointSet) override
Resolve the proper label for this cluster.
Definition: Cluster.cpp:87
size_t size() const override
Number of indexes tracked.
Definition: Cluster.cpp:45
size_t getLabel() const override
Get the cluster label.
Definition: Cluster.cpp:26
void setRootCluster(ICluster const *root) override
Set the root cluster.
Definition: Cluster.cpp:107
ICluster const * m_rootCluster
Root cluster.
Definition: Cluster.h:71
ClusterIntegratedValues integrate(std::shared_ptr< const Mantid::API::IMDHistoWorkspace > ws) const override
integrate the cluster
Definition: Cluster.cpp:70
void writeTo(std::shared_ptr< Mantid::API::IMDHistoWorkspace > ws) const override
Apply labels to the workspace.
Definition: Cluster.cpp:57
ICluster : Abstract cluster.
Definition: ICluster.h:25
virtual size_t getLabel() const =0
Get the cluster label.
boost::tuple< double, double > ClusterIntegratedValues
Definition: ICluster.h:27
virtual size_t getRepresentitiveIndex() const =0
Get a represetiative index of the cluster.
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
std::shared_ptr< const IMDHistoWorkspace > IMDHistoWorkspace_const_sptr
shared pointer to Mantid::API::IMDHistoWorkspace (const version)
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Definition: MDTypes.h:36
Peak indexing algorithm, which works by assigning multiple possible HKL values to each peak and then ...
Definition: IndexSXPeaks.h:29