~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/LineProfileTool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 11:34:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005113417-xcpfcbbqzrso5n7f
Tags: 0.9-2
* Install qtiplot manpage only in qtiplot package.
* Handle nostrip build option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 ***************************************************************************/
32
32
#include "LineProfileTool.h"
33
33
#include "ImageMarker.h"
34
 
#include "LineMarker.h"
 
34
#include "ArrowMarker.h"
35
35
#include "Graph.h"
 
36
#include "ApplicationWindow.h"
 
37
#include "MultiLayer.h"
36
38
 
37
39
#include <QPoint>
38
40
#include <QImage>
40
42
#include <QPainter>
41
43
#include <qwt_plot_canvas.h>
42
44
 
43
 
LineProfileTool::LineProfileTool(Graph *graph, int average_pixels)
 
45
LineProfileTool::LineProfileTool(Graph *graph, ApplicationWindow *app, int average_pixels)
44
46
        : QWidget(graph->plotWidget()->canvas()),
45
 
        PlotToolInterface(graph)
 
47
        PlotToolInterface(graph),
 
48
        d_app(app)
46
49
{
47
50
        d_op_start = d_op_dp = QPoint(0,0);
48
51
        // make sure we average over an odd number of pixels
49
52
        d_average_pixels = (average_pixels % 2) ? average_pixels : average_pixels + 1;
50
53
        d_target = dynamic_cast<ImageMarker*>(d_graph->selectedMarkerPtr());
51
54
        if (!d_target)
52
 
                QMessageBox::critical(d_graph->window(),tr("QtiPlot - Pixel selection warning"),
53
 
                                "Please select an image marker first.");
 
55
                QMessageBox::critical(d_graph->window(), tr("QtiPlot - Pixel selection warning"),
 
56
                                tr("Please select an image marker first."));
54
57
        d_graph->deselectMarker();
55
58
        setGeometry(0, 0, parentWidget()->width(), parentWidget()->height());
56
59
        show();
60
63
void LineProfileTool::calculateLineProfile(const QPoint& start, const QPoint& end)
61
64
{
62
65
        QRect rect = d_target->rect();
63
 
        if (!rect.contains(start) || !rect.contains(end))
64
 
        {
 
66
        if (!rect.contains(start) || !rect.contains(end)){
65
67
                QMessageBox::warning(d_graph, tr("QtiPlot - Pixel selection warning"),
66
 
                                "Please select the end line point inside the image rectangle!");
 
68
                                tr("Please select the end line point inside the image rectangle!"));
67
69
                return;
68
70
        }
69
71
 
79
81
        QSize realSize = pic.size();
80
82
        QSize actualSize = d_target->size();
81
83
 
82
 
        if (realSize != actualSize)
83
 
        {
 
84
        if (realSize != actualSize){
84
85
                double ratioX = (double)realSize.width()/(double)actualSize.width();
85
86
                double ratioY = (double)realSize.height()/(double)actualSize.height();
86
87
                x1 = int(x1*ratioX);
106
107
        px=x1;
107
108
        py=y1;
108
109
 
109
 
        if (dxabs>=dyabs) //the line is more horizontal than vertical
110
 
        {
111
 
                for(i=0;i<dxabs;i++)
112
 
                {
 
110
        if (dxabs>=dyabs){ //the line is more horizontal than vertical
 
111
                for(i=0;i<dxabs;i++){
113
112
                        y+=dyabs;
114
 
                        if (y>=dxabs)
115
 
                        {
 
113
                        if (y>=dxabs){
116
114
                                y-=dxabs;
117
115
                                py+=sdy;
118
116
                        }
124
122
                        text+=QString::number(py)+"\t";
125
123
                        text+=QString::number(averageImagePixel(image, px, py, true))+"\n";
126
124
                }
127
 
        }
128
 
        else // the line is more vertical than horizontal
129
 
        {
130
 
                for(i=0;i<dyabs;i++)
131
 
                {
 
125
        } else {// the line is more vertical than horizontal
 
126
                for(i=0;i<dyabs;i++){
132
127
                        x+=dxabs;
133
 
                        if (x>=dyabs)
134
 
                        {
 
128
                        if (x>=dyabs){
135
129
                                x-=dyabs;
136
130
                                px+=sdx;
137
131
                        }
144
138
                        text+=QString::number(averageImagePixel(image, px, py, false))+"\n";
145
139
                }
146
140
        }
147
 
        QString caption = tr("Table") + "1";
148
 
        emit createTablePlot(caption, n, 4, text);
 
141
 
 
142
        Table *t = d_app->newTable(tr("Table") + "1", n, 4, text);
 
143
        MultiLayer* plot = d_app->multilayerPlot(t, QStringList(QString(t->name())+"_intensity"), 0);
 
144
        Graph *g = (Graph*)plot->activeGraph();
 
145
        if (g){
 
146
                g->setTitle("");
 
147
                g->setXAxisTitle(tr("pixels"));
 
148
                g->setYAxisTitle(tr("pixel intensity (a.u.)"));
 
149
        }
 
150
 
149
151
}
150
152
 
151
153
int LineProfileTool::averageImagePixel(const QImage& image, int px, int py, bool moreHorizontal)
153
155
        QRgb pixel;
154
156
        int sum=0,start,i;
155
157
        int middle=int(0.5*(d_average_pixels-1));
156
 
        if (moreHorizontal)
157
 
        {
 
158
        if (moreHorizontal){
158
159
                start=py-middle;
159
 
                for(i=0; i<d_average_pixels; i++)
160
 
                {
 
160
                for(i=0; i<d_average_pixels; i++){
161
161
                        pixel= image.pixel(px,start+i);
162
162
                        sum+=qGray(pixel);
163
163
                }
164
 
        }
165
 
        else
166
 
        {
 
164
        } else {
167
165
                start=px-middle;
168
 
                for(i=0; i<d_average_pixels; i++)
169
 
                {
 
166
                for(i=0; i<d_average_pixels; i++) {
170
167
                        pixel= image.pixel(start+i,py);
171
168
                        sum+=qGray(pixel);
172
169
                }
176
173
 
177
174
void LineProfileTool::addLineMarker(const QPoint &start, const QPoint &end)
178
175
{
179
 
        LineMarker *mrk = new LineMarker();
 
176
        ArrowMarker *mrk = new ArrowMarker();
180
177
        mrk->attach(d_graph->plotWidget());
181
178
 
182
179
        mrk->setStartPoint(start);
187
184
        mrk->drawEndArrow(false);
188
185
        mrk->drawStartArrow(false);
189
186
 
190
 
        d_graph->insertLineMarker(mrk);
 
187
        d_graph->addArrow(mrk);
191
188
        mrk->detach();
192
189
        d_graph->replot();
193
190
}