Skip to content

Commit

Permalink
Refs #11053 Update peaks filter
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Mar 6, 2015
1 parent 6c1d583 commit 8c81d2f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 23 deletions.
Expand Up @@ -2,9 +2,11 @@
#include "MantidVatesAPI/vtkDataSetToPeaksFilteredDataSet.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidVatesAPI/FilteringUpdateProgressAction.h"
#include "MantidVatesAPI/FieldDataToMetadata.h"
#include "MantidVatesAPI/MetadataJsonManager.h"
#include "MantidVatesAPI/VatesConfigurations.h"

#include <boost/scoped_ptr.hpp>

#include <vtkInformation.h>
Expand All @@ -18,9 +20,14 @@ vtkStandardNewMacro(vtkPeaksFilter);

using namespace Mantid::VATES;

vtkPeaksFilter::vtkPeaksFilter() : m_peaksWorkspaceName(""),
vtkPeaksFilter::vtkPeaksFilter() : m_peaksWorkspaceNames(""),
m_delimiter(";"),
m_radiusNoShape(0.5),
m_radiusType(0)
m_radiusType(0),
m_minValue(0.1),
m_maxValue(0.1),
m_metadataJsonManager(new MetadataJsonManager()),
m_vatesConfigurations(new VatesConfigurations())
{
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(1);
Expand All @@ -39,18 +46,22 @@ int vtkPeaksFilter::RequestData(vtkInformation*, vtkInformationVector **inputVec
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkUnstructuredGrid *outputDataSet = vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

// Get the peaks workspace
if (!Mantid::API::AnalysisDataService::Instance().doesExist(m_peaksWorkspaceName))
#if 1
std::vector<std::string> peaksWorkspaceNames = extractPeakWorkspaceNames();
std::vector<Mantid::API::IPeaksWorkspace_sptr> peaksWorkspaces = getPeaksWorkspaces(peaksWorkspaceNames);

if (peaksWorkspaces.empty())
{
return 0;
return 0;
}

Mantid::API::IPeaksWorkspace_sptr peaksWorkspace = Mantid::API::AnalysisDataService::Instance().retrieveWS<Mantid::API::IPeaksWorkspace>(m_peaksWorkspaceName);
FilterUpdateProgressAction<vtkPeaksFilter> drawingProgressUpdate(this, "Drawing...");

vtkDataSetToPeaksFilteredDataSet peaksFilter(inputDataSet, outputDataSet);
peaksFilter.initialize(peaksWorkspace, m_radiusNoShape, m_radiusType);
peaksFilter.execute();

peaksFilter.initialize(peaksWorkspaces, m_radiusNoShape, m_radiusType);
peaksFilter.execute(drawingProgressUpdate);
#else
outputDataSet->ShallowCopy(inputDataSet);
#endif
return 1;
}

Expand All @@ -60,19 +71,25 @@ int vtkPeaksFilter::RequestInformation(vtkInformation*, vtkInformationVector** i
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkUnstructuredGrid *inputDataSet = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));

vtkFieldData* fieldData = inputDataSet->GetFieldData();
// If the field data does not contain the metadata, then don't do anything.
try
{
vtkFieldData* fieldData = inputDataSet->GetFieldData();

// Extract information for meta data in Json format.
FieldDataToMetadata fieldDataToMetadata;
// Extract information for meta data in Json format.
FieldDataToMetadata fieldDataToMetadata;

#if 0
std::string jsonString = fieldDataToMetadata(fieldData, m_vatesConfigurations->getMetadataIdJson());
m_metadataJsonManager->readInSerializedJson(jsonString);
std::string jsonString = fieldDataToMetadata(fieldData, m_vatesConfigurations->getMetadataIdJson());
m_metadataJsonManager->readInSerializedJson(jsonString);

m_minValue = m_metadataJsonManager->getMinValue();
m_maxValue = m_metadataJsonManager->getMaxValue();
m_instrument = m_metadataJsonManager->getInstrument();
}
catch (...)
{
}

m_minValue = m_metadataJsonManager->getMinValue();
m_maxValue = m_metadataJsonManager->getMaxValue();
m_instrument = m_metadataJsonManager->getInstrument();
#endif
return 1;
}

Expand All @@ -87,7 +104,7 @@ void vtkPeaksFilter::PrintSelf(ostream& os, vtkIndent indent)
*/
void vtkPeaksFilter::SetPeaksWorkspace(std::string peaksWorkspaceName)
{
m_peaksWorkspaceName = peaksWorkspaceName;
m_peaksWorkspaceNames = peaksWorkspaceName;
}

