Commit 4302afd4 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Added a sub-dialog with vertex and face valence histograms.

parent 3c618ac0
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
#include <Math_Tools/Math_Tools.hh> #include <Math_Tools/Math_Tools.hh>
#include "ValenceHistogramDialog.hh"
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#else #else
#include <QtGui> #include <QtGui>
...@@ -73,7 +75,9 @@ ...@@ -73,7 +75,9 @@
InfoMeshObjectPlugin::InfoMeshObjectPlugin() : InfoMeshObjectPlugin::InfoMeshObjectPlugin() :
info_(0), info_(0),
infoBar_(0) infoBar_(0),
lastPickedObject_(0),
lastPickedObjectId_(-1)
{ {
} }
...@@ -101,6 +105,9 @@ void InfoMeshObjectPlugin::pluginsInitialized() { ...@@ -101,6 +105,9 @@ void InfoMeshObjectPlugin::pluginsInitialized() {
// Create info dialog // Create info dialog
info_ = new InfoDialog(); info_ = new InfoDialog();
connect(info_->valenceHistograms_pb, SIGNAL( clicked() ),
this, SLOT( slotShowHistogram() ));
// Set default pick mode in dialog box // Set default pick mode in dialog box
info_->pickMode->setCurrentIndex(0); // PICK_FACES info_->pickMode->setCurrentIndex(0); // PICK_FACES
...@@ -742,12 +749,18 @@ InfoMeshObjectPlugin:: ...@@ -742,12 +749,18 @@ InfoMeshObjectPlugin::
emit log( LOGINFO , object->getObjectinfo() ); emit log( LOGINFO , object->getObjectinfo() );
lastPickedObject_ = object;
lastPickedObjectId_ = object->id();
if ( object->dataType(DATA_TRIANGLE_MESH) ) if ( object->dataType(DATA_TRIANGLE_MESH) )
printMeshInfo( PluginFunctions::triMesh(object) , object->id(), target_idx, hit_point ); printMeshInfo( PluginFunctions::triMesh(object) , object->id(), target_idx, hit_point );
if ( object->dataType(DATA_POLY_MESH) ) if ( object->dataType(DATA_POLY_MESH) )
printMeshInfo( PluginFunctions::polyMesh(object) , object->id(), target_idx, hit_point ); printMeshInfo( PluginFunctions::polyMesh(object) , object->id(), target_idx, hit_point );
} else return; } else {
lastPickedObject_ = 0;
return;
}
} }
else else
{ {
...@@ -828,6 +841,11 @@ void InfoMeshObjectPlugin::updateData( int _identifier , const UpdateType& _type ...@@ -828,6 +841,11 @@ void InfoMeshObjectPlugin::updateData( int _identifier , const UpdateType& _type
BaseObjectData* object; BaseObjectData* object;
PluginFunctions::getObject(_identifier,object); PluginFunctions::getObject(_identifier,object);
if (_identifier == lastPickedObjectId_ && _deleted) {
lastPickedObject_ = 0;
lastPickedObjectId_ = -1;
}
// Last object that is target has been removed. // Last object that is target has been removed.
if ( _deleted && object && object->target() && (PluginFunctions::targetCount() == 1) ) { if ( _deleted && object && object->target() && (PluginFunctions::targetCount() == 1) ) {
infoBar_->hideCounts(); infoBar_->hideCounts();
...@@ -927,6 +945,29 @@ void InfoMeshObjectPlugin::slotAllCleared(){ ...@@ -927,6 +945,29 @@ void InfoMeshObjectPlugin::slotAllCleared(){
} }
void InfoMeshObjectPlugin::slotShowHistogram() {
if (!lastPickedObject_) return;
ValenceHistogramDialog *dialog = 0;
{
TriMeshObject *tmo = dynamic_cast<TriMeshObject*>(lastPickedObject_);
if (tmo) {
dialog = new ValenceHistogramDialog(*tmo->mesh(), info_);
}
}
if (!dialog) {
PolyMeshObject *pmo = dynamic_cast<PolyMeshObject*>(lastPickedObject_);
if (pmo) {
dialog = new ValenceHistogramDialog(*pmo->mesh(), info_);
}
}
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->show();
dialog->raise();
}
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( InfoMeshObjectPlugin , InfoMeshObjectPlugin ); Q_EXPORT_PLUGIN2( InfoMeshObjectPlugin , InfoMeshObjectPlugin );
#endif #endif
......
...@@ -123,6 +123,8 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface ...@@ -123,6 +123,8 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface
void slotInformationRequested(const QPoint _clickedPoint, DataType _type); void slotInformationRequested(const QPoint _clickedPoint, DataType _type);
DataType supportedDataTypes(); DataType supportedDataTypes();
void slotShowHistogram();
public : public :
// default constructor // default constructor
...@@ -221,6 +223,9 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface ...@@ -221,6 +223,9 @@ class InfoMeshObjectPlugin : public QObject, BaseInterface, InformationInterface
/** @} */ /** @} */
private:
BaseObjectData *lastPickedObject_;
int lastPickedObjectId_;
}; };
#endif //MOVEPLUGIN_HH #endif //MOVEPLUGIN_HH
......
/*
* ValenceHistogramDialog.cc
*
* Created on: Jan 27, 2016
* Author: hc
*/
#include "ValenceHistogramDialog.hh"
ValenceHistogramDialog::ValenceHistogramDialog(TriMesh &mesh, QWidget *parent)
: QDialog(parent) {
setupUi(this);
init(mesh);
}
ValenceHistogramDialog::ValenceHistogramDialog(PolyMesh &mesh, QWidget *parent)
: QDialog(parent) {
init(mesh);
setupUi(this);
}
static void fillHistogramTable(std::vector<size_t> &hist, QTableWidget &tw) {
tw.clear();
std::vector<size_t>::iterator nonzero_begin = hist.begin();
for (; nonzero_begin != hist.end() && *nonzero_begin == 0;
++nonzero_begin);
if (nonzero_begin == hist.end()) return;
std::vector<size_t>::iterator nonzero_end = hist.end();
for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
--nonzero_end);
const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
const size_t ofs = std::distance(hist.begin(), nonzero_begin);
tw.setRowCount(1);
tw.setColumnCount(hist_size);
QStringList vheaders;
vheaders.push_back(QString::fromUtf8("Count"));
tw.setVerticalHeaderLabels(vheaders);
int i = 0;
QStringList hheaders;
for (std::vector<size_t>::iterator it = nonzero_begin;
it != nonzero_end; ++it, ++i) {
//tw.setItem(0, i, new QTableWidgetItem(QString::number(ofs + i)));
hheaders.push_back(QString::number(ofs + i));
tw.setItem(0, i, new QTableWidgetItem(QString::number(*it)));
}
tw.setHorizontalHeaderLabels(hheaders);
}
template<class MeshT>
void ValenceHistogramDialog::init(MeshT &mesh) {
/*
* Vertices
*/
vertex_valence_hist.clear();
for (TriMesh::VertexIter v_it = mesh.vertices_begin(),
v_end = mesh.vertices_end(); v_it != v_end; ++v_it) {
size_t valence = mesh.valence(*v_it);
if (vertex_valence_hist.size() <= valence) {
vertex_valence_hist.resize(valence + 1, 0);
}
vertex_valence_hist[valence] += 1;
}
vertexValenceChart_wdgt->setHistogram(&vertex_valence_hist);
fillHistogramTable(vertex_valence_hist, *vertexValence_tw);
/*
* Faces
*/
face_valence_hist.clear();
for (TriMesh::FaceIter f_it = mesh.faces_begin(),
f_end = mesh.faces_end(); f_it != f_end; ++f_it) {
size_t valence = mesh.valence(*f_it);
if (face_valence_hist.size() <= valence) {
face_valence_hist.resize(
valence - face_valence_hist.size() + 1, 0);
}
++face_valence_hist[valence];
}
faceValenceChart_wdgt->setHistogram(&face_valence_hist);
fillHistogramTable(face_valence_hist, *faceValence_tw);
}
/*
* ValenceHistogramDialog.hh
*
* Created on: Jan 27, 2016
* Author: hc
*/
#ifndef PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMDIALOG_HH_
#define PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMDIALOG_HH_
#include "ui_infoValenceHistograms.hh"
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
#include <ObjectTypes/PolyMesh/PolyMeshTypes.hh>
#include <ObjectTypes/TriangleMesh/TriangleMeshTypes.hh>
class ValenceHistogramDialog: public QDialog, public Ui::ValenceHistogramsDlg {
Q_OBJECT
public:
ValenceHistogramDialog(TriMesh &mesh, QWidget *parent = 0);
ValenceHistogramDialog(PolyMesh &mesh, QWidget *parent = 0);
template<class MeshT> void init(MeshT &mesh);
private:
std::vector<size_t> vertex_valence_hist, face_valence_hist;
};
#endif /* PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMDIALOG_HH_ */
/*
* ValenceHistogramWidget.cc
*
* Created on: Jan 27, 2016
* Author: hc
*/
#include "ValenceHistogramWidget.hh"
#include <QPainter>
#include <iostream>
ValenceHistogramWidget::ValenceHistogramWidget(QWidget *parent) :
histogram_(0) {
}
void ValenceHistogramWidget::paintEvent(QPaintEvent *event) {
if (!histogram_) {
QWidget::paintEvent(event);
return;
}
/*
* Analyze histogram/
*/
std::vector<size_t>::iterator nonzero_begin = histogram_->begin();
for (; nonzero_begin != histogram_->end() && *nonzero_begin == 0;
++nonzero_begin);
if (nonzero_begin == histogram_->end()) return;
std::vector<size_t>::iterator nonzero_end = histogram_->end();
for (; (nonzero_end-1) != nonzero_begin && *(nonzero_end-1) == 0;
--nonzero_end);
const size_t hist_size = std::distance(nonzero_begin, nonzero_end);
const size_t hist_max = *std::max_element(nonzero_begin, nonzero_end);
const size_t ofs = std::distance(histogram_->begin(), nonzero_begin);
/*
* Establish regions
*/
QRectF paint_rect = this->contentsRect();
QRectF bargraph_rect = paint_rect;
bargraph_rect.setBottom(bargraph_rect.bottom() - 16);
QRectF label_rect = paint_rect;
label_rect.setTop(bargraph_rect.bottom());
QPainter painter(this);
/*
* Painter attributes.
*/
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(QColor::fromRgbF(0.518, 0.573, 0.643, 1.0));
painter.setFont(this->font());
const qreal stride =
static_cast<qreal>(bargraph_rect.width()) / hist_size;
const qreal gap = (stride > 8) ? 1.0 : 0.0;
const qreal label_gap = 4;
QRectF barRect(0, 0, stride - gap, 0);
const qreal scale = static_cast<qreal>(bargraph_rect.height()) / hist_max;
/*
* Draw.
*/
int cnt = 0;
qreal lastLabelX = label_rect.left();
for (std::vector<size_t>::iterator it = nonzero_begin;
it != nonzero_end; ++it, ++cnt) {
// Bar
painter.setPen(Qt::NoPen);
barRect.setHeight(scale * (*it));
barRect.moveBottomLeft(
bargraph_rect.bottomLeft() + QPoint(stride * cnt, 0));
if (gap > 0.0)
painter.drawRoundedRect(barRect, 3, 3, Qt::AbsoluteSize);
else
painter.drawRect(barRect);
// Label
painter.setPen(Qt::black);
QString labelText = QString::number(cnt + ofs);
QRectF labelBB =
painter.boundingRect(
QRectF(barRect.center().x()-50, label_rect.y(),
100.0, label_rect.height()),
Qt::AlignHCenter | Qt::AlignBottom, labelText);
if (labelBB.left() >= lastLabelX + label_gap) {
painter.drawText(labelBB, Qt::AlignHCenter | Qt::AlignBottom,
labelText);
lastLabelX = labelBB.right();
}
}
}
void ValenceHistogramWidget::setHistogram(std::vector<size_t> *histogram) {
histogram_ = histogram;
this->update();
}
/*
* ValenceHistogramWidget.hh
*
* Created on: Jan 27, 2016
* Author: hc
*/
#ifndef PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMWIDGET_HH_
#define PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMWIDGET_HH_
#include <QWidget>
class ValenceHistogramWidget: public QWidget {
Q_OBJECT
public:
ValenceHistogramWidget(QWidget *parent);
void setHistogram(std::vector<size_t> *histogram);
protected:
void paintEvent(QPaintEvent *event);
std::vector<size_t> *histogram_;
};
#endif /* PLUGIN_INFOMESHOBJECT_VALENCEHISTOGRAMWIDGET_HH_ */
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ValenceHistogramsDlg</class>
<widget class="QDialog" name="ValenceHistogramsDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
<string>Valence Histograms</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="gfx_tab">
<attribute name="title">
<string>Diagrams</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Vertex Valences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="ValenceHistogramWidget" name="vertexValenceChart_wdgt" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Face Valences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="ValenceHistogramWidget" name="faceValenceChart_wdgt" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="txt_tab">
<attribute name="title">
<string>Tabular</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Vertex Valences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QTableWidget" name="vertexValence_tw"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Face Valences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QTableWidget" name="faceValence_tw"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ValenceHistogramWidget</class>
<extends>QWidget</extends>
<header>ValenceHistogramWidget.hh</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>ValenceHistogramsDlg</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>596</x>
<y>678</y>
</hint>
<hint type="destinationlabel">
<x>540</x>
<y>1</y>
</hint>
</hints>
</connection>
</connections>
</ui>
...@@ -7,15 +7,9 @@ ...@@ -7,15 +7,9 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>750</width> <width>750</width>
<height>620</height> <height>800</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Object Information</string> <string>Object Information</string>
</property> </property>
...@@ -34,7 +28,7 @@ ...@@ -34,7 +28,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>714</width> <width>714</width>
<height>1048</height> <height>1037</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
...@@ -58,6 +52,9 @@ ...@@ -58,6 +52,9 @@
<layout class="QFormLayout" name="formLayout_4"> <layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="font"> <property name="font">
...@@ -1820,6 +1817,13 @@ ...@@ -1820,6 +1817,13 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="valenceHistograms_pb">
<property name="text">
<string>Compute Valence Histograms</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
...@@ -1838,6 +1842,9 @@ ...@@ -1838,6 +1842,9 @@
<property name="text"> <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
<property name="default">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
...@@ -1855,8 +1862,8 @@ ...@@ -1855,8 +1862,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>493</x> <x>742</x>
<y>627</y> <y>792</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>422</x> <x>422</x>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment