Răsfoiți Sursa

Merge branch 'dev' of github.com:libigl/libigl into dev

Former-commit-id: 28dd927d18e06d5cb771e0e17faad9bf0a836c09
Alec Jacobson 6 ani în urmă
părinte
comite
928cbe67bb

+ 3 - 0
CMakeLists.txt

@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.1)
+
+include(${CMAKE_CURRENT_LIST_DIR}/optional/CMakeLists.txt)

+ 92 - 5
include/igl/principal_curvature.cpp

@@ -692,8 +692,8 @@ IGL_INLINE void CurvatureCalculator::computeCurvature()
 
     if (vv.size()<6)
     {
-      std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
-      return;
+      //std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
+      continue;
     }
 
 
@@ -720,8 +720,8 @@ IGL_INLINE void CurvatureCalculator::computeCurvature()
     }
     if (vv.size()<6)
     {
-      std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
-      return;
+      //std::cerr << "Could not compute curvature of radius " << scaledRadius << std::endl;
+      continue;
     }
     if (montecarlo)
     {
@@ -773,6 +773,92 @@ IGL_INLINE void CurvatureCalculator::printCurvature(const std::string& outpath)
 
 }
 
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename DerivedPD1,
+  typename DerivedPD2,
+  typename DerivedPV1,
+  typename DerivedPV2,
+  typename Index>
+IGL_INLINE void igl::principal_curvature(
+  const Eigen::PlainObjectBase<DerivedV>& V,
+  const Eigen::PlainObjectBase<DerivedF>& F,
+  Eigen::PlainObjectBase<DerivedPD1>& PD1,
+  Eigen::PlainObjectBase<DerivedPD2>& PD2,
+  Eigen::PlainObjectBase<DerivedPV1>& PV1,
+  Eigen::PlainObjectBase<DerivedPV2>& PV2,
+  std::vector<Index>& bad_vertices,
+  unsigned radius,
+  bool useKring)
+{
+
+  if (radius < 2)
+  {
+    radius = 2;
+    std::cout << "WARNING: igl::principal_curvature needs a radius >= 2, fixing it to 2." << std::endl;
+  }
+
+  // Preallocate memory
+  PD1.resize(V.rows(),3);
+  PD2.resize(V.rows(),3);
+
+  // Preallocate memory
+  PV1.resize(V.rows(),1);
+  PV2.resize(V.rows(),1);
+
+  // Precomputation
+  CurvatureCalculator cc;
+  cc.init(V.template cast<double>(),F.template cast<int>());
+  cc.sphereRadius = radius;
+
+  if (useKring)
+  {
+    cc.kRing = radius;
+    cc.st = K_RING_SEARCH;
+  }
+
+  // Compute
+  cc.computeCurvature();
+
+  // Copy it back
+  for (unsigned i=0; i<V.rows(); ++i)
+  {
+    if (!cc.curv[i].empty())
+    {
+      PD1.row(i) << cc.curvDir[i][0][0], cc.curvDir[i][0][1], cc.curvDir[i][0][2];
+      PD2.row(i) << cc.curvDir[i][1][0], cc.curvDir[i][1][1], cc.curvDir[i][1][2];
+      PD1.row(i).normalize();
+      PD2.row(i).normalize();
+
+      if (std::isnan(PD1(i,0)) || std::isnan(PD1(i,1)) || std::isnan(PD1(i,2)) || std::isnan(PD2(i,0)) || std::isnan(PD2(i,1)) || std::isnan(PD2(i,2)))
+      {
+        PD1.row(i) << 0,0,0;
+        PD2.row(i) << 0,0,0;
+      }
+
+      PV1(i) = cc.curv[i][0];
+      PV2(i) = cc.curv[i][1];
+
+      if (PD1.row(i) * PD2.row(i).transpose() > 10e-6)
+      {
+        bad_vertices.push_back((Index)i);
+
+        PD1.row(i) *= 0;
+        PD2.row(i) *= 0;
+      }
+    } else {
+      bad_vertices.push_back((Index)i);
+
+      PV1(i) = 0;
+      PV2(i) = 0;
+      PD1.row(i) << 0,0,0;
+      PD2.row(i) << 0,0,0;
+    }
+  }
+
+}
+
 template <
   typename DerivedV,
   typename DerivedF,
