Skip to content

Commit

Permalink
Sync with 6696bec
Browse files Browse the repository at this point in the history
  • Loading branch information
qnzhou committed May 3, 2022
1 parent 7ac3ab9 commit 1a8f10c
Show file tree
Hide file tree
Showing 42 changed files with 2,850 additions and 402 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if(LAGRANGE_WITH_CCACHE AND CCACHE_PROGRAM)
endif()

################################################################################
project(Lagrange VERSION 6.0.0)
project(Lagrange VERSION 6.1.0)

# Detects whether internal libs are available
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/recipes/internal")
Expand Down
10 changes: 9 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ The following is a list of sources from which code was used/modified in this cod
-------------------------------------------------------------------------------
This codebase contains a modified portion of code from CMake Scripts which can be obtained at:
* SOURCE:
* ['https://github.com/StableCoder/cmake-scripts/blob/master/sanitizers.cmake', 'https://github.com/StableCoder/cmake-scripts/blob/master/code-coverage.cmake']
* https://github.com/StableCoder/cmake-scripts

* LICENSE:
* https://github.com/StableCoder/cmake-scripts/blob/master/LICENSE

-------------------------------------------------------------------------------
This codebase contains a modified portion of code from Earcut which can be obtained at:
* SOURCE:
* https://github.com/mapbox/earcut.hpp

* LICENSE:
* https://github.com/mapbox/earcut.hpp/blob/master/LICENSE

-------------------------------------------------------------------------------
This codebase contains a modified portion of code from Floating-point exception handling example which can be obtained at:
* SOURCE:
Expand Down
6 changes: 5 additions & 1 deletion cmake/recipes/external/glfw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ FetchContent_MakeAvailable(glfw)

add_library(glfw::glfw ALIAS glfw)

set_target_properties(glfw PROPERTIES FOLDER third_party)
foreach(name IN ITEMS glfw update_mappings)
if(TARGET ${name})
set_target_properties(${name} PROPERTIES FOLDER third_party)
endif()
endforeach()

# Warning config
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
Expand Down
26 changes: 26 additions & 0 deletions cmake/recipes/external/mshio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright 2022 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.
#
if(TARGET mshio::mshio)
return()
endif()

message(STATUS "Third-party (external): creating target 'mshio::mshio'")

include(FetchContent)
FetchContent_Declare(
mshio
GIT_REPOSITORY https://github.com/qnzhou/MshIO.git
GIT_TAG b4f2c104ac00088e0f7f9c57ebd35e3a436f787e
)
FetchContent_MakeAvailable(mshio)

set_target_properties(mshio PROPERTIES FOLDER third_party)
2 changes: 1 addition & 1 deletion modules/core/include/lagrange/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Attribute : public AttributeBase
///
/// Gets the default value to use when growing the attribute.
///
ValueType get_default_value() { return m_default_value; }
ValueType get_default_value() const { return m_default_value; }

///
/// Sets the growth policy for external buffers.
Expand Down
74 changes: 56 additions & 18 deletions modules/core/include/lagrange/SurfaceMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,19 @@ class SurfaceMesh
///
/// Shrink buffer capacities to fit current mesh attributes, deallocating any extra capacity.
///
/// @todo Not implemented yet.
///
void shrink_to_fit();

///
/// Compress mesh storage if the mesh is regular. This iterates over all facets to check if the
/// mesh is regular. If so the following attributes are removed:
///
/// - "$facet_to_first_corner"
/// - "$corner_to_facet"
///
/// @todo Not implemented yet.
///
void compress_if_regular();

public:
Expand All @@ -417,32 +422,44 @@ class SurfaceMesh
/// @{

///
/// Whether the mesh only contains triangular facets. A mesh with no facet is considered a
/// Whether the mesh *must* only contain triangular facets. A mesh with no facet is considered a
/// triangle mesh.
///
/// @note A mesh with hybrid storage *may* still be a triangle mesh, which this method
/// does not check.
///
/// @return True if triangle mesh, False otherwise.
///
[[nodiscard]] bool is_triangle_mesh() const;

///
/// Whether the mesh only contains quadrilateral facets. A mesh with no facet is considered a
/// quad mesh.
/// Whether the mesh *must* only contains quadrilateral facets. A mesh with no facet is
/// considered a quad mesh.
///
/// @note A mesh with hybrid storage *may* still be a quad mesh, which this method
/// does not check.
///
/// @return True if quad mesh, False otherwise.
///
[[nodiscard]] bool is_quad_mesh() const;

