1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
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 GNU General Public License as published by *
13 * the Free Software 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 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 #ifndef TETRAMESH_SUPPORT_H
24 #define TETRAMESH_SUPPORT_H
25
26 #include <vcg/simplex/tetrahedron/topology.h>
27 namespace vcg {
28 namespace tri {
29
30 template <class TetraMesh, class TriMesh>
CreateTriMeshFromTTBorder(TetraMesh & tetramesh,TriMesh & trimesh)31 inline void CreateTriMeshFromTTBorder(TetraMesh & tetramesh, TriMesh & trimesh)
32 {
33 typedef typename TetraMesh::VertexPointer VertexPointer;
34 typedef typename TriMesh::FacePointer FacePointer;
35
36 RequireTTAdjacency(tetramesh);
37 tri::UpdateTopology<TetraMesh>::TetraTetra(tetramesh);
38
39 trimesh.Clear();
40
41 std::vector<VertexPointer> verts;
42
43 typedef typename TetraMesh::TetraType TetraType;
44
45 ForEachTetra(tetramesh, [&] (TetraType & t) {
46 for (int i = 0; i < 4; ++i)
47 if (vcg::tetrahedron::IsTTBorder(t, i))
48 {
49 verts.push_back(t.V(Tetra::VofF(i, 0)));
50 verts.push_back(t.V(Tetra::VofF(i, 1)));
51 verts.push_back(t.V(Tetra::VofF(i, 2)));
52 }
53 });
54
55 typedef typename TriMesh::VertexIterator VertexIterator;
56 typedef typename TriMesh::FaceIterator FaceIterator;
57
58 VertexIterator vi = tri::Allocator<TriMesh>::AddVertices(trimesh, verts.size());
59 FaceIterator fi = tri::Allocator<TriMesh>::AddFaces(trimesh, verts.size() / 3);
60
61 for (int i = 0; i < verts.size(); i += 3)
62 {
63 fi->Alloc(3);
64
65 vi->P() = verts[i + 0]->P();
66 fi->V(0) = &*vi;
67 ++vi;
68
69 vi->P() = verts[i + 1]->P();
70 fi->V(1) = &*vi;
71 ++vi;
72
73 vi->P() = verts[i + 2]->P();
74 fi->V(2) = &*vi;
75 ++vi;
76
77 ++fi;
78 }
79
80 //do it while you build the mesh
81 vcg::tri::Clean<TriMesh>::RemoveDuplicateVertex(trimesh);
82 vcg::tri::Allocator<TriMesh>::CompactEveryVector(trimesh);
83 }
84
85 } // end namespace tri
86 } // end namespace vcg
87
88
89 #endif // EXTRUDE_H
90