Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TParallelCoordRange.cxx
Go to the documentation of this file.
1// @(#)root/treeviewer:$Id$
2// Author: Bastien Dalla Piazza 02/08/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TParallelCoordRange.h"
13#include "TParallelCoord.h"
14#include "TParallelCoordVar.h"
15
16#include "TPolyLine.h"
17#include "TList.h"
18#include "TVirtualPad.h"
19#include "TPoint.h"
20#include "TFrame.h"
21#include "TCanvas.h"
22#include "TString.h"
23
24#include <iostream>
25
26
27/** \class TParallelCoordRange
28A TParallelCoordRange is a range used for parallel coordinates plots.
29*/
30
31////////////////////////////////////////////////////////////////////////////////
32/// Default constructor.
33
35 :TNamed("Range","Range"), TAttLine(), fSize(0.01)
36{
37 fMin = 0;
38 fMax = 0;
39 fVar = nullptr;
40 fSelect = nullptr;
41 SetBit(kShowOnPad,true);
42 SetBit(kLiveUpdate,false);
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Destructor.
47
51
52////////////////////////////////////////////////////////////////////////////////
53/// Normal constructor.
54
56 :TNamed("Range","Range"), TAttLine(1,1,1), fSize(0.01)
57{
58 if(min == max) {
59 min = var->GetCurrentMin();
60 max = var->GetCurrentMax();
61 }
62 fMin = min;
63 fMax = max;
64
65 fVar = var;
66 fSelect = nullptr;
67
68 if (!sel) {
70 if (s) fSelect = s;
71 else return;
72 } else {
73 fSelect = sel;
74 }
75
77
78 SetBit(kShowOnPad,true);
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Make the selection which owns the range to be drawn on top of the others.
84
86{
87 TList *list = fVar->GetParallel()->GetSelectList();
88 list->Remove(fSelect);
89 list->AddLast(fSelect);
90 gPad->Update();
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Delete the range.
95
96void TParallelCoordRange::Delete(const Option_t* /*options*/)
97{
98 fVar->GetRanges()->Remove(this);
100 delete this;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Compute the distance to the primitive.
105
107{
108 if(TestBit(kShowOnPad)){
109 Double_t xx,yy,thisx=0,thisy=0;
110 xx = gPad->AbsPixeltoX(px);
111 yy = gPad->AbsPixeltoY(py);
112 fVar->GetXYfromValue(fMin,thisx,thisy);
113 Int_t dist = 9999;
114 if(fVar->GetVert()){
115 if(xx > thisx-2*fSize && xx < thisx && yy > thisy-fSize && yy<thisy+fSize) dist = 0;
116 fVar->GetXYfromValue(fMax,thisx,thisy);
117 if(xx > thisx-2*fSize && xx < thisx && yy > thisy-fSize && yy<thisy+fSize) dist = 0;
118 } else {
119 if(yy > thisy-2*fSize && yy < thisy && xx > thisx-fSize && xx<thisx+fSize) dist = 0;
120 fVar->GetXYfromValue(fMax,thisx,thisy);
121 if(yy > thisy-2*fSize && yy < thisy && xx > thisx-fSize && xx<thisx+fSize) dist = 0;
122 }
123 return dist;
124 } else return 9999;
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Draw a TParallelCoordRange.
129
131{
132 AppendPad(options);
133}
134
136 public:
139
141 {
142 TFrame *frame = parent.GetFrame();
143
144 Double_t xx = parent.AbsPixeltoX(px);
145 Double_t yy = parent.AbsPixeltoY(py);
146
147 value = var->GetValuefromXY(xx, yy);
148
149 return var->GetVert() ? (yy > frame->GetY1() && yy < frame->GetY2())
150 : (xx > frame->GetX1() && xx < frame->GetX2());
151 }
152
153 void Paint(TParallelCoordVar *var, TVirtualPad &parent, Double_t size, Double_t currentMin, Double_t currentMax)
154 {
155 std::vector<Double_t> tx(5), ty(5);
156 Double_t txx = 0, tyy = 0;
157 var->GetXYfromValue(value, txx, tyy);
158 if (var->GetVert()) {
159 tx[0] = txx;
160 tx[1] = tx[4] = txx - size;
161 ty[0] = ty[1] = ty[4] = tyy;
162 tx[2] = tx[3] = txx - 2 * size;
163 ty[2] = tyy + size;
164 ty[3] = tyy - size;
165 } else {
166 ty[0] = tyy;
167 ty[1] = ty[4] = tyy - size;
168 tx[0] = tx[1] = tx[4] = txx;
169 ty[2] = ty[3] = tyy - 2 * size;
170 tx[2] = txx - size;
171 tx[3] = txx + size;
172 }
173
174 // paint marker
175 TAttLine{kBlack, 1, 1}.ModifyOn(parent);
176 parent.PaintPolyLine(5, tx.data(), ty.data(), "iparallelrangemarker");
177
178 Double_t txx2, tyy2;
179 var->GetXYfromValue(dragpoint == 1 ? currentMax : currentMin, txx2, tyy2);
180 if (var->GetVert()) {
181 tx[0] = tx[1] = txx - 2*size;
182 ty[0] = tyy;
183 ty[1] = tyy2;
184 } else {
185 tx[0] = txx;
186 tx[1] = txx2;
187 ty[0] = ty[1] = tyy - 2*size;
188 }
189
190 // paint binding line between markers
191 TAttLine{kBlack, 1, 2}.ModifyOn(parent);
192 parent.PaintPolyLine(2, tx.data(), ty.data(), "iparallelrangebind");
193
194 }
195};
196
197////////////////////////////////////////////////////////////////////////////////
198/// Execute the entry.
199
201{
202 if (!gPad) return;
203
204 auto &parent = *gPad;
205
206 if (!parent.IsEditable() && entry!=kMouseEnter) return;
207
208 parent.SetCursor(kPointer);
209
210 auto inter = parent.GetInteractive<TParallelCoordRangeInteractive>(this);
211
212 switch (entry) {
213 case kButton1Down:
214 inter = parent.MakeInteractive<TParallelCoordRangeInteractive>(this);
215 parent.GetCanvas()->Selected(&parent, fVar->GetParallel(), 1);
216 if (inter->GetValue(fVar, parent, px, py)) {
217 if (inter->value < (fMin + fMax) /2)
218 inter->dragpoint = 1;
219 else
220 inter->dragpoint = 2;
221 } else {
222 // not found reasonable value
223 parent.FreeInteractive(this);
224 break;
225 }
226 // no break
227 case kButton1Motion:
228 if (inter && inter->GetValue(fVar, parent, px, py)) {
229 inter->Paint(fVar, parent, fSize, fMin, fMax);
230 parent.UpdateAsync();
231 }
232 break;
233 case kButton1Up:
234 if (inter) {
235 Double_t min = inter->dragpoint == 1 ? inter->value : fMin;
236 Double_t max = inter->dragpoint == 2 ? inter->value : fMax;
237 if (min > max)
238 std::swap(min, max);
239 fMin = min;
240 fMax = max;
241 parent.Modified();
242 }
243 parent.FreeInteractive(this);
244 break;
245 }
246}
247
248
249////////////////////////////////////////////////////////////////////////////////
250/// Evaluate if the given value is within the range or not.
251
253{
254 return evtval>=fMin && evtval<=fMax;
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Paint a TParallelCoordRange.
259
261{
262 if(TestBit(kShowOnPad)){
263 PaintSlider(fMin,true);
264 PaintSlider(fMax,true);
265 }
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Paint a slider.
270
272{
274
275 TPolyLine *p= new TPolyLine();
276 p->SetLineStyle(1);
277 p->SetLineColor(1);
278 p->SetLineWidth(1);
279
280 Double_t *x = new Double_t[5];
281 Double_t *y = new Double_t[5];
282
283 Double_t xx,yy;
284
285 fVar->GetXYfromValue(value,xx,yy);
286 if(fVar->GetVert()){
287 x[0] = xx; x[1]=x[4]=xx-fSize; x[2]=x[3]=xx-2*fSize;
288 y[0]=y[1]=y[4]=yy; y[2] = yy+fSize; y[3] = yy-fSize;
289 } else {
290 y[0] = yy; y[1]=y[4]=yy-fSize; y[2]=y[3]= yy-2*fSize;
291 x[0]=x[1]=x[4]=xx; x[2]=xx-fSize; x[3] = xx+fSize;
292 }
293 if (fill) {
294 p->SetFillStyle(1001);
295 p->SetFillColor(0);
296 p->PaintPolyLine(4,&x[1],&y[1],"f");
297 p->SetFillColor(GetLineColor());
298 p->SetFillStyle(3001);
299 p->PaintPolyLine(4,&x[1],&y[1],"f");
300 }
301 p->PaintPolyLine(5,x,y);
302
303 delete p;
304 delete [] x;
305 delete [] y;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Print info about the range.
310
311void TParallelCoordRange::Print(Option_t* /*options*/) const
312{
313 printf("On \"%s\" : min = %f, max = %f\n", fVar->GetTitle(), fMin, fMax);
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Make the selection which owns the range to be drawn under all the others.
318
320{
321 TList *list = fVar->GetParallel()->GetSelectList();
322 list->Remove(fSelect);
323 list->AddFirst(fSelect);
324 gPad->Update();
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Set the selection line color.
329
335
336////////////////////////////////////////////////////////////////////////////////
337/// Set the selection line width.
338
343
344
345
346/** \class TParallelCoordSelect
347A TParallelCoordSelect is a specialised TList to hold TParallelCoordRanges used
348by TParallelCoord.
349
350Selections of specific entries can be defined over the data se using parallel
351coordinates. With that representation, a selection is an ensemble of ranges
352defined on the axes. Ranges defined on the same axis are conjugated with OR
353(an entry must be in one or the other ranges to be selected). Ranges on
354different axes are are conjugated with AND (an entry must be in all the ranges
355to be selected). Several selections can be defined with different colors. It is
356possible to generate an entry list from a given selection and apply it to the
357tree using the editor ("Apply to tree" button).
358*/
359
360////////////////////////////////////////////////////////////////////////////////
361/// Default constructor.
362
364 : TList(), TAttLine(kBlue,1,1)
365{
366 fTitle = "Selection";
367 SetBit(kActivated,true);
368 SetBit(kShowRanges,true);
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Normal constructor.
373
375 : TList(), TAttLine(kBlue,1,1)
376{
377 fTitle = title;
378 SetBit(kActivated,true);
379 SetBit(kShowRanges,true);
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Destructor.
384
386{
387 TIter next(this);
388 TParallelCoordRange* range;
389 while ((range = (TParallelCoordRange*)next())) range->GetVar()->GetRanges()->Remove(range);
391}
392
393////////////////////////////////////////////////////////////////////////////////
394/// Activate the selection.
395
397{
398 TIter next(this);
399 TParallelCoordRange* range;
400 while ((range = (TParallelCoordRange*)next())) range->SetBit(TParallelCoordRange::kShowOnPad,on);
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Show the ranges needles.
406
408{
409 TIter next(this);
410 TParallelCoordRange* range;
411 while ((range = (TParallelCoordRange*)next())) range->SetBit(TParallelCoordRange::kShowOnPad,s);
413}
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kButton1Down
Definition Buttons.h:17
@ kMouseEnter
Definition Buttons.h:23
dim_t fSize
@ kPointer
Definition GuiTypes.h:376
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Width_t
Line width (short)
Definition RtypesCore.h:99
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
@ kBlack
Definition Rtypes.h:65
@ kBlue
Definition Rtypes.h:66
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
#define gPad
Line Attributes class.
Definition TAttLine.h:21
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void ModifyOn(TVirtualPad &pad)
Change current line attributes on specified pad.
Definition TAttLine.cxx:255
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Double_t GetX1() const
Definition TBox.h:51
Double_t GetX2() const
Definition TBox.h:52
Double_t GetY1() const
Definition TBox.h:53
Double_t GetY2() const
Definition TBox.h:54
Define a Frame.
Definition TFrame.h:19
A doubly linked list.
Definition TList.h:38
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:952
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
Bool_t GetValue(TParallelCoordVar *var, TVirtualPad &parent, Int_t px, Int_t py)
void Paint(TParallelCoordVar *var, TVirtualPad &parent, Double_t size, Double_t currentMin, Double_t currentMax)
A TParallelCoordRange is a range used for parallel coordinates plots.
void SetLineWidth(Width_t wid) override
Set the selection line width.
void Draw(Option_t *options="") override
Draw a TParallelCoordRange.
void SetLineColor(Color_t col) override
Set the selection line color.
void Paint(Option_t *options) override
Paint a TParallelCoordRange.
TParallelCoordSelect * fSelect
Selection owning the range.
TParallelCoordVar * GetVar()
TParallelCoordVar * fVar
Variable owning the range.
virtual void SendToBack()
Make the selection which owns the range to be drawn under all the others.
virtual void BringOnTop()
Make the selection which owns the range to be drawn on top of the others.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute the distance to the primitive.
~TParallelCoordRange() override
Destructor.
const Double_t fSize
Size of the painted range.
void PaintSlider(Double_t value, bool fill=false)
Paint a slider.
void Print(Option_t *options) const override
Print info about the range.
void Delete(const Option_t *options="") override
Delete the range.
Double_t fMin
Min value for the range.
void ExecuteEvent(Int_t entry, Int_t px, Int_t py) override
Execute the entry.
Double_t fMax
Max value for the range.
bool IsIn(Double_t evtval)
Evaluate if the given value is within the range or not.
TParallelCoordRange()
Default constructor.
A TParallelCoordSelect is a specialised TList to hold TParallelCoordRanges used by TParallelCoord.
void SetShowRanges(bool s)
Show the ranges needles.
~TParallelCoordSelect() override
Destructor.
TParallelCoordSelect()
Default constructor.
void SetActivated(bool on)
Activate the selection.
TParallelCoord axes.
Double_t GetValuefromXY(Double_t x, Double_t y)
Get the value corresponding to the position.
bool GetVert() const
Tells if the axis is vertical or not.
Double_t GetCurrentMax() const
Double_t GetCurrentMin() const
void GetXYfromValue(Double_t value, Double_t &x, Double_t &y)
Get a position corresponding to the value on the axis.
TList * GetRanges() const
TParallelCoord * GetParallel() const
TList * GetSelectList()
TParallelCoordSelect * GetCurrentSelection()
Return the selection currently being edited.
void CleanUpSelections(TParallelCoordRange *range)
Clean up the selections from the ranges which could have been deleted when a variable has been delete...
@ kLiveUpdate
To paint the entries when being modified.
Defined by an array on N points in a 2-D space.
Definition TPolyLine.h:23
Helper class to store interactive parameters for individual objects Should be used via MakeInteractiv...
Definition TVirtualPad.h:72
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:53
virtual TFrame * GetFrame()=0
virtual Double_t AbsPixeltoX(Double_t px)=0
virtual void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="")=0
virtual Double_t AbsPixeltoY(Double_t py)=0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17