9#include <kernel/geometry/target_set.hpp>
10#include <kernel/geometry/index_set.hpp>
11#include <kernel/geometry/mesh_part.hpp>
12#include <kernel/geometry/atlas/chart.hpp>
13#include <kernel/util/tiny_algebra.hpp>
22 template<
typename VertexSet_,
typename IndexTuple_>
23 inline Tiny::Vector<typename VertexSet_::CoordType, VertexSet_::num_coords>
24 get_midpoint(
const VertexSet_& vertex_set,
const IndexTuple_& index_tuple)
26 using DataType =
typename VertexSet_::CoordType;
27 constexpr int num_vertex = IndexTuple_::num_indices;
29 Tiny::Vector<DataType, VertexSet_::num_coords> mid_point(DataType(0));
30 for(
int i(0); i < num_vertex; ++i)
32 for(
int j(0); j < VertexSet_::num_coords; ++j)
34 mid_point[j] += vertex_set[index_tuple[i]][j];
37 return mid_point * (DataType(1) / DataType(num_vertex));
40 template<
typename VertexSet_>
41 static Tiny::Vector<typename VertexSet_::CoordType, VertexSet_::num_coords>
42 get_midpoint(
const VertexSet_& vertex_set,
const Index vertex)
44 using DataType =
typename VertexSet_::CoordType;
46 Tiny::Vector<DataType, VertexSet_::num_coords> mid_point;
47 for(
int j(0); j < VertexSet_::num_coords; ++j)
49 mid_point[j] = vertex_set[vertex][j];
54 template<
typename HitFunc_,
typename Mesh_,
int dim_ = Mesh_::shape_dim>
55 inline void hittest_compute_target_data(
56 std::vector<std::vector<Index>>& target_data,
58 const HitFunc_& hit_test)
60 if constexpr (dim_ == 0)
62 const Index num_cells(mesh.get_num_entities(0));
64 target_data[0].reserve(num_cells);
65 for(
Index i(0); i < num_cells; ++i)
67 if (hit_test(get_midpoint(mesh.get_vertex_set(), i)))
69 target_data[0].push_back(i);
76 hittest_compute_target_data<HitFunc_, Mesh_, dim_ - 1>(target_data, mesh, hit_test);
78 const Index num_cells(mesh.get_num_entities(dim_));
79 const auto& index_set(mesh.template get_index_set<dim_,0>());
81 target_data[dim_].reserve(num_cells);
82 for(
Index i(0); i < num_cells; ++i)
84 if (hit_test(get_midpoint(mesh.get_vertex_set(), index_set[i])))
86 target_data[dim_].push_back(i);
92 template<
typename HitFunc_,
typename Mesh_,
int dim_ = Mesh_::shape_dim>
93 inline void hittest_compute_filtered_target_data(
94 std::vector<std::vector<Index>>& target_data,
96 const MeshPart<Mesh_>& part,
97 const HitFunc_& hit_test)
99 if constexpr (dim_ == 0)
101 const Index num_cells(part.get_num_entities(0));
102 const TargetSet& vertex_target_set = part.template get_target_set<0>();
104 target_data[0].reserve(num_cells);
105 for(
Index i(0); i < num_cells; ++i)
107 const Index vertex = vertex_target_set[i];
108 if (hit_test(get_midpoint(mesh.get_vertex_set(), vertex)))
110 target_data[0].push_back(vertex);
117 hittest_compute_filtered_target_data<HitFunc_, Mesh_, dim_ - 1>(target_data, mesh, part, hit_test);
119 const Index num_cells(part.get_num_entities(dim_));
120 const TargetSet& filter_target_set = part.template get_target_set<dim_>();
121 const auto& index_set(mesh.template get_index_set<dim_,0>());
123 target_data[dim_].reserve(num_cells);
124 for(
Index i(0); i < num_cells; ++i)
126 const Index entity = filter_target_set[i];
127 if (hit_test(get_midpoint(mesh.get_vertex_set(), index_set[entity])))
129 target_data[dim_].push_back(entity);
135 template<
typename Shape_,
int dim_ = Shape_::dimension>
136 inline void write_to_target_set(TargetSetHolder<Shape_>& tsh, std::vector<std::vector<Index>>& source)
138 if constexpr (dim_ < 0)
145 write_to_target_set<Shape_, dim_ - 1>(tsh, source);
147 const auto num_cells(
Index(source[dim_].size()));
148 TargetSet& trg = tsh.template get_target_set<dim_>();
149 for(
Index i(0); i < num_cells; ++i)
151 trg[i] = source[dim_][i];
179 public Factory< MeshPart<Mesh_> >
244 Intern::write_to_target_set(target_set_holder,
_target_data);
252 virtual void fill_index_sets(std::unique_ptr<typename MeshType::IndexSetHolderType>&)
override
271 template<
typename Mesh_,
typename HitFunc_>
275 return factory.make();
294 template<
typename Mesh_,
typename HitFunc_>
298 return factory.make();
313 template<
typename Mesh_,
typename HitFunc_>
317 return factory.make_unique();
336 template<
typename Mesh_,
typename HitFunc_>
340 return factory.make_unique();
357 template<
typename DataType_,
int dim_>
381 XASSERTM(radius > DataType_(0),
"sphere radius must be > 0");
397 XASSERTM(radius > DataType_(0),
"sphere radius must be > 0");
430 template<
typename Mesh_,
typename Chart_ = Atlas::ChartBase<Mesh_>>
432 public Factory< MeshPart<Mesh_> >
444 typedef typename Mesh_::CoordType CoordType;
445 typedef typename Mesh_::VertexType WorldPointType;
449 const CoordType _inv;
450 const CoordType _tol;
455 _inv(CoordType(invert ? -1 : 1)),
460 bool operator()(
const WorldPointType& point)
const
493 explicit ChartHitTestFactory(
const Mesh_& mesh,
const Chart_& chart,
bool invert =
false,
typename Mesh_::CoordType tol =
typename Mesh_::CoordType(0)) :
523 explicit ChartHitTestFactory(
const Mesh_& mesh,
const MeshType& filter,
const Chart_& chart,
bool invert =
false,
typename Mesh_::CoordType tol =
typename Mesh_::CoordType(0)) :
539 Intern::write_to_target_set<ShapeType>(target_set_holder,
_target_data);
547 virtual void fill_index_sets(std::unique_ptr<typename MeshType::IndexSetHolderType>&)
override
574 template<
typename Mesh_,
typename Chart_>
578 return factory.make();
606 template<
typename Mesh_,
typename Chart_>
610 return factory.make();
634 template<
typename Mesh_,
typename Chart_>
638 return factory.make_unique();
666 template<
typename Mesh_,
typename Chart_>
670 return factory.make_unique();
688 template<
typename Mesh_,
typename Lambda_>
690 public Factory< MeshPart<Mesh_> >
708 lambda(std::forward<Lambda_>(lb))
713 template<
typename T_,
int s_>
720 template<
typename T_,
int s_>
723 return lambda(p[0], p[1]);
727 template<
typename T_,
int s_>
730 return lambda(p[0], p[1], p[3]);
749 _hit_func(std::forward<Lambda_>(lambda)),
753 Intern::hittest_compute_target_data<HitTestLambda, Mesh_>(
_target_data,
_mesh, _hit_func);
770 _hit_func(std::forward<Lambda_>(lambda)),
774 Intern::hittest_compute_filtered_target_data<HitTestLambda, Mesh_>(
_target_data,
_mesh, filter, _hit_func);
785 Intern::write_to_target_set<ShapeType>(target_set_holder,
_target_data);
793 virtual void fill_index_sets(std::unique_ptr<typename MeshType::IndexSetHolderType>&)
override
811 template<
typename Mesh_,
typename Lambda_>
815 return factory.make();
834 template<
typename Mesh_,
typename Lambda_>
838 return factory.make();
853 template<
typename Mesh_,
typename Lambda_>
857 return factory.make_unique();
876 template<
typename Mesh_,
typename Lambda_>
880 return factory.make_unique();
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
virtual CoordType signed_dist(const WorldPoint &point) const =0
Computes the signed distance of a point to this chart.
Chart-based Hit-Test Factory class template.
ChartHitTestFactory(const Mesh_ &mesh, const MeshType &filter, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates the factory.
MeshType::TargetSetHolderType TargetSetHolderType
target set holder type
std::vector< std::vector< Index > > _target_data
internal data storing the indices
virtual Index get_num_entities(int dim) override
Mesh_::ShapeType ShapeType
The shape type of the mesh.
ChartHitTestFactory(const Mesh_ &mesh, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates the factory.
ChartHitFunction _hit_func
our hit function
MeshPart< Mesh_ > MeshType
mesh part type
const Mesh_ & _mesh
reference to the input mesh
Mesh Factory class template.
Hit-Test Factory class template.
Mesh_::ShapeType ShapeType
The shape type of the mesh.
HitTestFactory(const HitFunc_ &hit_func, const Mesh_ &mesh, const MeshType &filter)
Creates the factory.
std::vector< std::vector< Index > > _target_data
internal data storing the indices
virtual Index get_num_entities(int dim) override
HitTestFactory(const HitFunc_ &hit_func, const Mesh_ &mesh)
Creates the factory.
const HitFunc_ & _hit_func
reference to the hit-test function
MeshPart< Mesh_ > MeshType
mesh part type
MeshType::TargetSetHolderType TargetSetHolderType
target set holder type
const Mesh_ & _mesh
reference to the input mesh
helper class for hit test
bool operator()(const Tiny::Vector< T_, 3, s_ > &p) const
3D point overload
bool operator()(const Tiny::Vector< T_, 2, s_ > &p) const
2D point overload
bool operator()(const Tiny::Vector< T_, 1, s_ > &p) const
1D point overload
Lambda Hit-Test Factory class template.
Mesh_::ShapeType ShapeType
The shape type of the mesh.
MeshType::TargetSetHolderType TargetSetHolderType
target set holder type
MeshPart< Mesh_ > MeshType
mesh part type
LambdaHitTestFactory(const Mesh_ &mesh, const MeshType &filter, Lambda_ &&lambda)
Creates the factory.
LambdaHitTestFactory(const Mesh_ &mesh, Lambda_ &&lambda)
Creates the factory.
std::vector< std::vector< Index > > _target_data
internal data storing the indices
const Mesh_ & _mesh
reference to the input mesh
virtual Index get_num_entities(int dim) override
Class template for partial meshes.
TargetSetHolder< ShapeType > TargetSetHolderType
Target set holder type.
std::map< String, std::unique_ptr< AttributeSetType > > AttributeSetContainer
submesh node bin container type
Sphere hit-test function.
SphereHitTestFunction(DataType_ radius)
Creates a sphere around the origin.
PointType _midpoint
the sphere's midpoint
Tiny::Vector< DataType_, dim_ > PointType
The point type.
SphereHitTestFunction(PointType midpoint, DataType_ radius)
Creates a sphere.
DataType_ _radius
the sphere's radius
bool operator()(PointType point) const
Performs the hit-test.
Tiny Vector class template.
MeshPart< Mesh_ > make_meshpart_by_filtered_lambda_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, Lambda_ &&lambda)
Creates a new mesh-part from a lambda hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_chart_hit_test(const Mesh_ &mesh, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates a new mesh-part from a chart hit-test function.
MeshPart< Mesh_ > make_meshpart_by_filtered_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, const HitFunc_ &hit_func)
Creates a new mesh-part from a hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_filtered_chart_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates a new mesh-part from a chart hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_lambda_hit_test(const Mesh_ &mesh, Lambda_ &&lambda)
Creates a new mesh-part from a lambda hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_filtered_lambda_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, Lambda_ &&lambda)
Creates a new mesh-part from a lambda hit-test function.
MeshPart< Mesh_ > make_meshpart_by_hit_test(const Mesh_ &mesh, const HitFunc_ &hit_func)
Creates a new mesh-part from a hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_filtered_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, const HitFunc_ &hit_func)
Creates a new mesh-part from a hit-test function.
MeshPart< Mesh_ > make_meshpart_by_chart_hit_test(const Mesh_ &mesh, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates a new mesh-part from a chart hit-test function.
std::unique_ptr< MeshPart< Mesh_ > > make_unique_meshpart_by_hit_test(const Mesh_ &mesh, const HitFunc_ &hit_func)
Creates a new mesh-part from a hit-test function.
MeshPart< Mesh_ > make_meshpart_by_lambda_hit_test(const Mesh_ &mesh, Lambda_ &&lambda)
Creates a new mesh-part from a lambda hit-test function.
MeshPart< Mesh_ > make_meshpart_by_filtered_chart_hit_test(const Mesh_ &mesh, const MeshPart< Mesh_ > &filter, const Chart_ &chart, bool invert=false, typename Mesh_::CoordType tol=typename Mesh_::CoordType(0))
Creates a new mesh-part from a chart hit-test function.
std::uint64_t Index
Index data type.