Commit 5935d534 authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Some modifications to the PeaksWorkspace. Outputting Qx, Qy, and Qz to a...

Some modifications to the PeaksWorkspace. Outputting Qx, Qy, and Qz to a PeaksWorkspace from the instrument view. re #3173
parent 7d461bc5
......@@ -33,7 +33,9 @@ set ( SRC_FILES
src/IMDEventWorkspace.cpp
src/IMDIterator.cpp
src/IMDWorkspace.cpp
src/IPeak.cpp
src/IPeakFunction.cpp
src/IPeaksWorkspace.cpp
src/ITableWorkspace.cpp
src/ImplicitFunctionParameterParserFactory.cpp
src/ImplicitFunctionParserFactory.cpp
......@@ -128,7 +130,9 @@ set ( INC_FILES
inc/MantidAPI/IMDEventWorkspace.h
inc/MantidAPI/IMDIterator.h
inc/MantidAPI/IMDWorkspace.h
inc/MantidAPI/IPeak.h
inc/MantidAPI/IPeakFunction.h
inc/MantidAPI/IPeaksWorkspace.h
inc/MantidAPI/ITableWorkspace.h
inc/MantidAPI/IWorkspaceProperty.h
inc/MantidAPI/ImplicitFunction.h
......
#ifndef MANTID_API_IPEAK_H_
#define MANTID_API_IPEAK_H_
#include "MantidAPI/DllConfig.h"
#include "MantidGeometry/IInstrument.h"
#include "MantidGeometry/Math/Matrix.h"
#include "MantidGeometry/V3D.h"
#include "MantidKernel/PhysicalConstants.h"
//#include "MantidKernel/System.h"
namespace Mantid
{
namespace API
{
/** Structure describing a single-crystal peak
*
* @author Janik Zikovsky
* @date 2011-04-15 13:24:07.963491
*/
class MANTID_API_DLL IPeak
{
public:
virtual ~IPeak();
virtual void setInstrument(Mantid::Geometry::IInstrument_const_sptr inst) = 0;
virtual int getDetectorID() const = 0;
virtual void setDetectorID(int m_DetectorID) = 0;
virtual Mantid::Geometry::IDetector_const_sptr getDetector() const = 0;
virtual Mantid::Geometry::IInstrument_const_sptr getInstrument() const = 0;
virtual int getRunNumber() const = 0;
virtual void setRunNumber(int m_RunNumber) = 0;
virtual double getH() const = 0;
virtual double getK() const = 0;
virtual double getL() const = 0;
virtual Mantid::Geometry::V3D getHKL() = 0;
virtual void setH(double m_H) = 0;
virtual void setK(double m_K) = 0;
virtual void setL(double m_L) = 0;
virtual void setHKL(double H, double K, double L) = 0;
virtual void setHKL(Mantid::Geometry::V3D HKL) = 0;
virtual Mantid::Geometry::V3D getQLabFrame() const = 0;
virtual Mantid::Geometry::V3D getQSampleFrame() const = 0;
virtual void setQSampleFrame(Mantid::Geometry::V3D QSampleFrame, double detectorDistance=1.0) = 0;
virtual void setQLabFrame(Mantid::Geometry::V3D QLabFrame, double detectorDistance=1.0) = 0;
virtual void setWavelength(double wavelength) = 0;
virtual double getWavelength() const = 0;
virtual double getDSpacing() const = 0;
virtual double getTOF() const = 0;
virtual double getInitialEnergy() const = 0;
virtual double getFinalEnergy() const = 0;
virtual void setInitialEnergy(double m_InitialEnergy) = 0;
virtual void setFinalEnergy(double m_FinalEnergy) = 0;
virtual double getIntensity() const = 0;
virtual double getSigmaIntensity() const = 0;
virtual void setIntensity(double m_Intensity) = 0;
virtual void setSigmaIntensity(double m_SigmaIntensity) = 0;
virtual double getBinCount() const = 0;
virtual void setBinCount(double m_BinCount) = 0;
virtual Mantid::Geometry::Matrix<double> getGoniometerMatrix() const = 0;
virtual void setGoniometerMatrix(Mantid::Geometry::Matrix<double> m_GoniometerMatrix) = 0;
virtual std::string getBankName() const = 0;
virtual int getRow() const = 0;
virtual int getCol() const = 0;
virtual Mantid::Geometry::V3D getDetPos() const = 0;
virtual double getL1() const = 0;
virtual double getL2() const = 0;
};
} // namespace Mantid
} // namespace API
#endif /* MANTID_API_IPEAK_H_ */
#ifndef MANTID_API_IPEAKSPACE_H_
#define MANTID_API_IPEAKSPACE_H_ 1
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeak.h"
//IsamplePosition should be IsampleOrientation
namespace Mantid
{
namespace API
{
//==========================================================================================
/** @class Mantid::DataObjects::PeaksWorkspace
The class PeaksWorkspace stores information about a set of SCD peaks.
@author Ruth Mikkelson, SNS ORNL
@date 3/10/2010
Copyright &copy; 2010 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>
*/
class MANTID_API_DLL IPeaksWorkspace: public ITableWorkspace
{
public:
virtual ~IPeaksWorkspace();
//boost::shared_ptr<IPeaksWorkspace> clone() = 0;
//void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst) = 0;
/** Sets the default instrument for new peaks */
virtual void setInstrument(Mantid::Geometry::IInstrument_const_sptr inst) = 0;
/** Returns the default instrument for new peaks */
virtual Mantid::Geometry::IInstrument_const_sptr getInstrument() const = 0;
//---------------------------------------------------------------------------------------------
/** @return the number of peaks
*/
virtual int getNumberPeaks() const = 0;
//---------------------------------------------------------------------------------------------
/** Removes the indicated peak
* @param peakNum the peak to remove. peakNum starts at 0
*/
virtual void removePeak(const int peakNum) = 0;
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param peak :: Peak object to add (copy) into this.
*/
virtual void addPeak(const IPeak& ipeak) = 0;
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
virtual IPeak & getPeak(const int peakNum) = 0;
//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param QLabFrame :: Q of the center of the peak, in reciprocal space
* @param detectorDistance :: distance between the sample and the detector.
* @return a pointer to a new Peak object.
*/
virtual IPeak* createPeak(Mantid::Geometry::V3D QLabFrame, double detectorDistance=1.0) = 0;
};
/// Typedef for a shared pointer to a peaks workspace.
typedef boost::shared_ptr<IPeaksWorkspace> IPeaksWorkspace_sptr;
/// Typedef for a shared pointer to a const peaks workspace.
typedef boost::shared_ptr<const IPeaksWorkspace> IPeaksWorkspace_const_sptr;
}
}
#endif
......@@ -22,6 +22,7 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidGeometry/MDGeometry/MDGeometryDescription.h"
namespace Mantid
{
......@@ -79,6 +80,9 @@ public:
/// Create a ITableWorkspace
ITableWorkspace_sptr createTable(const std::string& className = "TableWorkspace") const;
/// Create a IPeaksWorkspace
IPeaksWorkspace_sptr createPeaks(const std::string& className = "PeaksWorkspace") const;
private:
friend struct Mantid::Kernel::CreateUsingNew<WorkspaceFactoryImpl>;
......
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IPeak.h"
namespace Mantid
{
namespace API
{
using namespace Kernel;
IPeak::~IPeak() {}
} //API namespace
} //Mantid namespace
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IPeaksWorkspace.h"
namespace Mantid
{
namespace API
{
using namespace Kernel;
IPeaksWorkspace::~IPeaksWorkspace() {}
} //API namespace
} //Mantid namespace
......@@ -232,6 +232,28 @@ ITableWorkspace_sptr WorkspaceFactoryImpl::createTable(const std::string& classN
return ws;
}
/// Create a IPeaksWorkspace
IPeaksWorkspace_sptr WorkspaceFactoryImpl::createPeaks(const std::string& className) const
{
IPeaksWorkspace_sptr ws;
try
{
ws = boost::dynamic_pointer_cast<IPeaksWorkspace>(this->create(className));
if (!ws)
{
//g_log.error("Class "+className+" cannot be cast to IPeaksWorkspace");
throw std::runtime_error("Class "+className+" cannot be cast to IPeaksWorkspace");
}
}
catch(Kernel::Exception::NotFoundError& e)
{
g_log.error(e.what());
throw;
}
return ws;
}
/// this create method is currently used to build MD workspaces from MD workspaces, but may be used to build MD workspaces from matrix workspaces in a future;
/*
IMDWorkspace_sptr
......
......@@ -223,11 +223,11 @@ namespace Crystal
lastStr = getWord( in , false );
// Find the detector ID from row/col
IInstrument_sptr inst = outWS->getInstrument();
IInstrument_const_sptr inst = outWS->getInstrument();
if (!inst) throw std::runtime_error("No instrument in PeaksWorkspace!");
IComponent_sptr bank = inst->getComponentByName(bankName);
IComponent_const_sptr bank = inst->getComponentByName(bankName);
if (!bank) throw std::runtime_error("Bank named " + bankName + " not found!");
RectangularDetector_sptr rect = boost::dynamic_pointer_cast<RectangularDetector>(bank);
RectangularDetector_const_sptr rect = boost::dynamic_pointer_cast<const RectangularDetector>(bank);
if (!rect) throw std::runtime_error("Bank named " + bankName + " is not a RectangularDetector!");
IDetector_sptr det = rect->getAtXY(int(col), int(row));
if (!det) throw std::runtime_error("Detector not found on " + bankName + "!");
......
......@@ -266,7 +266,7 @@ namespace Crystal
{
PARALLEL_START_INTERUPT_REGION
Peak & p = HKLPeaksWorkspace->getPeak(i);
IPeak & p = HKLPeaksWorkspace->getPeak(i);
doHKL(int(p.getH()), int(p.getK()), int(p.getL()));
PARALLEL_END_INTERUPT_REGION
......
......@@ -78,7 +78,7 @@ namespace Crystal
std::ofstream out( filename.c_str() );
IInstrument_sptr inst = ws->getInstrument();
IInstrument_const_sptr inst = ws->getInstrument();
double l1; V3D beamline; double beamline_norm; V3D samplePos;
inst->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);
......@@ -145,8 +145,7 @@ namespace Crystal
mess << "bank" << bank;
std::string bankName = mess.str();
// Retrieve it
RectangularDetector_sptr det;
det = boost::dynamic_pointer_cast<RectangularDetector>(inst->getComponentByName(bankName));
RectangularDetector_const_sptr det = boost::dynamic_pointer_cast<const RectangularDetector>(inst->getComponentByName(bankName));
if (det)
{
// Center of the detector
......
......@@ -4,6 +4,7 @@
#include "MantidDataHandling/DeleteTableRows.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidKernel/ArrayProperty.h"
#include <set>
......@@ -41,13 +42,22 @@ namespace Mantid
void DeleteTableRows::exec()
{
API::ITableWorkspace_sptr tw = getProperty("TableWorkspace");
API::IPeaksWorkspace_sptr pw = boost::dynamic_pointer_cast<API::IPeaksWorkspace>(tw);
std::vector<size_t> rows = getProperty("Rows");
// sort the row indices in reverse order
std::set<size_t,std::greater<size_t> > sortedRows(rows.begin(),rows.end());
std::set<size_t,std::greater<size_t> >::iterator it = sortedRows.begin();
for(; it != sortedRows.end(); ++it)
{
tw->removeRow(static_cast<int>(*it));
int i = static_cast<int>(*it);
if (pw)
{
pw->removePeak(i);
}
else
{
tw->removeRow(i);
}
}
setProperty("TableWorkspace",tw);
}
......
#ifndef MANTID_DATAOBJECTS_PEAK_H_
#define MANTID_DATAOBJECTS_PEAK_H_
#include "MantidAPI/IPeak.h"
#include "MantidGeometry/IInstrument.h"
#include "MantidGeometry/Math/Matrix.h"
#include "MantidGeometry/V3D.h"
......@@ -18,28 +19,29 @@ namespace DataObjects
* @author Janik Zikovsky
* @date 2011-04-15 13:24:07.963491
*/
class DLLExport Peak
class DLLExport Peak: public API::IPeak
{
public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
Peak(Mantid::Geometry::IInstrument_sptr m_inst, Mantid::Geometry::V3D QSampleFrame, double detectorDistance=1.0);
Peak(Mantid::Geometry::IInstrument_sptr m_inst, Mantid::Geometry::V3D QSampleFrame, Mantid::Geometry::Matrix<double> goniometer, double detectorDistance=1.0);
Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength);
Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL);
Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL, Mantid::Geometry::Matrix<double> goniometer);
Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, Mantid::Geometry::V3D QSampleFrame, double detectorDistance=1.0);
Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, Mantid::Geometry::V3D QSampleFrame, Mantid::Geometry::Matrix<double> goniometer, double detectorDistance=1.0);
Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength);
Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL);
Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL, Mantid::Geometry::Matrix<double> goniometer);
// Copy constructor is compiler-provided.
// Peak(const Peak & other);
Peak(const API::IPeak & ipeak);
virtual ~Peak();
void setInstrument(Mantid::Geometry::IInstrument_sptr inst);
void setInstrument(Mantid::Geometry::IInstrument_const_sptr inst);
int getDetectorID() const;
void setDetectorID(int m_DetectorID);
Mantid::Geometry::IDetector_sptr getDetector() const;
Mantid::Geometry::IInstrument_sptr getInstrument() const;
Mantid::Geometry::IDetector_const_sptr getDetector() const;
Mantid::Geometry::IInstrument_const_sptr getInstrument() const;
int getRunNumber() const;
void setRunNumber(int m_RunNumber);
......@@ -92,10 +94,10 @@ namespace DataObjects
protected:
/// Shared pointer to the instrument (for calculating some values )
Mantid::Geometry::IInstrument_sptr m_inst;
Mantid::Geometry::IInstrument_const_sptr m_inst;
/// Detector pointed to
Mantid::Geometry::IDetector_sptr m_det;
Mantid::Geometry::IDetector_const_sptr m_det;
/// Name of the parent bank
std::string m_BankName;
......
......@@ -4,7 +4,7 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/Column.h"
#include "MantidDataObjects/TableWorkspace.h"
......@@ -31,6 +31,8 @@ namespace Kernel
class Logger;
}
using namespace API;
namespace DataObjects
{
//==========================================================================================
......@@ -60,7 +62,7 @@ namespace DataObjects
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
*/
class DLLExport PeaksWorkspace: public Mantid::API::ITableWorkspace
class DLLExport PeaksWorkspace: public Mantid::API::IPeaksWorkspace
{
public:
......@@ -77,11 +79,11 @@ namespace DataObjects
void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst);
/** Sets the default instrument for new peaks */
void setInstrument(Mantid::Geometry::IInstrument_sptr inst)
void setInstrument(Mantid::Geometry::IInstrument_const_sptr inst)
{ m_defaultInst = inst; }
/** Returns the default instrument for new peaks */
Mantid::Geometry::IInstrument_sptr getInstrument()
Mantid::Geometry::IInstrument_const_sptr getInstrument() const
{ return m_defaultInst; }
//---------------------------------------------------------------------------------------------
......@@ -106,9 +108,9 @@ namespace DataObjects
/** Add a peak to the list
* @param peak :: Peak object to add (copy) into this.
*/
void addPeak(const Peak peak)
void addPeak(const IPeak& ipeak)
{
peaks.push_back(peak);
peaks.push_back(Peak(ipeak));
}
//---------------------------------------------------------------------------------------------
......@@ -116,12 +118,23 @@ namespace DataObjects
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
Peak & getPeak(const int peakNum)
IPeak & getPeak(const int peakNum)
{
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0 ) throw std::invalid_argument("PeaksWorkspace::getPeak(): peakNum is out of range.");
return peaks[peakNum];
}
//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param QLabFrame :: Q of the center of the peak, in reciprocal space
* @param detectorDistance :: distance between the sample and the detector.
* @return a pointer to a new Peak object.
*/
IPeak* createPeak(Mantid::Geometry::V3D QLabFrame, double detectorDistance=1.0)
{
return new Peak(getInstrument(),QLabFrame,detectorDistance);
}
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
std::vector<Peak> & getPeaks()
......@@ -176,7 +189,7 @@ namespace DataObjects
std::vector<Peak> peaks;
/// Default instrument for new peaks
Mantid::Geometry::IInstrument_sptr m_defaultInst;
Mantid::Geometry::IInstrument_const_sptr m_defaultInst;
/** Column shared pointers. */
std::vector<boost::shared_ptr<Mantid::DataObjects::PeakColumn> > columns;
......
......@@ -21,7 +21,7 @@ namespace DataObjects
* @param detectorDistance :: distance between the sample and the detector.
* Used to give a valid TOF. Default 1.0 meters.
*/
Peak::Peak(Mantid::Geometry::IInstrument_sptr m_inst, Mantid::Geometry::V3D QLabFrame, double detectorDistance)
Peak::Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, Mantid::Geometry::V3D QLabFrame, double detectorDistance)
: m_H(0), m_K(0), m_L(0),
m_Intensity(0), m_SigmaIntensity(0), m_BinCount(0),
m_GoniometerMatrix(3,3,true),
......@@ -44,7 +44,7 @@ namespace DataObjects
* @param detectorDistance :: distance between the sample and the detector.
* Used to give a valid TOF. Default 1.0 meters.
*/
Peak::Peak(Mantid::Geometry::IInstrument_sptr m_inst, Mantid::Geometry::V3D QSampleFrame,
Peak::Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, Mantid::Geometry::V3D QSampleFrame,
Mantid::Geometry::Matrix<double> goniometer, double detectorDistance)
: m_H(0), m_K(0), m_L(0),
m_Intensity(0), m_SigmaIntensity(0), m_BinCount(0),
......@@ -67,7 +67,7 @@ namespace DataObjects
* @param m_Wavelength :: incident neutron wavelength, in Angstroms
* @return
*/
Peak::Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength)
Peak::Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength)
: m_H(0), m_K(0), m_L(0),
m_Intensity(0), m_SigmaIntensity(0), m_BinCount(0),
m_GoniometerMatrix(3,3,true),
......@@ -89,7 +89,7 @@ namespace DataObjects
* @param HKL :: vector with H,K,L position of the peak
* @return
*/
Peak::Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL)
Peak::Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL)
: m_H(HKL[0]), m_K(HKL[1]), m_L(HKL[2]),
m_Intensity(0), m_SigmaIntensity(0), m_BinCount(0),
m_GoniometerMatrix(3,3,true),
......@@ -111,7 +111,7 @@ namespace DataObjects
* @param goniometer :: a 3x3 rotation matrix
* @return
*/
Peak::Peak(Mantid::Geometry::IInstrument_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL, Mantid::Geometry::Matrix<double> goniometer) :
Peak::Peak(Mantid::Geometry::IInstrument_const_sptr m_inst, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL, Mantid::Geometry::Matrix<double> goniometer) :
m_H(HKL[0]), m_K(HKL[1]), m_L(HKL[2]),
m_Intensity(0), m_SigmaIntensity(0), m_BinCount(0),
m_GoniometerMatrix(goniometer),
......@@ -124,7 +124,29 @@ namespace DataObjects
this->setWavelength(m_Wavelength);
}
//----------------------------------------------------------------------------------------------
/** Constructor making a Peak from IPeak interface
*
* @param ipeak :: const reference to an IPeak object
* @return
*/
Peak::Peak(const API::IPeak & ipeak):
m_H(ipeak.getH()),
m_K(ipeak.getK()),
m_L(ipeak.getL()),
m_Intensity(ipeak.getIntensity()),
m_SigmaIntensity(ipeak.getSigmaIntensity()),
m_BinCount(ipeak.getBinCount()),
m_InitialEnergy(ipeak.getInitialEnergy()),
m_FinalEnergy(ipeak.getFinalEnergy()),