Skip to content
Snippets Groups Projects
Commit 56fc6f0f authored by Bhuvan Bezawada's avatar Bhuvan Bezawada
Browse files

Added more properties for iterator

re #23145
Cleaned up files as well.
parent b145f0ea
No related branches found
No related tags found
No related merge requests found
Showing with 87 additions and 45 deletions
#ifndef MANTID_GEOMETRY_DETECTORINFOITEM_H_ #ifndef MANTID_GEOMETRY_DETECTORINFOITEM_H_
#define MANTID_GEOMETRY_DETECTORINFOITEM_H_ #define MANTID_GEOMETRY_DETECTORINFOITEM_H_
#include <utility>
#include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
using Mantid::Kernel::V3D; #include <utility>
using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfo;
using Mantid::Kernel::Quat;
using Mantid::Kernel::V3D;
namespace Mantid { namespace Mantid {
namespace Geometry { namespace Geometry {
...@@ -20,8 +22,18 @@ public: ...@@ -20,8 +22,18 @@ public:
DetectorInfoItem(DetectorInfoItem &&other) = default; DetectorInfoItem(DetectorInfoItem &&other) = default;
DetectorInfoItem &operator=(DetectorInfoItem &&rhs) = default; DetectorInfoItem &operator=(DetectorInfoItem &&rhs) = default;
bool isMonitor() const { return m_detectorInfo->isMonitor(m_index); }
bool isMasked() const { return m_detectorInfo->isMasked(m_index); }
double twoTheta() const { return m_detectorInfo->twoTheta(m_index); }
Mantid::Kernel::V3D position() const { Mantid::Kernel::V3D position() const {
return m_detectorInfo->position(m_index); return m_detectorInfo->position(m_index);
}
Mantid::Kernel::Quat rotation() const {
return m_detectorInfo->rotation(m_index);
} }
void advance(int64_t delta) { void advance(int64_t delta) {
...@@ -54,8 +66,8 @@ private: ...@@ -54,8 +66,8 @@ private:
DetectorInfoItem(const DetectorInfo &detectorInfo, const size_t index) DetectorInfoItem(const DetectorInfo &detectorInfo, const size_t index)
: m_detectorInfo(&detectorInfo), m_index(index) {} : m_detectorInfo(&detectorInfo), m_index(index) {}
// Non-owning pointer. A reference makes the class unable to define assignment // Non-owning pointer. A reference makes the class unable to define an
// operator that we need. // assignment operator that we need.
const DetectorInfo *m_detectorInfo; const DetectorInfo *m_detectorInfo;
size_t m_index; size_t m_index;
}; };
......
#ifndef MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ #ifndef MANTID_GEOMETRY_DETECTORINFOITERATOR_H_
#define MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ #define MANTID_GEOMETRY_DETECTORINFOITERATOR_H_
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <memory> #include <memory>
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
namespace Mantid { namespace Mantid {
...@@ -17,7 +17,8 @@ class MANTID_GEOMETRY_DLL DetectorInfoIterator ...@@ -17,7 +17,8 @@ class MANTID_GEOMETRY_DLL DetectorInfoIterator
boost::bidirectional_traversal_tag> { boost::bidirectional_traversal_tag> {
public: public:
DetectorInfoIterator(const DetectorInfo& owner, const size_t index) : m_item(owner, index) {} DetectorInfoIterator(const DetectorInfo &detectorInfo, const size_t index)
: m_item(detectorInfo, index) {}
private: private:
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
......
#ifndef MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ #ifndef MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_
#define MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ #define MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp> #include <boost/python/copy_const_reference.hpp>
#include <boost/python/def.hpp> #include <boost/python/def.hpp>
...@@ -8,14 +12,9 @@ ...@@ -8,14 +12,9 @@
#include <boost/python/module.hpp> #include <boost/python/module.hpp>
#include <boost/python/reference_existing_object.hpp> #include <boost/python/reference_existing_object.hpp>
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfo;
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
using Mantid::Geometry::DetectorInfoIterator; using Mantid::Geometry::DetectorInfoIterator;
using namespace boost::python; using namespace boost::python;
namespace Mantid { namespace Mantid {
...@@ -23,8 +22,8 @@ namespace Geometry { ...@@ -23,8 +22,8 @@ namespace Geometry {
class DetectorInfoPythonIterator { class DetectorInfoPythonIterator {
public: public:
explicit DetectorInfoPythonIterator(const DetectorInfo &source) explicit DetectorInfoPythonIterator(const DetectorInfo &detectorInfo)
: m_begin(source.begin()), m_end(source.end()), m_current(*m_begin) {} : m_begin(detectorInfo.begin()), m_end(detectorInfo.end()), m_current(*m_begin) {}
const DetectorInfoItem &next() { const DetectorInfoItem &next() {
if (m_begin == m_end) { if (m_begin == m_end) {
...@@ -42,4 +41,5 @@ private: ...@@ -42,4 +41,5 @@ private:
} // namespace Geometry } // namespace Geometry
} // namespace Mantid } // namespace Mantid
#endif /* MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ */ #endif /* MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ */
...@@ -389,10 +389,12 @@ DetectorInfo::getDetectorPtr(const size_t index) const { ...@@ -389,10 +389,12 @@ DetectorInfo::getDetectorPtr(const size_t index) const {
return m_lastDetector[thread]; return m_lastDetector[thread];
} }
// Begin method for iterator
DetectorInfoIterator DetectorInfo::begin() const { DetectorInfoIterator DetectorInfo::begin() const {
return DetectorInfoIterator(*this, 0); return DetectorInfoIterator(*this, 0);
} }
// End method for iterator
DetectorInfoIterator DetectorInfo::end() const { DetectorInfoIterator DetectorInfo::end() const {
return DetectorInfoIterator(*this, size()); return DetectorInfoIterator(*this, size());
} }
......
#include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h"
#include "MantidKernel/Quat.h" #include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp> #include <boost/python/copy_const_reference.hpp>
...@@ -10,11 +14,6 @@ ...@@ -10,11 +14,6 @@
#include <boost/python/return_value_policy.hpp> #include <boost/python/return_value_policy.hpp>
#include <iterator> #include <iterator>
#include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h"
using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfo;
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
using Mantid::Geometry::DetectorInfoIterator; using Mantid::Geometry::DetectorInfoIterator;
...@@ -24,10 +23,12 @@ using Mantid::Kernel::Quat; ...@@ -24,10 +23,12 @@ using Mantid::Kernel::Quat;
using Mantid::Kernel::V3D; using Mantid::Kernel::V3D;
using namespace boost::python; using namespace boost::python;
DetectorInfoPythonIterator make_pyiterator(const DetectorInfo &source) { // Helper method to make the python iterator
return DetectorInfoPythonIterator(source); DetectorInfoPythonIterator make_pyiterator(const DetectorInfo &detectorInfo) {
return DetectorInfoPythonIterator(detectorInfo);
}; };
// Export DetectorInfo
void export_DetectorInfo() { void export_DetectorInfo() {
// Function pointers to distinguish between overloaded versions // Function pointers to distinguish between overloaded versions
......
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
using Mantid::Kernel::V3D; using Mantid::Kernel::V3D;
using namespace boost::python; using namespace boost::python;
// Export DetectorInfoItem
void export_DetectorInfoItem() { void export_DetectorInfoItem() {
// Export to Python // Export to Python
class_<DetectorInfoItem>("DetectorInfoItem", no_init) class_<DetectorInfoItem>("DetectorInfoItem", no_init)
.add_property("position", &DetectorInfoItem::position); .add_property("isMonitor", &DetectorInfoItem::isMonitor)
.add_property("isMasked", &DetectorInfoItem::isMasked)
.add_property("twoTheta", &DetectorInfoItem::twoTheta)
.add_property("position", &DetectorInfoItem::position)
.add_property("rotation", &DetectorInfoItem::rotation);
} }
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/init.hpp> #include <boost/python/init.hpp>
#include <boost/python/module.hpp>
#include "MantidGeometry/Instrument/DetectorInfoIterator.h"
using Mantid::Geometry::DetectorInfoIterator; using Mantid::Geometry::DetectorInfoIterator;
using namespace boost::python; using namespace boost::python;
// Export DetectorInfoIterator
void export_DetectorInfoIterator() { void export_DetectorInfoIterator() {
// Export to Python // Export to Python
class_<DetectorInfoIterator, boost::noncopyable>("DetectorInfoIterator", no_init); class_<DetectorInfoIterator, boost::noncopyable>("DetectorInfoIterator",
no_init);
} }
#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h"
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp> #include <boost/python/copy_const_reference.hpp>
#include <boost/python/def.hpp> #include <boost/python/def.hpp>
...@@ -5,25 +7,22 @@ ...@@ -5,25 +7,22 @@
#include <boost/python/module.hpp> #include <boost/python/module.hpp>
#include <boost/python/reference_existing_object.hpp> #include <boost/python/reference_existing_object.hpp>
#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h"
using namespace boost::python;
using Mantid::Geometry::DetectorInfoPythonIterator; using Mantid::Geometry::DetectorInfoPythonIterator;
using namespace boost::python;
// Export DetectorInfoPythonIterator
void export_DetectorInfoPythonIterator() { void export_DetectorInfoPythonIterator() {
// Export to Python // Export to Python
class_<DetectorInfoPythonIterator>("DetectorInfoPythonIterator", no_init) class_<DetectorInfoPythonIterator>("DetectorInfoPythonIterator", no_init)
.def("__iter__", objects::identity_function()) .def("__iter__", objects::identity_function())
.def( .def(
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
"__next__" "__next__"
#else #else
"next" "next"
#endif #endif
, ,
&DetectorInfoPythonIterator::next, &DetectorInfoPythonIterator::next,
return_value_policy<copy_const_reference>()); return_value_policy<copy_const_reference>());
}
//def("detectorInfo", detectorInfo, return_value_policy<reference_existing_object>());
}
\ No newline at end of file
...@@ -106,11 +106,31 @@ class DetectorInfoTest(unittest.TestCase): ...@@ -106,11 +106,31 @@ class DetectorInfoTest(unittest.TestCase):
--------------- ---------------
""" """
def test_iteration_for_isMonitor(self):
info = self._ws.detectorInfo()
for detInfo in info:
self.assertEquals(type(detInfo.isMonitor), bool)
def test_iteration_for_isMasked(self):
info = self._ws.detectorInfo()
for detInfo in info:
self.assertEquals(type(detInfo.isMasked), bool)
def test_iteration_for_twoTheta(self):
info = self._ws.detectorInfo()
for detInfo in info:
self.assertEquals(type(detInfo.twoTheta), float)
def test_iteration_for_position(self): def test_iteration_for_position(self):
info = self._ws.detectorInfo() info = self._ws.detectorInfo()
for detInfo in info: for detInfo in info:
self.assertEquals(type(detInfo.position), V3D) self.assertEquals(type(detInfo.position), V3D)
def test_iteration_for_rotation(self):
info = self._ws.detectorInfo()
for detInfo in info:
self.assertEquals(type(detInfo.rotation), Quat)
""" """
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment