Skip to content

Commit f294ce1

Browse files
authored
Sync with b9072b4 (#16)
1 parent 2f78a64 commit f294ce1

17 files changed

Lines changed: 524 additions & 105 deletions

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ set(LAGRANGE_IDE_PREFIX ${LAGRANGE_IDE_PREFIX_DEFAULT} CACHE STRING "Folder pref
179179

180180
# When building anorigami module, defaults to pre-built Arpack and dynamic MKL/TBB
181181
# When building python module, compile MKL/TBB as a shared library
182-
if(LAGRANGE_MODULE_ANORIGAMI OR LAGRANGE_MODULE_PYTHON OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
182+
if(LAGRANGE_MODULE_ANORIGAMI OR LAGRANGE_MODULE_MESHPROC OR LAGRANGE_MODULE_PYTHON
183+
OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
183184
set(MKL_LINKING "dynamic" CACHE STRING "Linking strategy to use with MKL (static, dynamic or sdl)")
184185
option(TBB_PREFER_STATIC "Build with static TBB" OFF)
185186
option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.13.0
1+
6.14.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
anorigami;deformers;quadrangulation
1+
anorigami;deformers;meshproc;quadrangulation

cmake/lagrange/lagrange_download_data.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function(lagrange_download_data)
2929
PREFIX "${FETCHCONTENT_BASE_DIR}/lagrange-test-data"
3030
SOURCE_DIR ${LAGRANGE_DATA_FOLDER}
3131
GIT_REPOSITORY https://github.com/adobe/lagrange-test-data.git
32-
GIT_TAG 6f0438404e272321b543ada9a828adcac49f9941
32+
GIT_TAG 3b2de026c4b96a85f1a40b2d412586dc071c8761
3333
CONFIGURE_COMMAND ""
3434
BUILD_COMMAND ""
3535
INSTALL_COMMAND ""

modules/core/include/lagrange/AttributeTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#pragma once
1717

18+
#include <cstdint>
19+
1820
// clang-format off
1921

2022
/// @addtogroup group-surfacemesh-attr

modules/core/include/lagrange/SurfaceMesh.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,15 @@ class SurfaceMesh
836836
/// @param[in] source_name Attribute name to copy from. If left empty, the target attribute
837837
/// name will be used.
838838
///
839+
/// @tparam OtherScalar Source mesh scalar type.
840+
/// @tparam OtherIndex Source mesh index type.
841+
///
839842
/// @return The attribute identifier.
840843
///
844+
template<typename OtherScalar, typename OtherIndex>
841845
AttributeId create_attribute_from(
842846
std::string_view name,
843-
const SurfaceMesh& source_mesh,
847+
const SurfaceMesh<OtherScalar, OtherIndex>& source_mesh,
844848
std::string_view source_name = {});
845849

846850
///
@@ -2478,6 +2482,9 @@ class SurfaceMesh
24782482
protected:
24792483
/// @cond LA_INTERNAL_DOCS
24802484

2485+
/// It's ok to be friend with meshes of different types.
2486+
template<typename, typename> friend class SurfaceMesh;
2487+
24812488
///
24822489
/// Hidden attribute manager class.
24832490
///

modules/core/include/lagrange/SurfaceMeshTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#pragma once
1717

18+
#include <cstdint>
19+
1820
// clang-format off
1921

2022
/// @addtogroup group-surfacemesh
Lines changed: 40 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Adobe. All rights reserved.
2+
* Copyright 2023 Adobe. All rights reserved.
33
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License. You may obtain a copy
55
* of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -11,90 +11,54 @@
1111
*/
1212
#pragma once
1313

14-
#include <cassert>
15-
#include <limits>
16-
#include <list>
17-
#include <queue>
18-
#include <vector>
14+
#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
15+
#include <lagrange/legacy/compute_dijkstra_distance.h>
16+
#endif
1917

20-
#include <lagrange/Mesh.h>
21-
#include <lagrange/common.h>
22-
#include <lagrange/compute_triangle_normal.h>
18+
#include <lagrange/SurfaceMesh.h>
19+
#include <lagrange/utils/SmallVector.h>
20+
#include <optional>
2321

2422
namespace lagrange {
2523

26-
template <typename MeshType>
27-
std::list<std::pair<typename MeshType::Index, typename MeshType::Scalar>> compute_dijkstra_distance(
28-
MeshType& mesh,
29-
typename MeshType::Index seed_facet_id,
30-
const Eigen::Matrix<typename MeshType::Scalar, 3, 1>& bc,
31-
typename MeshType::Scalar radius = 0.0)
24+
///
25+
/// Option struct for compute_dijkstra_distance
26+
///
27+
template <typename Scalar, typename Index>
28+
struct DijkstraDistanceOptions
3229
{
33-
using Scalar = typename MeshType::Scalar;
34-
if (mesh.get_dim() != 3) {
35-
throw std::runtime_error("Input mesh must be 3D mesh.");
36-
}
37-
if (mesh.get_vertex_per_facet() != 3) {
38-
throw std::runtime_error("Input mesh is not triangle mesh");
39-
}
40-
if (!mesh.has_facet_attribute("normal")) {
41-
compute_triangle_normal(mesh);
42-
}
43-
if (!mesh.is_connectivity_initialized()) {
44-
mesh.initialize_connectivity();
45-
}
30+
/// Seed facet index
31+
Index seed_facet = invalid<Index>();
4632

47-
using Index = typename MeshType::Index;
48-
using FacetType = Eigen::Matrix<Index, 3, 1>;
49-
using VertexType = typename MeshType::VertexType;
50-
using AttributeArray = typename MeshType::AttributeArray;
33+
/// Seed facet barycentric coordinate
34+
SmallVector<Scalar, 3> barycentric_coords;
5135

52-
if (radius <= 0.0) {
53-
radius = std::numeric_limits<Scalar>::max();
54-
}
55-
const Index num_facets = mesh.get_num_facets();
56-
const Index num_vertices = mesh.get_num_vertices();
57-
const auto& vertices = mesh.get_vertices();
58-
const auto& facets = mesh.get_facets();
59-
la_runtime_assert(seed_facet_id < num_facets);
60-
const FacetType seed_facet = facets.row(seed_facet_id);
61-
const VertexType seed_point = vertices.row(seed_facet[0]) * bc[0] +
62-
vertices.row(seed_facet[1]) * bc[1] +
63-
vertices.row(seed_facet[2]) * bc[2];
36+
/// Maximum radius of the dijkstra distance
37+
Scalar radius = 0.0;
6438

65-
using Entry = std::pair<Index, Scalar>;
66-
auto comp = [](const Entry& e1, const Entry& e2) { return e1.second > e2.second; };
67-
std::priority_queue<Entry, std::vector<Entry>, decltype(comp)> Q(comp);
68-
AttributeArray dist(num_vertices, 1);
69-
dist.setConstant(-1);
70-
Q.push({seed_facet[0], (vertices.row(seed_facet[0]) - seed_point).norm()});
71-
Q.push({seed_facet[1], (vertices.row(seed_facet[1]) - seed_point).norm()});
72-
Q.push({seed_facet[2], (vertices.row(seed_facet[2]) - seed_point).norm()});
39+
/// Output attribute name for dijkstra distance.
40+
std::string_view output_attribute_name = "@dijkstra_distance";
7341

74-
std::list<Entry> involved_vts;
75-
while (!Q.empty()) {
76-
Entry entry = Q.top();
77-
involved_vts.push_back(entry);
78-
Q.pop();
79-
Scalar curr_dist = dist(entry.first, 0);
42+
/// Output involved vertices
43+
bool output_involved_vertices = false;
44+
};
45+
46+
47+
///
48+
/// Computes dijkstra distance from a seed facet.
49+
///
50+
/// @param mesh Input mesh.
51+
/// @param options Options for computing dijkstra distance.
52+
///
53+
/// @tparam Scalar Mesh scalar type.
54+
/// @tparam Index Mesh index type.
55+
///
56+
/// @return Optionally, a vector of indices of vertices involved
57+
///
58+
template <typename Scalar, typename Index>
59+
std::optional<std::vector<Index>> compute_dijkstra_distance(
60+
SurfaceMesh<Scalar, Index>& mesh,
61+
const DijkstraDistanceOptions<Scalar, Index>& options = {});
8062

81-
if (curr_dist < 0 || entry.second < curr_dist) {
82-
dist(entry.first, 0) = entry.second;
83-
const auto& adj_vertices = mesh.get_vertices_adjacent_to_vertex(entry.first);
84-
for (const auto& vj : adj_vertices) {
85-
Scalar d = entry.second + (vertices.row(vj) - vertices.row(entry.first)).norm();
86-
if (d < radius) {
87-
Scalar next_dist = dist(vj, 0);
88-
if (next_dist < 0 || d < next_dist) {
89-
Q.push({vj, d});
90-
}
91-
}
92-
}
93-
}
94-
}
9563

96-
mesh.add_vertex_attribute("dijkstra_distance");
97-
mesh.import_vertex_attribute("dijkstra_distance", dist);
98-
return involved_vts;
99-
}
10064
} // namespace lagrange
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2017 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
#pragma once
13+
14+
15+
#include <cassert>
16+
#include <limits>
17+
#include <list>
18+
#include <queue>
19+
#include <vector>
20+
21+
#include <lagrange/Mesh.h>
22+
#include <lagrange/common.h>
23+
24+
namespace lagrange {
25+
LAGRANGE_LEGACY_INLINE
26+
namespace legacy {
27+
28+
29+
template <typename MeshType>
30+
std::list<std::pair<typename MeshType::Index, typename MeshType::Scalar>> compute_dijkstra_distance(
31+
MeshType& mesh,
32+
typename MeshType::Index seed_facet_id,
33+
const Eigen::Matrix<typename MeshType::Scalar, 3, 1>& bc,
34+
typename MeshType::Scalar radius = 0.0)
35+
{
36+
using Scalar = typename MeshType::Scalar;
37+
if (mesh.get_dim() != 3) {
38+
throw std::runtime_error("Input mesh must be 3D mesh.");
39+
}
40+
if (mesh.get_vertex_per_facet() != 3) {
41+
throw std::runtime_error("Input mesh is not triangle mesh");
42+
}
43+
if (!mesh.is_connectivity_initialized()) {
44+
mesh.initialize_connectivity();
45+
}
46+
47+
using Index = typename MeshType::Index;
48+
using FacetType = Eigen::Matrix<Index, 3, 1>;
49+
using VertexType = typename MeshType::VertexType;
50+
using AttributeArray = typename MeshType::AttributeArray;
51+
52+
if (radius <= 0.0) {
53+
radius = std::numeric_limits<Scalar>::max();
54+
}
55+
const Index num_facets = mesh.get_num_facets();
56+
const Index num_vertices = mesh.get_num_vertices();
57+
const auto& vertices = mesh.get_vertices();
58+
const auto& facets = mesh.get_facets();
59+
la_runtime_assert(seed_facet_id < num_facets);
60+
const FacetType seed_facet = facets.row(seed_facet_id);
61+
const VertexType seed_point = vertices.row(seed_facet[0]) * bc[0] +
62+
vertices.row(seed_facet[1]) * bc[1] +
63+
vertices.row(seed_facet[2]) * bc[2];
64+
65+
using Entry = std::pair<Index, Scalar>;
66+
auto comp = [](const Entry& e1, const Entry& e2) { return e1.second > e2.second; };
67+
std::priority_queue<Entry, std::vector<Entry>, decltype(comp)> Q(comp);
68+
AttributeArray dist(num_vertices, 1);
69+
dist.setConstant(-1);
70+
Q.push({seed_facet[0], (vertices.row(seed_facet[0]) - seed_point).norm()});
71+
Q.push({seed_facet[1], (vertices.row(seed_facet[1]) - seed_point).norm()});
72+
Q.push({seed_facet[2], (vertices.row(seed_facet[2]) - seed_point).norm()});
73+
74+
std::list<Entry> involved_vts;
75+
while (!Q.empty()) {
76+
Entry entry = Q.top();
77+
involved_vts.push_back(entry);
78+
Q.pop();
79+
Scalar curr_dist = dist(entry.first, 0);
80+
81+
if (curr_dist < 0 || entry.second < curr_dist) {
82+
dist(entry.first, 0) = entry.second;
83+
const auto& adj_vertices = mesh.get_vertices_adjacent_to_vertex(entry.first);
84+
for (const auto& vj : adj_vertices) {
85+
Scalar d = entry.second + (vertices.row(vj) - vertices.row(entry.first)).norm();
86+
if (d < radius) {
87+
Scalar next_dist = dist(vj, 0);
88+
if (next_dist < 0 || d < next_dist) {
89+
Q.push({vj, d});
90+
}
91+
}
92+
}
93+
}
94+
}
95+
96+
mesh.add_vertex_attribute("dijkstra_distance");
97+
mesh.import_vertex_attribute("dijkstra_distance", dist);
98+
return involved_vts;
99+
}
100+
101+
} // namespace legacy
102+
} // namespace lagrange

0 commit comments

Comments
 (0)