Skip to content

Commit

Permalink
Merge branch 'main' into zhouyuan/regular_space
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhouyuan-Chen committed Oct 17, 2023
2 parents 4561fce + d13e71b commit fe3882f
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ std::tuple<Eigen::MatrixXd, Eigen::MatrixXi> delaunay_geogram(
}

long dim = points.cols();
assert(dim == 2 || dim == 3);

static std::once_flag once_flag;
std::call_once(once_flag, []() { GEO::initialize(); });
Expand Down Expand Up @@ -67,12 +66,12 @@ std::tuple<Eigen::MatrixXd, Eigen::MatrixXi> delaunay_geogram(
vertices.row(i) = Eigen::Map<const Eigen::Vector3d>(engine->vertex_ptr(i)).transpose();
break;
}
default: {
// for generality allowing for arbitrary dimensions
vertices.row(i) =
Eigen::Map<const Eigen::VectorXd>(engine->vertex_ptr(i), dim).transpose();
break;
}
// default: {
// // for generality allowing for arbitrary dimensions
// vertices.row(i) =
// Eigen::Map<const Eigen::VectorXd>(engine->vertex_ptr(i), dim).transpose();
// break;
//}
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/wmtk/TriMeshOperationExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ TriMesh::TriMeshOperationExecutor::TriMeshOperationExecutor(
m_incident_face_datas.emplace_back(get_incident_face_data(f.tuple()));
}

assert(m_incident_face_datas.size() <= 2);
if (m_incident_face_datas[0].fid != m.id_face(m_operating_tuple)) {
assert(m_incident_face_datas.size() == 2);
std::swap(m_incident_face_datas[0], m_incident_face_datas[1]);
}

// update hash on all faces in the two-ring neighborhood
SimplicialComplex hash_update_region(m);
for (const Simplex& v : edge_closed_star.get_vertices()) {
Expand Down Expand Up @@ -426,11 +432,13 @@ void TriMesh::TriMeshOperationExecutor::split_edge_single_mesh()
Tuple& ret = m_output_tuple = m_mesh.edge_tuple_from_id(new_eids[1]);
if (m_mesh.id_vertex(ret) != v_new) {
ret = m_mesh.switch_vertex(ret);
assert(m_mesh.id_vertex(ret) == v_new);
}
if (m_mesh.id_face(ret) != new_tuple_fid) {
ret = m_mesh.switch_face(ret);
assert(m_mesh.id_face(ret) == new_tuple_fid);
}
assert(m_mesh.is_valid_slow(ret));
assert(m_mesh.is_valid(ret, hash_accessor));
}

void TriMesh::TriMeshOperationExecutor::update_hash_in_map(TriMesh& child_mesh)
Expand Down Expand Up @@ -525,7 +533,7 @@ void TriMesh::TriMeshOperationExecutor::collapse_edge_single_mesh()
ret = m_mesh.switch_face(ret);
}
assert(m_mesh.id_face(ret) == new_tuple_fid);
assert(m_mesh.is_valid_slow(ret));
assert(m_mesh.is_valid(ret, hash_accessor));


// return a ccw tuple from left ear if it exists, otherwise return a ccw tuple from right ear
Expand Down
3 changes: 3 additions & 0 deletions src/wmtk/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ set(SRC_FILES
TupleInspector.hpp
)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})


add_subdirectory(metaprogramming)
12 changes: 12 additions & 0 deletions src/wmtk/utils/metaprogramming/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(SRC_FILES
DerivedReferenceWrapperVariantTraits.hpp
ReferenceWrappedFunctorReturnCache.hpp
ReferenceWrappedFunctorReturnType.hpp
ReferenceWrapperVariant.hpp
as_variant.hpp
unwrap_ref.hpp
)

target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})

add_subdirectory(tuple)
7 changes: 7 additions & 0 deletions src/wmtk/utils/metaprogramming/tuple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(SRC_FILES
concatenate_types.hpp
get_unique_remove_void_types.hpp
get_unique_types.hpp
remove_void_types.hpp
)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
27 changes: 27 additions & 0 deletions src/wmtk/utils/metaprogramming/tuple/concatenate_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <tuple>

