1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
*
* Tulip 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.
*
* Tulip 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 General Public License for more details.
*
*/
#include "ConvolutionClusteringSetup.h"
#include <QPainter>
using namespace std;
using namespace tlp;
class HistogramWidget : public QWidget {
public:
HistogramWidget(ConvolutionClusteringSetup *dialog, QWidget *parent)
: QWidget(parent), setupDialog(dialog) {
// setFrameShape(Q3Frame::StyledPanel); setFrameShadow(Q3Frame::Raised);
}
void paintEvent(QPaintEvent *) {
QPainter painter(this);
vector<double> &histogram = *(setupDialog->getPlugin()->getHistogram());
if (histogram.size() < 1) {
setupDialog->abort();
return;
}
double theMax,theMin;
theMax = histogram[0];
theMin = histogram[0];
for (unsigned int i=1; i<histogram.size(); ++i) {
if (theMax < histogram[i]) theMax = histogram[i];
if (theMin > histogram[i]) theMin = histogram[i];
}
if (setupDialog->getLogarithmicScale()) {
theMax = log10(theMax + 1.0);
theMin = log10(theMin + 1.0);
}
//compute axis position
QFont f( "times", 12, QFont::Bold );
painter.setFont( f );
painter.setPen( Qt::black );
//les 20 de plus permetront de placer des l�gendes sur les axes.
double scale = double(histogram.size())/64.0;
int legendWidth = (int)(20.0*scale);
int borderWidth = (int)(10.0*scale);
int axisWidth = (int)(15.0*scale);
painter.setWindow( 0, 0, 2*histogram.size()+legendWidth, histogram.size()+legendWidth ); // defines coordinate system
painter.fillRect(0, 0,
2*histogram.size()+legendWidth, histogram.size()+legendWidth ,
QBrush(QColor(255,255,255)));
// draw bars
QColor c;
double histoScale = double(histogram.size()) / theMax;
for (unsigned int i=0; i<histogram.size(); i++ ) {
c.setHsv( (int) ((double)i*360.0/(double)histogram.size()) , 255, 255 );
painter.setBrush( c );
int height;
if (setupDialog->getLogarithmicScale())
height = (int)(log10(1.0 + double(histogram[i])) *histoScale );
else
height = (int)(double(histogram[i]) * histoScale);
if (height < 1) height = 1;
painter.drawRect( borderWidth+i*2, borderWidth + 1 + histogram.size() - height,
2, height );
}
//draw axis
painter.drawLine(borderWidth, borderWidth, borderWidth,
histogram.size()+borderWidth);
painter.drawLine(borderWidth, histogram.size()+borderWidth,
2*histogram.size()+axisWidth, histogram.size()+borderWidth);
c.setHsv( 359 , 255, 255 );
//draw local minimum
list<int> localMinimum=setupDialog->getPlugin()->getLocalMinimum();
while (!localMinimum.empty()) {
int i=localMinimum.front();
localMinimum.pop_front();
painter.drawLine(borderWidth+i*2, borderWidth,
borderWidth+i*2, histogram.size()+borderWidth);
}
}
private:
ConvolutionClusteringSetup *setupDialog;
};
/*
* Constructs a ConvolutionClusteringSetup which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
ConvolutionClusteringSetup::ConvolutionClusteringSetup( ConvolutionClustering *convolPlugin, QWidget* parent)
: QDialog( parent),
convolPlugin(convolPlugin),
useLogarithmicScale(false) {
setupUi(this);
histogramWidget = new HistogramWidget(this, Frame3);
QGridLayout *flayout = new QGridLayout(Frame3);
flayout->setMargin(1);
flayout->addWidget(histogramWidget, 0, 0);
int a,b,c;
convolPlugin->getParameters(a,b,c);
widthSlider->setMinimum(1);
widthSlider->setMaximum(a);
widthSlider->setValue(c);
discretizationSlider->setMinimum(1);
discretizationSlider->setMaximum(2*a);
discretizationSlider->setValue(a);
}
/*
* Destroys the object and frees any allocated resources
*/
ConvolutionClusteringSetup::~ConvolutionClusteringSetup() {
// no need to delete child widgets, Qt does it all for us
}
/*
* public slot
*/
void ConvolutionClusteringSetup::setlog(bool b) {
useLogarithmicScale=b;
update();
}
void ConvolutionClusteringSetup::update() {
// GC 4.2: >? is no longer supported
//widthSlider->setMaxValue(discretizationSlider->value() / 2 >? 1);
widthSlider->setMaximum(std::max(discretizationSlider->value() / 2, 1));
convolPlugin->setParameters(discretizationSlider->value(),0,widthSlider->value());
if (histogramWidget)
histogramWidget->update();
QWidget::update();
}
|