Wildmeshing Toolkit
Grid3Options.cpp
Go to the documentation of this file.
1 
2 #include "Grid3Options.hpp"
3 #include <wmtk/Mesh.hpp>
4 #include <wmtk/TetMesh.hpp>
6 #include "grid_utils.hpp"
7 
8 
10 const std::array<std::string, 2> Grid3Options::tiling_names = {{"bcc", "freudenthal"}};
11 
12 namespace {
13 std::shared_ptr<TetMesh> make_freudenthal_mesh(const Grid3Options& opt)
14 {
15  const auto& d = opt.dimensions;
16  auto vertex_dimensions = opt.dimensions;
17  for (size_t j = 0; j < d.size(); ++j) {
18  int64_t& v = vertex_dimensions[j];
19  if (!opt.cycles[j]) {
20  v++;
21  }
22  }
23  using CoordType = std::array<int64_t, 3>;
24 
25  Eigen::Matrix<int64_t, Eigen::Dynamic, 4> FV(6 * d[0] * d[1] * d[2], 4);
26 
27  CoordType i;
28  // auto& [j, k, l] = i;
29  int64_t& j = i[0];
30  int64_t& k = i[1];
31  int64_t& l = i[2];
32  for (j = 0; j < d[0]; ++j) {
33  for (k = 0; k < d[1]; ++k) {
34  for (l = 0; l < d[2]; ++l) {
35  auto f = [&](int64_t a, int64_t b, int64_t c) {
36  CoordType coord{{j + a, k + b, l + c}};
37  for (size_t e = 0; e < 3; ++e) {
38  auto& v = coord[e];
39  v = v % vertex_dimensions[e];
40  }
41 
42 
43  return procedural::grid_index(vertex_dimensions, coord);
44  };
45  int64_t c[8] = {
46  f(0, 0, 0),
47  f(1, 0, 0),
48  f(1, 1, 0),
49  f(0, 1, 0),
50  f(0, 0, 1),
51  f(1, 0, 1),
52  f(1, 1, 1),
53  f(0, 1, 1),
54  };
55  int64_t f0_index = 6 * procedural::grid_index(d, i);
56 
57 
58  FV.row(f0_index + 0) << c[0], c[1], c[3], c[4];
59  FV.row(f0_index + 1) << c[5], c[2], c[6], c[7];
60  FV.row(f0_index + 2) << c[4], c[1], c[5], c[3];
61  FV.row(f0_index + 3) << c[4], c[3], c[7], c[5];
62  FV.row(f0_index + 4) << c[3], c[1], c[5], c[2];
63  FV.row(f0_index + 5) << c[2], c[3], c[7], c[5];
64  }
65  }
66  }
67 
68  auto m = std::make_shared<TetMesh>();
69  m->initialize(FV);
70  if (opt.coordinates.has_value()) {
71  int vertex_size = vertex_dimensions[0] * vertex_dimensions[1] * vertex_dimensions[2];
72 
73  const auto& spacing = opt.coordinates->spacing;
74  Eigen::Matrix<double, Eigen::Dynamic, 3> P(vertex_size, 3);
75  for (j = 0; j < vertex_dimensions[0]; ++j) {
76  double x = spacing[0] * j;
77  for (k = 0; k < vertex_dimensions[1]; ++k) {
78  double y = spacing[1] * k;
79  for (l = 0; l < vertex_dimensions[2]; ++l) {
80  double z = spacing[2] * l;
81  int64_t index = procedural::grid_index(vertex_dimensions, i);
82 
83  P.row(index) << x, y, z;
84  }
85  }
86  }
87  const auto& name = opt.coordinates->name;
89  }
90  return m;
91 }
92 } // namespace
93 
94 std::shared_ptr<TetMesh> make_mesh(const Grid3Options& opt)
95 {
96  switch (opt.tiling_type) {
97  case Grid3Options::TilingType::Freudenthal: return make_freudenthal_mesh(opt);
99  throw std::runtime_error("bcc lattice not implemented yet");
100  [[fallthrough]];
101  default: break;
102  }
103  throw std::runtime_error("failed to select a tiling type");
104  return nullptr;
105 }
106 } // namespace wmtk::components::procedural
static const std::array< std::string, 2 > tiling_names
std::shared_ptr< TriMesh > make_mesh(const DiskOptions &opt)
Definition: DiskOptions.cpp:10
int64_t grid_index(const std::array< int64_t, 3 > &d, const std::array< int64_t, 3 > &i)
Definition: grid_utils.cpp:16
attribute::MeshAttributeHandle set_matrix_attribute(const Mat &data, const std::string &name, const PrimitiveType &type, Mesh &mesh)
Definition: mesh_utils.hpp:9