Repository navigation
Expand file tree
/
Copy pathVertexValanceAttribute.cpp
More file actions
144 lines (126 loc) · 4.32 KB
/
Copy pathVertexValanceAttribute.cpp
File metadata and controls
144 lines (126 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* This file is part of PyMesh. Copyright (c) 2015 by Qingnan Zhou */
#include "VertexValanceAttribute.h"
#include <set>
#include <sstream>
#include <Mesh.h>
#include <Core/Exception.h>
#include <Misc/Multiplet.h>
using namespace PyMesh;
void VertexValanceAttribute::compute_from_mesh(Mesh& mesh) {
const size_t num_voxels = mesh.get_num_voxels();
const size_t num_vertex_per_voxel = mesh.get_vertex_per_voxel();
if (num_voxels == 0) {
compute_from_surface_mesh(mesh);
} else if (num_vertex_per_voxel == 4) {
compute_from_tet_mesh(mesh);
} else if (num_vertex_per_voxel == 8) {
compute_from_hex_mesh(mesh);
} else {
std::stringstream err_msg;
err_msg << "Vertex valance computation is not supported on mesh with "
<< num_vertex_per_voxel << " vertices per voxel";
throw NotImplementedError(err_msg.str());
}
}
void VertexValanceAttribute::compute_from_surface_mesh(Mesh& mesh) {
const size_t num_vertices = mesh.get_num_vertices();
const size_t num_faces = mesh.get_num_faces();
const size_t num_vertex_per_face = mesh.get_vertex_per_face();
VectorF& vertex_valance = m_values;
vertex_valance = VectorF::Zero(num_vertices);
std::set<Duplet> edges;
for (size_t i=0; i<num_faces; i++) {
VectorI face = mesh.get_face(i);
for (size_t j=0; j<num_vertex_per_face; j++) {
Duplet edge(face[j], face[(j+1)%num_vertex_per_face]);
edges.insert(edge);
}
}
for (auto edge : edges) {
const auto& data = edge.get_ori_data();
vertex_valance[data[0]] ++;
vertex_valance[data[1]] ++;
}
}
void VertexValanceAttribute::compute_from_tet_mesh(Mesh& mesh) {
const size_t num_vertices = mesh.get_num_vertices();
const size_t num_voxels = mesh.get_num_voxels();
const size_t num_vertex_per_voxel = mesh.get_vertex_per_voxel();
assert(num_vertex_per_voxel == 4);
VectorF& vertex_valance = m_values;
vertex_valance = VectorF::Zero(num_vertices);
std::set<Duplet> edges;
for (size_t i=0; i<num_voxels; i++) {
VectorI voxel = mesh.get_voxel(i);
Duplet edge[6] = {
{voxel[0], voxel[1]},
{voxel[0], voxel[2]},
{voxel[0], voxel[3]},
{voxel[1], voxel[2]},
{voxel[1], voxel[3]},
{voxel[2], voxel[3]} };
edges.insert(edge[0]);
edges.insert(edge[1]);
edges.insert(edge[2]);
edges.insert(edge[3]);
edges.insert(edge[4]);
edges.insert(edge[5]);
}
for (auto edge : edges) {
const auto& data = edge.get_ori_data();
vertex_valance[data[0]] ++;
vertex_valance[data[1]] ++;
}
}
void VertexValanceAttribute::compute_from_hex_mesh(Mesh& mesh) {
const size_t num_vertices = mesh.get_num_vertices();
const size_t num_voxels = mesh.get_num_voxels();
const size_t num_vertex_per_voxel = mesh.get_vertex_per_voxel();
assert(num_vertex_per_voxel == 8);
// Vertex ordering
// 3 _________ 2
// /: /|
// 7/ : / |
// +--------+6 |
// | : | |
// | 0:.....|..|1
// | ; | /
// +--------+/
// 4 5
VectorF& vertex_valance = m_values;
vertex_valance = VectorF::Zero(num_vertices);
std::set<Duplet> edges;
for (size_t i=0; i<num_voxels; i++) {
VectorI voxel = mesh.get_voxel(i);
Duplet edge[12] = {
{voxel[0], voxel[1]},
{voxel[1], voxel[2]},
{voxel[2], voxel[3]},
{voxel[3], voxel[0]},
{voxel[4], voxel[5]},
{voxel[5], voxel[6]},
{voxel[6], voxel[7]},
{voxel[7], voxel[4]},
{voxel[0], voxel[4]},
{voxel[1], voxel[5]},
{voxel[2], voxel[6]},
{voxel[3], voxel[7]} };
edges.insert(edge[0]);
edges.insert(edge[1]);
edges.insert(edge[2]);
edges.insert(edge[3]);
edges.insert(edge[4]);
edges.insert(edge[5]);
edges.insert(edge[6]);
edges.insert(edge[7]);
edges.insert(edge[8]);
edges.insert(edge[9]);
edges.insert(edge[10]);
edges.insert(edge[11]);
}
for (auto edge : edges) {
const auto& data = edge.get_ori_data();
vertex_valance[data[0]] ++;
vertex_valance[data[1]] ++;
}
}