15#define TRGCDC_SHORT_NAMES
18#include <pangomm/init.h>
19#include "trg/trg/Utilities.h"
20#include "trg/cdc/TRGCDC.h"
21#include "trg/cdc/Wire.h"
22#include "trg/cdc/WireHit.h"
23#include "trg/cdc/Segment.h"
24#include "trg/cdc/FrontEnd.h"
25#include "trg/cdc/Merger.h"
26#include "trg/cdc/HoughPlane.h"
27#include "trg/cdc/HoughPlaneMulti2.h"
28#include "trg/cdc/Display.h"
29#include "trg/cdc/DisplayRphi.h"
30#include "trg/cdc/DisplayDrawingAreaHough.h"
40 TRGCDCDisplayDrawingAreaHough::TRGCDCDisplayDrawingAreaHough(
43 : TRGCDCDisplayDrawingArea(w, size, 10),
49 _scaleX(0), _scaleY(0),
50 _winx(0), _winy(0), _winw(0), _winh(0), _wind(0),
53 _blue(Gdk::Color(
"blue")),
54 _red(Gdk::Color(
"red")),
55 _green(Gdk::Color(
"green")),
56 _black(Gdk::Color(
"black")),
57 _white(Gdk::Color(
"white")),
58 _gray(Gdk::Color(
"gray")),
59 _yellow(Gdk::Color(
"yellow")),
61 _gray0(Gdk::Color(
"gray90")),
62 _gray1(Gdk::Color(
"gray80")),
63 _gray2(Gdk::Color(
"gray70")),
64 _gray3(Gdk::Color(
"gray60"))
68 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
69 colormap->alloc_color(_blue);
70 colormap->alloc_color(_red);
71 colormap->alloc_color(_green);
72 colormap->alloc_color(_black);
73 colormap->alloc_color(_white);
74 colormap->alloc_color(_gray);
75 colormap->alloc_color(_yellow);
76 colormap->alloc_color(_gray0);
77 colormap->alloc_color(_gray1);
78 colormap->alloc_color(_gray2);
79 colormap->alloc_color(_gray3);
81 add_events(Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK);
84 TRGCDCDisplayDrawingAreaHough::~TRGCDCDisplayDrawingAreaHough()
89 TRGCDCDisplayDrawingAreaHough::on_realize()
91 Gtk::DrawingArea::on_realize();
92 _window = get_window();
93 _window->get_geometry(_winx, _winy, _winw, _winh, _wind);
98 _gc = Gdk::GC::create(_window);
99 _window->set_background(_white);
104 TRGCDCDisplayDrawingAreaHough::on_expose_event(GdkEventExpose*)
106 Glib::RefPtr<Gdk::Window> window = get_window();
107 window->get_geometry(_winx, _winy, _winw, _winh, _wind);
114 TRGCDCDisplayDrawingAreaHough::on_button_press_event(GdkEventButton* e)
118 on_expose_event((GdkEventExpose*) NULL);
121 if (! _hp)
return true;
124 const int cx0 = int(
float(e->x) / _scaleX / _hp->xSize());
125 const int cy0 = _hp->nY() - int(
float(e->y) / _scaleY / _hp->ySize());
126 const unsigned sid = _hp->serialId(cx0, cy0);
129 const unsigned n = _hp->entry(cx0, cy0);
132 display().information(
"Cell(" + TRGUtilities::itostring(cx0) +
"," +
133 TRGUtilities::itostring(cy0) +
", sid" +
134 TRGUtilities::itostring(sid) +
") " +
135 TRGUtilities::itostring(n) +
"hits");
138 _gc->set_foreground(_red);
145 if (display().rphi()) {
146 const TRGCDC& cdc = * TRGCDC::getTRGCDC();
147 const TCHPlaneMulti2& hp =
148 *
dynamic_cast<const TCHPlaneMulti2*
>(_hp);
149 vector<const TCSegment*> list;
151 for (
unsigned i = 0; i < 5; i++) {
152 const vector<unsigned>& l = hp.patternId(i, sid);
153 for (
unsigned j = 0; j < l.size(); j++) {
154 list.push_back(& cdc.segment(i * 2, l[j]));
155 if (list.size() == 1) {
156 segs =
"s" + cdc.segment(i * 2, l[j]).name();
158 segs +=
",s" + cdc.segment(i * 2, l[j]).name();
162 display().rphi()->information(segs);
163 display().rphi()->area().on_expose_event(0);
164 display().rphi()->area().oneShot(list, _red);
170 cout <<
"***********************" << endl;
171 cout <<
"x=" << e->x <<
",y=" << e->y << endl;
172 cout <<
"cx0=" << cx0 <<
",cy0=" << cy0 << endl;
173 cout <<
"************************" << endl;
179 TRGCDCDisplayDrawingAreaHough::draw(
void)
183 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
184 _gc->set_line_attributes(1,
190 const float xMin = _hp->xMin();
191 const float xMax = _hp->xMax();
192 const float yMin = _hp->yMin();
193 const float yMax = _hp->yMax();
196 _scaleX = _scale / (xMax - xMin) * _winw;
197 _scaleY = _scale / (yMax - yMin) * _winh;
201 for (
unsigned i = 0; i < _hp->nX(); i++) {
202 for (
unsigned j = 0; j < _hp->nY(); j++) {
203 const unsigned n = _hp->entry(i, j);
204 if (n > nMax) nMax = n;
209 cout <<
"max entry=" << nMax << endl;
212 for (
unsigned i = 0; i < _hp->nX(); i++) {
213 for (
unsigned j = 0; j < _hp->nY(); j++) {
214 const unsigned n = _hp->entry(i, j);
219 _gc->set_foreground(_gray0);
221 _gc->set_foreground(_gray1);
223 _gc->set_foreground(_gray2);
225 _gc->set_foreground(_blue);
227 _gc->set_foreground(_red);
236 const int z0 = toY(y0);
237 const int x1 = int(_hp->xSize() * _scaleX);
238 const int y1 = int(_hp->ySize() * _scaleY);
239 _gc->set_foreground(_gray0);
240 _window->draw_rectangle(_gc,
true, x0, z0, x1, y1);
248 _gc->set_foreground(_green);
249 _gc->set_line_attributes(2,
253 const vector<vector<unsigned> *>& regions = _hp->regions();
254 for (
unsigned i = 0; i < (unsigned) regions.size(); i++)
255 drawRegion(regions[i]);
276 TRGCDCDisplayDrawingAreaHough::resetPosition(
void)
283 TRGCDCDisplayDrawingAreaHough::xT(
double x)
const
285 const double xx = x - _x + double(_hp->nX()) / 2;
286 return int(xx * _hp->xSize() * _scaleX);
290 TRGCDCDisplayDrawingAreaHough::yT(
double y)
const
292 const double yy = y - _y + double(_hp->nY()) / 2;
293 return - int(yy * _hp->ySize() * _scaleY) + _winh;
297 TRGCDCDisplayDrawingAreaHough::xR(
double x)
const
299 return int(x / _hp->xSize() * _scaleX);
303 TRGCDCDisplayDrawingAreaHough::yR(
double y)
const
305 return - int((y -
double(_winh)) / _hp->ySize() / _scaleY);
309 TRGCDCDisplayDrawingAreaHough::drawCell(
unsigned xCell,
unsigned yCell)
311 const float x = float(xCell) * _hp->xSize() * _scaleX;
312 const float y = float(yCell) * _hp->ySize() * _scaleY;
314 const int x0 = int(x);
315 const int y0 = int(y);
316 const int z0 = toY(y0);
317 const int x1 = int(x + _hp->xSize() * _scaleX) - x0;
318 const int y1 = int(y + _hp->ySize() * _scaleY) - y0;
320 _window->draw_rectangle(_gc,
true, x0, z0, x1, y1);
330 TRGCDCDisplayDrawingAreaHough:: drawRegion(
const std::vector<unsigned>& r)
332 for (
unsigned i = 0; i < r.size(); i++) {
333 const unsigned id = r[i];
338 const float x = float(ix) * _hp->xSize() * _scaleX;
339 const float y = float(iy) * _hp->ySize() * _scaleY;
341 const int x0 = int(x);
342 const int y0 = int(y);
343 const int z0 = toY(y0);
345 const int x1 = int(x + _hp->xSize() * _scaleX);
346 const int y1 = int(y + _hp->ySize() * _scaleY) - y0;
347 const int z1 = z0 + y1;
349 for (
unsigned k = 0; k < 8; k++) {
351 unsigned idx = _hp->neighbor(
id, k);
353 if (idx ==
id)
continue;
355 for (
unsigned l = 0; l < (unsigned) r.size(); l++) {
363 _window->draw_line(_gc, x0, z0, x1, z0);
365 _window->draw_line(_gc, x1, z0, x1, z1);
367 _window->draw_line(_gc, x0, z1, x1, z1);
369 _window->draw_line(_gc, x0, z0, x0, z1);
Abstract base class for different kinds of events.