Skip to content

Commit

Permalink
Sync with 3d5b3fe (#38)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephanie Wang <[email protected]>
  • Loading branch information
evastgh and Stephanie Wang authored Aug 6, 2024
1 parent 4d53624 commit 5bdff7d
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 519 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.24.0
6.25.0
4 changes: 2 additions & 2 deletions cmake/recipes/external/assimp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ CPMAddPackage(
GIT_TAG c1deb808faadd85a7a007447b62ae238a4be2337
)

set_target_properties(assimp PROPERTIES FOLDER third_party//assimp)
set_target_properties(assimp PROPERTIES FOLDER third_party/assimp)
if(TARGET UpdateAssimpLibsDebugSymbolsAndDLLs)
set_target_properties(UpdateAssimpLibsDebugSymbolsAndDLLs PROPERTIES FOLDER third_party//assimp)
set_target_properties(UpdateAssimpLibsDebugSymbolsAndDLLs PROPERTIES FOLDER third_party/assimp)
endif()
set_target_properties(zlibstatic PROPERTIES FOLDER third_party)
10 changes: 10 additions & 0 deletions cmake/recipes/external/blosc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ set_target_properties(blosc_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(NOT TARGET Blosc::blosc)
add_library(Blosc::blosc ALIAS blosc_static)
endif()

foreach(name IN ITEMS
blosc_static
blosc_shared
bench
fuzz_compress
fuzz_decompress
)
set_target_properties(${name} PROPERTIES FOLDER third_party/blosc)
endforeach()
474 changes: 0 additions & 474 deletions cmake/recipes/external/mkl.cmake

This file was deleted.

1 change: 0 additions & 1 deletion modules/bvh/include/lagrange/bvh/BVHNanoflann.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class BVHNanoflann : public BVH<_VertexArray, _ElementArray>
return false;
}


void build(const VertexArray&, const ElementArray&) override
{
la_runtime_assert(0, "BVHNannoflann does not support elements.");
Expand Down
1 change: 1 addition & 0 deletions modules/core/include/lagrange/AttributeFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum class AttributeUsage : uint16_t {
FacetIndex = (1 << 9), ///< Single channel integer attribute indexing a mesh facet.
CornerIndex = (1 << 10), ///< Single channel integer attribute indexing a mesh corner.
EdgeIndex = (1 << 11), ///< Single channel integer attribute indexing a mesh edge.
String = (1 << 12), ///< Mesh attribute is a metadata string (stored as a uint8_t buffer).
};

/// Identified to be used to access an attribute. Attribute names are mapped to a unique identified
Expand Down
56 changes: 56 additions & 0 deletions modules/core/include/lagrange/SurfaceMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,62 @@ class SurfaceMesh
AttributeExportPolicy policy = AttributeExportPolicy::CopyIfExternal)
-> std::shared_ptr<const IndexedAttribute<ValueType, Index>>;

public:
/// @}
/// @name Metadata attributes
/// @{

///
/// Create a metadata attribute. Internally, a metadata attribute is simply
/// a regular mesh attribute with the following properties:
///
/// - Element type is `AttributeElement::Value`
/// - Usage is `AttributeUsage::String`
/// - ValueType is `uint8_t`
/// - Number of channels is 1.
///
/// @param name Attribute name.
/// @param value Attribute default value.
///
/// @return AttributeId Id of the newly created attribute
///
AttributeId create_metadata(std::string_view name, std::string_view value);

///
/// Write metadata attribute value.
///
/// @param id Attribute id.
/// @param value Attribute value.
///
void set_metadata(AttributeId id, std::string_view value);

///
/// Write metadata attribute value.
///
/// @param[in] name The name
/// @param value Attribute value.
/// @param id Attribute id.
///
void set_metadata(std::string_view name, std::string_view value);

///
/// Read metadata attribute value.
///
/// @param id Attribute id.
///
/// @return Attribute value.
///
std::string_view get_metadata(AttributeId id) const;

///
/// Read metadata attribute value.
///
/// @param name Attribute name.
///
/// @return Attribute value.
///
std::string_view get_metadata(std::string_view name) const;

public:
/// @}
/// @name Attribute accessors
Expand Down
1 change: 1 addition & 0 deletions modules/core/include/lagrange/utils/warnoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
Expand Down
58 changes: 58 additions & 0 deletions modules/core/python/src/bind_surface_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,64 @@ If not provided, the edges are initialized in an arbitrary order.
surface_mesh_class.def("get_one_corner_around_vertex", &MeshType::get_one_corner_around_vertex);
surface_mesh_class.def("is_boundary_edge", &MeshType::is_boundary_edge);

struct MetaData
{
MeshType* mesh = nullptr;

std::vector<AttributeId> get_metadata() const
{
la_runtime_assert(mesh != nullptr, "MetaData is not initialized.");
lagrange::AttributeMatcher opts;
opts.usages = AttributeUsage::String;
opts.element_types = AttributeElement::Value;
opts.num_channels = 1;
return lagrange::find_matching_attributes(*mesh, opts);
}
};
auto meta_data_class = nb::class_<MetaData>(m, "MetaData");
meta_data_class.def("__len__", [](const MetaData& self) {
auto data = self.get_metadata();
return data.size();
});
meta_data_class.def("__getitem__", [](const MetaData& self, std::string_view key) {
return self.mesh->get_metadata(key);
});
meta_data_class.def(
"__setitem__",
[](MetaData& self, std::string_view key, std::string_view value) {
la_runtime_assert(self.mesh != nullptr, "MetaData is not initialized.");
if (self.mesh->has_attribute(key)) {
self.mesh->set_metadata(key, value);
} else {
self.mesh->create_metadata(key, value);
}
});
meta_data_class.def("__delitem__", [](MetaData& self, std::string_view key) {
la_runtime_assert(self.mesh != nullptr, "MetaData is not initialized.");
self.mesh->delete_attribute(key);
});
meta_data_class.def("__repr__", [](const MetaData& self) -> std::string {
auto data = self.get_metadata();
if (data.empty()) return "MetaData({})";

std::string r;
for (auto id : data) {
auto name = self.mesh->get_attribute_name(id);
auto value = self.mesh->get_metadata(id);
fmt::format_to(std::back_inserter(r), " {}: {},\n", name, value);
}
return fmt::format("MetaData(\n{})", r);
});

surface_mesh_class.def_prop_ro(
"metadata",
[](MeshType& self) {
MetaData meta_data;
meta_data.mesh = &self;
return meta_data;
},
"Metadata of the mesh.");

surface_mesh_class.def(
"get_matching_attribute_ids",
[](MeshType& self,
Expand Down
9 changes: 9 additions & 0 deletions modules/core/python/tests/test_surface_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,12 @@ def test_position_usage(self, single_triangle):
mesh = single_triangle
position_attr = mesh.attribute(mesh.attr_id_vertex_to_position)
assert position_attr.usage == lagrange.AttributeUsage.Position

def test_metadata(self, single_triangle):
mesh = single_triangle
mesh.metadata["author"] = "John"
assert mesh.metadata["author"] == "John"
mesh.metadata["author"] = "Jane"
assert mesh.metadata["author"] == "Jane"
mesh.metadata["author"] = "🐶"
assert mesh.metadata["author"] == "🐶"
3 changes: 3 additions & 0 deletions modules/core/src/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ AttributeBase::AttributeBase(AttributeElement element, AttributeUsage usage, siz
case AttributeUsage::FacetIndex: la_runtime_assert(num_channels == 1); break;
case AttributeUsage::CornerIndex: la_runtime_assert(num_channels == 1); break;
case AttributeUsage::EdgeIndex: la_runtime_assert(num_channels == 1); break;
case AttributeUsage::String: la_runtime_assert(num_channels == 1); break;
default: throw Error("Unsupported usage");
}
}
Expand Down Expand Up @@ -79,6 +80,8 @@ Attribute<ValueType>::Attribute(AttributeElement element, AttributeUsage usage,
case AttributeUsage::Bitangent: la_runtime_assert(std::is_floating_point_v<ValueType>); break;
case AttributeUsage::Color: break;
case AttributeUsage::UV: break;
// TODO: Fix parsing error with la_runtime_assert() and <,> syntax
case AttributeUsage::String: la_runtime_assert((std::is_same_v<ValueType, uint8_t>)); break;
default: throw Error("Unsupported usage");
}
LA_IGNORE_SWITCH_ENUM_WARNING_END
Expand Down
41 changes: 41 additions & 0 deletions modules/core/src/SurfaceMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,47 @@ auto SurfaceMesh<Scalar, Index>::delete_and_export_const_indexed_attribute(
return attr_ptr;
}

template <typename Scalar, typename Index>
AttributeId SurfaceMesh<Scalar, Index>::create_metadata(
std::string_view name,
std::string_view value)
{
static_assert(sizeof(char) == sizeof(uint8_t));
auto id = create_attribute<uint8_t>(name, AttributeElement::Value, AttributeUsage::String);
set_metadata(id, value);
return id;
}

template <typename Scalar, typename Index>
void SurfaceMesh<Scalar, Index>::set_metadata(AttributeId id, std::string_view value)
{
// TODO: Should we make this null-terminated?
auto& attr = ref_attribute<uint8_t>(id);
attr.resize_elements(value.size());
la_debug_assert(attr.get_usage() == AttributeUsage::String);
std::copy_n(value.begin(), value.size(), attr.ref_all().begin());
}

template <typename Scalar, typename Index>
void SurfaceMesh<Scalar, Index>::set_metadata(std::string_view name, std::string_view value)
{
set_metadata(get_attribute_id(name), value);
}

template <typename Scalar, typename Index>
std::string_view SurfaceMesh<Scalar, Index>::get_metadata(AttributeId id) const
{
const auto& attr = get_attribute<uint8_t>(id);
la_debug_assert(attr.get_usage() == AttributeUsage::String);
return {reinterpret_cast<const char*>(attr.get_all().data()), attr.get_all().size()};
}

template <typename Scalar, typename Index>
std::string_view SurfaceMesh<Scalar, Index>::get_metadata(std::string_view name) const
{
return get_metadata(get_attribute_id(name));
}

template <typename Scalar, typename Index>
bool SurfaceMesh<Scalar, Index>::has_attribute(std::string_view name) const
{
Expand Down
10 changes: 4 additions & 6 deletions modules/core/src/views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,26 @@ ConstVectorView<ValueType> vector_view(const Attribute<ValueType>& attribute)
template <typename ValueType>
RowMatrixView<ValueType> reshaped_ref(Attribute<ValueType>& attribute, size_t num_cols)
{
la_runtime_assert(attribute.get_num_channels() == 1);
if (attribute.empty()) {
return {attribute.ref_all().data(), 0, Eigen::Index(num_cols)};
}
la_runtime_assert(num_cols != 0 && attribute.get_num_elements() % num_cols == 0);
la_runtime_assert(num_cols != 0 && attribute.get_all().size() % num_cols == 0);
return {
attribute.ref_all().data(),
Eigen::Index(attribute.get_num_elements() / num_cols),
Eigen::Index(attribute.get_all().size() / num_cols),
Eigen::Index(num_cols)};
}

template <typename ValueType>
ConstRowMatrixView<ValueType> reshaped_view(const Attribute<ValueType>& attribute, size_t num_cols)
{
la_runtime_assert(attribute.get_num_channels() == 1);
if (attribute.empty()) {
return {attribute.get_all().data(), 0, Eigen::Index(num_cols)};
}
la_runtime_assert(num_cols != 0 && attribute.get_num_elements() % num_cols == 0);
la_runtime_assert(num_cols != 0 && attribute.get_all().size() % num_cols == 0);
return {
attribute.get_all().data(),
Eigen::Index(attribute.get_num_elements() / num_cols),
Eigen::Index(attribute.get_all().size() / num_cols),
Eigen::Index(num_cols)};
}

Expand Down
18 changes: 9 additions & 9 deletions modules/core/tests/test_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,56 +1072,56 @@ void test_ownership()

} // namespace

TEST_CASE("IndexedAttribute: Move-Copy", "[next]")
TEST_CASE("IndexedAttribute: Move-Copy", "[attribute]")
{
#define LA_X_move_copy_indexed_values(I, S) test_move_copy_indexed<S, I>();
#define LA_X_move_copy_indexed_indices(_, I) LA_ATTRIBUTE_X(move_copy_indexed_values, I)
LA_SURFACE_MESH_INDEX_X(move_copy_indexed_indices, 0)
}

TEST_CASE("Attribute: Create", "[next]")
TEST_CASE("Attribute: Create", "[attribute]")
{
#define LA_X_create_attribute(_, ValueType) test_create_attribute<ValueType>();
LA_ATTRIBUTE_X(create_attribute, 0)
}

TEST_CASE("Attribute: Move-Copy Internal", "[next]")
TEST_CASE("Attribute: Move-Copy Internal", "[attribute]")
{
#define LA_X_move_copy_internal(_, ValueType) test_move_copy_internal<ValueType>();
LA_ATTRIBUTE_X(move_copy_internal, 0)
}

TEST_CASE("Attribute: Move-Copy External", "[next]")
TEST_CASE("Attribute: Move-Copy External", "[attribute]")
{
#define LA_X_move_copy_external(_, ValueType) test_move_copy_external<ValueType>();
LA_ATTRIBUTE_X(move_copy_external, 0)
}

TEST_CASE("Attribute: Data Access", "[next]")
TEST_CASE("Attribute: Data Access", "[attribute]")
{
#define LA_X_data_access(_, ValueType) test_data_access<ValueType>();
LA_ATTRIBUTE_X(data_access, 0)
}

TEST_CASE("Attribute: Write Policy", "[next]")
TEST_CASE("Attribute: Write Policy", "[attribute]")
{
#define LA_X_write_policy(_, ValueType) test_write_policy<ValueType>();
LA_ATTRIBUTE_X(write_policy, 0)
}

TEST_CASE("Attribute: Growth Policy", "[next]")
TEST_CASE("Attribute: Growth Policy", "[attribute]")
{
#define LA_X_growth_policy(_, ValueType) test_growth_policy<ValueType>();
LA_ATTRIBUTE_X(growth_policy, 0)
}

TEST_CASE("Attribute: Empty Buffers", "[next]")
TEST_CASE("Attribute: Empty Buffers", "[attribute]")
{
#define LA_X_empty_buffers(_, ValueType) test_empty_buffers<ValueType>();
LA_ATTRIBUTE_X(empty_buffers, 0)
}

TEST_CASE("Attribute: ownership", "[next]")
TEST_CASE("Attribute: ownership", "[attribute]")
{
#define LA_X_ownership(_, ValueType) test_ownership<ValueType>();
LA_ATTRIBUTE_X(ownership, 0)
Expand Down
Loading

0 comments on commit 5bdff7d

Please sign in to comment.