Visual Computing Library
Loading...
Searching...
No Matches
hexahedron.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_MESH_CREATE_HEXAHEDRON_H
24#define VCL_ALGORITHMS_MESH_CREATE_HEXAHEDRON_H
25
26#include <vclib/mesh/requirements.h>
27
28namespace vcl {
29
30namespace detail {
31
32template<FaceMeshConcept MeshType>
33void fillHexahedronTriangles(MeshType& m)
34{
35 m.reserveFaces(12);
36 m.addFace(0, 2, 1);
37 m.addFace(3, 1, 2);
38 m.addFace(0, 4, 2);
39 m.addFace(6, 2, 4);
40 m.addFace(0, 1, 4);
41 m.addFace(5, 4, 1);
42 m.addFace(7, 6, 5);
43 m.addFace(4, 5, 6);
44 m.addFace(7, 3, 6);
45 m.addFace(2, 6, 3);
46 m.addFace(7, 5, 3);
47 m.addFace(1, 3, 5);
48}
49
50template<FaceMeshConcept MeshType>
51void fillHexahedronQuads(MeshType& m)
52{
53 m.reserveFaces(6);
54 m.addFace(2, 3, 1, 0);
55 m.addFace(4, 6, 2, 0);
56 m.addFace(1, 5, 4, 0);
57 m.addFace(6, 4, 5, 7);
58 m.addFace(3, 2, 6, 7);
59 m.addFace(5, 1, 3, 7);
60}
61
62} // namespace detail
63
76template<FaceMeshConcept MeshType>
78{
79 using CoordType = MeshType::Vertex::CoordType;
80
82 CoordType(-1, -1, -1), CoordType(1, 1, 1));
83}
84
97template<FaceMeshConcept MeshType, Point3Concept CoordType>
98MeshType createHexahedron(const CoordType& min, const CoordType& max)
99{
100 MeshType m;
101
102 // fill vertices...
103 m.addVertices(
104 CoordType(min(0), min(1), min(2)),
105 CoordType(max(0), min(1), min(2)),
106 CoordType(min(0), max(1), min(2)),
107 CoordType(max(0), max(1), min(2)),
108 CoordType(min(0), min(1), max(2)),
109 CoordType(max(0), min(1), max(2)),
110 CoordType(min(0), max(1), max(2)),
111 CoordType(max(0), max(1), max(2)));
112
113 // fill faces
114 if constexpr (HasTriangles<MeshType>) {
115 detail::fillHexahedronTriangles(m);
116 }
117 else {
118 detail::fillHexahedronQuads(m);
119 }
120 return m;
121}
122
135template<FaceMeshConcept MeshType, Point3Concept CoordType>
136MeshType createCube(const CoordType& min, double edgeLength)
137{
138 return createHexahedron<MeshType>(min, CoordType(min + edgeLength));
139}
140
153template<FaceMeshConcept MeshType>
154MeshType createCube()
155{
156 using CoordType = MeshType::Vertex::CoordType;
157 return createCube<MeshType>(CoordType(-0.5, -0.5, -0.5), 1);
158}
159
160} // namespace vcl
161
162#endif // VCL_ALGORITHMS_MESH_CREATE_HEXAHEDRON_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition per_face.h:40
MeshType createCube()
Creates and returns a Cube having (-0.5, -0.5, -0.5) as minimum extreme and 1 length.
Definition hexahedron.h:154
MeshType createHexahedron()
Creates and returns a hexahedron having as extremes the points (-1, -1, -1) and (1,...
Definition hexahedron.h:77
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:83
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:42