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

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