source: trunk/FACT++/gui/QCameraWidget.cc@ 11797

Last change on this file since 11797 was 11796, checked in by lyard, 14 years ago
added tooltip for all cameras
File size: 4.9 KB
Line 
1#include "QCameraWidget.h"
2#include <sstream>
3#include <iostream>
4
5 QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
6 {
7 fWhite = 0;
8 fBold.resize(1440);
9 fEnable.resize(1440);
10 fBold.assign(1440, false);
11 fEnable.assign(1440, true);
12 fMin = -1;
13 fMax = -1;
14 lastFace = -1;
15 CalculatePixelsColor();
16
17 }
18 void QCameraWidget::paintGL()
19 {
20 glClear(GL_COLOR_BUFFER_BIT);
21 glLoadIdentity();
22
23 glTranslatef(0,-0.44,0);
24 glScalef(1.5, 1.5, 1.5);
25 drawCamera(true);
26 drawPatches();
27
28 glLineWidth(1.0f);
29 glColor3f(1,1,1);
30 drawHexagon(fWhite, false);
31 }
32 void QCameraWidget::drawCamera(bool alsoWire)
33 {
34 if (!pixelColorUpToDate)
35 CalculatePixelsColor();
36 glLineWidth(1.0);
37 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
38 {
39 glColor3fv(pixelsColor[i]);
40 glLoadName(i);
41 drawHexagon(i,true);
42 }
43 if (!alsoWire)
44 return;
45 glColor3f(0.0f,0.0f,0.0f);
46 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
47 {
48 drawHexagon(i, false);
49 }
50 }
51 void QCameraWidget::Reset()
52 {
53 fBold.assign(1440, false);
54 }
55 void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
56 {
57 int face = PixelAtPosition(cEvent->pos());
58 if (face != -1) {
59 fWhite = face;
60 emit signalCurrentPixel(face);
61 updateGL();
62 }
63 }
64 void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
65 {
66 int face = PixelAtPosition(cEvent->pos());
67 if (face != -1 && lastFace != face) {
68 emit signalPixelMoveOver(face);
69 cout << "Emitting" << endl;
70 }
71 lastFace = face;
72 }
73 void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
74 {
75 int face = PixelAtPosition(cEvent->pos());
76 if (face != -1) {
77 fWhite = face;
78 emit signalPixelDoubleClick(face);
79 updateGL();
80 }
81 }
82 void QCameraWidget::SetBold(int idx)
83 {
84 //cout << "Boldness not taken into account yet" << endl;
85 }
86 void QCameraWidget::SetWhite(int idx)
87 {
88 fWhite = idx;
89 }
90 void QCameraWidget::SetEnable(int idx, bool b)
91 {
92 fEnable[idx] = b;
93 }
94 void QCameraWidget::Toggle(int idx)
95 {
96 }
97 double QCameraWidget::GetData(int idx)
98 {
99 return fData[idx];
100 }
101 void QCameraWidget::SetMin(int64_t min)
102 {
103 fMin = min;
104 pixelColorUpToDate = false;
105 if (isVisible())
106 updateGL();
107 }
108 void QCameraWidget::SetMax(int64_t max)
109 {
110 fMax = max;
111 pixelColorUpToDate = false;
112 if (isVisible())
113 updateGL();
114 }
115 const char* QCameraWidget::GetName()
116 {
117 return "QCameraWidget";
118 }
119 char *QCameraWidget::GetObjectInfo(int px, int py)
120 {
121
122 static stringstream stream;
123 static string str;
124 const int pixel = this->PixelAtPosition(QPoint(px, py));
125 if (pixel >= 0)
126 {
127 stream << "Pixel=" << pixel << " Data=" << fData[pixel] << '\0';
128 }
129 str = stream.str();
130 return const_cast<char*>(str.c_str());
131 }
132 void QCameraWidget::CalculatePixelsColor()
133 {
134 double dmin = fData[0];
135 double dmax = fData[0];
136 for (int i=0;i<1440;i++)
137 {
138 if (!fEnable[i]) continue;
139 if (fData[i] > dmax) dmax = fData[i];
140 if (fData[i] < dmin) dmin = fData[i];
141 }
142 if (fMin >= 0) dmin = fMin;
143 if (fMax >= 0) dmax = fMax;
144 float color;
145 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
146 {
147 color = float((fData[i]-dmin)/(dmax-dmin));
148 if (!fEnable[i])
149 color = 0;
150 int index = 0;
151 while (ss[index] < color)
152 index++;
153 index--;
154 if (index < 0) index = 0;
155 if (index > 3) index = 3;
156 float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
157 if (weight0 > 1.0f) weight0 = 1.0f;
158 if (weight0 < 0.0f) weight0 = 0.0f;
159 float weight1 = 1.0f-weight0;
160 pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
161 pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
162 pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
163 }
164 pixelColorUpToDate = true;
165 }
166 void QCameraWidget::SetData(const valarray<double> &ddata)
167 {
168// fData = ddata;
169 for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
170 fData[i] = ddata[i];
171 pixelColorUpToDate = false;
172 if (isVisible())
173 updateGL();
174 }
Note: See TracBrowser for help on using the repository browser.