Commit 9dbcb099 authored by Martin Heistermann's avatar Martin Heistermann

Extract Interface from ColorCoder, implement RGB-Linear CC, use it in propvis for double+int.

parent a9a0e559
......@@ -125,7 +125,6 @@ protected:
virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
virtual void setVertexPropertyFromText(unsigned int index, QString text);
OpenMesh::Vec4f convertColor(QColor color);
virtual void setPropertyFromText(unsigned int index, QString text);
virtual int getEntityCount();
......
......@@ -70,7 +70,6 @@ public:
virtual ~OMPropertyVisualizerDouble(){}
protected:
virtual void visualizeFaceProp(bool _setDrawMode = true);
virtual void visualizeEdgeProp(bool _setDrawMode = true);
virtual void visualizeHalfedgeProp(bool _setDrawMode = true);
......
......@@ -66,13 +66,11 @@ template <typename MeshT>
void OMPropertyVisualizerDouble<MeshT>::visualizeFaceProp(bool _setDrawMode)
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::ColorCoder cc;
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
OpenMesh::FPropHandleT< double > prop;
......@@ -133,18 +131,13 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeFaceProp(bool _setDrawMode)
v = std::min(max,v);
double t = (v-min)/range;
typename MeshT::Color color;
if( doubleWidget->doubleColorCoder->isChecked())
color = cc.color_float4(t);
else
color = (colorMin)*(1.0-t) + (colorMax)*t;
typename MeshT::Color color = cc->color_float4(t);
// set color
OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);
......@@ -154,15 +147,12 @@ template <typename MeshT>
void OMPropertyVisualizerDouble<MeshT>::visualizeEdgeProp(bool _setDrawMode)
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
typename MeshT::Color colorMin;
colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::ColorCoder cc;
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::EPropHandleT< double > prop;
......@@ -225,19 +215,13 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeEdgeProp(bool _setDrawMode)
v = std::min(max,v);
double t = (v-min)/range;
typename MeshT::Color color;
if( doubleWidget->doubleColorCoder->isChecked())
color = cc.color_float4(t);
else
color = (colorMin)*(1.0-t) + (colorMax)*t;
typename MeshT::Color color = cc->color_float4(t);
// set color
OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::EDGES_COLORED);
......@@ -248,14 +232,11 @@ template <typename MeshT>
void OMPropertyVisualizerDouble<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::ColorCoder cc;
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::HPropHandleT< double > prop;
......@@ -317,14 +298,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
v = std::min(max,v);
double t = (v-min)/range;
typename MeshT::Color color;
if( doubleWidget->doubleColorCoder->isChecked())
color = cc.color_float4(t);
else {
color = (colorMin)*(1.0-t) + (colorMax)*t;
}
typename MeshT::Color color = cc->color_float4(t);
// set color
OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, color);
......@@ -338,13 +312,11 @@ template <typename MeshT>
void OMPropertyVisualizerDouble<MeshT>::visualizeVertexProp(bool _setDrawMode)
{
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
typename MeshT::Color colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
// color coder in [0,1]
ACG::ColorCoder cc;
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
//TODO check if this also works if the property is Vec3d
OpenMesh::VPropHandleT< double > prop;
......@@ -406,14 +378,7 @@ void OMPropertyVisualizerDouble<MeshT>::visualizeVertexProp(bool _setDrawMode)
v = std::min(max,v);
double t = (v-min)/range;
typename MeshT::Color color;
if( doubleWidget->doubleColorCoder->isChecked())
color = cc.color_float4(t);
else {
color = (colorMin)*(1.0-t) + (colorMax)*t;
}
typename MeshT::Color color = cc->color_float4(t);
// set color
OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
......
......@@ -66,7 +66,6 @@ public:
virtual ~OMPropertyVisualizerInteger(){}
protected:
virtual void visualizeFaceProp(bool _setDrawMode = true);
virtual void visualizeEdgeProp(bool _setDrawMode = true);
virtual void visualizeHalfedgeProp(bool _setDrawMode = true);
......
......@@ -49,6 +49,7 @@
#define OM_PROPERTY_VISUALIZER_INTEGER_CC
#include <ACG/Utils/IColorCoder.hh>
#include <ACG/Utils/ColorConversion.hh>
#include "OMPropertyVisualizerInteger.hh"
......@@ -78,13 +79,9 @@ template <typename MeshT, typename T>
void OMPropertyVisualizerInteger<MeshT, T>::visualizeFaceProp(bool _setDrawMode)
{
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
colorMax = ACG::to_Vec4f(integerWidget->intMax->color());
// color coder in [0,1]
ACG::ColorCoder cc;
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -132,19 +129,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeFaceProp(bool _setDrawMode)
typename MeshT::Color color;
if (integerWidget->intColorCoder->isChecked())
{
color = cc.color_float4(pos);
}
else if ( !integerWidget->intRandom->isChecked() ){
color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
color[3] = 1.0;
} else {
if (integerWidget->intRandom->isChecked() ){
if ( randomColor.find( getValue(prop, f_it) ) == randomColor.end() ){
color = mColorGenerator.generateNextColor();
......@@ -154,11 +139,14 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeFaceProp(bool _setDrawMode)
}
color = randomColor[ getValue(prop, f_it) ];
} else {
color = cc->color_float4(pos);
}
OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
}
}
delete cc;
if (_setDrawMode)
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);
......@@ -168,13 +156,9 @@ template <typename MeshT, typename T>
void OMPropertyVisualizerInteger<MeshT, T>::visualizeEdgeProp(bool _setDrawMode)
{
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
colorMax = ACG::to_Vec4f(integerWidget->intMax->color());
// color coder in [0,1]
ACG::ColorCoder cc;
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -222,19 +206,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeEdgeProp(bool _setDrawMode)
typename MeshT::Color color;
if (integerWidget->intColorCoder->isChecked())
{
color = cc.color_float4(pos);
}
else if ( !integerWidget->intRandom->isChecked() ){
color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
color[3] = 1.0;
} else {
if (integerWidget->intRandom->isChecked() ){
if ( randomColor.find( getValue(prop, e_it) ) == randomColor.end() ){
color = mColorGenerator.generateNextColor();
......@@ -244,6 +216,8 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeEdgeProp(bool _setDrawMode)
}
color = randomColor[ getValue(prop, e_it) ];
} else {
color = cc->color_float4(pos);
}
OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, color);
......@@ -259,13 +233,9 @@ template <typename MeshT, typename T>
void OMPropertyVisualizerInteger<MeshT, T>::visualizeHalfedgeProp(bool _setDrawMode)
{
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
colorMax = ACG::to_Vec4f(integerWidget->intMax->color());
// color coder in [0,1]
ACG::ColorCoder cc;
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -313,19 +283,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeHalfedgeProp(bool _setDrawM
typename MeshT::Color color;
if (integerWidget->intColorCoder->isChecked())
{
color = cc.color_float4(pos);
}
else if ( !integerWidget->intRandom->isChecked() ){
color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
color[3] = 1.0;
} else {
if (integerWidget->intRandom->isChecked() ){
if ( randomColor.find( getValue(prop, he_it) ) == randomColor.end() ){
color = mColorGenerator.generateNextColor();
......@@ -335,6 +293,8 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeHalfedgeProp(bool _setDrawM
}
color = randomColor[ getValue(prop, he_it) ];
} else {
color = cc->color_float4(pos);
}
OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, color);
......@@ -349,13 +309,9 @@ template <typename MeshT, typename T>
void OMPropertyVisualizerInteger<MeshT, T>::visualizeVertexProp(bool _setDrawMode)
{
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
typename MeshT::Color colorMin, colorMax;
colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
colorMax = ACG::to_Vec4f(integerWidget->intMax->color());
// color coder in [0,1]
ACG::ColorCoder cc;
typename MeshT::Color colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
ACG::IColorCoder *cc = integerWidget->buildColorCoder(); // color coder in [0,1]
std::map< int, typename MeshT::Color> randomColor;
......@@ -403,21 +359,7 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeVertexProp(bool _setDrawMod
typename MeshT::Color color;
if (integerWidget->intColorCoder->isChecked())
{
color = cc.color_float4(pos);
}
else if ( !integerWidget->intRandom->isChecked() ){
color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
color[3] = 1.0;
}
else
{
if (integerWidget->intRandom->isChecked() ){
if ( randomColor.find( getValue(prop, v_it) ) == randomColor.end() ){
color = mColorGenerator.generateNextColor();
......@@ -427,6 +369,8 @@ void OMPropertyVisualizerInteger<MeshT, T>::visualizeVertexProp(bool _setDrawMod
}
color = randomColor[ getValue(prop, v_it) ];
} else {
color = cc->color_float4(pos);
}
OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
......
......@@ -348,20 +348,6 @@ void OMPropertyVisualizer<MeshT>::clear()
clearVertexProp();
}
template <typename MeshT>
OpenMesh::Vec4f OMPropertyVisualizer<MeshT>::convertColor(const QColor _color){
OpenMesh::Vec4f color;
color[0] = _color.redF();
color[1] = _color.greenF();
color[2] = _color.blueF();
color[3] = _color.alphaF();
return color;
}
template <typename MeshT>
void OMPropertyVisualizer<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
{
......
......@@ -110,8 +110,6 @@ protected:
template<typename PropType>
void duplicateProperty_stage1();
OpenMesh::Vec4f convertColor(QColor color);
template <typename InnerType>
QString getPropertyText_(unsigned int index);
......
......@@ -58,9 +58,7 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/Utils/ColorCoder.hh>
#include <ACG/Utils/IColorCoder.hh>
#include <iostream>
......@@ -72,7 +70,6 @@ public:
virtual ~OVMPropertyVisualizerDouble(){}
protected:
template <typename PropType, typename EntityIterator>
void visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end);
virtual void duplicateProperty();
......
......@@ -57,8 +57,6 @@
#include <ACG/Utils/LinearTwoColorCoder.hh>
#include <ACG/Utils/ColorConversion.hh>
#include <QObject>
template <typename MeshT>
OVMPropertyVisualizerDouble<MeshT>::OVMPropertyVisualizerDouble(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
: OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
......@@ -77,11 +75,8 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
ACG::Vec4f colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
ACG::Vec4f colorMax = ACG::to_Vec4f(doubleWidget->doubleMax->color());
// color coder in [0,1]
ACG::ColorCoder cc;
ACG::IColorCoder *cc = doubleWidget->buildColorCoder();
double min, max;
if ( doubleWidget->doubleAbsolute->isChecked() ){
......@@ -137,13 +132,7 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
double t = (value-min)/range;
ACG::Vec4f color;
if( doubleWidget->doubleColorCoder->isChecked())
color = cc.color_float4(t);
else {
color = (colorMin)*(1.0-t) + (colorMax)*t;
}
ACG::Vec4f color = cc->color_float4(t);
if (doubleWidget->doubleMapOutsideRange->isChecked()) {
if (prop[*e_it] < min || prop[*e_it] > max)
......@@ -154,6 +143,7 @@ void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIter
object->colors()[*e_it] = color;
}
}
delete cc;
}
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble<MeshT>, typename MeshT, double)
......
......@@ -68,7 +68,6 @@ public:
virtual ~OVMPropertyVisualizerInteger(){}
protected:
template <typename PropType, typename EntityIterator>
void visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end);
virtual void duplicateProperty();
......
......@@ -53,6 +53,7 @@
#include "OVMPropertyVisualizerInteger.hh"
#include <ACG/Utils/ColorConversion.hh>
#include <ACG/Utils/LinearTwoColorCoder.hh>
template <typename MeshT, typename T>
OVMPropertyVisualizerInteger<MeshT,T>::OVMPropertyVisualizerInteger(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo, bool isUnsigned)
......@@ -82,10 +83,8 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
if (!prop) return;
IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
ACG::Vec4f colorMin, colorMax;
colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
colorMax = ACG::to_Vec4f(integerWidget->intMax->color());
ACG::Vec4f colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
std::map< int, ACG::Vec4f> randomColor;
......@@ -113,7 +112,7 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
integerWidget->intFixedRangeMax->setValue(max);
}
ACG::ColorCoder cc;
ACG::IColorCoder *cc = integerWidget->buildColorCoder();
unsigned int range = max - min;
VolumeMeshObject<MeshT>* object;
......@@ -127,20 +126,9 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
T value = prop[*e_it];
double pos = (value - min) / (double) range;
ACG::Vec4f color;
if (integerWidget->intColorCoder->isChecked())
{
color = cc.color_float4(pos);
}
else
if ( !integerWidget->intRandom->isChecked() )
{
color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
color[3] = 1.0;
}
else
if ( integerWidget->intRandom->isChecked() )
{
// TODO: build appropriate subclass of IColorCoder for this purpose
if ( randomColor.find( value ) == randomColor.end() )
{
color = mColorGenerator.generateNextColor();
......@@ -149,11 +137,15 @@ void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, Entity
}
color = randomColor[ value ];
}
else
{
color = cc->color_float4(pos);
}
object->colors()[*e_it] = color;
}
}
delete cc;
}
#define KOMMA ,
CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
......
......@@ -234,19 +234,6 @@ void OVMPropertyVisualizer<MeshT>::visualize(bool _setDrawMode, QWidget* _widget
}
}
template <typename MeshT>
OpenMesh::Vec4f OVMPropertyVisualizer<MeshT>::convertColor(const QColor _color){
OpenMesh::Vec4f color;
color[0] = _color.redF();
color[1] = _color.greenF();
color[2] = _color.blueF();
color[3] = _color.alphaF();
return color;
}
template <typename MeshT>
void OVMPropertyVisualizer<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
{
......
......@@ -156,7 +156,6 @@ public:
/// Returns the header for saving.
virtual QString getHeader() = 0;
static inline QString toStr(bool b) { return b ? QObject::tr("True") : QObject::tr("False"); }
static inline QString toStr(double d) { return QObject::tr("%1").arg(d); }
static inline QString toStr(int i) { return QObject::tr("%1").arg(i); }
......
......@@ -52,6 +52,10 @@
#include "ui_DoubleWidget.hh"
#include "ACG/Utils/IColorCoder.hh"
#include "ACG/Utils/LinearTwoColorCoder.hh"
#include <ACG/Utils/ColorConversion.hh>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
......@@ -69,6 +73,22 @@ public:
{
setupUi(this);
}
/**
* @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.
*/
ACG::IColorCoder *buildColorCoder()
{
if (doubleColorCoder->isChecked()) {
return new ACG::ColorCoder();
} else {
return new ACG::LinearTwoColorCoder(
ACG::to_Vec4f(doubleMin->color()),
ACG::to_Vec4f(doubleMax->color()));
}
}
signals:
void widgetShown();
......
......@@ -52,6 +52,11 @@
#include "ui_IntegerWidget.hh"
#include "ACG/Utils/IColorCoder.hh"
#include "ACG/Utils/ColorCoder.hh"
#include "ACG/Utils/LinearTwoColorCoder.hh"
#include <ACG/Utils/ColorConversion.hh>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
......@@ -69,6 +74,23 @@ public:
{
setupUi(this);
}
/**
* @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.
*/
ACG::IColorCoder *buildColorCoder()
{
if (intColorCoder->isChecked()) {
return new ACG::ColorCoder();
} else {
return new ACG::LinearTwoColorCoder(
ACG::to_Vec4f(intMin->color()),
ACG::to_Vec4f(intMax->color()));
}
}
signals:
void widgetShown();
......
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