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 protected:
48
49 size_t id_;
50 };
51
52 // --------------------------------------------------------------------
53
54 class BoxSelection : public Selection
55 {
56 public:
58 const json &selection,
59 const BBox &mesh_bbox);
60
61 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
62
63 protected:
65 };
66
67 // --------------------------------------------------------------------
68
70 {
71 public:
73 const json &selection,
74 const BBox &mesh_bbox);
75
76 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override
77 {
78 return true;
79 }
80
81 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
82
83 protected:
85 double tolerance_;
87 };
88
89 // --------------------------------------------------------------------
90
92 {
93 public:
95 const json &selection,
96 const BBox &mesh_bbox);
97
98 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
99
100 protected:
102 double radius2_;
103 };
104
105 // --------------------------------------------------------------------
106
108 {
109 public:
111 const json &selection,
112 const BBox &mesh_bbox);
113
114 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
115
116 protected:
119 double radius2_;
120 double height_;
121 };
122
123 // --------------------------------------------------------------------
124
126 {
127 public:
129 const json &selection,
130 const BBox &mesh_bbox);
131
132 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
133
134 protected:
135 int axis_;
136 double position_;
137 };
138
139 // --------------------------------------------------------------------
140
142 {
143 public:
145 const json &selection,
146 const BBox &mesh_bbox);
147
148 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
149
150 protected:
153 };
154
155 // --------------------------------------------------------------------
156
158 {
159 public:
160 UniformSelection(const int id)
161 : Selection(id) {}
162
163 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
164 };
165
166 // --------------------------------------------------------------------
167
169 {
170 public:
172 const std::vector<int> &ids);
173
174 virtual bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override { return true; }
175
176 virtual int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
177
178 protected:
180
181 std::vector<int> ids_;
182 };
183
184 // --------------------------------------------------------------------
185
187 {
188 public:
190 const std::string &file_path,
191 const int id_offset = 0);
192
193 bool inside(const size_t p_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
194 int id(const size_t element_id, const std::vector<int> &vs, const RowVectorNd &p) const override;
195
196 private:
197 std::vector<std::pair<int, std::vector<int>>> data_;
198 };
199 } // namespace utils
200} // 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:76
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
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::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
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:45
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