Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit c80f4f37 authored by kraus's avatar kraus
Browse files

using affine transformation instead of coordinate transformation. This allows...

using affine transformation instead of coordinate transformation. This allows for shear and perspective operations (to be implemented).
parent 42f4e425
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,62 @@ std::string FCall("([a-z]*)\\((.*)"); ...@@ -18,6 +18,62 @@ std::string FCall("([a-z]*)\\((.*)");
typedef std::string::iterator iterator; typedef std::string::iterator iterator;
struct AffineTransformation: public Tenzor<double, 3> {
AffineTransformation(const Vector_t& row0,
const Vector_t& row1):
Tenzor(row0[0], row0[1], row0[2], row1[0], row1[1], row1[2], 0.0, 0.0, 1.0) {
}
AffineTransformation():
Tenzor(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0) { }
AffineTransformation getInverse() const {
AffineTransformation Ret;
double det = (*this)(0, 0) * (*this)(1, 1) - (*this)(1, 0) * (*this)(0, 1);
Ret(0, 0) = (*this)(1, 1) / det;
Ret(1, 0) = -(*this)(1, 0) / det;
Ret(0, 1) = -(*this)(0, 1) / det;
Ret(1, 1) = (*this)(0, 0) / det;
Ret(0, 2) = - Ret(0, 0) * (*this)(0, 2) - Ret(0, 1) * (*this)(1, 2);
Ret(1, 2) = - Ret(1, 0) * (*this)(0, 2) - Ret(1, 1) * (*this)(1, 2);
Ret(2, 2) = 1.0;
return Ret;
}
Vector_t getOrigin() const {
return Vector_t(-(*this)(0, 2), -(*this)(1, 2), 0.0);
}
double getAngle() const {
return atan2((*this)(1, 0), (*this)(0, 0));
}
Vector_t transformTo(const Vector_t &v) const {
const Tenzor<double, 3> &A = *static_cast<const Tenzor<double, 3>* >(this);
Vector_t b(v[0], v[1], 1.0);
return dot(A, b);
}
Vector_t transformFrom(const Vector_t &v) const {
AffineTransformation inv = getInverse();
return inv.transformTo(v);
}
AffineTransformation mult(const AffineTransformation &B) {
AffineTransformation Ret;
const Tenzor<double, 3> &A = *static_cast<const Tenzor<double, 3> *>(this);
const Tenzor<double, 3> &BTenz = *static_cast<const Tenzor<double, 3> *>(&B);
Tenzor<double, 3> &C = *static_cast<Tenzor<double, 3> *>(&Ret);
C = dot(A, BTenz);
return Ret;
}
};
struct Base; struct Base;
struct Function { struct Function {
...@@ -30,13 +86,12 @@ struct Function { ...@@ -30,13 +86,12 @@ struct Function {
bool parse(iterator &it, const iterator &end, Function* &fun); bool parse(iterator &it, const iterator &end, Function* &fun);
struct Base: public Function { struct Base: public Function {
CoordinateSystemTrafo trafo_m; AffineTransformation trafo_m;
// std::tuple<unsigned int, // std::tuple<unsigned int,
// double, // double,
// double> repeat_m; // double> repeat_m;
Base(): Base():
trafo_m(Vector_t(0.0), trafo_m()
Quaternion(1.0, 0.0, 0.0, 0.0))
// , repeat_m(std::make_tuple(0u, 0.0, 0.0)) // , repeat_m(std::make_tuple(0u, 0.0, 0.0))
{ } { }
...@@ -60,12 +115,15 @@ struct Rectangle: public Base { ...@@ -60,12 +115,15 @@ struct Rectangle: public Base {
std::string indent(indentwidth, ' '); std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' '); std::string indent2(indentwidth + 8, ' ');
Vector_t origin = trafo_m.getOrigin(); Vector_t origin = trafo_m.getOrigin();
double angle = acos(trafo_m.getRotation()[0]) * 2 * Physics::rad2deg; double angle = trafo_m.getAngle() * Physics::rad2deg;
std::cout << indent << "rectangle, \n" std::cout << indent << "rectangle, \n"
<< indent2 << "w: " << width_m << ", \n" << indent2 << "w: " << width_m << ", \n"
<< indent2 << "h: " << height_m << ", \n" << indent2 << "h: " << height_m << ", \n"
<< indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n" << indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n"
<< indent2 << "angle: " << angle; << indent2 << "angle: " << angle << "\n"
<< indent2 << trafo_m(0, 0) << "\t" << trafo_m(0, 1) << "\t" << trafo_m(0, 2) << "\n"
<< indent2 << trafo_m(1, 0) << "\t" << trafo_m(1, 1) << "\t" << trafo_m(1, 2) << "\n"
<< indent2 << trafo_m(2, 0) << "\t" << trafo_m(2, 1) << "\t" << trafo_m(2, 2) << std::endl;
} }
virtual void writeGnuplot(std::ofstream &out) const { virtual void writeGnuplot(std::ofstream &out) const {
...@@ -134,12 +192,15 @@ struct Ellipse: public Base { ...@@ -134,12 +192,15 @@ struct Ellipse: public Base {
std::string indent(indentwidth, ' '); std::string indent(indentwidth, ' ');
std::string indent2(indentwidth + 8, ' '); std::string indent2(indentwidth + 8, ' ');
Vector_t origin = trafo_m.getOrigin(); Vector_t origin = trafo_m.getOrigin();
double angle = acos(trafo_m.getRotation()[0]) * 2 * Physics::rad2deg; double angle = trafo_m.getAngle() * Physics::rad2deg;
std::cout << indent << "ellipse, \n" std::cout << indent << "ellipse, \n"
<< indent2 << "w: " << width_m << ", \n" << indent2 << "w: " << width_m << ", \n"
<< indent2 << "h: " << height_m << ", \n" << indent2 << "h: " << height_m << ", \n"
<< indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n" << indent2 << "origin: " << origin[0] << ", " << origin[1] << ",\n"
<< indent2 << "angle: " << angle; << indent2 << "angle: " << angle << "\n"
<< indent2 << trafo_m(0, 0) << "\t" << trafo_m(0, 1) << "\t" << trafo_m(0, 2) << "\n"
<< indent2 << trafo_m(1, 0) << "\t" << trafo_m(1, 1) << "\t" << trafo_m(1, 2) << "\n"
<< indent2 << trafo_m(2, 0) << "\t" << trafo_m(2, 1) << "\t" << trafo_m(2, 2) << std::endl;
} }
virtual void writeGnuplot(std::ofstream &out) const { virtual void writeGnuplot(std::ofstream &out) const {
...@@ -234,20 +295,23 @@ struct Repeat: public Function { ...@@ -234,20 +295,23 @@ struct Repeat: public Function {
} }
virtual void apply(std::vector<Base*> &bfuncs) { virtual void apply(std::vector<Base*> &bfuncs) {
CoordinateSystemTrafo shift(Vector_t(shiftx_m, shifty_m, 0.0), AffineTransformation shift(Vector_t(1.0, 0.0, -shiftx_m),
Quaternion(1.0, 0.0, 0.0, 0.0)); Vector_t(0.0, 1.0, -shifty_m));
std::cout << shiftx_m << "\t" << shift(0, 2) << std::endl;
// CoordinateSystemTrafo shift(Vector_t(shiftx_m, shifty_m, 0.0),
// Quaternion(1.0, 0.0, 0.0, 0.0));
func_m->apply(bfuncs); func_m->apply(bfuncs);
const unsigned int size = bfuncs.size(); const unsigned int size = bfuncs.size();
CoordinateSystemTrafo current_shift = shift; AffineTransformation current_shift = shift;
for (unsigned int i = 0; i < N_m; ++ i) { for (unsigned int i = 0; i < N_m; ++ i) {
for (unsigned int j = 0; j < size; ++ j) { for (unsigned int j = 0; j < size; ++ j) {
Base *obj = bfuncs[j]->clone(); Base *obj = bfuncs[j]->clone();
obj->trafo_m *= current_shift; obj->trafo_m = obj->trafo_m.mult(current_shift);
bfuncs.push_back(obj); bfuncs.push_back(obj);
} }
current_shift *= shift; current_shift = current_shift.mult(shift);
} }
} }
...@@ -295,14 +359,15 @@ struct Translate: public Function { ...@@ -295,14 +359,15 @@ struct Translate: public Function {
} }
virtual void apply(std::vector<Base*> &bfuncs) { virtual void apply(std::vector<Base*> &bfuncs) {
CoordinateSystemTrafo shift(Vector_t(shiftx_m, shifty_m, 0.0), AffineTransformation shift(Vector_t(1.0, 0.0, -shiftx_m),
Quaternion(1.0, 0.0, 0.0, 0.0)); Vector_t(0.0, 1.0, -shifty_m));
func_m->apply(bfuncs); func_m->apply(bfuncs);
const unsigned int size = bfuncs.size(); const unsigned int size = bfuncs.size();
for (unsigned int j = 0; j < size; ++ j) { for (unsigned int j = 0; j < size; ++ j) {
Base *obj = bfuncs[j]; Base *obj = bfuncs[j];
obj->trafo_m *= shift;// * obj->trafo_m; obj->trafo_m = obj->trafo_m.mult(shift);
} }
} }
...@@ -348,14 +413,15 @@ struct Rotate: public Function { ...@@ -348,14 +413,15 @@ struct Rotate: public Function {
} }
virtual void apply(std::vector<Base*> &bfuncs) { virtual void apply(std::vector<Base*> &bfuncs) {
CoordinateSystemTrafo rotation(Vector_t(0.0, 0.0, 0.0), AffineTransformation rotation(Vector_t(cos(angle_m), sin(angle_m), 0.0),
Quaternion(cos(-0.5 * angle_m), 0.0, 0.0, sin(-0.5 * angle_m))); Vector_t(-sin(angle_m), cos(angle_m), 0.0));
func_m->apply(bfuncs); func_m->apply(bfuncs);
const unsigned int size = bfuncs.size(); const unsigned int size = bfuncs.size();
for (unsigned int j = 0; j < size; ++ j) { for (unsigned int j = 0; j < size; ++ j) {
Base *obj = bfuncs[j]; Base *obj = bfuncs[j];
obj->trafo_m *= rotation; obj->trafo_m = obj->trafo_m.mult(rotation);
} }
} }
...@@ -363,7 +429,7 @@ struct Rotate: public Function { ...@@ -363,7 +429,7 @@ struct Rotate: public Function {
bool parse_detail(iterator &it, const iterator &end, Function* &fun) { bool parse_detail(iterator &it, const iterator &end, Function* &fun) {
Rotate *rot = static_cast<Rotate*>(fun); Rotate *rot = static_cast<Rotate*>(fun);
if (!parse(it, end, rot->func_m)) return false; if (!parse(it, end, rot->func_m)) return false;
std::cout << std::string(it, end) << std::endl;
boost::regex argumentList("," + Double + "\\)(.*)"); boost::regex argumentList("," + Double + "\\)(.*)");
boost::smatch what; boost::smatch what;
......
...@@ -8,13 +8,10 @@ repeat( ...@@ -8,13 +8,10 @@ repeat(
0.52359877 0.52359877
), ),
translate( translate(
rotate( rectangle(
rectangle( 0.2,
0.2, 0.1
0.1 ),
),
0.252359877
),
-0.01, -0.01,
-0.02 -0.02
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment