Mantid
Loading...
Searching...
No Matches
MDPlaneImplicitFunction.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include <limits>
8#include <sstream>
9
11
12#include <Poco/DOM/AutoPtr.h>
13#include <Poco/DOM/DOMWriter.h>
14#include <Poco/DOM/Document.h>
15#include <Poco/DOM/Element.h>
16#include <Poco/DOM/Text.h>
17#include <boost/algorithm/string.hpp>
18#include <boost/format.hpp>
19
20namespace Mantid::Geometry {
21
23
32MDPlaneImplicitFunction::MDPlaneImplicitFunction(const size_t nd, const float *normal, const float *point)
33 : MDImplicitFunction(), origin(nd) {
34 for (std::size_t i = 0; i < nd; i++) {
35 this->origin[i] = static_cast<coord_t>(point[i]);
36 }
37 this->addPlane(MDPlane(nd, normal, point));
38}
39
48MDPlaneImplicitFunction::MDPlaneImplicitFunction(const size_t nd, const double *normal, const double *point)
49 : MDImplicitFunction(), origin(nd) {
50 for (std::size_t i = 0; i < nd; i++) {
51 this->origin[i] = static_cast<coord_t>(point[i]);
52 }
53 this->addPlane(MDPlane(nd, normal, point));
54}
55
62 if (this->getNumPlanes() > 0) {
63 throw std::runtime_error("Only one plane per MDPlaneImplicitFunction.");
64 } else {
66 this->checkOrigin();
67 }
68}
69
70std::string MDPlaneImplicitFunction::getName() const { return std::string("PlaneImplicitFuction"); }
71
73 using namespace Poco::XML;
74 AutoPtr<Document> pDoc = new Document;
75 AutoPtr<Element> functionElement = pDoc->createElement("Function");
76 pDoc->appendChild(functionElement);
77 AutoPtr<Element> typeElement = pDoc->createElement("Type");
78 AutoPtr<Text> typeText = pDoc->createTextNode(this->getName());
79 typeElement->appendChild(typeText);
80 functionElement->appendChild(typeElement);
81
82 AutoPtr<Element> parameterListElement = pDoc->createElement("ParameterList");
83 functionElement->appendChild(parameterListElement);
84
85 // Normal Parameter
86 AutoPtr<Element> normParameterElement = pDoc->createElement("Parameter");
87 parameterListElement->appendChild(normParameterElement);
88 AutoPtr<Element> normTypeElement = pDoc->createElement("Type");
89 AutoPtr<Text> normText = pDoc->createTextNode("NormalParameter");
90 normTypeElement->appendChild(normText);
91 normParameterElement->appendChild(normTypeElement);
92 AutoPtr<Element> normValueElement = pDoc->createElement("Value");
93 const coord_t *norm = this->getPlane(0).getNormal();
94 AutoPtr<Text> normValueText = pDoc->createTextNode(this->coordValue(norm));
95 normValueElement->appendChild(normValueText);
96 normParameterElement->appendChild(normValueElement);
97
98 // Origin Parameter
99 AutoPtr<Element> origParameterElement = pDoc->createElement("Parameter");
100 parameterListElement->appendChild(origParameterElement);
101 AutoPtr<Element> origTypeElement = pDoc->createElement("Type");
102 AutoPtr<Text> origText = pDoc->createTextNode("OriginParameter");
103 origTypeElement->appendChild(origText);
104 origParameterElement->appendChild(origTypeElement);
105 AutoPtr<Element> origValueElement = pDoc->createElement("Value");
106 origParameterElement->appendChild(origValueElement);
107 AutoPtr<Text> origValueText = pDoc->createTextNode(this->coordValue(this->origin.data()));
108 origValueElement->appendChild(origValueText);
109 origParameterElement->appendChild(origValueElement);
110
111 std::stringstream xmlstream;
112 DOMWriter writer;
113 writer.writeNode(xmlstream, pDoc);
114
115 std::string formattedXMLString = boost::str(boost::format(xmlstream.str().c_str()));
116 return formattedXMLString;
117}
118
125std::string MDPlaneImplicitFunction::coordValue(const coord_t *arr) const {
126 std::ostringstream valueStream;
127 std::size_t nd = this->getNumDims();
128 for (std::size_t i = 0; i < nd - 1; i++) {
129 valueStream << arr[i] << " ";
130 }
131 valueStream << arr[nd - 1];
132 return valueStream.str();
133}
134
136 if (origin.empty()) {
137 origin.resize(getNumDims(), std::numeric_limits<coord_t>::quiet_NaN());
138 }
139}
140
141} // namespace Mantid::Geometry
An "ImplicitFunction" defining a hyper-cuboid-shaped region in N dimensions.
void addPlane(const MDPlane &plane)
Add a bounded plane to this implicit function.
const MDPlane & getPlane(size_t index) const
std::string coordValue(const coord_t *arr) const
Create string for coordinate values.
std::vector< coord_t > origin
The origin point of the implicit plane.
void checkOrigin()
Set defaults to origin if not used.
void addPlane(const MDPlane &plane)
Overriding the addPlane for check.
A generalized description of a N-dimensional hyperplane.
Definition: MDPlane.h:41
const coord_t * getNormal() const
Definition: MDPlane.h:57
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27