OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Polygon.cpp
Go to the documentation of this file.
2#include "Physics/Physics.h"
5#include "Utilities/Mesher.h"
6
7#include <regex>
8
9namespace mslang {
10 void Polygon::triangulize(std::vector<Vector_t<double, 3>>& nodes) {
11 Mesher mesher(nodes);
12 triangles_m = mesher.getTriangles();
13 }
14
15 bool Polygon::parse_detail(iterator& it, const iterator& end, Function*& fun) {
16 Polygon* poly = static_cast<Polygon*>(fun);
17
18 ArgumentExtractor arguments(std::string(it, end));
19 std::vector<Vector_t<double, 3>> nodes;
20
21 for (unsigned int i = 0; i + 1 < arguments.getNumArguments(); i += 2) {
22 try {
23 double x = parseMathExpression(arguments.get(i));
24 double y = parseMathExpression(arguments.get(i + 1));
25 nodes.push_back(Vector_t<double, 3>(x, y, 1.0));
26 } catch (std::runtime_error& e) {
27 std::cout << e.what() << std::endl;
28 return false;
29 }
30 }
31
32 if (nodes.size() < 3) return false;
33
34 poly->triangulize(nodes);
35
36 it += (arguments.getLengthConsumed() + 1);
37 return true;
38 }
39
40 void Polygon::print(int /*ident*/) {
41 // for (auto pix: pixels_m) pix.print(ident);
42 }
43
44 void Polygon::apply(std::vector<std::shared_ptr<Base>>& bfuncs) {
45 for (Triangle& tri : triangles_m)
46 bfuncs.push_back(std::shared_ptr<Base>(tri.clone()));
47 }
48} // namespace mslang
ippl::Vector< T, Dim > Vector_t
Definition Mesher.h:6
std::vector< mslang::Triangle > getTriangles() const
Definition Mesher.cpp:5
double parseMathExpression(const std::string &str)
Definition matheval.cpp:4
std::string::iterator iterator
Definition MSLang.h:14
unsigned int getNumArguments() const
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
virtual void print(int ident)
Definition Polygon.cpp:40
std::vector< Triangle > triangles_m
Definition Polygon.h:9
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Polygon.cpp:44
void triangulize(std::vector< Vector_t< double, 3 > > &nodes)
Definition Polygon.cpp:10
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Polygon.cpp:15