@@ -851,4 +937,5 @@ IGL_INLINE void igl::principal_curvature(
 template void igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
 template void igl::principal_curvature<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, unsigned int, bool);
 template void igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, unsigned int, bool);
-#endif
+template void igl::principal_curvature<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, std::vector<int, std::allocator<int> >&, unsigned int, bool);
+#endif

+ 29 - 4
include/igl/principal_curvature.h

@@ -12,6 +12,8 @@
 #include <Eigen/Geometry>
 #include <Eigen/Dense>
 
+#include <vector>
+
 #include "igl_inline.h"
 //#include <igl/cotmatrix.h>
 //#include <igl/writeOFF.h>
@@ -35,6 +37,9 @@ namespace igl
   //   PV1 #V by 1 maximal curvature value for each vertex.
   //   PV2 #V by 1 minimal curvature value for each vertex.
   //
+  // Return value:
+  //   Function returns vector of indices of bad vertices if any.
+  //
   // See also: average_onto_faces, average_onto_vertices
   //
   // This function has been developed by: Nikolas De Giorgis, Luigi Rocca and Enrico Puppo.
@@ -43,11 +48,11 @@ namespace igl
   // Daniele Panozzo, Enrico Puppo, Luigi Rocca
   // GraVisMa, 2010
 template <
-  typename DerivedV, 
+  typename DerivedV,
   typename DerivedF,
-  typename DerivedPD1, 
-  typename DerivedPD2, 
-  typename DerivedPV1, 
+  typename DerivedPD1,
+  typename DerivedPD2,
+  typename DerivedPV1,
   typename DerivedPV2>
 IGL_INLINE void principal_curvature(
   const Eigen::PlainObjectBase<DerivedV>& V,
@@ -58,6 +63,26 @@ IGL_INLINE void principal_curvature(
   Eigen::PlainObjectBase<DerivedPV2>& PV2,
   unsigned radius = 5,
   bool useKring = true);
+
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename DerivedPD1,
+  typename DerivedPD2,
+  typename DerivedPV1,
+  typename DerivedPV2,
+  typename Index>
+IGL_INLINE void principal_curvature(
+  const Eigen::PlainObjectBase<DerivedV>& V,
+  const Eigen::PlainObjectBase<DerivedF>& F,
+  Eigen::PlainObjectBase<DerivedPD1>& PD1,
+  Eigen::PlainObjectBase<DerivedPD2>& PD2,
+  Eigen::PlainObjectBase<DerivedPV1>& PV1,
+  Eigen::PlainObjectBase<DerivedPV2>& PV2,
+  std::vector<Index>& bad_vertices,
+  unsigned radius = 5,
+  bool useKring = true);
+
 }
 
 

+ 2 - 2
optional/CMakeLists.txt

@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.1)
 project(libigl)
 
-set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../shared/cmake")
+set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../shared/cmake")
 # These ensure that lib*.a are placed in the directory where `cmake
 # ../optional/` was issued.
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
@@ -9,7 +9,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
 
 ### conditionally compile certain modules depending on libraries found on the system
-list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../shared/cmake)
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../shared/cmake)
 find_package(CGAL QUIET COMPONENTS Core)
 find_package(MATLAB QUIET)
 find_package(MOSEK)

+ 29 - 0
shared/cmake/libigl-config.cmake.in

@@ -0,0 +1,29 @@
+@PACKAGE_INIT@
+
+include(${CMAKE_CURRENT_LIST_DIR}/libigl-export.cmake)
+
+if (TARGET igl::core)
+  if (NOT TARGET Eigen3::Eigen)
+    find_package(Eigen3 QUIET)
+    if (NOT Eigen3_FOUND)
+      # try with PkgCOnfig
+      find_package(PkgConfig REQUIRED)
+      pkg_check_modules(Eigen3 QUIET IMPORTED_TARGET eigen3)
+    endif()
+
+    if (NOT Eigen3_FOUND)
+      message(FATAL_ERROR "Could not find required dependency Eigen3")
+      set(libigl_core_FOUND FALSE)
+    else()
+      target_link_libraries(igl::core INTERFACE PkgConfig::Eigen3)
+      set(libigl_core_FOUND TRUE)
+    endif()
+  else()
+    target_link_libraries(igl::core INTERFACE Eigen3::Eigen)
+    set(libigl_core_FOUND TRUE)
+  endif()
+
+endif()
+
+check_required_components(libigl)
+

