Mantid
Loading...
Searching...
No Matches
CompositeImplicitFunction.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 <sstream>
8
10
11#include <boost/algorithm/string.hpp>
12#include <boost/format.hpp>
13
14#include <Poco/DOM/AutoPtr.h>
15#include <Poco/DOM/DOMWriter.h>
16#include <Poco/DOM/Document.h>
17#include <Poco/DOM/Element.h>
18#include <Poco/DOM/Text.h>
19
20#include <numeric>
21
22namespace Mantid::Geometry {
23
25 bool bSuccess = false;
26 if (constituentFunction.get() != nullptr) {
27 this->m_Functions.emplace_back(constituentFunction);
28 bSuccess = true;
29 }
30 return bSuccess;
31}
32
34
37 using namespace Poco::XML;
38 AutoPtr<Document> pDoc = new Document;
39 AutoPtr<Element> functionElement = pDoc->createElement("Function");
40 pDoc->appendChild(functionElement);
41 AutoPtr<Element> typeElement = pDoc->createElement("Type");
42 AutoPtr<Text> typeText = pDoc->createTextNode(this->getName());
43 typeElement->appendChild(typeText);
44 functionElement->appendChild(typeElement);
45 AutoPtr<Element> parameterListElement = pDoc->createElement("ParameterList");
46 functionElement->appendChild(parameterListElement);
47
48 std::string functionXML =
49 std::accumulate(m_Functions.cbegin(), m_Functions.cend(), std::string(),
50 [](const auto &lhs, const auto &function) { return lhs + function->toXMLString(); });
51 AutoPtr<Text> functionFormatText = pDoc->createTextNode("%s");
52 functionElement->appendChild(functionFormatText);
53
54 std::stringstream xmlstream;
55 DOMWriter writer;
56 writer.writeNode(xmlstream, pDoc);
57
58 std::string formattedXMLString = boost::str(boost::format(xmlstream.str().c_str()) % functionXML.c_str());
59 return formattedXMLString;
60}
61
64int CompositeImplicitFunction::getNFunctions() const { return static_cast<int>(this->m_Functions.size()); }
65
67 bool evalResult = false;
68 std::vector<std::shared_ptr<Mantid::Geometry::MDImplicitFunction>>::const_iterator it;
69 for (it = this->m_Functions.begin(); it != this->m_Functions.end(); ++it) {
70 evalResult = (*it)->isPointContained(coords);
71 if (!evalResult) {
72 break;
73 }
74 }
75 return evalResult;
76}
77
78bool CompositeImplicitFunction::isPointContained(const std::vector<coord_t> &coords) {
79 bool evalResult = false;
80 std::vector<std::shared_ptr<Mantid::Geometry::MDImplicitFunction>>::const_iterator it;
81 for (it = this->m_Functions.begin(); it != this->m_Functions.end(); ++it) {
82 evalResult = (*it)->isPointContained(coords);
83 if (!evalResult) {
84 break;
85 }
86 }
87 return evalResult;
88}
89} // namespace Mantid::Geometry
bool addFunction(const Mantid::Geometry::MDImplicitFunction_sptr &constituentFunction)
std::vector< Mantid::Geometry::MDImplicitFunction_sptr > m_Functions
bool isPointContained(const coord_t *coords) override
Is a point in MDimensions contained by this ImplicitFunction? If the point is bounded by ALL planes c...
std::string toXMLString() const override
Serialize to XML.
int getNFunctions() const
Return the number of functions in this composite.
std::shared_ptr< MDImplicitFunction > MDImplicitFunction_sptr
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27