File: QFitsMarkers.cpp

package info (click to toggle)
dpuser 4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,084 kB
  • sloc: cpp: 124,807; ansic: 6,866; lex: 1,113; makefile: 777; yacc: 742; sh: 78
file content (280 lines) | stat: -rw-r--r-- 7,400 bytes parent folder | download | duplicates (3)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include <QPainter>

#include "QFitsMarkers.h"
#include "QFitsSingleBuffer.h"
#include "QFitsMultiBuffer.h"

QFitsMarkers::QFitsMarkers(QColor sourceBorder,
                           QColor sourceFill,
                           QColor continuumBorder,
                           QColor continuumFill,
                           QColor lockBorder,
                           QColor lockFill,
                           Qt::PenStyle ps,
                           Qt::BrushStyle bs)
{
    sourcePen = new QPen(sourceBorder);
    sourcePen->setStyle(ps);
    continuumPen = new QPen(continuumBorder);
    continuumPen->setStyle(ps);
    lockPen = new QPen(lockBorder);
    lockPen->setStyle(ps);

    sourceBrush = new QBrush(sourceFill);
    sourceBrush->setStyle(bs);
    continuumBrush = new QBrush(continuumFill);
    continuumBrush->setStyle(bs);
    lockBrush = new QBrush(lockFill);
    lockBrush->setStyle(bs);

    initVal = 0;
    initCenter();
    bufferToPaint = NULL;

    markerLockX = -1;
    markerLockY = -1;
}

bool QFitsMarkers::hasSourceMarkers() {
    bool ret = false;
    if (getSizeSource() > 0) {
        ret = true;
    }
    return ret;
}

bool QFitsMarkers::hasAnyMarkers() {
    bool ret = false;
    if ((getSizeSource() > 0) || (getSizeContinuum() > 0)){
        ret = true;
    }
    return ret;
}

// either add positive values (x,y) OR (negative values (-x, -y)
// and NEVER mixed values like (x,-y)!!
void QFitsMarkers::addMarkerSource(long x, long y) {
    // delete point (x,y) or its negative if it is already marked
    deleteMarker(x, y);

    // now append the new value
    markersSourceX.append(x);
    markersSourceY.append(y);
}

void QFitsMarkers::addMarkerContinuum(long x, long y) {
    // delete point (x,y) or its negative if it is already marked
    deleteMarker(x, y);

    // now append the new value
    markersContinuumX.append(x);
    markersContinuumY.append(y);
}

void QFitsMarkers::addMarkerLock(long x, long y) {
    markerLockX = x;
    markerLockY = y;
}


void QFitsMarkers::setupPointMarker() {
    deleteAllMarkers();

    addMarkerSource(centerX, centerY);
}

void QFitsMarkers::setupCircleMarkers(int r1) {
    deleteAllMarkers();

    for (long i = centerX - r1; i <= centerX + r1; i++) {
        for (long j = centerY - r1; j <= centerY + r1; j++) {
            if ((i-centerX)*(i-centerX) + (j-centerY)*(j-centerY) <= r1*r1) {
                addMarkerSource(i, j);
            }
        }
    }
}

void QFitsMarkers::setupCircleAnnularMarkers(int r1, int r2) {
    setupCircleMarkers(r1);

    if (r1 <= r2) {
        // outer circle
        for (long i = centerX - r2; i <= centerX + r2; i++) {
            for (long j = centerY - r2; j <= centerY + r2; j++) {
                if (((i-centerX)*(i-centerX) + (j-centerY)*(j-centerY) <= r2*r2) &&
                    ((i-centerX)*(i-centerX) + (j-centerY)*(j-centerY) > r1*r1))
                {
                    // surrounding sky
                    addMarkerContinuum(i, j);
                }
            }
        }
    }
}

int QFitsMarkers::getSizeSource() {
    return markersSourceX.size();
}

int QFitsMarkers::getSizeContinuum() {
    return markersContinuumX.size();
}

void QFitsMarkers::getMarkerSource(int i, long *x, long *y) {
    *x = markersSourceX.at(i);
    *y = markersSourceY.at(i);
}

void QFitsMarkers::getMarkerContinuum(int i, long *x, long *y) {
    *x = markersContinuumX.at(i);
    *y = markersContinuumY.at(i);
}

void QFitsMarkers::deleteMarker(long x, long y) {
    for (int i = 0; i < getSizeContinuum(); i++) {
        if ((markersContinuumX.at(i) == x) &&
            (markersContinuumY.at(i) == y))
        {
            markersContinuumX.remove(i);
            markersContinuumY.remove(i);
            break;
        }
    }

    for (int i = 0; i < getSizeSource(); i++) {
        if ((markersSourceX.at(i) == x) &&
            (markersSourceY.at(i) == y))
        {
            markersSourceX.remove(i);
            markersSourceY.remove(i);
            break;
        }
    }
}

void QFitsMarkers::deleteMarkerLock() {
    markerLockX = -1;
    markerLockY = -1;
}

void QFitsMarkers::setCenter(QFitsSingleBuffer *sb, long newCenterX, long newCenterY) {

    setBufferToPaint(sb);

    long xshift = newCenterX - centerX;
    long yshift = newCenterY - centerY;

    centerX = newCenterX;
    centerY = newCenterY;

    long valX = 0, valY = 0;
    for (int i = 0; i < getSizeSource(); i++) {
        valX = markersSourceX.at(i);
        valY = markersSourceY.at(i);

        markersSourceX.replace(i, valX + xshift);
        markersSourceY.replace(i, valY + yshift);
    }

    for (int i = 0; i < getSizeContinuum(); i++) {
        valX = markersContinuumX.at(i);
        valY = markersContinuumY.at(i);

        markersContinuumX.replace(i, valX + xshift);
        markersContinuumY.replace(i, valY + yshift);
    }
}

void QFitsMarkers::setBufferToPaint(QFitsSingleBuffer *sb) {
    bufferToPaint = sb;
}

void QFitsMarkers::deleteAllMarkers() {
    markersSourceX.clear();
    markersSourceY.clear();
    markersContinuumX.clear();
    markersContinuumY.clear();

    initCenter();
}

void QFitsMarkers::drawAllMarkers(QPainter *pa,
                                  int xoffset, int yoffset, QFitsSingleBuffer *sb)
{
    if (bufferToPaint == NULL) {
        return;
    }

    // get zoom factor
    double w = 1.;
    if (bufferToPaint->getZoomFactor() > 1.) {
        // > 100%
        w = bufferToPaint->getZoomFactor();
    }

    // loop points and draw them
    int xw = w,
        yw = w,
        x = 0, y = 0;
    pa->translate(xoffset, yoffset);

    if ((sb->underMouse() && (sb->getLockedSingleBuffer() == NULL)) || (sb->getLockedSingleBuffer() == sb)) {
    // paint continuum markers
        for (int i = 0; i < getSizeContinuum(); i++) {
            x = markersContinuumX.at(i);
            y = markersContinuumY.at(i);

            if ((x >= 1) && (x <= bufferToPaint->Naxis(1)) &&
                (y >= 1) && (y <= bufferToPaint->Naxis(2)))
            {
                bufferToPaint->imageToWidget(&x, &y);

                pa->setPen(*continuumPen);
                pa->setBrush(*continuumBrush);

                pa->drawRect(x, y, xw, yw);
            }
        }

        // paint source markers
        for (int i = 0; i < getSizeSource(); i++) {
            x = markersSourceX.at(i);
            y = markersSourceY.at(i);

            if ((x >= 1) && (x <= bufferToPaint->Naxis(1)) &&
                (y >= 1) && (y <= bufferToPaint->Naxis(2)))
            {
                bufferToPaint->imageToWidget(&x, &y);

                pa->setPen(*sourcePen);
                pa->setBrush(*sourceBrush);

                pa->drawRect(x, y, xw, yw);
            }
        }
    }

    bool isMBchild = bufferToPaint->isMultiBufferChild();

    if (!isMBchild ||
        (isMBchild && (sb == sb->getMyMultiBuffer()->getLockedSingleBuffer())))
    {
        // paint lock marker
        x = markerLockX;
        y = markerLockY;
        if ((x >= 1) && (x <= bufferToPaint->Naxis(1)) &&
            (y >= 1) && (y <= bufferToPaint->Naxis(2)))
        {
            bufferToPaint->imageToWidget(&x, &y);
            pa->setPen(*lockPen);
            pa->setBrush(*lockBrush);
            pa->drawRect(x, y, xw, yw);
        }
    }
}

void QFitsMarkers::initCenter() {
    centerX = initVal;
    centerY = initVal;
}