Commit 0c643f6a authored by Jan Möbius's avatar Jan Möbius

Merge branch 'feature-int-histograms' into 'master'

Feature int histograms (includes refactoring)

See merge request !19
parents ea397e7e e97c5c6c
......@@ -61,6 +61,8 @@ OMPropertyVisualizerInteger<MeshT, T>::OMPropertyVisualizerInteger(MeshT* _mesh,
w->intAbsolute->setChecked(false); //because we already have unsigned integers wo don't have to calculate their absolute value
w->intAbsolute->setCheckable(false);
}
this->connect(w->computeHistogramButton, &QPushButton::clicked,
[this, w](){this->template showHistogram<T>(w->histogram);});
}
template <typename MeshT,typename T>
......
......@@ -162,7 +162,7 @@ template <Template> \
void Classname::visualizeCellProp(bool _setDrawMode) \
{\
OpenVolumeMesh::CellPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->cells_begin(), OVMPropertyVisualizer<MeshT>::mesh->cells_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->cells());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......@@ -174,7 +174,7 @@ template <Template>\
void Classname::visualizeFaceProp(bool _setDrawMode)\
{\
OpenVolumeMesh::FacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->faces_begin(), OVMPropertyVisualizer<MeshT>::mesh->faces_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->faces());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......@@ -186,7 +186,7 @@ template <Template>\
void Classname::visualizeHalffaceProp(bool _setDrawMode)\
{\
OpenVolumeMesh::HalfFacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin(), OVMPropertyVisualizer<MeshT>::mesh->halffaces_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halffaces());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......@@ -198,7 +198,7 @@ template <Template>\
void Classname::visualizeEdgeProp(bool _setDrawMode)\
{\
OpenVolumeMesh::EdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->edges_begin(), OVMPropertyVisualizer<MeshT>::mesh->edges_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->edges());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......@@ -210,7 +210,7 @@ template <Template>\
void Classname::visualizeHalfedgeProp(bool _setDrawMode)\
{\
OpenVolumeMesh::HalfEdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin(), OVMPropertyVisualizer<MeshT>::mesh->halfedges_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halfedges());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......@@ -222,7 +222,7 @@ template <Template>\
void Classname::visualizeVertexProp(bool _setDrawMode)\
{\
OpenVolumeMesh::VertexPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->vertices_begin(), OVMPropertyVisualizer<MeshT>::mesh->vertices_end());\
visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->vertices());\
if (_setDrawMode)\
{\
VolumeMeshObject<MeshT>* object;\
......
......@@ -59,8 +59,8 @@ public:
protected:
template <typename PropType, typename EntityIterator>
void visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end);
template <typename PropType, typename HandleIterable>
void visualizeProp(PropType prop, HandleIterable handles);
void duplicateProperty() override;
void visualizeFaceProp(bool _setDrawMode = true) override;
......
......@@ -59,8 +59,8 @@ OVMPropertyVisualizerBoolean<MeshT>::OVMPropertyVisualizerBoolean(MeshT* _mesh,
}
template <typename MeshT>
template <typename PropType, typename EntityIterator>
void OVMPropertyVisualizerBoolean<MeshT>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
template <typename PropType, typename HandleIterable>
void OVMPropertyVisualizerBoolean<MeshT>::visualizeProp(PropType prop, HandleIterable handles)
{
if (!prop)
return;
......@@ -74,11 +74,11 @@ void OVMPropertyVisualizerBoolean<MeshT>::visualizeProp(PropType prop, EntityIte
VolumeMeshObject<MeshT>* object;
PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
for (EntityIterator e_it = e_begin ; e_it != e_end; ++e_it)
if ( prop[*e_it] )
object->colors()[*e_it] = colorTrue;
for (const auto &h: handles)
if ( prop[h] )
object->colors()[h] = colorTrue;
else
object->colors()[*e_it] = colorFalse;
object->colors()[h] = colorFalse;
}
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerBoolean<MeshT>, typename MeshT, bool)
......
......@@ -63,8 +63,8 @@ public:
virtual ~OVMPropertyVisualizerDouble(){}
protected:
template <typename PropType, typename EntityIterator>
void visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end);
template <typename PropType, typename HandleIterable>
void visualizeProp(PropType prop, HandleIterable handles);
void duplicateProperty() override;
void visualizeFaceProp(bool _setDrawMode = true) override;
......
......@@ -66,37 +66,31 @@ OVMPropertyVisualizerDouble<MeshT>::OVMPropertyVisualizerDouble(MeshT* _mesh, in
}
template <typename MeshT>
template <typename PropType, typename EntityIterator>
void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
template <typename PropType, typename HandleIterable>
void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, HandleIterable handles)
{
using Handle = decltype(*begin(handles));
if (!prop) return;
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
ACG::Vec4f colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
auto cc = doubleWidget->buildColorCoder();
double min, max;
if ( doubleWidget->doubleAbsolute->isChecked() ){
min = FLT_MAX;
max = 0.0;
} else {
min = FLT_MAX;
max = FLT_MIN;
}
for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it){
double value = prop[*e_it];
if ( doubleWidget->doubleAbsolute->isChecked() ){
min = std::min( min, fabs(value));
max = std::max( max, fabs(value));
bool abs = doubleWidget->doubleAbsolute->isChecked();
auto transform_value = [abs](double v) {
if (abs) {
return std::fabs(v);
} else {
min = std::min( min, value);
max = std::max( max, value);
}
}
return v;
};
};
auto get_value = [&](Handle handle)
{
return transform_value(prop[handle]);
};
// fixed range?
double min, max;
if( doubleWidget->doubleFixedRange->isChecked())
{
min = doubleWidget->doubleFixedRangeMin->value();
......@@ -104,6 +98,13 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
}
else
{
min = std::numeric_limits<double>::infinity();
max = -std::numeric_limits<double>::infinity();
for (const Handle &h: handles) {
auto value = get_value(h);
min = std::min(min, value);
max = std::max(max, value);
}
doubleWidget->doubleFixedRangeMin->setValue(min);
doubleWidget->doubleFixedRangeMax->setValue(max);
}
......@@ -112,21 +113,11 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
VolumeMeshObject<MeshT>* object;
PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it){
if (range == 0.0)
object->colors()[*e_it] = colorMin;
else {
double value = prop[*e_it];
// absolut value?
if ( doubleWidget->doubleAbsolute->isChecked())
value = fabs(value);
double t = (value-min)/range;
object->colors()[*e_it] = cc->color_float4(t);
}
for (const Handle &h: handles)
{
double value = get_value(h);
double t = (value - min) / range;
object->colors()[h] = cc->color_float4(t);
}
}
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble<MeshT>, typename MeshT, double)
......
......@@ -61,8 +61,8 @@ public:
virtual ~OVMPropertyVisualizerInteger(){}
protected:
template <typename PropType, typename EntityIterator>
void visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end);
template <typename PropType, typename HandleIterable>
void visualizeProp(PropType prop, HandleIterable handles);
void duplicateProperty() override;
void visualizeFaceProp(bool _setDrawMode = true) override;
......
......@@ -66,11 +66,14 @@ OVMPropertyVisualizerInteger<MeshT,T>::OVMPropertyVisualizerInteger(MeshT* _mesh
mNumericLimitMax = std::numeric_limits<T>::max();
mNumericLimitMin = std::numeric_limits<T>::min();
this->connect(w->computeHistogramButton, &QPushButton::clicked,
[this, w](){this->template showHistogram<T>(w->histogram);});
}
template <typename MeshT, typename T>
template <typename PropType, typename EntityIterator>
void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
template <typename PropType, typename HandleIterable>
void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, HandleIterable handles)
{
if (!prop) return;
......@@ -86,9 +89,9 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
T min = mNumericLimitMax;
T max = mNumericLimitMin;
for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
for (const auto &h: handles)
{
T value = prop[*e_it];
T value = prop[h];
min = std::min( min, value);
max = std::max( max, value);
}
......@@ -110,12 +113,12 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
VolumeMeshObject<MeshT>* object;
PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
for (const auto &h: handles)
{
if (range == 0)
object->colors()[*e_it] = colorMin;
object->colors()[h] = colorMin;
else {
T value = prop[*e_it];
T value = prop[h];
double pos = (value - min) / (double) range;
ACG::Vec4f color;
if ( integerWidget->intRandom->isChecked() )
......@@ -134,7 +137,7 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
color = cc->color_float4(pos);
}
object->colors()[*e_it] = color;
object->colors()[h] = color;
}
}
}
......
......@@ -403,7 +403,8 @@ void OVMPropertyVisualizer<MeshT>::setVertexPropertyFromText(unsigned int /*inde
template<typename MeshT>
template<typename Type>
void OVMPropertyVisualizer<MeshT>::showHistogram(ACG::QtWidgets::QtHistogramWidget *histogramWidget) {
void OVMPropertyVisualizer<MeshT>::showHistogram(ACG::QtWidgets::QtHistogramWidget *histogramWidget)
{
using PV = OVMPropertyVisualizer<MeshT>;
const std::string &prop_name = PV::propertyInfo.propName();
......
......@@ -161,5 +161,5 @@ OpenMesh::Vec2f PropertyVisualizer::strToVec2f (QString str)
std::unique_ptr<ACG::IColorCoder> PropertyVisualizer::buildColorCoder()
{
throw std::runtime_error("Requested color coder on a Propvis that does not implement it");
return nullptr;
}
......@@ -193,10 +193,9 @@ void PropertyVisualizer::showHistogramT(
ACG::QtWidgets::QtHistogramWidget *widget,
Iterable data)
{
const size_t max_bins = 50; // TODO: expose in GUI?
widget->setMinimumHeight(300);
widget->setColorCoder(buildColorCoder());
widget->setHistogram(ptr::make_unique<ACG::HistogramT<PropType>>(data.begin(), data.end(), max_bins));
widget->setHistogram(ACG::create_histogram_auto(data));
}
#endif /* PROPERTY_VISUALIZER_HH */
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>243</height>
<width>443</width>
<height>566</height>
</rect>
</property>
<property name="windowTitle">
......@@ -17,7 +17,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
......@@ -164,6 +173,35 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="histogramGroupbox">
<property name="title">
<string>Histogram</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="computeHistogramButton">
<property name="text">
<string>Compute Histogram</string>
</property>
</widget>
</item>
<item>
<widget class="ACG::QtWidgets::QtHistogramWidget" name="histogram" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -175,6 +213,12 @@
<extends>QPushButton</extends>
<header>ACG/QtWidgets/QtColorChooserButton.hh</header>
</customwidget>
<customwidget>
<class>ACG::QtWidgets::QtHistogramWidget</class>
<extends>QWidget</extends>
<header>ACG/QtWidgets/QtHistogramWidget.hh</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>intFixedRange</tabstop>
......
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