Commit 1b86f07e authored by Martin Heistermann's avatar Martin Heistermann

Propvis histograms: use unique_ptr where possible.

parent bd79ca9a
......@@ -58,8 +58,7 @@
#include <ACG/Utils/ColorCoder.hh>
#include <memory>
#include <iostream>
template <typename MeshT>
......@@ -85,7 +84,7 @@ protected:
virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
virtual void setVertexPropertyFromText(unsigned int index, QString text);
ACG::IColorCoder *buildColorCoder() override;
std::unique_ptr<ACG::IColorCoder> buildColorCoder() override;
};
......
......@@ -73,7 +73,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeFaceProp(bool _setDrawMode)
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
auto cc = doubleWidget->buildColorCoder();
OpenMesh::FPropHandleT< double > prop;
......@@ -140,7 +140,6 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeFaceProp(bool _setDrawMode)
OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);
......@@ -155,7 +154,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeEdgeProp(bool _setDrawMode)
colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
auto cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::EPropHandleT< double > prop;
......@@ -224,7 +223,6 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeEdgeProp(bool _setDrawMode)
OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::EDGES_COLORED);
......@@ -239,7 +237,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
auto cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::HPropHandleT< double > prop;
......@@ -319,7 +317,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeVertexProp(bool _setDrawMode)
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
auto cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::VPropHandleT< double > prop;
......@@ -453,7 +451,7 @@ void OMPropertyVisualizerDouble<MeshT>::setVertexPropertyFromText(unsigned int i
}
template<typename MeshT>
ACG::IColorCoder *OMPropertyVisualizerDouble<MeshT>::buildColorCoder()
std::unique_ptr<ACG::IColorCoder> OMPropertyVisualizerDouble<MeshT>::buildColorCoder()
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
return doubleWidget->buildColorCoder();
......
......@@ -81,7 +81,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeFaceProp(bool _setDrawMode)
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
auto cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -146,7 +146,6 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeFaceProp(bool _setDrawMode)
OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);
......@@ -158,7 +157,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeEdgeProp(bool _setDrawMode)
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
auto cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -235,7 +234,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeHalfedgeProp(bool _setDrawM
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
auto cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -311,7 +310,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeVertexProp(bool _setDrawMod
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
auto cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......
......@@ -60,6 +60,7 @@
#include <ACG/Utils/IColorCoder.hh>
#include <memory>
#include <iostream>
template <typename MeshT>
......@@ -90,7 +91,7 @@ protected:
virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
virtual void setVertexPropertyFromText(unsigned int index, QString text);
ACG::IColorCoder *buildColorCoder() override;
std::unique_ptr<ACG::IColorCoder> buildColorCoder() override;
};
#if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_VISUALIZER_DOUBLE_CC)
......
......@@ -82,7 +82,7 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
ACG::Vec4f colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
auto cc = doubleWidget->buildColorCoder();
double min, max;
if ( doubleWidget->doubleAbsolute->isChecked() ){
......@@ -149,7 +149,6 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
object->colors()[*e_it] = color;
}
}
delete cc;
}
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble<MeshT>, typename MeshT, double)
......@@ -268,7 +267,7 @@ void OVMPropertyVisualizerDouble<MeshT>::setVertexPropertyFromText(unsigned int
}
template <typename MeshT>
ACG::IColorCoder *OVMPropertyVisualizerDouble<MeshT>::buildColorCoder()
std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerDouble<MeshT>::buildColorCoder()
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
return doubleWidget->buildColorCoder();
......
......@@ -59,6 +59,7 @@
#include <ACG/Utils/HuePartitioningColors.hh>
#include <iostream>
#include <memory>
template <typename MeshT, typename T>
class OVMPropertyVisualizerInteger: public OVMPropertyVisualizer<MeshT>{
......@@ -88,7 +89,7 @@ protected:
virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
virtual void setVertexPropertyFromText(unsigned int index, QString text);
ACG::IColorCoder *buildColorCoder() override;
std::unique_ptr<ACG::IColorCoder> buildColorCoder() override;
T mNumericLimitMax;
T mNumericLimitMin;
......
......@@ -112,7 +112,7 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
integerWidget->intFixedRangeMax->setValue(max);
}
ACG::IColorCoder *cc = integerWidget->buildColorCoder();
auto cc = integerWidget->buildColorCoder();
unsigned int range = max - min;
VolumeMeshObject<MeshT>* object;
......@@ -145,7 +145,6 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
object->colors()[*e_it] = color;
}
}
delete cc;
}
#define KOMMA ,
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
......@@ -266,7 +265,7 @@ void OVMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned
}
template <typename MeshT, typename T>
ACG::IColorCoder *OVMPropertyVisualizerInteger<MeshT, T>::buildColorCoder()
std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerInteger<MeshT, T>::buildColorCoder()
{
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
return integerWidget->buildColorCoder();
......
......@@ -156,7 +156,7 @@ OpenMesh::Vec2f PropertyVisualizer::strToVec2f (QString str)
return OpenMesh::Vec2f(strList[0].toFloat(),strList[1].toFloat());
}
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");
}
......@@ -56,6 +56,7 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <ACG/QtWidgets/QtHistogramWidget.hh>
#include <ACG/Utils/IColorCoder.hh>
#include <ACG/Utils/SmartPointer.hh>
#include "OpenMesh/Core/Geometry/VectorT.hh"
......@@ -180,7 +181,7 @@ public:
protected:
virtual ACG::IColorCoder *buildColorCoder();
virtual std::unique_ptr<ACG::IColorCoder> buildColorCoder();
template<typename PropType, typename Iterable>
void showHistogramT(ACG::QtWidgets::QtHistogramWidget *widget,
......@@ -200,8 +201,7 @@ void PropertyVisualizer::showHistogramT(
const size_t max_bins = 50; // TODO: expose in GUI?
widget->setMinimumHeight(300);
widget->setColorCoder(buildColorCoder());
ACG::Histogram *hist = new ACG::HistogramT<PropType>(data.begin(), data.end(), max_bins);
widget->setHistogram(hist);
widget->setHistogram(ptr::make_unique<ACG::HistogramT<PropType>>(data.begin(), data.end(), max_bins));
}
#endif /* PROPERTY_VISUALIZER_HH */
......@@ -55,6 +55,7 @@
#include "ACG/Utils/IColorCoder.hh"
#include "ACG/Utils/LinearTwoColorCoder.hh"
#include <ACG/Utils/ColorConversion.hh>
#include <ACG/Utils/SmartPointer.hh>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
......@@ -76,15 +77,14 @@ public:
/**
* @brief Builds a color coder according to UI settings
* @return Pointer to an IColorCoder for parameters in [0..1]
* @note Caller is responsible for deleting the returned object.
* @return unique_ptr to an IColorCoder for parameters in [0..1]
*/
ACG::IColorCoder *buildColorCoder()
std::unique_ptr<ACG::IColorCoder> buildColorCoder()
{
if (doubleColorCoder->isChecked()) {
return new ACG::ColorCoder();
return ptr::make_unique<ACG::ColorCoder>();
} else {
return new ACG::LinearTwoColorCoder(
return ptr::make_unique<ACG::LinearTwoColorCoder>(
ACG::to_Vec4f(doubleMin->color()),
ACG::to_Vec4f(doubleMax->color()));
}
......
......@@ -56,6 +56,7 @@
#include "ACG/Utils/ColorCoder.hh"
#include "ACG/Utils/LinearTwoColorCoder.hh"
#include <ACG/Utils/ColorConversion.hh>
#include <ACG/Utils/SmartPointer.hh>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
......@@ -77,15 +78,14 @@ public:
/**
* @brief Builds a color coder according to UI settings
* @return Pointer to an IColorCoder for parameters in [0..1]
* @note Caller is responsible for deleting the returned object.
* @return unique_ptr to an IColorCoder for parameters in [0..1]
*/
ACG::IColorCoder *buildColorCoder()
std::unique_ptr<ACG::IColorCoder> buildColorCoder()
{
if (intColorCoder->isChecked()) {
return new ACG::ColorCoder();
return ptr::make_unique<ACG::ColorCoder>();
} else {
return new ACG::LinearTwoColorCoder(
return ptr::make_unique<ACG::LinearTwoColorCoder>(
ACG::to_Vec4f(intMin->color()),
ACG::to_Vec4f(intMax->color()));
}
......
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