namespace wmtk::utils::metaprogramming::tuple {


// creates a tuple that concatenates the types passed in


// generic case so we can specialize with tuples passed in
template <typename T, typename U>
struct concatenate_types
{
};

// main case where we pass in two tuples
template <typename... Ts, typename... Us>
struct concatenate_types<std::tuple<Ts...>, std::tuple<Us...>>
{
using type = std::tuple<Ts..., Us...>;
};


// alias to underlying type
template <typename T, typename U>
using concatenate_types_t = typename concatenate_types<T, U>::type;
} // namespace wmtk::utils::metaprogramming::tuple
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <tuple>
#include <type_traits>
#include "get_unique_types.hpp"
#include "remove_void_types.hpp"


namespace wmtk::utils::metaprogramming::tuple {


// given a set of types, a tuple without the voids and makes unique types
template <typename... Ts>
using get_unique_remove_void_types_t = // get_unique_t<Ts...>;
typename detail::remove_void_tuple<void, get_unique_types_t<Ts...>>::type;
}

74 changes: 74 additions & 0 deletions src/wmtk/utils/metaprogramming/tuple/get_unique_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once
#include <tuple>
#include <type_traits>
#include "concatenate_types.hpp"

namespace wmtk::utils::metaprogramming::tuple {


// given a tuple, extracts a tuple with only unique types in the input

// strategy is to recursively extract the last copy of any given type


// alternates between get_unique_types<tuple<Ts...> with
// main_unique_tuple_types<T,std::tuple<Ts...>> to combine Ts... and T,Ts... as necessary

namespace detail {


// basic initializations - by default return empty in case the input is empty (which is not caught
// by later cases)
template <typename...>
struct get_unique_types
{
using type = std::tuple<>;
};
// basic initialization, expects a T and a Tuple
template <typename T, typename RemainingTuple>
struct get_unique_types_tuple
{
};
// convenience to avoid typename for get_unique_types...
template <typename... Ts>
using get_unique_types_t = typename get_unique_types<Ts...>::type;


// actual base case - single type is unique so we return that type
template <typename T>
struct get_unique_types<T>
{
using type = std::tuple<T>;
};


// from a list of types, check if the first is unique compared to the rest
template <typename T, typename... Ts>
struct get_unique_types<T, Ts...>
{
using type = typename get_unique_types_tuple<T, std::tuple<Ts...>>::type;
};


// do the meat of the implementation - check if T is unique in T,Ts...
// if so then add it to the unique of the rest
template <typename T, typename... Ts>
struct get_unique_types_tuple<T, std::tuple<Ts...>>
{
// is t unique among T,Ts...
constexpr static bool t_is_unique = (!std::is_same_v<T, Ts> && ...);
// if its unique then create {T} otherwise {}
using adding_t_type = std::conditional_t<t_is_unique, std::tuple<T>, std::tuple<>>;

// concatenate adding_t_type \cup unique(Ts...)
using type = concatenate_types_t<adding_t_type, get_unique_types_t<Ts...>>;
};


} // namespace detail

// main access point
template <typename... Ts>
using get_unique_types_t = detail::get_unique_types_t<Ts...>;

} // namespace wmtk::utils::metaprogramming::tuple
49 changes: 49 additions & 0 deletions src/wmtk/utils/metaprogramming/tuple/remove_void_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include <tuple>
#include "concatenate_types.hpp"


namespace wmtk::utils::metaprogramming::tuple {
namespace detail {
template <typename...>
struct remove_void
{
using type = std::tuple<>;
};
template <>
struct remove_void<void>
{
using type = std::tuple<>;
};
template <typename T>
struct remove_void<T>
{
using type = std::tuple<T>;
};

template <typename... Ts>
using remove_void_t = typename remove_void<Ts...>::type;

template <typename T, typename RemainingTuple>
struct remove_void_tuple
{
};
template <typename T, typename... Ts>
struct remove_void_tuple<T, std::tuple<Ts...>>
{
constexpr static bool t_not_void = !std::is_same_v<T, void>;
using adding_t_type = std::conditional_t<t_not_void, std::tuple<T>, std::tuple<>>;

using type = concatenate_types_t<adding_t_type, remove_void_t<Ts...>>;
};

template <typename T, typename... Ts>
struct remove_void<T, Ts...>
{
using type = typename remove_void_tuple<T, std::tuple<Ts...>>::type;
};
} // namespace detail

template <typename... Ts>
using remove_void_types_t = detail::remove_void_t<Ts...>;
} // namespace wmtk::utils::metaprogramming::tuple
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(TEST_SOURCES
test_3d_operations.cpp
test_multi_mesh.cpp
test_variant_metaprogramming.cpp
test_tuple_metaprogramming.cpp


tools/DEBUG_PointMesh.hpp
Expand Down
Loading

0 comments on commit fe3882f

Please sign in to comment.