Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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()
{
}
}
}