diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkPeakMarkerFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkPeakMarkerFactory.h index c6c2af234f6ae62264e2b907550a17ad535e2a70..4fc88e0f00151bb3042309a00f0e6fc49a9bd04e 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkPeakMarkerFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkPeakMarkerFactory.h @@ -34,17 +34,15 @@ #include "MantidAPI/IMDWorkspace.h" #include "MantidAPI/IPeaksWorkspace.h" #include "MantidVatesAPI/vtkDataSetFactory.h" -#include <vtkCellData.h> -#include <vtkFloatArray.h> -#include <vtkHexahedron.h> -#include <vtkUnstructuredGrid.h> namespace Mantid { namespace VATES { +// Forward dec. +class ProgressAction; -class DLLExport vtkPeakMarkerFactory: public vtkDataSetFactory +class DLLExport vtkPeakMarkerFactory { public: @@ -79,6 +77,12 @@ public: return "vtkPeakMarkerFactory"; } + /// Getter for the peak workspace integration radius + double getIntegrationRadius() const; + + /// Was the peaks workspace integrated? + bool isPeaksWorkspaceIntegrated() const; + protected: virtual void validate() const; @@ -98,6 +102,8 @@ private: /// Which peak dimension to use ePeakDimensions m_dimensionToShow; + /// peak radius value. + double m_peakRadius; }; diff --git a/Code/Mantid/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp b/Code/Mantid/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp index bfdc9b161044963a093f8d842950adbe0b407c92..a7e1a7978cca73959e9eddb5411339e463532d22 100644 --- a/Code/Mantid/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp @@ -6,6 +6,11 @@ #include "MantidAPI/IPeak.h" #include "MantidKernel/V3D.h" #include <vtkVertex.h> +#include <vtkGlyph3D.h> +#include <vtkSphereSource.h> +#include <vtkUnstructuredGrid.h> +#include <vtkFloatArray.h> +#include <vtkCellData.h> #include "MantidKernel/ReadLock.h" using Mantid::API::IPeaksWorkspace; @@ -18,7 +23,7 @@ namespace VATES { vtkPeakMarkerFactory::vtkPeakMarkerFactory(const std::string& scalarName, ePeakDimensions dimensions) : - m_scalarName(scalarName), m_dimensionToShow(dimensions) + m_scalarName(scalarName), m_dimensionToShow(dimensions), m_peakRadius(-1) { } @@ -53,6 +58,24 @@ namespace VATES { m_workspace = boost::dynamic_pointer_cast<IPeaksWorkspace>(workspace); validateWsNotNull(); + + try + { + m_peakRadius = atof(m_workspace->run().getProperty("PeakRadius")->value().c_str()); + } + catch(Mantid::Kernel::Exception::NotFoundError&) + { + } + } + + double vtkPeakMarkerFactory::getIntegrationRadius() const + { + return m_peakRadius; + } + + bool vtkPeakMarkerFactory::isPeaksWorkspaceIntegrated() const + { + return (m_peakRadius > 0); } void vtkPeakMarkerFactory::validateWsNotNull() const @@ -70,7 +93,7 @@ namespace VATES /** Create the vtkStructuredGrid from the provided workspace @param progressUpdating: Reporting object to pass progress information up the stack. - @return vtkUnStructuredGrid with a bunch of points. + @return vtkPolyData glyph. */ vtkDataSet* vtkPeakMarkerFactory::create(ProgressAction& progressUpdating) const { @@ -138,6 +161,7 @@ namespace VATES points->Squeeze(); visualDataSet->Squeeze(); + return visualDataSet; } diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h index 5f689c5f59ceb91d8dd2a55601bbaf3c0b0c40b0..65f088179fae9ca34c9c49b482027a43d5cff0e9 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h @@ -144,18 +144,71 @@ public: void testCreateWithoutInitializeThrows() { FakeProgressAction progressUpdate; - using namespace Mantid::VATES; vtkPeakMarkerFactory factory("signal"); TS_ASSERT_THROWS(factory.create(progressUpdate), std::runtime_error); } void testTypeName() { - using namespace Mantid::VATES; vtkPeakMarkerFactory factory ("signal"); TS_ASSERT_EQUALS("vtkPeakMarkerFactory", factory.getFactoryTypeName()); } + void testGetPeakRadiusDefault() + { + vtkPeakMarkerFactory factory("signal"); + TS_ASSERT_EQUALS(-1, factory.getIntegrationRadius()); + } + + void testIsPeaksWorkspaceIntegratedDefault() + { + vtkPeakMarkerFactory factory("signal"); + TS_ASSERT_EQUALS(false, factory.isPeaksWorkspaceIntegrated()); + } + + void testGetPeakRadiusWhenNotIntegrated() + { + IPeaksWorkspace* mockWorkspace = new MockPeaksWorkspace; + const double expectedRadius =-1; // The default + // Note that no PeaksRadius property has been set. + + vtkPeakMarkerFactory factory("signal"); + factory.initialize(Mantid::API::IPeaksWorkspace_sptr(mockWorkspace)); + TS_ASSERT_EQUALS(expectedRadius, factory.getIntegrationRadius()); + } + + void testIsPeaksWorkspaceIntegratedWhenNotIntegrated() + { + IPeaksWorkspace* mockWorkspace = new MockPeaksWorkspace; + // Note that no PeaksRadius property has been set. + + vtkPeakMarkerFactory factory("signal"); + factory.initialize(Mantid::API::IPeaksWorkspace_sptr(mockWorkspace)); + TS_ASSERT_EQUALS(false, factory.isPeaksWorkspaceIntegrated()); // false is the default + } + + void testGetPeakRadiusWhenIntegrated() + { + IPeaksWorkspace* mockWorkspace = new MockPeaksWorkspace; + const double expectedRadius = 4; + mockWorkspace->mutableRun().addProperty("PeakRadius", expectedRadius, true); // Has a PeaksRadius so must have been processed via IntegratePeaksMD + + vtkPeakMarkerFactory factory("signal"); + factory.initialize(Mantid::API::IPeaksWorkspace_sptr(mockWorkspace)); + TS_ASSERT_EQUALS(expectedRadius, factory.getIntegrationRadius()); + } + + void testIsPeaksWorkspaceIntegratedWhenIntegrated() + { + IPeaksWorkspace* mockWorkspace = new MockPeaksWorkspace; + const double expectedRadius = 4; + mockWorkspace->mutableRun().addProperty("PeakRadius", expectedRadius, true); // Has a PeaksRadius so must have been processed via IntegratePeaksMD + + vtkPeakMarkerFactory factory("signal"); + factory.initialize(Mantid::API::IPeaksWorkspace_sptr(mockWorkspace)); + TS_ASSERT_EQUALS(true, factory.isPeaksWorkspaceIntegrated()); + } + };