Skip to content

Commit

Permalink
refs #9194. Refactor PeakBackground into separate physical location.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Mar 28, 2014
1 parent bc80092 commit 7102ddb
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 56 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Crystal/CMakeLists.txt
Expand Up @@ -32,6 +32,7 @@ set ( SRC_FILES
src/OptimizeCrystalPlacement.cpp
src/OptimizeExtinctionParameters.cpp
src/OptimizeLatticeForCellType.cpp
src/PeakBackground.cpp
src/PeakHKLErrors.cpp
src/PeakIntegration.cpp
src/PeakIntensityVsRadius.cpp
Expand Down Expand Up @@ -95,6 +96,7 @@ set ( INC_FILES
inc/MantidCrystal/OptimizeCrystalPlacement.h
inc/MantidCrystal/OptimizeExtinctionParameters.h
inc/MantidCrystal/OptimizeLatticeForCellType.h
inc/MantidCrystal/PeakBackground.h
inc/MantidCrystal/PeakHKLErrors.h
inc/MantidCrystal/PeakIntegration.h
inc/MantidCrystal/PeakIntensityVsRadius.h
Expand Down Expand Up @@ -153,6 +155,7 @@ set ( TEST_FILES
NormaliseVanadiumTest.h
OptimizeCrystalPlacementTest.h
OptimizeLatticeForCellTypeTest.h
PeakBackgroundTest.h
PeakHKLErrorsTest.h
PeakIntegrationTest.h
PeakIntensityVsRadiusTest.h
Expand Down
70 changes: 70 additions & 0 deletions Code/Mantid/Framework/Crystal/inc/MantidCrystal/PeakBackground.h
@@ -0,0 +1,70 @@
#ifndef MANTID_CRYSTAL_PEAKBACKGROUND_H_
#define MANTID_CRYSTAL_PEAKBACKGROUND_H_

#include "MantidKernel/System.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/IMDIterator.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidCrystal/HardThresholdBackground.h"



namespace Mantid
{
namespace Crystal
{

/** PeakBackground : Extension of HardThresholdBackground to consider regions of the image as background if they are outside
the peaks radius limits (no mater what their theshold is). For pixels inside the radius, they must also be above the threshold value.
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 PeakBackground : public HardThresholdBackground
{
private:

/// Peak workspace containing peaks of interest
Mantid::API::IPeaksWorkspace_const_sptr m_peaksWS;
/// Radius estimate
const double m_radiusEstimate;
/// MD coordinates to use
const Mantid::API::SpecialCoordinateSystem m_mdCoordinates;

public:
/// Constructor
PeakBackground(Mantid::API::IPeaksWorkspace_const_sptr peaksWS, const double& radiusEstimate, const double& thresholdSignal, const Mantid::API::MDNormalization normalisation, const Mantid::API::SpecialCoordinateSystem coordinates);

/// Overriden is background function
virtual bool isBackground(Mantid::API::IMDIterator* iterator) const;

/// Overriden configure iterator function.
virtual void configureIterator(Mantid::API::IMDIterator* const iterator) const;

/// Destructor
virtual ~PeakBackground();
};


} // namespace Crystal
} // namespace Mantid

#endif /* MANTID_CRYSTAL_PEAKBACKGROUND_H_ */
Expand Up @@ -6,7 +6,7 @@ Uses connected component analysis to integrate peaks in an PeaksWorkspace over a

#include "MantidCrystal/IntegratePeaksUsingClusters.h"
#include "MantidCrystal/ConnectedComponentLabeling.h"
#include "MantidCrystal/HardThresholdBackground.h"
#include "MantidCrystal/PeakBackground.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/IMDIterator.h"
Expand Down Expand Up @@ -46,61 +46,6 @@ namespace
const double m_thresholdDistance;
};

class PeakBackground : public Mantid::Crystal::HardThresholdBackground
{
private:

IPeaksWorkspace_const_sptr m_peaksWS;
const double m_radiusEstimate;
const SpecialCoordinateSystem m_mdCoordinates;

public:
PeakBackground(IPeaksWorkspace_const_sptr peaksWS, const double& radiusEstimate, const double& thresholdSignal, const Mantid::API::MDNormalization normalisation, const SpecialCoordinateSystem coordinates)
: Mantid::Crystal::HardThresholdBackground(thresholdSignal, normalisation), m_peaksWS(peaksWS), m_radiusEstimate(radiusEstimate), m_mdCoordinates(coordinates)
{
}

virtual bool isBackground(Mantid::API::IMDIterator* iterator) const
{
if(!HardThresholdBackground::isBackground(iterator) )
{
const VMD& center = iterator->getCenter();
V3D temp(center[0], center[1], center[2]); // This assumes dims 1, 2, and 3 in the workspace correspond to positions.

for(size_t i = 0; i < m_peaksWS->getNumberPeaks(); ++i)
{
V3D coords;
if(m_mdCoordinates==QLab)
{
coords= m_peaksWS->getPeak(i).getQLabFrame();
}
else if(m_mdCoordinates==QSample)
{
coords= m_peaksWS->getPeak(i).getQSampleFrame();
}
else if(m_mdCoordinates==Mantid::API::HKL)
{
coords= m_peaksWS->getPeak(i).getHKL();
}
if(coords.distance(temp) < m_radiusEstimate)
{
return false;
}

}

}
return true;
}

void configureIterator(Mantid::API::IMDIterator* const iterator) const
{
}

virtual ~PeakBackground()
{
}
};
}

namespace Mantid
Expand Down
68 changes: 68 additions & 0 deletions Code/Mantid/Framework/Crystal/src/PeakBackground.cpp
@@ -0,0 +1,68 @@
#include "MantidCrystal/PeakBackground.h"
#include "MantidAPI/IPeak.h"

using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::API::IPeak;

namespace Mantid
{
namespace Crystal
{


//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakBackground::PeakBackground(IPeaksWorkspace_const_sptr peaksWS, const double& radiusEstimate, const double& thresholdSignal, const Mantid::API::MDNormalization normalisation, const SpecialCoordinateSystem coordinates)
: HardThresholdBackground(thresholdSignal, normalisation), m_peaksWS(peaksWS), m_radiusEstimate(radiusEstimate), m_mdCoordinates(coordinates)
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
PeakBackground::~PeakBackground()
{
}


bool PeakBackground::isBackground(Mantid::API::IMDIterator* iterator) const
{
if(!HardThresholdBackground::isBackground(iterator) )
{
const VMD& center = iterator->getCenter();
V3D temp(center[0], center[1], center[2]); // This assumes dims 1, 2, and 3 in the workspace correspond to positions.

for(size_t i = 0; i < m_peaksWS->getNumberPeaks(); ++i)
{
V3D coords;
if(m_mdCoordinates==QLab)
{
coords= m_peaksWS->getPeak(i).getQLabFrame();
}
else if(m_mdCoordinates==QSample)
{
coords= m_peaksWS->getPeak(i).getQSampleFrame();
}
else if(m_mdCoordinates==Mantid::API::HKL)
{
coords= m_peaksWS->getPeak(i).getHKL();
}
if(coords.distance(temp) < m_radiusEstimate)
{
return false;
}

}

}
return true;
}

void PeakBackground::configureIterator(Mantid::API::IMDIterator* const ) const
{
}

} // namespace Crystal
} // namespace Mantid

0 comments on commit 7102ddb

Please sign in to comment.