43 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 45 #include "TetrahedralCuboidGenerator.hh" 47 void TetrahedralCuboidGenerator::add_vertices(
Vector const& position,
Vector const& length)
50 vertices_.reserve((size_[0] + 1) * (size_[1] + 1) * (size_[2] + 1));
52 Vector h(length[0] / size_[0], length[1] / size_[1], length[2] / size_[2]);
53 Vector origin = position - 0.5 * length;
55 for (std::size_t k = 0; k < size_[2] + 1; ++k)
56 for (std::size_t j = 0; j < size_[1] + 1; ++j)
57 for (std::size_t i = 0; i < size_[0] + 1; ++i)
58 vertices_.push_back(mesh_->
add_vertex(
Vector(h[0]*i, h[1]*j, h[2]*k) + origin));
61 void TetrahedralCuboidGenerator::get_cube_vertices(std::size_t i, std::size_t j, std::size_t k,
62 std::vector<OpenVolumeMesh::VertexHandle>& v)
const 64 v[0] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
65 v[1] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
66 v[2] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
67 v[3] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
68 v[4] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
69 v[5] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
70 v[6] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
71 v[7] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
74 void TetrahedralCuboidGenerator::add_faces()
76 std::vector<OpenVolumeMesh::VertexHandle> v(8);
78 for (std::size_t i = 0; i < size_[0]; ++i)
79 for (std::size_t j = 0; j < size_[1]; ++j)
80 for (std::size_t k = 0; k < size_[2]; ++k)
82 get_cube_vertices(i, j, k, v);
84 if ((i + j + k) % 2 == 0)
85 add_cube_type_1_faces(i, j, k, v);
87 add_cube_type_2_faces(i, j, k, v);
91 void TetrahedralCuboidGenerator::add_cube_type_1_faces(std::size_t i, std::size_t j, std::size_t k,
92 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
94 std::vector<OpenVolumeMesh::VertexHandle> fv(3);
97 fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[6];
98 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
99 fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[4];
100 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
103 fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[5];
104 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
105 fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[1];
106 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
109 fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[3];
110 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
111 fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[2];
112 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
115 fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[6];
116 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
117 fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[5];
118 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
119 fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[3];
120 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
121 fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[5];
122 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
125 if (i == size_[0] - 1) {
126 fv[0] = v[3]; fv[1] = v[5]; fv[2] = v[1];
127 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
128 fv[0] = v[3]; fv[1] = v[7]; fv[2] = v[5];
129 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
133 if (j == size_[1] - 1) {
134 fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[7];
135 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
136 fv[0] = v[3]; fv[1] = v[2]; fv[2] = v[6];
137 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
141 if (k == size_[2] - 1) {
142 fv[0] = v[5]; fv[1] = v[6]; fv[2] = v[4];
143 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
144 fv[0] = v[5]; fv[1] = v[7]; fv[2] = v[6];
145 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
149 void TetrahedralCuboidGenerator::add_cube_type_2_faces(std::size_t i, std::size_t j, std::size_t k,
150 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
152 std::vector<OpenVolumeMesh::VertexHandle> fv(3);
155 fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[4];
156 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
157 fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[4];
158 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
161 fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[1];
162 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
163 fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[1];
164 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
167 fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[2];
168 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
169 fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[2];
170 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
173 fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[4];
174 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
175 fv[0] = v[1]; fv[1] = v[2]; fv[2] = v[7];
176 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
177 fv[0] = v[2]; fv[1] = v[4]; fv[2] = v[7];
178 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
179 fv[0] = v[1]; fv[1] = v[4]; fv[2] = v[2];
180 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
183 if (i == size_[0] - 1) {
184 fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[5];
185 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
186 fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[7];
187 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
191 if (j == size_[1] - 1) {
192 fv[0] = v[2]; fv[1] = v[7]; fv[2] = v[3];
193 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
194 fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[7];
195 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
199 if (k == size_[2] - 1) {
200 fv[0] = v[4]; fv[1] = v[7]; fv[2] = v[6];
201 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
202 fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[7];
203 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
207 void TetrahedralCuboidGenerator::add_cells()
209 std::vector<OpenVolumeMesh::VertexHandle> v(8);
211 for (std::size_t i = 0; i < size_[0]; ++i)
212 for (std::size_t j = 0; j < size_[1]; ++j)
213 for (std::size_t k = 0; k < size_[2]; ++k)
215 get_cube_vertices(i, j, k, v);
217 if ((i + j + k) % 2 == 0)
218 add_cube_type_1_cells(i, j, k, v);
220 add_cube_type_2_cells(i, j, k, v);
224 void TetrahedralCuboidGenerator::add_cube_type_1_cells(std::size_t i, std::size_t j, std::size_t k,
225 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
227 std::vector<OpenVolumeMesh::FaceHandle> f(4);
228 std::vector<OpenVolumeMesh::HalfFaceHandle> hf(4);
235 hf[0] = mesh_->halfface_handle(f[0], 1);
236 hf[1] = mesh_->halfface_handle(f[1], 1);
237 hf[2] = mesh_->halfface_handle(f[2], 1);
238 hf[3] = mesh_->halfface_handle(f[3], 1);
245 hf[0] = mesh_->halfface_handle(f[0], 0);
246 hf[1] = mesh_->halfface_handle(f[1], 0);
247 hf[2] = mesh_->halfface_handle(f[2], 1);
248 hf[3] = mesh_->halfface_handle(f[3], 0);
255 hf[0] = mesh_->halfface_handle(f[0], 1);
256 hf[1] = mesh_->halfface_handle(f[1], 0);
257 hf[2] = mesh_->halfface_handle(f[2], 0);
258 hf[3] = mesh_->halfface_handle(f[3], 0);
265 hf[0] = mesh_->halfface_handle(f[0], 1);
266 hf[1] = mesh_->halfface_handle(f[1], 1);
267 hf[2] = mesh_->halfface_handle(f[2], 1);
268 hf[3] = mesh_->halfface_handle(f[3], 0);
275 hf[0] = mesh_->halfface_handle(f[0], 0);
276 hf[1] = mesh_->halfface_handle(f[1], 1);
277 hf[2] = mesh_->halfface_handle(f[2], 0);
278 hf[3] = mesh_->halfface_handle(f[3], 0);
282 void TetrahedralCuboidGenerator::add_cube_type_2_cells(std::size_t i, std::size_t j, std::size_t k,
283 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
285 std::vector<OpenVolumeMesh::FaceHandle> f(4);
286 std::vector<OpenVolumeMesh::HalfFaceHandle> hf(4);
293 hf[0] = mesh_->halfface_handle(f[0], 1);
294 hf[1] = mesh_->halfface_handle(f[1], 1);
295 hf[2] = mesh_->halfface_handle(f[2], 1);
296 hf[3] = mesh_->halfface_handle(f[3], 1);
303 hf[0] = mesh_->halfface_handle(f[0], 0);
304 hf[1] = mesh_->halfface_handle(f[1], 0);
305 hf[2] = mesh_->halfface_handle(f[2], 0);
306 hf[3] = mesh_->halfface_handle(f[3], 0);
313 hf[0] = mesh_->halfface_handle(f[0], 1);
314 hf[1] = mesh_->halfface_handle(f[1], 0);
315 hf[2] = mesh_->halfface_handle(f[2], 1);
316 hf[3] = mesh_->halfface_handle(f[3], 0);
323 hf[0] = mesh_->halfface_handle(f[0], 1);
324 hf[1] = mesh_->halfface_handle(f[1], 1);
325 hf[2] = mesh_->halfface_handle(f[2], 0);
326 hf[3] = mesh_->halfface_handle(f[3], 0);
333 hf[0] = mesh_->halfface_handle(f[0], 0);
334 hf[1] = mesh_->halfface_handle(f[1], 1);
335 hf[2] = mesh_->halfface_handle(f[2], 1);
336 hf[3] = mesh_->halfface_handle(f[3], 0);
340 TetrahedralCuboidGenerator::TetrahedralCuboidGenerator(
PolyhedralMesh& mesh,
345 unsigned const n_z) :
354 add_vertices(position, length);
virtual VertexHandle add_vertex()
Override of empty add_vertex function.