diff --git a/Framework/Kernel/inc/MantidKernel/MDUnit.h b/Framework/Kernel/inc/MantidKernel/MDUnit.h index 2d9df34609a00d5383a99e3c789154082df4e2ef..7d339496728af1362694c34683bd7bc16937fd16 100644 --- a/Framework/Kernel/inc/MantidKernel/MDUnit.h +++ b/Framework/Kernel/inc/MantidKernel/MDUnit.h @@ -54,10 +54,16 @@ public: /// Dimensionless RLU class DLLExport ReciprocalLatticeUnit : public QUnit { public: + ReciprocalLatticeUnit(); + ReciprocalLatticeUnit(const UnitLabel &unitLabel); UnitLabel getUnitLabel() const; bool canConvertTo(const MDUnit &other) const; ReciprocalLatticeUnit *clone() const; virtual ~ReciprocalLatticeUnit(); + +private: + bool isSpecialRLUUnitLabel() const; + UnitLabel m_unitLabel; }; /// Inverse Angstroms unit diff --git a/Framework/Kernel/src/MDUnit.cpp b/Framework/Kernel/src/MDUnit.cpp index 5dc249f5dbf94c3431f57da9fdbbb74949905cc9..e995ba5e0682baf319864c6d3c312616495aaa5c 100644 --- a/Framework/Kernel/src/MDUnit.cpp +++ b/Framework/Kernel/src/MDUnit.cpp @@ -33,8 +33,19 @@ bool QUnit::isQUnit() const { return true; } //---------------------------------------------------------------------------------------------- // RLU //---------------------------------------------------------------------------------------------- +ReciprocalLatticeUnit::ReciprocalLatticeUnit() : m_unitLabel(UnitLabel("")) {} + +ReciprocalLatticeUnit::ReciprocalLatticeUnit(const UnitLabel &unitLabel) + : m_unitLabel(unitLabel) {} + +ReciprocalLatticeUnit::~ReciprocalLatticeUnit() {} + UnitLabel ReciprocalLatticeUnit::getUnitLabel() const { - return Units::Symbol::RLU; + if (isSpecialRLUUnitLabel()) { + return m_unitLabel; + } else { + return Units::Symbol::RLU; + } } bool ReciprocalLatticeUnit::canConvertTo(const MDUnit &other) const { @@ -42,10 +53,18 @@ bool ReciprocalLatticeUnit::canConvertTo(const MDUnit &other) const { } ReciprocalLatticeUnit *ReciprocalLatticeUnit::clone() const { - return new ReciprocalLatticeUnit; + if (isSpecialRLUUnitLabel()) { + return new ReciprocalLatticeUnit(m_unitLabel); + } else { + return new ReciprocalLatticeUnit; + } +} + +bool ReciprocalLatticeUnit::isSpecialRLUUnitLabel() const { + boost::regex pattern("in.*A.*\\^-1"); + return boost::regex_match(m_unitLabel.ascii(), pattern); } -ReciprocalLatticeUnit::~ReciprocalLatticeUnit() {} //---------------------------------------------------------------------------------------------- // End RLU //---------------------------------------------------------------------------------------------- diff --git a/Framework/Kernel/src/MDUnitFactory.cpp b/Framework/Kernel/src/MDUnitFactory.cpp index 286ec9f2f878d42f5d2b0ef8e4553ee825408cbd..3b0371d9161a2e7bed8fde8320fe717b902a1e8a 100644 --- a/Framework/Kernel/src/MDUnitFactory.cpp +++ b/Framework/Kernel/src/MDUnitFactory.cpp @@ -34,8 +34,8 @@ bool InverseAngstromsUnitFactory::canInterpret( } ReciprocalLatticeUnit * -ReciprocalLatticeUnitFactory::createRaw(const std::string &) const { - return new ReciprocalLatticeUnit; +ReciprocalLatticeUnitFactory::createRaw(const std::string & unitString) const { + return new ReciprocalLatticeUnit(UnitLabel(unitString)); } bool ReciprocalLatticeUnitFactory::canInterpret( @@ -44,15 +44,15 @@ bool ReciprocalLatticeUnitFactory::canInterpret( // In addition to having RLU we can encounter units of type "in 6.28 A^-1" // We need to account for the latter here - boost::regex pattern("in.*A\\^-1"); + boost::regex pattern("in.*A.*\\^-1"); auto isHoraceStyle = boost::regex_match(unitString, pattern); return isRLU || isHoraceStyle; } MDUnitFactory_uptr makeMDUnitFactoryChain() { typedef MDUnitFactory_uptr FactoryType; - auto first = FactoryType(new InverseAngstromsUnitFactory); - first->setSuccessor(FactoryType(new ReciprocalLatticeUnitFactory)) + auto first = FactoryType(new ReciprocalLatticeUnitFactory); + first->setSuccessor(FactoryType(new InverseAngstromsUnitFactory)) // Add more factories here! // Make sure that LabelUnitFactory is the last in the chain to give a fall // through diff --git a/Framework/Kernel/test/MDUnitTest.h b/Framework/Kernel/test/MDUnitTest.h index 17718f5806b0fc0084be4a317c97fe3c7e04f325..757fe99edf6a1518142bcd9aa47e3fed8d4bd198 100644 --- a/Framework/Kernel/test/MDUnitTest.h +++ b/Framework/Kernel/test/MDUnitTest.h @@ -15,6 +15,18 @@ public: static MDUnitTest *createSuite() { return new MDUnitTest(); } static void destroySuite(MDUnitTest *suite) { delete suite; } + void test_RLU_Constructor_with_valid_special_unit_label_accepts_the_label() { + auto unitLabel = UnitLabel("in 1.992 A^-1"); + ReciprocalLatticeUnit unit(unitLabel); + TS_ASSERT_EQUALS(unitLabel.ascii(), unit.getUnitLabel().ascii()); + } + + void test_RLU_Constructor_with_invalid_special_unit_label_does_not_accept_the_label() { + auto unitLabel = UnitLabel("in invalidLabel A-1"); + ReciprocalLatticeUnit unit(unitLabel); + TS_ASSERT_EQUALS(Units::Symbol::RLU, unit.getUnitLabel()); + } + void test_RLU_getUnitLabel() { ReciprocalLatticeUnit unit; TS_ASSERT_EQUALS(Units::Symbol::RLU, unit.getUnitLabel()); diff --git a/Framework/SINQ/src/SINQHMListener.cpp b/Framework/SINQ/src/SINQHMListener.cpp index fd449cb9648dd54cadb67cea330d91aa46ed5fcd..408cb99013cbea6f21fdd3eaf3cf0325cdf8615e 100644 --- a/Framework/SINQ/src/SINQHMListener.cpp +++ b/Framework/SINQ/src/SINQHMListener.cpp @@ -102,8 +102,9 @@ boost::shared_ptr<Workspace> SINQHMListener::extractData() { std::vector<MDHistoDimension_sptr> dimensions; for (int i = 0; i < rank; i++) { + Mantid::Geometry::GeneralFrame frame(dimNames[i], ""); dimensions.push_back(MDHistoDimension_sptr(new MDHistoDimension( - dimNames[i], dimNames[i], "", .0, coord_t(dim[i]), dim[i]))); + dimNames[i], dimNames[i], frame, .0, coord_t(dim[i]), dim[i]))); } MDHistoWorkspace_sptr ws(new MDHistoWorkspace(dimensions)); ws->setTo(.0, .0, .0); diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h index c2edb75dc8ff427f4f97ce48f83e79af5d3245c1..ab7872e02a20efc35e3083eb358f157f258cdafb 100644 --- a/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h +++ b/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h @@ -79,7 +79,7 @@ template <typename MDE, size_t nd> void addMDDimensionsWithIndividualFrames( boost::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> out, Mantid::coord_t min, Mantid::coord_t max, - std::vector<Mantid::Geometry::MDFrame_sptr> frame, + const std::vector<Mantid::Geometry::MDFrame_sptr>& frame, std::string axisNameFormat, std::string axisIdFormat) { for (size_t d = 0; d < nd; d++) { char name[200]; @@ -321,7 +321,7 @@ makeMDEWWithFrames(size_t splitInto, coord_t min, coord_t max, template <size_t nd> boost::shared_ptr<MDEventWorkspace<MDLeanEvent<nd>, nd>> makeMDEWWithIndividualFrames(size_t splitInto, coord_t min, coord_t max, - std::vector<Mantid::Geometry::MDFrame_sptr> frame, + const std::vector<Mantid::Geometry::MDFrame_sptr>& frame, size_t numEventsPerBox = 0) { return makeAnyMDEWWithIndividualFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox); diff --git a/Vates/VatesAPI/src/LoadVTK.cpp b/Vates/VatesAPI/src/LoadVTK.cpp index a003d1569f72fb1ba7ef008ada705180e846474e..53c37ca3b04db09e90ebe5e4b86b155051b0247f 100644 --- a/Vates/VatesAPI/src/LoadVTK.cpp +++ b/Vates/VatesAPI/src/LoadVTK.cpp @@ -321,12 +321,12 @@ namespace Mantid double bounds[6]; readDataset->ComputeBounds(); readDataset->GetBounds(bounds); - - auto dimX = boost::make_shared<MDHistoDimension>("X", "X", "", static_cast<coord_t>(bounds[0]), static_cast<coord_t>(bounds[1]), + Mantid::Geometry::UnknownFrame frame(""); + auto dimX = boost::make_shared<MDHistoDimension>("X", "X", frame, static_cast<coord_t>(bounds[0]), static_cast<coord_t>(bounds[1]), dimensions[0]); - auto dimY = boost::make_shared<MDHistoDimension>("Y", "Y", "", static_cast<coord_t>(bounds[2]), static_cast<coord_t>(bounds[3]), + auto dimY = boost::make_shared<MDHistoDimension>("Y", "Y", frame, static_cast<coord_t>(bounds[2]), static_cast<coord_t>(bounds[3]), dimensions[1]); - auto dimZ = boost::make_shared<MDHistoDimension>("Z", "Z", "", static_cast<coord_t>(bounds[4]), static_cast<coord_t>(bounds[5]), + auto dimZ = boost::make_shared<MDHistoDimension>("Z", "Z", frame, static_cast<coord_t>(bounds[4]), static_cast<coord_t>(bounds[5]), dimensions[2]); const int64_t nPoints = static_cast<int64_t>( readDataset->GetNumberOfPoints() ); diff --git a/Vates/VatesAPI/test/LoadVTKTest.h b/Vates/VatesAPI/test/LoadVTKTest.h index f8e46c2dee856da0851ea4ec3b9987247b646b79..ee748126b01dbb86721edb632d7380dacdb89a27 100644 --- a/Vates/VatesAPI/test/LoadVTKTest.h +++ b/Vates/VatesAPI/test/LoadVTKTest.h @@ -133,6 +133,10 @@ public: do_check_dimension(outWS->getDimension(1), "Y", 0, 67, 68); // These numbers are expected min, max, and nbins known from the input file for dim y. do_check_dimension(outWS->getDimension(2), "Z", 0, 67, 68); // These numbers are expected min, max, and nbins known from the input file for dim z. + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(0))) + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(1))) + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(2))) + double topPercent = loadVTK.getProperty("KeepTopPercent"); TSM_ASSERT_EQUALS("Should default to 25%", 25, topPercent);