PolyFEM
Loading...
Searching...
No Matches
Selection.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <polyfem/Common.hpp>
6
7namespace polyfem
8{
9 namespace utils
10 {
12 {
13 public:
14 typedef std::array<RowVectorNd, 2> BBox;
15
16 Selection(const int id) : id_(id) {}
17
18 virtual ~Selection() {}
19
20 virtual bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const = 0;
21
22 virtual int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const
23 {
24 return id_;
25 }
26
32 static std::shared_ptr<Selection> build(
33 const json &j_selections,
34 const BBox &mesh_bbox,
35 const io::ResourceIO &resources);
36
42 static std::vector<std::shared_ptr<utils::Selection>> build_selections(
43 const json &j_selections,
44 const BBox &mesh_bbox,
45 const io::ResourceIO &resources);
46
47 inline bool boundary_only() const { return boundary_only_; }
48
49 private:
50 bool boundary_only_ = true;
51
52 protected:
54
55 size_t id_;
56 };
57
58 // --------------------------------------------------------------------
59
60 class BoxSelection : public Selection
61 {
62 public:
64 const json &selection,
65 const BBox &mesh_bbox);
66
67 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
68
69 protected:
71 };
72
73 // --------------------------------------------------------------------
74
76 {
77 public:
79 const json &selection,
80 const BBox &mesh_bbox);
81
82 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override
83 {
84 return true;
85 }
86
87 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
88
89 protected:
91 double tolerance_;
93 };
94
95 // --------------------------------------------------------------------
96
98 {
99 public:
101 const json &selection,
102 const BBox &mesh_bbox);
103
104 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
105
106 protected:
108 double radius2_;
109 };
110
111 // --------------------------------------------------------------------
112
114 {
115 public:
117 const json &selection,
118 const BBox &mesh_bbox);
119
120 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
121
122 protected:
125 double radius2_;
126 double height_;
127 };
128
129 // --------------------------------------------------------------------
130
132 {
133 public:
135 const json &selection,
136 const BBox &mesh_bbox);
137
138 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
139
140 protected:
141 int axis_;
142 double position_;
143 };
144
145 // --------------------------------------------------------------------
146
148 {
149 public:
151 const json &selection,
152 const BBox &mesh_bbox);
153
154 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
155
156 protected:
159 };
160
161 // --------------------------------------------------------------------
162
164 {
165 public:
166 UniformSelection(const int id)
167 : Selection(id) {}
168
169 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
170 };
171
172 // --------------------------------------------------------------------
173
175 {
176 public:
178 const std::vector<int> &ids);
179
180 virtual bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
181
182 virtual int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
183
184 protected:
186
187 std::vector<int> ids_;
188 };
189
190 // --------------------------------------------------------------------
191
193 {
194 public:
196 const io::ResourceIO &resources,
197 const std::string &path,
198 const int id_offset = 0);
199
200 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
201 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
202
203 private:
204 std::vector<std::pair<int, std::vector<int>>> data_;
205 };
206 } // namespace utils
207} // namespace polyfem
Read-only interface to a hierarchical collection of simulation resources.
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
int id(const size_t element_id, const std::vector< int > &vs, const RowVectorNd &p) const override
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
Definition Selection.hpp:82
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
int id(const size_t element_id, const std::vector< int > &vs, const RowVectorNd &p) const override
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
std::vector< std::pair< int, std::vector< int > > > data_
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
static std::vector< std::shared_ptr< utils::Selection > > build_selections(const json &j_selections, const BBox &mesh_bbox, const io::ResourceIO &resources)
Build a vector of selection objects from a JSON selection(s).
Definition Selection.cpp:47
std::array< RowVectorNd, 2 > BBox
Definition Selection.hpp:14
static std::shared_ptr< Selection > build(const json &j_selections, const BBox &mesh_bbox, const io::ResourceIO &resources)
Build a selection objects from a JSON selection.
Definition Selection.cpp:14
virtual bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const =0
virtual int id(const size_t element_id, const std::vector< int > &vs, const RowVectorNd &p) const
Definition Selection.hpp:22
virtual bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
virtual int id(const size_t element_id, const std::vector< int > &vs, const RowVectorNd &p) const override
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
bool inside(const size_t p_id, const std::vector< int > &vs, const RowVectorNd &p) const override
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13