Skip to content

Commit

Permalink
Sync with fe86ed4 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
qnzhou authored Dec 13, 2024
1 parent 1ad95ef commit cc5c79a
Show file tree
Hide file tree
Showing 64 changed files with 2,183 additions and 639 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ if(LAGRANGE_MODULE_PYTHON OR LAGRANGE_ALL OR BUILD_SHARED_LIBS)
option(TBB_PREFER_STATIC "Build with static TBB" OFF)
endif()

if(LAGRANGE_MODULE_ANORIGAMI OR LAGRANGE_MODULE_MESHPROC OR LAGRANGE_MODULE_CONTOURING OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
if(LAGRANGE_MODULE_ANORIGAMI OR
LAGRANGE_MODULE_BAKING OR
LAGRANGE_MODULE_MESHPROC OR
LAGRANGE_MODULE_CONTOURING OR
(LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL)
)
# When building anorigami module, we also need to compile tbbmalloc
option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON) # TBB 2020 option
option(TBBMALLOC_BUILD "Enable tbbmalloc build" ON) # OneTBB 2021 option
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.28.0
6.29.0
2 changes: 1 addition & 1 deletion cmake/lagrange/lagrangeMklModules.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
anorigami;deformers;meshproc;quadrangulation
anorigami;baking;deformers;meshproc;quadrangulation
2 changes: 1 addition & 1 deletion cmake/recipes/external/clipper2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include(CPM)
CPMAddPackage(
NAME clipper2
GITHUB_REPOSITORY AngusJohnson/Clipper2
GIT_TAG Clipper2_1.2.0
GIT_TAG Clipper2_1.4.0
SOURCE_SUBDIR CPP
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/recipes/external/glad.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ FetchContent_Declare(
FetchContent_MakeAvailable(glad)
add_library(glad::glad ALIAS glad)

set_target_properties(glad PROPERTIES FOLDER ThirdParty)
set_target_properties(glad PROPERTIES FOLDER third_party)
2 changes: 1 addition & 1 deletion cmake/recipes/external/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ block()
CPMAddPackage(
NAME imgui
GITHUB_REPOSITORY adobe/imgui
GIT_TAG fbaad5ad4cc881f9139c3e9fa9d5747d285b1940 # docking_v1.90.4
GIT_TAG dff188effaa59c5c4d502868b96bd717207adb9c # docking_v1.91.5
)
endblock()

Expand Down
150 changes: 0 additions & 150 deletions cmake/recipes/external/libfive.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion cmake/recipes/external/poissonrecon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include(CPM)
CPMAddPackage(
NAME poissonrecon
GITHUB_REPOSITORY mkazhdan/PoissonRecon
GIT_TAG 5b774d26a1fa38c0bfc70f4bb7ac972088e3567a
GIT_TAG 8718872658a3a9eb032e951caca80146a59fc975
)

add_library(poissonrecon::poissonrecon INTERFACE IMPORTED GLOBAL)
Expand Down
5 changes: 3 additions & 2 deletions cmake/recipes/external/polyscope.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ include(glad)
include(CPM)
CPMAddPackage(
NAME polyscope
GITHUB_REPOSITORY nmwsharp/polyscope
GIT_TAG bb034326842313151c9419e51fac20c6c4ef8a93
GITHUB_REPOSITORY haskha/polyscope # change back to latest nmwsharp/polyscope after #306 is merged
GIT_TAG fc4046ee65d05cf30a2160d09eef484d1d06a363
)

add_library(polyscope::polyscope ALIAS polyscope)
set_target_properties(polyscope PROPERTIES FOLDER third_party)
4 changes: 2 additions & 2 deletions cmake/recipes/external/tbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME TBB)
include(CPM)
CPMAddPackage(
NAME tbb
GITHUB_REPOSITORY wjakob/tbb
GIT_TAG 9e219e24fe223b299783200f217e9d27790a87b0
GITHUB_REPOSITORY jdumas/tbb
GIT_TAG fc14676e566fce307558f5bf48c5e16fe81a4a58
)

# Install rules for the tbb_static target (not defined by upstream CMakeLists.txt)
Expand Down
2 changes: 1 addition & 1 deletion cmake/recipes/external/winding_number.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include(CPM)
CPMAddPackage(
NAME WindingNumber
GITHUB_REPOSITORY jdumas/WindingNumber
GIT_TAG d0083297a9c3459a61573c0a0b4c0586ea84b727
GIT_TAG a48b8f555b490afe7aab9159c7daaf83fa2cdf8e
)

set_target_properties(WindingNumber PROPERTIES FOLDER third_party)
2 changes: 1 addition & 1 deletion modules/core/examples/mesh_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void register_mesh(std::string_view mesh_name, SurfaceMesh mesh)
.unaryExpr([&](float x) { return std::is_floating_point_v<ValueType> ? x : x / 255.f; })
// Gamma correction
.unaryExpr([](float x) {
float gamma = 2.2;
float gamma = 2.2f;
return std::pow(x, gamma);
});
};
Expand Down
4 changes: 4 additions & 0 deletions modules/core/include/lagrange/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#include <limits>
#include <memory>

