Skip to content

Commit

Permalink
Merge pull request #694 from wildmeshing/mtao/remove_mesh_from_isotropic
Browse files Browse the repository at this point in the history
removing the mesh from isotropic and depending on the pos handle instead
mtao authored Jan 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents b650f9e + df3adc9 commit 9479255
Showing 5 changed files with 24 additions and 28 deletions.
6 changes: 0 additions & 6 deletions components/tests/test_component_isotropic_remeshing.cpp
Original file line number Diff line number Diff line change
@@ -698,7 +698,6 @@ TEST_CASE("remeshing_tetrahedron", "[components][isotropic_remeshing][2D]")


CHECK_NOTHROW(wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.1,
@@ -732,7 +731,6 @@ TEST_CASE("remeshing_with_boundary", "[components][isotropic_remeshing][2D]")
SECTION("lock_boundary_false")
{
wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.5,
@@ -763,7 +761,6 @@ TEST_CASE("remeshing_with_boundary", "[components][isotropic_remeshing][2D]")
SECTION("lock_boundary_true")
{
wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.5,
@@ -828,7 +825,6 @@ TEST_CASE("remeshing_preserve_topology", "[components][isotropic_remeshing][2D][


wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.5,
@@ -903,7 +899,6 @@ TEST_CASE("remeshing_preserve_topology_realmesh", "[components][isotropic_remesh

for (int i = 0; i < 25; i++) {
wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.05,
@@ -995,7 +990,6 @@ TEST_CASE("remeshing_realmesh", "[components][isotropic_remeshing][2D][.]")
// const auto& child_mesh = *child_ptr;

wmtk::components::internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
0.5,
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
namespace wmtk::components::internal {

void isotropic_remeshing(
TriMesh& mesh,
attribute::MeshAttributeHandle& position,
std::vector<attribute::MeshAttributeHandle>& pass_through_attributes,
const double length,
@@ -29,6 +28,10 @@ void isotropic_remeshing(
const std::vector<attribute::MeshAttributeHandle>& other_positions,
const std::optional<attribute::MeshAttributeHandle>& position_for_inversion)
{
assert(dynamic_cast<TriMesh*>(&position.mesh()) != nullptr);

TriMesh& mesh = static_cast<TriMesh&>(position.mesh());

const double length_min = (4. / 5.) * length;
const double length_max = (4. / 3.) * length;

Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
namespace wmtk::components::internal {

void isotropic_remeshing(
TriMesh& mesh,
attribute::MeshAttributeHandle& position,
std::vector<attribute::MeshAttributeHandle>& pass_through_attributes,
const double length,
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace wmtk::components::internal {

struct IsotropicRemeshingAttributes
{
std::string position;
nlohmann::json position;
nlohmann::json inversion_position;
nlohmann::json other_positions;
};
@@ -40,4 +40,4 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
iterations,
lock_boundary);

} // namespace wmtk::components::internal
} // namespace wmtk::components::internal
Original file line number Diff line number Diff line change
@@ -10,12 +10,11 @@
namespace wmtk::components {
// compute the length relative to the bounding box diagonal
double relative_to_absolute_length(
const TriMesh& mesh,
const attribute::MeshAttributeHandle& pos_handle,
const double length_rel)
{
auto pos = mesh.create_const_accessor(pos_handle.as<double>());
const auto vertices = mesh.get_all(PrimitiveType::Vertex);
auto pos = pos_handle.mesh().create_const_accessor<double>(pos_handle);
const auto vertices = pos_handle.mesh().get_all(PrimitiveType::Vertex);

Eigen::VectorXd p_min, p_max;
p_min = p_max = pos.const_vector_attribute(vertices.front());
@@ -43,26 +42,27 @@ void isotropic_remeshing(const base::Paths& paths, const nlohmann::json& j, io::

IsotropicRemeshingOptions options = j.get<IsotropicRemeshingOptions>();

// input
std::shared_ptr<Mesh> mesh_in = cache.read_mesh(options.input);


if (mesh_in->top_simplex_type() != PrimitiveType::Face) {
log_and_throw_error("Info works only for triangle meshes: {}", mesh_in->top_simplex_type());
}

TriMesh& mesh = static_cast<TriMesh&>(*mesh_in);

auto pos_handle =
mesh.get_attribute_handle<double>(options.attributes.position, PrimitiveType::Vertex);
auto pos_handles = base::get_attributes(cache, *mesh_in, options.attributes.position);
assert(pos_handles.size() == 1);
auto pos_handle = pos_handles.front();

auto pass_through_attributes = base::get_attributes(cache, mesh, options.pass_through);
auto other_positions = base::get_attributes(cache, mesh, options.attributes.other_positions);
auto pass_through_attributes = base::get_attributes(cache, *mesh_in, options.pass_through);
auto other_positions =
base::get_attributes(cache, *mesh_in, options.attributes.other_positions);

if (options.length_abs < 0) {
if (options.length_rel < 0) {
throw std::runtime_error("Either absolute or relative length must be set!");
}
options.length_abs = relative_to_absolute_length(mesh, pos_handle, options.length_rel);
options.length_abs = relative_to_absolute_length(pos_handle, options.length_rel);
}

// clear attributes
@@ -71,26 +71,26 @@ void isotropic_remeshing(const base::Paths& paths, const nlohmann::json& j, io::
keeps.insert(keeps.end(), other_positions.begin(), other_positions.end());

// TODO: brig me back!
// mesh.clear_attributes(keeps);
mesh_in->clear_attributes(keeps);

// gather handles again as they were invalidated by clear_attributes
pos_handle =
mesh.get_attribute_handle<double>(options.attributes.position, PrimitiveType::Vertex);
pass_through_attributes = base::get_attributes(cache, mesh, options.pass_through);
pos_handles = base::get_attributes(cache, *mesh_in, options.attributes.position);
assert(pos_handles.size() == 1);
pos_handle = pos_handles.front();
pass_through_attributes = base::get_attributes(cache, *mesh_in, options.pass_through);

std::optional<attribute::MeshAttributeHandle> position_for_inversion;

if (!options.attributes.inversion_position.empty()) {
auto tmp = base::get_attributes(cache, mesh, options.attributes.inversion_position);
auto tmp = base::get_attributes(cache, *mesh_in, options.attributes.inversion_position);
assert(tmp.size() == 1);
position_for_inversion = tmp.front();
}

other_positions = base::get_attributes(cache, mesh, options.attributes.other_positions);
other_positions = base::get_attributes(cache, *mesh_in, options.attributes.other_positions);


internal::isotropic_remeshing(
mesh,
pos_handle,
pass_through_attributes,
options.length_abs,
@@ -100,6 +100,6 @@ void isotropic_remeshing(const base::Paths& paths, const nlohmann::json& j, io::
position_for_inversion);

// output
cache.write_mesh(mesh, options.output);
cache.write_mesh(*mesh_in, options.output);
}
} // namespace wmtk::components

0 comments on commit 9479255

Please sign in to comment.