PolyFEM
Loading...
Searching...
No Matches
Selection.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <polyfem/Common.hpp>
5
6namespace polyfem
7{
8 namespace utils
9 {
11 {
12 public:
13 typedef std::array<RowVectorNd, 2> BBox;
14
15 Selection(const int id) : id_(id) {}
16
17 virtual ~Selection() {}
18
19 virtual bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const = 0;
20
21 virtual int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const
22 {
23 return id_;
24 }
25
31 static std::shared_ptr<Selection> build(
32 const json &j_selections,
33 const BBox &mesh_bbox,
34 const std::string &root_path);
35
41 static std::vector<std::shared_ptr<utils::Selection>> build_selections(
42 const json &j_selections,
43 const BBox &mesh_bbox,
44 const std::string &root_path);
45
46 inline bool boundary_only() const { return boundary_only_; }
47
48 private:
49 bool boundary_only_ = true;
50
51 protected:
53
54 size_t id_;
55 };
56
57 // --------------------------------------------------------------------
58
59 class BoxSelection : public Selection
60 {
61 public:
63 const json &selection,
64 const BBox &mesh_bbox);
65
66 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
67
68 protected:
70 };
71
72 // --------------------------------------------------------------------
73
75 {
76 public:
78 const json &selection,
79 const BBox &mesh_bbox);
80
81 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override
82 {
83 return true;
84 }
85
86 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
87
88 protected:
90 double tolerance_;
92 };
93
94 // --------------------------------------------------------------------
95
97 {
98 public:
100 const json &selection,
101 const BBox &mesh_bbox);
102
103 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
104
105 protected:
107 double radius2_;
108 };
109
110 // --------------------------------------------------------------------
111
113 {
114 public:
116 const json &selection,
117 const BBox &mesh_bbox);
118
119 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
120
121 protected:
124 double radius2_;
125 double height_;
126 };
127
128 // --------------------------------------------------------------------
129
131 {
132 public:
134 const json &selection,
135 const BBox &mesh_bbox);
136
137 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
138
139 protected:
140 int axis_;
141 double position_;
142 };
143
144 // --------------------------------------------------------------------
145
147 {
148 public:
150 const json &selection,
151 const BBox &mesh_bbox);
152
153 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
154
155 protected:
158 };
159
160 // --------------------------------------------------------------------
161
163 {
164 public:
165 UniformSelection(const int id)
166 : Selection(id) {}
167
168 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
169 };
170
171 // --------------------------------------------------------------------
172
174 {
175 public:
177 const std::vector<int> &ids);
178
179 virtual bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
180
181 virtual int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
182
183 protected:
185
186 std::vector<int> ids_;
187 };
188
189 // --------------------------------------------------------------------
190
192 {
193 public:
195 const std::string &file_path,
196 const int id_offset = 0);
197
198 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
199 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
200
201 private:
202 std::vector<std::pair<int, std::vector<int>>> data_;
203 };
204 } // namespace utils
205} // namespace polyfem
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:81
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::shared_ptr< Selection > build(const json &j_selections, const BBox &mesh_bbox, const std::string &root_path)
Build a selection objects from a JSON selection.
Definition Selection.cpp:16
std::array< RowVectorNd, 2 > BBox
Definition Selection.hpp:13
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:21
static std::vector< std::shared_ptr< utils::Selection > > build_selections(const json &j_selections, const BBox &mesh_bbox, const std::string &root_path)
Build a vector of selection objects from a JSON selection(s).
Definition Selection.cpp:49
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