| OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generate_cube.hh
1 #ifndef GENERATE_CUBE_HH
2 #define GENERATE_CUBE_HH
3
4 template <typename MeshType>
5 size_t generate_cube( MeshType& mesh )
6 {
7 typedef typename MeshType::VertexHandle VertexHandle;
8 typedef typename MeshType::Point Point;
9
10 typename MeshType::VertexHandle vhandle[8];
11
12 vhandle[0] = mesh.add_vertex(Point(-1, -1, 1));
13 vhandle[1] = mesh.add_vertex(Point( 1, -1, 1));
14 vhandle[2] = mesh.add_vertex(Point( 1, 1, 1));
15 vhandle[3] = mesh.add_vertex(Point(-1, 1, 1));
16 vhandle[4] = mesh.add_vertex(Point(-1, -1, -1));
17 vhandle[5] = mesh.add_vertex(Point( 1, -1, -1));
18 vhandle[6] = mesh.add_vertex(Point( 1, 1, -1));
19 vhandle[7] = mesh.add_vertex(Point(-1, 1, -1));
20
21 // generate (quadrilateral) faces
22
23 std::vector< VertexHandle > face_vhandles;
24
25 face_vhandles.clear();
26 face_vhandles.push_back(vhandle[0]);
27 face_vhandles.push_back(vhandle[1]);
28 face_vhandles.push_back(vhandle[2]);
29 face_vhandles.push_back(vhandle[3]);
30 mesh.add_face(face_vhandles);
31
32 face_vhandles.clear();
33 face_vhandles.push_back(vhandle[7]);
34 face_vhandles.push_back(vhandle[6]);
35 face_vhandles.push_back(vhandle[5]);
36 face_vhandles.push_back(vhandle[4]);
37 mesh.add_face(face_vhandles);
38
39 face_vhandles.clear();
40 face_vhandles.push_back(vhandle[1]);
41 face_vhandles.push_back(vhandle[0]);
42 face_vhandles.push_back(vhandle[4]);
43 face_vhandles.push_back(vhandle[5]);
44 mesh.add_face(face_vhandles);
45
46 face_vhandles.clear();
47 face_vhandles.push_back(vhandle[2]);
48 face_vhandles.push_back(vhandle[1]);
49 face_vhandles.push_back(vhandle[5]);
50 face_vhandles.push_back(vhandle[6]);
51 mesh.add_face(face_vhandles);
52
53 face_vhandles.clear();
54 face_vhandles.push_back(vhandle[3]);
55 face_vhandles.push_back(vhandle[2]);
56 face_vhandles.push_back(vhandle[6]);
57 face_vhandles.push_back(vhandle[7]);
58 mesh.add_face(face_vhandles);
59
60 face_vhandles.clear();
61 face_vhandles.push_back(vhandle[0]);
62 face_vhandles.push_back(vhandle[3]);
63 face_vhandles.push_back(vhandle[7]);
64 face_vhandles.push_back(vhandle[4]);
65 mesh.add_face(face_vhandles);
66
67 return mesh.n_vertices();
68 };
69
70 #endif