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 ...@@ -33,7 +33,9 @@ set ( SRC_FILES
src/IMDEventWorkspace.cpp src/IMDEventWorkspace.cpp
src/IMDIterator.cpp src/IMDIterator.cpp
src/IMDWorkspace.cpp src/IMDWorkspace.cpp
src/IPeak.cpp
src/IPeakFunction.cpp src/IPeakFunction.cpp
src/IPeaksWorkspace.cpp
src/ITableWorkspace.cpp src/ITableWorkspace.cpp
src/ImplicitFunctionParameterParserFactory.cpp src/ImplicitFunctionParameterParserFactory.cpp
src/ImplicitFunctionParserFactory.cpp src/ImplicitFunctionParserFactory.cpp
...@@ -128,7 +130,9 @@ set ( INC_FILES ...@@ -128,7 +130,9 @@ set ( INC_FILES
inc/MantidAPI/IMDEventWorkspace.h inc/MantidAPI/IMDEventWorkspace.h
inc/MantidAPI/IMDIterator.h inc/MantidAPI/IMDIterator.h
inc/MantidAPI/IMDWorkspace.h inc/MantidAPI/IMDWorkspace.h
inc/MantidAPI/IPeak.h
inc/MantidAPI/IPeakFunction.h inc/MantidAPI/IPeakFunction.h
inc/MantidAPI/IPeaksWorkspace.h
inc/MantidAPI/ITableWorkspace.h inc/MantidAPI/ITableWorkspace.h
inc/MantidAPI/IWorkspaceProperty.h inc/MantidAPI/IWorkspaceProperty.h
inc/MantidAPI/ImplicitFunction.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 @@ ...@@ -22,6 +22,7 @@
#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/IMDWorkspace.h" #include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidGeometry/MDGeometry/MDGeometryDescription.h" #include "MantidGeometry/MDGeometry/MDGeometryDescription.h"
namespace Mantid namespace Mantid
{ {
...@@ -79,6 +80,9 @@ public: ...@@ -79,6 +80,9 @@ public:
/// Create a ITableWorkspace /// Create a ITableWorkspace
ITableWorkspace_sptr createTable(const std::string& className = "TableWorkspace") const; ITableWorkspace_sptr createTable(const std::string& className = "TableWorkspace") const;
/// Create a IPeaksWorkspace
IPeaksWorkspace_sptr createPeaks(const std::string& className = "PeaksWorkspace") const;
private: private:
friend struct Mantid::Kernel::CreateUsingNew<WorkspaceFactoryImpl>; 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 ...@@ -232,6 +232,28 @@ ITableWorkspace_sptr WorkspaceFactoryImpl::createTable(const std::string& classN
return ws; 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; /// 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 IMDWorkspace_sptr
......
...@@ -223,11 +223,11 @@ namespace Crystal ...@@ -223,11 +223,11 @@ namespace Crystal
lastStr = getWord( in , false ); lastStr = getWord( in , false );
// Find the detector ID from row/col // 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!"); 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!"); 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!"); if (!rect) throw std::runtime_error("Bank named " + bankName + " is not a RectangularDetector!");
IDetector_sptr det = rect->getAtXY(int(col), int(row)); IDetector_sptr det = rect->getAtXY(int(col), int(row));
if (!det) throw std::runtime_error("Detector not found on " + bankName + "!"); if (!det) throw std::runtime_error("Detector not found on " + bankName + "!");
......
...@@ -266,7 +266,7 @@ namespace Crystal ...@@ -266,7 +266,7 @@ namespace Crystal
{ {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
Peak & p = HKLPeaksWorkspace->getPeak(i); IPeak & p = HKLPeaksWorkspace->getPeak(i);
doHKL(int(p.getH()), int(p.getK()), int(p.getL())); doHKL(int(p.getH()), int(p.getK()), int(p.getL()));
PARALLEL_END_INTERUPT_REGION PARALLEL_END_INTERUPT_REGION
......
...@@ -78,7 +78,7 @@ namespace Crystal ...@@ -78,7 +78,7 @@ namespace Crystal
std::ofstream out( filename.c_str() ); 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; double l1; V3D beamline; double beamline_norm; V3D samplePos;
inst->getInstrumentParameters(l1, beamline, beamline_norm, samplePos); inst->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);
...@@ -145,8 +145,7 @@ namespace Crystal ...@@ -145,8 +145,7 @@ namespace Crystal
mess << "bank" << bank; mess << "bank" << bank;
std::string bankName = mess.str(); std::string bankName = mess.str();
// Retrieve it // Retrieve it
RectangularDetector_sptr det; RectangularDetector_const_sptr det = boost::dynamic_pointer_cast<const RectangularDetector>(inst->getComponentByName(bankName));
det = boost::dynamic_pointer_cast<RectangularDetector>(inst->getComponentByName(bankName));
if (det) if (det)
{ {
// Center of the detector // Center of the detector
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "MantidDataHandling/DeleteTableRows.h" #include "MantidDataHandling/DeleteTableRows.h"
#include "MantidAPI/IWorkspaceProperty.h" #include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ArrayProperty.h"
#include <set> #include <set>
...@@ -41,13 +42,22 @@ namespace Mantid ...@@ -41,13 +42,22 @@ namespace Mantid
void DeleteTableRows::exec() void DeleteTableRows::exec()
{ {
API::ITableWorkspace_sptr tw = getProperty("TableWorkspace"); API::ITableWorkspace_sptr tw = getProperty("TableWorkspace");
API::IPeaksWorkspace_sptr pw = boost::dynamic_pointer_cast<API::IPeaksWorkspace>(tw);
std::vector<size_t> rows = getProperty("Rows"); std::vector<size_t> rows = getProperty("Rows");
// sort the row indices in reverse order // 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> > sortedRows(rows.begin(),rows.end());
std::set<size_t,std::greater<size_t> >::iterator it = sortedRows.begin(); std::set<size_t,std::greater<size_t> >::iterator it = sortedRows.begin();
for(; it != sortedRows.end(); ++it) 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); setProperty("TableWorkspace",tw);
} }
......
#ifndef MANTID_DATAOBJECTS_PEAK_H_ #ifndef MANTID_DATAOBJECTS_PEAK_H_
#define MANTID_DATAOBJECTS_PEAK_H_ #define MANTID_DATAOBJECTS_PEAK_H_
#include "MantidAPI/IPeak.h"
#include "MantidGeometry/IInstrument.h" #include "MantidGeometry/IInstrument.h"
#include "MantidGeometry/Math/Matrix.h" #include "MantidGeometry/Math/Matrix.h"
#include "MantidGeometry/V3D.h" #include "MantidGeometry/V3D.h"
...@@ -18,28 +19,29 @@ namespace DataObjects ...@@ -18,28 +19,29 @@ namespace DataObjects
* @author Janik Zikovsky * @author Janik Zikovsky
* @date 2011-04-15 13:24:07.963491 * @date 2011-04-15 13:24:07.963491
*/ */
class DLLExport Peak class DLLExport Peak: public API::IPeak
{ {
public: public:
/// Allow PeakColumn class to directly access members. /// Allow PeakColumn class to directly access members.
friend class PeakColumn; friend class PeakColumn;
Peak(Mantid::Geometry::IInstrument_sptr m_inst, Mantid::Geometry::V3D QSampleFrame, double detectorDistance=1.0); Peak(Mantid::Geometry::IInstrument_const_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_const_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_const_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_const_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, int m_DetectorID, double m_Wavelength, Mantid::Geometry::V3D HKL, Mantid::Geometry::Matrix<double> goniometer);
// Copy constructor is compiler-provided. // Copy constructor is compiler-provided.
// Peak(const Peak & other); // Peak(const Peak & other);
Peak(const API::IPeak & ipeak);
virtual ~Peak(); virtual ~Peak();
void setInstrument(Mantid::Geometry::IInstrument_sptr inst); void setInstrument(Mantid::Geometry::IInstrument_const_sptr inst);
int getDetectorID() const; int getDetectorID() const;
void setDetectorID(int m_DetectorID); void setDetectorID(int m_DetectorID);
Mantid::Geometry::IDetector_sptr getDetector() const; Mantid::Geometry::IDetector_const_sptr getDetector() const;
Mantid::Geometry::IInstrument_sptr getInstrument() const; Mantid::Geometry::IInstrument_const_sptr getInstrument() const;
int getRunNumber() const; int getRunNumber() const;
void setRunNumber(int m_RunNumber); void setRunNumber(int m_RunNumber);
...@@ -92,10 +94,10 @@ namespace DataObjects ...@@ -92,10 +94,10 @@ namespace DataObjects
protected: protected:
/// Shared pointer to the instrument (for calculating some values ) /// 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 /// Detector pointed to
Mantid::Geometry::IDetector_sptr m_det; Mantid::Geometry::IDetector_const_sptr m_det;
/// Name of the parent bank /// Name of the parent bank
std::string m_BankName; std::string m_BankName;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Includes // Includes
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/TableRow.h" #include "MantidAPI/TableRow.h"
#include "MantidAPI/Column.h" #include "MantidAPI/Column.h"
#include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/TableWorkspace.h"
...@@ -31,6 +31,8 @@ namespace Kernel ...@@ -31,6 +31,8 @@ namespace Kernel
class Logger; class Logger;
} }
using namespace API;
namespace DataObjects namespace DataObjects
{ {
//========================================================================================== //==========================================================================================
...@@ -60,7 +62,7 @@ namespace DataObjects ...@@ -60,7 +62,7 @@ namespace DataObjects
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> 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: public:
...@@ -77,11 +79,11 @@ namespace DataObjects ...@@ -77,11 +79,11 @@ namespace DataObjects
void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst); void appendFile( std::string filename, Mantid::Geometry::IInstrument_sptr inst);
/** Sets the default instrument for new peaks */ /** 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; } { m_defaultInst = inst; }
/** Returns the default instrument for new peaks */ /** Returns the default instrument for new peaks */
Mantid::Geometry::IInstrument_sptr getInstrument() Mantid::Geometry::IInstrument_const_sptr getInstrument() const
{ return m_defaultInst; } { return m_defaultInst; }
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
...@@ -106,9 +108,9 @@ namespace DataObjects ...@@ -106,9 +108,9 @@ namespace DataObjects
/** Add a peak to the list /** Add a peak to the list
* @param peak :: Peak object to add (copy) into this. * @param peak :: Peak object to add (copy) into this.
*/