71 const std::string &type,
72 const std::vector<double> &shape_arguments,
73 const Point<dim> &position,
74 const Tensor<1, 3> &orientation)
79 std::shared_ptr<Shape<dim>> shape;
80 if (shape_type == ShapeType::sphere)
82 std::make_shared<Sphere<dim>>(shape_arguments[0], position, orientation);
83 else if (shape_type == ShapeType::hyper_rectangle)
85 Tensor<1, dim> half_lengths;
86 for (
int i = 0; i < dim; ++i)
88 half_lengths[i] = shape_arguments[i];
90 shape = std::make_shared<HyperRectangle<dim>>(half_lengths,
94 else if (shape_type == ShapeType::ellipsoid)
97 for (
int i = 0; i < dim; ++i)
99 radii[i] = shape_arguments[i];
101 shape = std::make_shared<Ellipsoid<dim>>(radii, position, orientation);
103 else if (shape_type == ShapeType::superquadric)
105 if constexpr (dim == 3)
107 Tensor<1, dim> half_lengths{};
108 Tensor<1, dim> exponents{};
109 for (
int d = 0; d < dim; d++)
111 half_lengths[d] = shape_arguments[d];
112 exponents[d] = shape_arguments[d + dim];
114 double epsilon = 1e-8;
115 if (shape_arguments.size() == 7)
117 epsilon = shape_arguments[3 + dim];
119 shape = std::make_shared<Superquadric<dim>>(
120 half_lengths, exponents, epsilon, position, orientation);
123 else if (shape_type == ShapeType::torus)
125 if constexpr (dim == 3)
126 shape = std::make_shared<
Torus<dim>>(shape_arguments[0],
131 else if (shape_type == ShapeType::cone)
133 if constexpr (dim == 3)
134 shape = std::make_shared<
Cone<dim>>(shape_arguments[0],
139 else if (shape_type == ShapeType::cylinder)
141 if constexpr (dim == 3)
147 else if (shape_type == ShapeType::cylindrical_tube)
149 if constexpr (dim == 3)
156 else if (shape_type == ShapeType::cylindrical_helix)
158 if constexpr (dim == 3)
166 else if (shape_type == ShapeType::cut_hollow_sphere)
168 if constexpr (dim == 3)
175 else if (shape_type == ShapeType::death_star)
177 if constexpr (dim == 3)
184 else if (shape_type == ShapeType::plane)
186 shape = std::make_shared<Plane<dim>>(position, orientation);
189 AssertThrow(
false, ExcNotImplemented());
196 const std::string &file_name,
197 const Point<dim> &position,
198 const Tensor<1, 3> &orientation)
203 std::shared_ptr<Shape<dim>> shape;
204 std::vector<double> shape_arguments;
205 if (shape_type == ShapeType::rbf)
207 shape = std::make_shared<RBFShape<dim>>(file_name, position, orientation);
209 else if (shape_type == ShapeType::composite)
213 std::map<unsigned int, std::shared_ptr<Shape<dim>>> components;
214 std::map<
unsigned int,
215 std::tuple<typename CompositeShape<dim>::BooleanOperation,
221 std::ifstream myfile(file_name);
226 std::vector<std::string> column_names;
227 std::vector<double> line_of_data;
228 bool parsing_shapes =
false;
229 bool parsing_operations =
false;
231 std::string marker =
"#";
232 while (std::getline(myfile, line))
235 size_t markerPos = line.find(marker);
236 if (markerPos != std::string::npos)
238 line = line.substr(0, markerPos);
242 if (line ==
"shapes")
244 parsing_shapes =
true;
245 parsing_operations =
false;
247 else if (line ==
"operations")
249 parsing_shapes =
false;
250 parsing_operations =
true;
254 std::vector<std::string> list_of_words_base =
255 Utilities::split_string_list(line,
";");
256 std::vector<std::string> list_of_words_clean;
257 for (
const auto &word : list_of_words_base)
260 list_of_words_clean.emplace_back(word);
264 unsigned int identifier = stoi(list_of_words_clean[0]);
265 const std::string &type_str = list_of_words_clean[1];
266 std::string arguments_str = list_of_words_clean[2];
267 std::ranges::replace(arguments_str,
':',
';');
268 const std::string &position_str = list_of_words_clean[3];
269 const std::string &orientation_str =
270 list_of_words_clean[4];
272 std::vector<std::string> position_str_component =
273 Utilities::split_string_list(position_str,
":");
274 std::vector<std::string> orientation_str_component =
275 Utilities::split_string_list(orientation_str,
":");
277 std::vector<double> temp_position_vec =
278 Utilities::string_to_double(position_str_component);
279 std::vector<double> temp_orientation_vec =
280 Utilities::string_to_double(orientation_str_component);
282 Point<dim> temp_position;
283 Point<3> temp_orientation =
284 Point<3>({temp_orientation_vec[0],
285 temp_orientation_vec[1],
286 temp_orientation_vec[2]});
287 temp_position[0] = temp_position_vec[0];
288 temp_position[1] = temp_position_vec[1];
289 if constexpr (dim == 3)
290 temp_position[2] = temp_position_vec[2];
292 std::shared_ptr<Shape<dim>> shape_temp;
294 type_str, arguments_str, Point<dim>(), Tensor<1, 3>());
295 shape_temp->set_position(temp_position);
296 shape_temp->set_orientation(temp_orientation);
297 components[identifier] = shape_temp->static_copy();
299 else if (parsing_operations)
301 unsigned int identifier = stoi(list_of_words_clean[0]);
302 const std::string &type_str = list_of_words_clean[1];
303 const std::string &arguments_str = list_of_words_clean[2];
304 std::vector<std::string> arguments_str_component =
305 Utilities::split_string_list(arguments_str,
":");
307 unsigned int first_shape =
308 stoi(arguments_str_component[0]);
309 unsigned int second_shape =
310 stoi(arguments_str_component[1]);
311 if (type_str ==
"union")
313 operations[identifier] = std::make_tuple(
318 else if (type_str ==
"difference")
320 operations[identifier] = std::make_tuple(
325 else if (type_str ==
"intersection")
327 operations[identifier] = std::make_tuple(
336 shape = std::make_shared<CompositeShape<dim>>(components,
342 throw std::invalid_argument(file_name);
344 else if (shape_type == ShapeType::opencascade)
346 shape = std::make_shared<OpenCascadeShape<dim>>(file_name,