Skip to content

Instantly share code, notes, and snippets.

@Unril
Last active June 14, 2018 06:54
Show Gist options
  • Select an option

  • Save Unril/03fa353d0461ed6bd41d to your computer and use it in GitHub Desktop.

Select an option

Save Unril/03fa353d0461ed6bd41d to your computer and use it in GitHub Desktop.

Revisions

  1. Unril renamed this gist Mar 4, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Unril created this gist Mar 4, 2016.
    11 changes: 11 additions & 0 deletions EigenOpenMeshPlugin.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    EIGEN_STRONG_INLINE Matrix &normalize() {
    *this /= norm();
    return *this;
    }

    EIGEN_STRONG_INLINE Scalar length() const { return norm(); }

    EIGEN_STRONG_INLINE Matrix &vectorize(Scalar v) {
    fill(v);
    return *this;
    }
    41 changes: 41 additions & 0 deletions openmesh.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #define EIGEN_MATRIX_PLUGIN "EigenOpenMeshPlugin.h"

    #include <Eigen/Core>
    #include <Eigen/Geometry>
    #include <OpenMesh/Core/Mesh/Traits.hh>
    #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>

    namespace OpenMesh {
    template <typename _Scalar, int _Rows, int _Cols, int _Options>
    struct vector_traits<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>> {
    static_assert(_Rows != Eigen::Dynamic && _Cols != Eigen::Dynamic,
    "Should not use dynamic vectors.");
    static_assert(_Rows == 1 || _Cols == 1, "Should not use matrices.");

    using vector_type = Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>;
    using value_type = _Scalar;
    static const size_t size_ = _Rows * _Cols;
    static size_t size() { return size_; }
    };

    template <typename _Scalar, int _Rows, int _Cols, int _Options>
    struct VectorDimensionsT<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>> {
    static_assert(_Rows != Eigen::Dynamic && _Cols != Eigen::Dynamic,
    "Should not use dynamic vectors.");
    static_assert(_Rows == 1 || _Cols == 1, "Should not use matrices.");
    enum { value = _Rows * _Cols };
    };

    template <typename Derived>
    typename Derived::Scalar dot(Eigen::MatrixBase<Derived> const &v1,
    Eigen::MatrixBase<Derived> const &v2) {
    return v1.dot(v2);
    }

    template <typename Derived>
    typename Derived::template cross_product_return_type<Derived>::type
    cross(Eigen::MatrixBase<Derived> const &v1,
    Eigen::MatrixBase<Derived> const &v2) {
    return v1.cross(v2);
    }
    }