///
/// Whether the mesh only contains facets of equal sizes. A mesh with no facet is considered
/// regular.
/// Whether the mesh *must* only contains facets of equal sizes. A mesh with no facet is
/// considered regular.
///
/// @note A mesh with hybrid storage *may* still be have regular facet sizes, which this
/// method does not check.
///
/// @return True if regular, False otherwise.
///
[[nodiscard]] bool is_regular() const;

///
/// Whether the mesh contains facets of different sizes. This is the opposite of is_regular (an
/// empty mesh is _not_ considered hybrid).
/// Whether the mesh *may* contain facets of different sizes. This is the opposite of is_regular
/// (an empty mesh is _not_ considered hybrid).
///
/// @note A mesh with hybrid storage *may* still have all its facet be the same size,
/// which this method does not check.
///
/// @return True if hybrid, False otherwise.
///
Expand Down Expand Up @@ -581,7 +598,7 @@ class SurfaceMesh
///
/// @return A pointer to the facet vertices.
///
[[nodiscard]] span<const Index> get_facet(Index f) const;
[[nodiscard]] span<const Index> get_facet_vertices(Index f) const;

///
/// Retrieves a writable pointer to a facet indices.
Expand All @@ -595,7 +612,7 @@ class SurfaceMesh
///
/// @return A pointer to the facet vertices.
///
[[nodiscard]] span<Index> ref_facet(Index f);
[[nodiscard]] span<Index> ref_facet_vertices(Index f);

public:
/// @}
Expand All @@ -612,6 +629,17 @@ class SurfaceMesh
///
[[nodiscard]] AttributeId get_attribute_id(std::string_view name) const;

///
/// Retrieve attribute name from its id.
///
/// @param[in] id %Attribute id.
///
/// @return %Attribute's name.
///
/// @throws Exception if id is invalid.
///
[[nodiscard]] std::string_view get_attribute_name(AttributeId id) const;

///
/// Create a new attribute and return the newly created attribute id. A mesh attribute is stored
/// as a row-major R x C matrix. The number of rows (R) is determined by the number of elements
Expand Down Expand Up @@ -1306,10 +1334,20 @@ class SurfaceMesh
/// @name Reserved attribute names and ids
/// @{

///
/// Check whether the given name corresponds to a reserved %attribute. Reserved %attributes are
/// %attributes whose name starts with a "$".
///
/// @param[in] name %Attribute name.
///
/// @return True if this is the name of a reserved %attribute, false otherwise.
///
static bool attr_name_is_reserved(std::string_view name);

