Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A composite cluster will fix the problem I've been having. Namely that the clusters are processed in parallel to get the uniform min, but the order that they are processed in will affect the end labeling. If clusters are set up as composites before hand. This will not be a problem.
- Loading branch information
1 parent
ed5270c
commit 7561484
Showing
7 changed files
with
396 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Code/Mantid/Framework/Crystal/inc/MantidCrystal/CompositeCluster.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#ifndef MANTID_CRYSTAL_COMPOSITECLUSTER_H_ | ||
#define MANTID_CRYSTAL_COMPOSITECLUSTER_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidCrystal/ICluster.h" | ||
#include <boost/shared_ptr.hpp> | ||
#include <boost/optional.hpp> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
/** CompositeCluster : Cluster made by by merging other IClusters. | ||
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
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 DLLExport CompositeCluster: ICluster | ||
{ | ||
public: | ||
CompositeCluster(); | ||
virtual ~CompositeCluster(); | ||
|
||
/// integrate the cluster | ||
ICluster::ClusterIntegratedValues integrate( | ||
boost::shared_ptr<const Mantid::API::IMDHistoWorkspace> ws) const; | ||
|
||
/// Apply labels to the workspace | ||
void writeTo(boost::shared_ptr<Mantid::API::IMDHistoWorkspace> ws) const; | ||
|
||
/// Get the cluster label | ||
size_t getLabel() const; | ||
|
||
/// Number of indexes tracked | ||
size_t size() const; | ||
|
||
/// Track a linear IMDHistoWorkspace index that belongs to the cluster. | ||
void addIndex(const size_t& index); | ||
|
||
/// Resolve the proper label for this cluster. | ||
void toUniformMinimum(std::vector<DisjointElement>& disjointSet); | ||
|
||
/// Own. | ||
void add(boost::shared_ptr<ICluster>& toOwn); | ||
|
||
private: | ||
|
||
/// Disabled copy construction | ||
CompositeCluster(const CompositeCluster&); | ||
/// Disabled assignement | ||
CompositeCluster& operator=(const CompositeCluster&); | ||
|
||
/// Label used by cluster | ||
boost::optional<size_t> m_label; | ||
/// Attached clusters. | ||
std::vector<boost::shared_ptr<ICluster> > m_ownedClusters; | ||
|
||
}; | ||
|
||
} // namespace Crystal | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CRYSTAL_COMPOSITECLUSTER_H_ */ |
74 changes: 74 additions & 0 deletions
74
Code/Mantid/Framework/Crystal/inc/MantidCrystal/ICluster.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef MANTID_CRYSTAL_ICLUSTER_H_ | ||
#define MANTID_CRYSTAL_ICLUSTER_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidCrystal/DisjointElement.h" | ||
#include <vector> | ||
#include <boost/shared_ptr.hpp> | ||
#include <boost/tuple/tuple.hpp> | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
class IMDHistoWorkspace; | ||
} | ||
namespace Crystal | ||
{ | ||
|
||
/** ICluster : Abstract cluster. Identifies neighbour elements in an image that are connected. | ||
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
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 DLLExport ICluster | ||
{ | ||
public: | ||
|
||
typedef boost::tuple<double, double> ClusterIntegratedValues; | ||
|
||
/// integrate the cluster | ||
virtual ClusterIntegratedValues integrate( | ||
boost::shared_ptr<const Mantid::API::IMDHistoWorkspace> ws) const = 0; | ||
|
||
/// Apply labels to the workspace | ||
virtual void writeTo(boost::shared_ptr<Mantid::API::IMDHistoWorkspace> ws) const = 0; | ||
|
||
/// Get the cluster label | ||
virtual size_t getLabel() const = 0; | ||
|
||
/// Number of indexes tracked | ||
virtual size_t size() const = 0; | ||
|
||
/// Track a linear IMDHistoWorkspace index that belongs to the cluster. | ||
virtual void addIndex(const size_t& index) = 0; | ||
|
||
/// Resolve the proper label for this cluster. | ||
virtual void toUniformMinimum(std::vector<DisjointElement>& disjointSet) = 0; | ||
|
||
/// Virtual destructor | ||
virtual ~ICluster(){}; | ||
|
||
}; | ||
|
||
} // namespace Crystal | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CRYSTAL_ICLUSTER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "MantidCrystal/CompositeCluster.h" | ||
#include <stdexcept> | ||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
CompositeCluster::CompositeCluster() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
CompositeCluster::~CompositeCluster() | ||
{ | ||
} | ||
|
||
ICluster::ClusterIntegratedValues CompositeCluster::integrate( | ||
boost::shared_ptr<const Mantid::API::IMDHistoWorkspace> ws) const | ||
{ | ||
|
||
double errorIntSQ = 0; | ||
double sigInt = 0; | ||
// Integrate owned clusters and add those results too. | ||
for (size_t i = 0; i < m_ownedClusters.size(); ++i) | ||
{ | ||
auto integratedValues = m_ownedClusters[i]->integrate(ws); | ||
sigInt += integratedValues.get<0>(); | ||
errorIntSQ += integratedValues.get<1>(); | ||
} | ||
return ClusterIntegratedValues(sigInt, errorIntSQ); | ||
} | ||
|
||
void CompositeCluster::writeTo(boost::shared_ptr<Mantid::API::IMDHistoWorkspace> ws) const | ||
{ | ||
for (size_t i = 0; i < m_ownedClusters.size(); ++i) | ||
{ | ||
m_ownedClusters[i]->writeTo(ws); | ||
} | ||
} | ||
|
||
size_t CompositeCluster::getLabel() const | ||
{ | ||
if (!m_label.is_initialized()) | ||
{ | ||
throw std::runtime_error("No child IClusters. CompositeCluster::getLabel() is not supported."); | ||
} | ||
else | ||
{ | ||
return m_label.get(); // Assumes all are uniform. | ||
} | ||
} | ||
|
||
size_t CompositeCluster::size() const | ||
{ | ||
size_t size = 0; | ||
for (size_t i = 0; i < m_ownedClusters.size(); ++i) | ||
{ | ||
size += m_ownedClusters[i]->size(); | ||
} | ||
return size; | ||
} | ||
|
||
void CompositeCluster::addIndex(const size_t& index) | ||
{ | ||
throw std::runtime_error("addIndex not implemented on CompositeCluster"); | ||
} | ||
|
||
void CompositeCluster::toUniformMinimum(std::vector<DisjointElement>& disjointSet) | ||
{ | ||
if (!m_ownedClusters.empty()) | ||
{ | ||
ICluster* minCluster = m_ownedClusters.front().get(); | ||
size_t minLabel = minCluster->getLabel(); | ||
for (size_t i = 1; i < m_ownedClusters.size(); ++i) | ||
{ | ||
size_t temp = m_ownedClusters[i]->getLabel(); | ||
if (temp < minLabel) | ||
{ | ||
minLabel = temp; | ||
minCluster = m_ownedClusters[i].get(); | ||
} | ||
} | ||
m_label = minLabel; | ||
|
||
for (size_t i = 0; i < m_ownedClusters.size(); ++i) | ||
{ | ||
minCluster->setAsParentOn(m_ownedClusters[i].get());// TODO | ||
} | ||
} | ||
} | ||
|
||
void CompositeCluster::add(boost::shared_ptr<ICluster>& toOwn) | ||
{ | ||
m_ownedClusters.push_back(toOwn); | ||
} | ||
|
||
} // namespace Crystal | ||
} // namespace Mantid |
Oops, something went wrong.