Skip to content

Commit

Permalink
Merge pull request #777 from wildmeshing/dzint/is_valid_simplex
Browse files Browse the repository at this point in the history
Dzint/is valid simplex
  • Loading branch information
mtao authored Jun 20, 2024
2 parents 461c480 + c23bdb4 commit f8300ee
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
2 changes: 1 addition & 1 deletion components/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(wmtk_data)

set(WMTK_COMPONENT_TEST_TARGET ${WMTK_COMPONENT_PREFIX}_tests)

file(GLOB WMTK_TEST_SOURCES test_*.cpp)
file(GLOB WMTKC_TEST_SOURCES test_*.cpp)
add_executable(${WMTK_COMPONENT_TEST_TARGET} ${WMTKC_TEST_SOURCES})
target_sources(${WMTK_COMPONENT_TEST_TARGET} PRIVATE integration_test.cpp)

Expand Down
16 changes: 16 additions & 0 deletions components/tests/test_component_isotropic_remeshing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ TEST_CASE("collapse_short_edges", "[components][isotropic_remeshing][collapse][2

// CHECK_THROWS(mesh.tuple_from_id(PrimitiveType::Vertex, 4));
const Tuple v5 = mesh.tuple_from_id(PrimitiveType::Vertex, 5);
#if defined(WMTK_ENABLE_HASH_UPDATE)
REQUIRE(mesh.is_valid_with_hash(v5));
#else
REQUIRE(mesh.is_valid(v5));
#endif

auto pos = mesh.create_accessor<double>(pos_attribute);
Eigen::Vector3d p5 = pos.vector_attribute(v5);
Expand Down Expand Up @@ -449,7 +453,11 @@ TEST_CASE("collapse_short_edges", "[components][isotropic_remeshing][collapse][2
REQUIRE(n_vertices == 9);

const Tuple v0 = mesh.tuple_from_id(PrimitiveType::Vertex, 0);
#if defined(WMTK_ENABLE_HASH_UPDATE)
REQUIRE(mesh.is_valid_with_hash(v0));
#else
REQUIRE(mesh.is_valid(v0));
#endif

auto pos = mesh.create_accessor<double>(pos_attribute);
Eigen::Vector3d p0 = pos.vector_attribute(v0);
Expand Down Expand Up @@ -488,7 +496,11 @@ TEST_CASE("collapse_short_edges", "[components][isotropic_remeshing][collapse][2
REQUIRE(n_vertices == 9);

const Tuple v0 = mesh.tuple_from_id(PrimitiveType::Vertex, 0);
#if defined(WMTK_ENABLE_HASH_UPDATE)
REQUIRE(mesh.is_valid_with_hash(v0));
#else
REQUIRE(mesh.is_valid(v0));
#endif

auto pos = mesh.create_accessor<double>(pos_attribute);
Eigen::Vector3d p0 = pos.vector_attribute(v0);
Expand All @@ -513,7 +525,11 @@ TEST_CASE("collapse_short_edges", "[components][isotropic_remeshing][collapse][2
REQUIRE(mesh.get_all(PrimitiveType::Vertex).size() == 9);

const Tuple v0 = mesh.tuple_from_id(PrimitiveType::Vertex, 0);
#if defined(WMTK_ENABLE_HASH_UPDATE)
REQUIRE(mesh.is_valid_with_hash(v0));
#else
REQUIRE(mesh.is_valid(v0));
#endif

auto pos = mesh.create_accessor<double>(pos_attribute);
Eigen::Vector3d p0 = pos.vector_attribute(v0);
Expand Down
44 changes: 23 additions & 21 deletions src/wmtk/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool Mesh::is_boundary(const simplex::Simplex& s) const
}


#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
bool Mesh::is_hash_valid(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor)
const
{
Expand All @@ -75,8 +75,7 @@ bool Mesh::is_hash_valid(const Tuple& tuple, const attribute::Accessor<int64_t>&
return true;
}

bool Mesh::is_hash_valid(const Tuple& tuple)
const
bool Mesh::is_hash_valid(const Tuple& tuple) const
{
auto ha = get_const_cell_hash_accessor();
return is_hash_valid(tuple, ha);
Expand All @@ -86,20 +85,21 @@ bool Mesh::is_hash_valid(const Tuple& tuple)
bool Mesh::is_valid_with_hash(const Tuple& tuple) const
{
auto ha = get_const_cell_hash_accessor();
return is_valid_with_hash(tuple,ha);
return is_valid_with_hash(tuple, ha);
}
bool Mesh::is_valid_with_hash(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor) const
bool Mesh::is_valid_with_hash(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor)
const
{
if(!is_valid(tuple)) {
if (!is_valid(tuple)) {
return false;
}
if(!is_hash_valid(tuple, hash_accessor)) {
if (!is_hash_valid(tuple, hash_accessor)) {
return false;
}
//#else
// const auto& flag_accessor = get_const_flag_accessor(top_simplex_type());
// return flag_accessor.index_access().const_scalar_attribute(tuple.m_global_cid) & 0x1;
//#endif
// #else
// const auto& flag_accessor = get_const_flag_accessor(top_simplex_type());
// return flag_accessor.index_access().const_scalar_attribute(tuple.m_global_cid) & 0x1;
// #endif
return true;
}
#endif
Expand All @@ -115,6 +115,12 @@ bool Mesh::is_removed(const Tuple& tuple) const
return !(flag_accessor.index_access().const_scalar_attribute(tuple.m_global_cid) & 0x1);
}

bool Mesh::is_valid(const simplex::Simplex& s) const
{
const int64_t id_tuple = id(s.tuple(), s.primitive_type());
return id_tuple == s.m_index;
}


const attribute::Accessor<char> Mesh::get_flag_accessor(PrimitiveType type) const
{
Expand All @@ -129,7 +135,7 @@ attribute::Accessor<char> Mesh::get_flag_accessor(PrimitiveType type)
return create_accessor(m_flag_handles.at(get_primitive_type_id(type)));
}

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
const attribute::Accessor<int64_t> Mesh::get_const_cell_hash_accessor() const
{
return create_const_accessor(m_cell_hash_handle);
Expand All @@ -151,7 +157,6 @@ void Mesh::update_cell_hash(const Tuple& cell, attribute::Accessor<int64_t>& has
}
void Mesh::update_cell_hash(const int64_t cid, attribute::Accessor<int64_t>& hash_accessor)
{

auto& h = hash_accessor.index_access().scalar_attribute(cid);
h = (h + 1) % (1 << 6);
}
Expand All @@ -160,7 +165,6 @@ void Mesh::update_cell_hashes(
const std::vector<Tuple>& cells,
attribute::Accessor<int64_t>& hash_accessor)
{

for (const Tuple& t : cells) {
update_cell_hash(t, hash_accessor);
}
Expand All @@ -169,26 +173,24 @@ void Mesh::update_cell_hashes(
const std::vector<int64_t>& cells,
attribute::Accessor<int64_t>& hash_accessor)
{

for (const int64_t t : cells) {
update_cell_hash(t, hash_accessor);
}
}

void Mesh::update_cell_hashes_slow(const std::vector<Tuple>& cells)
{

attribute::Accessor<int64_t> hash_accessor = get_cell_hash_accessor();
update_cell_hashes(cells, hash_accessor);
}
#endif


#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
Tuple Mesh::resurrect_tuple(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor)
const
{
#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)

Tuple t = tuple;
t.m_hash = get_cell_hash(tuple.m_global_cid, hash_accessor);
Expand All @@ -200,7 +202,7 @@ Tuple Mesh::resurrect_tuple(const Tuple& tuple, const attribute::Accessor<int64_

Tuple Mesh::resurrect_tuple_slow(const Tuple& tuple) const
{
#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
attribute::Accessor<int64_t> hash_accessor = get_cell_hash_accessor();
return resurrect_tuple(tuple, hash_accessor);
#else
Expand All @@ -209,7 +211,7 @@ Tuple Mesh::resurrect_tuple_slow(const Tuple& tuple) const
}
#endif

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
int64_t Mesh::get_cell_hash(int64_t cell_index, const attribute::Accessor<int64_t>& hash_accessor)
const
{
Expand Down Expand Up @@ -268,7 +270,7 @@ Tuple Mesh::switch_tuples_unsafe(
}


#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
void Mesh::update_vertex_operation_hashes(
const Tuple& vertex,
attribute::Accessor<int64_t>& hash_accessor)
Expand Down
16 changes: 11 additions & 5 deletions src/wmtk/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk
friend class operations::EdgeSplit;
friend class operations::EdgeOperationData;

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
friend void operations::utils::update_vertex_operation_multimesh_map_hash(
Mesh& m,
const simplex::SimplexCollection& vertex_closed_star,
Expand Down Expand Up @@ -274,7 +274,7 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk

const attribute::Accessor<char> get_flag_accessor(PrimitiveType type) const;
const attribute::Accessor<char> get_const_flag_accessor(PrimitiveType type) const;
#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
const attribute::Accessor<int64_t> get_cell_hash_accessor() const;
const attribute::Accessor<int64_t> get_const_cell_hash_accessor() const;

Expand All @@ -295,7 +295,7 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk

protected: // member functions
attribute::Accessor<char> get_flag_accessor(PrimitiveType type);
#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
attribute::Accessor<int64_t> get_cell_hash_accessor();

/**
Expand Down Expand Up @@ -491,13 +491,19 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk
* @return false
*/
virtual bool is_valid(const Tuple& tuple) const;
#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
bool is_valid_with_hash(const Tuple& tuple) const;
bool is_valid_with_hash(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor) const;
bool is_valid_with_hash(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor)
const;
#endif

bool is_removed(const Tuple& tuple) const;

/**
* @brief Check if the cached id in a simplex is up-to-date.
*/
bool is_valid(const simplex::Simplex& s) const;


//============================
// MultiMesh interface
Expand Down
9 changes: 6 additions & 3 deletions src/wmtk/operations/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::vector<simplex::Simplex> Operation::operator()(const simplex::Simplex& simp
return {};
}

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
const auto simplex_resurrect =
simplex::Simplex(mesh(), simplex.primitive_type(), resurrect_tuple(simplex.tuple()));
#else
Expand Down Expand Up @@ -95,11 +95,14 @@ bool Operation::before(const simplex::Simplex& simplex) const
// return false;
// }

if (!mesh().is_valid(simplex)) {
return false;
}
if (mesh().is_removed(simplex.tuple())) {
return false;
}

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
const auto simplex_resurrect =
simplex::Simplex(mesh(), simplex.primitive_type(), resurrect_tuple(simplex.tuple()));
#else
Expand Down Expand Up @@ -169,7 +172,7 @@ void Operation::apply_attribute_transfer(const std::vector<simplex::Simplex>& di
}
}

#if defined(WMTK_ENABLE_HASH_UPDATE)
#if defined(WMTK_ENABLE_HASH_UPDATE)
Tuple Operation::resurrect_tuple(const Tuple& tuple) const
{
return mesh().resurrect_tuple(tuple, hash_accessor());
Expand Down

0 comments on commit f8300ee

Please sign in to comment.