///
/// %Attribute name for vertex -> position.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_vertex_to_position()
{
Expand All @@ -1319,14 +1357,14 @@ class SurfaceMesh
///
/// %Attribute name for corner -> vertex indices.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_corner_to_vertex() { return s_corner_to_vertex; }

///
/// %Attribute name for facet -> first corner index.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_facet_to_first_corner()
{
Expand All @@ -1336,21 +1374,21 @@ class SurfaceMesh
///
/// %Attribute name for corner -> facet index.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_corner_to_facet() { return s_corner_to_facet; }

///
/// %Attribute name for corner -> edge indices.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_corner_to_edge() { return s_corner_to_edge; }

///
/// %Attribute name for edge -> first corner index.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_edge_to_first_corner()
{
Expand All @@ -1360,7 +1398,7 @@ class SurfaceMesh
///
/// %Attribute name for corner -> next corner around edge.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_next_corner_around_edge()
{
Expand All @@ -1370,7 +1408,7 @@ class SurfaceMesh
///
/// %Attribute name for vertex -> first corner index.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_vertex_to_first_corner()
{
Expand All @@ -1380,7 +1418,7 @@ class SurfaceMesh
///
/// %Attribute name for corner -> next corner around vertex.
///
/// @return Attribute name.
/// @return %Attribute name.
///
static constexpr std::string_view attr_name_next_corner_around_vertex()
{
Expand Down
7 changes: 4 additions & 3 deletions modules/core/include/lagrange/chain_edges.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ std::vector<std::list<Index>> chain_edges(const Allocator& edges)
std::vector<Chain> chains;
VertexAdjList next;
VertexAdjList prev;
next.reserve(edges.size());
prev.reserve(edges.size());
size_t num_edges = std::distance(edges.begin(), edges.end());
next.reserve(num_edges);
prev.reserve(num_edges);
std::unordered_set<Index> visited;
visited.reserve(edges.size() * 2);
visited.reserve(num_edges * 2);

LA_IGNORE_RANGE_LOOP_ANALYSIS_BEGIN
for (const auto& e : edges) {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/lagrange/compute_mesh_centroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ComputeMeshCentroidOutput<typename MeshType::Scalar> compute_mesh_centroid( //
Vertex3 centroid = Vertex3::Zero();
Scalar area = 0;

for (auto facet_id : lagrange::range_facets(mesh_ref, active_facets)) {
for (auto facet_id : range_sparse(mesh_ref.get_num_facets(), active_facets)) {
const Vertex3 v0 = vertices.row(facets(facet_id, 0));
const Vertex3 v1 = vertices.row(facets(facet_id, 1));
const Vertex3 v2 = vertices.row(facets(facet_id, 2));
Expand Down
2 changes: 1 addition & 1 deletion modules/core/include/lagrange/compute_mesh_covariance.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Eigen::Matrix<typename MeshType::Scalar, 3, 3> compute_mesh_covariance( //
};

Matrix3 covariance = Matrix3::Zero();
for (auto facet_id : lagrange::range_facets(mesh_ref, active_facets)) {
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));
Expand Down
6 changes: 3 additions & 3 deletions modules/core/include/lagrange/sample_points_on_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ SamplePointsOnSurfaceOutput<MeshType> sample_points_on_surface(
// Otherwise we could have just used total_mesh_area = facet_area.sum().
// In the new version of eigen, we can also use facet_area( active_facets ).sum()
Scalar total_mesh_area = 0;
for (auto facet_id : range_facets(mesh, active_facets)) {
for (auto facet_id : range_sparse(mesh.get_num_facets(), active_facets)) {
total_mesh_area += facet_area(facet_id);
}

Expand All @@ -120,7 +120,7 @@ SamplePointsOnSurfaceOutput<MeshType> sample_points_on_surface(

// Find the bounding box of the active facets on the mesh
BoundingBox bounding_box(n_dims);
for (auto facet_id : range_facets(mesh, active_facets)) {
for (auto facet_id : range_sparse(mesh.get_num_facets(), active_facets)) {
for (auto vertex_offset : range(mesh.get_vertex_per_facet())) {
const Index vertex_id = facets(facet_id, vertex_offset);
// bbox needs a column vector . Hence the transpose(). Arg...
Expand Down Expand Up @@ -219,7 +219,7 @@ SamplePointsOnSurfaceOutput<MeshType> sample_points_on_surface(
// than sampling length. Then get the midpoint of that triangle if
// its corresponding grid cell is not marked already.
//
for (auto facet_id : range_facets(mesh, active_facets)) {
for (auto facet_id : range_sparse(mesh.get_num_facets(), active_facets)) {
//
// Splitting code follows.
// This is done rather inefficiently using a queue. There is no need for that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct SelectFacetsByNormalSimilarityParameters
is_facet_selectable.clear();
} else {
is_facet_selectable.resize(mesh_ref.get_num_facets(), false);
for (auto facet_id : range_facets(mesh_ref, selectable_facets)) {
for (auto facet_id : range_sparse(mesh_ref.get_num_facets(), selectable_facets)) {
is_facet_selectable[facet_id] = true;
}
}
Expand Down
36 changes: 36 additions & 0 deletions modules/core/include/lagrange/triangulate_polygonal_facets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 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 <lagrange/SurfaceMesh.h>

#include <vector>

namespace lagrange {

///
/// @defgroup group-surfacemesh-views Polygon triangulation
/// @ingroup group-surfacemesh
///

///
/// Triangulate polygonal facets of a mesh using a prescribed set of rules.
///
/// @param[in, out] mesh Polygonal mesh to triangulate in place.
///
/// @tparam Scalar Mesh scalar type.
/// @tparam Index Mesh index type.
///
template <typename Scalar, typename Index>
void triangulate_polygonal_facets(SurfaceMesh<Scalar, Index>& mesh);

} // namespace lagrange
Loading

0 comments on commit 1a8f10c

Please sign in to comment.