Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with b9072b4 #16

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ set(LAGRANGE_IDE_PREFIX ${LAGRANGE_IDE_PREFIX_DEFAULT} CACHE STRING "Folder pref

# When building anorigami module, defaults to pre-built Arpack and dynamic MKL/TBB
# When building python module, compile MKL/TBB as a shared library
if(LAGRANGE_MODULE_ANORIGAMI OR LAGRANGE_MODULE_PYTHON OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
if(LAGRANGE_MODULE_ANORIGAMI OR LAGRANGE_MODULE_MESHPROC OR LAGRANGE_MODULE_PYTHON
OR (LAGRANGE_ALL AND NOT LAGRANGE_NO_INTERNAL))
set(MKL_LINKING "dynamic" CACHE STRING "Linking strategy to use with MKL (static, dynamic or sdl)")
option(TBB_PREFER_STATIC "Build with static TBB" OFF)
option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.13.0
6.14.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;quadrangulation
anorigami;deformers;meshproc;quadrangulation
2 changes: 1 addition & 1 deletion cmake/lagrange/lagrange_download_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function(lagrange_download_data)
PREFIX "${FETCHCONTENT_BASE_DIR}/lagrange-test-data"
SOURCE_DIR ${LAGRANGE_DATA_FOLDER}
GIT_REPOSITORY https://github.com/adobe/lagrange-test-data.git
GIT_TAG 6f0438404e272321b543ada9a828adcac49f9941
GIT_TAG 3b2de026c4b96a85f1a40b2d412586dc071c8761
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/lagrange/AttributeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <cstdint>

// clang-format off

/// @addtogroup group-surfacemesh-attr
Expand Down
9 changes: 8 additions & 1 deletion modules/core/include/lagrange/SurfaceMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,15 @@ class SurfaceMesh
/// @param[in] source_name Attribute name to copy from. If left empty, the target attribute
/// name will be used.
///
/// @tparam OtherScalar Source mesh scalar type.
/// @tparam OtherIndex Source mesh index type.
///
/// @return The attribute identifier.
///
template<typename OtherScalar, typename OtherIndex>
AttributeId create_attribute_from(
std::string_view name,
const SurfaceMesh& source_mesh,
const SurfaceMesh<OtherScalar, OtherIndex>& source_mesh,
std::string_view source_name = {});

///
Expand Down Expand Up @@ -2478,6 +2482,9 @@ class SurfaceMesh
protected:
/// @cond LA_INTERNAL_DOCS

/// It's ok to be friend with meshes of different types.
template<typename, typename> friend class SurfaceMesh;

///
/// Hidden attribute manager class.
///
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/lagrange/SurfaceMeshTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <cstdint>

// clang-format off

/// @addtogroup group-surfacemesh
Expand Down
116 changes: 40 additions & 76 deletions modules/core/include/lagrange/compute_dijkstra_distance.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* Copyright 2023 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
Expand All @@ -11,90 +11,54 @@
*/
#pragma once

#include <cassert>
#include <limits>
#include <list>
#include <queue>
#include <vector>
#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
#include <lagrange/legacy/compute_dijkstra_distance.h>
#endif

#include <lagrange/Mesh.h>
#include <lagrange/common.h>
#include <lagrange/compute_triangle_normal.h>
#include <lagrange/SurfaceMesh.h>
#include <lagrange/utils/SmallVector.h>
#include <optional>

namespace lagrange {

template <typename MeshType>
std::list<std::pair<typename MeshType::Index, typename MeshType::Scalar>> compute_dijkstra_distance(
MeshType& mesh,
typename MeshType::Index seed_facet_id,
const Eigen::Matrix<typename MeshType::Scalar, 3, 1>& bc,
typename MeshType::Scalar radius = 0.0)
///
/// Option struct for compute_dijkstra_distance
///
template <typename Scalar, typename Index>
struct DijkstraDistanceOptions
{
using Scalar = typename MeshType::Scalar;
if (mesh.get_dim() != 3) {
throw std::runtime_error("Input mesh must be 3D mesh.");
}
if (mesh.get_vertex_per_facet() != 3) {
throw std::runtime_error("Input mesh is not triangle mesh");
}
if (!mesh.has_facet_attribute("normal")) {
compute_triangle_normal(mesh);
}
if (!mesh.is_connectivity_initialized()) {
mesh.initialize_connectivity();
}
/// Seed facet index
Index seed_facet = invalid<Index>();

using Index = typename MeshType::Index;
using FacetType = Eigen::Matrix<Index, 3, 1>;
using VertexType = typename MeshType::VertexType;
using AttributeArray = typename MeshType::AttributeArray;
/// Seed facet barycentric coordinate
SmallVector<Scalar, 3> barycentric_coords;

if (radius <= 0.0) {
radius = std::numeric_limits<Scalar>::max();
}
const Index num_facets = mesh.get_num_facets();
const Index num_vertices = mesh.get_num_vertices();
const auto& vertices = mesh.get_vertices();
const auto& facets = mesh.get_facets();
la_runtime_assert(seed_facet_id < num_facets);
const FacetType seed_facet = facets.row(seed_facet_id);
const VertexType seed_point = vertices.row(seed_facet[0]) * bc[0] +
vertices.row(seed_facet[1]) * bc[1] +
vertices.row(seed_facet[2]) * bc[2];
/// Maximum radius of the dijkstra distance
Scalar radius = 0.0;

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

std::list<Entry> involved_vts;
while (!Q.empty()) {
Entry entry = Q.top();
involved_vts.push_back(entry);
Q.pop();
Scalar curr_dist = dist(entry.first, 0);
/// Output involved vertices
bool output_involved_vertices = false;
};


///
/// Computes dijkstra distance from a seed facet.
///
/// @param mesh Input mesh.
/// @param options Options for computing dijkstra distance.
///
/// @tparam Scalar Mesh scalar type.
/// @tparam Index Mesh index type.
///
/// @return Optionally, a vector of indices of vertices involved
///
template <typename Scalar, typename Index>
std::optional<std::vector<Index>> compute_dijkstra_distance(
SurfaceMesh<Scalar, Index>& mesh,
const DijkstraDistanceOptions<Scalar, Index>& options = {});

if (curr_dist < 0 || entry.second < curr_dist) {
dist(entry.first, 0) = entry.second;
const auto& adj_vertices = mesh.get_vertices_adjacent_to_vertex(entry.first);
for (const auto& vj : adj_vertices) {
Scalar d = entry.second + (vertices.row(vj) - vertices.row(entry.first)).norm();
if (d < radius) {
Scalar next_dist = dist(vj, 0);
if (next_dist < 0 || d < next_dist) {
Q.push({vj, d});
}
}
}
}
}

mesh.add_vertex_attribute("dijkstra_distance");
mesh.import_vertex_attribute("dijkstra_distance", dist);
return involved_vts;
}
} // namespace lagrange
102 changes: 102 additions & 0 deletions modules/core/include/lagrange/legacy/compute_dijkstra_distance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2017 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.
*/
#pragma once


#include <cassert>
#include <limits>
#include <list>
#include <queue>
#include <vector>

#include <lagrange/Mesh.h>
#include <lagrange/common.h>

namespace lagrange {
LAGRANGE_LEGACY_INLINE
namespace legacy {


template <typename MeshType>
std::list<std::pair<typename MeshType::Index, typename MeshType::Scalar>> compute_dijkstra_distance(
MeshType& mesh,
typename MeshType::Index seed_facet_id,
const Eigen::Matrix<typename MeshType::Scalar, 3, 1>& bc,
typename MeshType::Scalar radius = 0.0)
{
using Scalar = typename MeshType::Scalar;
if (mesh.get_dim() != 3) {
throw std::runtime_error("Input mesh must be 3D mesh.");
}
if (mesh.get_vertex_per_facet() != 3) {
throw std::runtime_error("Input mesh is not triangle mesh");
}
if (!mesh.is_connectivity_initialized()) {
mesh.initialize_connectivity();
}

using Index = typename MeshType::Index;
using FacetType = Eigen::Matrix<Index, 3, 1>;
using VertexType = typename MeshType::VertexType;
using AttributeArray = typename MeshType::AttributeArray;

if (radius <= 0.0) {
radius = std::numeric_limits<Scalar>::max();
}
const Index num_facets = mesh.get_num_facets();
const Index num_vertices = mesh.get_num_vertices();
const auto& vertices = mesh.get_vertices();
const auto& facets = mesh.get_facets();
la_runtime_assert(seed_facet_id < num_facets);
const FacetType seed_facet = facets.row(seed_facet_id);
const VertexType seed_point = vertices.row(seed_facet[0]) * bc[0] +
vertices.row(seed_facet[1]) * bc[1] +
vertices.row(seed_facet[2]) * bc[2];

using Entry = std::pair<Index, Scalar>;
auto comp = [](const Entry& e1, const Entry& e2) { return e1.second > e2.second; };
std::priority_queue<Entry, std::vector<Entry>, decltype(comp)> Q(comp);
AttributeArray dist(num_vertices, 1);
dist.setConstant(-1);
Q.push({seed_facet[0], (vertices.row(seed_facet[0]) - seed_point).norm()});
Q.push({seed_facet[1], (vertices.row(seed_facet[1]) - seed_point).norm()});
Q.push({seed_facet[2], (vertices.row(seed_facet[2]) - seed_point).norm()});

std::list<Entry> involved_vts;
while (!Q.empty()) {
Entry entry = Q.top();
involved_vts.push_back(entry);
Q.pop();
Scalar curr_dist = dist(entry.first, 0);

if (curr_dist < 0 || entry.second < curr_dist) {
dist(entry.first, 0) = entry.second;
const auto& adj_vertices = mesh.get_vertices_adjacent_to_vertex(entry.first);
for (const auto& vj : adj_vertices) {
Scalar d = entry.second + (vertices.row(vj) - vertices.row(entry.first)).norm();
if (d < radius) {
Scalar next_dist = dist(vj, 0);
if (next_dist < 0 || d < next_dist) {
Q.push({vj, d});
}
}
}
}
}

mesh.add_vertex_attribute("dijkstra_distance");
mesh.import_vertex_attribute("dijkstra_distance", dist);
return involved_vts;
}

} // namespace legacy
} // namespace lagrange
Loading
Loading