python_shared.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #pragma once
  9. #include <pybind11/pybind11.h>
  10. #include <pybind11/operators.h>
  11. #include <pybind11/complex.h>
  12. #include <pybind11/numpy.h>
  13. #include <pybind11/stl.h>
  14. #include <pybind11/functional.h>
  15. #include "py_doc.h"
  16. #include <Eigen/Dense>
  17. template<typename Scalar>
  18. void assert_is_VectorX(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  19. {
  20. if (v.size() == 0)
  21. return;
  22. if (v.cols() != 1)
  23. throw std::runtime_error(name + " must be a column vector.");
  24. }
  25. template<typename Scalar>
  26. void assert_is_RowVectorX(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  27. {
  28. if (v.size() == 0)
  29. return;
  30. if (v.rows() != 1)
  31. throw std::runtime_error(name + " must be a row vector.");
  32. }
  33. template<typename Scalar>
  34. void assert_is_Vector2(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  35. {
  36. if (v.size() == 0)
  37. return;
  38. if ((v.cols() != 1) || (v.rows() != 2))
  39. throw std::runtime_error(name + " must be a column vector with 2 entries.");
  40. }
  41. template<typename Scalar>
  42. void assert_is_RowVector2(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  43. {
  44. if (v.size() == 0)
  45. return;
  46. if ((v.cols() != 2) || (v.rows() != 1))
  47. throw std::runtime_error(name + " must be a row vector with 2 entries.");
  48. }
  49. template<typename Scalar>
  50. void assert_is_Vector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  51. {
  52. if (v.size() == 0)
  53. return;
  54. if ((v.cols() != 1) || (v.rows() != 3))
  55. throw std::runtime_error(name + " must be a column vector with 3 entries.");
  56. }
  57. template<typename Scalar>
  58. void assert_is_RowVector3(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  59. {
  60. if (v.size() == 0)
  61. return;
  62. if ((v.cols() != 3) || (v.rows() != 1))
  63. throw std::runtime_error(name + " must be a row vector with 3 entries.");
  64. }
  65. template<typename Scalar>
  66. void assert_is_Vector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  67. {
  68. if (v.size() == 0)
  69. return;
  70. if ((v.cols() != 1) || (v.rows() != 4))
  71. throw std::runtime_error(name + " must be a column vector with 4 entries.");
  72. }
  73. template<typename Scalar>
  74. void assert_is_RowVector4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  75. {
  76. if (v.size() == 0)
  77. return;
  78. if ((v.cols() != 4) || (v.rows() != 1))
  79. throw std::runtime_error(name + " must be a row vector with 4 entries.");
  80. }
  81. template<typename Scalar>
  82. void assert_is_Matrix4(const std::string name, const Eigen::PlainObjectBase<Scalar>& v)
  83. {
  84. if (v.size() == 0)
  85. return;
  86. if ((v.cols() != 4) || (v.rows() != 4))
  87. throw std::runtime_error(name + " must be a 4x4 matrix.");
  88. }
  89. namespace py = pybind11;