mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
ENH: More type deduction
Project, Reflect, Stereo, Ortho
This commit is contained in:
@@ -28,44 +28,41 @@ Eigen::Matrix<float, N, N> mirror(const tc::Group<> &group) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N>
|
struct Stereo {
|
||||||
vec<N> stereo(const vec<N + 1> &v) {
|
template<class U>
|
||||||
vec<N> r;
|
auto operator()(U &&mat) const {
|
||||||
for (int i = 0; i < N; ++i) {
|
const auto Rows = std::remove_reference<U>::type::RowsAtCompileTime;
|
||||||
r[i] = v[i] / (1 - v[N]);
|
return std::forward<U>(mat).template topRows<Rows - 1>().rowwise() / (1 - mat.template bottomRows<1>());
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<unsigned N>
|
struct Ortho {
|
||||||
vec<N> ortho(const vec<N + 1> &v) {
|
template<class U>
|
||||||
vec<N> r;
|
auto operator()(U &&mat) const {
|
||||||
for (int i = 0; i < N; ++i) {
|
const auto Rows = std::remove_reference<U>::type::RowsAtCompileTime;
|
||||||
r[i] = v[i];
|
return std::forward<U>(mat).template topRows<Rows - 1>();
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<class V>
|
struct Project {
|
||||||
V project(const V &vec, const V &target) {
|
template<class U, class V>
|
||||||
return vec.dot(target) / target.dot(target) * target;
|
auto operator()(U &&point, V &&axis) const {
|
||||||
|
return point.dot(axis) / axis.dot(axis) * std::forward<V>(axis);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<class V>
|
struct Reflect {
|
||||||
V reflect(const V &a, const V &axis) {
|
template<class U, class V>
|
||||||
return a - 2.f * project(a, axis);
|
auto operator()(U &&point, V &&axis) const {
|
||||||
}
|
return std::forward<U>(point) - 2 * Project()(point, axis);
|
||||||
|
|
||||||
template<class Point, class Axis>
|
|
||||||
auto project_(const Point &point, const Axis &axis) {
|
|
||||||
return axis.dot(point) / axis.dot(axis) * axis;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<class Mat>
|
template<class Mat>
|
||||||
Mat gram_schmidt(Mat mat) {
|
Mat gram_schmidt(Mat mat) {
|
||||||
for (int i = 0; i < mat.cols(); ++i) {
|
for (int i = 0; i < mat.cols(); ++i) {
|
||||||
for (int j = i + 1; j < mat.cols(); ++j) {
|
for (int j = i + 1; j < mat.cols(); ++j) {
|
||||||
mat.col(j) -= project_(mat.col(j), mat.col(i));
|
mat.col(j) -= Project()(mat.col(j), mat.col(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mat;
|
return mat;
|
||||||
|
|||||||
@@ -90,13 +90,18 @@ std::vector<vec4> points(const tc::Group<> &group, const C &coords) {
|
|||||||
|
|
||||||
tc::Path<vec5> path(cosets, mirrors.colwise());
|
tc::Path<vec5> path(cosets, mirrors.colwise());
|
||||||
|
|
||||||
std::vector<vec5> higher(path.order());
|
Eigen::Array<float, 5, Eigen::Dynamic> higher(5, path.order());
|
||||||
path.walk(start, reflect<vec5>, higher.begin());
|
path.walk(start, Reflect(), higher.matrix().colwise().begin());
|
||||||
|
// std::vector<vec5> higher(path.order());
|
||||||
|
// path.walk(start, Reflect(), higher.begin());
|
||||||
|
|
||||||
std::vector<vec4> lower(higher.size());
|
// Eigen::Array4Xf lower = higher.topRows<4>().rowwise() / (1 - higher.bottomRows<1>());
|
||||||
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
|
Eigen::Array4Xf lower = Stereo()(higher);
|
||||||
|
|
||||||
return lower;
|
std::vector<vec4> vec(lower.cols());
|
||||||
|
std::copy(lower.colwise().begin(), lower.colwise().end(), vec.begin());
|
||||||
|
|
||||||
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
|
|||||||
Reference in New Issue
Block a user