-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from wildmeshing/dzint/401-edgeswap-does-not-…
…use-invariants Add edge swap invariants
- Loading branch information
Showing
16 changed files
with
449 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "MinIncidentValenceInvariant.hpp" | ||
|
||
#include <wmtk/Mesh.hpp> | ||
#include <wmtk/simplex/link.hpp> | ||
|
||
namespace wmtk::invariants { | ||
|
||
|
||
MinIncidentValenceInvariant::MinIncidentValenceInvariant(const Mesh& m, long min_valence) | ||
: MeshInvariant(m) | ||
, m_min_valence(min_valence) | ||
{} | ||
|
||
bool MinIncidentValenceInvariant::before(const Tuple& t) const | ||
{ | ||
return is_greater_min_valence(t); | ||
} | ||
|
||
bool MinIncidentValenceInvariant::after(PrimitiveType type, const std::vector<Tuple>& t) const | ||
{ | ||
if (type == PrimitiveType::Edge) { | ||
for (const Tuple& e : t) { | ||
if (!is_greater_min_valence(e)) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool MinIncidentValenceInvariant::is_greater_min_valence(const Tuple& t) const | ||
{ | ||
using namespace simplex; | ||
|
||
const Simplex v0 = Simplex::vertex(t); | ||
const Simplex v1 = Simplex::vertex(mesh().switch_vertex(t)); | ||
const long val0 = | ||
static_cast<long>(link(mesh(), v0).simplex_vector(PrimitiveType::Vertex).size()); | ||
const long val1 = | ||
static_cast<long>(link(mesh(), v1).simplex_vector(PrimitiveType::Vertex).size()); | ||
|
||
return val0 >= m_min_valence && val1 >= m_min_valence; | ||
} | ||
|
||
} // namespace wmtk::invariants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <wmtk/attribute/AttributeHandle.hpp> | ||
#include "MeshInvariant.hpp" | ||
|
||
namespace wmtk::invariants { | ||
/** | ||
* Invariant for minimum valence on both incident vertices of an edge. | ||
*/ | ||
class MinIncidentValenceInvariant : public MeshInvariant | ||
{ | ||
public: | ||
MinIncidentValenceInvariant(const Mesh& m, long min_valence); | ||
using MeshInvariant::MeshInvariant; | ||
bool before(const Tuple& t) const override; | ||
bool after(PrimitiveType type, const std::vector<Tuple>& t) const override; | ||
|
||
private: | ||
bool is_greater_min_valence(const Tuple& t) const; | ||
|
||
long m_min_valence; | ||
}; | ||
} // namespace wmtk::invariants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "EdgeSwapBase.hpp" | ||
#include <wmtk/SimplicialComplex.hpp> | ||
#include <wmtk/TriMesh.hpp> | ||
#include <wmtk/invariants/InteriorEdgeInvariant.hpp> | ||
|
||
#include "EdgeCollapse.hpp" | ||
#include "EdgeSplit.hpp" | ||
|
||
namespace wmtk::operations { | ||
void OperationSettings<tri_mesh::EdgeSwapBase>::initialize_invariants(const TriMesh& m) | ||
{ | ||
// outdated + is valid tuple | ||
invariants = basic_invariant_collection(m); | ||
invariants.add(std::make_shared<InteriorEdgeInvariant>(m)); | ||
|
||
collapse_settings.initialize_invariants(m); | ||
split_settings.initialize_invariants(m); | ||
} | ||
|
||
|
||
namespace tri_mesh { | ||
EdgeSwapBase::EdgeSwapBase(Mesh& m, const Tuple& t, const OperationSettings<EdgeSwapBase>& settings) | ||
: TriMeshOperation(m) | ||
, TupleOperation(settings.invariants, t) | ||
, m_settings{settings} | ||
{} | ||
|
||
std::string EdgeSwapBase::name() const | ||
{ | ||
return "tri_mesh_edge_swap_base"; | ||
} | ||
|
||
Tuple EdgeSwapBase::return_tuple() const | ||
{ | ||
return m_output_tuple; | ||
} | ||
|
||
bool EdgeSwapBase::execute() | ||
{ | ||
// input | ||
// / \ | ||
// / \ | ||
// / f \ | ||
// X--->--- | ||
// \ / | ||
// \ / | ||
// \ / | ||
|
||
Tuple split_ret; | ||
{ | ||
tri_mesh::EdgeSplit split_op(mesh(), input_tuple(), m_settings.split_settings); | ||
if (!split_op()) { | ||
return false; | ||
} | ||
split_ret = split_op.return_tuple(); | ||
} | ||
// after split | ||
// /|\ | ||
// / | \ | ||
// / | f\ | ||
// ---X--> | ||
// \ | / | ||
// \ | / | ||
// \|/ | ||
|
||
// switch also face to keep edge orientation | ||
const Tuple coll_input_tuple = mesh().switch_face(mesh().switch_edge(split_ret)); | ||
// switch edge - switch face | ||
// /|\ | ||
// / ^ \ | ||
// /f | \ | ||
// ---X--- | ||
// \ | / | ||
// \ | / | ||
// \|/ | ||
Tuple coll_ret; | ||
{ | ||
tri_mesh::EdgeCollapse coll_op(mesh(), coll_input_tuple, m_settings.collapse_settings); | ||
if (!coll_op()) { | ||
return false; | ||
} | ||
coll_ret = coll_op.return_tuple(); | ||
} | ||
// collapse output | ||
// X | ||
// /|\ | ||
// < | \ | ||
// / | \ | ||
// | f | | | ||
// \ | / | ||
// \ | / | ||
// \|/ | ||
// adjust return tuple to be the swapped edge in the same orientation as the input | ||
m_output_tuple = mesh().switch_vertex(mesh().switch_edge(coll_ret)); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace tri_mesh | ||
} // namespace wmtk::operations |
Oops, something went wrong.