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

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