50 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
52 #include "TetrahedralCuboidGenerator.hh"
54 void TetrahedralCuboidGenerator::add_vertices(
Vector const& position,
Vector const& length)
57 vertices_.reserve((size_[0] + 1) * (size_[1] + 1) * (size_[2] + 1));
59 Vector h(length[0] / size_[0], length[1] / size_[1], length[2] / size_[2]);
60 Vector origin = position - 0.5 * length;
62 for (std::size_t k = 0; k < size_[2] + 1; ++k)
63 for (std::size_t j = 0; j < size_[1] + 1; ++j)
64 for (std::size_t i = 0; i < size_[0] + 1; ++i)
65 vertices_.push_back(mesh_->
add_vertex(
Vector(h[0]*i, h[1]*j, h[2]*k) + origin));
68 void TetrahedralCuboidGenerator::get_cube_vertices(std::size_t i, std::size_t j, std::size_t k,
69 std::vector<OpenVolumeMesh::VertexHandle>& v)
const
71 v[0] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
72 v[1] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
73 v[2] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
74 v[3] = vertices_[k * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
75 v[4] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i];
76 v[5] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + j * (size_[0] + 1) + i + 1];
77 v[6] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i];
78 v[7] = vertices_[(k + 1) * (size_[0] + 1) * (size_[1] + 1) + (j + 1) * (size_[0] + 1) + i + 1];
81 void TetrahedralCuboidGenerator::add_faces()
83 std::vector<OpenVolumeMesh::VertexHandle> v(8);
85 for (std::size_t i = 0; i < size_[0]; ++i)
86 for (std::size_t j = 0; j < size_[1]; ++j)
87 for (std::size_t k = 0; k < size_[2]; ++k)
89 get_cube_vertices(i, j, k, v);
91 if ((i + j + k) % 2 == 0)
92 add_cube_type_1_faces(i, j, k, v);
94 add_cube_type_2_faces(i, j, k, v);
98 void TetrahedralCuboidGenerator::add_cube_type_1_faces(std::size_t i, std::size_t j, std::size_t k,
99 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
101 std::vector<OpenVolumeMesh::VertexHandle> fv(3);
104 fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[6];
105 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
106 fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[4];
107 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
110 fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[5];
111 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
112 fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[1];
113 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
116 fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[3];
117 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
118 fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[2];
119 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
122 fv[0] = v[0]; fv[1] = v[5]; fv[2] = v[6];
123 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
124 fv[0] = v[0]; fv[1] = v[3]; fv[2] = v[5];
125 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
126 fv[0] = v[0]; fv[1] = v[6]; fv[2] = v[3];
127 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
128 fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[5];
129 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
132 if (i == size_[0] - 1) {
133 fv[0] = v[3]; fv[1] = v[5]; fv[2] = v[1];
134 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
135 fv[0] = v[3]; fv[1] = v[7]; fv[2] = v[5];
136 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
140 if (j == size_[1] - 1) {
141 fv[0] = v[3]; fv[1] = v[6]; fv[2] = v[7];
142 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
143 fv[0] = v[3]; fv[1] = v[2]; fv[2] = v[6];
144 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
148 if (k == size_[2] - 1) {
149 fv[0] = v[5]; fv[1] = v[6]; fv[2] = v[4];
150 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
151 fv[0] = v[5]; fv[1] = v[7]; fv[2] = v[6];
152 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
156 void TetrahedralCuboidGenerator::add_cube_type_2_faces(std::size_t i, std::size_t j, std::size_t k,
157 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
159 std::vector<OpenVolumeMesh::VertexHandle> fv(3);
162 fv[0] = v[0]; fv[1] = v[2]; fv[2] = v[4];
163 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
164 fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[4];
165 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
168 fv[0] = v[0]; fv[1] = v[4]; fv[2] = v[1];
169 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
170 fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[1];
171 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
174 fv[0] = v[0]; fv[1] = v[1]; fv[2] = v[2];
175 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
176 fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[2];
177 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
180 fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[4];
181 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
182 fv[0] = v[1]; fv[1] = v[2]; fv[2] = v[7];
183 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
184 fv[0] = v[2]; fv[1] = v[4]; fv[2] = v[7];
185 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
186 fv[0] = v[1]; fv[1] = v[4]; fv[2] = v[2];
187 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
190 if (i == size_[0] - 1) {
191 fv[0] = v[1]; fv[1] = v[7]; fv[2] = v[5];
192 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
193 fv[0] = v[1]; fv[1] = v[3]; fv[2] = v[7];
194 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
198 if (j == size_[1] - 1) {
199 fv[0] = v[2]; fv[1] = v[7]; fv[2] = v[3];
200 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
201 fv[0] = v[2]; fv[1] = v[6]; fv[2] = v[7];
202 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
206 if (k == size_[2] - 1) {
207 fv[0] = v[4]; fv[1] = v[7]; fv[2] = v[6];
208 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
209 fv[0] = v[4]; fv[1] = v[5]; fv[2] = v[7];
210 faces_.insert(std::make_pair(
SortedFace(fv), mesh_->add_face(fv)));
214 void TetrahedralCuboidGenerator::add_cells()
216 std::vector<OpenVolumeMesh::VertexHandle> v(8);
218 for (std::size_t i = 0; i < size_[0]; ++i)
219 for (std::size_t j = 0; j < size_[1]; ++j)
220 for (std::size_t k = 0; k < size_[2]; ++k)
222 get_cube_vertices(i, j, k, v);
224 if ((i + j + k) % 2 == 0)
225 add_cube_type_1_cells(i, j, k, v);
227 add_cube_type_2_cells(i, j, k, v);
231 void TetrahedralCuboidGenerator::add_cube_type_1_cells(std::size_t i, std::size_t j, std::size_t k,
232 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
234 std::vector<OpenVolumeMesh::FaceHandle> f(4);
235 std::vector<OpenVolumeMesh::HalfFaceHandle> hf(4);
242 hf[0] = mesh_->halfface_handle(f[0], 1);
243 hf[1] = mesh_->halfface_handle(f[1], 1);
244 hf[2] = mesh_->halfface_handle(f[2], 1);
245 hf[3] = mesh_->halfface_handle(f[3], 1);
252 hf[0] = mesh_->halfface_handle(f[0], 0);
253 hf[1] = mesh_->halfface_handle(f[1], 0);
254 hf[2] = mesh_->halfface_handle(f[2], 1);
255 hf[3] = mesh_->halfface_handle(f[3], 0);
262 hf[0] = mesh_->halfface_handle(f[0], 1);
263 hf[1] = mesh_->halfface_handle(f[1], 0);
264 hf[2] = mesh_->halfface_handle(f[2], 0);
265 hf[3] = mesh_->halfface_handle(f[3], 0);
272 hf[0] = mesh_->halfface_handle(f[0], 1);
273 hf[1] = mesh_->halfface_handle(f[1], 1);
274 hf[2] = mesh_->halfface_handle(f[2], 1);
275 hf[3] = mesh_->halfface_handle(f[3], 0);
282 hf[0] = mesh_->halfface_handle(f[0], 0);
283 hf[1] = mesh_->halfface_handle(f[1], 1);
284 hf[2] = mesh_->halfface_handle(f[2], 0);
285 hf[3] = mesh_->halfface_handle(f[3], 0);
289 void TetrahedralCuboidGenerator::add_cube_type_2_cells(std::size_t i, std::size_t j, std::size_t k,
290 std::vector<OpenVolumeMesh::VertexHandle>
const& v)
292 std::vector<OpenVolumeMesh::FaceHandle> f(4);
293 std::vector<OpenVolumeMesh::HalfFaceHandle> hf(4);
300 hf[0] = mesh_->halfface_handle(f[0], 1);
301 hf[1] = mesh_->halfface_handle(f[1], 1);
302 hf[2] = mesh_->halfface_handle(f[2], 1);
303 hf[3] = mesh_->halfface_handle(f[3], 1);
310 hf[0] = mesh_->halfface_handle(f[0], 0);
311 hf[1] = mesh_->halfface_handle(f[1], 0);
312 hf[2] = mesh_->halfface_handle(f[2], 0);
313 hf[3] = mesh_->halfface_handle(f[3], 0);
320 hf[0] = mesh_->halfface_handle(f[0], 1);
321 hf[1] = mesh_->halfface_handle(f[1], 0);
322 hf[2] = mesh_->halfface_handle(f[2], 1);
323 hf[3] = mesh_->halfface_handle(f[3], 0);
330 hf[0] = mesh_->halfface_handle(f[0], 1);
331 hf[1] = mesh_->halfface_handle(f[1], 1);
332 hf[2] = mesh_->halfface_handle(f[2], 0);
333 hf[3] = mesh_->halfface_handle(f[3], 0);
340 hf[0] = mesh_->halfface_handle(f[0], 0);
341 hf[1] = mesh_->halfface_handle(f[1], 1);
342 hf[2] = mesh_->halfface_handle(f[2], 1);
343 hf[3] = mesh_->halfface_handle(f[3], 0);
347 TetrahedralCuboidGenerator::TetrahedralCuboidGenerator(
PolyhedralMesh& mesh,
352 unsigned const n_z) :
361 add_vertices(position, length);
virtual VertexHandle add_vertex()
Override of empty add_vertex function.