Skip to content

Commit

Permalink
Update libigl
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Ferguson committed Mar 29, 2024
1 parent 50e6133 commit a0db726
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 72 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ target_link_libraries(${PROJECT_NAME}_dev PUBLIC osqp::osqp)
# libigl
include(eigen)
include(libigl)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core igl::triangle igl::tetgen)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core)
if(IPC_WITH_OPENGL)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::opengl_glfw igl::opengl_glfw_imgui igl::png)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::glfw igl::imgui igl::stb)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_OPENGL)
endif()

Expand Down
72 changes: 10 additions & 62 deletions cmake/recipes/libigl.cmake
Original file line number Diff line number Diff line change
@@ -1,72 +1,20 @@
#
# Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
# libigl (https://github.com/libigl/libigl)
# License: MPL-2.0
if(TARGET igl::core)
return()
endif()

message(STATUS "Third-party: creating target 'igl::core'")

# libigl
# WARNING: LIBIGL_USE_STATIC_LIBRARY=ON does not work with C++ 17
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
option(LIBIGL_WITH_CORK "Use Cork" OFF)
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
option(LIBIGL_WITH_LIM "Use LIM" OFF)
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
option(LIBIGL_WITH_PNG "Use PNG" ON)
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
option(LIBIGL_QUIET_VIEWER "Suppress viewer messages" ON)
option(LIBIGL_WITH_XML "Use XML" OFF)
option(LIBIGL_WITH_PREDICATES "Use exact predicates" ON)

set(LIBIGL_WITH_VIEWER ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW_IMGUI ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_WITH_PNG ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)

include(FetchContent)
FetchContent_Declare(
libigl
GIT_REPOSITORY https://github.com/libigl/libigl.git
GIT_TAG v2.3.0
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(libigl)
if(libigl_POPULATED)
return()
endif()
FetchContent_Populate(libigl)
set(LIBIGL_IMGUI ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_GLFW ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_OPENGL ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_STB ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE)
set(LIBIGL_PREDICATES ON CACHE BOOL "Use exact predicates" FORCE)
set(LIBIGL_COPYLEFT_TETGEN ${IPC_BUILD_MESH_PROCESSING_PROJECT} CACHE BOOL "Use Tetgen" FORCE)

include(eigen)

set(LIBIGL_WITH_PREDICATES ON CACHE BOOL "Use exact predicates" FORCE)

list(APPEND CMAKE_MODULE_PATH ${libigl_SOURCE_DIR}/cmake)
include(${libigl_SOURCE_DIR}/cmake/libigl.cmake ${libigl_BINARY_DIR})

# Install rules
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME libigl)
set_target_properties(igl PROPERTIES EXPORT_NAME core)
install(DIRECTORY ${libigl_SOURCE_DIR}/include/igl DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS igl igl_common EXPORT Libigl_Targets)
install(EXPORT Libigl_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/igl NAMESPACE igl::)
include(CPM)
CPMAddPackage("gh:libigl/[email protected]")
5 changes: 2 additions & 3 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Timer.hpp"
#include "CCDUtils.hpp"

#include <igl/triangle/triangulate.h>
#include <igl/cotmatrix.h>
#include <igl/avg_edge_length.h>
#include <igl/writeOBJ.h>
Expand Down Expand Up @@ -204,7 +203,7 @@ void Mesh<dim>::computeMassMatrix(const igl::MassMatrixType type)
cosines.col(1) = (l.col(0).array().pow(2) + l.col(2).array().pow(2) - l.col(1).array().pow(2)) / (l.col(2).array() * l.col(0).array() * 2.0);
cosines.col(2) = (l.col(1).array().pow(2) + l.col(0).array().pow(2) - l.col(2).array().pow(2)) / (l.col(0).array() * l.col(1).array() * 2.0);
Matrix<Scalar, Dynamic, 3> barycentric = cosines.array() * l.array();
normalize_row_sums(barycentric, barycentric);
barycentric = (barycentric.array().colwise() / barycentric.array().rowwise().sum()).eval();
Matrix<Scalar, Dynamic, 3> partial = barycentric;
partial.col(0).array() *= dblA.array() * 0.5;
partial.col(1).array() *= dblA.array() * 0.5;
Expand Down Expand Up @@ -354,7 +353,7 @@ void Mesh<dim>::computeMassMatrix(const igl::MassMatrixType type)
cosines.col(1) = (l.col(0).array().pow(2) + l.col(2).array().pow(2) - l.col(1).array().pow(2)) / (l.col(2).array() * l.col(0).array() * 2.0);
cosines.col(2) = (l.col(1).array().pow(2) + l.col(0).array().pow(2) - l.col(2).array().pow(2)) / (l.col(0).array() * l.col(1).array() * 2.0);
Matrix<Scalar, Dynamic, 3> barycentric = cosines.array() * l.array();
normalize_row_sums(barycentric, barycentric);
barycentric = (barycentric.array().colwise() / barycentric.array().rowwise().sum()).eval();
Matrix<Scalar, Dynamic, 3> partial = barycentric;
partial.col(0).array() *= dblA.array() * 0.5;
partial.col(1).array() *= dblA.array() * 0.5;
Expand Down
2 changes: 1 addition & 1 deletion src/Projects/Diagnostic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()
target_link_libraries(diagnostic PUBLIC osqp::osqp)

# libigl
target_link_libraries(diagnostic PUBLIC igl::core igl::triangle igl::tetgen)
target_link_libraries(diagnostic PUBLIC igl::core)

# tbb
target_link_libraries(diagnostic PUBLIC TBB::tbb)
Expand Down
1 change: 0 additions & 1 deletion src/Projects/Diagnostic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ std::string outputFolderPath = "output/";
#include <igl/readOBJ.h>
#include <igl/boundary_loop.h>
#include <igl/harmonic.h>
#include <igl/copyleft/tetgen/tetrahedralize.h>

#include <cstdio>

Expand Down
2 changes: 1 addition & 1 deletion src/Projects/MeshProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set_target_properties(meshprocessing PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE
target_link_libraries(meshprocessing PUBLIC ${PROJECT_NAME}_dev)

# libigl
target_link_libraries(meshprocessing PUBLIC igl::core igl::triangle igl::tetgen)
target_link_libraries(meshprocessing PUBLIC igl::core igl_copyleft::tetgen)

# tbb
target_link_libraries(meshprocessing PUBLIC TBB::tbb)
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <igl/readOBJ.h>
#ifdef USE_OPENGL
#include <igl/opengl/glfw/Viewer.h>
#include <igl/png/writePNG.h>
#include <igl/stb/write_image.h>
#endif
#include <igl/colormap.h>

Expand Down Expand Up @@ -384,7 +384,7 @@ void saveScreenshot(const std::string& filePath, double scale, bool writeGIF, bo

if (writePNG) {
// Save it to a PNG
igl::png::writePNG(R, G, B, A, filePath);
igl::stb::write_image(filePath, R, G, B, A);
}

if (writeGIF && (iterNum % GIFStep == 0)) {
Expand Down

0 comments on commit a0db726

Please sign in to comment.