// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2024 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #ifndef IGL_PLAINMATRIX_H #define IGL_PLAINMATRIX_H #include #include #include // Define void_t for compatibility if it's not in the standard library (C++11 and later) #if __cplusplus < 201703L namespace std { template using void_t = void; } #endif #ifndef IGL_DEFAULT_MAJORING #define IGL_DEFAULT_MAJORING Eigen::ColMajor #endif namespace igl { template struct PlainMatrixHelper { using Type = Eigen::Matrix; }; template struct get_options { static constexpr int value = IGL_DEFAULT_MAJORING; }; template struct get_options> { static constexpr int value = Derived::Options; }; /// Some libigl implementations would (still do?) use a pattern like: /// /// template /// void foo(const Eigen::MatrixBase& A) /// { /// DerivedA B; /// igl::unique_rows(A,true,B); /// } /// /// If `DerivedA` is `Eigen::Matrix`, then this may compile, but `DerivedA` might be /// from a Eigen::Map or Eigen::Ref and fail to compile due to missing /// construtor. /// /// Even worse, the code above will work if `DerivedA` has dynamic rows, but will /// throw a runtime error if `DerivedA` has fixed number of rows. /// /// Instead it's better to declare `B` as a `Eigen::Matrix` /// /// Eigen::Matrix B; /// /// Using `Eigen::Dynamic` for dimensions that may not be known at compile /// time (or may be different from A). /// /// `igl::PlainMatrix` is just a helper to make this easier. So in this case /// we could write: /// /// igl::PlainMatrix B; /// /// IIUC, if the code in question looks like: /// /// template /// void foo(Eigen::PlainObjectBase& C) /// { /// DerivedC B; /// … /// C.resize(not_known_at_compile_time,also_not_known_at_compile_time); /// } /// /// Then it's probably fine. If C can be resized to different sizes, then /// `DerivedC` should be `Eigen::Matrix`-like . // Helper to check if `Options` exists in Derived // Modify PlainMatrix to use get_options template ::value> using PlainMatrix = typename PlainMatrixHelper::Type; } #endif