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

First cleanup step. Correctly colorize histogram. refs #275

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13751 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 23aaed6f
......@@ -70,6 +70,7 @@
#include <float.h>
#include <math.h>
#include "TextureMath.hh"
//== NAMESPACES ===============================================================
......@@ -120,102 +121,42 @@ void QwtFunctionPlot::setFunction( std::vector<double>& _values)
max_ = std::max(max_, values_[i] );
}
// std::cerr << "Min is : "<< min_ << std::endl;
// std::cerr << "Max is : "<< max_ << std::endl;
}
//------------------------------------------------------------------------------
void QwtFunctionPlot::setParameters(bool _repeat, double _repeatMax,
bool _clamp, double _clampMin, double _clampMax,
bool _center,
bool _absolute,
bool _scale)
void QwtFunctionPlot::setParameters(const TexParameters& _parameters)
{
repeat_ = _repeat;
repeatMax_ = _repeatMax;
clamp_ = _clamp;
clampMin_ = _clampMin;
clampMax_ = _clampMax;
center_ = _center;
absolute_ = _absolute;
scale_ = _scale;
parameters_ = _parameters;
}
//------------------------------------------------------------------------------
void QwtFunctionPlot::setImage(QImage* _image)
void QwtFunctionPlot::setParameters(
bool _repeat,
double _repeatMax,
bool _clamp,
double _clampMin,
double _clampMax,
bool _center,
bool _absolute,
bool _scale)
{
image_ = _image;
}
//------------------------------------------------------------------------------
double QwtFunctionPlot::transform( double _value ){
// std::cerr << "Input value : " << _value << std::endl;
if (absolute_) {
_value = fabs(_value);
// std::cerr << "abs " << _value << std::endl;
}
if (clamp_){
_value = std::max( clampMin_, _value );
_value = std::min( clampMax_, _value );
// std::cerr << "clamp_ " << _value << std::endl;
}
if (repeat_){
_value = ( (_value - currentMin_) / (currentMax_-currentMin_) ) * repeatMax_;
// std::cerr << "repeat_ " << _value << std::endl;
}else{
if (center_) {
_value -= (currentMax_-currentMin_) / 2.0; //TODO:thats wrong
// std::cerr << "center_ " << _value << std::endl;
}
if (scale_) {
_value = (_value - currentMin_) / (currentMax_-currentMin_);
// std::cerr << "scale_" << _value << std::endl;
}
if (center_) {
_value += 0.5;
// std::cerr << "center_2" << _value << std::endl;
}
}
return _value;
parameters_.repeat = _repeat;
parameters_.repeatMax = _repeatMax;
parameters_.clamp = _clamp;
parameters_.clampMin = _clampMin;
parameters_.clampMax = _clampMax;
parameters_.center = _center;
parameters_.abs = _absolute;
parameters_.scale = _scale;
}
//------------------------------------------------------------------------------
void QwtFunctionPlot::initValues()
void QwtFunctionPlot::setImage(QImage* _image)
{
//get min/max values
currentMin_ = FLT_MAX;
currentMax_ = FLT_MIN;
for ( uint i=0; i < values_.size(); i++){
double tranformed = values_[i];
if (absolute_)
tranformed = fabs(tranformed);
if (clamp_){
tranformed = std::max( clampMin_, tranformed );
tranformed = std::min( clampMax_, tranformed );
}
currentMin_ = std::min(currentMin_, tranformed );
currentMax_ = std::max(currentMax_, tranformed );
}
image_ = _image;
}
//------------------------------------------------------------------------------
......@@ -237,8 +178,8 @@ void QwtFunctionPlot::zoomOut()
void QwtFunctionPlot::clamp()
{
QRectF clamped = plot_zoomer_->zoomRect();
clamped.setLeft( transform(min_) );
clamped.setRight( transform(max_) );
clamped.setLeft( min_ );
clamped.setRight( max_ );
emit plot_zoomer_->zoom(clamped);
}
......@@ -246,9 +187,6 @@ void QwtFunctionPlot::clamp()
void QwtFunctionPlot::replot()
{
initValues();
//create intervals
const int intervalCount = 100;
......@@ -260,11 +198,13 @@ void QwtFunctionPlot::replot()
#endif
std::vector< QColor > colors;
double pos = transform(min_);
double width = ( transform(max_) - transform(min_) ) / intervalCount;
double pos = min_;
double width = ( max_ - min_ ) / intervalCount;
QColor lastColor = Qt::black;
TextureMath convert(parameters_,min_,max_);
for ( int i = 0; i < (int)intervals.size(); i++ )
{
// std::cerr << "==============================" << std::endl;
......@@ -281,32 +221,15 @@ void QwtFunctionPlot::replot()
//compute a color for the given interval
if (image_ != 0){
double intervalCenter = pos + (width/2.0);
// std::cerr << "intervalCenter: " << intervalCenter << std::endl;
if (intervalCenter > 1.0 && !repeat_){
// std::cerr << lastColor.red() << " " << lastColor.green() << " " << lastColor.blue() << "\n";
colors.push_back( lastColor );
continue;
}
if ( intervalCenter < 0.0){
colors.push_back( lastColor );
continue;
}
const double intervalCenter = pos + (width/2.0);
if ( intervalCenter > 1.0){
intervalCenter -= floor(intervalCenter);
}
const double value = convert.transform(intervalCenter);
int val = int( value * ( image_->width() - 1) );
int val = int( intervalCenter * image_->width() );
// std::cerr << "Reading from image at " << val << std::endl;
val = val % image_->width(); // Simulate If texture is repeated, we have to make sure, we stay inside of the image
colors.push_back( QColor( image_->pixel(val, 0) ) );
lastColor = colors.back();
// std::cerr << lastColor.red() << " " << lastColor.green() << " " << lastColor.blue() << "\n";
}
}
......@@ -314,10 +237,10 @@ void QwtFunctionPlot::replot()
for ( uint i=0; i < values_.size(); i++)
for ( int j = 0; j < (int)intervals.size(); j++ )
#if QWT_VERSION >= 0x060000
if ( intervals[j].interval.contains( transform(values_[i]) ) )
if ( intervals[j].interval.contains( values_[i] ) )
intervals[j].value++;
#else
if ( intervals[j].contains( transform(values_[i]) ) )
if ( intervals[j].contains( values_[i] ) )
count[j]++;
#endif
......@@ -342,7 +265,7 @@ void QwtFunctionPlot::replot()
histogram_->attach(qwtPlot);
qwtPlot->setAxisScale(QwtPlot::yLeft, 0.0, maxCount);
qwtPlot->setAxisScale(QwtPlot::xBottom, transform(min_), transform(max_));
qwtPlot->setAxisScale(QwtPlot::xBottom, min_, max_);
qwtPlot->setAxisTitle(QwtPlot::yLeft, "count" );
qwtPlot->setAxisTitle(QwtPlot::xBottom, "values" );
......
......@@ -79,6 +79,8 @@
#endif
#include <vector>
#include "TextureParameters.hh"
//== FORWARDDECLARATIONS ======================================================
......@@ -105,12 +107,21 @@ public:
// set the function to plot
void setFunction( std::vector<double>& _values );
/// Set all parameters as one block
void setParameters(const TexParameters& _parameters);
/// Set the parameters separately
void setParameters(bool repeat, double repeatMax,
bool clamp, double clampMin, double clampMax,
bool center,
bool absolute,
bool scale);
/** The function plot accesses an image to get colors from them.
* The colors are equivalent to the rendered color textures.
*
* @param _image Image that is used to take the colors from
*/
void setImage(QImage* _image);
public slots:
......@@ -122,10 +133,6 @@ public slots:
private:
void initValues();
double transform( double _value );
QwtPlotZoomer* plot_zoomer_;
// Histogramm Plot
......@@ -139,20 +146,9 @@ private:
QImage* image_;
bool repeat_;
double repeatMax_;
bool clamp_;
double clampMin_;
double clampMax_;
bool center_;
bool absolute_;
bool scale_;
double min_;
double max_;
TexParameters parameters_;
double currentMin_;
double currentMax_;
double min_,max_;
};
......
......@@ -56,8 +56,6 @@
#include "OpenFlipper/common/GlobalOptions.hh"
#include "ImageStorage.hh"
#include <math.h>
#define TEXTUREDATA "TextureData"
......@@ -835,71 +833,6 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
}
void TextureControlPlugin::computeValue(Texture& _texture, double _min, double _max, double& _value) {
const bool clamp = _texture.parameters.clamp ;
const bool center = _texture.parameters.center;
const double max_val = _texture.parameters.max_val;
const double min_val = _texture.parameters.min_val;
const bool abs = _texture.parameters.abs;
const double clamp_max = _texture.parameters.clamp_max;
const double clamp_min = _texture.parameters.clamp_min;
const bool scale = _texture.parameters.scale;
const double scaleFactor = fabs(_max) + fabs(_min);
const bool repeat = _texture.parameters.repeat;
// Use absolute value as requested by plugin
if ( abs )
_value = fabs(_value);
// Clamp if requested
if ( clamp ) {
if ( _value > clamp_max )
_value = clamp_max;
if (_value < clamp_min)
_value = clamp_min;
}
// if all texCoords have the same value
if ( _min == _max ){
if ( ! repeat )
_value = 0.0;
else
_value = max_val;
return;
}
// if the texture should not be repeated, scale to 0..1
if ( ! repeat ) {
if (! center ) {
if ( scale) {
_value /= scaleFactor; //scaleFactor is != 0.0 (otherwise _min==_max)
_value -= _min/scaleFactor;
}
} else {
// the values above zero are mapped to 0.5..1 the negative ones to 0.5..0
if (_value > 0.0) {
_value /= ( _max * 2.0); //_max >= _value > 0.0
_value += 0.5;
} else {
if ( _min == 0.0 ){
_value = 0.0;
} else {
_value /= ( _min * 2.0);
_value = 0.5 - _value;
}
}
}
} else {
_value -= _min;
_value *= (max_val - min_val) / (_max - _min);
_value += min_val;
}
}
void TextureControlPlugin::slotDrawModeChanged(int _viewerId ) {
// Only update if we have a relevant draw mode
......@@ -1015,23 +948,23 @@ bool TextureControlPlugin::parseMode( QString _mode, Texture& _texture ) {
changed = true;
}
} else if ( sectionName == "clamp_max" ) {
if (value.toDouble() != _texture.parameters.clamp_max){
_texture.parameters.clamp_max = value.toDouble();
if (value.toDouble() != _texture.parameters.clampMax){
_texture.parameters.clampMax = value.toDouble();
changed = true;
}
} else if ( sectionName == "clamp_min" ) {
if (value.toDouble() != _texture.parameters.clamp_min){
_texture.parameters.clamp_min = value.toDouble();
if (value.toDouble() != _texture.parameters.clampMin){
_texture.parameters.clampMin = value.toDouble();
changed = true;
}
} else if ( sectionName == "max_val" ) {
if (value.toDouble() != _texture.parameters.max_val){
_texture.parameters.max_val = value.toDouble();
if (value.toDouble() != _texture.parameters.repeatMax){
_texture.parameters.repeatMax = value.toDouble();
changed = true;
}
} else if ( sectionName == "min_val" ) {
if (value.toDouble() != _texture.parameters.min_val){
_texture.parameters.min_val = value.toDouble();
if (value.toDouble() != _texture.parameters.repeatMin){
_texture.parameters.repeatMin = value.toDouble();
changed = true;
}
} else if ( sectionName == "repeat" ) {
......@@ -1131,23 +1064,23 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
changed = true;
}
if ( _mode.contains("clamp_max") && (texture.parameters.clamp_max != localTex.parameters.clamp_max) ){
localTex.parameters.clamp_max = texture.parameters.clamp_max;
if ( _mode.contains("clamp_max") && (texture.parameters.clampMax != localTex.parameters.clampMax) ){
localTex.parameters.clampMax = texture.parameters.clampMax;
changed = true;
}
if ( _mode.contains("clamp_min") && (texture.parameters.clamp_min != localTex.parameters.clamp_min) ){
localTex.parameters.clamp_min = texture.parameters.clamp_min;
if ( _mode.contains("clamp_min") && (texture.parameters.clampMin != localTex.parameters.clampMin) ){
localTex.parameters.clampMin = texture.parameters.clampMin;
changed = true;
}
if ( _mode.contains("max_val") && (texture.parameters.max_val != localTex.parameters.max_val) ){
localTex.parameters.max_val = texture.parameters.max_val;
if ( _mode.contains("max_val") && (texture.parameters.repeatMax != localTex.parameters.repeatMax) ){
localTex.parameters.repeatMax = texture.parameters.repeatMax;
changed = true;
}
if ( _mode.contains("min_val") && (texture.parameters.min_val != localTex.parameters.min_val) ){
localTex.parameters.min_val = texture.parameters.min_val;
if ( _mode.contains("min_val") && (texture.parameters.repeatMin != localTex.parameters.repeatMin) ){
localTex.parameters.repeatMin = texture.parameters.repeatMin;
changed = true;
}
......@@ -1345,20 +1278,20 @@ void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _t
localTexture.parameters.clamp = globalTexture.parameters.clamp;
changed = true;
}
if (localTexture.parameters.clamp_max != globalTexture.parameters.clamp_max){
localTexture.parameters.clamp_max = globalTexture.parameters.clamp_max;
if (localTexture.parameters.clampMax != globalTexture.parameters.clampMax){
localTexture.parameters.clampMax = globalTexture.parameters.clampMax;
changed = true;
}
if (localTexture.parameters.clamp_min != globalTexture.parameters.clamp_min){
localTexture.parameters.clamp_min = globalTexture.parameters.clamp_min;
if (localTexture.parameters.clampMin != globalTexture.parameters.clampMin){
localTexture.parameters.clampMin = globalTexture.parameters.clampMin;
changed = true;
}
if (localTexture.parameters.max_val != globalTexture.parameters.max_val){
localTexture.parameters.max_val = globalTexture.parameters.max_val;
if (localTexture.parameters.repeatMax != globalTexture.parameters.repeatMax){
localTexture.parameters.repeatMax = globalTexture.parameters.repeatMax;
changed = true;
}
if (localTexture.parameters.min_val != globalTexture.parameters.min_val){
localTexture.parameters.min_val = globalTexture.parameters.min_val;
if (localTexture.parameters.repeatMin != globalTexture.parameters.repeatMin){
localTexture.parameters.repeatMin = globalTexture.parameters.repeatMin;
changed = true;
}
if (localTexture.parameters.repeat != globalTexture.parameters.repeat){
......
......@@ -174,10 +174,6 @@ class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, Tex
private:
/// Take a scalar value and return a clamped,... depending on texture settings
inline
void computeValue(Texture& _texture, double _min, double _max, double& _value);
/// Calls the correct \a copyTexture() function to copy the texture property into the displayed OM property
template< typename MeshT >
void doUpdateTexture ( Texture& _texture , MeshT& _mesh);
......
......@@ -43,6 +43,7 @@
#define TEXTURECONTROL_1D_TEXTURE_HANDLING_C
#include "TextureControl.hh"
#include "TextureMath.hh"
template< typename MeshT >
void TextureControlPlugin::computeMinMaxScalar(Texture& _textureData ,
......@@ -52,8 +53,8 @@ void TextureControlPlugin::computeMinMaxScalar(Texture& _textureData ,
const bool abs = _textureData.parameters.abs;
const bool clamp = _textureData.parameters.clamp ;
const double clamp_max = _textureData.parameters.clamp_max;
const double clamp_min = _textureData.parameters.clamp_min;
const double clamp_max = _textureData.parameters.clampMax;
const double clamp_min = _textureData.parameters.clampMin;
_max = FLT_MIN;
_min = FLT_MAX;
......@@ -84,8 +85,8 @@ void TextureControlPlugin::computeMinMaxScalar(Texture& _textureData ,
const bool abs = _textureData.parameters.abs;
const bool clamp = _textureData.parameters.clamp ;
const double clamp_max = _textureData.parameters.clamp_max;
const double clamp_min = _textureData.parameters.clamp_min;
const double clamp_max = _textureData.parameters.clampMax;
const double clamp_min = _textureData.parameters.clampMin;
_max = FLT_MIN;
_min = FLT_MAX;
......@@ -118,14 +119,16 @@ void TextureControlPlugin::copyTexture ( Texture& _texture , MeshT& _mesh, OpenM
if ( !_mesh.has_vertex_texcoords2D() )
_mesh.request_vertex_texcoords2D();
TextureMath convert(_texture.parameters,min,max);
for ( typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it) {
// Get the value of the property
double value = _mesh.property(_texProp, v_it);
// Mangle it with the predefined user options
computeValue(_texture, min, max, value);
value = convert.transform(value);
// Write result to the openmesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
// Write result to the OpenMesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
_mesh.set_texcoord2D( v_it, ACG::Vec2f(float(value), float(value) ) );
}
}
......@@ -140,15 +143,17 @@ void TextureControlPlugin::copyTexture ( Texture& _texture , MeshT& _mesh, OpenM
if ( !_mesh.has_halfedge_texcoords2D() )
_mesh.request_halfedge_texcoords2D();
TextureMath convert(_texture.parameters,min,max);
for ( typename MeshT::HalfedgeIter h_it = _mesh.halfedges_begin(); h_it != _mesh.halfedges_end(); ++h_it) {
// Get the value of the property
double value = _mesh.property(_texProp, h_it);
// Mangle it with the predefined user options
computeValue(_texture, min, max, value);
value = convert.transform(value);
// Write result to the openmesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
// Write result to the OpenMesh texture coordinates ( 2d accessing the diagonal of a 2d texture)
_mesh.set_texcoord2D( h_it, ACG::Vec2f(float(value), float(value) ) );
}
}
......
......@@ -44,6 +44,7 @@
#define TEXTUREDATA_HH
#include <OpenFlipper/common/perObjectData.hh>
#include "TextureParameters.hh"
#include <QString>
#include <QStringList>
......@@ -51,7 +52,7 @@
#include <vector>
#include <map>
#include <float.h>
#include <iostream>
enum TextureType { UNSET = 1 << 0,
/// Texture Coordinates are stored on a per Vertex basis
......@@ -63,36 +64,6 @@ enum TextureType { UNSET = 1 << 0,
/// MultiTexture Mode
MULTITEXTURE = 1 << 4 };
class TexParameters
{
public:
TexParameters() :
scale ( true ),
clamp_min ( FLT_MIN ),
clamp_max ( FLT_MAX ),
clamp ( false ),
repeat ( false ),
center ( false ),
abs ( false ),
max_val ( 1.0 ),
min_val ( 0.0 ) {};
bool scale;
double clamp_min;
double clamp_max;
bool clamp;
bool repeat;
bool center;
bool abs;
double max_val;
double min_val;
};
class Texture {
public :
Texture();
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include "TextureMath.hh"
#include <math.h>
TextureMath::TextureMath(const bool _abs,
const bool _clamp,
const double _clampMin,
const double _clampMax,
const bool _repeat,
const double _minRepeat,
const double _maxRepeat,
const bool _center,
const bool _scale,
const double _minimalInput,
const double _maximalInput):
abs_(_abs),
clamp_(_clamp),
clampMin_(_clampMin),
clampMax_(_clampMax),
repeat_(_repeat),
repeatMin_(_minRepeat),
repeatMax_(_maxRepeat),
center_(_center),
scale_(_scale),
minInput_(_minimalInput),
maxInput_(_maximalInput)
{
}
TextureMath::TextureMath(const TexParameters& _parameters, const double _minimalInput, const double _maximalInput) :
abs_(_parameters.abs),
clamp_(_parameters.clamp),
clampMin_(_parameters.clampMin),
clampMax_(_parameters.clampMax),
repeat_(_parameters.repeat),
repeatMin_(_parameters.repeatMin),
repeatMax_(_parameters.repeatMax),
center_(_parameters.center),
scale_(_parameters.scale),
minInput_(_minimalInput),
maxInput_(_maximalInput)
{
}
double TextureMath::transform(const double _input) const
{
double value = _input;
// Use absolute value as requested by plugin
if ( abs_ )
value = fabs(value);
// Clamp if requested
if ( clamp_ ) {
if ( value > clampMax_ )
value = clampMax_;
if (value < clampMin_)
value = clampMin_;
}
// if all texCoords have the same value
if ( minInput_ == maxInput_){
if ( ! repeat_ )
value = 0.0;
else
value = maxInput_;
return value;
}
// if the texture should not be repeated, scale to 0..1
if ( ! repeat_ ) {
if (! center_ ) {
if ( scale_) {