Bladeren bron

Stupid template should compile now.

Jérémie Dumas 6 jaren geleden
bovenliggende
commit
b7db5a8ee0

+ 1 - 0
cmake/libigl.cmake

@@ -78,6 +78,7 @@ target_compile_features(igl_common INTERFACE ${CXX11_FEATURES})
 if(MSVC)
   # Enable parallel compilation for Visual Studio
   target_compile_options(igl_common INTERFACE /MP /bigobj)
+  target_compile_definitions(igl_common INTERFACE -DNOMINMAX)
 endif()
 
 ### Set compiler flags for building the tests on Windows with Visual Studio

+ 4 - 4
include/igl/copyleft/cgal/incircle.cpp

@@ -12,10 +12,10 @@
 
 template<typename Scalar>
 IGL_INLINE short igl::copyleft::cgal::incircle(
-    const Scalar pa[2],
-    const Scalar pb[2],
-    const Scalar pc[2],
-    const Scalar pd[2])
+    const Scalar *pa,
+    const Scalar *pb,
+    const Scalar *pc,
+    const Scalar *pd)
 {
   typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck;
   typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;

+ 8 - 8
include/igl/copyleft/cgal/incircle.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2016 Qingan Zhou <qnzhou@gmail.com>
-// 
-// 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 
+//
+// 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_COPYLEFT_CGAL_INCIRCLE_H
@@ -25,10 +25,10 @@ namespace igl
       //  -1 if pd is outside of the oriented circle formed by pa,pb,pc.
       template <typename Scalar>
       IGL_INLINE short incircle(
-          const Scalar pa[2],
-          const Scalar pb[2],
-          const Scalar pc[2],
-          const Scalar pd[2]);
+          const Scalar *pa,
+          const Scalar *pb,
+          const Scalar *pc,
+          const Scalar *pd);
     }
   }
 }

+ 6 - 5
include/igl/copyleft/cgal/orient2D.cpp

@@ -12,9 +12,9 @@
 
 template<typename Scalar>
 IGL_INLINE short igl::copyleft::cgal::orient2D(
-    const Scalar pa[2],
-    const Scalar pb[2],
-    const Scalar pc[2])
+    const Scalar *pa,
+    const Scalar *pb,
+    const Scalar *pc)
 {
   typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck;
   typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;
@@ -24,7 +24,8 @@ IGL_INLINE short igl::copyleft::cgal::orient2D(
   switch(CGAL::orientation(
         typename Kernel::Point_2(pa[0], pa[1]),
         typename Kernel::Point_2(pb[0], pb[1]),
-        typename Kernel::Point_2(pc[0], pc[1]))) {
+        typename Kernel::Point_2(pc[0], pc[1])))
+  {
     case CGAL::LEFT_TURN:
       return 1;
     case CGAL::RIGHT_TURN:
@@ -41,6 +42,6 @@ IGL_INLINE short igl::copyleft::cgal::orient2D(
 // generated by autoexplicit.sh
 template short igl::copyleft::cgal::orient2D<double>(double const*, double const*, double const*);
 #ifdef WIN32
-template short igl::copyleft::cgal::orient2D<double>(double const * const,double const * const,double const * const);
+template short igl::copyleft::cgal::orient2D<double>(double const * const, double const * const, double const * const);
 #endif
 #endif

+ 7 - 7
include/igl/copyleft/cgal/orient2D.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2016 Qingan Zhou <qnzhou@gmail.com>
-// 
-// 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 
+//
+// 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_COPYLEFT_CGAL_ORIENT_2D_H
@@ -25,9 +25,9 @@ namespace igl
       //  -1 if pa,pb,pc are clockwise oriented.
       template <typename Scalar>
       IGL_INLINE short orient2D(
-          const Scalar pa[2],
-          const Scalar pb[2],
-          const Scalar pc[2]);
+          const Scalar *pa,
+          const Scalar *pb,
+          const Scalar *pc);
     }
   }
 }

+ 3 - 4
include/igl/delaunay_triangulation.cpp

@@ -22,8 +22,8 @@ template<
   typename DerivedF>
 IGL_INLINE void igl::delaunay_triangulation(
     const Eigen::MatrixBase<DerivedV>& V,
-    const Orient2D orient2D,
-    const InCircle incircle,
+    Orient2D orient2D,
+    InCircle incircle,
     Eigen::PlainObjectBase<DerivedF>& F)
 {
   assert(V.cols() == 2);
@@ -61,7 +61,6 @@ IGL_INLINE void igl::delaunay_triangulation(
 // Explicit template instantiation
 template void igl::delaunay_triangulation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #ifdef WIN32
-template void igl::delaunay_triangulation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, short (*)(double const * const, double const * const, double const * const), short(*)(double const * const, double const * const, double const * const, double const * const), Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const &, short(*)(double const * const, double const * const, double const * const), short(*)(double const * const, double const * const, double const * const, double const * const), Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > &);
-template void igl::delaunay_triangulation<class Eigen::Matrix<double,-1,-1,0,-1,-1>,short (*)(double const * const,double const * const,double const * const),short (*)(double const * const,double const * const,double const * const,double const * const),class Eigen::Matrix<int,-1,-1,0,-1,-1> >(class Eigen::MatrixBase<class Eigen::Matrix<double,-1,-1,0,-1,-1> > const &,short (*const)(double const * const,double const * const,double const * const),short (*const)(double const * const,double const * const,double const * const,double const * const),class Eigen::PlainObjectBase<class Eigen::Matrix<int,-1,-1,0,-1,-1> > &);
+template void igl::delaunay_triangulation<class Eigen::Matrix<double, -1, -1, 0, -1, -1>, short(*)(double const *, double const *, double const *), short(*)(double const *, double const *, double const *, double const *), class Eigen::Matrix<int, -1, -1, 0, -1, -1>>(class Eigen::MatrixBase<class Eigen::Matrix<double, -1, -1, 0, -1, -1>> const &, short(*const)(double const *, double const *, double const *), short(*const)(double const *, double const *, double const *, double const *), class Eigen::PlainObjectBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> &);
 #endif
 #endif

+ 6 - 9
include/igl/delaunay_triangulation.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2016 Qingan Zhou <qnzhou@gmail.com>
-// 
-// 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 
+//
+// 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_DELAUNAY_TRIANGULATION_H
@@ -38,14 +38,11 @@ namespace igl
     >
   IGL_INLINE void delaunay_triangulation(
       const Eigen::MatrixBase<DerivedV>& V,
-      const Orient2D orient2D,
-      const InCircle incircle,
+      Orient2D orient2D,
+      InCircle incircle,
       Eigen::PlainObjectBase<DerivedF>& F);
 }
 
-
-
-
 #ifndef IGL_STATIC_LIBRARY
 #  include "delaunay_triangulation.cpp"
 #endif

+ 10 - 2
include/igl/grad.cpp

@@ -14,12 +14,16 @@
 #include "volume.h"
 #include "doublearea.h"
 
