OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Rotation.cpp
Go to the documentation of this file.
2
5
6#include <cmath>
7#include <iostream>
8#include <memory>
9#include <stdexcept>
10#include <string>
11#include <vector>
12
13namespace mslang {
14 void Rotation::print(int indentwidth) {
15 std::string indent(indentwidth, ' ');
16 std::string indent2(indentwidth + 8, ' ');
17 std::cout << indent << "rotate, " << std::endl;
18 func_m->print(indentwidth + 8);
19 std::cout << ",\n"
20 << indent2 << "angle: " << angle_m;
21 }
22
23 void Rotation::applyRotation(std::vector<std::shared_ptr<Base> > &bfuncs) {
24
25 AffineTransformation rotation(Vector_t({std::cos(angle_m), std::sin(angle_m), 0.0}),
26 Vector_t({-std::sin(angle_m), std::cos(angle_m), 0.0}));
27
28 const unsigned int size = bfuncs.size();
29
30 for (unsigned int j = 0; j < size; ++ j) {
31 std::shared_ptr<Base> &obj = bfuncs[j];
32 obj->trafo_m = obj->trafo_m.mult(rotation);
33
34 if (!obj->divisor_m.empty())
35 applyRotation(obj->divisor_m);
36 }
37 }
38
39 void Rotation::apply(std::vector<std::shared_ptr<Base> > &bfuncs) {
40 func_m->apply(bfuncs);
41 applyRotation(bfuncs);
42 }
43
45 Rotation *rot = static_cast<Rotation*>(fun);
46 if (!parse(it, end, rot->func_m)) return false;
47
48 ArgumentExtractor arguments(std::string(++ it, end));
49 try {
50 rot->angle_m = parseMathExpression(arguments.get(0));
51 } catch (std::runtime_error &e) {
52 std::cout << e.what() << std::endl;
53 return false;
54 }
55
56 it += (arguments.getLengthConsumed() + 1);
57
58 return true;
59 }
60}
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
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)=0
static bool parse(iterator &it, const iterator &end, Function *&fun)
Definition MSLang.cpp:46
virtual void print(int indent)=0
std::string get(unsigned int i) const
unsigned int getLengthConsumed() const
static bool parse_detail(iterator &it, const iterator &end, Function *&fun)
Definition Rotation.cpp:44
virtual void apply(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Rotation.cpp:39
void applyRotation(std::vector< std::shared_ptr< Base > > &bfuncs)
Definition Rotation.cpp:23
virtual void print(int indentwidth)
Definition Rotation.cpp:14
Function * func_m
Definition Rotation.h:11
Vektor< double, 3 > Vector_t
Definition Vektor.h:6