Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ValenceHistogramDialog.cc
1 /*
2 * ValenceHistogramDialog.cc
3 *
4 * Created on: Jan 27, 2016
5 * Author: hc
6 */
7
8 #include "ValenceHistogramDialog.hh"
9
10
11 ValenceHistogramDialog::ValenceHistogramDialog(TriMesh &mesh, QWidget *parent)
12 : QDialog(parent) {
13 setupUi(this);
14 init(mesh);
15 }
16
17 ValenceHistogramDialog::ValenceHistogramDialog(PolyMesh &mesh, QWidget *parent)
18 : QDialog(parent) {
19 setupUi(this);
20 init(mesh);
21 }
22
23 static void fillHistogramTable(std::vector<size_t> &hist, QTableWidget &tw) {
24 tw.clear();
25
26 std::vector<size_t>::iterator nonzero_begin = hist.begin();
27 for (; nonzero_begin != hist.end() && *nonzero_begin == 0;
28 ++nonzero_begin);
29 if (nonzero_begin == hist.end()) return;
30
31 std::vector<size_t>::iterator nonzero_end = hist.end();
32 for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
33 --nonzero_end);
34
35 const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
36 const size_t ofs = std::distance(hist.begin(), nonzero_begin);
37
38 tw.setRowCount(1);
39 tw.setColumnCount(hist_size);
40
41 QStringList vheaders;
42 vheaders.push_back(QString::fromUtf8("Count"));
43 tw.setVerticalHeaderLabels(vheaders);
44 int i = 0;
45 QStringList hheaders;
46 for (std::vector<size_t>::iterator it = nonzero_begin;
47 it != nonzero_end; ++it, ++i) {
48 //tw.setItem(0, i, new QTableWidgetItem(QString::number(ofs + i)));
49 hheaders.push_back(QString::number(ofs + i));
50 tw.setItem(0, i, new QTableWidgetItem(QString::number(*it)));
51 }
52 tw.setHorizontalHeaderLabels(hheaders);
53 }
54
55 template<class MeshT>
56 void ValenceHistogramDialog::init(MeshT &mesh) {
57 /*
58 * Vertices
59 */
60 vertex_valence_hist.clear();
61 for (typename MeshT::VertexIter v_it = mesh.vertices_begin(),
62 v_end = mesh.vertices_end(); v_it != v_end; ++v_it) {
63 size_t valence = mesh.valence(*v_it);
64 if (vertex_valence_hist.size() <= valence) {
65 vertex_valence_hist.resize(valence + 1, 0);
66 }
67 vertex_valence_hist[valence] += 1;
68 }
69 vertexValenceChart_wdgt->setHistogram(&vertex_valence_hist);
70 fillHistogramTable(vertex_valence_hist, *vertexValence_tw);
71
72 /*
73 * Faces
74 */
75 face_valence_hist.clear();
76 for (typename MeshT::FaceIter f_it = mesh.faces_begin(),
77 f_end = mesh.faces_end(); f_it != f_end; ++f_it) {
78 size_t valence = mesh.valence(*f_it);
79 if (face_valence_hist.size() <= valence) {
80 face_valence_hist.resize(
81 valence + 1, 0);
82 }
83 face_valence_hist[valence] += 1;
84 }
85
86 faceValenceChart_wdgt->setHistogram(&face_valence_hist);
87 fillHistogramTable(face_valence_hist, *faceValence_tw);
88 }