8 #include "ValenceHistogramDialog.hh" 10 #include <ACG/Utils/SmartPointer.hh> 12 ValenceHistogramDialog::ValenceHistogramDialog(TriMesh &mesh, QWidget *parent)
18 ValenceHistogramDialog::ValenceHistogramDialog(PolyMesh &mesh, QWidget *parent)
24 static void fillHistogramTable(std::vector<size_t> &hist, QTableWidget &tw) {
27 std::vector<size_t>::iterator nonzero_begin = hist.begin();
28 for (; nonzero_begin != hist.end() && *nonzero_begin == 0;
30 if (nonzero_begin == hist.end())
return;
32 std::vector<size_t>::iterator nonzero_end = hist.end();
33 for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
36 const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
37 const size_t ofs = std::distance(hist.begin(), nonzero_begin);
40 tw.setColumnCount(hist_size);
43 vheaders.push_back(QString::fromUtf8(
"Count"));
44 tw.setVerticalHeaderLabels(vheaders);
47 for (std::vector<size_t>::iterator it = nonzero_begin;
48 it != nonzero_end; ++it, ++i) {
50 hheaders.push_back(QString::number(ofs + i));
51 tw.setItem(0, i,
new QTableWidgetItem(QString::number(*it)));
53 tw.setHorizontalHeaderLabels(hheaders);
60 explicit ValenceHistogram(
const std::vector<size_t> &bins)
62 std::vector<size_t>::const_iterator nonzero_begin = bins.begin();
63 for (; nonzero_begin != bins.end() && *nonzero_begin == 0;
65 if (nonzero_begin == bins.end())
return;
67 std::vector<size_t>::const_iterator nonzero_end = bins.end();
68 for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
71 ofs_ = std::distance(bins.begin(), nonzero_begin);
72 bins_.assign(nonzero_begin, nonzero_end);
73 bin_widths_.assign(bins_.size() + 1, 1);
76 LabelType getLabelType()
const override 78 return LabelType::PerBin;
81 QString getBinLabel (
size_t idx)
const override 83 return QString::number(ofs_ + idx);
86 double getTotalWidth()
const override {
96 void ValenceHistogramDialog::init(MeshT &mesh) {
100 vertex_valence_hist.clear();
101 for (
typename MeshT::VertexIter v_it = mesh.vertices_begin(),
102 v_end = mesh.vertices_end(); v_it != v_end; ++v_it) {
103 size_t valence = mesh.valence(*v_it);
104 if (vertex_valence_hist.size() <= valence) {
105 vertex_valence_hist.resize(valence + 1, 0);
107 vertex_valence_hist[valence] += 1;
109 vertexValenceChart_wdgt->setHistogram(ptr::make_unique<ValenceHistogram>(vertex_valence_hist));
110 fillHistogramTable(vertex_valence_hist, *vertexValence_tw);
115 face_valence_hist.clear();
116 for (
typename MeshT::FaceIter f_it = mesh.faces_begin(),
117 f_end = mesh.faces_end(); f_it != f_end; ++f_it) {
118 size_t valence = mesh.valence(*f_it);
119 if (face_valence_hist.size() <= valence) {
120 face_valence_hist.resize(
123 face_valence_hist[valence] += 1;
126 faceValenceChart_wdgt->setHistogram(ptr::make_unique<ValenceHistogram>(face_valence_hist));
127 fillHistogramTable(face_valence_hist, *faceValence_tw);