ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Shape.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <shapes/Shape.hpp>
21
22#include <utils/Vector.hpp>
23
24#include <boost/multi_array.hpp>
25
26#include <vector>
27
28namespace Shapes {
29std::vector<int> Shape::rasterize(Utils::Vector3i const &grid_size,
30 double grid_spacing,
31 double grid_offset) const {
32 boost::multi_array<int, 3> raster(grid_size);
33 for (int i = 0; i < grid_size[0]; ++i) {
34 for (int j = 0; j < grid_size[1]; ++j) {
35 for (int k = 0; k < grid_size[2]; ++k) {
36 auto const pos = Utils::Vector3d{{(i + grid_offset) * grid_spacing,
37 (j + grid_offset) * grid_spacing,
38 (k + grid_offset) * grid_spacing}};
39 raster[i][j][k] = is_inside(pos);
40 }
41 }
42 }
43 return {raster.data(), raster.data() + raster.num_elements()};
44}
45} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
std::vector< int > rasterize(Utils::Vector3i const &grid_size, double grid_spacing, double grid_offset) const
Rasterize a shape on a regular grid.
Definition Shape.cpp:29
virtual bool is_inside(Utils::Vector3d const &pos) const
Check whether the given point is inside the shape or not.