8 #include "ValenceHistogramDialog.hh" 11 ValenceHistogramDialog::ValenceHistogramDialog(TriMesh &mesh, QWidget *parent)
17 ValenceHistogramDialog::ValenceHistogramDialog(PolyMesh &mesh, QWidget *parent)
23 static void fillHistogramTable(std::vector<size_t> &hist, QTableWidget &tw) {
26 std::vector<size_t>::iterator nonzero_begin = hist.begin();
27 for (; nonzero_begin != hist.end() && *nonzero_begin == 0;
29 if (nonzero_begin == hist.end())
return;
31 std::vector<size_t>::iterator nonzero_end = hist.end();
32 for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
35 const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
36 const size_t ofs = std::distance(hist.begin(), nonzero_begin);
39 tw.setColumnCount(hist_size);
42 vheaders.push_back(QString::fromUtf8(
"Count"));
43 tw.setVerticalHeaderLabels(vheaders);
46 for (std::vector<size_t>::iterator it = nonzero_begin;
47 it != nonzero_end; ++it, ++i) {
49 hheaders.push_back(QString::number(ofs + i));
50 tw.setItem(0, i,
new QTableWidgetItem(QString::number(*it)));
52 tw.setHorizontalHeaderLabels(hheaders);
56 void ValenceHistogramDialog::init(MeshT &mesh) {
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);
67 vertex_valence_hist[valence] += 1;
69 vertexValenceChart_wdgt->setHistogram(&vertex_valence_hist);
70 fillHistogramTable(vertex_valence_hist, *vertexValence_tw);
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(
83 face_valence_hist[valence] += 1;
86 faceValenceChart_wdgt->setHistogram(&face_valence_hist);
87 fillHistogramTable(face_valence_hist, *faceValence_tw);