+ 92 - 2
shared/cmake/libigl.cmake

@@ -68,7 +68,12 @@ endif()
 ################################################################################
 
 add_library(igl_common INTERFACE)
-target_include_directories(igl_common SYSTEM INTERFACE ${LIBIGL_SOURCE_DIR})
+target_include_directories(igl_common SYSTEM INTERFACE
+  $<BUILD_INTERFACE:${LIBIGL_SOURCE_DIR}>
+  $<INSTALL_INTERFACE:include>
+)
+# Export igl_common as igl::common
+set_property(TARGET igl_common PROPERTY EXPORT_NAME igl::common)
 if(LIBIGL_USE_STATIC_LIBRARY)
   target_compile_definitions(igl_common INTERFACE -DIGL_STATIC_LIBRARY)
 endif()
@@ -93,7 +98,10 @@ if(TARGET Eigen3::Eigen)
   # If an imported target already exists, use it
   target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
 else()
-  target_include_directories(igl_common SYSTEM INTERFACE ${LIBIGL_EXTERNAL}/eigen)
+  target_include_directories(igl_common SYSTEM INTERFACE 
+    $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
+    $<INSTALL_INTERFACE:include>
+  )
 endif()
 
 # C++11 Thread library
@@ -163,8 +171,11 @@ function(compile_igl_module module_dir)
   # Alias target because it looks nicer
   message(STATUS "Creating target: igl::${module_name} (${module_libname})")
   add_library(igl::${module_name} ALIAS ${module_libname})
+  # Export as igl::${module_name}
+  set_property(TARGET ${module_libname} PROPERTY EXPORT_NAME igl::${module_name})
 endfunction()
 
+
 ################################################################################
 ### IGL Core
 ################################################################################
@@ -432,3 +443,82 @@ if(LIBIGL_WITH_XML)
   target_link_libraries(igl_xml ${IGL_SCOPE} tinyxml2)
   target_include_directories(igl_xml ${IGL_SCOPE} ${TINYXML2_DIR})
 endif()
+
+################################################################################
+### Install and export all modules
+
+function(install_dir_files dir_name)
+  if (dir_name STREQUAL "core")
+    set(subpath "")
+  else()
+    set(subpath "/${dir_name}")
+  endif()
+
+  file(GLOB public_headers
+    ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.h
+  )
+
+  set(files_to_install ${public_headers})
+
+  if(NOT LIBIGL_USE_STATIC_LIBRARY)
+    file(GLOB public_sources
+      ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.cpp
+    )
+  endif()
+  list(APPEND files_to_install ${public_sources})
+
+  install(
+    FILES ${files_to_install}
+    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/igl${subpath}
+  )
+endfunction()
+
+################################################################################
+
+include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
+
+# Install and export core library
+install(
+   TARGETS
+     igl
+     igl_common
+   EXPORT igl-export
+   PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+export(
+  TARGETS
+    igl
+    igl_common
+  FILE libigl-export.cmake
+)
+
+# Install headers for core library
+install_dir_files(core)
+install_dir_files(copyleft)
+
+# Write package configuration file
+configure_package_config_file(
+  ${CMAKE_CURRENT_LIST_DIR}/libigl-config.cmake.in
+  ${CMAKE_BINARY_DIR}/libigl-config.cmake
+  INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libigl/cmake
+)
+install(
+  FILES
+    ${CMAKE_BINARY_DIR}/libigl-config.cmake
+  DESTINATION
+    ${CMAKE_INSTALL_DATADIR}/libigl/cmake
+)
+
+# Write export file
+export(EXPORT igl-export
+  FILE "${CMAKE_BINARY_DIR}/libigl-export.cmake"
+)
+install(EXPORT igl-export DESTINATION ${CMAKE_INSTALL_DATADIR}/libigl/cmake FILE libigl-export.cmake)
+
+
+export(PACKAGE libigl)
+