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
21
22/** \class TGraphEdge
23\ingroup gviz
24
25An edge object connecting two nodes which can be added in a
26TGraphStruct.
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// Graph Edge default constructor.
31
33{
34 fNode1 = 0;
35 fNode2 = 0;
36 fGVEdge = 0;
37 fX = 0;
38 fY = 0;
39 fN = 0;
40 fArrX = 0;
41 fArrY = 0;
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Graph Edge normal constructor.
46
48 :TObject(), TAttLine()
49{
50 fNode1 = n1;
51 fNode2 = n2;
52 fGVEdge = 0;
53 fX = 0;
54 fY = 0;
55 fN = 0;
56 fArrX = 0;
57 fArrY = 0;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Graph Edge default destructor.
62
64{
65 if (fNode1) delete fNode1;
66 if (fNode2) delete fNode2;
67 if (fX) { delete [] fX; fX = 0; }
68 if (fY) { delete [] fY; fY = 0; }
69 if (fN) { delete [] fN; fN = 0; }
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Create the GraphViz edge into the GraphViz data structure gv.
74
75void TGraphEdge::CreateGVEdge(GVizAgraph_t *gv)
76{
77 if (gv) {
78 Agnode_t *n1 = (Agnode_t*)fNode1->GetGVNode();
79 Agnode_t *n2 = (Agnode_t*)fNode2->GetGVNode();
80#ifdef WITH_CGRAPH
81 fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2, NULL, 1);
82#else
83 fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2);
84#endif
85 } else {
86 Error("CreateGVEdge","Invalid graphviz graph");
87 }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Compute distance from point px,py to an edge.
92
94{
95 Int_t a = 0, dist = 999;
96
97 for (Int_t i = 1; i <= fN[0]; i++) {
98 Int_t n = fN[i];
99 TPolyLine polyline(n, &fX[a], &fY[a], "L");
100 auto d = polyline.DistancetoPrimitive(px, py);
101 if (d < dist) dist = d;
102 a += n;
103 }
104
105 return dist;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Execute action corresponding to one event.
110
112{
113 Int_t a = 0;
114
115 for (Int_t i = 1; i <= fN[0]; i++) {
116 Int_t n = fN[i];
117 TPolyLine polyline(n, &fX[a], &fY[a], "L");
118 polyline.ExecuteEvent(event, px, py);
119 a += n;
120 }
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Layout this edge in the GraphViz space. This is done after gvLayout
125/// has been performed.
126
128{
129 bezier bz;
130 Int_t i,j;
131
132 if (fX) { delete [] fX; fX = 0; }
133 if (fY) { delete [] fY; fY = 0; }
134 if (fN) { delete [] fN; fN = 0; }
135
136 Int_t np = ED_spl((Agedge_t*)fGVEdge)->size;
137 fN = new Int_t[np+1];
138 fN[0] = np;
139 Int_t nb = 0;
140
141 // Compute the total size of the splines arrays
142 for (i=0; i<np; i++) {
143 bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
144 fN[i+1] = bz.size;
145 nb = nb+fN[i+1];
146 }
147
148 // Create the vectors holding all the splines' points.
149 fX = new Double_t[nb];
150 fY = new Double_t[nb];
151
152 // Fill the vectors with the splines' points.
153 Int_t k=0;
154 for (i=0; i<np; i++) {
155 bz = ED_spl((Agedge_t*)fGVEdge)->list[i];
156 fArrX = bz.ep.x;
157 fArrY = bz.ep.y;
158 for (j=0; j<fN[i+1]; j++) {
159 fX[k] = bz.list[j].x;
160 fY[k] = bz.list[j].y;
161 k++;
162 }
163 }
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Paint this edge with its current attributes.
168
170{
171 Int_t i,n,a;
172
175
176 graph.SetLineColor(GetLineColor());
177 graph.SetLineStyle(GetLineStyle());
178 graph.SetLineWidth(GetLineWidth());
179 arrow.SetAngle(38);
180 arrow.SetFillColor(GetLineColor());
181 arrow.SetLineColor(GetLineColor());
182
183 a = 0;
184
185 for (i=1; i<=fN[0]; i++) {
186
187 // Draw the edge body
188 n = fN[i];
189 graph.PaintGraph(n, &fX[a], &fY[a], "L");
190
191 // Draw the edge arrow
192 arrow.PaintArrow(fX[a+n-1], fY[a+n-1], fArrX, fArrY, 0.03, "|>");
193
194 a = a+n;
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Save primitive as a C++ statement(s) on output stream out
200
201void TGraphEdge::SavePrimitive(std::ostream &, Option_t *)
202{
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Save attributes as a C++ statement(s) on output stream out
207/// called by TGraphStruct::SavePrimitive.
208
209void TGraphEdge::SaveAttributes(std::ostream &out, const char* name)
210{
211 SaveLineAttributes(out,name,1,1,1);
212}
213
214////////////////////////////////////////////////////////////////////////////////
215
216void TGraphEdge::Streamer(TBuffer &/*b*/)
217{
218}
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
double Double_t
Definition RtypesCore.h:59
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
Draw all kinds of Arrows.
Definition TArrow.h:29
Line Attributes class.
Definition TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
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:273
Buffer base class used for serializing objects.
Definition TBuffer.h:43
An edge object connecting two nodes which can be added in a TGraphStruct.
Definition TGraphEdge.h:25
void CreateGVEdge(GVizAgraph_t *gv)
Create the GraphViz edge into the GraphViz data structure gv.
virtual ~TGraphEdge()
Graph Edge default destructor.
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
virtual void SavePrimitive(std::ostream &, Option_t *)
Save primitive as a C++ statement(s) on output stream out.
void Layout()
Layout this edge in the GraphViz space.
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
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.
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an edge.
Double_t * fX
X edge points (GV)
Definition TGraphEdge.h:33
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
virtual void Paint(Option_t *option="")
Paint this edge with its current attributes.
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
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:963
Defined by an array on N points in a 2-D space.
Definition TPolyLine.h:23
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Returns closest distance in pixels from point (px, py) to a polyline.
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
const Int_t n
Definition legend1.C:16
Definition graph.py:1