diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/CMakeLists.txt index bb5bd29e3383ebce30e834e526f7b53573583e2b..b8fbd101c3b0faebb0ba092e7f052061fb577daa 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/CMakeLists.txt +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/CMakeLists.txt @@ -1,4 +1,5 @@ -add_subdirectory( SQWReader ) +add_subdirectory( SQWReader ) #Candidate for removal +add_subdirectory( SQWEventReader ) add_subdirectory( EventNexusReader ) add_subdirectory( PeaksReader ) diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..721a4279ba14d4fa47645278d2250690867dbbbe --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/CMakeLists.txt @@ -0,0 +1,17 @@ +project( MantidParaViewSQWEventReader ) + +add_paraview_plugin( MantidParaViewSQWEventReaderSMPlugin "1.0" + SERVER_MANAGER_XML SQWEventReader.xml + SERVER_MANAGER_SOURCES vtkSQWEventReader.cxx + GUI_RESOURCE_FILES SQWEventReaderGUI.xml +) + +target_link_libraries( MantidParaViewSQWEventReaderSMPlugin +${MANTID_SUBPROJECT_LIBS} ) + +# Put library into subfolder. +output_binary_to(MantidParaViewSQWEventReaderSMPlugin ${PVPLUGINS_DIR}) + +install( TARGETS MantidParaViewSQWEventReaderSMPlugin ${TARGET_TYPE} DESTINATION ${PVPLUGINS_DIR} ) + + diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReader.xml b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReader.xml new file mode 100644 index 0000000000000000000000000000000000000000..c79de6fca7ee721fa4e1338f3d7a6aeb184aea3b --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReader.xml @@ -0,0 +1,86 @@ +<ServerManagerConfiguration> + <!-- Begin SQWEventReader --> + <ProxyGroup name="sources"> + <SourceProxy name="SQWEventReader" class="vtkSQWEventReader"> + <ProxyProperty name="ClipFunction" command="SetClipFunction" label="Rebinning Cut Type"> + <ProxyGroupDomain name="groups"> + <Group name="implicit_functions"/> + </ProxyGroupDomain> + <ProxyListDomain name="proxy_list"> + <Proxy group="implicit_functions" name="Plane" /> + </ProxyListDomain> + <Documentation> + This property specifies the parameters of the clip function (an implicit plane) used to clip/rebin the dataset. + </Documentation> + </ProxyProperty> + <IntVectorProperty + name="Apply Clipping" + command="SetApplyClip" + number_of_elements="1" + default_values="0"> + <BooleanDomain name="bool"/> + </IntVectorProperty> + <DoubleVectorProperty + name="Plane Width" + command="SetWidth" + number_of_elements="1" + default_values="1"> + </DoubleVectorProperty> + <DoubleVectorProperty + name="MinThreshold" + command="SetMinThreshold" + number_of_elements="1" + default_values="0.1" + > + </DoubleVectorProperty> + <DoubleVectorProperty + name="MaxThreshold" + command="SetMaxThreshold" + number_of_elements="1" + default_values="10000"> + </DoubleVectorProperty> + <StringVectorProperty + name="InputGeometryXML" + command="GetInputGeometryXML" + number_of_elements="1" + information_only="1"> + <SimpleStringInformationHelper /> + </StringVectorProperty> + <StringVectorProperty + name="AppliedGeometryXML" + command="SetAppliedGeometryXML" + number_of_elements="1" + default_values="--"> + </StringVectorProperty> + <StringVectorProperty + name="FileName" + command="SetFileName" + number_of_elements="1"> + <FileListDomain name="files"/> + </StringVectorProperty> + <StringVectorProperty + name="ThresholdRangeStrategyIndex" + command="SetThresholdRangeStrategyIndex" + number_of_elements="1" + default_values="0"> + </StringVectorProperty> + <DoubleVectorProperty + name="InputMinThreshold" + command="GetInputMinThreshold" + number_of_elements="1" + default_values="0.1" + information_only="1"> + <SimpleDoubleInformationHelper /> + </DoubleVectorProperty> + <DoubleVectorProperty + name="InputMaxThreshold" + command="GetInputMaxThreshold" + number_of_elements="1" + default_values="1000000" + information_only="1"> + <SimpleDoubleInformationHelper /> + </DoubleVectorProperty> + </SourceProxy> + </ProxyGroup> + <!-- End SQWEventReader --> +</ServerManagerConfiguration> \ No newline at end of file diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReaderGUI.xml b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReaderGUI.xml new file mode 100644 index 0000000000000000000000000000000000000000..9785318494254fea7283c4621153777ac022d3c5 --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/SQWEventReaderGUI.xml @@ -0,0 +1,6 @@ +<ParaViewReaders> + <Reader name="SQWEventReader" + extensions="sqw" + file_description="MD *.sqw format"> + </Reader> +</ParaViewReaders> \ No newline at end of file diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..59bde96caa91be771550e7ad929adf27f08dd762 --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.cxx @@ -0,0 +1,520 @@ +#include "vtkSQWEventReader.h" +#include "vtkInformation.h" +#include "vtkInformationVector.h" +#include "vtkObjectFactory.h" +#include "vtkMath.h" +#include "vtkCellArray.h" +#include "vtkCellData.h" +#include "vtkPointData.h" +#include "vtkTransform.h" +#include "vtkFloatArray.h" +#include "vtkStreamingDemandDrivenPipeline.h" +#include "vtkPlane.h" + +#include "MantidMDAlgorithms/PlaneImplicitFunction.h" +#include "MantidVatesAPI/TimeToTimeStep.h" +#include "MantidVatesAPI/vtkThresholdingUnstructuredGridFactory.h" +#include "MantidVatesAPI/vtkThresholdingHexahedronFactory.h" +#include "MantidVatesAPI/vtkThresholdingQuadFactory.h" +#include "MantidVatesAPI/vtkThresholdingLineFactory.h" +#include "MantidVatesAPI/MultiDimensionalDbPresenter.h" +#include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidVatesAPI/UserDefinedThresholdRange.h" +#include "MantidVatesAPI/GaussianThresholdRange.h" +#include "MantidVatesAPI/UserDefinedThresholdRange.h" +#include "MantidVatesAPI/NoThresholdRange.h" +#include "MantidVatesAPI/IgnoreZerosThresholdRange.h" +#include "MantidVatesAPI/MedianAndBelowThresholdRange.h" +#include "MantidGeometry/MDGeometry/MDGeometryXMLParser.h" + +#include <boost/format.hpp> +#include "MantidMDEvents/MDEventWorkspace.h" +#include "MantidMDEvents/BinToMDHistoWorkspace.h" +#include "MantidDataHandling/LoadInstrument.h" +#include "MantidMDEvents/LoadSQW.h" +#include "MantidAPI/IMDEventWorkspace.h" + +#include "MantidMDAlgorithms/PlaneImplicitFunction.h" +#include "MantidGeometry/MDGeometry/IMDDimensionFactory.h" +#include "MantidGeometry/MDGeometry/MDDimension.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" + +vtkCxxRevisionMacro(vtkSQWEventReader, "$Revision: 1.0 $"); +vtkStandardNewMacro(vtkSQWEventReader); + +using namespace Mantid::VATES; +using Mantid::Geometry::IMDDimension_sptr; +using Mantid::Geometry::IMDDimension_sptr; +using Mantid::Geometry::MDHistoDimension; +using Mantid::Geometry::MDHistoDimension_sptr; + +vtkSQWEventReader::vtkSQWEventReader() : + m_presenter(), + m_isSetup(false), + m_clipFunction(NULL), + m_mdEventWsId("eventWsId"), + m_histogrammedWsId("histogramWsId") +{ + this->FileName = NULL; + this->SetNumberOfInputPorts(0); + this->SetNumberOfOutputPorts(1); + //On first-pass rebinning is necessary. + m_actionManager.ask(RecalculateAll); +} + +vtkSQWEventReader::~vtkSQWEventReader() +{ + this->SetFileName(0); +} + + +void vtkSQWEventReader::configureThresholdRangeMethod() +{ + switch(m_thresholdMethodIndex) + { + case 0: + m_ThresholdRange = ThresholdRange_scptr(new IgnoreZerosThresholdRange()); + break; + case 1: + m_ThresholdRange = ThresholdRange_scptr(new NoThresholdRange()); + break; + case 2: + m_ThresholdRange = ThresholdRange_scptr(new MedianAndBelowThresholdRange()); + break; + case 3: + m_ThresholdRange = ThresholdRange_scptr(new UserDefinedThresholdRange(m_minThreshold, m_maxThreshold)); + break; + } +} + +/** + Sets number of bins for x dimension. + @param nbins : Number of bins for the x dimension. +*/ +void vtkSQWEventReader::SetXBins(int nbins) +{ + if(nbins != m_nXBins) + { + m_nXBins = nbins; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets number of bins for x dimension. + @param nbins : Number of bins for the x dimension. +*/ +void vtkSQWEventReader::SetYBins(int nbins) +{ + if(nbins != m_nYBins) + { + m_nYBins = nbins; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets number of bins for y dimension. + @param nbins : Number of bins for the x dimension. +*/ +void vtkSQWEventReader::SetZBins(int nbins) +{ + if(nbins != m_nZBins) + { + m_nZBins = nbins; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets maximum threshold for rendering. + @param maxThreshold : Maximum threshold value. +*/ +void vtkSQWEventReader::SetMaxThreshold(double maxThreshold) +{ + if(maxThreshold != m_maxThreshold) + { + m_maxThreshold = maxThreshold; + this->Modified(); + m_actionManager.ask(RecalculateVisualDataSetOnly); + } +} + +/** + Sets minimum threshold for rendering. + @param minThreshold : Minimum threshold value. +*/ +void vtkSQWEventReader::SetMinThreshold(double minThreshold) +{ + if(minThreshold != m_minThreshold) + { + m_minThreshold = minThreshold; + this->Modified(); + m_actionManager.ask(RecalculateVisualDataSetOnly); + } +} + +/** + Sets clipping. + @param applyClip : true if clipping should be applied. +*/ +void vtkSQWEventReader::SetApplyClip(bool applyClip) +{ + if(m_applyClip != applyClip) + { + m_applyClip = applyClip; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets width for plane. + @param width: width for plane. +*/ +void vtkSQWEventReader::SetWidth(double width) +{ + if(m_width.getValue() != width) + { + m_width = width; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets maximum threshold for rendering. + @param maxThreshold : Maximum threshold value. +*/ +void vtkSQWEventReader::SetClipFunction(vtkImplicitFunction* func) +{ + if(m_clipFunction != func) + { + m_clipFunction = func; + this->Modified(); + m_actionManager.ask(RecalculateAll); + } +} + +/** + Sets applied geometry xml. Provided by object panel. + @xml. Dimension xml. +*/ +void vtkSQWEventReader::SetAppliedGeometryXML(std::string appliedGeometryXML) +{ + if(m_isSetup) + { + //Create xml to represent the current applied geometry. + using namespace Mantid::Geometry; + MDGeometryBuilderXML<StrictDimensionPolicy> xmlBuilder; + xmlBuilder.addXDimension(m_appliedXDimension); + xmlBuilder.addYDimension(m_appliedYDimension); + xmlBuilder.addZDimension(m_appliedZDimension); + xmlBuilder.addTDimension(m_appliedTDimension); + const std::string existingGeometryXML = xmlBuilder.create(); + //If new xml has been provided and if that is different in any way from the existing. + if(!appliedGeometryXML.empty() && existingGeometryXML != appliedGeometryXML) + { + Mantid::Geometry::MDGeometryXMLParser xmlParser(appliedGeometryXML); + xmlParser.execute(); + + this->m_appliedXDimension = xmlParser.getXDimension(); + this->m_appliedYDimension = xmlParser.getYDimension(); + this->m_appliedZDimension = xmlParser.getZDimension(); + this->m_appliedTDimension = xmlParser.getTDimension(); + //TODO: This needs to be reworked. + MDGeometryBuilderXML<StrictDimensionPolicy> temp; + temp.addXDimension(m_appliedXDimension); + temp.addYDimension(m_appliedYDimension); + temp.addZDimension(m_appliedZDimension); + temp.addTDimension(m_appliedTDimension); + m_geometryXmlBuilder = temp; + + m_actionManager.ask(RecalculateAll); + this->Modified(); + } + } +} + +/** + Sets the selected index for the thresholding method. + @parameter selectedStrategyIndex : index as a string. +*/ +void vtkSQWEventReader::SetThresholdRangeStrategyIndex(std::string selectedStrategyIndex) +{ + int index = atoi(selectedStrategyIndex.c_str()); + if(index != m_thresholdMethodIndex) + { + m_thresholdMethodIndex = index; + this->Modified(); + } +} + + +/** + Gets the geometry xml from the workspace. Allows object panels to configure themeselves. + @return geometry xml const * char reference. +*/ +const char* vtkSQWEventReader::GetInputGeometryXML() +{ + return this->m_geometryXmlBuilder.create().c_str(); +} + +/** + Getter for the minimum threshold. + @return geometry xml const * char reference. +*/ +double vtkSQWEventReader::GetInputMinThreshold() +{ + return m_minThreshold; +} + +/** + Getter for the maximum threshold. + @return geometry xml const * char reference. +*/ +double vtkSQWEventReader::GetInputMaxThreshold() +{ + return m_maxThreshold; +} + +/** + Mantid properties for rebinning algorithm require formatted information. + @param dimension : dimension to extract property value for. + @return true available, false otherwise. + */ +std::string vtkSQWEventReader::extractFormattedPropertyFromDimension(Mantid::Geometry::IMDDimension_sptr dimension) const +{ + double min = dimension->getMinimum(); + double max = dimension->getMaximum(); + size_t 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 vtkSQWEventReader::doRebinning() +{ + Mantid::API::AnalysisDataService::Instance().remove(m_histogrammedWsId); + + Mantid::MDEvents::BinToMDHistoWorkspace hist_alg; + hist_alg.initialize(); + hist_alg.setPropertyValue("InputWorkspace", m_mdEventWsId); + 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]); + UpParameter up(normal.getY(), -normal.getX(), normal.getZ()); + Mantid::Kernel::V3D ax(normal.getX(), normal.getY(), normal.getZ()); + Mantid::Kernel::V3D ay(up.getX(), up.getY(), up.getZ()); + Mantid::Kernel::V3D az = ax.cross_prod(ay); + PerpendicularParameter perpendicular(az[0], az[1], az[2]); + if(ax.scalar_prod(ay) != 0) + { + throw std::logic_error("Normal and Up Vectors must be perpendicular"); + } + + PlaneImplicitFunction func(normal, origin, m_width); + hist_alg.setPropertyValue("ImplicitFunctionXML", func.toXMLString()); + } + } + + FilterUpdateProgressAction<vtkSQWEventReader> updatehandler(this); + // Run the algorithm and cache the output. + m_presenter.execute(hist_alg, m_histogrammedWsId, updatehandler); +} + + +int vtkSQWEventReader::RequestData(vtkInformation * vtkNotUsed(request), vtkInformationVector ** vtkNotUsed(inputVector), vtkInformationVector *outputVector) +{ + //get the info objects + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + configureThresholdRangeMethod(); + + vtkDataSet *output = vtkDataSet::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT())); + + + int time = 0; + if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS())) + { + // usually only one actual step requested + time = static_cast<int>(outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS())[0]); + } + + //When RecalculateAll wins-out, configure and run the rebinning algorithm. + if(RecalculateAll == m_actionManager.action()) + { + doRebinning(); + } + + // Chain of resposibility setup for visualisation. Encapsulates decision making on how workspace will be rendered. + std::string scalarName = "signal"; + vtkThresholdingLineFactory vtkGridFactory(m_ThresholdRange, scalarName); + vtkThresholdingQuadFactory* p_2dSuccessorFactory = new vtkThresholdingQuadFactory(m_ThresholdRange, scalarName); + vtkThresholdingHexahedronFactory* p_3dSuccessorFactory = new vtkThresholdingHexahedronFactory(m_ThresholdRange, scalarName); + vtkThresholdingUnstructuredGridFactory<TimeToTimeStep>* p_4dSuccessorFactory = new vtkThresholdingUnstructuredGridFactory<TimeToTimeStep>(m_ThresholdRange,scalarName, 0); + vtkGridFactory.SetSuccessor(p_2dSuccessorFactory); + p_2dSuccessorFactory->SetSuccessor(p_3dSuccessorFactory); + p_3dSuccessorFactory->SetSuccessor(p_4dSuccessorFactory); + + RebinningKnowledgeSerializer serializer(LocationNotRequired); //Object handles serialization of meta data. + + vtkDataSet * structuredMesh = vtkDataSet::SafeDownCast(m_presenter.getMesh(serializer, vtkGridFactory)); + + m_minThreshold = m_ThresholdRange->getMinimum(); + m_maxThreshold = m_ThresholdRange->getMaximum(); + output->ShallowCopy(structuredMesh); + + // Reset the action manager fresh for next cycle. + m_actionManager.reset(); + return 1; +} + +int vtkSQWEventReader::RequestInformation( + vtkInformation *vtkNotUsed(request), + vtkInformationVector **vtkNotUsed(inputVector), + vtkInformationVector *outputVector) +{ + using namespace Mantid::API; + using namespace Mantid::MDEvents; + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + //Ensure that the Event Workspace is only generated once + if(!m_isSetup) + { + AnalysisDataService::Instance().remove(m_mdEventWsId); + + Mantid::MDEvents::LoadSQW 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); + + // Now, we get the minimum extents in order to get nice default sizes + std::vector<Mantid::Geometry::MDDimensionExtents> ext = eventWs->getMinimumExtents(5); + std::vector<IMDDimension_sptr> defaultDimensions; + size_t nDimensions = eventWs->getNumDims(); + for (size_t d=0; d<nDimensions; d++) + { + IMDDimension_sptr inDim = eventWs->getDimension(d); + double min = (ext[d].min); + double max = (ext[d].max); + if (min > max) + { + min = 0.0; + max = 1.0; + } + //std::cout << "dim " << d << min << " to " << max << std::endl; + MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, size_t(10))); + defaultDimensions.push_back(dim); + } + + //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 = defaultDimensions[0]; + m_geometryXmlBuilder.addXDimension( m_appliedXDimension ); + } + if(nDimensions > 1) + { + m_appliedYDimension = defaultDimensions[1]; + m_geometryXmlBuilder.addYDimension( m_appliedYDimension ); + } + if(nDimensions > 2) + { + m_appliedZDimension = defaultDimensions[2]; + m_geometryXmlBuilder.addZDimension( m_appliedZDimension ); + } + if(nDimensions > 3) + { + m_appliedTDimension = defaultDimensions[3]; + m_geometryXmlBuilder.addTDimension( m_appliedTDimension ); + } + + m_isSetup = true; + + } + std::vector<double> timeStepValues(1); //TODO set time-step information. + outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &timeStepValues[0], static_cast<int>(timeStepValues.size())); + double timeRange[2]; + timeRange[0] = timeStepValues.front(); + timeRange[1] = timeStepValues.back(); + + outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2); + return 1; +} + +void vtkSQWEventReader::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} + +int vtkSQWEventReader::CanReadFile(const char* vtkNotUsed(fname)) +{ + return 1; //TODO: Apply checks here. +} + +unsigned long vtkSQWEventReader::GetMTime() +{ + unsigned long mTime = this->Superclass::GetMTime(); + unsigned long time; + + if (this->m_clipFunction != NULL) + { + + time = this->m_clipFunction->GetMTime(); + if(time > mTime) + { + mTime = time; + } + } + + return mTime; +} + +/** + Update/Set the progress. + @parameter progress : progress increment. +*/ +void vtkSQWEventReader::UpdateAlgorithmProgress(double progress) +{ + this->SetProgressText("Executing Mantid MDEvent Rebinning Algorithm..."); + this->UpdateProgress(progress); +} diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.h new file mode 100644 index 0000000000000000000000000000000000000000..7fe796e8c697062242d80c2b37343aabf11996af --- /dev/null +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewReaders/SQWEventReader/vtkSQWEventReader.h @@ -0,0 +1,160 @@ +#ifndef _vtkSQWEventReader_h +#define _vtkSQWEventReader_h +#include "vtkUnstructuredGridAlgorithm.h" +#include "MantidVatesAPI/MultiDimensionalDbPresenter.h" +#include "MantidMDAlgorithms/WidthParameter.h" +#include "MantidVatesAPI/EscalatingRebinningActionManager.h" +#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" +#include "MantidVatesAPI/ThresholdRange.h" + +class vtkImplicitFunction; +class VTK_EXPORT vtkSQWEventReader : public vtkUnstructuredGridAlgorithm +{ +public: + static vtkSQWEventReader *New(); + vtkTypeRevisionMacro(vtkSQWEventReader,vtkUnstructuredGridAlgorithm); + void PrintSelf(ostream& os, vtkIndent indent); + vtkSetStringMacro(FileName); + vtkGetStringMacro(FileName); + int CanReadFile(const char* fname); + void SetXBins(int x); + void SetYBins(int y); + void SetZBins(int z); + void SetMaxThreshold(double maxThreshold); + void SetMinThreshold(double minThreshold); + void SetWidth(double width); + void SetApplyClip(bool applyClip); + void SetClipFunction( vtkImplicitFunction * func); + void SetThresholdRangeStrategyIndex(std::string selectedStrategyIndex); + double GetInputMinThreshold(); + double GetInputMaxThreshold(); + /// Called by presenter to force progress information updating. + void UpdateAlgorithmProgress(double progress); + + void SetAppliedGeometryXML(std::string xml); + + const char* GetInputGeometryXML(); + +protected: + vtkSQWEventReader(); + ~vtkSQWEventReader(); + int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + int Canreadfile(const char *fname); + ///Handle time variation. + unsigned long GetMTime(); + +private: + + vtkSQWEventReader(const vtkSQWEventReader&); + + void operator = (const vtkSQWEventReader&); + + std::string extractFormattedPropertyFromDimension(Mantid::Geometry::IMDDimension_sptr dimension) const; + + void doRebinning(); + + /// Set-up a strategy for thresholding. + void configureThresholdRangeMethod(); + + /** + 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; + + /// Controller/Presenter. + Mantid::VATES::MultiDimensionalDbPresenter m_presenter; + + /// Number of x bins set + int m_nXBins; + + /// Number of y bins set. + int m_nYBins; + + /// Number of z bins set. + int m_nZBins; + + /// Flag indicates when set up is complete wrt the conversion of the nexus file to a MDEventWorkspace stored in ADS. + bool m_isSetup; + + /// The maximum threshold of counts for the visualisation. + double m_maxThreshold; + + /// The minimum threshold of counts for the visualisation. + double m_minThreshold; + + /// Flag indicating that clipping of some kind should be considered. + bool m_applyClip; + + /// vtkImplicit function from which to determine how the cut is to be made. + vtkImplicitFunction* m_clipFunction; + + /// With parameter (applied to plane with width). + Mantid::MDAlgorithms::WidthParameter m_width; + + /// MD Event Workspace id. strictly could be made static rather than an instance member. + const std::string m_mdEventWsId; + + /// MD Histogram(IMD) Workspace id. strictly could be made static rather than an instance member. + const std::string m_histogrammedWsId; + + /// 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 + Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::StrictDimensionPolicy> 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; + + int m_thresholdMethodIndex; + + Mantid::VATES::ThresholdRange_scptr m_ThresholdRange; +}; +#endif diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt index 0b85110ee3daa4e270eabbca49cbfda4f29409ef..912161b33630e5e0b5e646356e32a1997636bcf6 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/EventNexusReaderObjectPanel/CMakeLists.txt @@ -9,6 +9,9 @@ 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_object_panel( IFACES IFACE_SRCS + CLASS_NAME EventNexusReaderObjectPanel + XML_NAME SQWEventReader XML_GROUP sources ) add_paraview_plugin( MantidParaViewEventNexusReaderObjectPanel "1.0" GUI_INTERFACES ${IFACES} SOURCES ${MOC_SRCS} ${IFACE_SRCS} ${INCLUDE_FILES}