+namespace igl {
+
+namespace {
+
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE void grad_tet(
   const Eigen::MatrixBase<DerivedV>&V,
   const Eigen::MatrixBase<DerivedF>&T,
   Eigen::SparseMatrix<typename DerivedV::Scalar> &G,
-  bool uniform) 
+  bool uniform)
 {
   using namespace Eigen;
   assert(T.cols() == 4);
@@ -39,7 +43,7 @@ IGL_INLINE void grad_tet(
     F.row(3*m + i) << T(i,1), T(i,3), T(i,2);
   }
   // compute volume of each tet
-  Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> vol; 
+  Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> vol;
   igl::volume(V,T,vol);
 
   Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> A(F.rows());
@@ -204,6 +208,10 @@ IGL_INLINE void grad_tri(
   G.setFromTriplets(Gijv.begin(), Gijv.end());
 }
 
+} // anonymous namespace
+
+} // namespace igl
+
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE void igl::grad(
   const Eigen::MatrixBase<DerivedV>&V,

+ 12 - 3
include/igl/grad_intrinsic.cpp

@@ -19,7 +19,16 @@ IGL_INLINE void igl::grad_intrinsic(
   const int n = F.maxCoeff()+1;
   // number of faces
   const int m = F.rows();
-  typedef Eigen::Matrix<Gtype,Eigen::Dynamic,2> MatrixX2S;
+  // JD: There is a pretty subtle bug when using a fixed column size for this matrix.
+  // When calling igl::grad(V, ...), the two code paths `grad_tet` and `grad_tri`
+  // will be compiled. It turns out that `igl::grad_tet` calls `igl::volume`, which
+  // reads the coordinates of the `V` matrix into `RowVector3d`. If the matrix `V`
+  // has a known compile-time size of 2, this produces a compilation error when
+  // libigl is compiled in header-only mode. In static mode this doesn't happen
+  // because the matrix `V` is probably implicitly copied into a `Eigen::MatrixXd`.
+  // This is a situation that could be solved using `if constexpr` in C++17.
+  // In C++11, the alternative is to use SFINAE and `std::enable_if` (ugh).
+  typedef Eigen::Matrix<Gtype,Eigen::Dynamic,Eigen::Dynamic> MatrixX2S;
   MatrixX2S V2 = MatrixX2S::Zero(3*m,2);
   //     1=[x,y]
   //     /\
@@ -37,10 +46,10 @@ IGL_INLINE void igl::grad_intrinsic(
   V2.block(2*m,0,m,1) = l.col(0);
   // Place second vertex at [0 0]
   // Place third vertex at [x y]
-  V2.block(0,0,m,1) = 
+  V2.block(0,0,m,1) =
     (l.col(1).cwiseAbs2()-l.col(0).cwiseAbs2()-l.col(2).cwiseAbs2()).array()/
     (-2.*l.col(0)).array();
-  V2.block(0,1,m,1) = 
+  V2.block(0,1,m,1) =
     (l.col(2).cwiseAbs2() - V2.block(0,0,m,1).cwiseAbs2()).array().sqrt();
   DerivedF F2(F.rows(),F.cols());
   std::vector<Eigen::Triplet<Gtype> > Pijv;

+ 7 - 4
include/igl/is_delaunay.cpp

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
-// 
-// 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 
+//
+// 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/.
 #include "is_delaunay.h"
 #include "unique_edge_map.h"
@@ -102,4 +102,7 @@ template void igl::is_delaunay<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::
 template void igl::is_delaunay<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<bool, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<bool, -1, -1, 0, -1, -1> >&);
 // generated by autoexplicit.sh
 template bool igl::is_delaunay<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, int, short (*)(double const*, double const*, double const*, double const*), unsigned long>(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, short (*)(double const*, double const*, double const*, double const*), unsigned long);
+#ifdef WIN32
+template bool igl::is_delaunay<class Eigen::Matrix<double, -1, -1, 0, -1, -1>, class Eigen::Matrix<int, -1, -1, 0, -1, -1>, int, short(*)(double const *, double const *, double const *, double const *), unsigned __int64>(class Eigen::MatrixBase<class Eigen::Matrix<double, -1, -1, 0, -1, -1>> const &, class Eigen::MatrixBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1>> const &, class std::vector<class std::vector<int, class std::allocator<int>>, class std::allocator<class std::vector<int, class std::allocator<int>>>> const &, short(*const)(double const *, double const *, double const *, double const *), unsigned __int64);
+#endif
 #endif

+ 1 - 1
tests/include/igl/copyleft/cgal/delaunay_triangulation.cpp

@@ -5,7 +5,7 @@
 
 TEST_CASE("igl_copyleft_cgal_delaunay_triangulation: two_triangles", "[igl/copyleft/cgal]")
 {
-  const Eigen::MatrixXd V = 
+  const Eigen::MatrixXd V =
     (Eigen::MatrixXd(4,2)<<
      0,10,
      1,0,

+ 2 - 2
tutorial/716_HeatGeodesics/main.cpp

@@ -53,8 +53,8 @@ int main(int argc, char *argv[])
           (V.row(F(fid,2))-m3).squaredNorm()).minCoeff(&cid);
       const int vid = F(fid,cid);
       C.row(vid)<<1,0,0;
-      Eigen::VectorXd D = Eigen::VectorXd::Zero(data.Grad.cols(),1);
-      D(vid) = 1;
+      Eigen::VectorXd D = Eigen::VectorXd::Zero(data.Grad.cols());
+	  D(vid) = 1;
       igl::heat_geodesics_solve(data,(Eigen::VectorXi(1,1)<<vid).finished(),D);
       viewer.data().set_colors((D/D.maxCoeff()).replicate(1,3));
       return true;