Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphEdge.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Olivier Couet 13/07/09
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 "TGraph.h"
13#include "TArrow.h"
14#include "TPolyLine.h"
15#include "TGraphEdge.h"
16#include "TGraphNode.h"
17
18#include <gvc.h>
19
20
21/** \class TGraphEdge
22\ingroup gviz
23
24An edge object connecting two nodes which can be added in a
25TGraphStruct.
26*/
27
28////////////////////////////////////////////////////////////////////////////////
29/// Graph Edge default constructor.
30
32{
33 fNode1 = 0;
34 fNode2 = 0;
35 fGVEdge = 0;
36 fX = 0;
37 fY = 0;
38 fN = 0;
39 fArrX = 0;
40 fArrY = 0;
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Graph Edge normal constructor.
45
47 :TObject(), TAttLine()
48{
49 fNode1 = n1;
50 fNode2 = n2;
51 fGVEdge = 0;
52 fX = 0;
53 fY = 0;
54 fN = 0;
55 fArrX = 0;
56 fArrY = 0;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Graph Edge default destructor.
61
63{
64 if (fNode1) delete fNode1;
65 if (fNode2) delete fNode2;
66 if (fX) { delete [] fX; fX = 0; }
67 if (fY) { delete [] fY; fY = 0; }
68 if (fN) { delete [] fN; fN = 0; }
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Create the GraphViz edge into the GraphViz data structure gv.
73
75{
76 if (gv) {
79#ifdef WITH_CGRAPH
81#else
83#endif
84 } else {
85 Error("CreateGVEdge","Invalid graphviz graph");
86 }
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Compute distance from point px,py to an edge.
91
93{
94 Int_t a = 0, dist = 999;
95
96 for (Int_t i = 1; i <= fN[0]; i++) {
97 Int_t n = fN[i];
98 TPolyLine polyline(n, &fX[a], &fY[a], "L");
99 auto d = polyline.DistancetoPrimitive(px, py);
100 if (d < dist) dist = d;
101 a += n;
102 }
103
104 return dist;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Execute action corresponding to one event.
109
111{
112 Int_t a = 0;
113
114 for (Int_t i = 1; i <= fN[0]; i++) {
115 Int_t n = fN[i];
116 TPolyLine polyline(n, &fX[a], &fY[a], "L");
117 polyline.ExecuteEvent(event, px, py);
118 a += n;
119 }
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Layout this edge in the GraphViz space. This is done after gvLayout
124/// has been performed.
125
127{
128 bezier bz;
129 Int_t i,j;
130
131 if (fX) { delete [] fX; fX = 0; }
132 if (fY) { delete [] fY; fY = 0; }
133 if (fN) { delete [] fN; fN = 0; }
134
135 Int_t np = ED_spl((Agedge_t*)fGVEdge)->size;
136 fN = new Int_t[np+1];
137 fN[0] = np;
138 Int_t nb = 0;
139
140 // Compute the total size of the splines arrays
141 for (i=0; i<np; i++) {
142 bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
143 fN[i+1] = bz.size;
144 nb = nb+fN[i+1];
145 }
146
147 // Create the vectors holding all the splines' points.
148 fX = new Double_t[nb];
149 fY = new Double_t[nb];
150
151 // Fill the vectors with the splines' points.
152 Int_t k=0;
153 for (i=0; i<np; i++) {
154 bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
155 fArrX = bz.ep.x;
156 fArrY = bz.ep.y;
157 for (j=0; j<fN[i+1]; j++) {
158 fX[k] = bz.list[j].x;
159 fY[k] = bz.list[j].y;
160 k++;
161 }
162 }
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Paint this edge with its current attributes.
167
169{
170 Int_t i,n,a;
171
173 TGraph graph;
174
175 graph.SetLineColor(GetLineColor());
176 graph.SetLineStyle(GetLineStyle());
177 graph.SetLineWidth(GetLineWidth());
178 arrow.SetAngle(38);
179 arrow.SetFillColor(GetLineColor());
180 arrow.SetLineColor(GetLineColor());
181
182 a = 0;
183
184 for (i=1; i<=fN[0]; i++) {
185
186 // Draw the edge body
187 n = fN[i];
188 graph.PaintGraph(n, &fX[a], &fY[a], "L");
189
190 // Draw the edge arrow
191 arrow.PaintArrow(fX[a+n-1], fY[a+n-1], fArrX, fArrY, 0.03, "|>");
192
193 a = a+n;
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Save primitive as a C++ statement(s) on output stream out
199
200void TGraphEdge::SavePrimitive(std::ostream &, Option_t *)
201{
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Save attributes as a C++ statement(s) on output stream out
206/// called by TGraphStruct::SavePrimitive.
207
208void TGraphEdge::SaveAttributes(std::ostream &out, const char* name)
209{
210 SaveLineAttributes(out, name, 1, 1, 1);
211}
212
213////////////////////////////////////////////////////////////////////////////////
214
216{
217}
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 np
char name[80]
Definition TGX11.cxx:110
Draw all kinds of Arrows.
Definition TArrow.h:29
Line Attributes class.
Definition TAttLine.h:20
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:44
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:274
Buffer base class used for serializing objects.
Definition TBuffer.h:43
void CreateGVEdge(GVizAgraph_t *gv)
Create the GraphViz edge into the GraphViz data structure gv.
void Paint(Option_t *option="") override
Paint this edge with its current attributes.
TGraphNode * fNode1
First node.
Definition TGraphEdge.h:30
GVizAgedge_t * fGVEdge
Graphviz edge.
Definition TGraphEdge.h:32
TGraphNode * fNode2
Second node.
Definition TGraphEdge.h:31
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an edge.
void SavePrimitive(std::ostream &, Option_t *) override
Save primitive as a C++ statement(s) on output stream out.
void Layout()
Layout this edge in the GraphViz space.
~TGraphEdge() override
Graph Edge default destructor.
Int_t * fN
number of edge points (GV) fN[0] = number of splines fN[1...n] = number of points in each spline
Definition TGraphEdge.h:35
void Streamer(TBuffer &) override
Stream an object of class TObject.
Double_t fArrY
Arrow Y position.
Definition TGraphEdge.h:39
Double_t * fY
X edge points (GV)
Definition TGraphEdge.h:34
TGraphEdge()
Graph Edge default constructor.
Double_t fArrX
Arrow X position.
Definition TGraphEdge.h:38
void SaveAttributes(std::ostream &, const char *)
Save attributes as a C++ statement(s) on output stream out called by TGraphStruct::SavePrimitive.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Double_t * fX
X edge points (GV)
Definition TGraphEdge.h:33
A graph node object which can be added in a TGraphStruct.
Definition TGraphNode.h:27
GVizAgnode_t * GetGVNode()
Definition TGraphNode.h:50
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void PaintGraph(Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt)
Draw the (x,y) as a graph.
Definition TGraph.cxx:1986
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Defined by an array on N points in a 2-D space.
Definition TPolyLine.h:23
const Int_t n
Definition legend1.C:16