/**
Expand All @@ -109,3 +126,99 @@ void vtkPeaksFilter::SetRadiusType(int type)
m_radiusType = type;
this->Modified();
}

/**
* Updates the progress bar.
* @param progress Progress indicator.
* @param message Progress message.
*/
void vtkPeaksFilter::updateAlgorithmProgress(double progress, const std::string& message)
{
this->SetProgressText(message.c_str());
this->UpdateProgress(progress);
}

/**
* Extract the names of the peaks workspaces.
* @returns A list of peaks workspace names.
*/
std::vector<std::string> vtkPeaksFilter::extractPeakWorkspaceNames()
{
// Split the string in to bits
size_t pos = 0;
std::string peakNames = m_peaksWorkspaceNames;
std::vector<std::string> peaksWorkspaceNamesList;
std::string token;
while ((pos = peakNames.find(m_delimiter)) != std::string::npos) {
token = peakNames.substr(0, pos);
peaksWorkspaceNamesList.push_back(token);
peakNames.erase(0, pos + m_delimiter.length());
}

// If there was only one element in there then push it
if (peaksWorkspaceNamesList.empty()) {
peaksWorkspaceNamesList.push_back(peakNames);
}

return peaksWorkspaceNamesList;
}

/**
* Set the delimiter for concatenated workspace names.
* @param delimiter The workspace name delimiter
*/
void vtkPeaksFilter::SetDelimiter(std::string delimiter){
m_delimiter = delimiter;
this->Modified();
}


/**
* Get a list of peaks workspace pointers
* @returns A list of peaks workspace pointers.
*/
std::vector<Mantid::API::IPeaksWorkspace_sptr> vtkPeaksFilter::getPeaksWorkspaces(std::vector<std::string> peaksWorkspaceNames)
{
std::vector<Mantid::API::IPeaksWorkspace_sptr> peaksWorkspaces;

for (std::vector<std::string>::iterator it = peaksWorkspaceNames.begin(); it != peaksWorkspaceNames.end(); ++it)
{
// Check if the peaks workspace exists
if (!Mantid::API::AnalysisDataService::Instance().doesExist(*it))
{
continue;
}
peaksWorkspaces.push_back(Mantid::API::AnalysisDataService::Instance().retrieveWS<Mantid::API::IPeaksWorkspace>(*it));
}

return peaksWorkspaces;
}

/**
* Gets the minimum value of the data associated with the
* workspace.
* @returns The minimum value of the workspace data.
*/
double vtkPeaksFilter::GetMinValue()
{
return m_minValue;
}

/**
* Gets the maximum value of the data associated with the
* workspace.
* @returns The maximum value of the workspace data.
*/
double vtkPeaksFilter::GetMaxValue(){

return m_maxValue;
}

/**
* Getst the insturment name
* @returns The name of the instrument.
*/
const char* vtkPeaksFilter::GetInstrument() {
return m_instrument.c_str();
}

@@ -1,6 +1,7 @@
#ifndef _VTKPEAKSFILTER_h
#define _VTKPEAKSFILTER_h
#include "vtkUnstructuredGridAlgorithm.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidVatesAPI/MetadataJsonManager.h"
#include "MantidVatesAPI/VatesConfigurations.h"
#include <boost/scoped_ptr.hpp>
Expand All @@ -15,16 +16,23 @@ class VTK_EXPORT vtkPeaksFilter : public vtkUnstructuredGridAlgorithm
void SetPeaksWorkspace(std::string peaksWorkspaceName);
void SetRadiusNoShape(double radius);
void SetRadiusType(int type);
void SetDelimiter(std::string delimiter);
void updateAlgorithmProgress(double progress, const std::string& message);
double GetMinValue();
double GetMaxValue();
const char* GetInstrument();
protected:
vtkPeaksFilter();
~vtkPeaksFilter();
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);

private:
vtkPeaksFilter(const vtkPeaksFilter&);
void operator = (const vtkPeaksFilter&);
std::string m_peaksWorkspaceName;
std::vector<std::string> extractPeakWorkspaceNames();
std::vector<Mantid::API::IPeaksWorkspace_sptr> getPeaksWorkspaces(std::vector<std::string> peaksWorkspaceNames);
std::string m_peaksWorkspaceNames;
std::string m_delimiter;
double m_radiusNoShape;
int m_radiusType;
double m_minValue;
Expand Down

0 comments on commit 8c81d2f

Please sign in to comment.