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