// clang-format off
#include <lagrange/utils/warnoff.h>
#include <Eigen/Core>
#include <lagrange/utils/warnon.h>
// clang-format on

namespace lagrange {

Expand Down
95 changes: 35 additions & 60 deletions modules/core/include/lagrange/compute_mesh_covariance.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,44 @@
*/
#pragma once

#include <Eigen/Core>
#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
#include <lagrange/legacy/compute_mesh_covariance.h>
#endif

#include <lagrange/Mesh.h>
#include <lagrange/utils/range.h>
#include <lagrange/SurfaceMesh.h>
#include <optional>

namespace lagrange {

// Compute the covariance matrix
// mesh_ref, reference to the mesh
// center, the point around which the covariance is computed.
// active_facets, the facets that are included in the covariance computation.
// Empty would imply all facets.
//
// Adapted from https://github.com/mkazhdan/ShapeSPH/blob/master/Util/TriangleMesh.h#L101
template <typename MeshType>
Eigen::Matrix<typename MeshType::Scalar, 3, 3> compute_mesh_covariance( //
const MeshType &mesh_ref,
const typename MeshType::VertexType &center,
const typename MeshType::IndexList &active_facets = typename MeshType::IndexList())
{ //

using Scalar = typename MeshType::Scalar;
using Vector3 = Eigen::Matrix<Scalar, 1, 3>;
using Matrix3 = Eigen::Matrix<Scalar, 3, 3>;

const auto &vertices = mesh_ref.get_vertices();
const auto &facets = mesh_ref.get_facets();

la_runtime_assert(vertices.cols() == 3, "Currently, only 3 dimensions are supported");
la_runtime_assert(facets.cols() == 3, "Currently, only triangles are supported");

Matrix3 factors;
factors.row(0) << Scalar(1. / 2), Scalar(1. / 3), Scalar(1. / 6);
factors.row(1) << Scalar(1. / 3), Scalar(1. / 4), Scalar(1. / 8);
factors.row(2) << Scalar(1. / 6), Scalar(1. / 8), Scalar(1. / 12);

auto triangle_covariance = [&factors](
const Vector3 &v1,
const Vector3 &v2,
const Vector3 &v3,
const Vector3 &c) -> Matrix3 {
const Scalar a = (v2 - v1).cross(v3 - v1).norm();
Matrix3 p;
p.row(0) = v1 - c;
p.row(1) = v3 - v1;
p.row(2) = v2 - v3;

const Matrix3 covariance = a * p.transpose() * factors * p;

return covariance;
};

Matrix3 covariance = Matrix3::Zero();
for (auto facet_id : range_sparse(mesh_ref.get_num_facets(), active_facets)) {
const Vector3 v0 = vertices.row(facets(facet_id, 0));
const Vector3 v1 = vertices.row(facets(facet_id, 1));
const Vector3 v2 = vertices.row(facets(facet_id, 2));
covariance += triangle_covariance(v0, v1, v2, center);
} // over triangles

// Return
return covariance;
}

///
/// Options struct for computing mesh covariance.
///
struct MeshCovarianceOptions
{
/// The center around which the covariance is computed.
std::array<double, 3> center = {0, 0, 0};
/// The attribute name for the active facets in covariance computation.
/// If empty, all facets are active.
std::optional<std::string_view> active_facets_attribute_name;
};

/**
* Compute the covariance matrix w.r.t. a given center (default to zeros).
*
* @param[in] mesh The input mesh.
* @param[in] options Optional arguments.
*
* @tparam Scalar The scalar type of the mesh.
* @tparam Index The index type of the mesh.
*
* @return The covariance matrix in column-major order (but it should be symmetric).
*
* @see MeshCovarianceOptions. Adapted from
* https://github.com/mkazhdan/ShapeSPH/blob/master/Util/TriangleMesh.h#L101
*/
template <typename Scalar, typename Index>
std::array<std::array<Scalar, 3>, 3> compute_mesh_covariance(
const SurfaceMesh<Scalar, Index>& mesh,
const MeshCovarianceOptions& options = {});

} // namespace lagrange
5 changes: 5 additions & 0 deletions modules/core/include/lagrange/corner_to_edge_mapping.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
#include <lagrange/utils/assert.h>
#include <lagrange/utils/safe_cast.h>

// clang-format off
#include <lagrange/utils/warnoff.h>
#include <tbb/parallel_sort.h>
#include <lagrange/utils/warnon.h>
// clang-format on

#include <Eigen/Dense>

#include <algorithm>
Expand Down
4 changes: 4 additions & 0 deletions modules/core/include/lagrange/internal/fast_edge_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include <lagrange/utils/assert.h>
#include <lagrange/utils/timing.h>

// clang-format off
#include <lagrange/utils/warnoff.h>
#include <tbb/parallel_sort.h>
#include <lagrange/utils/warnon.h>
// clang-format on

#include <algorithm>
#include <numeric>
Expand Down
Loading

0 comments on commit cc5c79a

Please sign in to comment.