Skip to content

Commit

Permalink
Refs #6541. First cut at axis labels.
Browse files Browse the repository at this point in the history
This first pass gets things working for the NeXus reader.
  • Loading branch information
Michael Reuter committed Feb 7, 2013
1 parent 2afe50c commit 8fe88e7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ int vtkMDEWNexusReader::RequestData(vtkInformation * vtkNotUsed(request), vtkInf
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->ShallowCopy(clipperOutput);

m_presenter->setAxisLabels(output);

clipper->Delete();

return 1;
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/Common.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef MANTID_VATES_COMMON_H_
#define MANTID_VATES_COMMON_H_
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>

class vtkFieldData;

namespace Mantid
{
Expand Down Expand Up @@ -31,6 +33,12 @@ enum RebinningIterationAction {
ReloadAndRecalculateAll // Reload the original workspace and then Rebin it.
};

std::string makeAxisTitle(Dimension_const_sptr dim);

void setAxisLabel(std::string metadataLabel,
std::string labelString,
vtkFieldData *fieldData);

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Mantid
const std::string& getGeometryXML() const;
virtual bool hasTDimensionAvailable() const;
virtual std::vector<double> getTimeStepValues() const;
virtual void setAxisLabels(vtkDataSet* visualDataSet);
virtual ~MDEWLoadingPresenter();
protected:
/*---------------------------------------------------------------------------
Expand All @@ -54,8 +55,10 @@ namespace Mantid

Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> xmlBuilder;
Mantid::Geometry::IMDDimension_sptr tDimension;
std::vector<std::string> axisLabels;
virtual void appendMetadata(vtkDataSet* visualDataSet, const std::string& wsName) ;
virtual void extractMetadata(Mantid::API::IMDEventWorkspace_sptr eventWs);

virtual bool canLoadFileBasedOnExtension(const std::string& filename, const std::string& expectedExtension) const;
virtual bool shouldLoad();
bool m_isSetup;
Expand Down
35 changes: 35 additions & 0 deletions Code/Mantid/Vates/VatesAPI/src/Common.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
#include "MantidVatesAPI/Common.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"

#include <vtkNew.h>
#include <vtkFieldData.h>
#include <vtkStringArray.h>

//using namespace Mantid::Geometry;
namespace Mantid
{
namespace VATES
{
std::string makeAxisTitle(Dimension_const_sptr dim)
{
std::string title = dim->getName();
title += " (";
title += dim->getUnits();
title += ")";
return title;
}

void setAxisLabel(std::string metadataLabel,
std::string labelString,
vtkFieldData *fieldData)
{
vtkNew<vtkStringArray> axisTitle;
axisTitle->SetName(metadataLabel.c_str());
axisTitle->SetNumberOfComponents(1);
axisTitle->SetNumberOfTuples(1);
axisTitle->SetValue(0, labelString.c_str());
fieldData->AddArray(axisTitle.GetPointer());
}


} // VATES
} // Mantid
14 changes: 14 additions & 0 deletions Code/Mantid/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "MantidVatesAPI/RebinningKnowledgeSerializer.h"
#include "MantidVatesAPI/MetadataToFieldData.h"
#include "MantidVatesAPI/RebinningCutterXMLDefinitions.h"
#include "MantidVatesAPI/Common.h"

#include <boost/algorithm/string.hpp>
#include <vtkFieldData.h>
Expand Down Expand Up @@ -55,6 +56,7 @@ namespace Mantid
max = 1.0;
}
//std::cout << "dim " << d << min << " to " << max << std::endl;
axisLabels.push_back(makeAxisTitle(inDim));
MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, inDim->getNBins()));
dimensions.push_back(dim);
}
Expand Down Expand Up @@ -159,6 +161,18 @@ namespace Mantid
outputFD->Delete();
}

/**
* Set the axis labels from the current dimensions
* @param visualDataSet: The VTK dataset to update
*/
void MDEWLoadingPresenter::setAxisLabels(vtkDataSet *visualDataSet)
{
vtkFieldData* fieldData = visualDataSet->GetFieldData();
setAxisLabel("AxisTitleForX", axisLabels[0], fieldData);
setAxisLabel("AxisTitleForY", axisLabels[1], fieldData);
setAxisLabel("AxisTitleForZ", axisLabels[2], fieldData);
}

/**
Gets the geometry in a string format.
@return geometry string ref.
Expand Down

0 comments on commit 8fe88e7

Please sign in to comment.