Skip to content

Commit

Permalink
refs #9115. Implement ConnectedComponentsLabelling with 1d tests.
Browse files Browse the repository at this point in the history
Implement simple testing for connected component labelling.
  • Loading branch information
OwenArnold committed Mar 13, 2014
1 parent 8da661a commit 7228a39
Show file tree
Hide file tree
Showing 18 changed files with 625 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDIterator.h
Expand Up @@ -113,6 +113,9 @@ class IMDWorkspace;
/// Returns true if masking is used.
virtual bool getIsMasked() const = 0;

/// Find neighbouring indexes.
virtual std::vector<size_t> findNeighbourIndexes() const = 0;

protected:
/// Normalization method for getNormalizedSignal()
Mantid::API::MDNormalization m_normalization;
Expand Down
Expand Up @@ -81,6 +81,8 @@ namespace API

virtual bool getIsMasked() const;

virtual std::vector<size_t> findNeighbourIndexes() const;

private:
void calcWorkspacePos(size_t newWI);

Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspaceMDIterator.cpp
Expand Up @@ -302,6 +302,15 @@ namespace API
}
}

/**
* Find neighbour indexes
* @return Neighbour indexes to the current index.
*/
std::vector<size_t> MatrixWorkspaceMDIterator::findNeighbourIndexes() const
{
throw std::runtime_error("MatrixWorkspaceMDIterator does not implement findNeighbourIndexes");
}


} // namespace Mantid
} // namespace API
13 changes: 10 additions & 3 deletions Code/Mantid/Framework/Crystal/CMakeLists.txt
Expand Up @@ -5,16 +5,18 @@ set ( SRC_FILES
src/CalculateUMatrix.cpp
src/CentroidPeaks.cpp
src/ClearUB.cpp
src/DisjointElement.cpp
src/CombinePeaksWorkspaces.cpp
src/ConnectedComponentLabelling.cpp
src/DiffPeaksWorkspaces.cpp
src/DisjointElement.cpp
src/FilterPeaks.cpp
src/FindSXPeaks.cpp
src/FindUBUsingFFT.cpp
src/FindUBUsingIndexedPeaks.cpp
src/FindUBUsingLatticeParameters.cpp
src/FindUBUsingMinMaxD.cpp
src/GoniometerAnglesFromPhiRotation.cpp
src/HardThresholdBackground.cpp
src/HasUB.cpp
src/IndexPeaks.cpp
src/IndexSXPeaks.cpp
Expand Down Expand Up @@ -58,13 +60,15 @@ set ( SRC_FILES
set ( SRC_UNITY_IGNORE_FILES )
set ( INC_FILES
inc/MantidCrystal/AnvredCorrection.h
inc/MantidCrystal/BackgroundStrategy.h
inc/MantidCrystal/CalculatePeaksHKL.h
inc/MantidCrystal/CalculateUMatrix.h
inc/MantidCrystal/CentroidPeaks.h
inc/MantidCrystal/ClearUB.h
inc/MantidCrystal/DisjointElement.h
inc/MantidCrystal/CombinePeaksWorkspaces.h
inc/MantidCrystal/ConnectedComponentLabelling.h
inc/MantidCrystal/DiffPeaksWorkspaces.h
inc/MantidCrystal/DisjointElement.h
inc/MantidCrystal/FilterPeaks.h
inc/MantidCrystal/FindSXPeaks.h
inc/MantidCrystal/FindUBUsingFFT.h
Expand All @@ -73,6 +77,7 @@ set ( INC_FILES
inc/MantidCrystal/FindUBUsingMinMaxD.h
inc/MantidCrystal/GSLFunctions.h
inc/MantidCrystal/GoniometerAnglesFromPhiRotation.h
inc/MantidCrystal/HardThresholdBackground.h
inc/MantidCrystal/HasUB.h
inc/MantidCrystal/IndexPeaks.h
inc/MantidCrystal/IndexSXPeaks.h
Expand Down Expand Up @@ -119,16 +124,18 @@ set ( TEST_FILES
CalculateUMatrixTest.h
CentroidPeaksTest.h
ClearUBTest.h
DisjointElementTest.h
CombinePeaksWorkspacesTest.h
ConnectedComponentLabellingTest.h
DiffPeaksWorkspacesTest.h
DisjointElementTest.h
FilterPeaksTest.h
FindSXPeaksTest.h
FindUBUsingFFTTest.h
FindUBUsingIndexedPeaksTest.h
FindUBUsingLatticeParametersTest.h
FindUBUsingMinMaxDTest.h
GoniometerAnglesFromPhiRotationTest.h
HardThresholdBackgroundTest.h
HasUBTest.h
IndexPeaksTest.h
IndexSXPeaksTest.h
Expand Down
@@ -0,0 +1,45 @@
#ifndef BACKGROUNDSTRATEGY_H_
#define BACKGROUNDSTRATEGY_H_

namespace Mantid
{
namespace API
{
class IMDIterator;
}
namespace Crystal
{
/** BackgroundStrategy : Abstract class used for identifying elements of a IMDWorkspace that are not considered background.
Copyright &copy; 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 BackgroundStrategy
{
public:
virtual bool isBackground(Mantid::API::IMDIterator* const iterator) const = 0;
virtual void configureIterator(Mantid::API::IMDIterator* const iterator) const = 0;
virtual ~BackgroundStrategy()
{
}
};
}
}
#endif /* BACKGROUNDSTRATEGY_H_ */
@@ -0,0 +1,52 @@
#ifndef MANTID_CRYSTAL_CONNECTEDCOMPONENTLABELLING_H_
#define MANTID_CRYSTAL_CONNECTEDCOMPONENTLABELLING_H_

#include "MantidKernel/System.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include <boost/shared_ptr.hpp>

namespace Mantid
{
namespace Crystal
{
class BackgroundStrategy;

/** ConnectedComponentLabelling : Implements connected component labeling on MDHistoWorkspaces.
Copyright &copy; 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 ConnectedComponentLabelling
{
public:
ConnectedComponentLabelling();
void startLabellingId(const size_t& id);
boost::shared_ptr<Mantid::API::IMDHistoWorkspace> execute(Mantid::API::IMDHistoWorkspace_sptr ws, BackgroundStrategy * const strategy) const;
virtual ~ConnectedComponentLabelling();
private:
size_t m_startId;

};


} // namespace Crystal
} // namespace Mantid

#endif /* MANTID_CRYSTAL_CONNECTEDCOMPONENTLABELLING_H_ */
Expand Up @@ -33,6 +33,8 @@ namespace Crystal
class DLLExport DisjointElement
{
public:
/// Default constructor
DisjointElement();
/// Constructor
DisjointElement(const int id);
/// Destructor
Expand All @@ -49,11 +51,13 @@ namespace Crystal
int getRank() const;
/// Increment the rank
int incrementRank();
private:
// Disabled copy and assignment.
/// Is empty.
bool isEmpty() const;
/// Copy constructor.
DisjointElement(const DisjointElement& other);
/// Assignment operator.
DisjointElement& operator=(const DisjointElement& other);

private:
bool hasParent() const;
int compress();
void setParent(DisjointElement * other);
Expand All @@ -64,7 +68,7 @@ namespace Crystal
/// Current rank
int m_rank;
/// Identifier
const int m_id;
int m_id;

};

Expand Down
@@ -0,0 +1,53 @@
#ifndef MANTID_CRYSTAL_HARDTHRESHOLDBACKGROUND_H_
#define MANTID_CRYSTAL_HARDTHRESHOLDBACKGROUND_H_

#include "MantidKernel/System.h"
#include "MantidCrystal/BackgroundStrategy.h"
#include "MantidAPI/IMDWorkspace.h"

namespace Mantid
{
namespace Crystal
{

/** HardThresholdBackground : Implementation of BackgroundStrategy using a fixed background signal value as the threshold.
Copyright &copy; 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 HardThresholdBackground : public BackgroundStrategy
{
public:
HardThresholdBackground(const double thresholdSignal, const Mantid::API::MDNormalization normalisation);
virtual bool isBackground(Mantid::API::IMDIterator* iterator) const;
void configureIterator(Mantid::API::IMDIterator* const iterator) const;
virtual ~HardThresholdBackground();
private:
/// Cutoff
const double m_thresholdSignal;
/// Normalization
const Mantid::API::MDNormalization m_normalization;
};


} // namespace Crystal
} // namespace Mantid

#endif /* MANTID_CRYSTAL_HARDTHRESHOLDBACKGROUND_H_ */

0 comments on commit 7228a39

Please sign in to comment.