diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h index 8c793cfda541e13db015ae4d97c38c9007da50b2..050e5eb7e6e63ac406d8ef209d0bf00f379dd365 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h @@ -53,37 +53,37 @@ public: ~MDGeometryBuilderXML(); /// Add a dimension that is neither considered x, y, z or t. - bool addOrdinaryDimension(IMDDimension_const_sptr dimension); + bool addOrdinaryDimension(IMDDimension_const_sptr dimension) const; /// Add x dimension. - bool addXDimension(IMDDimension_const_sptr dimension); + bool addXDimension(IMDDimension_const_sptr dimension) const; /// Add y dimension. - bool addYDimension(IMDDimension_const_sptr dimension); + bool addYDimension(IMDDimension_const_sptr dimension) const; /// Add z dimension. - bool addZDimension(IMDDimension_const_sptr dimension); + bool addZDimension(IMDDimension_const_sptr dimension) const; /// Add t dimension. - bool addTDimension(IMDDimension_const_sptr dimension); + bool addTDimension(IMDDimension_const_sptr dimension) const; /// Create the xml. - std::string create(); + const std::string& create() const; private: typedef std::vector<IMDDimension_const_sptr> DimensionContainerType; - DimensionContainerType m_vecDimensions; + mutable DimensionContainerType m_vecDimensions; - IMDDimension_const_sptr m_spXDimension; + mutable IMDDimension_const_sptr m_spXDimension; - IMDDimension_const_sptr m_spYDimension; + mutable IMDDimension_const_sptr m_spYDimension; - IMDDimension_const_sptr m_spZDimension; + mutable IMDDimension_const_sptr m_spZDimension; - IMDDimension_const_sptr m_spTDimension; + mutable IMDDimension_const_sptr m_spTDimension; MDGeometryBuilderXML(const MDGeometryBuilderXML&); @@ -101,6 +101,12 @@ private: /// Determine whetether a valid t dimension has been provided. bool hasTDimension() const; + /// Flag indicating that some change in the inputs has occured. Triggers full recreation. + mutable bool m_changed; + + /// Variable suports lazy calculation. + mutable std::string m_lastResult; + }; } diff --git a/Code/Mantid/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp b/Code/Mantid/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp index 50e7b366423692fdb0d59d648bb9dddf70d7d853..dea1527b65818b52d5486a4a15e65209491d9f12 100644 --- a/Code/Mantid/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp +++ b/Code/Mantid/Framework/Geometry/src/MDGeometry/MDGeometryXMLBuilder.cpp @@ -35,11 +35,11 @@ public: @param dimensionToAdd :: The dimension to add to the geometry. @return true if addition was successful. */ -bool MDGeometryBuilderXML::addOrdinaryDimension(IMDDimension_const_sptr dimensionToAdd) +bool MDGeometryBuilderXML::addOrdinaryDimension(IMDDimension_const_sptr dimensionToAdd) const { CompareIMDDimension_const_sptr comparitor(dimensionToAdd); DimensionContainerType::iterator location = std::find_if(m_vecDimensions.begin(), m_vecDimensions.end(), comparitor); - + m_changed = true; if(location == m_vecDimensions.end()) { m_vecDimensions.push_back(dimensionToAdd); @@ -56,7 +56,7 @@ bool MDGeometryBuilderXML::addOrdinaryDimension(IMDDimension_const_sptr dimensio @param dimensionToAdd :: The dimension to add to the geometry. @return true if addition was successful. */ -bool MDGeometryBuilderXML::addXDimension(IMDDimension_const_sptr dimension) +bool MDGeometryBuilderXML::addXDimension(IMDDimension_const_sptr dimension) const { m_spXDimension = dimension; return addOrdinaryDimension(dimension); @@ -67,7 +67,7 @@ bool MDGeometryBuilderXML::addXDimension(IMDDimension_const_sptr dimension) @param dimensionToAdd :: The dimension to add to the geometry. @return true if addition was successful. */ -bool MDGeometryBuilderXML::addYDimension(IMDDimension_const_sptr dimension) +bool MDGeometryBuilderXML::addYDimension(IMDDimension_const_sptr dimension) const { m_spYDimension = dimension; return addOrdinaryDimension(dimension); @@ -78,7 +78,7 @@ bool MDGeometryBuilderXML::addYDimension(IMDDimension_const_sptr dimension) @param dimensionToAdd :: The dimension to add to the geometry. @return true if addition was successful. */ -bool MDGeometryBuilderXML::addZDimension(IMDDimension_const_sptr dimension) +bool MDGeometryBuilderXML::addZDimension(IMDDimension_const_sptr dimension) const { m_spZDimension = dimension; return addOrdinaryDimension(dimension); @@ -89,93 +89,97 @@ bool MDGeometryBuilderXML::addZDimension(IMDDimension_const_sptr dimension) @param dimensionToAdd :: The dimension to add to the geometry. @return true if addition was successful. */ -bool MDGeometryBuilderXML::addTDimension(IMDDimension_const_sptr dimension) +bool MDGeometryBuilderXML::addTDimension(IMDDimension_const_sptr dimension) const { m_spTDimension = dimension; return addOrdinaryDimension(dimension); } /** - Builder creational method. Processes added dimensions. creates xml string. - @return xmlstring. - */ -std::string MDGeometryBuilderXML::create() +Builder creational method. Processes added dimensions. creates xml string. +@return xmlstring. +*/ +const std::string& MDGeometryBuilderXML::create() const { using namespace Poco::XML; - - //Create the root element for this fragment. - AutoPtr<Document> pDoc = new Document; - AutoPtr<Element> dimensionSetElement = pDoc->createElement("DimensionSet"); - pDoc->appendChild(dimensionSetElement); - - //Loop through dimensions and generate xml for each. - std::string dimensionXMLString; - - DimensionContainerType::iterator it = m_vecDimensions.begin(); - - for (; it != m_vecDimensions.end(); ++it) + std::string formattedXMLString; + if(true == m_changed) { - dimensionXMLString += (*it)->toXMLString(); - } - - //Pass dimensions to dimension set. - dimensionSetElement->appendChild(pDoc->createTextNode("%s")); - - //x-dimension mapping. - AutoPtr<Element> xDimensionElement = pDoc->createElement("XDimension"); - AutoPtr<Element> xDimensionIdElement = pDoc->createElement("RefDimensionId"); - if (hasXDimension()) - { - std::string xDimensionId = this->m_spXDimension->getDimensionId(); - AutoPtr<Text> idXText = pDoc->createTextNode(xDimensionId); - xDimensionIdElement->appendChild(idXText); - } - xDimensionElement->appendChild(xDimensionIdElement); - dimensionSetElement->appendChild(xDimensionElement); - - //y-dimension mapping. - AutoPtr<Element> yDimensionElement = pDoc->createElement("YDimension"); - AutoPtr<Element> yDimensionIdElement = pDoc->createElement("RefDimensionId"); - if (hasYDimension()) - { - std::string yDimensionId = this->m_spYDimension->getDimensionId(); - AutoPtr<Text> idYText = pDoc->createTextNode(yDimensionId); - yDimensionIdElement->appendChild(idYText); - } - yDimensionElement->appendChild(yDimensionIdElement); - dimensionSetElement->appendChild(yDimensionElement); - - //z-dimension mapping. - AutoPtr<Element> zDimensionElement = pDoc->createElement("ZDimension"); - AutoPtr<Element> zDimensionIdElement = pDoc->createElement("RefDimensionId"); - if (hasZDimension()) - { - std::string zDimensionId = this->m_spZDimension->getDimensionId(); - AutoPtr<Text> idZText = pDoc->createTextNode(zDimensionId); - zDimensionIdElement->appendChild(idZText); - } - zDimensionElement->appendChild(zDimensionIdElement); - dimensionSetElement->appendChild(zDimensionElement); - - //t-dimension mapping. - AutoPtr<Element> tDimensionElement = pDoc->createElement("TDimension"); - AutoPtr<Element> tDimensionIdElement = pDoc->createElement("RefDimensionId"); - if (hasTDimension()) - { - std::string tDimensionId = this->m_spTDimension->getDimensionId(); - AutoPtr<Text> idTText = pDoc->createTextNode(tDimensionId); - tDimensionIdElement->appendChild(idTText); - } - tDimensionElement->appendChild(tDimensionIdElement); - dimensionSetElement->appendChild(tDimensionElement); - - std::stringstream xmlstream; - DOMWriter writer; - writer.writeNode(xmlstream, pDoc); - - std::string formattedXMLString = boost::str(boost::format(xmlstream.str().c_str()) + //Create the root element for this fragment. + AutoPtr<Document> pDoc = new Document; + AutoPtr<Element> dimensionSetElement = pDoc->createElement("DimensionSet"); + pDoc->appendChild(dimensionSetElement); + + //Loop through dimensions and generate xml for each. + std::string dimensionXMLString; + + DimensionContainerType::iterator it = m_vecDimensions.begin(); + + for (; it != m_vecDimensions.end(); ++it) + { + dimensionXMLString += (*it)->toXMLString(); + } + + //Pass dimensions to dimension set. + dimensionSetElement->appendChild(pDoc->createTextNode("%s")); + + //x-dimension mapping. + AutoPtr<Element> xDimensionElement = pDoc->createElement("XDimension"); + AutoPtr<Element> xDimensionIdElement = pDoc->createElement("RefDimensionId"); + if (hasXDimension()) + { + std::string xDimensionId = this->m_spXDimension->getDimensionId(); + AutoPtr<Text> idXText = pDoc->createTextNode(xDimensionId); + xDimensionIdElement->appendChild(idXText); + } + xDimensionElement->appendChild(xDimensionIdElement); + dimensionSetElement->appendChild(xDimensionElement); + + //y-dimension mapping. + AutoPtr<Element> yDimensionElement = pDoc->createElement("YDimension"); + AutoPtr<Element> yDimensionIdElement = pDoc->createElement("RefDimensionId"); + if (hasYDimension()) + { + std::string yDimensionId = this->m_spYDimension->getDimensionId(); + AutoPtr<Text> idYText = pDoc->createTextNode(yDimensionId); + yDimensionIdElement->appendChild(idYText); + } + yDimensionElement->appendChild(yDimensionIdElement); + dimensionSetElement->appendChild(yDimensionElement); + + //z-dimension mapping. + AutoPtr<Element> zDimensionElement = pDoc->createElement("ZDimension"); + AutoPtr<Element> zDimensionIdElement = pDoc->createElement("RefDimensionId"); + if (hasZDimension()) + { + std::string zDimensionId = this->m_spZDimension->getDimensionId(); + AutoPtr<Text> idZText = pDoc->createTextNode(zDimensionId); + zDimensionIdElement->appendChild(idZText); + } + zDimensionElement->appendChild(zDimensionIdElement); + dimensionSetElement->appendChild(zDimensionElement); + + //t-dimension mapping. + AutoPtr<Element> tDimensionElement = pDoc->createElement("TDimension"); + AutoPtr<Element> tDimensionIdElement = pDoc->createElement("RefDimensionId"); + if (hasTDimension()) + { + std::string tDimensionId = this->m_spTDimension->getDimensionId(); + AutoPtr<Text> idTText = pDoc->createTextNode(tDimensionId); + tDimensionIdElement->appendChild(idTText); + } + tDimensionElement->appendChild(tDimensionIdElement); + dimensionSetElement->appendChild(tDimensionElement); + + std::stringstream xmlstream; + DOMWriter writer; + writer.writeNode(xmlstream, pDoc); + + m_lastResult = boost::str(boost::format(xmlstream.str().c_str()) % dimensionXMLString.c_str()); - return formattedXMLString; + m_changed = false; + } + return m_lastResult; } bool MDGeometryBuilderXML::hasXDimension() const @@ -201,7 +205,7 @@ bool MDGeometryBuilderXML::hasTDimension() const /** Constructor */ -MDGeometryBuilderXML::MDGeometryBuilderXML() +MDGeometryBuilderXML::MDGeometryBuilderXML() : m_changed(true) { } diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DimensionFactory.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DimensionFactory.h index ad1b33c80dc94f2d81a1da3fd3208508251823e5..cafe9879554039e6943f3b13ac8c70f9c6a3514d 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DimensionFactory.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DimensionFactory.h @@ -1,5 +1,5 @@ #ifndef DIMENSIONFACTORY_H_ -#define DIMENSIONFACTORY_H_ +#define DIMENSIONFACTORY_H_ /** * DimensionFactory. Handles conversion of dimension xml to IMDDimension objects. @@ -74,7 +74,7 @@ public: /// Factory method. More explicit naming as create() should be preferred. Mantid::Geometry::MDDimension* createAsMDDimension() const; - + private: DimensionFactory(); @@ -88,6 +88,12 @@ private: Mantid::Geometry::MDDimension* createRawDimension(Poco::XML::Element* reciprocalMapping, const std::string& id) const; }; + DLLExport Mantid::Geometry::IMDDimension_sptr createDimension(const std::string& dimensionXMLString); + + DLLExport Mantid::Geometry::IMDDimension_sptr createDimension(const std::string& dimensionXMLString, int nBins, double min, double max); + + + } } diff --git a/Code/Mantid/Framework/MDAlgorithms/src/DimensionFactory.cpp b/Code/Mantid/Framework/MDAlgorithms/src/DimensionFactory.cpp index dd3c2418f7780a1f0f23c25a38cc203c53ed2670..7f95f607748c34e7a5967eefaec84935b283d77b 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/DimensionFactory.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/DimensionFactory.cpp @@ -1,7 +1,7 @@ #include <Poco/DOM/Element.h> #include <Poco/DOM/DOMParser.h> #include <Poco/DOM/Document.h> -#include <Poco/DOM/NodeList.h> +#include <Poco/DOM/NodeList.h> #include <Poco/DOM/NamedNodeMap.h> #include "MantidGeometry/MDGeometry/MDGeometryDescription.h" @@ -147,5 +147,37 @@ Mantid::Geometry::MDDimension* DimensionFactory::createRawDimension( return mdDimension; } +/** + Convenience service non-member function. Hides use of factory. Creates IMDDimension. + @param dimensionXMLString :: Dimension xml. + @return new IMDDimension in a shared pointer. + */ +Mantid::Geometry::IMDDimension_sptr createDimension(const std::string& dimensionXMLString) + { + using Mantid::MDAlgorithms::DimensionFactory; + DimensionFactory factory = DimensionFactory::createDimensionFactory(dimensionXMLString); + return Mantid::Geometry::IMDDimension_sptr(factory.create()); + } + +/** + Convenience service non-member function. Hides use of factory. Creates IMDDimension. Also sets min max and number of bins on the dimension. + @param dimensionXMLString :: Dimension xml. + @param nBins :: Number of bins. + @param min :: Minimum + @param max :: Maximum + @return new IMDDimension in a shared pointer. + */ + Mantid::Geometry::IMDDimension_sptr createDimension(const std::string& dimensionXMLString, int nBins, double min, double max) + { + using Mantid::MDAlgorithms::DimensionFactory; + DimensionFactory factory = DimensionFactory::createDimensionFactory(dimensionXMLString); + Mantid::Geometry::MDDimension* dimension = factory.createAsMDDimension(); + double currentMin = min; + double currentMax = max; + //Set the number of bins to use for a given dimension. + dimension->setRange(currentMin, currentMax, nBins); + return Mantid::Geometry::IMDDimension_sptr(dimension); + } + } } diff --git a/Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp b/Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp index 33d05089f2d709c3cb6233539c4c1a0ff7d36d33..f11f5c7b8e0cc7c8371180ab32663af18073994d 100644 --- a/Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp +++ b/Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp @@ -1,16 +1,6 @@ #include "MantidMDEvents/MDHistoWorkspace.h" #include "MantidKernel/System.h" - -#include <Poco/DOM/DOMParser.h> -#include <Poco/DOM/Document.h> -#include <Poco/DOM/Element.h> -#include <Poco/DOM/Attr.h> -#include <Poco/DOM/Text.h> -#include <Poco/DOM/AutoPtr.h> -#include <Poco/DOM/DOMWriter.h> -#include <Poco/XML/XMLWriter.h> -#include <boost/algorithm/string.hpp> -#include <boost/format.hpp> +#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" namespace Mantid { @@ -143,69 +133,36 @@ namespace MDEvents //--------------------------------------------------------------------------------------------------- std::string MDHistoWorkspace::getGeometryXML() const { - using namespace Poco::XML; - - //Create the root element for this fragment. - AutoPtr<Document> pDoc = new Document; - AutoPtr<Element> dimensionSetElement = pDoc->createElement("DimensionSet"); - pDoc->appendChild(dimensionSetElement); - - //Loop through dimensions and generate xml for each. - std::string dimensionXMLString; - for(size_t i = 0; i <m_dimensions.size(); i++) + using Mantid::Geometry::MDGeometryBuilderXML; + MDGeometryBuilderXML xmlBuilder; + // Add all dimensions. + for(size_t i = 0; i <this->m_dimensions.size(); i++) { - dimensionXMLString += m_dimensions[i]->toXMLString(); + xmlBuilder.addOrdinaryDimension(this->m_dimensions[i]); } - - //Pass dimensions to dimension set. - dimensionSetElement->appendChild(pDoc->createTextNode("%s")); - - //x-dimension mapping. - AutoPtr<Element> xDimensionElement = pDoc->createElement("XDimension"); - AutoPtr<Element> xDimensionIdElement = pDoc->createElement("RefDimensionId"); - std::string xDimensionId = this->getXDimension()->getDimensionId(); - AutoPtr<Text> idXText = pDoc->createTextNode(xDimensionId); - xDimensionIdElement->appendChild(idXText); - xDimensionElement->appendChild(xDimensionIdElement); - dimensionSetElement->appendChild(xDimensionElement); - - //y-dimension mapping. - AutoPtr<Element> yDimensionElement = pDoc->createElement("YDimension"); - AutoPtr<Element> yDimensionIdElement = pDoc->createElement("RefDimensionId"); - std::string yDimensionId = this->getYDimension()->getDimensionId(); - AutoPtr<Text> idYText = pDoc->createTextNode(yDimensionId); - yDimensionIdElement->appendChild(idYText); - yDimensionElement->appendChild(yDimensionIdElement); - dimensionSetElement->appendChild(yDimensionElement); - - //z-dimension mapping. - AutoPtr<Element> zDimensionElement = pDoc->createElement("ZDimension"); - AutoPtr<Element> zDimensionIdElement = pDoc->createElement("RefDimensionId"); - std::string zDimensionId = this->getZDimension()->getDimensionId(); - AutoPtr<Text> idZText = pDoc->createTextNode(zDimensionId); - zDimensionIdElement->appendChild(idZText); - zDimensionElement->appendChild(zDimensionIdElement); - dimensionSetElement->appendChild(zDimensionElement); - - //t-dimension mapping. - AutoPtr<Element> tDimensionElement = pDoc->createElement("TDimension"); - AutoPtr<Element> tDimensionIdElement = pDoc->createElement("RefDimensionId"); - std::string tDimensionId = this->getTDimension()->getDimensionId(); - AutoPtr<Text> idTText = pDoc->createTextNode(tDimensionId); - tDimensionIdElement->appendChild(idTText); - tDimensionElement->appendChild(tDimensionIdElement); - dimensionSetElement->appendChild(tDimensionElement); - - std::stringstream xmlstream; - DOMWriter writer; - writer.writeNode(xmlstream, pDoc); - - std::string formattedXMLString = boost::str(boost::format(xmlstream.str().c_str()) % dimensionXMLString.c_str()); - return formattedXMLString; + // Add mapping dimensions + const unsigned int nDimensions = m_dimensions.size(); + if(nDimensions > 0) + { + xmlBuilder.addXDimension(this->getXDimension()); + } + if(nDimensions > 1) + { + xmlBuilder.addYDimension(this->getYDimension()); + } + if(nDimensions > 2) + { + xmlBuilder.addZDimension(this->getZDimension()); + } + if(nDimensions > 3) + { + xmlBuilder.addTDimension(this->getTDimension()); + } + // Create the xml. + return xmlBuilder.create(); } - } // namespace Mantid } // namespace MDEvents diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx index cdec974a766bfe3a4f13469a0fc5e20118ef577f..368b56bc9003fee9e59b50f08400c97696fac36a 100755 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.cxx @@ -14,6 +14,7 @@ #include "MantidMDAlgorithms/PlaneImplicitFunction.h" #include "MantidMDAlgorithms/BoxImplicitFunction.h" #include "MantidMDAlgorithms/NullImplicitFunction.h" +#include "MantidMDAlgorithms/DimensionFactory.h" #include "MantidVatesAPI/EscalatingRebinningActionManager.h" #include "MantidVatesAPI/RebinningCutterXMLDefinitions.h" #include "MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h" @@ -21,6 +22,8 @@ #include "MantidVatesAPI/vtkProxyFactory.h" #include "MantidVatesAPI/TimeToTimeStep.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidVatesAPI/Common.h" +#include "MantidVatesAPI/vtkDataSetToGeometry.h" #include <boost/functional/hash.hpp> #include <sstream> @@ -209,15 +212,17 @@ int vtkRebinningCutter::RequestInformation(vtkInformation* vtkNotUsed(request), if(true == bGoodInputProvided) { DimensionVec dimensionsVec(4); - dimensionsVec[0] = m_presenter.getXDimensionFromDS(inputDataset); - dimensionsVec[1] = m_presenter.getYDimensionFromDS(inputDataset); - dimensionsVec[2] = m_presenter.getZDimensionFromDS(inputDataset); - dimensionsVec[3] = m_presenter.getTDimensionFromDS(inputDataset); - m_appliedXDimension = dimensionsVec[0]; - m_appliedYDimension = dimensionsVec[1]; - m_appliedZDimension = dimensionsVec[2]; - m_appliedTDimension = dimensionsVec[3]; + vtkDataSetToGeometry metaDataProcessor(inputDataset); + metaDataProcessor.execute(); + dimensionsVec[0] = metaDataProcessor.getXDimension(); + dimensionsVec[1] = metaDataProcessor.getYDimension(); + dimensionsVec[2] = metaDataProcessor.getZDimension(); + dimensionsVec[3] = metaDataProcessor.getTDimension(); + m_appliedXDimension = metaDataProcessor.getXDimension(); + m_appliedYDimension = metaDataProcessor.getYDimension(); + m_appliedZDimension = metaDataProcessor.getZDimension(); + m_appliedTDimension = metaDataProcessor.getTDimension(); // Construct reduction knowledge. m_presenter.constructReductionKnowledge(dimensionsVec, dimensionsVec[0], dimensionsVec[1], @@ -326,7 +331,8 @@ void vtkRebinningCutter::SetAppliedXDimensionXML(std::string xml) if (m_appliedXDimension->toXMLString() != xml && !xml.empty()) { this->Modified(); - Mantid::VATES::Dimension_sptr temp = Mantid::VATES::createDimension(xml); + + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); m_actionRequester->ask(RecalculateVisualDataSetOnly); //The visualisation dataset will at least need to be recalculated. formulateRequestUsingNBins(temp); @@ -342,7 +348,8 @@ void vtkRebinningCutter::SetAppliedYDimensionXML(std::string xml) if (m_appliedYDimension->toXMLString() != xml && !xml.empty()) { this->Modified(); - Mantid::VATES::Dimension_sptr temp = Mantid::VATES::createDimension(xml); + using Mantid::MDAlgorithms::DimensionFactory; + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); //The visualisation dataset will at least need to be recalculated. m_actionRequester->ask(RecalculateVisualDataSetOnly); formulateRequestUsingNBins(temp); @@ -358,7 +365,7 @@ void vtkRebinningCutter::SetAppliedZDimensionXML(std::string xml) if (m_appliedZDimension->toXMLString() != xml && !xml.empty()) { this->Modified(); - Mantid::VATES::Dimension_sptr temp = Mantid::VATES::createDimension(xml); + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); //The visualisation dataset will at least need to be recalculated. m_actionRequester->ask(RecalculateVisualDataSetOnly); formulateRequestUsingNBins(temp); @@ -374,7 +381,7 @@ void vtkRebinningCutter::SetAppliedtDimensionXML(std::string xml) if (m_appliedTDimension->toXMLString() != xml && !xml.empty()) { this->Modified(); - Mantid::VATES::Dimension_sptr temp = Mantid::VATES::createDimension(xml); + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); //The visualisation dataset will at least need to be recalculated. m_actionRequester->ask(RecalculateVisualDataSetOnly); formulateRequestUsingNBins(temp); @@ -413,25 +420,6 @@ unsigned long vtkRebinningCutter::GetMTime() return mTime; } -Mantid::VATES::Dimension_sptr vtkRebinningCutter::getDimensionX(vtkDataSet* in_ds) const -{ - return m_presenter.getXDimensionFromDS(in_ds); -} - -Mantid::VATES::Dimension_sptr vtkRebinningCutter::getDimensionY(vtkDataSet* in_ds) const -{ - return m_presenter.getYDimensionFromDS(in_ds); -} - -Mantid::VATES::Dimension_sptr vtkRebinningCutter::getDimensionZ(vtkDataSet* in_ds) const -{ - return m_presenter.getZDimensionFromDS(in_ds); -} - -Mantid::VATES::Dimension_sptr vtkRebinningCutter::getDimensiont(vtkDataSet* in_ds) const -{ - return m_presenter.getTDimensionFromDS(in_ds); -} BoxFunction_sptr vtkRebinningCutter::constructBox(vtkDataSet* inputDataset) const diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h index cce2d3b98546f927053b5bbb6e9fd3c4be45384f..1567ae3fc06955e7f668c0458d556cc99a558de4 100755 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/RebinningCutterOperator/vtkRebinningCutter.h @@ -111,17 +111,7 @@ private: /// Executor pefroms the logic associated with running rebinning operations. Mantid::VATES::RebinningCutterPresenter m_presenter; - /// Get the x dimension form the input dataset. - Mantid::VATES::Dimension_sptr getDimensionX(vtkDataSet* in_ds) const; - /// Get the y dimension form the input dataset. - Mantid::VATES::Dimension_sptr getDimensionY(vtkDataSet* in_ds) const; - - /// Get the z dimension form the input dataset. - Mantid::VATES::Dimension_sptr getDimensionZ(vtkDataSet* in_ds) const; - - /// Get the t dimension form the input dataset. - Mantid::VATES::Dimension_sptr getDimensiont(vtkDataSet* in_ds) const; BoxFunction_sptr constructBox(vtkDataSet* ) const; diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/EventNexusReader.xml b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/EventNexusReader.xml index 2ac7a0ce483c54cc3cd1b542d7c5a98ca281d304..4d0942836978e797788ad19cd8dfb80d63da2914 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/EventNexusReader.xml +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/EventNexusReader.xml @@ -57,12 +57,44 @@ number_of_elements="1" default_values="10000"> </DoubleVectorProperty> + <StringVectorProperty + name="InputGeometryXML" + command="GetInputGeometryXML" + number_of_elements="1" + information_only="1"> + <SimpleStringInformationHelper /> + </StringVectorProperty> + <StringVectorProperty + name="AppliedXDimensionXML" + command="SetAppliedXDimensionXML" + number_of_elements="1" + default_values="--"> + </StringVectorProperty> + <StringVectorProperty + name="AppliedYDimensionXML" + command="SetAppliedYDimensionXML" + number_of_elements="1" + default_values="--"> + </StringVectorProperty> + <StringVectorProperty + name="AppliedZDimensionXML" + command="SetAppliedZDimensionXML" + number_of_elements="1" + default_values="--"> + </StringVectorProperty> + <StringVectorProperty + name="AppliedtDimensionXML" + command="SetAppliedtDimensionXML" + number_of_elements="1" + default_values="--"> + </StringVectorProperty> <StringVectorProperty name="FileName" command="SetFileName" number_of_elements="1"> <FileListDomain name="files"/> </StringVectorProperty> + </SourceProxy> </ProxyGroup> <!-- End EventNexusReader --> diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.cxx index 0867985b4fc723fefe75ae71fb377d571185ca77..4771652a28a0ba860974f22385614a5c933cdf34 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.cxx +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.cxx @@ -26,8 +26,10 @@ #include "MantidMDEvents/BinToMDHistoWorkspace.h" #include "MantidDataHandling/LoadInstrument.h" #include "MantidMDEvents/OneStepMDEW.h" +#include "MantidAPI/IMDEventWorkspace.h" #include "MantidMDAlgorithms/PlaneImplicitFunction.h" +#include "MantidMDAlgorithms/DimensionFactory.h" vtkCxxRevisionMacro(vtkEventNexusReader, "$Revision: 1.0 $"); vtkStandardNewMacro(vtkEventNexusReader); @@ -53,6 +55,10 @@ vtkEventNexusReader::~vtkEventNexusReader() this->SetFileName(0); } +/** + Sets number of bins for x dimension. + @param nbins : Number of bins for the x dimension. +*/ void vtkEventNexusReader::SetXBins(int nbins) { if(nbins != m_nXBins) @@ -63,6 +69,10 @@ void vtkEventNexusReader::SetXBins(int nbins) } } +/** + Sets number of bins for x dimension. + @param nbins : Number of bins for the x dimension. +*/ void vtkEventNexusReader::SetYBins(int nbins) { if(nbins != m_nYBins) @@ -73,6 +83,10 @@ void vtkEventNexusReader::SetYBins(int nbins) } } +/** + Sets number of bins for y dimension. + @param nbins : Number of bins for the x dimension. +*/ void vtkEventNexusReader::SetZBins(int nbins) { if(nbins != m_nZBins) @@ -83,6 +97,10 @@ void vtkEventNexusReader::SetZBins(int nbins) } } +/** + Sets maximum threshold for rendering. + @param maxThreshold : Maximum threshold value. +*/ void vtkEventNexusReader::SetMaxThreshold(double maxThreshold) { if(maxThreshold != m_maxThreshold) @@ -93,6 +111,10 @@ void vtkEventNexusReader::SetMaxThreshold(double maxThreshold) } } +/** + Sets minimum threshold for rendering. + @param minThreshold : Minimum threshold value. +*/ void vtkEventNexusReader::SetMinThreshold(double minThreshold) { if(minThreshold != m_minThreshold) @@ -103,6 +125,10 @@ void vtkEventNexusReader::SetMinThreshold(double minThreshold) } } +/** + Sets clipping. + @param applyClip : true if clipping should be applied. +*/ void vtkEventNexusReader::SetApplyClip(bool applyClip) { if(m_applyClip != applyClip) @@ -113,6 +139,10 @@ void vtkEventNexusReader::SetApplyClip(bool applyClip) } } +/** + Sets width for plane. + @param width: width for plane. +*/ void vtkEventNexusReader::SetWidth(double width) { if(m_width.getValue() != width) @@ -123,6 +153,10 @@ void vtkEventNexusReader::SetWidth(double width) } } +/** + Sets maximum threshold for rendering. + @param maxThreshold : Maximum threshold value. +*/ void vtkEventNexusReader::SetClipFunction(vtkImplicitFunction* func) { if(m_clipFunction != func) @@ -132,12 +166,163 @@ void vtkEventNexusReader::SetClipFunction(vtkImplicitFunction* func) m_actionManager.ask(RecalculateAll); } } + +/** + Sets applied X Dimensional xml. Provided by object panel. + @xml. Dimension xml. +*/ +void vtkEventNexusReader::SetAppliedXDimensionXML(std::string xml) +{ + if (hasXDimension()) + { + if (m_appliedXDimension->toXMLString() != xml && !xml.empty()) + { + this->Modified(); + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); + //The visualisation dataset will at least need to be recalculated. + m_actionManager.ask(RecalculateAll); + this->m_appliedXDimension = temp; + } + } +} +/** + Sets applied Y Dimensional xml. Provided by object panel. + @xml. Dimension xml. +*/ +void vtkEventNexusReader::SetAppliedYDimensionXML(std::string xml) +{ + if (hasYDimension()) + { + if (m_appliedYDimension->toXMLString() != xml && !xml.empty()) + { + this->Modified(); + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); + //The visualisation dataset will at least need to be recalculated. + m_actionManager.ask(RecalculateAll); + this->m_appliedYDimension = temp; + } + } +} -int vtkEventNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkInformationVector ** vtkNotUsed(inputVector), vtkInformationVector *outputVector) +/** + Sets applied Z Dimensional xml. Provided by object panel. + @xml. Dimension xml. +*/ +void vtkEventNexusReader::SetAppliedZDimensionXML(std::string xml) { - try + if (hasZDimension()) + { + if (m_appliedZDimension->toXMLString() != xml && !xml.empty()) + { + this->Modified(); + + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); + //The visualisation dataset will at least need to be recalculated. + m_actionManager.ask(RecalculateAll); + this->m_appliedZDimension = temp; + } + } +} + +/** + Sets applied T Dimensional xml. Provided by object panel. + @xml. Dimension xml. +*/ +void vtkEventNexusReader::SetAppliedtDimensionXML(std::string xml) +{ + if (hasTDimension()) + { + if (m_appliedTDimension->toXMLString() != xml && !xml.empty()) + { + this->Modified(); + Mantid::VATES::Dimension_sptr temp = Mantid::MDAlgorithms::createDimension(xml); + //The visualisation dataset will at least need to be recalculated. + m_actionManager.ask(RecalculateAll); + this->m_appliedTDimension = temp; + } + } +} + +/** + Gets the geometry xml from the workspace. Allows object panels to configure themeselves. + @return geometry xml const * char reference. +*/ +const char* vtkEventNexusReader::GetInputGeometryXML() +{ + return this->m_geometryXmlBuilder.create().c_str(); +} + +/** + Mantid properties for rebinning algorithm require formatted information. + @param dimension : dimension to extract property value for. + @return true available, false otherwise. + */ +std::string vtkEventNexusReader::extractFormattedPropertyFromDimension(Mantid::Geometry::IMDDimension_sptr dimension) const +{ + double min = dimension->getMinimum(); + double max = dimension->getMaximum(); + int nbins = dimension->getNBins(); + std::string id = dimension->getDimensionId(); + return boost::str(boost::format("%s, %f, %f, %d") %id %min %max % nbins); +} + +/** + Actually perform the rebinning. Configure the rebinning algorithm and pass to presenter. + */ +void vtkEventNexusReader::doRebinning() +{ + Mantid::API::AnalysisDataService::Instance().remove(m_histogrammedWsId); + + Mantid::MDEvents::BinToMDHistoWorkspace hist_alg; + hist_alg.initialize(); + hist_alg.setPropertyValue("InputWorkspace", m_mdEventWsId); + double min = 0; + double max = 0; + int nbins = 0; + std::string id; + if(this->hasXDimension()) + { + hist_alg.setPropertyValue("DimX", extractFormattedPropertyFromDimension(m_appliedXDimension)); + } + if(this->hasYDimension()) + { + hist_alg.setPropertyValue("DimY", extractFormattedPropertyFromDimension(m_appliedYDimension)); + } + if(this->hasZDimension()) + { + hist_alg.setPropertyValue("DimZ", extractFormattedPropertyFromDimension(m_appliedZDimension)); + } + if(this->hasTDimension()) { + hist_alg.setPropertyValue("DimT", extractFormattedPropertyFromDimension(m_appliedTDimension)); + } + hist_alg.setPropertyValue("OutputWorkspace", m_histogrammedWsId); + + if(true == m_applyClip) + { + vtkPlane* plane = dynamic_cast<vtkPlane*>(this->m_clipFunction); + if(NULL != plane) + { + //user has requested the use of implicit functions as part of rebinning. only planes understood for time being. + using namespace Mantid::MDAlgorithms; + double* pNormal = plane->GetNormal(); + double* pOrigin = plane->GetOrigin(); + NormalParameter normal(pNormal[0], pNormal[1], pNormal[2]); + OriginParameter origin(pOrigin[0], pOrigin[1], pOrigin[2]); + PlaneImplicitFunction func(normal, origin, m_width); + hist_alg.setPropertyValue("ImplicitFunctionXML", func.toXMLString()); + } + } + + FilterUpdateProgressAction<vtkEventNexusReader> updatehandler(this); + // Run the algorithm and cache the output. + m_presenter.execute(hist_alg, m_histogrammedWsId, updatehandler); +} + + +int vtkEventNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkInformationVector ** vtkNotUsed(inputVector), vtkInformationVector *outputVector) +{ //get the info objects vtkInformation *outInfo = outputVector->GetInformationObject(0); @@ -154,36 +339,7 @@ int vtkEventNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkIn //When RecalculateAll wins-out, configure and run the rebinning algorithm. if(RecalculateAll == m_actionManager.action()) { - Mantid::API::AnalysisDataService::Instance().remove(m_histogrammedWsId); - - Mantid::MDEvents::BinToMDHistoWorkspace hist_alg; - hist_alg.initialize(); - hist_alg.setPropertyValue("InputWorkspace", m_mdEventWsId); - hist_alg.setPropertyValue("DimX", boost::str(boost::format("Qx, -2.0, 2.0, %d") % m_nXBins)); - hist_alg.setPropertyValue("DimY", boost::str(boost::format("Qy, -2.0, 2.0, %d") % m_nYBins)); - hist_alg.setPropertyValue("DimZ", boost::str(boost::format("Qz, -2.0, 2.0, %d") % m_nZBins)); - hist_alg.setPropertyValue("DimT", "NONE,0.0,10.0, 1"); - hist_alg.setPropertyValue("OutputWorkspace", m_histogrammedWsId); - - if(true == m_applyClip) - { - vtkPlane* plane = dynamic_cast<vtkPlane*>(this->m_clipFunction); - if(NULL != plane) - { - //user has requested the use of implicit functions as part of rebinning. only planes understood for time being. - using namespace Mantid::MDAlgorithms; - double* pNormal = plane->GetNormal(); - double* pOrigin = plane->GetOrigin(); - NormalParameter normal(pNormal[0], pNormal[1], pNormal[2]); - OriginParameter origin(pOrigin[0], pOrigin[1], pOrigin[2]); - PlaneImplicitFunction func(normal, origin, m_width); - hist_alg.setPropertyValue("ImplicitFunctionXML", func.toXMLString()); - } - } - - FilterUpdateProgressAction<vtkEventNexusReader> updatehandler(this); - // Run the algorithm and cache the output. - m_presenter.execute(hist_alg, m_histogrammedWsId, updatehandler); + doRebinning(); } // Chain of resposibility setup for visualisation. Encapsulates decision making on how workspace will be rendered. @@ -192,7 +348,7 @@ int vtkEventNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkIn vtkThresholdingQuadFactory* p_2dSuccessorFactory = new vtkThresholdingQuadFactory(scalarName, m_minThreshold, m_maxThreshold); vtkThresholdingHexahedronFactory* p_3dSuccessorFactory = new vtkThresholdingHexahedronFactory(scalarName, m_minThreshold, m_maxThreshold); vtkThresholdingUnstructuredGridFactory<TimeToTimeStep>* p_4dSuccessorFactory = new vtkThresholdingUnstructuredGridFactory<TimeToTimeStep>(scalarName, time, m_minThreshold, m_maxThreshold); - p_2dSuccessorFactory->SetSuccessor(p_2dSuccessorFactory); + p_2dSuccessorFactory->SetSuccessor(p_3dSuccessorFactory); p_3dSuccessorFactory->SetSuccessor(p_4dSuccessorFactory); vtkGridFactory.SetSuccessor(p_3dSuccessorFactory); @@ -204,11 +360,6 @@ int vtkEventNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkIn // Reset the action manager fresh for next cycle. m_actionManager.reset(); return 1; - } - catch(std::exception& ex) - { - std::string mess = ex.what(); - } } int vtkEventNexusReader::RequestInformation( @@ -223,13 +374,42 @@ int vtkEventNexusReader::RequestInformation( //Ensure that the Event Workspace is only generated once if(!m_isSetup) { - AnalysisDataService::Instance().remove("mdEventWsId"); + AnalysisDataService::Instance().remove(m_mdEventWsId); Mantid::MDEvents::OneStepMDEW alg; alg.initialize(); alg.setPropertyValue("Filename", this->FileName); alg.setPropertyValue("OutputWorkspace", m_mdEventWsId); alg.execute(); + + Workspace_sptr result=AnalysisDataService::Instance().retrieve(m_mdEventWsId); + Mantid::API::IMDEventWorkspace_sptr eventWs = boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result); + + int nDimensions = eventWs->getNumDims(); + + //Configuring the geometry xml builder allows the object panel associated with this reader to later + //determine how to display all geometry related properties. + if(nDimensions > 0) + { + m_appliedXDimension = eventWs->getDimension(0); + m_geometryXmlBuilder.addXDimension( m_appliedXDimension ); + } + if(nDimensions > 1) + { + m_appliedYDimension = eventWs->getDimension(1); + m_geometryXmlBuilder.addYDimension( m_appliedYDimension ); + } + if(nDimensions > 2) + { + m_appliedZDimension = eventWs->getDimension(2); + m_geometryXmlBuilder.addZDimension( m_appliedZDimension ); + } + if(nDimensions > 3) + { + m_appliedTDimension = eventWs->getDimension(3); + m_geometryXmlBuilder.addTDimension( m_appliedTDimension ); + } + m_isSetup = true; } @@ -271,8 +451,12 @@ unsigned long vtkEventNexusReader::GetMTime() return mTime; } +/** + Update/Set the progress. + @parameter progress : progress increment. +*/ void vtkEventNexusReader::UpdateAlgorithmProgress(double progress) { this->SetProgressText("Executing Mantid MDEvent Rebinning Algorithm..."); this->UpdateProgress(progress); -} \ No newline at end of file +} diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.h index a4e3eb6a8b5cc557d3efa1b282d323f432dd0ce5..8a234b2f680c85756539100f033b52fcd75a08ff 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.h +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/EventNexusReader/vtkEventNexusReader.h @@ -4,6 +4,7 @@ #include "MantidVatesAPI/MultiDimensionalDbPresenter.h" #include "MantidMDAlgorithms/WidthParameter.h" #include "MantidVatesAPI/EscalatingRebinningActionManager.h" +#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" class vtkImplicitFunction; class VTK_EXPORT vtkEventNexusReader : public vtkUnstructuredGridAlgorithm @@ -26,6 +27,13 @@ public: /// Called by presenter to force progress information updating. void UpdateAlgorithmProgress(double progress); + void SetAppliedXDimensionXML(std::string xml); + void SetAppliedYDimensionXML(std::string xml); + void SetAppliedZDimensionXML(std::string xml); + void SetAppliedtDimensionXML(std::string xml); + + const char* GetInputGeometryXML(); + protected: vtkEventNexusReader(); ~vtkEventNexusReader(); @@ -36,9 +44,51 @@ protected: unsigned long GetMTime(); private: + vtkEventNexusReader(const vtkEventNexusReader&); + void operator = (const vtkEventNexusReader&); + std::string extractFormattedPropertyFromDimension(Mantid::Geometry::IMDDimension_sptr dimension) const; + + void doRebinning(); + + /** + Detect wheter x dimension is available. + @return true available, false otherwise. + */ + bool hasXDimension() const + { + return NULL != m_appliedXDimension.get(); + } + + /** + Detect wheter y dimension is available. + @return true available, false otherwise. + */ + bool hasYDimension() const + { + return NULL != m_appliedYDimension.get(); + } + + /** + Detect wheter z dimension is available. + @return true available, false otherwise. + */ + bool hasZDimension() const + { + return NULL != m_appliedZDimension.get(); + } + + /** + Detect wheter t dimension is available. + @return true available, false otherwise. + */ + bool hasTDimension() const + { + return NULL != m_appliedTDimension.get(); + } + /// File name from which to read. char *FileName; @@ -80,5 +130,23 @@ private: /// Abstracts the handling of rebinning states and rules govening when those states should apply. Mantid::VATES::EscalatingRebinningActionManager m_actionManager; + + /// Converts dimension objects into well-formed xml describing the overall geometry + const Mantid::Geometry::MDGeometryBuilderXML m_geometryXmlBuilder; + + /// Sets the rebinning action to rebin if the number of bins has changed on a dimension. + void formulateRequestUsingNBins(Mantid::VATES::Dimension_sptr newDim); + + /// the dimension information applied to the XDimension Mapping. + Mantid::VATES::Dimension_sptr m_appliedXDimension; + + /// the dimension information applied to the yDimension Mapping. + Mantid::VATES::Dimension_sptr m_appliedYDimension; + + // the dimension information applied to the zDimension Mapping. + Mantid::VATES::Dimension_sptr m_appliedZDimension; + + /// the dimension information applied to the tDimension Mapping. + Mantid::VATES::Dimension_sptr m_appliedTDimension; }; #endif diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/CMakeLists.txt index 6fc785516cdd069b30cf5c1b00854ebc561a7944..cc15b1cff1d7bfc07e3f20b44c46321da1a8634b 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(EventNexusReaderObjectPanel) add_subdirectory(RebinningCutterObjectPanel) add_subdirectory(RebinningCutterToolBarExtension) add_subdirectory(QtWidgets) diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1448af041583195cf2efedcee73b87961c81927a --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt @@ -0,0 +1,18 @@ +#Include Qt widgets +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../QtWidgets) +set_mantid_subprojects(Vates/VatesAPI) +FIND_PACKAGE(ParaView REQUIRED) +INCLUDE(${PARAVIEW_USE_FILE}) + +#So that source file shows in VS. +SET(INCLUDE_FILES EventNexusReaderObjectPanel.h) +SET(SRC_FILES EventNexusReaderObjectPanel.cxx) + +QT4_WRAP_CPP(MOC_SRCS EventNexusReaderObjectPanel.h) +ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS + CLASS_NAME EventNexusReaderObjectPanel + XML_NAME EventNexusReader XML_GROUP sources) +ADD_PARAVIEW_PLUGIN(MantidParaViewEventNexusReaderObjectPanel "1.0" + GUI_INTERFACES ${IFACES} + SOURCES ${MOC_SRCS} ${IFACE_SRCS} ${INCLUDE_FILES} ${SRC_FILES}) +TARGET_LINK_LIBRARIES(MantidParaViewEventNexusReaderObjectPanel MantidParaViewQtWidgets) diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2a3cc73ada98c6386e9eb4e4b60bc076bee0a006 --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.cxx @@ -0,0 +1,130 @@ +#include "EventNexusReaderObjectPanel.h" +#include "pqObjectPanelInterface.h" +#include "pqPropertyManager.h" +#include "pqNamedWidgets.h" +#include "vtkSMStringVectorProperty.h" +#include <QLayout> +#include <QMessageBox> +#include <QCheckBox> +#include "GeometryWidget.h" +#include "MantidVatesAPI/RebinningCutterPresenter.h" + +EventNexusReaderObjectPanel::EventNexusReaderObjectPanel(pqProxy* pxy, QWidget* p) : +pqAutoGeneratedObjectPanel(pxy, p), m_geometryXMLString("") +{ + //Auto generated widgets are replaced by Custom Widgets. Autogenerated ones need to be removed. + removeAutoGeneratedWidgets(); + + //Empty geometry widget added to layout. + m_geometryWidget = new GeometryWidget; + this->layout()->addWidget(m_geometryWidget); +} + +/// Event handler for framework event. +void EventNexusReaderObjectPanel::updateInformationAndDomains() +{ + this->proxy()->UpdatePropertyInformation(); + + vtkSMStringVectorProperty* inputGeometryProperty = vtkSMStringVectorProperty::SafeDownCast( + this->proxy()->GetProperty("InputGeometryXML")); + + std::string geometryXMLString = inputGeometryProperty->GetElement(0); + + if(m_geometryXMLString != geometryXMLString) //Only attempt to reconstruct the geometry widget if the xml has changed. + { + try + { + m_geometryWidget->constructWidget(Mantid::VATES::getDimensions(geometryXMLString, false)); + connect(m_geometryWidget, SIGNAL(ignoreBinChanges()), this, SLOT(ignoreBinChangesListner())); + + //Get the property which is used to specify the applied x dimension. + vtkSMProperty * appliedXDimesionXML = this->proxy()->GetProperty("AppliedXDimensionXML"); + + //Get the property which is used to specify the applied y dimension. + vtkSMProperty * appliedYDimesionXML = this->proxy()->GetProperty("AppliedYDimensionXML"); + + //Get the property which is used to specify the applied z dimension. + vtkSMProperty * appliedZDimesionXML = this->proxy()->GetProperty("AppliedZDimensionXML"); + + //Get the property which is used to specify the applied t dimension. + vtkSMProperty * appliedtDimesionXML = this->proxy()->GetProperty("AppliedtDimensionXML"); + + //Hook up geometry change event to listener on filter. + this->propertyManager()->registerLink(m_geometryWidget, "XDimensionXML", + SIGNAL(valueChanged()), this->proxy(), appliedXDimesionXML); + + //Hook up geometry change event to listener on filter. + this->propertyManager()->registerLink(m_geometryWidget, "YDimensionXML", + SIGNAL(valueChanged()), this->proxy(), appliedYDimesionXML); + + //Hook up geometry change event to listener on filter. + this->propertyManager()->registerLink(m_geometryWidget, "ZDimensionXML", + SIGNAL(valueChanged()), this->proxy(), appliedZDimesionXML); + + //Hook up geometry change event to listener on filter. + this->propertyManager()->registerLink(m_geometryWidget, "tDimensionXML", + SIGNAL(valueChanged()), this->proxy(), appliedtDimesionXML); + + m_geometryXMLString = geometryXMLString; + } + catch(std::exception& ex) + { + QMessageBox::information(NULL, "Setup Not possible.", + "Could not interpret metadata. Are you using a rebinning source? Check field data."); + } + } +} + +/// Direct removal of autogenerated widgets. +void EventNexusReaderObjectPanel::removeAutoGeneratedWidgets() +{ + popWidget(); // Autogenerated Z-dimension QLineEdit + popWidget(); // Autogenerated Z-dimension QLabel + popWidget(); // Autogenerated Y-dimension QLineEdit + popWidget(); // Autogenerated Y-dimension QLabel + popWidget(); // Autogenerated X-dimension QLineEdit + popWidget(); // Autogenerated X-dimension QLabel + popWidget(); // Autogenerated t-dimension QLineEdit + popWidget(); // Autogenerated t-dimension QLabel +} + +/// Pop widgets off the layout and hide them. +void EventNexusReaderObjectPanel::popWidget() +{ + //Pop the last widget off the layout and hide it. + QLayoutItem* pLayoutItem = layout()->itemAt(layout()->count() - 1); + QWidget* pWidget = pLayoutItem->widget(); + if (NULL == pWidget) + { + throw std::domain_error( + "Error ::popWidget(). Attempting to pop a non-widget object off the layout!"); + } + else + { + pWidget->setHidden(true); + this->layout()->removeItem(pLayoutItem); + } +} + +/// Listener for ignore bin changes. +void EventNexusReaderObjectPanel::ignoreBinChangesListner() +{ + QLayoutItem *child; + unsigned int size = layout()->count(); + for(unsigned int i = 0; i < size; i++) + { + child = layout()->itemAt(i); + QWidget* pWidget = child->widget(); + if (NULL != pWidget) // capability query of layout item. + { + QCheckBox* checkBox; + if((checkBox = dynamic_cast<QCheckBox*>(pWidget)) != NULL) //capability query of widget. + { + // Apply Clip check box set to unchecked. + checkBox->setChecked(false); + break; + } + } + } + +} diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.h new file mode 100644 index 0000000000000000000000000000000000000000..2ec895f4379d782ddccec89f01a8579a5a1047a2 --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/EventNexusReaderObjectPanel.h @@ -0,0 +1,64 @@ +#include "pqAutoGeneratedObjectPanel.h" + +#include "MantidKernel/System.h" + +/** + + Adds and removes from Paraview's autogenerated object panel for the Rebinning Cutting filter. + + @author Owen Arnold, Tessella plc + @date 17/03/2011 + + Copyright © 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> + Code Documentation is available at: <http://doxygen.mantidproject.org> + */ + +//Forward declarations +class GeometryWidget; +class DLLExport EventNexusReaderObjectPanel : public pqAutoGeneratedObjectPanel +{ +Q_OBJECT +private: + /// cached geometry xml string. + std::string m_geometryXMLString; + /// Pointer to custom geometry widget. + GeometryWidget* m_geometryWidget; + +private slots: + /// Handler for ignoring bin changes. i.e. + void ignoreBinChangesListner(); + +public: + + /// Constructor + EventNexusReaderObjectPanel(pqProxy* pxy, QWidget* p); + + /// Framework overriden method. + void updateInformationAndDomains(); + + /// Remove selected auto-generated widgets + void removeAutoGeneratedWidgets(); + + /// Pop the widget off the layout + void popWidget(); + + + +}; diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp index bce163857b35718efa33f9f6d87aeafcdb81603c..1ef12a8f2ae568f942e0b5cb2843dc24a9148c8b 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp @@ -14,6 +14,7 @@ #include <boost/algorithm/string.hpp> #include <boost/format.hpp> #include "MantidVatesAPI/RebinningCutterPresenter.h" +#include "MantidMDAlgorithms/DimensionFactory.h" DimensionWidget::DimensionWidget( GeometryWidget* geometryWidget, @@ -72,16 +73,16 @@ void DimensionWidget::constructWidget(const int dimensionIndex) maxLabel->setText("Maximum"); m_layout->addWidget(maxLabel, 2, 0, Qt::AlignLeft); m_maxBox = new QLineEdit(); - m_maxBox->setEnabled(false); - connect(m_maxBox, SIGNAL(returnPressed()), this, SLOT(maxBoxListener())); + //m_maxBox->setEnabled(false); + connect(m_maxBox, SIGNAL(editingFinished()), this, SLOT(maxBoxListener())); m_layout->addWidget(m_maxBox, 2, 1, Qt::AlignLeft); QLabel* minLabel = new QLabel(); minLabel->setText("Minimum"); m_layout->addWidget(minLabel, 3, 0, Qt::AlignLeft); m_minBox = new QLineEdit(); - m_minBox->setEnabled(false); - connect(m_minBox, SIGNAL(returnPressed()), this, SLOT(minBoxListener())); + //m_minBox->setEnabled(false); + connect(m_minBox, SIGNAL(editingFinished()), this, SLOT(minBoxListener())); m_layout->addWidget(m_minBox, 3, 1, Qt::AlignLeft); this->setLayout(m_layout); @@ -104,11 +105,17 @@ void DimensionWidget::populateWidget(const int dimensionIndex) m_nBinsBox->setText(nBinsString.c_str()); } - std::string maxValueString = boost::str(boost::format("%i") % spDimensionToRender->getMaximum()); - m_maxBox->setText(maxValueString.c_str()); + if( m_maxBox->text().isEmpty()) + { + std::string maxValueString = boost::str(boost::format("%i") % spDimensionToRender->getMaximum()); + m_maxBox->setText(maxValueString.c_str()); + } - std::string minValueString = boost::str(boost::format("%i") % spDimensionToRender->getMinimum()); - m_minBox->setText(minValueString.c_str()); + if( m_minBox->text().isEmpty()) + { + std::string minValueString = boost::str(boost::format("%i") % spDimensionToRender->getMinimum()); + m_minBox->setText(minValueString.c_str()); + } } } @@ -149,8 +156,7 @@ boost::shared_ptr<Mantid::Geometry::IMDDimension> DimensionWidget::getDimension boost::shared_ptr<Mantid::Geometry::IMDDimension> originalDimension = m_vecNonIntegratedDimensions[m_currentDimensionIndex]; //Remake the dimension with a new number of bins. Note: Would be much better to have the clone facility. - - return Mantid::VATES::createDimension(originalDimension->toXMLString(), this->getNBins()); + return Mantid::MDAlgorithms::createDimension(originalDimension->toXMLString(), this->getNBins(), this->getMinimum(), this->getMaximum()); } void DimensionWidget::dimensionSelectedListener() @@ -185,12 +191,12 @@ void DimensionWidget::nBinsListener() void DimensionWidget::minBoxListener() { - + m_geometryWidget->dimensionWidgetChanged(ApplyBinChanges); } void DimensionWidget::maxBoxListener() { - + m_geometryWidget->dimensionWidgetChanged(ApplyBinChanges); } DimensionWidget::~DimensionWidget() diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp index 1a93321dd2691480b7f598fb94f79548d89f9ec8..12f59d0f271b6aef38034fe168a0063f69783701 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp @@ -27,7 +27,7 @@ void GeometryWidget::validateSetup() const } } -GeometryWidget::GeometryWidget() : m_isConstructed(false) +GeometryWidget::GeometryWidget() : m_isConstructed(false), m_xDimensionWidget(NULL), m_yDimensionWidget(NULL), m_zDimensionWidget(NULL), m_tDimensionWidget(NULL) { } @@ -45,22 +45,34 @@ void GeometryWidget::constructWidget(std::vector<boost::shared_ptr<Mantid::Geome delete m_zDimensionWidget; delete m_tDimensionWidget; } - + unsigned int size = nonIntegratedVector.size(); //Create widget to display/control the aligned x-dimension - m_xDimensionWidget = new DimensionWidget(this, "x Dimension", 0, nonIntegratedVector); - layout->addWidget(m_xDimensionWidget, 0, 0); + if(size > 0) + { + m_xDimensionWidget = new DimensionWidget(this, "x Dimension", 0, nonIntegratedVector); + layout->addWidget(m_xDimensionWidget, 0, 0); + } //Create widget to display/control the aligned y-dimension - m_yDimensionWidget = new DimensionWidget(this, "y Dimension", 1, nonIntegratedVector); - layout->addWidget(m_yDimensionWidget, 1, 0); + if(size > 1) + { + m_yDimensionWidget = new DimensionWidget(this, "y Dimension", 1, nonIntegratedVector); + layout->addWidget(m_yDimensionWidget, 1, 0); + } //Create widget to display/control the aligned z-dimension - m_zDimensionWidget = new DimensionWidget(this, "z Dimension", 2, nonIntegratedVector); - layout->addWidget(m_zDimensionWidget, 2, 0); + if(size > 2) + { + m_zDimensionWidget = new DimensionWidget(this, "z Dimension", 2, nonIntegratedVector); + layout->addWidget(m_zDimensionWidget, 2, 0); + } //Create widget to display/control the aligned t-dimension - m_tDimensionWidget = new DimensionWidget(this, "t Dimension", 3, nonIntegratedVector); - layout->addWidget(m_tDimensionWidget, 3, 0); + if(size > 3) + { + m_tDimensionWidget = new DimensionWidget(this, "t Dimension", 3, nonIntegratedVector); + layout->addWidget(m_tDimensionWidget, 3, 0); + } this->setLayout(layout); m_isConstructed = true; @@ -71,25 +83,53 @@ QString GeometryWidget::getXDimensionXML() const { validateSetup(); //Get the selected alignment for the xdimension. - return m_xDimensionWidget->getDimension()->toXMLString().c_str(); + if(hasXDimension()) + { + return m_xDimensionWidget->getDimension()->toXMLString().c_str(); + } + else + { + return ""; + } } QString GeometryWidget::getYDimensionXML() const { validateSetup(); - return m_yDimensionWidget->getDimension()->toXMLString().c_str(); + if(hasYDimension()) + { + return m_yDimensionWidget->getDimension()->toXMLString().c_str(); + } + else + { + return ""; + } } QString GeometryWidget::getZDimensionXML() const { validateSetup(); - return m_zDimensionWidget->getDimension()->toXMLString().c_str(); + if(hasZDimension()) + { + return m_zDimensionWidget->getDimension()->toXMLString().c_str(); + } + else + { + return ""; + } } QString GeometryWidget::gettDimensionXML() const { validateSetup(); - return m_tDimensionWidget->getDimension()->toXMLString().c_str(); + if(hasTDimension()) + { + return m_tDimensionWidget->getDimension()->toXMLString().c_str(); + } + else + { + return ""; + } } @@ -109,10 +149,22 @@ void GeometryWidget::dimensionWidgetChanged(BinChangeStatus status) void GeometryWidget::applyBinsFromDimensions() { - m_xDimensionWidget->resetBins(); - m_yDimensionWidget->resetBins(); - m_zDimensionWidget->resetBins(); - m_tDimensionWidget->resetBins(); + if(hasXDimension()) + { + m_xDimensionWidget->resetBins(); + } + if(hasYDimension()) + { + m_yDimensionWidget->resetBins(); + } + if(hasZDimension()) + { + m_zDimensionWidget->resetBins(); + } + if(hasTDimension()) + { + m_tDimensionWidget->resetBins(); + } } void GeometryWidget::childAppliedNewDimensionSelection(const unsigned int oldDimensionIndex, @@ -129,36 +181,36 @@ void GeometryWidget::childAppliedNewDimensionSelection(const unsigned int oldDim //The new Dimension is overwriting the dimension on this widget. //Assign the old widget the old dimension from the calling widget. - if (isEqualToChangedDimension(m_xDimensionWidget->getDimension())) + if (hasXDimension() && isEqualToChangedDimension(m_xDimensionWidget->getDimension())) { - if (pDimensionWidget != m_xDimensionWidget) + if (pDimensionWidget != m_xDimensionWidget) //prevent self assigment. { //Update the xDimensionWidget only. m_xDimensionWidget->populateWidget(oldDimensionIndex); } } - if (isEqualToChangedDimension(m_yDimensionWidget->getDimension())) + if (hasYDimension() && isEqualToChangedDimension(m_yDimensionWidget->getDimension())) { - if (pDimensionWidget != m_yDimensionWidget) + if (pDimensionWidget != m_yDimensionWidget) //prevent self assigment. { //Update the yDimensionWidget only. m_yDimensionWidget->populateWidget(oldDimensionIndex); } } - if (isEqualToChangedDimension(m_zDimensionWidget->getDimension())) + if (hasZDimension() && isEqualToChangedDimension(m_zDimensionWidget->getDimension())) { - if (pDimensionWidget != m_zDimensionWidget) + if (pDimensionWidget != m_zDimensionWidget) //prevent self assigment. { //Update the zDimensionWidget only. m_zDimensionWidget->populateWidget(oldDimensionIndex); } } - if (isEqualToChangedDimension(m_tDimensionWidget->getDimension())) + if (hasTDimension() && isEqualToChangedDimension(m_tDimensionWidget->getDimension())) { - if (pDimensionWidget != m_tDimensionWidget) + if (pDimensionWidget != m_tDimensionWidget) //prevent self assigment. { //Update the zDimensionWidget only. m_tDimensionWidget->populateWidget(oldDimensionIndex); diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h index c2d5ec7ca79a3da45cf61d4523673134272cbf2b..0563a15cdffb2b484a375237c6821fcb7131a5d0 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h @@ -86,6 +86,26 @@ QString getZDimensionXML() const; /// Gets the t dimension in a serialzed form QString gettDimensionXML() const; +bool hasXDimension() const +{ + return m_xDimensionWidget != NULL; +} + +bool hasYDimension() const +{ + return m_yDimensionWidget != NULL; +} + +bool hasZDimension() const +{ + return m_zDimensionWidget != NULL; +} + +bool hasTDimension() const +{ + return m_tDimensionWidget != NULL; +} + void setXDimensionXML(QString value) { //Do nothing. diff --git a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt index cdf26af57d99a8b5cfaad5f565838a3a76fc2660..9bf87462b0cc156c5053a36e7818497763439a96 100644 --- a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt @@ -10,6 +10,7 @@ project ( VatesAPI ) set ( SRC_FILES src/Clipper.cpp +src/Common.cpp src/DimensionComparitor.cpp src/EscalatingRebinningActionManager.cpp src/FieldDataToMetadata.cpp @@ -23,6 +24,7 @@ src/RebinningXMLGenerator.cpp src/TimeStepToTimeStep.cpp src/TimeToTimeStep.cpp src/vtkDataSetFactory.cpp +src/vtkDataSetToGeometry.cpp src/vtkClipperDataSetFactory.cpp src/vtkProxyFactory.cpp src/vtkStructuredGridFactory.cpp @@ -50,6 +52,7 @@ inc/MantidVatesAPI/RebinningXMLGenerator.h inc/MantidVatesAPI/TimeStepToTimeStep.h inc/MantidVatesAPI/TimeToTimeStep.h inc/MantidVatesAPI/vtkDataSetFactory.h +inc/MantidVatesAPI/vtkDataSetToGeometry.h inc/MantidVatesAPI/vtkClipperDataSetFactory.h inc/MantidVatesAPI/vtkProxyFactory.h inc/MantidVatesAPI/vtkStructuredGridFactory.h @@ -61,7 +64,9 @@ inc/MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h set (TEST_FILES test/EscalatingRebinningActionManagerTest.h +test/vtkDataSetFactoryTest.h test/vtkClipperDataSetFactoryTest.h +test/vtkDataSetToGeometryTest.h test/vtkProxyFactoryTest.h test/vtkStructuredGridFactoryTest.h test/vtkThresholdingUnstructuredGridFactoryTest.h diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/Common.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/Common.h index abd4f7d1dd9d7a02cfa74bdeff41f8ebe2c407d3..4a5c59314fbef417d89c68c26009d7f37085348f 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/Common.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/Common.h @@ -3,6 +3,7 @@ #include <vector> #include <boost/shared_ptr.hpp> + namespace Mantid { namespace Geometry @@ -29,7 +30,6 @@ enum RebinningIterationAction { RecalculateAll // Rebin and create 3D visualisation slice from 4D dataset. }; - } } diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MultiDimensionalDbPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MultiDimensionalDbPresenter.h index 0d646593c3dc0d62f19eaaf0f60b23e28a207b56..443514d7a717991caea8e3fd31d41510846fb578 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MultiDimensionalDbPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MultiDimensionalDbPresenter.h @@ -6,6 +6,7 @@ #include "MantidAPI/IMDWorkspace.h" #include "MantidVatesAPI/RebinningXMLGenerator.h" #include "MantidVatesAPI/ProgressAction.h" +#include "MantidVatesAPI/Common.h" #include <Poco/ActiveMethod.h> #include <Poco/NotificationCenter.h> @@ -111,6 +112,12 @@ public: /// Get extents VecExtents getExtents() const; + + /// Get the dimension from the image with the id. + Mantid::VATES::Dimension_const_sptr getDimensionFromWorkspace(const std::string& id) + { + return m_workspace->getDimension(id); + } }; } } diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterPresenter.h index 3d7df8093eef4f08a11fa5faa38e4e58cd0d0ae8..8825f6acc1eeaa1704adbaefc25c6e6744c504ef 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterPresenter.h @@ -3,7 +3,6 @@ #include <vtkUnstructuredGrid.h> #include <vtkBox.h> -#include <map> #include "MantidAPI/IMDWorkspace.h" #include <MantidVatesAPI/Common.h> @@ -81,11 +80,6 @@ private: /// Serializer to create and pass on rebinning metadata. RebinningXMLGenerator m_serializer; - typedef std::map<std::string, int> IDtoColumn_map; - - /// Provides an initial record of ids to column numbers. Required for dimension swapping later. - mutable IDtoColumn_map m_idToColumnMap; - /// Create a geometry from dimensions and then serialise it. std::string constructGeometryXML(DimensionVec dimensions, Dimension_sptr dimensionX, @@ -93,9 +87,6 @@ private: Dimension_sptr dimensionZ, Dimension_sptr dimensiont); - /// Populates m_idToColumnMap if the workspace is a MDWorkspace only. - void createIdToColumnMappings(Mantid::API::IMDWorkspace_sptr outputWorkspace) const; - public: /// Constructor @@ -139,18 +130,6 @@ public: /// Get the dimension from the image with the id. Dimension_const_sptr getDimensionFromWorkspace(const std::string& id); - /// Get the x dimension from vtkDataSet field data. - Dimension_sptr getXDimensionFromDS(vtkDataSet* vtkDataSetInput) const; - - /// Get the y dimension from vtkDataSet field data. - Dimension_sptr getYDimensionFromDS(vtkDataSet* vtkDataSetInput) const; - - /// Get the z dimension from vtkDataSet field data. - Dimension_sptr getZDimensionFromDS(vtkDataSet* vtkDataSetInput) const; - - /// Get the t dimension from vtkDataSet field data. - Dimension_sptr getTDimensionFromDS(vtkDataSet* vtkDataSetInput) const; - /// Get the workspace geometry as an xml string. const std::string& getWorkspaceGeometry() const; @@ -185,15 +164,6 @@ public: /// Helper method to get dimensions from a geometry xml string. DLLExport std::vector<boost::shared_ptr<Mantid::Geometry::IMDDimension> > getDimensions(const std::string& geometryXMLString, bool nonIntegratedOnly = false); - /// helper method to get a dimension from a dimension xml element. - DLLExport Mantid::Geometry::MDDimension* createDimension(Poco::XML::Element* dimensionXML); - - /// helper method to get a dimension from a dimension xml element string. - DLLExport Mantid::VATES::Dimension_sptr createDimension(const std::string& dimensionXMLString); - - /// helper method to get a dimension from a dimension xml element string and set the number of bins for that dimension to a specified value. - DLLExport Mantid::VATES::Dimension_sptr createDimension(const std::string& dimensionXMLString, int nBins); - /// helper method to extract the bounding box. DLLExport std::vector<double> getBoundingBox(const std::string& functionXMLString); diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterXMLDefinitions.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterXMLDefinitions.h index 40a667c976dfd3cd5b86c738ac71f6901a0f63c5..6d756d5522370afad9166b8e8bc3e947ba1493b7 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterXMLDefinitions.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/RebinningCutterXMLDefinitions.h @@ -83,6 +83,30 @@ public: { return "DimensionSet"; } + static const std::string workspaceDimensionElementName() + { + return "Dimension"; + } + static const std::string workspaceXDimensionElementName() + { + return "XDimension"; + } + static const std::string workspaceYDimensionElementName() + { + return "YDimension"; + } + static const std::string workspaceZDimensionElementName() + { + return "ZDimension"; + } + static const std::string workspaceTDimensionElementName() + { + return "TDimension"; + } + static const std::string workspaceRefDimensionElementName() + { + return "RefDimensionId"; + } ///An id for recognising specific vtkFieldData objects on inbound and outbound datasets. static const std::string metaDataId() { diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkClipperDataSetFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkClipperDataSetFactory.h index c965daf9c50f2067a98de9e362bd7bbf8a8f0f06..3759d0551fe70320f6065f74b26855a7e4cbe353 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkClipperDataSetFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkClipperDataSetFactory.h @@ -63,6 +63,11 @@ public: { } + virtual std::string getFactoryTypeName() const + { + return "vtkClipperDataSetFactory"; + } + private: /// Function describing clipping. boost::shared_ptr<Mantid::API::ImplicitFunction> m_implicitFunction; diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetFactory.h index 7d56a3f13516ad50dce092afd09b10a2bb1c07a5..67130431f3f66ce0690cf325615570598ddacece 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetFactory.h @@ -5,6 +5,7 @@ #include "MantidKernel/System.h" #include <boost/shared_ptr.hpp> +#include <string> #include "vtkDataSet.h" class vtkFloatArray; @@ -83,6 +84,9 @@ public: /// Determine whether a successor factory has been provided. virtual bool hasSuccessor() const; + /// Get the name of the type. + virtual std::string getFactoryTypeName() const =0; + protected: /// Typedef for internal unique shared pointer for successor types. diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToGeometry.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToGeometry.h new file mode 100644 index 0000000000000000000000000000000000000000..4eba4467000e1a3c54587a0e2dba8d49424b08ac --- /dev/null +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToGeometry.h @@ -0,0 +1,117 @@ +#ifndef VTKDATASET_TO_GEOMETRY_H_ +#define VTKDATASET_TO_GEOMETRY_H_ + +#include "MantidGeometry/MDGeometry/IMDDimension.h" +#include "MantidKernel/System.h" + +class vtkDataSet; +namespace Mantid +{ + namespace VATES + { + + /** @class vtkDataSetToGeometry + + Handles the extraction of dimensions from a vtkDataSet by getting at the field data and then processing the xml contained within to determine how mappings have been formed. + + @author Owen Arnold, Tessella Support Services plc + @date 13/05/2011 + + Copyright © 2007-8 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>. + Code Documentation is available at: <http://doxygen.mantidproject.org> + */ + class DLLExport vtkDataSetToGeometry + { + + private: + + vtkDataSet* m_dataSet; + + bool m_executed; + + vtkDataSetToGeometry& operator=(const vtkDataSetToGeometry&); + + vtkDataSetToGeometry(const vtkDataSetToGeometry&); + + Mantid::Geometry::IMDDimension_sptr m_xDimension; + + Mantid::Geometry::IMDDimension_sptr m_yDimension; + + Mantid::Geometry::IMDDimension_sptr m_zDimension; + + Mantid::Geometry::IMDDimension_sptr m_tDimension; + + void validate() const; + + public: + + explicit vtkDataSetToGeometry(vtkDataSet* dataSet); + + ~vtkDataSetToGeometry(); + + void execute(); + + + /** + Getter for x dimension + @return x dimension. + */ + Mantid::Geometry::IMDDimension_sptr getXDimension() const + { + validate(); + return m_xDimension; + } + + /** + Getter for y dimension + @return y dimension. + */ + Mantid::Geometry::IMDDimension_sptr getYDimension() const + { + validate(); + return m_yDimension; + } + + /** + Getter for z dimension + @return z dimension. + */ + Mantid::Geometry::IMDDimension_sptr getZDimension() const + { + validate(); + return m_zDimension; + } + + /** + Getter for t dimension + @return t dimension. + */ + Mantid::Geometry::IMDDimension_sptr getTDimension() const + { + validate(); + return m_tDimension; + } + + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkProxyFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkProxyFactory.h index 19ae4ee97f569b869babb8283a9920afa8d4972d..ffaab62f898d32ba83da75fe7001f2b96722b9be 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkProxyFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkProxyFactory.h @@ -62,8 +62,11 @@ public: vtkFloatArray* createScalarArray() const; - void validate() const + void validate() const{} + + virtual std::string getFactoryTypeName() const { + return "vtkProxyFactory"; } private: diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkStructuredGridFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkStructuredGridFactory.h index c9330edda5686a7f783ec5c0a22084938218c2c4..d4be1622bcadbe4f5723b066c3aaa5fa0cd4e978 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkStructuredGridFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkStructuredGridFactory.h @@ -71,6 +71,11 @@ public: /// Generates a scalar array for signal. vtkFloatArray* createScalarArray() const; + virtual std::string getFactoryTypeName() const + { + return "vtkStructuredGridFactory"; + } + protected: /// Validate the object. diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingHexahedronFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingHexahedronFactory.h index e6a22fbd9ac70938ccadfe540b6b4cac2c3db0af..30fb2ed9c046fb268668aa6d5833eeeb67e9de18 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingHexahedronFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingHexahedronFactory.h @@ -66,6 +66,11 @@ public: typedef std::vector<UnstructuredPoint> Column; + virtual std::string getFactoryTypeName() const + { + return "vtkThresholdingHexahedronFactory"; + } + protected: virtual void validate() const; diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingLineFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingLineFactory.h index d55229f974551b38be2fb249cd57b37dc919c010..03a8ba41542af9be083fa9b4aa251ae55306bbb0 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingLineFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingLineFactory.h @@ -57,6 +57,11 @@ namespace Mantid typedef std::vector<UnstructuredPoint> Column; + virtual std::string getFactoryTypeName() const + { + return "vtkThresholdingLineFactory"; + } + protected: virtual void validate() const; diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingQuadFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingQuadFactory.h index 78de304c8c32a82a5afe052a6ed58aa5cf3c1ef7..fa6ee2d539e4ba7971f263d22d1120c6da27fcc9 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingQuadFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingQuadFactory.h @@ -60,6 +60,11 @@ however, some visualisation frameworks won't be able to treat these factories in typedef std::vector<UnstructuredPoint> Column; + virtual std::string getFactoryTypeName() const + { + return "vtkThresholdingQuadFactory"; + } + protected: virtual void validate() const; diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h index 06f2f7e7b8f43488eb39c9748014c1b67ef18e9b..55380aadead6dabdcc7e4d017f528a8566c82bf1 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h @@ -68,6 +68,11 @@ public: typedef std::vector<UnstructuredPoint> Column; + virtual std::string getFactoryTypeName() const + { + return "vtkThresholdingUnstructuredGridFactory"; + } + protected: virtual void validate() const; diff --git a/Code/Mantid/Vates/VatesAPI/src/Common.cpp b/Code/Mantid/Vates/VatesAPI/src/Common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/Code/Mantid/Vates/VatesAPI/src/Common.cpp @@ -0,0 +1 @@ + diff --git a/Code/Mantid/Vates/VatesAPI/src/RebinningCutterPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/RebinningCutterPresenter.cpp index 738c881db970a12eeda5d56b0f96b7a717d8a6dd..ba32cf8a031437a31723756b2ba5a5f19963e206 100644 --- a/Code/Mantid/Vates/VatesAPI/src/RebinningCutterPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/RebinningCutterPresenter.cpp @@ -31,6 +31,7 @@ #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/WorkspaceFactory.h" #include "MDDataObjects/MD_FileFormatFactory.h" +#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" #include <Poco/DOM/DOMParser.h> #include <Poco/DOM/Document.h> @@ -178,8 +179,6 @@ Mantid::API::IMDWorkspace_sptr RebinningCutterPresenter::applyRebinningAction( IMDWorkspace_sptr outputWs = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(outputWorkspace)); - //Seam method. Should make it easier to remove in future. - createIdToColumnMappings(outputWs); return outputWs; } @@ -214,83 +213,6 @@ Dimension_const_sptr RebinningCutterPresenter::getDimensionFromWorkspace(const s return outputWs->getDimension(id); } -Dimension_sptr RebinningCutterPresenter::getXDimensionFromDS(vtkDataSet* vtkDataSetInput) const -{ - Poco::XML::Element* geometryXMLElement = findExistingGeometryInformation(vtkDataSetInput, XMLDefinitions::metaDataId().c_str() ); - - std::vector<boost::shared_ptr<IMDDimension> > dimensionVec = getDimensions(geometryXMLElement); - - //Find the requested xDimension alignment from the dimension id provided in the xml. - Poco::XML::Element* xDimensionElement = geometryXMLElement->getChildElement("XDimension"); - std::string xDimId = xDimensionElement->getChildElement("RefDimensionId")->innerText(); - std::vector<boost::shared_ptr<IMDDimension> >::iterator xDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(xDimId)); - - if (xDimensionIt == dimensionVec.end()) - { - throw std::invalid_argument("Cannot determine x-dimension mapping."); - } - - return *xDimensionIt; -} - -Dimension_sptr RebinningCutterPresenter::getYDimensionFromDS(vtkDataSet* vtkDataSetInput) const -{ - Poco::XML::Element* geometryXMLElement = findExistingGeometryInformation(vtkDataSetInput, XMLDefinitions::metaDataId().c_str() ); - - std::vector<boost::shared_ptr<IMDDimension> > dimensionVec = getDimensions(geometryXMLElement); - - //Find the requested xDimension alignment from the dimension id provided in the xml. - Poco::XML::Element* yDimensionElement = geometryXMLElement->getChildElement("YDimension"); - std::string yDimId = yDimensionElement->getChildElement("RefDimensionId")->innerText(); - std::vector<boost::shared_ptr<IMDDimension> >::iterator yDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(yDimId)); - - if (yDimensionIt == dimensionVec.end()) - { - throw std::invalid_argument("Cannot determine y-dimension mapping."); - } - - return *yDimensionIt; -} - -Dimension_sptr RebinningCutterPresenter::getZDimensionFromDS(vtkDataSet* vtkDataSetInput) const -{ - - Poco::XML::Element* geometryXMLElement = findExistingGeometryInformation(vtkDataSetInput, XMLDefinitions::metaDataId().c_str() ); - - std::vector<boost::shared_ptr<IMDDimension> > dimensionVec = getDimensions(geometryXMLElement); - - //Find the requested xDimension alignment from the dimension id provided in the xml. - Poco::XML::Element* zDimensionElement = geometryXMLElement->getChildElement("ZDimension"); - std::string zDimId = zDimensionElement->getChildElement("RefDimensionId")->innerText(); - std::vector<boost::shared_ptr<IMDDimension> >::iterator zDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(zDimId)); - - if (zDimensionIt == dimensionVec.end()) - { - throw std::invalid_argument("Cannot determine z-dimension mapping."); - } - - return *zDimensionIt; -} - -Dimension_sptr RebinningCutterPresenter::getTDimensionFromDS(vtkDataSet* vtkDataSetInput) const -{ - Poco::XML::Element* geometryXMLElement = findExistingGeometryInformation(vtkDataSetInput, XMLDefinitions::metaDataId().c_str() ); - - std::vector<boost::shared_ptr<IMDDimension> > dimensionVec = getDimensions(geometryXMLElement); - - //Find the requested xDimension alignment from the dimension id provided in the xml. - Poco::XML::Element* tDimensionElement = geometryXMLElement->getChildElement("TDimension"); - std::string tDimId = tDimensionElement->getChildElement("RefDimensionId")->innerText(); - std::vector<boost::shared_ptr<IMDDimension> >::iterator tDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(tDimId)); - - if (tDimensionIt == dimensionVec.end()) - { - throw std::invalid_argument("Cannot determine t-dimension mapping."); - } - - return *tDimensionIt; -} - const std::string& RebinningCutterPresenter::getWorkspaceGeometry() const { VerifyInitalization(); @@ -314,99 +236,19 @@ std::string RebinningCutterPresenter::constructGeometryXML( Dimension_sptr dimensionZ, Dimension_sptr dimensiont) { - using namespace Mantid::Geometry; - std::set<MDBasisDimension> basisDimensions; - for(unsigned int i = 0; i < dimensions.size(); i++) + Mantid::Geometry::MDGeometryBuilderXML xmlBuilder; + DimensionVec::iterator it = dimensions.begin(); + for(;it != dimensions.end(); ++it) { - //read dimension. - std::string dimensionId = dimensions[i]->getDimensionId(); - bool isReciprocal = boost::dynamic_pointer_cast<MDDimension>(dimensions[i])->isReciprocal(); - //basis dimension. - if(!m_idToColumnMap.empty()) - { - basisDimensions.insert(MDBasisDimension(dimensionId, isReciprocal, m_idToColumnMap[dimensionId])); - } - else - { - basisDimensions.insert(MDBasisDimension(dimensionId, isReciprocal, i)); - } - - //NB: Geometry requires both a basis and geometry description to work. Initially all cuts and dimensions treated as orthogonal. - //So that congruent checks pass on the geometry, the basis is fabricated from the dimensions. This is not an ideal implementation. Other designs will - //be considered. + xmlBuilder.addOrdinaryDimension(*it); } - - boost::shared_ptr<UnitCell> spCell = boost::shared_ptr<UnitCell>(new UnitCell()); // Unit cell currently does nothing. - MDGeometryBasis basis(basisDimensions, spCell); - - //TODO: Get Rotation matrix from Plane ImplicitFunction - RotationMatrix identityMatrix(9, 0); - identityMatrix[0] = 1; - identityMatrix[4] = 1; - identityMatrix[8] = 1; - - // Convert IMDDimensions to MDDimensions - std::vector<IMDDimension_sptr> md_dimensions; - for (size_t i=0; i<dimensions.size(); i++) - md_dimensions.push_back( boost::dynamic_pointer_cast<MDDimension>(dimensions[i])); - - MDGeometryDescription description(md_dimensions, boost::dynamic_pointer_cast<MDDimension>(dimensionX), boost::dynamic_pointer_cast<MDDimension>(dimensionY), - boost::dynamic_pointer_cast<MDDimension>(dimensionZ), boost::dynamic_pointer_cast<MDDimension>(dimensiont), identityMatrix); - - //Create a geometry. - MDGeometry geometry(basis, description); - return geometry.toXMLString(); - + xmlBuilder.addXDimension(dimensionX); + xmlBuilder.addYDimension(dimensionY); + xmlBuilder.addZDimension(dimensionZ); + xmlBuilder.addTDimension(dimensiont); + return xmlBuilder.create(); } -void RebinningCutterPresenter::createIdToColumnMappings(IMDWorkspace_sptr outputWorkspace) const -{ - - /* - This method is necessary to solve a problem that should have been solved elsewhere but - hasn't been: The column information (i.e. which column in the file!) a particular basis - dimension represents has penetrated the file-access boundary. Basically then, the high-level - code needs to know how the data is arranged in the underlying file format. A - consequence of this is that here we have to keep a running map of the original - columnnumbers to dimension ids so that we can provide MDGeometryBasis with the corresponding columnnumbers. - This has been hived-off into a separate method in the hope that the situation will improved, and this function can be deleted. - */ - - //Is this an MDWorkspace? - Mantid::MDDataObjects::MDWorkspace_sptr mdWorkspace = boost::dynamic_pointer_cast<Mantid::MDDataObjects::MDWorkspace>(outputWorkspace); - if(NULL != mdWorkspace.get()) - { - //Are there no existing column mappings? - if(m_idToColumnMap.empty()) - { - //The implementation of MDGeometry shows that it implitily sets the index of the vector up to the the column number. - //The tag is an alias for the dimension id. - std::vector<std::string> idsIndexedByColumnNumber = mdWorkspace->get_const_MDGeometry().getBasisTags(); - //Loop through all columns and store the mapping. - for(int i = 0; i < idsIndexedByColumnNumber.size(); i++) - { - m_idToColumnMap.insert(std::make_pair(idsIndexedByColumnNumber[i], i)); - } - } - } -} - -Mantid::VATES::Dimension_sptr createDimension(const std::string& dimensionXMLString) -{ - DimensionFactory factory = DimensionFactory::createDimensionFactory(dimensionXMLString); - return Mantid::VATES::Dimension_sptr(factory.create()); -} - -Mantid::VATES::Dimension_sptr createDimension(const std::string& dimensionXMLString, int nBins) -{ - DimensionFactory factory = DimensionFactory::createDimensionFactory(dimensionXMLString); - MDDimension* dimension = factory.createAsMDDimension(); - double currentMin = dimension->getMinimum(); - double currentMax = dimension->getMaximum(); - //Set the number of bins to use for a given dimension. - dimension->setRange(currentMin, currentMax, nBins); - return Mantid::VATES::Dimension_sptr(dimension); -} std::vector<boost::shared_ptr<Mantid::Geometry::IMDDimension> > getDimensions( Poco::XML::Element* geometryXMLElement, bool nonIntegratedOnly) diff --git a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetFactory.cpp b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetFactory.cpp index 2c6d967b9d35cf362dfc79eeaf2e210b3a9b2d3d..5e2ffccacdae29c52ee3b9b47ddb30061779307e 100644 --- a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetFactory.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetFactory.cpp @@ -13,11 +13,26 @@ vtkDataSetFactory::~vtkDataSetFactory() { } +/** + Set the successor factory for the chain-of-responsibility. + @param pSuccessor :: pointer to the successor. Note RAII is used. + @return true if addition was successful. + */ void vtkDataSetFactory::SetSuccessor(vtkDataSetFactory* pSuccessor) -{ +{ + //Assigment peformed first (RAII) to guarentee no side effects. m_successor = vtkDataSetFactory::SuccessorType(pSuccessor); + //Unless overriden, successors should not be the same type as the present instance. + if(pSuccessor->getFactoryTypeName() == this->getFactoryTypeName()) + { + throw std::runtime_error("Cannot assign a successor to vtkDataSetFactory with the same type as the present vtkDataSetFactory type."); + } } +/** + Determine when a successor is available. + @return true if a successor is available. + */ bool vtkDataSetFactory::hasSuccessor() const { return NULL != m_successor.get(); diff --git a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToGeometry.cpp b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToGeometry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49b88351fa65ea8442841f07b41891ababf51e39 --- /dev/null +++ b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToGeometry.cpp @@ -0,0 +1,146 @@ +#include "MantidVatesAPI/vtkDataSetToGeometry.h" +#include "MantidVatesAPI/FieldDataToMetadata.h" +#include "MantidVatesAPI/RebinningCutterXMLDefinitions.h" +#include "MantidMDAlgorithms/DimensionFactory.h" + +#include "vtkDataSet.h"; + +#include <Poco/DOM/DOMParser.h> +#include <Poco/DOM/Document.h> +#include <Poco/DOM/Element.h> +#include <Poco/DOM/NodeList.h> +#include <Poco/DOM/NodeIterator.h> +#include <Poco/DOM/NodeFilter.h> +#include <Poco/DOM/NamedNodeMap.h> + +#include<algorithm> + +namespace Mantid +{ + namespace VATES + { + /// Helper unary comparison type for IMDDimensions. + struct findID : public std::unary_function <Mantid::Geometry::IMDDimension, bool> + { + const std::string m_id; + findID(const std::string id) : m_id(id){ } + + bool operator ()(const boost::shared_ptr<Mantid::Geometry::IMDDimension> obj) const + { + return m_id == obj->getDimensionId(); + } + }; + + /** + Validate the current object. Take action if not set up properly. + */ + void vtkDataSetToGeometry::validate() const + { + if(!m_executed) + { + throw std::runtime_error("Attempting to get dimension information from vtkDataSetToGeometry, before calling ::execute()"); + } + } + + /** + Peforms the processing associated with these transformations. + */ + void vtkDataSetToGeometry::execute() + { + typedef std::vector<Mantid::Geometry::IMDDimension_sptr>::iterator Iterator; + FieldDataToMetadata convert; + std::string xmlString = convert(m_dataSet->GetFieldData(), XMLDefinitions::metaDataId()); + + Poco::XML::DOMParser pParser; + Poco::XML::Document* pDoc = pParser.parseString(xmlString); + Poco::XML::Element* pRootElem = pDoc->documentElement(); + Poco::XML::Element* geometryXMLElement = pRootElem->getChildElement(XMLDefinitions::workspaceGeometryElementName()); + if (geometryXMLElement == NULL) + { + throw std::runtime_error("The element containing the workspace geometry must be present."); + } + + + Poco::XML::NodeList* dimensionsXML = geometryXMLElement-> getElementsByTagName(XMLDefinitions::workspaceDimensionElementName()); + std::vector<Mantid::Geometry::IMDDimension_sptr > dimensionVec; + + ////Extract dimensions + int nDimensions = dimensionsXML->length(); + for (int i = 0; i < nDimensions; i++) + { + Poco::XML::Element* dimensionXML = static_cast<Poco::XML::Element*> (dimensionsXML->item(i)); + Mantid::MDAlgorithms::DimensionFactory factory(dimensionXML); + Mantid::Geometry::IMDDimension* dimension = factory.create(); + + dimensionVec.push_back(boost::shared_ptr<Mantid::Geometry::IMDDimension>(dimension)); + } + + Poco::XML::Element* xDimensionElement = geometryXMLElement->getChildElement(XMLDefinitions::workspaceXDimensionElementName()); + std::string xDimId = xDimensionElement->getChildElement(XMLDefinitions::workspaceRefDimensionElementName())->innerText(); + if(!xDimId.empty()) + { + Iterator xDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(xDimId)); + if (xDimensionIt == dimensionVec.end()) + { + throw std::invalid_argument("Cannot determine x-dimension mapping."); + } + m_xDimension = *xDimensionIt; + } + + Poco::XML::Element* yDimensionElement = geometryXMLElement->getChildElement(XMLDefinitions::workspaceYDimensionElementName()); + std::string yDimId = yDimensionElement->getChildElement(XMLDefinitions::workspaceRefDimensionElementName())->innerText(); + + if(!yDimId.empty()) + { + Iterator yDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(yDimId)); + if (yDimensionIt == dimensionVec.end()) + { + throw std::invalid_argument("Cannot determine y-dimension mapping."); + } + m_yDimension = *yDimensionIt; + } + + Poco::XML::Element* zDimensionElement = geometryXMLElement->getChildElement(XMLDefinitions::workspaceZDimensionElementName()); + std::string zDimId = zDimensionElement->getChildElement(XMLDefinitions::workspaceRefDimensionElementName())->innerText(); + + if(!zDimId.empty()) + { + Iterator zDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(zDimId)); + if (zDimensionIt == dimensionVec.end()) + { + throw std::invalid_argument("Cannot determine z-dimension mapping."); + } + m_zDimension = *zDimensionIt; + } + + Poco::XML::Element* tDimensionElement = geometryXMLElement->getChildElement(XMLDefinitions::workspaceTDimensionElementName()); + std::string tDimId = tDimensionElement->getChildElement(XMLDefinitions::workspaceRefDimensionElementName())->innerText(); + if(!tDimId.empty()) + { + Iterator tDimensionIt = find_if(dimensionVec.begin(), dimensionVec.end(), findID(tDimId)); + if (tDimensionIt == dimensionVec.end()) + { + throw std::invalid_argument("Cannot determine t-dimension mapping."); + } + m_tDimension = *tDimensionIt; + } + + m_executed = true; + } + + /** + Constructor + @param dataSet : vtkDataSet to process + */ + vtkDataSetToGeometry::vtkDataSetToGeometry(vtkDataSet* dataSet) : m_dataSet(dataSet), m_executed(false) + { + } + + /** + Destructor + */ + vtkDataSetToGeometry::~vtkDataSetToGeometry() + { + } + } +} \ No newline at end of file diff --git a/Code/Mantid/Vates/VatesAPI/test/RebinningCutterTest.h b/Code/Mantid/Vates/VatesAPI/test/RebinningCutterTest.h index 691f9ac5b9e1c36bc184f5fb3115f87dd64a7370..0997c6cd57637278dce365d4018d6b96fe98736c 100644 --- a/Code/Mantid/Vates/VatesAPI/test/RebinningCutterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/RebinningCutterTest.h @@ -60,16 +60,20 @@ private: RebinningCutterPresenter presenter; - DimensionVec vec; - MDDimensionRes* pDimQx = new MDDimensionRes("qx", q1); //In reality these commands come from UI inputs. + Mantid::Geometry::V3D x(1, 0, 0); + Mantid::Geometry::V3D y(0, 1, 0); + Mantid::Geometry::V3D z(0, 0, 1); + + DimensionVec vec; + MDDimensionRes* pDimQx = new MDDimensionRes("qx", q1, &x); //In reality these commands come from UI inputs. pDimQx->setRange(-1.5, 5, 5); Dimension_sptr dimX = Dimension_sptr(pDimQx); - MDDimensionRes* pDimQy = new MDDimensionRes("qy", q2); //In reality these commands come from UI inputs. + MDDimensionRes* pDimQy = new MDDimensionRes("qy", q2, &y); //In reality these commands come from UI inputs. pDimQy->setRange(-6.6, 6.6, 5); Dimension_sptr dimY = Dimension_sptr(pDimQy); - MDDimensionRes* pDimQz = new MDDimensionRes("qz", q3); //In reality these commands come from UI inputs. + MDDimensionRes* pDimQz = new MDDimensionRes("qz", q3, &z); //In reality these commands come from UI inputs. pDimQz->setRange(-6.6, 6.6, 5); Dimension_sptr dimZ = Dimension_sptr(pDimQz); @@ -388,50 +392,6 @@ void testGetDimensionFromWorkspaceThrows() dataSet->Delete(); } -void testGetXDimension() -{ - Mantid::VATES::RebinningCutterPresenter presenter; - vtkDataSet* dataSet = constructInputDataSet(); //Creates a vtkDataSet with fielddata containing geomtry xml. - Mantid::VATES::Dimension_sptr xDimension = presenter.getXDimensionFromDS(dataSet); - TSM_ASSERT_EQUALS("Wrong number of x dimension bins", 5, xDimension->getNBins()); - TSM_ASSERT_EQUALS("Wrong minimum x obtained", 5, xDimension->getMaximum()); - TSM_ASSERT_EQUALS("Wrong maximum x obtained", -1.5, xDimension->getMinimum()); - dataSet->Delete(); -} - -void testGetYDimension() -{ - Mantid::VATES::RebinningCutterPresenter presenter; - vtkDataSet* dataSet = constructInputDataSet(); //Creates a vtkDataSet with fielddata containing geomtry xml. - Mantid::VATES::Dimension_sptr yDimension = presenter.getYDimensionFromDS(dataSet); - TSM_ASSERT_EQUALS("Wrong number of y dimension bins", 5, yDimension->getNBins()); - TSM_ASSERT_EQUALS("Wrong minimum y obtained", 6.6, yDimension->getMaximum()); - TSM_ASSERT_EQUALS("Wrong maximum y obtained", -6.6, yDimension->getMinimum()); - dataSet->Delete(); -} - -void testGetZDimension() -{ - Mantid::VATES::RebinningCutterPresenter presenter; - vtkDataSet* dataSet = constructInputDataSet(); //Creates a vtkDataSet with fielddata containing geomtry xml. - Mantid::VATES::Dimension_sptr zDimension = presenter.getZDimensionFromDS(dataSet); - TSM_ASSERT_EQUALS("Wrong number of z dimension bins", 5, zDimension->getNBins()); - TSM_ASSERT_EQUALS("Wrong minimum z obtained", -6.6, zDimension->getMinimum()); - TSM_ASSERT_EQUALS("Wrong maximum z obtained", 6.6, zDimension->getMaximum()); - dataSet->Delete(); -} - -void testGettDimension() -{ - Mantid::VATES::RebinningCutterPresenter presenter; - vtkDataSet* dataSet = constructInputDataSet(); //Creates a vtkDataSet with fielddata containing geomtry xml. - Mantid::VATES::Dimension_sptr tDimension = presenter.getTDimensionFromDS(dataSet); - TSM_ASSERT_EQUALS("Wrong number of z dimension bins", 5, tDimension->getNBins()); - TSM_ASSERT_EQUALS("Wrong minimum t obtained", 0, tDimension->getMinimum()); - TSM_ASSERT_EQUALS("Wrong maximum t obtained", 150, tDimension->getMaximum()); - dataSet->Delete(); -} - void testGetWorkspaceGeometryThrows() { Mantid::VATES::RebinningCutterPresenter presenter; diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetFactoryTest.h index 5da57e9dd67e8f5aa9bcae3e71937f738e916d75..9df7f6ad1d72f22836f3cb0f961bccaff5c5d499 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetFactoryTest.h @@ -2,94 +2,70 @@ #ifndef VTKDATASETFACTORYTEST_H_ #define VTKDATASETFACTORYTEST_H_ -#include "MantidMDAlgorithms/Load_MDWorkspace.h" -#include "MDDataObjects/MDWorkspace.h" +#include "MantidVatesAPI/vtkDataSetFactory.h" +#include <cxxtest/TestSuite.h> #include <gmock/gmock.h> #include <gtest/gtest.h> +#include "vtkDataSet.h" +#include "vtkFloatArray.h" - -class vtkDataSetFactoryTest +class vtkDataSetFactoryTest : public CxxTest::TestSuite { -protected: +private: - /// Geometry Policy utilises compile-time polymorphism in vtkDataSetFactories - /// for testing purposes. Otherwise too unwieldy to generate MDGeometry from scratch. - class GeometryPolicy + class MockvtkDataSetFactory : public Mantid::VATES::vtkDataSetFactory { public: - - GeometryPolicy(int i, int j, int k, int t) : m_i(i), m_j(j), m_k(k), m_t(t) - { - } - - boost::shared_ptr<Mantid::Geometry::IMDDimension> getXDimension() const - { - using namespace Mantid::Geometry; - MDDimension* dimension = new MDDimension("qx"); - dimension->setRange(0, 1, m_i); - return boost::shared_ptr<IMDDimension>(dimension); - } - boost::shared_ptr<Mantid::Geometry::IMDDimension> getYDimension() const + MOCK_CONST_METHOD0(create, + vtkDataSet*()); + MOCK_CONST_METHOD0(createMeshOnly, + vtkDataSet*()); + MOCK_CONST_METHOD0(createScalarArray, + vtkFloatArray*()); + MOCK_METHOD1(initialize, + void(boost::shared_ptr<Mantid::API::IMDWorkspace>)); + MOCK_CONST_METHOD0(validate, + void()); + MOCK_CONST_METHOD0(getFactoryTypeName, std::string()); + void SetSuccessorConcrete(vtkDataSetFactory* pSuccessor) { - using namespace Mantid::Geometry; - MDDimension* dimension = new MDDimension("qy"); - dimension->setRange(0, 1, m_j); - return boost::shared_ptr<IMDDimension>(dimension); + return vtkDataSetFactory::SetSuccessor(pSuccessor); } - boost::shared_ptr<Mantid::Geometry::IMDDimension> getZDimension() const + bool hasSuccessorConcrete() const { - using namespace Mantid::Geometry; - MDDimension* dimension = new MDDimension("qz"); - dimension->setRange(0, 1, m_k); - return boost::shared_ptr<IMDDimension>(dimension); - } - boost::shared_ptr<Mantid::Geometry::IMDDimension> getTDimension() const - { - using namespace Mantid::Geometry; - MDDimension* dimension = new MDDimension("t"); - dimension->setRange(0, 1, m_t); - return boost::shared_ptr<IMDDimension>(dimension); - } - - private: - const int m_i; - const int m_j; - const int m_k; - const int m_t; - }; - - /// Image Policy utilises compile-time polymorphism in vtkDataSetFactories - /// for testing purposes. Otherwise too unwieldy to generate MDImage from scratch. - class ImagePolicy - { - - - public: - /// Embedded type information - typedef GeometryPolicy GeometryType; - /// Get the Geometry - ImagePolicy(int i, int j, int k, int t): m_geometry(i, j, k, t) - { + return vtkDataSetFactory::hasSuccessor(); } + }; - GeometryType* getGeometry() - { - return &m_geometry; - } - /// Get the MDImagePoint - Mantid::MDDataObjects::MD_image_point getPoint(int i, int j, int k, int t) const - { - Mantid::MDDataObjects::MD_image_point point; - point.s = i; - return point; - } +public: - private: - GeometryPolicy m_geometry; - }; + void testSetSuccessor() + { + MockvtkDataSetFactory factory; + MockvtkDataSetFactory* pSuccessor = new MockvtkDataSetFactory; + + EXPECT_CALL(factory, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); + EXPECT_CALL(*pSuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeB")); //Different type name, so setting the successor should work. + factory.SetSuccessor(pSuccessor); + + TSM_ASSERT("Successor should have been set", factory.hasSuccessor()); + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(&factory)); + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(pSuccessor)); + } + + void testSetSuccessorThrows() + { + MockvtkDataSetFactory factory; + MockvtkDataSetFactory* pSuccessor = new MockvtkDataSetFactory; + EXPECT_CALL(factory, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); + EXPECT_CALL(*pSuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); //Same type name. should NOT work. + TSM_ASSERT_THROWS("By default, should throw when successor type is the same as the container.", factory.SetSuccessor(pSuccessor), std::runtime_error); + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(&factory)); + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(pSuccessor)); + } }; diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToGeometryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToGeometryTest.h new file mode 100644 index 0000000000000000000000000000000000000000..f8343885bc09bfe6f89fe97162682c47b4635fd7 --- /dev/null +++ b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToGeometryTest.h @@ -0,0 +1,203 @@ + +#ifndef VTKDATASET_TO_GEOMETRY_TEST_H_ +#define VTKDATASET_TO_GEOMETRY_TEST_H_ + +#include "MantidVatesAPI/vtkDataSetToGeometry.h" + +#include <cxxtest/TestSuite.h> + +#include "vtkFieldData.h" +#include "vtkCharArray.h" +#include "vtkRectilinearGrid.h" + +#include "MantidVatesAPI/RebinningCutterXMLDefinitions.h" + +class vtkDataSetToGeometryTest : public CxxTest::TestSuite +{ + +private: + +// Helper method. Creates xml required as input for geometry. Allows mappings to be specified via function parameters. + static std::string constructXML(const std::string& xDimensionIdMapping, const std::string& yDimensionIdMapping, const std::string& zDimensionIdMapping, const std::string& tDimensionIdMapping) +{ + return std::string("<?xml version=\"1.0\" encoding=\"utf-8\"?>") + +"<MDInstruction>" + + "<DimensionSet>" + + "<Dimension ID=\"en\">" + + "<Name>Energy</Name>" + + "<UpperBounds>150</UpperBounds>" + + "<LowerBounds>0</LowerBounds>" + + "<NumberOfBins>5</NumberOfBins>" + + "</Dimension>" + + "<Dimension ID=\"qx\">" + + "<Name>Qx</Name>" + + "<UpperBounds>5</UpperBounds>" + + "<LowerBounds>-1.5</LowerBounds>" + + "<NumberOfBins>5</NumberOfBins>" + + "</Dimension>" + + "<Dimension ID=\"qy\">" + + "<Name>Qy</Name>" + + "<UpperBounds>6.6</UpperBounds>" + + "<LowerBounds>-6.6</LowerBounds>" + + "<NumberOfBins>5</NumberOfBins>" + + "</Dimension>" + + "<Dimension ID=\"qz\">" + + "<Name>Qz</Name>" + + "<UpperBounds>6.6</UpperBounds>" + + "<LowerBounds>-6.6</LowerBounds>" + + "<NumberOfBins>5</NumberOfBins>" + + "</Dimension>" + + "<XDimension>" + + "<RefDimensionId>" + + xDimensionIdMapping + + "</RefDimensionId>" + + "</XDimension>" + + "<YDimension>" + + "<RefDimensionId>" + + yDimensionIdMapping + + "</RefDimensionId>" + + "</YDimension>" + + "<ZDimension>" + + "<RefDimensionId>" + + zDimensionIdMapping + + "</RefDimensionId>" + + "</ZDimension>" + + "<TDimension>" + + "<RefDimensionId>" + + tDimensionIdMapping + + "</RefDimensionId>" + + "</TDimension>" + + "</DimensionSet>" + +"</MDInstruction>"; + } + + +static vtkFieldData* createFieldDataWithCharArray(std::string testData, std::string id) +{ + vtkFieldData* fieldData = vtkFieldData::New(); + vtkCharArray* charArray = vtkCharArray::New(); + charArray->SetName(id.c_str()); + charArray->Allocate(100); + for(unsigned int i = 0; i < testData.size(); i++) + { + char cNextVal = testData.at(i); + if(int(cNextVal) > 1) + { + charArray->InsertNextValue(cNextVal); + + } + } + fieldData->AddArray(charArray); + charArray->Delete(); + return fieldData; +} + +public: + + void testNoDimensionMappings() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("", "", "", ""), Mantid::VATES::XMLDefinitions::metaDataId())); // No mappings + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension mappings are absent. No dimension should have been set.", xmlParser.getYDimension().get() == NULL); + TSM_ASSERT("Y dimension mappings are absent. No dimension should have been set.", xmlParser.getYDimension().get() == NULL); + TSM_ASSERT("Z dimension mappings are absent. No dimension should have been set.", xmlParser.getZDimension().get() == NULL); + TSM_ASSERT("T dimension mappings are absent. No dimension should have been set.", xmlParser.getTDimension().get() == NULL); + data->Delete(); + } + + void testGetXDimension() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("en", "", "", ""), Mantid::VATES::XMLDefinitions::metaDataId())); // Only x + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension should have been extracted via its mappings", xmlParser.getXDimension().get() != NULL); + TSM_ASSERT("Y dimension mappings are absent. No dimension should have been set.", xmlParser.getYDimension().get() == NULL); + TSM_ASSERT("Z dimension mappings are absent. No dimension should have been set.", xmlParser.getZDimension().get() == NULL); + TSM_ASSERT("T dimension mappings are absent. No dimension should have been set.", xmlParser.getTDimension().get() == NULL); + data->Delete(); + } + + void testGetYDimension() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("", "en", "", ""), Mantid::VATES::XMLDefinitions::metaDataId())); // Only y + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension mappings are absent. No dimension should have been set.", xmlParser.getXDimension().get() == NULL); + TSM_ASSERT("Y dimension should have been extracted via its mappings", xmlParser.getYDimension().get() != NULL); + TSM_ASSERT("Z dimension mappings are absent. No dimension should have been set.", xmlParser.getZDimension().get() == NULL); + TSM_ASSERT("T dimension mappings are absent. No dimension should have been set.", xmlParser.getTDimension().get() == NULL); + data->Delete(); + } + + void testGetZDimension() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("", "", "en", ""), Mantid::VATES::XMLDefinitions::metaDataId())); // Only z + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension mappings are absent. No dimension should have been set.", xmlParser.getXDimension().get() == NULL); + TSM_ASSERT("Y dimension mappings are absent. No dimension should have been set.", xmlParser.getYDimension().get() == NULL); + TSM_ASSERT("Z dimension should have been extracted via its mappings", xmlParser.getZDimension().get() != NULL); + TSM_ASSERT("T dimension mappings are absent. No dimension should have been set.", xmlParser.getTDimension().get() == NULL); + data->Delete(); + } + + void testGetTDimension() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("", "", "", "en"), Mantid::VATES::XMLDefinitions::metaDataId())); // Only t + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension mappings are absent. No dimension should have been set.", xmlParser.getXDimension().get() == NULL); + TSM_ASSERT("Y dimension mappings are absent. No dimension should have been set.", xmlParser.getYDimension().get() == NULL); + TSM_ASSERT("Z dimension mappings are absent. No dimension should have been set.", xmlParser.getZDimension().get() == NULL); + TSM_ASSERT("T dimension should have been extracted via its mappings", xmlParser.getTDimension().get() != NULL); + data->Delete(); + } + + void testAllDimensions() + { + using namespace Mantid::VATES; + vtkRectilinearGrid* data = vtkRectilinearGrid::New(); + data->SetFieldData(createFieldDataWithCharArray(constructXML("qy", "qx", "en", "qz"), Mantid::VATES::XMLDefinitions::metaDataId())); // All configured. + + vtkDataSetToGeometry xmlParser(data); + xmlParser.execute(); + + TSM_ASSERT("X dimension should have been extracted via its mappings", xmlParser.getXDimension().get() != NULL); + TSM_ASSERT("Y dimension should have been extracted via its mappings", xmlParser.getYDimension().get() != NULL); + TSM_ASSERT("Z dimension should have been extracted via its mappings", xmlParser.getZDimension().get() != NULL); + TSM_ASSERT("T dimension should have been extracted via its mappings", xmlParser.getTDimension().get() != NULL); + + TSM_ASSERT_EQUALS("Wrong mapping for XDimension", "qy", xmlParser.getXDimension()->getDimensionId()); + TSM_ASSERT_EQUALS("Wrong mapping for YDimension", "qx", xmlParser.getYDimension()->getDimensionId()); + TSM_ASSERT_EQUALS("Wrong mapping for ZDimension", "en", xmlParser.getZDimension()->getDimensionId()); + TSM_ASSERT_EQUALS("Wrong mapping for TDimension", "qz", xmlParser.getTDimension()->getDimensionId()); + + data->Delete(); + } + + + +}; + +#endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkProxyFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkProxyFactoryTest.h index 874f0e86a9e8ed37b0011b7851d759b46b952095..f13e7d21ba218000c163f289955476aac3df149b 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkProxyFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkProxyFactoryTest.h @@ -56,6 +56,14 @@ public: inputProductB->Delete(); } + void testTypeName() + { + vtkRectilinearGrid* inputProduct = vtkRectilinearGrid::New(); + Mantid::VATES::vtkProxyFactory factory(inputProduct); + TS_ASSERT_EQUALS("vtkProxyFactory", factory.getFactoryTypeName()); + inputProduct->Delete(); + } + }; #endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkStructuredGridFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkStructuredGridFactoryTest.h index 0bd3f6a81d9c5162c57d1eae06f797f76de78732..2c4203ea859daa4eff05f4e0d936dbc1448d7427 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkStructuredGridFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkStructuredGridFactoryTest.h @@ -260,6 +260,13 @@ public: TSM_ASSERT_THROWS("No T dimension, so should not be possible to complete initialization.", factory.initialize(ws_sptr), std::runtime_error); } + void testTypeName() + { + using namespace Mantid::VATES; + vtkStructuredGridFactory<TimeStepToTimeStep> factory("signal", 1); + TS_ASSERT_EQUALS("vtkStructuredGridFactory", factory.getFactoryTypeName()); + } + }; #endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingHexahedronFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingHexahedronFactoryTest.h index ff6bdb075be9874be8d7128cba0146e3db738f62..0451593cccf7302cfad0533add45a58d89fcdd1e 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingHexahedronFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingHexahedronFactoryTest.h @@ -84,6 +84,8 @@ private: bool()); MOCK_CONST_METHOD0(validate, void()); + MOCK_CONST_METHOD0(getFactoryTypeName, std::string()); + }; public: @@ -203,6 +205,7 @@ private: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -249,6 +252,7 @@ private: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. EXPECT_CALL(*pMockFactorySuccessor, create()).Times(1); //expect it then to call create on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -265,6 +269,13 @@ private: TSM_ASSERT("successor factory not used as expected.", Mock::VerifyAndClearExpectations(pMockFactorySuccessor)); } + void testTypeName() + { + using namespace Mantid::VATES; + vtkThresholdingHexahedronFactory factory ("signal"); + TS_ASSERT_EQUALS("vtkThresholdingHexahedronFactory", factory.getFactoryTypeName()); + } + }; #endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingLineFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingLineFactoryTest.h index 7b4b91c31de9dedc96ca2034c3642d766f4d51f9..0e8f75392ae50b9ac3c0d9f39a3e2c5a6edeb3cd 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingLineFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingLineFactoryTest.h @@ -158,6 +158,7 @@ private: bool()); MOCK_CONST_METHOD0(validate, void()); + MOCK_CONST_METHOD0(getFactoryTypeName, std::string()); }; @@ -281,6 +282,7 @@ public: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -327,6 +329,7 @@ public: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. EXPECT_CALL(*pMockFactorySuccessor, create()).Times(1); //expect it then to call create on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -343,6 +346,13 @@ public: TSM_ASSERT("successor factory not used as expected.", Mock::VerifyAndClearExpectations(pMockFactorySuccessor)); } + void testTypeName() + { + using namespace Mantid::VATES; + vtkThresholdingLineFactory factory ("signal"); + TS_ASSERT_EQUALS("vtkThresholdingLineFactory", factory.getFactoryTypeName()); + } + }; #endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingQuadFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingQuadFactoryTest.h index c59771ef613cda9d436e64643796796672efad15..8277f227a93567cfa247650c3e7721822dad45d6 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingQuadFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingQuadFactoryTest.h @@ -158,6 +158,7 @@ private: bool()); MOCK_CONST_METHOD0(validate, void()); + MOCK_CONST_METHOD0(getFactoryTypeName, std::string()); }; @@ -280,6 +281,7 @@ public: EXPECT_CALL(*pMockWs, getNumDims()).Times(1).WillOnce(Return(1)); //1 dimensions on the workspace. MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -327,6 +329,7 @@ public: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. EXPECT_CALL(*pMockFactorySuccessor, create()).Times(1); //expect it then to call create on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -343,6 +346,14 @@ public: TSM_ASSERT("successor factory not used as expected.", Mock::VerifyAndClearExpectations(pMockFactorySuccessor)); } + + void testTypeName() + { + using namespace Mantid::VATES; + vtkThresholdingQuadFactory factory("signal"); + TS_ASSERT_EQUALS("vtkThresholdingQuadFactory", factory.getFactoryTypeName()); + } + }; #endif diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingUnstructuredGridFactoryTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingUnstructuredGridFactoryTest.h index 4ff275a401461bc443c26498e70fc33dfe8c6843..7f522a10ac6b00cc56dac61e97653d0eaada926d 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingUnstructuredGridFactoryTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkThresholdingUnstructuredGridFactoryTest.h @@ -86,6 +86,7 @@ private: bool()); MOCK_CONST_METHOD0(validate, void()); + MOCK_CONST_METHOD0(getFactoryTypeName, std::string()); }; public: @@ -212,6 +213,7 @@ private: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -260,6 +262,7 @@ private: MockvtkDataSetFactory* pMockFactorySuccessor = new MockvtkDataSetFactory; EXPECT_CALL(*pMockFactorySuccessor, initialize(_)).Times(1); //expect it then to call initialize on the successor. EXPECT_CALL(*pMockFactorySuccessor, create()).Times(1); //expect it then to call create on the successor. + EXPECT_CALL(*pMockFactorySuccessor, getFactoryTypeName()).WillOnce(testing::Return("TypeA")); Mantid::API::IMDWorkspace_sptr ws_sptr(pMockWs); @@ -277,6 +280,14 @@ private: TSM_ASSERT("successor factory not used as expected.", Mock::VerifyAndClearExpectations(pMockFactorySuccessor)); } + void testTypeName() + { + using namespace Mantid::VATES; + vtkThresholdingUnstructuredGridFactory<TimeStepToTimeStep> factory = + vtkThresholdingUnstructuredGridFactory<TimeStepToTimeStep> ("signal", (double)0); + TS_ASSERT_EQUALS("vtkThresholdingUnstructuredGridFactory", factory.getFactoryTypeName()); + } + }; #endif